diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-01-12 13:23:54 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-01-12 13:23:54 -0800 |
commit | c54dadc397030412b566bfa1e1d80eb65be0aa23 (patch) | |
tree | 44956259a59167c3c94d1c99cf16a8b4bce373d3 /src/wasm-binary.h | |
parent | 2e5363210f7ef4861bf734e89fef96176b4157bc (diff) | |
parent | 7daceb70fd2b97751d47fa9b792a0ba7bb846284 (diff) | |
download | binaryen-c54dadc397030412b566bfa1e1d80eb65be0aa23.tar.gz binaryen-c54dadc397030412b566bfa1e1d80eb65be0aa23.tar.bz2 binaryen-c54dadc397030412b566bfa1e1d80eb65be0aa23.zip |
Merge pull request #98 from WebAssembly/wasm-as_testing
wasm-as testing
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 1f6b5b0e4..9accbfbc0 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -543,19 +543,29 @@ public: breakStack.pop_back(); } void visitBreak(Break *curr) { - o << int8_t(BinaryConsts::Br); + o << int8_t(curr->condition ? BinaryConsts::BrIf : BinaryConsts::Br); for (int i = breakStack.size() - 1; i >= 0; i--) { if (breakStack[i] == curr->name) { o << int8_t(breakStack.size() - 1 - i); return; } } - abort(); + if (curr->condition) visit(curr->condition); } void visitSwitch(Switch *curr) { o << int8_t(BinaryConsts::TableSwitch) << int16_t(curr->cases.size()) - << int16_t(curr->targets.size()); - abort(); // WTF + << int16_t(curr->targets.size()); + std::map<Name, int16_t> mapping; // target name => index in cases + for (size_t i = 0; i < curr->cases.size(); i++) { + mapping[curr->cases[i].name] = i; + } + for (auto target : curr->targets) { + o << mapping[target]; + } + visit(curr->value); + for (auto c : curr->cases) { + visit(c.body); + } } void visitCall(Call *curr) { o << int8_t(BinaryConsts::CallFunction) << LEB128(getFunctionIndex(curr->target)); @@ -712,6 +722,7 @@ public: case f64: o << int8_t(BinaryConsts::F64##code); break; \ default: abort(); \ } \ + break; \ } #define INT_TYPED_CODE(code) { \ switch (curr->left->type) { \ @@ -719,6 +730,7 @@ public: case i64: o << int8_t(BinaryConsts::I64##code); break; \ default: abort(); \ } \ + break; \ } #define FLOAT_TYPED_CODE(code) { \ switch (curr->left->type) { \ @@ -726,6 +738,7 @@ public: case f64: o << int8_t(BinaryConsts::F64##code); break; \ default: abort(); \ } \ + break; \ } switch (curr->op) { |