summaryrefslogtreecommitdiff
path: root/src/passes/LegalizeJSInterface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/LegalizeJSInterface.cpp')
-rw-r--r--src/passes/LegalizeJSInterface.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp
index 10e751701..e7a5f9220 100644
--- a/src/passes/LegalizeJSInterface.cpp
+++ b/src/passes/LegalizeJSInterface.cpp
@@ -157,12 +157,12 @@ private:
std::map<Name, Name> illegalImportsToLegal;
template<typename T> bool isIllegal(T* t) {
- for (const auto& param : t->sig.params) {
+ for (const auto& param : t->getParams()) {
if (param == Type::i64) {
return true;
}
}
- return t->sig.results == Type::i64;
+ return t->getResults() == Type::i64;
}
bool isDynCall(Name name) { return name.startsWith("dynCall_"); }
@@ -201,10 +201,10 @@ private:
auto* call = module->allocator.alloc<Call>();
call->target = func->name;
- call->type = func->sig.results;
+ call->type = func->getResults();
std::vector<Type> legalParams;
- for (const auto& param : func->sig.params) {
+ for (const auto& param : func->getParams()) {
if (param == Type::i64) {
call->operands.push_back(I64Utilities::recreateI64(
builder, legalParams.size(), legalParams.size() + 1));
@@ -216,12 +216,12 @@ private:
legalParams.push_back(param);
}
}
- legal->sig.params = Type(legalParams);
-
- if (func->sig.results == Type::i64) {
+ Type resultsType =
+ func->getResults() == Type::i64 ? Type::i32 : func->getResults();
+ legal->type = Signature(Type(legalParams), resultsType);
+ if (func->getResults() == Type::i64) {
Function* f =
getFunctionOrImport(module, SET_TEMP_RET0, Type::i32, Type::none);
- legal->sig.results = Type::i32;
auto index = Builder::addVar(legal, Name(), Type::i64);
auto* block = builder.makeBlock();
block->list.push_back(builder.makeLocalSet(index, call));
@@ -231,10 +231,8 @@ private:
block->finalize();
legal->body = block;
} else {
- legal->sig.results = func->sig.results;
legal->body = call;
}
-
return module->addFunction(legal)->name;
}
@@ -248,14 +246,14 @@ private:
legalIm->base = im->base;
auto stub = make_unique<Function>();
stub->name = Name(std::string("legalfunc$") + im->name.str);
- stub->sig = im->sig;
+ stub->type = im->type;
auto* call = module->allocator.alloc<Call>();
call->target = legalIm->name;
std::vector<Type> params;
Index i = 0;
- for (const auto& param : im->sig.params) {
+ for (const auto& param : im->getParams()) {
if (param == Type::i64) {
call->operands.push_back(I64Utilities::getI64Low(builder, i));
call->operands.push_back(I64Utilities::getI64High(builder, i));
@@ -268,17 +266,17 @@ private:
++i;
}
- if (im->sig.results == Type::i64) {
+ if (im->getResults() == Type::i64) {
Function* f =
getFunctionOrImport(module, GET_TEMP_RET0, Type::none, Type::i32);
call->type = Type::i32;
Expression* get = builder.makeCall(f->name, {}, call->type);
stub->body = I64Utilities::recreateI64(builder, call, get);
} else {
- call->type = im->sig.results;
+ call->type = im->getResults();
stub->body = call;
}
- legalIm->sig = Signature(Type(params), call->type);
+ legalIm->type = Signature(Type(params), call->type);
const auto& stubName = stub->name;
if (!module->getFunctionOrNull(stubName)) {
@@ -302,13 +300,12 @@ private:
return f;
}
// Failing that create a new function import.
- auto import = new Function;
- import->name = name;
+ auto import = Builder::makeFunction(name, Signature(params, results), {});
import->module = ENV;
import->base = name;
- import->sig = Signature(params, results);
- module->addFunction(import);
- return import;
+ auto* ret = import.get();
+ module->addFunction(std::move(import));
+ return ret;
}
};