diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-01-20 10:35:49 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-01-20 10:35:49 -0800 |
commit | 64923a04cf9795482cc55264b75d1294c32a007d (patch) | |
tree | 8c2413b9c11ea8c5f4653a718e7214bc5877a700 /src | |
parent | 960043a359046b1536c75aeca2f7092e15714d45 (diff) | |
download | binaryen-64923a04cf9795482cc55264b75d1294c32a007d.tar.gz binaryen-64923a04cf9795482cc55264b75d1294c32a007d.tar.bz2 binaryen-64923a04cf9795482cc55264b75d1294c32a007d.zip |
improve wasm2asm switch emitting, and add testcase
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm2asm.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h index f1a58e170..ad73159e6 100644 --- a/src/wasm2asm.h +++ b/src/wasm2asm.h @@ -645,6 +645,7 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { ret[1]->push_back(theBreak); return ret; } + 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; @@ -658,6 +659,10 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { Ref theSwitch = ValueBuilder::makeSwitch(value); 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) { @@ -665,13 +670,13 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) { added = true; } } - if (c.name == curr->default_) { - ValueBuilder::appendDefaultToSwitch(theSwitch); - 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); + } return ret; } |