From db5ee8d83eb32fc7fd007f9e3d9b46d748161ae7 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 22 Aug 2016 12:05:20 -0700 Subject: set type of calls to their target, instead of the previous behavior where the asm.js context informed us. this lets us add drops where necessary --- src/asm2wasm.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index a85fd4676..5167ad70f 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -401,9 +401,9 @@ private: } void fixCallType(Expression* call, WasmType type) { - if (call->is()) call->type = type; - if (call->is()) call->type = type; - else if (call->is()) call->type = type; + if (call->is()) call->cast()->type = type; + if (call->is()) call->cast()->type = type; + else if (call->is()) call->cast()->type = type; } FunctionType* getBuiltinFunctionType(Name module, Name base, ExpressionList* operands = nullptr) { @@ -736,7 +736,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) { wasm.removeImport(curr); } - // Finalize indirect calls and import calls + // Finalize calls now that everything is known and generated struct FinalizeCalls : public WalkerPass>> { bool isFunctionParallel() override { return true; } @@ -747,6 +747,10 @@ void Asm2WasmBuilder::processAsm(Ref ast) { FinalizeCalls(Asm2WasmBuilder* parent) : parent(parent) {} + void visitCall(Call* curr) { + curr->type = getModule()->getFunction(curr->target)->result; + } + void visitCallImport(CallImport* curr) { // fill out call_import - add extra params as needed, etc. asm tolerates ffi overloading, wasm does not auto iter = parent->importedFunctionTypes.find(curr->target); @@ -768,6 +772,8 @@ void Asm2WasmBuilder::processAsm(Ref ast) { } } } + + curr->type = getModule()->getImport(curr->target)->functionType->result; } void visitCallIndirect(CallIndirect* curr) { // we already call into target = something + offset, where offset is a callImport with the name of the table. replace that with the table offset -- cgit v1.2.3