v8/test/cctest/wasm/test-run-wasm-relocation.cc
Mircea Trofin 5eb1aa488e Revert "Revert "[wasm] Rename TestingModule to TestingModuleBuilder.""
This reverts commit 3913bde188.

Reason for revert: Reason for revert fixed.

Original change's description:
> Revert "[wasm] Rename TestingModule to TestingModuleBuilder."
> 
> This reverts commit ed06fc9127.
> 
> Reason for revert: Need to revert previous CL
> 
> Original change's description:
> > [wasm] Rename TestingModule to TestingModuleBuilder.
> > 
> > This is a followup to moving the ModuleEnv to the compiler directory and
> > making it immutable.
> > 
> > R=​mtrofin@chromium.org, ahaas@chromium.org
> > 
> > Bug: 
> > Change-Id: I0f5ec1b697bdcfad0b4dc2bca577cc0f40de8dc0
> > Reviewed-on: https://chromium-review.googlesource.com/616762
> > Commit-Queue: Ben Titzer <titzer@chromium.org>
> > Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
> > Reviewed-by: Andreas Haas <ahaas@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47419}
> 
> TBR=titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org
> 
> Change-Id: I9b3b379e89f523c2fcf205a1d268aa294bbc44ff
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/622567
> Reviewed-by: Michael Achenbach <machenbach@chromium.org>
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47448}

TBR=machenbach@chromium.org,titzer@chromium.org,mtrofin@chromium.org,ahaas@chromium.org

Change-Id: Idce6f1ca8ed0ea80edb50292e9b6e2d7712f29cf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/622034
Reviewed-by: Mircea Trofin <mtrofin@chromium.org>
Commit-Queue: Mircea Trofin <mtrofin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47454}
2017-08-19 16:34:27 +00:00

63 lines
3.6 KiB
C++

// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdlib.h>
#include "src/assembler-inl.h"
#include "src/objects-inl.h"
#include "src/v8.h"
#include "test/cctest/cctest.h"
#include "test/cctest/compiler/c-signature.h"
#include "test/cctest/wasm/wasm-run-utils.h"
#include "test/common/wasm/wasm-macro-gen.h"
using namespace v8::internal;
using namespace v8::internal::compiler;
#define FOREACH_TYPE(TEST_BODY) \
TEST_BODY(int32_t, WASM_I32_ADD) \
TEST_BODY(int64_t, WASM_I64_ADD) \
TEST_BODY(float, WASM_F32_ADD) \
TEST_BODY(double, WASM_F64_ADD)
#define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, ADD) \
TEST(WasmRelocateGlobal_##C_TYPE) { \
WasmRunner<C_TYPE, C_TYPE> r(kExecuteCompiled); \
Isolate* isolate = CcTest::i_isolate(); \
\
r.builder().AddGlobal<C_TYPE>(); \
r.builder().AddGlobal<C_TYPE>(); \
\
/* global = global + p0 */ \
BUILD(r, WASM_SET_GLOBAL(1, ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))), \
WASM_GET_GLOBAL(0)); \
CHECK_EQ(1, r.builder().CodeTableLength()); \
\
int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \
\
Handle<Code> code = r.builder().GetFunctionCode(0); \
\
Address old_start = r.builder().globals_start(); \
Address new_start = old_start + 1; \
\
Address old_addresses[4]; \
uint32_t address_index = 0U; \
for (RelocIterator it(*code, filter); !it.done(); it.next()) { \
old_addresses[address_index] = it.rinfo()->wasm_global_reference(); \
it.rinfo()->update_wasm_global_reference(isolate, old_start, new_start); \
++address_index; \
} \
CHECK_LE(address_index, 4U); \
\
address_index = 0U; \
for (RelocIterator it(*code, filter); !it.done(); it.next()) { \
CHECK_EQ(old_addresses[address_index] + 1, \
it.rinfo()->wasm_global_reference()); \
++address_index; \
} \
CHECK_LE(address_index, 4U); \
}
FOREACH_TYPE(LOAD_SET_GLOBAL_TEST_BODY)