1 /*
2  * Copyright 2015 WebAssembly Community Group participants
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef wasm_asm_v_wasm_h
18 #define wasm_asm_v_wasm_h
19 
20 #include "emscripten-optimizer/optimizer.h"
21 #include "mixed_arena.h"
22 #include "wasm.h"
23 
24 namespace wasm {
25 
26 Type asmToWasmType(AsmType asmType);
27 
28 AsmType wasmToAsmType(Type type);
29 
30 char getSig(Type type);
31 std::string getSig(Function* func);
32 std::string getSig(Type results, Type params);
33 
34 template<typename T,
35          typename std::enable_if<std::is_base_of<Expression, T>::value>::type* =
36            nullptr>
getSig(T * call)37 std::string getSig(T* call) {
38   std::string ret;
39   ret += getSig(call->type);
40   for (auto operand : call->operands) {
41     ret += getSig(operand->type);
42   }
43   return ret;
44 }
45 
46 template<typename ListType>
getSig(Type result,const ListType & operands)47 std::string getSig(Type result, const ListType& operands) {
48   std::string ret;
49   ret += getSig(result);
50   for (auto operand : operands) {
51     ret += getSig(operand->type);
52   }
53   return ret;
54 }
55 
56 template<typename ListType>
getSigFromStructs(Type result,const ListType & operands)57 std::string getSigFromStructs(Type result, const ListType& operands) {
58   std::string ret;
59   ret += getSig(result);
60   for (auto operand : operands) {
61     ret += getSig(operand.type);
62   }
63   return ret;
64 }
65 
66 // converts an f32 to an f64 if necessary
67 Expression* ensureDouble(Expression* expr, MixedArena& allocator);
68 
69 } // namespace wasm
70 
71 #endif // wasm_asm_v_wasm_h
72