diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-11-18 16:22:26 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-11-18 16:22:26 -0800 |
commit | 0b02cbdc0af0a42032b35344bc2f8d3f768766db (patch) | |
tree | b195c549dcbd926b9b8058fd28930fdb810f023b | |
parent | 262bf6fbddf19eb1b365de91aab36c7d4578c135 (diff) | |
download | binaryen-0b02cbdc0af0a42032b35344bc2f8d3f768766db.tar.gz binaryen-0b02cbdc0af0a42032b35344bc2f8d3f768766db.tar.bz2 binaryen-0b02cbdc0af0a42032b35344bc2f8d3f768766db.zip |
use builtin types to mark CallImports directly, they do not need coercions to be understood
-rw-r--r-- | src/asm2wasm.h | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 5614329d0..a8cb8fc15 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -371,6 +371,21 @@ private: else if (call->is<CallIndirect>()) call->type = type; } + FunctionType* getBuiltinFunctionType(Name module, Name base) { + if (module == GLOBAL_MATH) { + if (base == ABS /* XXX, this should be overloaded */) { + static FunctionType* builtin = nullptr; + if (!builtin) { + builtin = new FunctionType(); + builtin->params.push_back(f64); + builtin->result = f64; + } + return builtin; + } + } + return nullptr; + } + Function* processFunction(Ref ast); }; @@ -537,14 +552,10 @@ void Asm2WasmBuilder::processAsm(Ref ast) { Import& import = *pair.second; if (importedFunctionTypes.find(name) != importedFunctionTypes.end()) { // special math builtins - if (import.module == GLOBAL_MATH) { - IString base = import.base; - if (base == ABS /* XXX, this should be overloaded */) { - import.type = FunctionType(); - import.type.params.push_back(f64); - import.type.result = f64; - continue; - } + FunctionType* builtin = getBuiltinFunctionType(import.module, import.base); + if (builtin) { + import.type = *builtin; + continue; } import.type = importedFunctionTypes[name]; } else if (import.module != ASM2WASM) { // special-case the special module @@ -973,6 +984,9 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { #else ret = allocator.alloc<CallImport>(); noteImportedFunctionCall(ast, type, &asmData); + Import* import = wasm.importsMap[name]; + auto builtin = getBuiltinFunctionType(import->module, import->base); + if (builtin) ret->type = builtin->result; #endif } else { ret = allocator.alloc<Call>(); |