diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-01-11 20:40:55 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-01-11 20:58:53 -0800 |
commit | 686a8334090f57e1ba218e552819b3c6374059b5 (patch) | |
tree | f5dd8b43127fda4671eb4c7ce93440995525744e /src/asm_v_wasm.h | |
parent | efe369358fd6c8ede5145f12bfa511b515d2a32a (diff) | |
download | binaryen-686a8334090f57e1ba218e552819b3c6374059b5.tar.gz binaryen-686a8334090f57e1ba218e552819b3c6374059b5.tar.bz2 binaryen-686a8334090f57e1ba218e552819b3c6374059b5.zip |
refactor FunctionType to always be accessed from the Module's central store, which is necessary for simple binary writing
Diffstat (limited to 'src/asm_v_wasm.h')
-rw-r--r-- | src/asm_v_wasm.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/asm_v_wasm.h b/src/asm_v_wasm.h index f0065bbf9..394c7a321 100644 --- a/src/asm_v_wasm.h +++ b/src/asm_v_wasm.h @@ -17,6 +17,7 @@ #ifndef wasm_asm_v_wasm_h #define wasm_asm_v_wasm_h +#include "mixed_arena.h" #include "emscripten-optimizer/optimizer.h" namespace wasm { @@ -81,6 +82,15 @@ std::string getSig(CallBase *call) { return ret; } +std::string getSig(WasmType result, ExpressionList& operands) { + std::string ret; + ret += getSig(result); + for (auto operand : operands) { + ret += getSig(operand->type); + } + return ret; +} + WasmType sigToWasmType(char sig) { switch (sig) { case 'i': return i32; @@ -101,6 +111,22 @@ FunctionType sigToFunctionType(std::string sig) { return ret; } +FunctionType* ensureFunctionType(std::string sig, Module* wasm, MixedArena& allocator) { + cashew::IString name(("FUNCSIG$" + sig).c_str(), false); + if (wasm->functionTypesMap.find(name) != wasm->functionTypesMap.end()) { + return wasm->functionTypesMap[name]; + } + // add new type + auto type = allocator.alloc<FunctionType>(); + type->name = name; + type->result = sigToWasmType(sig[0]); + for (size_t i = 1; i < sig.size(); i++) { + type->params.push_back(sigToWasmType(sig[i])); + } + wasm->addFunctionType(type); + return type; +} + } // namespace wasm #endif // wasm_asm_v_wasm_h |