diff options
Diffstat (limited to 'src/passes/FuncCastEmulation.cpp')
-rw-r--r-- | src/passes/FuncCastEmulation.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/passes/FuncCastEmulation.cpp b/src/passes/FuncCastEmulation.cpp index f36e1e909..729a4a6c3 100644 --- a/src/passes/FuncCastEmulation.cpp +++ b/src/passes/FuncCastEmulation.cpp @@ -131,7 +131,7 @@ struct ParallelFuncCastEmulation Pass* create() override { return new ParallelFuncCastEmulation(ABIType); } - ParallelFuncCastEmulation(Name ABIType) : ABIType(ABIType) {} + ParallelFuncCastEmulation(Signature ABIType) : ABIType(ABIType) {} void visitCallIndirect(CallIndirect* curr) { if (curr->operands.size() > NUM_PARAMS) { @@ -146,7 +146,7 @@ struct ParallelFuncCastEmulation curr->operands.push_back(LiteralUtils::makeZero(i64, *getModule())); } // Set the new types - curr->fullType = ABIType; + curr->sig = ABIType; auto oldType = curr->type; curr->type = i64; curr->finalize(); // may be unreachable @@ -155,18 +155,15 @@ struct ParallelFuncCastEmulation } private: - // the name of a type for a call with the right params and return - Name ABIType; + // The signature of a call with the right params and return + Signature ABIType; }; struct FuncCastEmulation : public Pass { void run(PassRunner* runner, Module* module) override { // we just need the one ABI function type for all indirect calls - std::string sig = "j"; - for (Index i = 0; i < NUM_PARAMS; i++) { - sig += 'j'; - } - ABIType = ensureFunctionType(sig, module)->name; + Signature ABIType(Type(std::vector<Type>(NUM_PARAMS, Type::i64)), + Type::i64); // Add a way for JS to call into the table (as our i64 ABI means an i64 // is returned when there is a return value, which JS engines will fail on), // using dynCalls @@ -191,9 +188,6 @@ struct FuncCastEmulation : public Pass { } private: - // the name of a type for a call with the right params and return - Name ABIType; - // Creates a thunk for a function, casting args and return value as needed. Name makeThunk(Name name, Module* module) { Name thunk = std::string("byn$fpcast-emu$") + name.str; @@ -203,8 +197,8 @@ private: } // The item in the table may be a function or a function import. auto* func = module->getFunction(name); - std::vector<Type>& params = func->params; - Type type = func->result; + const std::vector<Type>& params = func->sig.params.expand(); + Type type = func->sig.results; Builder builder(*module); std::vector<Expression*> callOperands; for (Index i = 0; i < params.size(); i++) { @@ -216,12 +210,11 @@ private: for (Index i = 0; i < NUM_PARAMS; i++) { thunkParams.push_back(i64); } - auto* thunkFunc = builder.makeFunction(thunk, - std::move(thunkParams), - i64, - {}, // no vars - toABI(call, module)); - thunkFunc->type = ABIType; + auto* thunkFunc = + builder.makeFunction(thunk, + Signature(Type(thunkParams), Type::i64), + {}, // no vars + toABI(call, module)); module->addFunction(thunkFunc); return thunk; } |