diff options
Diffstat (limited to 'src/asm2wasm.h')
-rw-r--r-- | src/asm2wasm.h | 67 |
1 files changed, 10 insertions, 57 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 280624d9b..75862abc8 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -243,26 +243,10 @@ private: } } - FunctionType *getFunctionType(Ref parent, ExpressionList& operands) { + FunctionType* getFunctionType(Ref parent, ExpressionList& operands) { // generate signature WasmType result = !!parent ? detectWasmType(parent, nullptr) : none; - std::string str = "FUNCSIG$"; - str += getSig(result); - for (auto operand : operands) { - str += getSig(operand->type); - } - IString sig(str.c_str(), false); - if (wasm.functionTypesMap.find(sig) == wasm.functionTypesMap.end()) { - // add new type - auto type = allocator.alloc<FunctionType>(); - type->name = sig; - type->result = result; - for (auto operand : operands) { - type->params.push_back(operand->type); - } - wasm.addFunctionType(type); - } - return wasm.functionTypesMap[sig]; + return ensureFunctionType(getSig(result, operands), &wasm, allocator); } public: @@ -421,34 +405,9 @@ private: if (base == ABS) { assert(operands && operands->size() == 1); WasmType type = (*operands)[0]->type; - if (type == i32) { - static FunctionType* builtin = nullptr; - if (!builtin) { - builtin = new FunctionType(); - builtin->params.push_back(i32); - builtin->result = i32; - } - return builtin; - } - if (type == f32) { - static FunctionType* builtin = nullptr; - if (!builtin) { - builtin = new FunctionType(); - builtin->params.push_back(f32); - builtin->result = f32; - } - return builtin; - } - if (type == f64) { - static FunctionType* builtin = nullptr; - if (!builtin) { - builtin = new FunctionType(); - builtin->params.push_back(f64); - builtin->result = f64; - } - return builtin; - } - + if (type == i32) return ensureFunctionType("ii", &wasm, allocator); + if (type == f32) return ensureFunctionType("ff", &wasm, allocator); + if (type == f64) return ensureFunctionType("dd", &wasm, allocator); } } return nullptr; @@ -692,10 +651,10 @@ void Asm2WasmBuilder::processAsm(Ref ast) { // special math builtins FunctionType* builtin = getBuiltinFunctionType(import.module, import.base); if (builtin) { - import.type = *builtin; + import.type = builtin; continue; } - import.type = importedFunctionTypes[name]; + import.type = ensureFunctionType(getSig(&importedFunctionTypes[name]), &wasm, allocator); } else if (import.module != ASM2WASM) { // special-case the special module // never actually used toErase.push_back(name); @@ -906,10 +865,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { import->name = F64_REM; import->module = ASM2WASM; import->base = F64_REM; - import->type.name = F64_REM; - import->type.result = f64; - import->type.params.push_back(f64); - import->type.params.push_back(f64); + import->type = ensureFunctionType("ddd", &wasm, allocator); wasm.addImport(import); } return call; @@ -950,8 +906,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { import->name = DEBUGGER; import->module = ASM2WASM; import->base = DEBUGGER; - import->type.name = DEBUGGER; - import->type.result = none; + import->type = ensureFunctionType("v", &wasm, allocator); wasm.addImport(import); } return call; @@ -1057,9 +1012,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { import->name = F64_TO_INT; import->module = ASM2WASM; import->base = F64_TO_INT; - import->type.name = F64_TO_INT; - import->type.result = i32; - import->type.params.push_back(f64); + import->type = ensureFunctionType("id", &wasm, allocator); wasm.addImport(import); } return ret; |