Skip to content

Commit 4ad7b43

Browse files
committed
make makeCallImport more similar to makeCall; do not assume all imports exist, let functions be created in a way independent from global state
1 parent 287f85e commit 4ad7b43

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/ast_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ struct ExpressionManipulator {
258258
return ret;
259259
}
260260
Expression* visitCallImport(CallImport *curr) {
261-
auto* ret = builder.makeCallImport(curr->target, {});
261+
auto* ret = builder.makeCallImport(curr->target, {}, curr->type);
262262
for (Index i = 0; i < curr->operands.size(); i++) {
263263
ret->operands.push_back(copy(curr->operands[i]));
264264
}

src/wasm-builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ class Builder {
107107
call->operands.set(args);
108108
return call;
109109
}
110-
CallImport* makeCallImport(Name target, const std::vector<Expression*>& args) {
110+
CallImport* makeCallImport(Name target, const std::vector<Expression*>& args, WasmType type) {
111111
auto* call = wasm.allocator.alloc<CallImport>();
112-
call->type = wasm.getImport(target)->type->result;
112+
call->type = type; // similar to makeCall, for consistency
113113
call->target = target;
114114
call->operands.set(args);
115115
return call;

src/wasm-linker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ Function* Linker::getImportThunk(Name name, const FunctionType* funcType) {
396396
for (Index i = 0; i < funcType->params.size(); ++i) {
397397
args.push_back(wasmBuilder.makeGetLocal(i, funcType->params[i]));
398398
}
399-
Expression* call = wasmBuilder.makeCallImport(name, args);
399+
Expression* call = wasmBuilder.makeCallImport(name, args, funcType->result);
400400
f->body = call;
401401
out.wasm.addFunction(f);
402402
return f;

0 commit comments

Comments
 (0)