diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-08-17 19:50:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-17 10:50:37 -0700 |
commit | 0fdbb1d33810d84bbd9a408b3486bff0d9015989 (patch) | |
tree | 54a0955fa5b4640ab0b7538a7c5ba96578de6b7d /src/wasm2js.h | |
parent | 5f992018bf0e80a430d9a0169c7f8048e0a98b2b (diff) | |
download | binaryen-0fdbb1d33810d84bbd9a408b3486bff0d9015989.tar.gz binaryen-0fdbb1d33810d84bbd9a408b3486bff0d9015989.tar.bz2 binaryen-0fdbb1d33810d84bbd9a408b3486bff0d9015989.zip |
Prepare for compound types that are single but not basic (#3046)
As a follow-up to https://github.com/WebAssembly/binaryen/pull/3012#pullrequestreview-459686171 this PR prepares for the new compound Signature, Struct and Array types that are single but not basic.
This includes:
* Renames `Type::getSingle` to `Type::getBasic` (NFC). Previously, its name was not representing its implementation (`isSingle` excluded `none` and `unreachable` while `getSingle` didn't, i.e. `getSingle` really was `getBasic`). Note that a hypothetical `Type::getSingle` cannot return `ValueType` anyway (new compound types are single but don't map to `ValueType`), so I figured it's best to skip implementing it until we actually need it.
* Marks locations where we are (still) assuming that all single types are basic types, as suggested in https://github.com/WebAssembly/binaryen/pull/3012#discussion_r465356708, but using a macro, so we get useful errors once we start implementing the new types and can quickly traverse the affected locations.
The macro is added where
* there used to be a `switch (type.getSingle())` or similar that handled any basic type (NFC), but in the future will also have to handle single types that are not basic types.
* we are not dealing with `Unary`, `Binary`, `Load`, `Store` or `AtomicXY` instructions, since these don't deal with compound types anyway.
Diffstat (limited to 'src/wasm2js.h')
-rw-r--r-- | src/wasm2js.h | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h index 8d233eb95..c06d90180 100644 --- a/src/wasm2js.h +++ b/src/wasm2js.h @@ -151,11 +151,12 @@ public: // Get a temp var. IString getTemp(Type type, Function* func) { IString ret; - if (frees[type.getSingle()].size() > 0) { - ret = frees[type.getSingle()].back(); - frees[type.getSingle()].pop_back(); + TODO_SINGLE_COMPOUND(type); + if (frees[type.getBasic()].size() > 0) { + ret = frees[type.getBasic()].back(); + frees[type.getBasic()].pop_back(); } else { - size_t index = temps[type.getSingle()]++; + size_t index = temps[type.getBasic()]++; ret = IString((std::string("wasm2js_") + type.toString() + "$" + std::to_string(index)) .c_str(), @@ -169,7 +170,8 @@ public: // Free a temp var. void freeTemp(Type type, IString temp) { - frees[type.getSingle()].push_back(temp); + TODO_SINGLE_COMPOUND(type); + frees[type.getBasic()].push_back(temp); } // Generates a mangled name from `name` within the specified scope. @@ -639,7 +641,8 @@ void Wasm2JSBuilder::addExports(Ref ast, Module* wasm) { void Wasm2JSBuilder::addGlobal(Ref ast, Global* global) { if (auto* const_ = global->init->dynCast<Const>()) { Ref theValue; - switch (const_->type.getSingle()) { + TODO_SINGLE_COMPOUND(const_->type); + switch (const_->type.getBasic()) { case Type::i32: { theValue = ValueBuilder::makeInt(const_->value.geti32()); break; @@ -656,7 +659,9 @@ void Wasm2JSBuilder::addGlobal(Ref ast, Global* global) { ValueBuilder::makeDouble(const_->value.getf64()), ASM_DOUBLE); break; } - default: { assert(false && "Top const type not supported"); } + default: { + assert(false && "Top const type not supported"); + } } Ref theVar = ValueBuilder::makeVar(); ast->push_back(theVar); @@ -1240,7 +1245,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, // normal load Ref ptr = makePointer(curr->ptr, curr->offset); Ref ret; - switch (curr->type.getSingle()) { + switch (curr->type.getBasic()) { case Type::i32: { switch (curr->bytes) { case 1: @@ -1343,7 +1348,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Ref ptr = makePointer(curr->ptr, curr->offset); Ref value = visit(curr->value, EXPRESSION_RESULT); Ref ret; - switch (curr->valueType.getSingle()) { + switch (curr->valueType.getBasic()) { case Type::i32: { switch (curr->bytes) { case 1: @@ -1391,7 +1396,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Ref visitDrop(Drop* curr) { return visit(curr->value, NO_RESULT); } Ref visitConst(Const* curr) { - switch (curr->type.getSingle()) { + switch (curr->type.getBasic()) { case Type::i32: return ValueBuilder::makeInt(curr->value.geti32()); // An i64 argument translates to two actual arguments to asm.js @@ -1431,7 +1436,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Ref visitUnary(Unary* curr) { // normal unary - switch (curr->type.getSingle()) { + switch (curr->type.getBasic()) { case Type::i32: { switch (curr->op) { case ClzInt32: { @@ -1612,7 +1617,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Ref left = visit(curr->left, EXPRESSION_RESULT); Ref right = visit(curr->right, EXPRESSION_RESULT); Ref ret; - switch (curr->type.getSingle()) { + switch (curr->type.getBasic()) { case Type::i32: { switch (curr->op) { case AddInt32: |