summaryrefslogtreecommitdiff
path: root/src/wasm-builder.h
diff options
context:
space:
mode:
authorThomas Lively <7121787+tlively@users.noreply.github.com>2019-12-11 17:12:37 -0800
committerAlon Zakai <azakai@google.com>2019-12-11 17:12:37 -0800
commit759c485a9f35bd859d43b86b02e1397a669fa469 (patch)
treea5c7475002b406e35c6d1e5c2d843000947ef192 /src/wasm-builder.h
parentacd786dbd1e59f9d105c4ec8603c2ff46f233649 (diff)
downloadbinaryen-759c485a9f35bd859d43b86b02e1397a669fa469.tar.gz
binaryen-759c485a9f35bd859d43b86b02e1397a669fa469.tar.bz2
binaryen-759c485a9f35bd859d43b86b02e1397a669fa469.zip
Remove FunctionType (#2510)
Function signatures were previously redundantly stored on Function objects as well as on FunctionType objects. These two signature representations had to always be kept in sync, which was error-prone and needlessly complex. This PR takes advantage of the new ability of Type to represent multiple value types by consolidating function signatures as a pair of Types (params and results) stored on the Function object. Since there are no longer module-global named function types, significant changes had to be made to the printing and emitting of function types, as well as their parsing and manipulation in various passes. The C and JS APIs and their tests also had to be updated to remove named function types.
Diffstat (limited to 'src/wasm-builder.h')
-rw-r--r--src/wasm-builder.h35
1 files changed, 14 insertions, 21 deletions
diff --git a/src/wasm-builder.h b/src/wasm-builder.h
index 533f83d94..22fa0e642 100644
--- a/src/wasm-builder.h
+++ b/src/wasm-builder.h
@@ -43,15 +43,13 @@ public:
// make* functions, other globals
Function* makeFunction(Name name,
- std::vector<Type>&& params,
- Type resultType,
+ Signature sig,
std::vector<Type>&& vars,
Expression* body = nullptr) {
auto* func = new Function;
func->name = name;
- func->result = resultType;
+ func->sig = sig;
func->body = body;
- func->params.swap(params);
func->vars.swap(vars);
return func;
}
@@ -63,14 +61,15 @@ public:
Expression* body = nullptr) {
auto* func = new Function;
func->name = name;
- func->result = resultType;
func->body = body;
+ std::vector<Type> paramVec;
for (auto& param : params) {
- func->params.push_back(param.type);
+ paramVec.push_back(param.type);
Index index = func->localNames.size();
func->localIndices[param.name] = index;
func->localNames[index] = param.name;
}
+ func->sig = Signature(Type(paramVec), resultType);
for (auto& var : vars) {
func->vars.push_back(var.type);
Index index = func->localNames.size();
@@ -210,27 +209,19 @@ public:
call->finalize();
return call;
}
- CallIndirect* makeCallIndirect(FunctionType* type,
- Expression* target,
+ CallIndirect* makeCallIndirect(Expression* target,
const std::vector<Expression*>& args,
- bool isReturn = false) {
- return makeCallIndirect(type->name, target, args, type->result, isReturn);
- }
- CallIndirect* makeCallIndirect(Name fullType,
- Expression* target,
- const std::vector<Expression*>& args,
- Type type,
+ Signature sig,
bool isReturn = false) {
auto* call = allocator.alloc<CallIndirect>();
- call->fullType = fullType;
- call->type = type;
+ call->sig = sig;
+ call->type = sig.results;
call->target = target;
call->operands.set(args);
call->isReturn = isReturn;
call->finalize();
return call;
}
- // FunctionType
LocalGet* makeLocalGet(Index index, Type type) {
auto* ret = allocator.alloc<LocalGet>();
ret->index = index;
@@ -582,9 +573,11 @@ public:
static Index addParam(Function* func, Name name, Type type) {
// only ok to add a param if no vars, otherwise indices are invalidated
- assert(func->localIndices.size() == func->params.size());
+ assert(func->localIndices.size() == func->sig.params.size());
assert(name.is());
- func->params.push_back(type);
+ std::vector<Type> params = func->sig.params.expand();
+ params.push_back(type);
+ func->sig.params = Type(params);
Index index = func->localNames.size();
func->localIndices[name] = index;
func->localNames[index] = name;
@@ -613,7 +606,7 @@ public:
}
static void clearLocals(Function* func) {
- func->params.clear();
+ func->sig.params = Type::none;
func->vars.clear();
clearLocalNames(func);
}