summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2019-04-17 17:03:36 -0700
committerGitHub <noreply@github.com>2019-04-17 17:03:36 -0700
commitc7712d3757461da036f9c7714cec372d584733e3 (patch)
tree58e87de7eaa1ad2bba4cd99dfc0483c788af59be /src
parentaaf1c43f10cb703c9f926ddcb5aa2e728b651e07 (diff)
downloadbinaryen-c7712d3757461da036f9c7714cec372d584733e3.tar.gz
binaryen-c7712d3757461da036f9c7714cec372d584733e3.tar.bz2
binaryen-c7712d3757461da036f9c7714cec372d584733e3.zip
wasm2js: fix br_table to loop (#2018)
Diffstat (limited to 'src')
-rw-r--r--src/wasm2js.h20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/wasm2js.h b/src/wasm2js.h
index 3c868e8dd..927dbac24 100644
--- a/src/wasm2js.h
+++ b/src/wasm2js.h
@@ -973,6 +973,14 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Function* func, IString resul
return ValueBuilder::makeLabel(fromName(asmLabel, NameScope::Label), ret);
}
+ Ref makeBreakOrContinue(Name name) {
+ if (continueLabels.count(name)) {
+ return ValueBuilder::makeContinue(fromName(name, NameScope::Label));
+ } else {
+ return ValueBuilder::makeBreak(fromName(name, NameScope::Label));
+ }
+ }
+
Ref visitBreak(Break* curr) {
if (curr->condition) {
// we need an equivalent to an if here, so use that code
@@ -983,13 +991,7 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Function* func, IString resul
fakeIf.ifTrue = &fakeBreak;
return visit(&fakeIf, result);
}
- Ref theBreak;
- auto iter = continueLabels.find(curr->name);
- if (iter == continueLabels.end()) {
- theBreak = ValueBuilder::makeBreak(fromName(curr->name, NameScope::Label));
- } else {
- theBreak = ValueBuilder::makeContinue(fromName(curr->name, NameScope::Label));
- }
+ Ref theBreak = makeBreakOrContinue(curr->name);
if (!curr->value) return theBreak;
// generate the value, including assigning to the result, and then do the break
Ref ret = visitAndAssign(curr->value, breakResults[curr->name]);
@@ -1016,10 +1018,10 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m, Function* func, IString resul
ret[1]->push_back(theSwitch);
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], NameScope::Label))), false);
+ ValueBuilder::appendCodeToSwitch(theSwitch, blockify(makeBreakOrContinue(curr->targets[i])), false);
}
ValueBuilder::appendDefaultToSwitch(theSwitch);
- ValueBuilder::appendCodeToSwitch(theSwitch, blockify(ValueBuilder::makeBreak(fromName(curr->default_, NameScope::Label))), false);
+ ValueBuilder::appendCodeToSwitch(theSwitch, blockify(makeBreakOrContinue(curr->default_)), false);
return ret;
}