From 0b5d70e43b4b984ed7a25cf16ee2ccece3812dbf Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 18 Apr 2016 15:54:55 -0700 Subject: fix br_table order of evaluation, the value is first --- src/wasm-interpreter.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/wasm-interpreter.h') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 8f3f09ed1..c57c764e4 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -292,24 +292,23 @@ private: } Flow visitSwitch(Switch *curr) { NOTE_ENTER("Switch"); - Flow flow = visit(curr->condition); - if (flow.breaking()) return flow; - NOTE_EVAL1(flow.value); - int64_t index = flow.value.getInteger(); - + Flow flow; + Literal value; if (curr->value) { flow = visit(curr->value); if (flow.breaking()) return flow; - NOTE_EVAL1(flow.value); - } else { - flow = Flow(); + value = flow.value; + NOTE_EVAL1(value); } - + flow = visit(curr->condition); + if (flow.breaking()) return flow; + int64_t index = flow.value.getInteger(); Name target = curr->default_; if (index >= 0 && (size_t)index < curr->targets.size()) { target = curr->targets[(size_t)index]; } flow.breakTo = target; + flow.value = value; return flow; } -- cgit v1.2.3 From f0f98a3480394495a11d73c74ea81808bea44530 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 18 Apr 2016 16:00:12 -0700 Subject: update MemorySize => CurrentMemory --- src/passes/Print.cpp | 2 +- src/s2wasm.h | 2 +- src/wasm-binary.h | 10 +++++----- src/wasm-interpreter.h | 2 +- src/wasm-s-parser.h | 6 +----- src/wasm.h | 4 ++-- 6 files changed, 11 insertions(+), 15 deletions(-) (limited to 'src/wasm-interpreter.h') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index aa533849f..ddeec3dce 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -383,7 +383,7 @@ struct PrintSExpression : public Visitor { void visitHost(Host *curr) { switch (curr->op) { case PageSize: printOpening(o, "pagesize") << ')'; break; - case MemorySize: printOpening(o, "memory_size") << ')'; break; + case CurrentMemory: printOpening(o, "current_memory") << ')'; break; case GrowMemory: { printOpening(o, "grow_memory"); incIndent(); diff --git a/src/s2wasm.h b/src/s2wasm.h index ff3c1f29f..d0dbe8c6a 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -1066,7 +1066,7 @@ class S2WasmBuilder { } else if (match("unreachable")) { addToBlock(allocator.alloc()); } else if (match("memory_size")) { - makeHost(MemorySize); + makeHost(CurrentMemory); } else if (match("grow_memory")) { makeHost1(GrowMemory); } else if (match(".Lfunc_end")) { diff --git a/src/wasm-binary.h b/src/wasm-binary.h index db2c0d71d..08dafc563 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -237,7 +237,7 @@ enum FunctionEntry { }; enum ASTNodes { - MemorySize = 0x3b, + CurrentMemory = 0x3b, GrowMemory = 0x39, I32Add = 0x40, I32Sub = 0x41, @@ -1097,8 +1097,8 @@ public: void visitHost(Host *curr) { if (debug) std::cerr << "zz node: Host" << std::endl; switch (curr->op) { - case MemorySize: { - o << int8_t(BinaryConsts::MemorySize); + case CurrentMemory: { + o << int8_t(BinaryConsts::CurrentMemory); break; } case GrowMemory: { @@ -1943,8 +1943,8 @@ public: } bool maybeVisitImpl(Host *curr, uint8_t code) { switch (code) { - case BinaryConsts::MemorySize: { - curr->op = MemorySize; + case BinaryConsts::CurrentMemory: { + curr->op = CurrentMemory; curr->type = i32; break; } diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index c57c764e4..61b67958f 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -604,7 +604,7 @@ private: NOTE_ENTER("Host"); switch (curr->op) { case PageSize: return Literal((int32_t)Memory::kPageSize); - case MemorySize: return Literal(int32_t(instance.memorySize * Memory::kPageSize)); + case CurrentMemory: return Literal(int32_t(instance.memorySize * Memory::kPageSize)); case GrowMemory: { Flow flow = visit(curr->operands[0]); if (flow.breaking()) return flow; diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index c1a1162e1..be3263312 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -623,7 +623,7 @@ public: if (id == CALL) return makeCall(s); if (id == CALL_IMPORT) return makeCallImport(s); if (id == CALL_INDIRECT) return makeCallIndirect(s); - } + } else if (str[1] == 'u') return makeHost(s, HostOp::CurrentMemory); abort_on(str); } case 'e': { @@ -647,10 +647,6 @@ public: if (str[1] == 'o') return makeLoop(s); abort_on(str); } - case 'm': { - if (str[1] == 'e') return makeHost(s, HostOp::MemorySize); - abort_on(str); - } case 'n': { if (str[1] == 'o') return allocator.alloc(); abort_on(str); diff --git a/src/wasm.h b/src/wasm.h index 93c9d8709..ee2f27388 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -709,7 +709,7 @@ enum BinaryOp { }; enum HostOp { - PageSize, MemorySize, GrowMemory, HasFeature + PageSize, CurrentMemory, GrowMemory, HasFeature }; // @@ -1041,7 +1041,7 @@ public: void finalize() { switch (op) { - case PageSize: case MemorySize: case HasFeature: { + case PageSize: case CurrentMemory: case HasFeature: { type = i32; break; } -- cgit v1.2.3 From 9f61ec61a3c46705ac0b81e87a591ae9e58d030c Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 18 Apr 2016 16:05:49 -0700 Subject: current_memory now returns in units of page size --- src/wasm-interpreter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/wasm-interpreter.h') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 61b67958f..60b3b966f 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -604,7 +604,7 @@ private: NOTE_ENTER("Host"); switch (curr->op) { case PageSize: return Literal((int32_t)Memory::kPageSize); - case CurrentMemory: return Literal(int32_t(instance.memorySize * Memory::kPageSize)); + case CurrentMemory: return Literal(int32_t(instance.memorySize)); case GrowMemory: { Flow flow = visit(curr->operands[0]); if (flow.breaking()) return flow; -- cgit v1.2.3 From d06406cc9d05e5654a3df73ab1d09252c774aadb Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 18 Apr 2016 16:07:08 -0700 Subject: grow_memory now returns in units of page size --- src/wasm-interpreter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/wasm-interpreter.h') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 60b3b966f..3d4eea722 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -616,7 +616,7 @@ private: if (newSize > instance.wasm.memory.max) trap("growMemory: exceeds max"); instance.externalInterface->growMemory(instance.memorySize * Memory::kPageSize, newSize * Memory::kPageSize); instance.memorySize = newSize; - return Literal(int32_t(ret * Memory::kPageSize)); + return Literal(int32_t(ret)); } case HasFeature: { IString id = curr->nameOperand; -- cgit v1.2.3