OLD | NEW |
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 #define VERIFY(...) \ | 61 #define VERIFY(...) \ |
62 do { \ | 62 do { \ |
63 static const byte code[] = {__VA_ARGS__}; \ | 63 static const byte code[] = {__VA_ARGS__}; \ |
64 Verify(kSuccess, sigs.v_i(), code, code + sizeof(code)); \ | 64 Verify(kSuccess, sigs.v_i(), code, code + sizeof(code)); \ |
65 } while (false) | 65 } while (false) |
66 | 66 |
67 class AstDecoderTest : public TestWithZone { | 67 class AstDecoderTest : public TestWithZone { |
68 public: | 68 public: |
69 typedef std::pair<uint32_t, LocalType> LocalsDecl; | 69 typedef std::pair<uint32_t, LocalType> LocalsDecl; |
70 | 70 |
71 AstDecoderTest() : module(nullptr) {} | 71 AstDecoderTest() : module(nullptr), local_decls(zone()) {} |
| 72 |
72 TestSignatures sigs; | 73 TestSignatures sigs; |
73 ModuleEnv* module; | 74 ModuleEnv* module; |
74 LocalDeclEncoder local_decls; | 75 LocalDeclEncoder local_decls; |
75 | 76 |
76 void AddLocals(LocalType type, uint32_t count) { | 77 void AddLocals(LocalType type, uint32_t count) { |
77 local_decls.AddLocals(count, type); | 78 local_decls.AddLocals(count, type); |
78 } | 79 } |
79 | 80 |
80 // Prepends local variable declarations and renders nice error messages for | 81 // Prepends local variable declarations and renders nice error messages for |
81 // verification failures. | 82 // verification failures. |
(...skipping 2332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2414 pos = ExpectRun(map, pos, kAstF64, d); | 2415 pos = ExpectRun(map, pos, kAstF64, d); |
2415 } | 2416 } |
2416 } | 2417 } |
2417 } | 2418 } |
2418 } | 2419 } |
2419 } | 2420 } |
2420 | 2421 |
2421 TEST_F(LocalDeclDecoderTest, UseEncoder) { | 2422 TEST_F(LocalDeclDecoderTest, UseEncoder) { |
2422 const byte* data = nullptr; | 2423 const byte* data = nullptr; |
2423 const byte* end = nullptr; | 2424 const byte* end = nullptr; |
2424 LocalDeclEncoder local_decls; | 2425 LocalDeclEncoder local_decls(zone()); |
2425 | 2426 |
2426 local_decls.AddLocals(5, kAstF32); | 2427 local_decls.AddLocals(5, kAstF32); |
2427 local_decls.AddLocals(1337, kAstI32); | 2428 local_decls.AddLocals(1337, kAstI32); |
2428 local_decls.AddLocals(212, kAstI64); | 2429 local_decls.AddLocals(212, kAstI64); |
2429 local_decls.Prepend(&data, &end); | 2430 local_decls.Prepend(&data, &end); |
2430 | 2431 |
2431 AstLocalDecls decls(zone()); | 2432 AstLocalDecls decls(zone()); |
2432 bool result = DecodeLocalDecls(decls, data, end); | 2433 bool result = DecodeLocalDecls(decls, data, end); |
2433 EXPECT_TRUE(result); | 2434 EXPECT_TRUE(result); |
2434 EXPECT_EQ(5 + 1337 + 212, decls.total_local_count); | 2435 EXPECT_EQ(5 + 1337 + 212, decls.total_local_count); |
2435 | 2436 |
2436 LocalTypeMap map = Expand(decls); | 2437 LocalTypeMap map = Expand(decls); |
2437 size_t pos = 0; | 2438 size_t pos = 0; |
2438 pos = ExpectRun(map, pos, kAstF32, 5); | 2439 pos = ExpectRun(map, pos, kAstF32, 5); |
2439 pos = ExpectRun(map, pos, kAstI32, 1337); | 2440 pos = ExpectRun(map, pos, kAstI32, 1337); |
2440 pos = ExpectRun(map, pos, kAstI64, 212); | 2441 pos = ExpectRun(map, pos, kAstI64, 212); |
2441 delete[] data; | 2442 delete[] data; |
2442 } | 2443 } |
2443 | 2444 |
2444 } // namespace wasm | 2445 } // namespace wasm |
2445 } // namespace internal | 2446 } // namespace internal |
2446 } // namespace v8 | 2447 } // namespace v8 |
OLD | NEW |