summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asm_v_wasm.h21
-rw-r--r--src/s2wasm.h16
2 files changed, 31 insertions, 6 deletions
diff --git a/src/asm_v_wasm.h b/src/asm_v_wasm.h
index a19334c2c..f0065bbf9 100644
--- a/src/asm_v_wasm.h
+++ b/src/asm_v_wasm.h
@@ -46,6 +46,7 @@ AsmType wasmToAsmType(WasmType type) {
char getSig(WasmType type) {
switch (type) {
case i32: return 'i';
+ case i64: return 'j';
case f32: return 'f';
case f64: return 'd';
case none: return 'v';
@@ -80,6 +81,26 @@ std::string getSig(CallBase *call) {
return ret;
}
+WasmType sigToWasmType(char sig) {
+ switch (sig) {
+ case 'i': return i32;
+ case 'j': return i64;
+ case 'f': return f32;
+ case 'd': return f64;
+ case 'v': return none;
+ default: abort();
+ }
+}
+
+FunctionType sigToFunctionType(std::string sig) {
+ FunctionType ret;
+ ret.result = sigToWasmType(sig[0]);
+ for (size_t i = 1; i < sig.size(); i++) {
+ ret.params.push_back(sigToWasmType(sig[i]));
+ }
+ return ret;
+}
+
} // namespace wasm
#endif // wasm_asm_v_wasm_h
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 4811632b1..9d50693e9 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -552,12 +552,6 @@ private:
auto specific = allocator.alloc<CallImport>();
specific->target = target;
curr = specific;
- if (wasm.importsMap.count(target) == 0) {
- auto import = allocator.alloc<Import>();
- import->name = import->base = target;
- import->module = ENV;
- wasm.addImport(import);
- }
}
}
curr->type = type;
@@ -585,6 +579,15 @@ private:
} else {
call->fullType = wasm.functionTypesMap[typeName];
}
+ } else if (curr->is<CallImport>()) {
+ auto target = curr->cast<CallImport>()->target;
+ if (wasm.importsMap.count(target) == 0) {
+ auto import = allocator.alloc<Import>();
+ import->name = import->base = target;
+ import->module = ENV;
+ import->type = sigToFunctionType(getSig(curr));
+ wasm.addImport(import);
+ }
}
};
auto handleTyped = [&](WasmType type) {
@@ -1070,6 +1073,7 @@ public:
auto import = parent->allocator.alloc<Import>();
import->name = import->base = curr->target;
import->module = ENV;
+ import->type = sigToFunctionType(getSig(curr));
parent->wasm.addImport(import);
}
}