diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-10-29 17:32:59 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-10-29 17:32:59 -0700 |
commit | ec5e1d0ffdc2769d754cc7c679c3b286f787bb6e (patch) | |
tree | f39eabfff65a2299429d2523c0fef074c647f0a6 /src/asm2wasm.cpp | |
parent | d93c05bfa9a7fc813c31c7972e6680d6ef0277d2 (diff) | |
download | binaryen-ec5e1d0ffdc2769d754cc7c679c3b286f787bb6e.tar.gz binaryen-ec5e1d0ffdc2769d754cc7c679c3b286f787bb6e.tar.bz2 binaryen-ec5e1d0ffdc2769d754cc7c679c3b286f787bb6e.zip |
don't emit empty blocks
Diffstat (limited to 'src/asm2wasm.cpp')
-rw-r--r-- | src/asm2wasm.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/asm2wasm.cpp b/src/asm2wasm.cpp index ef43a6ac2..3f6173adf 100644 --- a/src/asm2wasm.cpp +++ b/src/asm2wasm.cpp @@ -1093,7 +1093,10 @@ Function* Asm2WasmModule::processFunction(Ref ast) { abort_on("bad processUnshifted", ptr); }; - processStatements = [&](Ref ast, unsigned from) { + processStatements = [&](Ref ast, unsigned from) -> Expression* { + unsigned size = ast->size() - from; + if (size == 0) return allocator.alloc<Nop>(); + if (size == 1) return process(ast[from]); auto block = allocator.alloc<Block>(); for (unsigned i = from; i < ast->size(); i++) { block->list.push_back(process(ast[i])); @@ -1104,7 +1107,12 @@ Function* Asm2WasmModule::processFunction(Ref ast) { function->body = processStatements(body, start); if (needTopmost) { Block* topmost = dynamic_cast<Block*>(function->body); - assert(topmost); + // if there's no block there, or there is a block but it already has a var, we need a new block. + if (!topmost || topmost->var.is()) { + topmost = allocator.alloc<Block>(); + topmost->list.push_back(function->body); + function->body = topmost; + } topmost->var = TOPMOST; } // cleanups/checks |