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

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

Issue 1972153002: [wasm] Implement an interpreter for WASM. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « test/unittests/unittests.gyp ('k') | test/unittests/wasm/control-transfer-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 LocalDeclEncoder local_decls; 75 LocalDeclEncoder local_decls;
76 76
77 void AddLocals(LocalType type, uint32_t count) { 77 void AddLocals(LocalType type, uint32_t count) {
78 local_decls.AddLocals(count, type); 78 local_decls.AddLocals(count, type);
79 } 79 }
80 80
81 // Prepends local variable declarations and renders nice error messages for 81 // Prepends local variable declarations and renders nice error messages for
82 // verification failures. 82 // verification failures.
83 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start, 83 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
84 const byte* end) { 84 const byte* end) {
85 local_decls.Prepend(&start, &end); 85 local_decls.Prepend(zone(), &start, &end);
86 // Verify the code. 86 // Verify the code.
87 TreeResult result = 87 TreeResult result =
88 VerifyWasmCode(zone()->allocator(), module, sig, start, end); 88 VerifyWasmCode(zone()->allocator(), module, sig, start, end);
89 89
90 if (result.error_code != expected) { 90 if (result.error_code != expected) {
91 ptrdiff_t pc = result.error_pc - result.start; 91 ptrdiff_t pc = result.error_pc - result.start;
92 ptrdiff_t pt = result.error_pt - result.start; 92 ptrdiff_t pt = result.error_pt - result.start;
93 std::ostringstream str; 93 std::ostringstream str;
94 if (expected == kSuccess) { 94 if (expected == kSuccess) {
95 str << "Verification failed: " << result.error_code << " pc = +" << pc; 95 str << "Verification failed: " << result.error_code << " pc = +" << pc;
96 if (result.error_pt) str << ", pt = +" << pt; 96 if (result.error_pt) str << ", pt = +" << pt;
97 str << ", msg = " << result.error_msg.get(); 97 str << ", msg = " << result.error_msg.get();
98 } else { 98 } else {
99 str << "Verification expected: " << expected << ", but got " 99 str << "Verification expected: " << expected << ", but got "
100 << result.error_code; 100 << result.error_code;
101 if (result.error_code != kSuccess) { 101 if (result.error_code != kSuccess) {
102 str << " pc = +" << pc; 102 str << " pc = +" << pc;
103 if (result.error_pt) str << ", pt = +" << pt; 103 if (result.error_pt) str << ", pt = +" << pt;
104 } 104 }
105 } 105 }
106 FATAL(str.str().c_str()); 106 FATAL(str.str().c_str());
107 } 107 }
108
109 delete[] start; // local_decls.Prepend() allocated a new buffer.
110 } 108 }
111 109
112 void TestBinop(WasmOpcode opcode, FunctionSig* success) { 110 void TestBinop(WasmOpcode opcode, FunctionSig* success) {
113 // op(local[0], local[1]) 111 // op(local[0], local[1])
114 byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; 112 byte code[] = {WASM_BINOP(opcode, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
115 EXPECT_VERIFIES(success, code); 113 EXPECT_VERIFIES(success, code);
116 114
117 // Try all combinations of return and parameter types. 115 // Try all combinations of return and parameter types.
118 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 116 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
119 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 117 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
(...skipping 2300 matching lines...) Expand 10 before | Expand all | Expand 10 after
2420 } 2418 }
2421 2419
2422 TEST_F(LocalDeclDecoderTest, UseEncoder) { 2420 TEST_F(LocalDeclDecoderTest, UseEncoder) {
2423 const byte* data = nullptr; 2421 const byte* data = nullptr;
2424 const byte* end = nullptr; 2422 const byte* end = nullptr;
2425 LocalDeclEncoder local_decls(zone()); 2423 LocalDeclEncoder local_decls(zone());
2426 2424
2427 local_decls.AddLocals(5, kAstF32); 2425 local_decls.AddLocals(5, kAstF32);
2428 local_decls.AddLocals(1337, kAstI32); 2426 local_decls.AddLocals(1337, kAstI32);
2429 local_decls.AddLocals(212, kAstI64); 2427 local_decls.AddLocals(212, kAstI64);
2430 local_decls.Prepend(&data, &end); 2428 local_decls.Prepend(zone(), &data, &end);
2431 2429
2432 AstLocalDecls decls(zone()); 2430 AstLocalDecls decls(zone());
2433 bool result = DecodeLocalDecls(decls, data, end); 2431 bool result = DecodeLocalDecls(decls, data, end);
2434 EXPECT_TRUE(result); 2432 EXPECT_TRUE(result);
2435 EXPECT_EQ(5 + 1337 + 212, decls.total_local_count); 2433 EXPECT_EQ(5 + 1337 + 212, decls.total_local_count);
2436 2434
2437 LocalTypeMap map = Expand(decls); 2435 LocalTypeMap map = Expand(decls);
2438 size_t pos = 0; 2436 size_t pos = 0;
2439 pos = ExpectRun(map, pos, kAstF32, 5); 2437 pos = ExpectRun(map, pos, kAstF32, 5);
2440 pos = ExpectRun(map, pos, kAstI32, 1337); 2438 pos = ExpectRun(map, pos, kAstI32, 1337);
2441 pos = ExpectRun(map, pos, kAstI64, 212); 2439 pos = ExpectRun(map, pos, kAstI64, 212);
2442 delete[] data;
2443 } 2440 }
2444 2441
2445 } // namespace wasm 2442 } // namespace wasm
2446 } // namespace internal 2443 } // namespace internal
2447 } // namespace v8 2444 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/unittests.gyp ('k') | test/unittests/wasm/control-transfer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698