From 44e83f2fb039a38b0764a172aa7c64ec3290d8c5 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 1 Nov 2015 15:31:00 -0800 Subject: remove condition from break --- src/asm2wasm.h | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/asm2wasm.h') diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 356077460..3a8d3d579 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -836,7 +836,6 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { needTopmost = true; auto ret = allocator.alloc(); ret->name = TOPMOST; - ret->condition = nullptr; ret->value = !!ast[1] ? process(ast[1]) : nullptr; return ret; } else if (what == BLOCK) { @@ -845,14 +844,12 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { auto ret = allocator.alloc(); assert(breakStack.size() > 0); ret->name = !!ast[1] ? getBreakLabelName(ast[1]->getIString()) : breakStack.back(); - ret->condition = nullptr; ret->value = nullptr; return ret; } else if (what == CONTINUE) { auto ret = allocator.alloc(); assert(continueStack.size() > 0); ret->name = !!ast[1] ? getContinueLabelName(ast[1]->getIString()) : continueStack.back(); - ret->condition = nullptr; ret->value = nullptr; return ret; } else if (what == WHILE) { @@ -874,12 +871,15 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { if (forever) { ret->body = process(ast[2]); } else { - Break *continueWhile = allocator.alloc(); - continueWhile->name = in; - continueWhile->condition = process(ast[1]); - continueWhile->value = nullptr; + Break *breakOut = allocator.alloc(); + breakOut->name = in; + breakOut->value = nullptr; + If *condition = allocator.alloc(); + condition->condition = process(ast[1]); + condition->ifTrue = breakOut; + condition->ifFalse = nullptr; auto body = allocator.alloc(); - body->list.push_back(continueWhile); + body->list.push_back(condition); body->list.push_back(process(ast[2])); ret->body = body; } @@ -923,16 +923,19 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) { ret->body = process(ast[2]); continueStack.pop_back(); breakStack.pop_back(); - Break *continueIf = allocator.alloc(); - continueIf->name = in; - continueIf->condition = process(ast[1]); - continueIf->value = nullptr; + Break *continueIn = allocator.alloc(); + continueIn->name = in; + continueIn->value = nullptr; + If *condition = allocator.alloc(); + condition->condition = process(ast[1]); + condition->ifTrue = continueIn; + condition->ifFalse = nullptr; if (Block *block = ret->body->dyn_cast()) { - block->list.push_back(continueIf); + block->list.push_back(condition); } else { auto newBody = allocator.alloc(); newBody->list.push_back(ret->body); - newBody->list.push_back(continueIf); + newBody->list.push_back(condition); ret->body = newBody; } return ret; @@ -1054,7 +1057,6 @@ void Asm2WasmBuilder::optimize() { // look in the child's children to see if there are more uses of this name BreakSeeker breakSeeker(curr->name); - breakSeeker.walk(child->condition); breakSeeker.walk(child->value); if (breakSeeker.found == 0) return child->value; -- cgit v1.2.3