Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Unified Diff: test/unittests/wasm/ast-decoder-unittest.cc

Issue 2135693002: [wasm] Add a BytecodeIterator and use in non-performance-critical situations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add C++ iterator Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/wasm-interpreter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/wasm/ast-decoder-unittest.cc
diff --git a/test/unittests/wasm/ast-decoder-unittest.cc b/test/unittests/wasm/ast-decoder-unittest.cc
index 889cfb1b1a3ed1695f729675aafc22a5f5acd37f..05a0e95f6a73e5c87a644d1a1f2a5c88eebc497e 100644
--- a/test/unittests/wasm/ast-decoder-unittest.cc
+++ b/test/unittests/wasm/ast-decoder-unittest.cc
@@ -2437,6 +2437,60 @@ TEST_F(LocalDeclDecoderTest, UseEncoder) {
pos = ExpectRun(map, pos, kAstI64, 212);
}
+class BytecodeIteratorTest : public TestWithZone {};
+
+TEST_F(BytecodeIteratorTest, SimpleForeach) {
+ byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
+ BytecodeIterator iter(code, code + sizeof(code));
+ WasmOpcode expected[] = {kExprI8Const, kExprIf, kExprI8Const,
+ kExprElse, kExprI8Const, kExprEnd};
+ size_t pos = 0;
+ for (WasmOpcode opcode : iter) {
+ if (pos >= arraysize(expected)) {
+ EXPECT_TRUE(false);
ahaas 2016/07/11 12:31:19 why don't you say EXPECT_TRUE(pos < arraysize(exp
+ break;
+ }
+ EXPECT_EQ(expected[pos++], opcode);
+ }
+ EXPECT_EQ(arraysize(expected), pos);
+}
+
+TEST_F(BytecodeIteratorTest, ForeachTwice) {
+ byte code[] = {WASM_IF_ELSE(WASM_ZERO, WASM_ZERO, WASM_ZERO)};
+ BytecodeIterator iter(code, code + sizeof(code));
+ int count = 0;
+
+ count = 0;
+ for (WasmOpcode opcode : iter) {
+ USE(opcode);
+ count++;
+ }
+ EXPECT_EQ(6, count);
+
+ count = 0;
+ for (WasmOpcode opcode : iter) {
+ USE(opcode);
+ count++;
+ }
+ EXPECT_EQ(6, count);
+}
+
+TEST_F(BytecodeIteratorTest, WithAstDecls) {
+ byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)};
+ AstLocalDecls decls(zone());
+ BytecodeIterator iter(code, code + sizeof(code), &decls);
+
+ EXPECT_EQ(3, decls.decls_encoded_size);
+ EXPECT_EQ(3, iter.pc_offset());
+ EXPECT_TRUE(iter.has_next());
+ EXPECT_EQ(kExprI8Const, iter.current());
+ iter.next();
+ EXPECT_TRUE(iter.has_next());
+ EXPECT_EQ(kExprI8Const, iter.current());
+ iter.next();
+ EXPECT_FALSE(iter.has_next());
+}
+
} // namespace wasm
} // namespace internal
} // namespace v8
« no previous file with comments | « src/wasm/wasm-interpreter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698