diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-04-26 10:06:27 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-04-26 10:06:27 -0700 |
commit | ea1d1e60d48159c15075fb86b7e442329101f79c (patch) | |
tree | bab414cd97f135f400f19348e3c01698a90336a3 /src | |
parent | 62ed39b5806e75c3c8835b6d996cd3b07a6cec23 (diff) | |
download | binaryen-ea1d1e60d48159c15075fb86b7e442329101f79c.tar.gz binaryen-ea1d1e60d48159c15075fb86b7e442329101f79c.tar.bz2 binaryen-ea1d1e60d48159c15075fb86b7e442329101f79c.zip |
emit ifs in an optimized way in binary format
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-binary.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 3ded58f40..ea57d5d3b 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -29,6 +29,7 @@ #include "shared-constants.h" #include "asm_v_wasm.h" #include "wasm-builder.h" +#include "ast_utils.h" namespace wasm { @@ -801,17 +802,30 @@ public: breakStack.pop_back(); o << int8_t(BinaryConsts::End); } + + // emits a node, but if it is a block with no name, emit a list of its contents + void recursePossibleBlockContents(Expression* curr) { + auto* block = curr->dynCast<Block>(); + if (!block || (block->name.is() && BreakSeeker::has(curr, block->name))) { + recurse(curr); + return; + } + for (auto* child : block->list) { + recurse(child); + } + } + void visitIf(If *curr) { if (debug) std::cerr << "zz node: If" << std::endl; recurse(curr->condition); o << int8_t(BinaryConsts::If); breakStack.push_back(IMPOSSIBLE_CONTINUE); // the binary format requires this; we have a block if we need one; TODO: optimize - recurse(curr->ifTrue); // TODO: emit block contents directly, if possible + recursePossibleBlockContents(curr->ifTrue); // TODO: emit block contents directly, if possible breakStack.pop_back(); if (curr->ifFalse) { o << int8_t(BinaryConsts::Else); breakStack.push_back(IMPOSSIBLE_CONTINUE); // TODO ditto - recurse(curr->ifFalse); + recursePossibleBlockContents(curr->ifFalse); breakStack.pop_back(); } o << int8_t(BinaryConsts::End); |