summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/s2wasm.h11
-rw-r--r--test/dot_s/basics.wast2
2 files changed, 9 insertions, 4 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index a04ab65bd..9766471f7 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -279,6 +279,7 @@ private:
typedef std::pair<Const*, Name> Addressing;
std::vector<Addressing> addressings;
std::vector<Block*> loopBlocks; // we need to clear their names
+ std::set<Name> seenLabels; // if we already used a label, we don't need it in a loop (there is a block above it, with that label)
// main loop
while (1) {
skipWhitespace();
@@ -354,6 +355,7 @@ private:
curr->name = getStr();
bstack.back()->list.push_back(curr);
bstack.push_back(curr);
+ seenLabels.insert(curr->name);
} else if (match("BB")) {
s -= 2;
Name name = getStrToColon();
@@ -373,11 +375,14 @@ private:
if (*s == 'l') {
auto curr = allocator.alloc<Loop>();
bstack.back()->list.push_back(curr);
- curr->out = name;
+ curr->in = name;
mustMatch("loop");
- curr->in = getStr();
+ Name out = getStr();
+ if (seenLabels.count(out) == 0) {
+ curr->out = out;
+ }
auto block = allocator.alloc<Block>();
- block->name = curr->in; // temporary, fake
+ block->name = out; // temporary, fake
curr->body = block;
loopBlocks.push_back(block);
bstack.push_back(block);
diff --git a/test/dot_s/basics.wast b/test/dot_s/basics.wast
index db607575e..29001914b 100644
--- a/test/dot_s/basics.wast
+++ b/test/dot_s/basics.wast
@@ -30,7 +30,7 @@
)
$BB0_4
)
- (loop $BB0_1 $BB0_4
+ (loop $BB0_1
(block
(set_local $$0
(i32.add