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 <stdlib.h> | 5 #include <stdlib.h> |
6 | 6 |
7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
8 #include "src/objects-inl.h" | 8 #include "src/objects-inl.h" |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 #include "test/cctest/cctest.h" | 10 #include "test/cctest/cctest.h" |
11 #include "test/cctest/compiler/c-signature.h" | 11 #include "test/cctest/compiler/c-signature.h" |
12 #include "test/cctest/wasm/wasm-run-utils.h" | 12 #include "test/cctest/wasm/wasm-run-utils.h" |
13 | 13 |
14 using namespace v8::internal; | 14 using namespace v8::internal; |
15 using namespace v8::internal::compiler; | 15 using namespace v8::internal::compiler; |
16 | 16 |
17 #define FOREACH_TYPE(TEST_BODY) \ | 17 #define FOREACH_TYPE(TEST_BODY) \ |
18 TEST_BODY(int32_t, WASM_I32_ADD) \ | 18 TEST_BODY(int32_t, WASM_I32_ADD) \ |
19 TEST_BODY(int64_t, WASM_I64_ADD) \ | 19 TEST_BODY(int64_t, WASM_I64_ADD) \ |
20 TEST_BODY(float, WASM_F32_ADD) \ | 20 TEST_BODY(float, WASM_F32_ADD) \ |
21 TEST_BODY(double, WASM_F64_ADD) | 21 TEST_BODY(double, WASM_F64_ADD) |
22 | 22 |
23 #define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, ADD) \ | 23 #define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, ADD) \ |
24 TEST(WasmRelocateGlobal_##C_TYPE) { \ | 24 TEST(WasmRelocateGlobal_##C_TYPE) { \ |
25 WasmRunner<C_TYPE, C_TYPE> r(kExecuteCompiled); \ | 25 WasmRunner<C_TYPE, C_TYPE> r(kExecuteCompiled); \ |
26 \ | 26 Isolate* isolate = CcTest::i_isolate(); \ |
27 r.module().AddGlobal<C_TYPE>(); \ | 27 \ |
28 r.module().AddGlobal<C_TYPE>(); \ | 28 r.module().AddGlobal<C_TYPE>(); \ |
29 \ | 29 r.module().AddGlobal<C_TYPE>(); \ |
30 /* global = global + p0 */ \ | 30 \ |
31 BUILD(r, WASM_SET_GLOBAL(1, ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))), \ | 31 /* global = global + p0 */ \ |
32 WASM_GET_GLOBAL(0)); \ | 32 BUILD(r, WASM_SET_GLOBAL(1, ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))), \ |
33 CHECK_EQ(1, r.module().instance->function_code.size()); \ | 33 WASM_GET_GLOBAL(0)); \ |
34 \ | 34 CHECK_EQ(1, r.module().instance->function_code.size()); \ |
35 int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \ | 35 \ |
36 \ | 36 int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \ |
37 Handle<Code> code = r.module().instance->function_code[0]; \ | 37 \ |
38 \ | 38 Handle<Code> code = r.module().instance->function_code[0]; \ |
39 Address old_start = r.module().instance->globals_start; \ | 39 \ |
40 Address new_start = old_start + 1; \ | 40 Address old_start = r.module().instance->globals_start; \ |
41 \ | 41 Address new_start = old_start + 1; \ |
42 Address old_addresses[4]; \ | 42 \ |
43 uint32_t address_index = 0U; \ | 43 Address old_addresses[4]; \ |
44 for (RelocIterator it(*code, filter); !it.done(); it.next()) { \ | 44 uint32_t address_index = 0U; \ |
45 old_addresses[address_index] = it.rinfo()->wasm_global_reference(); \ | 45 for (RelocIterator it(*code, filter); !it.done(); it.next()) { \ |
46 it.rinfo()->update_wasm_global_reference(old_start, new_start); \ | 46 old_addresses[address_index] = it.rinfo()->wasm_global_reference(); \ |
47 ++address_index; \ | 47 it.rinfo()->update_wasm_global_reference(isolate, old_start, new_start); \ |
48 } \ | 48 ++address_index; \ |
49 CHECK_LE(address_index, 4U); \ | 49 } \ |
50 \ | 50 CHECK_LE(address_index, 4U); \ |
51 address_index = 0U; \ | 51 \ |
52 for (RelocIterator it(*code, filter); !it.done(); it.next()) { \ | 52 address_index = 0U; \ |
53 CHECK_EQ(old_addresses[address_index] + 1, \ | 53 for (RelocIterator it(*code, filter); !it.done(); it.next()) { \ |
54 it.rinfo()->wasm_global_reference()); \ | 54 CHECK_EQ(old_addresses[address_index] + 1, \ |
55 ++address_index; \ | 55 it.rinfo()->wasm_global_reference()); \ |
56 } \ | 56 ++address_index; \ |
57 CHECK_LE(address_index, 4U); \ | 57 } \ |
| 58 CHECK_LE(address_index, 4U); \ |
58 } | 59 } |
59 | 60 |
60 FOREACH_TYPE(LOAD_SET_GLOBAL_TEST_BODY) | 61 FOREACH_TYPE(LOAD_SET_GLOBAL_TEST_BODY) |
OLD | NEW |