blob: 6b1f643391e8585fc8563d9c735186c68933b81a [file] [log] [blame]
Ben Murdoch61f157c2016-09-16 13:49:30 +01001// 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
3// found in the LICENSE file.
4
5#include <stdlib.h>
6
7#include "src/v8.h"
8
9#include "test/cctest/cctest.h"
10#include "test/cctest/compiler/c-signature.h"
11#include "test/cctest/wasm/wasm-run-utils.h"
12
13using namespace v8::internal;
14using namespace v8::internal::compiler;
15
16#define FOREACH_TYPE(TEST_BODY) \
17 TEST_BODY(int8_t, Int8, WASM_I32_ADD) \
18 TEST_BODY(uint8_t, Uint8, WASM_I32_ADD) \
19 TEST_BODY(int16_t, Int16, WASM_I32_ADD) \
20 TEST_BODY(uint16_t, Uint16, WASM_I32_ADD) \
21 TEST_BODY(int32_t, Int32, WASM_I32_ADD) \
22 TEST_BODY(uint32_t, Uint32, WASM_I32_ADD) \
23 TEST_BODY(float, Float32, WASM_F32_ADD) \
24 TEST_BODY(double, Float64, WASM_F64_ADD)
25
26#define LOAD_STORE_GLOBAL_TEST_BODY(C_TYPE, MACHINE_TYPE, ADD) \
27 TEST(WasmRelocateGlobal##MACHINE_TYPE) { \
28 TestingModule module(kExecuteCompiled); \
29 module.AddGlobal<int32_t>(MachineType::MACHINE_TYPE()); \
30 module.AddGlobal<int32_t>(MachineType::MACHINE_TYPE()); \
31 \
32 WasmRunner<C_TYPE> r(&module, MachineType::MACHINE_TYPE()); \
33 \
34 /* global = global + p0 */ \
35 BUILD(r, \
36 WASM_STORE_GLOBAL(1, ADD(WASM_LOAD_GLOBAL(0), WASM_GET_LOCAL(0)))); \
37 CHECK_EQ(1, module.instance->function_code.size()); \
38 \
39 int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \
40 \
41 Handle<Code> code = module.instance->function_code[0]; \
42 \
43 Address old_start = module.instance->globals_start; \
44 Address new_start = old_start + 1; \
45 \
46 Address old_addresses[2]; \
47 uint32_t address_index = 0U; \
48 for (RelocIterator it(*code, filter); !it.done(); it.next()) { \
49 old_addresses[address_index] = it.rinfo()->wasm_global_reference(); \
50 it.rinfo()->update_wasm_global_reference(old_start, new_start); \
51 ++address_index; \
52 } \
53 CHECK_EQ(2U, address_index); \
54 \
55 address_index = 0U; \
56 for (RelocIterator it(*code, filter); !it.done(); it.next()) { \
57 CHECK_EQ(old_addresses[address_index] + 1, \
58 it.rinfo()->wasm_global_reference()); \
59 ++address_index; \
60 } \
61 CHECK_EQ(2U, address_index); \
62 }
63
64FOREACH_TYPE(LOAD_STORE_GLOBAL_TEST_BODY)