From 4ad7b4317d77c161cab69f5ae2b52b1583c96f11 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 26 Jun 2016 10:04:46 -0700 Subject: make makeCallImport more similar to makeCall; do not assume all imports exist, let functions be created in a way independent from global state --- src/ast_utils.h | 2 +- src/wasm-builder.h | 4 ++-- src/wasm-linker.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ast_utils.h b/src/ast_utils.h index c2a3db435..77bfaf1f3 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -258,7 +258,7 @@ struct ExpressionManipulator { return ret; } Expression* visitCallImport(CallImport *curr) { - auto* ret = builder.makeCallImport(curr->target, {}); + auto* ret = builder.makeCallImport(curr->target, {}, curr->type); for (Index i = 0; i < curr->operands.size(); i++) { ret->operands.push_back(copy(curr->operands[i])); } diff --git a/src/wasm-builder.h b/src/wasm-builder.h index e58d66795..501124999 100644 --- a/src/wasm-builder.h +++ b/src/wasm-builder.h @@ -107,9 +107,9 @@ public: call->operands.set(args); return call; } - CallImport* makeCallImport(Name target, const std::vector& args) { + CallImport* makeCallImport(Name target, const std::vector& args, WasmType type) { auto* call = wasm.allocator.alloc(); - call->type = wasm.getImport(target)->type->result; + call->type = type; // similar to makeCall, for consistency call->target = target; call->operands.set(args); return call; diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index eb7f9e00d..34dbc7f9c 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -396,7 +396,7 @@ Function* Linker::getImportThunk(Name name, const FunctionType* funcType) { for (Index i = 0; i < funcType->params.size(); ++i) { args.push_back(wasmBuilder.makeGetLocal(i, funcType->params[i])); } - Expression* call = wasmBuilder.makeCallImport(name, args); + Expression* call = wasmBuilder.makeCallImport(name, args, funcType->result); f->body = call; out.wasm.addFunction(f); return f; -- cgit v1.2.3