summaryrefslogtreecommitdiff
path: root/src/wasm2asm.h
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-07 21:25:14 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-03-07 21:25:14 -0800
commitbc74a6478aa229abf6dbf7269e67aeeb570e7554 (patch)
treef24fd1e1ed75184abd5d2710a93a4b9a889a3d94 /src/wasm2asm.h
parent8efa11fbb9ff8cfd8bacc9d16642e13e2bbac9b4 (diff)
parent9407880de631fb4e9f8caa0c746e4d39f40be91d (diff)
downloadbinaryen-bc74a6478aa229abf6dbf7269e67aeeb570e7554.tar.gz
binaryen-bc74a6478aa229abf6dbf7269e67aeeb570e7554.tar.bz2
binaryen-bc74a6478aa229abf6dbf7269e67aeeb570e7554.zip
Merge pull request #231 from WebAssembly/spec-updates
Spec updates
Diffstat (limited to 'src/wasm2asm.h')
-rw-r--r--src/wasm2asm.h38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h
index d8ac6376e..310ba4224 100644
--- a/src/wasm2asm.h
+++ b/src/wasm2asm.h
@@ -652,36 +652,24 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) {
}
Expression *defaultBody = nullptr; // default must be last in asm.js
Ref visitSwitch(Switch *curr) {
- Ref ret = ValueBuilder::makeLabel(fromName(curr->name), ValueBuilder::makeBlock());
- Ref value;
- if (isStatement(curr->value)) {
+ assert(!curr->value);
+ Ref ret = ValueBuilder::makeBlock();
+ Ref condition;
+ if (isStatement(curr->condition)) {
ScopedTemp temp(i32, parent);
- flattenAppend(ret[2], visit(curr->value, temp));
- value = temp.getAstName();
+ flattenAppend(ret[2], visit(curr->condition, temp));
+ condition = temp.getAstName();
} else {
- value = visit(curr->value, EXPRESSION_RESULT);
+ condition = visit(curr->condition, EXPRESSION_RESULT);
}
- Ref theSwitch = ValueBuilder::makeSwitch(value);
+ Ref theSwitch = ValueBuilder::makeSwitch(condition);
ret[2][1]->push_back(theSwitch);
- for (auto& c : curr->cases) {
- if (c.name == curr->default_) {
- defaultBody = c.body;
- continue;
- }
- bool added = false;
- for (size_t i = 0; i < curr->targets.size(); i++) {
- if (curr->targets[i] == c.name) {
- ValueBuilder::appendCaseToSwitch(theSwitch, ValueBuilder::makeNum(i));
- added = true;
- }
- }
- assert(added);
- ValueBuilder::appendCodeToSwitch(theSwitch, blockify(visit(c.body, NO_RESULT)), false);
- }
- if (defaultBody) {
- ValueBuilder::appendDefaultToSwitch(theSwitch);
- ValueBuilder::appendCodeToSwitch(theSwitch, blockify(visit(defaultBody, NO_RESULT)), false);
+ for (size_t i = 0; i < curr->targets.size(); i++) {
+ ValueBuilder::appendCaseToSwitch(theSwitch, ValueBuilder::makeNum(i));
+ ValueBuilder::appendCodeToSwitch(theSwitch, blockify(ValueBuilder::makeBreak(fromName(curr->targets[i]))), false);
}
+ ValueBuilder::appendDefaultToSwitch(theSwitch);
+ ValueBuilder::appendCodeToSwitch(theSwitch, blockify(ValueBuilder::makeBreak(fromName(curr->default_))), false);
return ret;
}