summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/LowerCase.cpp105
-rw-r--r--src/passes/NameManager.cpp1
-rw-r--r--src/passes/Print.cpp27
-rw-r--r--src/passes/RemoveUnusedNames.cpp7
4 files changed, 14 insertions, 126 deletions
diff --git a/src/passes/LowerCase.cpp b/src/passes/LowerCase.cpp
deleted file mode 100644
index c0ab8d235..000000000
--- a/src/passes/LowerCase.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2016 WebAssembly Community Group participants
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//
-// Lowers switch cases out into blocks,
-//
-/*
- (tableswitch $switch$0
- (i32.sub
- (get_local $x)
- (i32.const 1)
- )
- (table (case $switch-case$1) (case $switch-case$2)) (case $switch-default$3)
- (case $switch-case$1
- (return
- (i32.const 1)
- )
- )
- (case $switch-case$2
- (return
- (i32.const 2)
- )
- )
- (case $switch-default$3
- (nop)
- )
- )
-
- into
-
- (block $forswitch$switch$0
- (block $switch-case$3
- (block $switch-case$2
- (block $switch-case$1
- (tableswitch $switch$0
- (i32.sub
- (get_local $x)
- (i32.const 1)
- )
- (table (br $switch-case$1) (br $switch-case$2)) (br $switch-default$3)
- )
- )
- (return
- (i32.const 1)
- )
- )
- (return
- (i32.const 2)
- )
- )
- (nop)
- )
-*/
-
-
-#include <memory>
-
-#include <wasm.h>
-#include <pass.h>
-
-namespace wasm {
-
-struct LowerCase : public WalkerPass<WasmWalker<LowerCase, void>> {
- MixedArena* allocator;
-
- void prepare(PassRunner* runner, Module *module) override {
- allocator = runner->allocator;
- }
-
- void visitSwitch(Switch *curr) {
- if (curr->cases.size() == 0) return;
- auto top = allocator->alloc<Block>();
- top->list.push_back(curr);
- top->finalize();
- for (auto& c : curr->cases) {
- top->name = c.name;
- auto next = allocator->alloc<Block>();
- next->list.push_back(top);
- next->list.push_back(c.body);
- next->finalize();
- top = next;
- }
- curr->cases.clear();
- top->name = curr->name;
- curr->name = Name();
- replaceCurrent(top);
- }
-};
-
-static RegisterPass<LowerCase> registerPass("lower-case", "lowers cases into blocks");
-
-} // namespace wasm
diff --git a/src/passes/NameManager.cpp b/src/passes/NameManager.cpp
index 8ed29c478..8519d70eb 100644
--- a/src/passes/NameManager.cpp
+++ b/src/passes/NameManager.cpp
@@ -44,7 +44,6 @@ void NameManager::visitBreak(Break* curr) {
names.insert(curr->name);
}
void NameManager::visitSwitch(Switch* curr) {
- names.insert(curr->name);
names.insert(curr->default_);
for (auto& target : curr->targets) {
names.insert(target);
diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp
index e8e917a6e..91c4040f6 100644
--- a/src/passes/Print.cpp
+++ b/src/passes/Print.cpp
@@ -125,29 +125,16 @@ struct PrintSExpression : public WasmVisitor<PrintSExpression, void> {
decIndent();
}
void visitSwitch(Switch *curr) {
- printOpening(o, "tableswitch ");
- if (curr->name.is()) o << curr->name;
- incIndent();
- printFullLine(curr->value);
- doIndent(o, indent) << "(table";
- std::set<Name> caseNames;
- for (auto& c : curr->cases) {
- caseNames.insert(c.name);
- }
+ printOpening(o, "br_table");
for (auto& t : curr->targets) {
- o << maybeSpace << "(" << (caseNames.count(t) == 0 ? "br" : "case") << " " << (t.is() ? t : curr->default_) << ")";
+ o << " " << t;
}
- o << ")";
- if (curr->default_.is()) o << " (" << (caseNames.count(curr->default_) == 0 ? "br" : "case") << " " << curr->default_ << ")";
- o << maybeNewLine;
- for (auto& c : curr->cases) {
- doIndent(o, indent);
- printMinorOpening(o, "case ") << c.name;
- incIndent();
- printFullLine(c.body);
- decIndent();
- o << maybeNewLine;
+ o << " " << curr->default_;
+ incIndent();
+ if (curr->value) {
+ printFullLine(curr->value);
}
+ printFullLine(curr->condition);
decIndent();
}
diff --git a/src/passes/RemoveUnusedNames.cpp b/src/passes/RemoveUnusedNames.cpp
index 6929aa671..a8beaa15e 100644
--- a/src/passes/RemoveUnusedNames.cpp
+++ b/src/passes/RemoveUnusedNames.cpp
@@ -38,6 +38,13 @@ struct RemoveUnusedNames : public WalkerPass<WasmWalker<RemoveUnusedNames>> {
}
}
+ void visitSwitch(Switch *curr) {
+ for (auto name : curr->targets) {
+ branchesSeen.insert(name);
+ }
+ branchesSeen.insert(curr->default_);
+ }
+
void visitFunction(Function *curr) {
branchesSeen.clear();
}