summaryrefslogtreecommitdiff
path: root/src/asm2wasm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-05 16:28:09 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-03-05 16:28:09 -0800
commit3f838fd9c42eb9408b82120a43da0caeae44963e (patch)
treec945d502d4f9f20c843fbabfa5dd83a3aae9153d /src/asm2wasm.h
parent9445c4900b120455583fbf48c8a08666a050bc5a (diff)
downloadbinaryen-3f838fd9c42eb9408b82120a43da0caeae44963e.tar.gz
binaryen-3f838fd9c42eb9408b82120a43da0caeae44963e.tar.bz2
binaryen-3f838fd9c42eb9408b82120a43da0caeae44963e.zip
harmonize ffi calls in asm2wasm, adding arguments as needed. this helps with asm ffis which tolerate overloading, unlike wasm
Diffstat (limited to 'src/asm2wasm.h')
-rw-r--r--src/asm2wasm.h23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 353f80413..1aca26e88 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -204,8 +204,9 @@ private:
// uses, in the first pass
std::map<IString, FunctionType> importedFunctionTypes;
+ std::map<IString, std::vector<CallImport*>> importedFunctionCalls;
- void noteImportedFunctionCall(Ref ast, WasmType resultType, AsmData *asmData) {
+ void noteImportedFunctionCall(Ref ast, WasmType resultType, AsmData *asmData, CallImport* call) {
assert(ast[0] == CALL && ast[1][0] == NAME);
IString importName = ast[1][1]->getIString();
FunctionType type;
@@ -242,6 +243,7 @@ private:
} else {
importedFunctionTypes[importName] = type;
}
+ importedFunctionCalls[importName].push_back(call);
}
FunctionType* getFunctionType(Ref parent, ExpressionList& operands) {
@@ -670,6 +672,20 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
wasm.removeImport(curr);
}
+ // fill out call_import - add extra params as needed. asm tolerates ffi overloading, wasm does not
+ for (auto& pair : importedFunctionCalls) {
+ IString name = pair.first;
+ auto& list = pair.second;
+ auto type = importedFunctionTypes[name];
+ for (auto* call : list) {
+ for (size_t i = call->operands.size(); i < type.params.size(); i++) {
+ auto val = allocator.alloc<Const>();
+ val->type = val->value.type = type.params[i];
+ call->operands.push_back(val);
+ }
+ }
+ }
+
// finalize indirect calls
for (auto& pair : callIndirects) {
@@ -1148,8 +1164,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
if (wasm.importsMap.find(name) != wasm.importsMap.end()) {
Ref parent = astStackHelper.getParent();
WasmType type = !!parent ? detectWasmType(parent, &asmData) : none;
- ret = allocator.alloc<CallImport>();
- noteImportedFunctionCall(ast, type, &asmData);
+ auto specific = allocator.alloc<CallImport>();
+ noteImportedFunctionCall(ast, type, &asmData, specific);
+ ret = specific;
} else {
ret = allocator.alloc<Call>();
}