diff options
-rw-r--r-- | src/asm2wasm.h | 11 | ||||
-rw-r--r-- | test/unit.asm.js | 16 | ||||
-rw-r--r-- | test/unit.wast | 38 |
3 files changed, 62 insertions, 3 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 577b3f717..c3439800a 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -646,7 +646,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { IStringSet functionVariables; // params or locals - IString parentLabel; // set in LABEL, then read in WHILE/DO + IString parentLabel; // set in LABEL, then read in WHILE/DO/SWITCH std::vector<IString> breakStack; // where a break will go std::vector<IString> continueStack; // where a continue will go @@ -1212,8 +1212,13 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { ret->type = ret->list[1]->type; return ret; } else if (what == SWITCH) { - // XXX switch is still in flux in the spec repo, just emit a placeholder - IString name = getNextId("switch"); + IString name; + if (!parentLabel.isNull()) { + name = getBreakLabelName(parentLabel); + parentLabel = IString(); + } else { + name = getNextId("switch"); + } breakStack.push_back(name); auto ret = allocator.alloc<Switch>(); ret->name = name; diff --git a/test/unit.asm.js b/test/unit.asm.js index ed52e515b..49e912ae1 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -57,6 +57,22 @@ function () { case 12: return 121; case 5: return 51; } + Lout: switch (x | 0) { + case 12: break; + case 10: break Lout; + case 5: { + while (1) { + break; + } + break; + } + case 2: { + while (1) { + break Lout; + } + break; + } + } } function frem() { return +(5.5 % 1.2); diff --git a/test/unit.wast b/test/unit.wast index 9ebf440be..88f2de77b 100644 --- a/test/unit.wast +++ b/test/unit.wast @@ -208,6 +208,44 @@ (nop) ) ) + (tableswitch $label$break$Lout + (i32.sub + (get_local $x) + (i32.const 2) + ) + (table (case $switch-case$15) (case $switch-default$16) (case $switch-default$16) (case $switch-case$12) (case $switch-default$16) (case $switch-default$16) (case $switch-default$16) (case $switch-default$16) (case $switch-case$9) (case $switch-default$16) (case $switch-case$8)) (case $switch-default$16) + (case switch-case$8 + (br $label$break$Lout + ) + ) + (case switch-case$9 + (br $label$break$Lout + ) + ) + (case switch-case$12 + (block + (loop $while-out$10 $while-in$11 + (br $while-out$10 + ) + ) + (br $label$break$Lout + ) + ) + ) + (case switch-case$15 + (block + (loop $while-out$13 $while-in$14 + (br $label$break$Lout + ) + ) + (br $label$break$Lout + ) + ) + ) + (case switch-default$16 + (nop) + ) + ) ) ) (func $frem (result f64) |