diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-12 09:33:32 -0500 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-12 09:33:32 -0500 |
commit | 722bb6a82070fa8bd3a263f478b3d2779eee7f1d (patch) | |
tree | 4660341e1971cccac8048376b27f6ea8a2127b5b | |
parent | 54e70e4b391d87482024efcf0829e967e46da866 (diff) | |
download | binaryen-722bb6a82070fa8bd3a263f478b3d2779eee7f1d.tar.gz binaryen-722bb6a82070fa8bd3a263f478b3d2779eee7f1d.tar.bz2 binaryen-722bb6a82070fa8bd3a263f478b3d2779eee7f1d.zip |
work on call_indirect in s2wasm
-rw-r--r-- | src/asm_v_wasm.h | 11 | ||||
-rw-r--r-- | src/s2wasm.h | 13 | ||||
-rw-r--r-- | test/dot_s/call.wast | 8 |
3 files changed, 27 insertions, 5 deletions
diff --git a/src/asm_v_wasm.h b/src/asm_v_wasm.h index 829d79930..1bf689802 100644 --- a/src/asm_v_wasm.h +++ b/src/asm_v_wasm.h @@ -38,7 +38,6 @@ char getSig(WasmType type) { } std::string getSig(FunctionType *type) { - // generate signature std::string ret; ret += getSig(type->result); for (auto param : type->params) { @@ -48,7 +47,6 @@ std::string getSig(FunctionType *type) { } std::string getSig(Function *func) { - // generate signature std::string ret; ret += getSig(func->result); for (auto param : func->params) { @@ -57,6 +55,15 @@ std::string getSig(Function *func) { return ret; } +std::string getSig(CallBase *call) { + std::string ret; + ret += getSig(call->type); + for (auto operand : call->operands) { + ret += getSig(operand->type); + } + return ret; +} + } // namespace wasm #endif // _asm_v_wasm_h_ diff --git a/src/s2wasm.h b/src/s2wasm.h index 19fd426ac..1d42a08e6 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -5,6 +5,7 @@ #include "wasm.h" #include "parsing.h" +#include "asm_v_wasm.h" namespace wasm { @@ -362,7 +363,7 @@ private: if (match("_import")) { curr = allocator.alloc<CallImport>(); } else if (match("_indirect")) { - curr = allocator.alloc<CallImport>(); + curr = allocator.alloc<CallIndirect>(); } else { curr = allocator.alloc<Call>(); } @@ -384,6 +385,16 @@ private: } std::reverse(curr->operands.begin(), curr->operands.end()); setOutput(curr, assign); + if (curr->is<CallIndirect>()) { + auto call = curr->dyn_cast<CallIndirect>(); + auto type = allocator.alloc<FunctionType>(); + call->fullType = type; + type->name = cashew::IString((std::string("FUNCSIG_") + getSig(call)).c_str(), false); + // TODO type->result + for (auto operand : call->operands) { + type->params.push_back(operand->type); + } + } } else if (match("block")) { auto curr = allocator.alloc<Block>(); curr->name = getStr(); diff --git a/test/dot_s/call.wast b/test/dot_s/call.wast index 0e1ed43cb..7c7e47a25 100644 --- a/test/dot_s/call.wast +++ b/test/dot_s/call.wast @@ -70,7 +70,9 @@ (func $call_indirect_void (param $$0 i32) (block $fake_return_waka123 (block - (call_import $$0) + (call_indirect $FUNCSIG_v + (get_local $$0) + ) (br $fake_return_waka123) ) ) @@ -79,7 +81,9 @@ (block $fake_return_waka123 (block (br $fake_return_waka123 - (call_import $$0) + (call_indirect $FUNCSIG_v + (get_local $$0) + ) ) ) ) |