From 944b56ad5d6a0f0df040cac684109a5e3f50f653 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 12 Jan 2016 11:40:42 -0800 Subject: fix some macros in wasm-as --- src/wasm-binary.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 1f6b5b0e4..16e24fcb8 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -712,6 +712,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 +720,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 +728,7 @@ public: case f64: o << int8_t(BinaryConsts::F64##code); break; \ default: abort(); \ } \ + break; \ } switch (curr->op) { -- cgit v1.2.3 From e404e460b93eb8aee8995827dfbe29840315a572 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 12 Jan 2016 11:53:45 -0800 Subject: implement switch in wasm-as --- src/wasm-binary.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 16e24fcb8..79742a414 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -554,8 +554,18 @@ public: } 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 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)); -- cgit v1.2.3 From 860d56e5c724d32ce8cc890ff97a02dbdf379259 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 12 Jan 2016 11:56:12 -0800 Subject: implement br_if in wasm-as --- src/wasm-binary.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/wasm-binary.h') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 79742a414..9accbfbc0 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -543,14 +543,14 @@ 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()) -- cgit v1.2.3