Commit 5993a116 authored by clemensh's avatar clemensh Committed by Commit bot

Revert of [wasm] Make WasmRunner the central test structure (patchset #5...

Revert of [wasm] Make WasmRunner the central test structure (patchset #5 id:80001 of https://codereview.chromium.org/2551043002/ )

Reason for revert:
Win64 dbg failures

Original issue's description:
> [wasm] Make WasmRunner the central test structure
>
> The WasmRunner now always holds a TestingModule, and allows to add
> several functions to it. The prepares a change to always run wasm code
> with a full module behind it, removing the special handling for "no wasm
> instance" at runtime (http://crrev.com/2551053002).
> This CL here also templatizes the WasmRunner such that the Call method must
> be called with the same signature specified for the WasmRunner. This
> already catched several mismatches there.
>
> R=titzer@chromium.org, ahaas@chromium.org
> BUG=v8:5620
>
> Review-Url: https://codereview.chromium.org/2551043002
> Cr-Commit-Position: refs/heads/master@{#41728}
> Committed: https://chromium.googlesource.com/v8/v8/+/2ff59062314e9b86bcc28dfaa53cedf2d98e3a13

TBR=ahaas@chromium.org,titzer@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:5620

Review-Url: https://codereview.chromium.org/2583543002
Cr-Commit-Position: refs/heads/master@{#41732}
parent 7ca72292
This diff is collapsed.
This diff is collapsed.
...@@ -35,14 +35,14 @@ TEST(Run_WasmInt8Const_i) { ...@@ -35,14 +35,14 @@ TEST(Run_WasmInt8Const_i) {
} }
TEST(Run_WasmIfElse) { TEST(Run_WasmIfElse) {
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted); WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10))); BUILD(r, WASM_IF_ELSE_I(WASM_GET_LOCAL(0), WASM_I8(9), WASM_I8(10)));
CHECK_EQ(10, r.Call(0)); CHECK_EQ(10, r.Call(0));
CHECK_EQ(9, r.Call(1)); CHECK_EQ(9, r.Call(1));
} }
TEST(Run_WasmIfReturn) { TEST(Run_WasmIfReturn) {
WasmRunner<int32_t, int32_t> r(kExecuteInterpreted); WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32());
BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65)); BUILD(r, WASM_IF(WASM_GET_LOCAL(0), WASM_RETURN1(WASM_I8(77))), WASM_I8(65));
CHECK_EQ(65, r.Call(0)); CHECK_EQ(65, r.Call(0));
CHECK_EQ(77, r.Call(1)); CHECK_EQ(77, r.Call(1));
...@@ -131,7 +131,8 @@ TEST(Run_WasmBlockBreakN) { ...@@ -131,7 +131,8 @@ TEST(Run_WasmBlockBreakN) {
} }
TEST(Run_Wasm_nested_ifs_i) { TEST(Run_Wasm_nested_ifs_i) {
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteInterpreted); WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Int32(),
MachineType::Int32());
BUILD(r, WASM_IF_ELSE_I( BUILD(r, WASM_IF_ELSE_I(
WASM_GET_LOCAL(0), WASM_GET_LOCAL(0),
...@@ -179,7 +180,8 @@ TEST(Breakpoint_I32Add) { ...@@ -179,7 +180,8 @@ TEST(Breakpoint_I32Add) {
Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal, Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal,
kExprI32Add); kExprI32Add);
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted); WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
r.Build(code, code + arraysize(code)); r.Build(code, code + arraysize(code));
...@@ -218,7 +220,8 @@ TEST(Step_I32Mul) { ...@@ -218,7 +220,8 @@ TEST(Step_I32Mul) {
static const int kTraceLength = 4; static const int kTraceLength = 4;
byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted); WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
r.Build(code, code + arraysize(code)); r.Build(code, code + arraysize(code));
...@@ -256,7 +259,8 @@ TEST(Breakpoint_I32And_disable) { ...@@ -256,7 +259,8 @@ TEST(Breakpoint_I32And_disable) {
std::unique_ptr<int[]> offsets = std::unique_ptr<int[]> offsets =
Find(code, sizeof(code), kNumBreakpoints, kExprI32And); Find(code, sizeof(code), kNumBreakpoints, kExprI32And);
WasmRunner<int32_t, uint32_t, uint32_t> r(kExecuteInterpreted); WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
MachineType::Uint32());
r.Build(code, code + arraysize(code)); r.Build(code, code + arraysize(code));
...@@ -293,8 +297,9 @@ TEST(Breakpoint_I32And_disable) { ...@@ -293,8 +297,9 @@ TEST(Breakpoint_I32And_disable) {
} }
TEST(GrowMemory) { TEST(GrowMemory) {
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize); WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(1, r.Call(1)); CHECK_EQ(1, r.Call(1));
} }
...@@ -302,8 +307,9 @@ TEST(GrowMemory) { ...@@ -302,8 +307,9 @@ TEST(GrowMemory) {
TEST(GrowMemoryPreservesData) { TEST(GrowMemoryPreservesData) {
int32_t index = 16; int32_t index = 16;
int32_t value = 2335; int32_t value = 2335;
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize); WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index), BUILD(r, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V(index),
WASM_I32V(value)), WASM_I32V(value)),
WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)), WASM_DROP,
...@@ -314,14 +320,16 @@ TEST(GrowMemoryPreservesData) { ...@@ -314,14 +320,16 @@ TEST(GrowMemoryPreservesData) {
TEST(GrowMemoryInvalidSize) { TEST(GrowMemoryInvalidSize) {
{ {
// Grow memory by an invalid amount without initial memory. // Grow memory by an invalid amount without initial memory.
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
WasmRunner<int32_t> r(&module, MachineType::Uint32());
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(-1, r.Call(1048575)); CHECK_EQ(-1, r.Call(1048575));
} }
{ {
// Grow memory by an invalid amount without initial memory. // Grow memory by an invalid amount without initial memory.
WasmRunner<int32_t, uint32_t> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
r.module().AddMemory(WasmModule::kPageSize); WasmRunner<int32_t> r(&module, MachineType::Uint32());
module.AddMemory(WasmModule::kPageSize);
BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0))); BUILD(r, WASM_GROW_MEMORY(WASM_GET_LOCAL(0)));
CHECK_EQ(-1, r.Call(1048575)); CHECK_EQ(-1, r.Call(1048575));
} }
...@@ -330,7 +338,9 @@ TEST(GrowMemoryInvalidSize) { ...@@ -330,7 +338,9 @@ TEST(GrowMemoryInvalidSize) {
TEST(TestPossibleNondeterminism) { TEST(TestPossibleNondeterminism) {
{ {
// F32Div may produced NaN // F32Div may produced NaN
WasmRunner<float, float, float> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32(),
MachineType::Float32());
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5f, 2.5f); r.Call(1048575.5f, 2.5f);
CHECK(!r.possible_nondeterminism()); CHECK(!r.possible_nondeterminism());
...@@ -339,7 +349,8 @@ TEST(TestPossibleNondeterminism) { ...@@ -339,7 +349,8 @@ TEST(TestPossibleNondeterminism) {
} }
{ {
// F32Sqrt may produced NaN // F32Sqrt may produced NaN
WasmRunner<float, float> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32());
BUILD(r, WASM_F32_SQRT(WASM_GET_LOCAL(0))); BUILD(r, WASM_F32_SQRT(WASM_GET_LOCAL(0)));
r.Call(16.0f); r.Call(16.0f);
CHECK(!r.possible_nondeterminism()); CHECK(!r.possible_nondeterminism());
...@@ -348,7 +359,9 @@ TEST(TestPossibleNondeterminism) { ...@@ -348,7 +359,9 @@ TEST(TestPossibleNondeterminism) {
} }
{ {
// F32Mul may produced NaN // F32Mul may produced NaN
WasmRunner<float, float, float> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
WasmRunner<float> r(&module, MachineType::Float32(),
MachineType::Float32());
BUILD(r, WASM_F32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_F32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5f, 2.5f); r.Call(1048575.5f, 2.5f);
CHECK(!r.possible_nondeterminism()); CHECK(!r.possible_nondeterminism());
...@@ -357,7 +370,9 @@ TEST(TestPossibleNondeterminism) { ...@@ -357,7 +370,9 @@ TEST(TestPossibleNondeterminism) {
} }
{ {
// F64Div may produced NaN // F64Div may produced NaN
WasmRunner<double, double, double> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64(),
MachineType::Float64());
BUILD(r, WASM_F64_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_F64_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5, 2.5); r.Call(1048575.5, 2.5);
CHECK(!r.possible_nondeterminism()); CHECK(!r.possible_nondeterminism());
...@@ -366,7 +381,8 @@ TEST(TestPossibleNondeterminism) { ...@@ -366,7 +381,8 @@ TEST(TestPossibleNondeterminism) {
} }
{ {
// F64Sqrt may produced NaN // F64Sqrt may produced NaN
WasmRunner<double, double> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64());
BUILD(r, WASM_F64_SQRT(WASM_GET_LOCAL(0))); BUILD(r, WASM_F64_SQRT(WASM_GET_LOCAL(0)));
r.Call(1048575.5); r.Call(1048575.5);
CHECK(!r.possible_nondeterminism()); CHECK(!r.possible_nondeterminism());
...@@ -375,7 +391,9 @@ TEST(TestPossibleNondeterminism) { ...@@ -375,7 +391,9 @@ TEST(TestPossibleNondeterminism) {
} }
{ {
// F64Mul may produced NaN // F64Mul may produced NaN
WasmRunner<double, double, double> r(kExecuteInterpreted); TestingModule module(kExecuteInterpreted);
WasmRunner<double> r(&module, MachineType::Float64(),
MachineType::Float64());
BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); BUILD(r, WASM_F64_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
r.Call(1048575.5, 2.5); r.Call(1048575.5, 2.5);
CHECK(!r.possible_nondeterminism()); CHECK(!r.possible_nondeterminism());
......
...@@ -97,36 +97,48 @@ void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a, ...@@ -97,36 +97,48 @@ void EXPECT_CALL(double expected, Handle<JSFunction> jsfunc, double a,
} // namespace } // namespace
TEST(Run_Int32Sub_jswrapped) { TEST(Run_Int32Sub_jswrapped) {
WasmRunner<int, int, int> r(kExecuteCompiled); CcTest::InitializeVM();
BUILD(r, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); TestSignatures sigs;
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); TestingModule module;
WasmFunctionCompiler t(sigs.i_ii(), &module);
BUILD(t, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(33, jsfunc, 44, 11); EXPECT_CALL(33, jsfunc, 44, 11);
EXPECT_CALL(-8723487, jsfunc, -8000000, 723487); EXPECT_CALL(-8723487, jsfunc, -8000000, 723487);
} }
TEST(Run_Float32Div_jswrapped) { TEST(Run_Float32Div_jswrapped) {
WasmRunner<float, float, float> r(kExecuteCompiled); CcTest::InitializeVM();
BUILD(r, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); TestSignatures sigs;
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); TestingModule module;
WasmFunctionCompiler t(sigs.f_ff(), &module);
BUILD(t, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(92, jsfunc, 46, 0.5); EXPECT_CALL(92, jsfunc, 46, 0.5);
EXPECT_CALL(64, jsfunc, -16, -0.25); EXPECT_CALL(64, jsfunc, -16, -0.25);
} }
TEST(Run_Float64Add_jswrapped) { TEST(Run_Float64Add_jswrapped) {
WasmRunner<double, double, double> r(kExecuteCompiled); CcTest::InitializeVM();
BUILD(r, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); TestSignatures sigs;
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); TestingModule module;
WasmFunctionCompiler t(sigs.d_dd(), &module);
BUILD(t, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(3, jsfunc, 2, 1); EXPECT_CALL(3, jsfunc, 2, 1);
EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25); EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25);
} }
TEST(Run_I32Popcount_jswrapped) { TEST(Run_I32Popcount_jswrapped) {
WasmRunner<int, int> r(kExecuteCompiled); CcTest::InitializeVM();
BUILD(r, WASM_I32_POPCNT(WASM_GET_LOCAL(0))); TestSignatures sigs;
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); TestingModule module;
WasmFunctionCompiler t(sigs.i_i(), &module);
BUILD(t, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(2, jsfunc, 9, 0); EXPECT_CALL(2, jsfunc, 9, 0);
EXPECT_CALL(3, jsfunc, 11, 0); EXPECT_CALL(3, jsfunc, 11, 0);
...@@ -134,13 +146,15 @@ TEST(Run_I32Popcount_jswrapped) { ...@@ -134,13 +146,15 @@ TEST(Run_I32Popcount_jswrapped) {
} }
TEST(Run_CallJS_Add_jswrapped) { TEST(Run_CallJS_Add_jswrapped) {
WasmRunner<int, int> r(kExecuteCompiled); CcTest::InitializeVM();
TestSignatures sigs; TestSignatures sigs;
TestingModule module;
WasmFunctionCompiler t(sigs.i_i(), &module);
uint32_t js_index = uint32_t js_index =
r.module().AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })"); module.AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })");
BUILD(r, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0))); BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = r.module().WrapCode(r.function()->func_index); Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(101, jsfunc, 2, -8); EXPECT_CALL(101, jsfunc, 2, -8);
EXPECT_CALL(199, jsfunc, 100, -1); EXPECT_CALL(199, jsfunc, 100, -1);
...@@ -157,9 +171,9 @@ void RunJSSelectTest(int which) { ...@@ -157,9 +171,9 @@ void RunJSSelectTest(int which) {
HandleScope scope(CcTest::InitIsolateOnce()); HandleScope scope(CcTest::InitIsolateOnce());
FunctionSig sig(1, num_params, types); FunctionSig sig(1, num_params, types);
WasmRunner<void> r(kExecuteCompiled); TestingModule module;
uint32_t js_index = AddJSSelector(&r.module(), &sig, which); uint32_t js_index = AddJSSelector(&module, &sig, which);
WasmFunctionCompiler& t = r.NewFunction(&sig); WasmFunctionCompiler t(&sig, &module);
{ {
std::vector<byte> code; std::vector<byte> code;
...@@ -175,7 +189,7 @@ void RunJSSelectTest(int which) { ...@@ -175,7 +189,7 @@ void RunJSSelectTest(int which) {
t.Build(&code[0], &code[end]); t.Build(&code[0], &code[end]);
} }
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index()); Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
double expected = inputs.arg_d(which); double expected = inputs.arg_d(which);
EXPECT_CALL(expected, jsfunc, 0.0, 0.0); EXPECT_CALL(expected, jsfunc, 0.0, 0.0);
} }
...@@ -231,10 +245,10 @@ void RunWASMSelectTest(int which) { ...@@ -231,10 +245,10 @@ void RunWASMSelectTest(int which) {
type, type, type, type}; type, type, type, type};
FunctionSig sig(1, num_params, types); FunctionSig sig(1, num_params, types);
WasmRunner<void> r(kExecuteCompiled); TestingModule module;
WasmFunctionCompiler& t = r.NewFunction(&sig); WasmFunctionCompiler t(&sig, &module);
BUILD(t, WASM_GET_LOCAL(which)); BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index()); Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = { Handle<Object> args[] = {
isolate->factory()->NewNumber(inputs.arg_d(0)), isolate->factory()->NewNumber(inputs.arg_d(0)),
...@@ -303,10 +317,10 @@ void RunWASMSelectAlignTest(int num_args, int num_params) { ...@@ -303,10 +317,10 @@ void RunWASMSelectAlignTest(int num_args, int num_params) {
FunctionSig sig(1, num_params, types); FunctionSig sig(1, num_params, types);
for (int which = 0; which < num_params; which++) { for (int which = 0; which < num_params; which++) {
WasmRunner<void> r(kExecuteCompiled); TestingModule module;
WasmFunctionCompiler& t = r.NewFunction(&sig); WasmFunctionCompiler t(&sig, &module);
BUILD(t, WASM_GET_LOCAL(which)); BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index()); Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)), Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)),
isolate->factory()->NewNumber(inputs.arg_d(1)), isolate->factory()->NewNumber(inputs.arg_d(1)),
...@@ -397,8 +411,6 @@ void RunJSSelectAlignTest(int num_args, int num_params) { ...@@ -397,8 +411,6 @@ void RunJSSelectAlignTest(int num_args, int num_params) {
LocalType types[kMaxParams + 1] = {type, type, type, type, type, type, LocalType types[kMaxParams + 1] = {type, type, type, type, type, type,
type, type, type, type, type}; type, type, type, type, type};
FunctionSig sig(1, num_params, types); FunctionSig sig(1, num_params, types);
i::AccountingAllocator allocator;
Zone zone(&allocator, ZONE_NAME);
// Build the calling code. // Build the calling code.
std::vector<byte> code; std::vector<byte> code;
...@@ -407,21 +419,21 @@ void RunJSSelectAlignTest(int num_args, int num_params) { ...@@ -407,21 +419,21 @@ void RunJSSelectAlignTest(int num_args, int num_params) {
ADD_CODE(code, WASM_GET_LOCAL(i)); ADD_CODE(code, WASM_GET_LOCAL(i));
} }
uint8_t predicted_js_index = 1; ADD_CODE(code, kExprCallFunction, 0);
ADD_CODE(code, kExprCallFunction, predicted_js_index);
size_t end = code.size(); size_t end = code.size();
code.push_back(0); code.push_back(0);
// Call different select JS functions. // Call different select JS functions.
for (int which = 0; which < num_params; which++) { for (int which = 0; which < num_params; which++) {
WasmRunner<void> r(kExecuteCompiled); HandleScope scope(isolate);
uint32_t js_index = AddJSSelector(&r.module(), &sig, which); TestingModule module;
CHECK_EQ(predicted_js_index, js_index); uint32_t js_index = AddJSSelector(&module, &sig, which);
WasmFunctionCompiler& t = r.NewFunction(&sig); CHECK_EQ(0u, js_index);
WasmFunctionCompiler t(&sig, &module);
t.Build(&code[0], &code[end]); t.Build(&code[0], &code[end]);
Handle<JSFunction> jsfunc = r.module().WrapCode(t.function_index()); Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = { Handle<Object> args[] = {
factory->NewNumber(inputs.arg_d(0)), factory->NewNumber(inputs.arg_d(0)),
......
...@@ -13,29 +13,31 @@ ...@@ -13,29 +13,31 @@
using namespace v8::internal; using namespace v8::internal;
using namespace v8::internal::compiler; using namespace v8::internal::compiler;
#define FOREACH_TYPE(TEST_BODY) \ #define FOREACH_TYPE(TEST_BODY) \
TEST_BODY(int32_t, WASM_I32_ADD) \ TEST_BODY(int32_t, I32, WASM_I32_ADD) \
TEST_BODY(int64_t, WASM_I64_ADD) \ TEST_BODY(int64_t, I64, WASM_I64_ADD) \
TEST_BODY(float, WASM_F32_ADD) \ TEST_BODY(float, F32, WASM_F32_ADD) \
TEST_BODY(double, WASM_F64_ADD) TEST_BODY(double, F64, WASM_F64_ADD)
#define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, ADD) \ #define LOAD_SET_GLOBAL_TEST_BODY(C_TYPE, MACHINE_TYPE, ADD) \
TEST(WasmRelocateGlobal_##C_TYPE) { \ TEST(WasmRelocateGlobal##MACHINE_TYPE) { \
WasmRunner<C_TYPE, C_TYPE> r(kExecuteCompiled); \ TestingModule module(kExecuteCompiled); \
module.AddGlobal<C_TYPE>(kAst##MACHINE_TYPE); \
module.AddGlobal<C_TYPE>(kAst##MACHINE_TYPE); \
\ \
r.module().AddGlobal<C_TYPE>(); \ WasmRunner<C_TYPE> r(&module, \
r.module().AddGlobal<C_TYPE>(); \ WasmOpcodes::MachineTypeFor(kAst##MACHINE_TYPE)); \
\ \
/* global = global + p0 */ \ /* global = global + p0 */ \
BUILD(r, WASM_SET_GLOBAL(1, ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))), \ BUILD(r, WASM_SET_GLOBAL(1, ADD(WASM_GET_GLOBAL(0), WASM_GET_LOCAL(0))), \
WASM_GET_GLOBAL(0)); \ WASM_GET_GLOBAL(0)); \
CHECK_EQ(1, r.module().instance->function_code.size()); \ CHECK_EQ(1u, module.instance->function_code.size()); \
\ \
int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \ int filter = 1 << RelocInfo::WASM_GLOBAL_REFERENCE; \
\ \
Handle<Code> code = r.module().instance->function_code[0]; \ Handle<Code> code = module.instance->function_code[0]; \
\ \
Address old_start = r.module().instance->globals_start; \ Address old_start = module.instance->globals_start; \
Address new_start = old_start + 1; \ Address new_start = old_start + 1; \
\ \
Address old_addresses[4]; \ Address old_addresses[4]; \
......
...@@ -45,7 +45,7 @@ WASM_EXEC_TEST(I32x4Splat) { ...@@ -45,7 +45,7 @@ WASM_EXEC_TEST(I32x4Splat) {
// return 0 // return 0
// //
// return 1 // return 1
WasmRunner<int32_t, int32_t> r(kExecuteCompiled); WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32());
byte lane_val = 0; byte lane_val = 0;
byte simd = r.AllocateLocal(kAstS128); byte simd = r.AllocateLocal(kAstS128);
BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT( BUILD(r, WASM_BLOCK(WASM_SET_LOCAL(simd, WASM_SIMD_I32x4_SPLAT(
...@@ -58,7 +58,8 @@ WASM_EXEC_TEST(I32x4Splat) { ...@@ -58,7 +58,8 @@ WASM_EXEC_TEST(I32x4Splat) {
WASM_EXEC_TEST(I32x4ReplaceLane) { WASM_EXEC_TEST(I32x4ReplaceLane) {
FLAG_wasm_simd_prototype = true; FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t, int32_t> r(kExecuteCompiled); WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32());
byte old_val = 0; byte old_val = 0;
byte new_val = 1; byte new_val = 1;
byte simd = r.AllocateLocal(kAstS128); byte simd = r.AllocateLocal(kAstS128);
...@@ -91,7 +92,8 @@ WASM_EXEC_TEST(I32x4ReplaceLane) { ...@@ -91,7 +92,8 @@ WASM_EXEC_TEST(I32x4ReplaceLane) {
WASM_EXEC_TEST(I32x4Add) { WASM_EXEC_TEST(I32x4Add) {
FLAG_wasm_simd_prototype = true; FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32(), MachineType::Int32());
byte a = 0; byte a = 0;
byte b = 1; byte b = 1;
byte expected = 2; byte expected = 2;
...@@ -113,7 +115,8 @@ WASM_EXEC_TEST(I32x4Add) { ...@@ -113,7 +115,8 @@ WASM_EXEC_TEST(I32x4Add) {
WASM_EXEC_TEST(I32x4Sub) { WASM_EXEC_TEST(I32x4Sub) {
FLAG_wasm_simd_prototype = true; FLAG_wasm_simd_prototype = true;
WasmRunner<int32_t, int32_t, int32_t, int32_t> r(kExecuteCompiled); WasmRunner<int32_t> r(kExecuteCompiled, MachineType::Int32(),
MachineType::Int32(), MachineType::Int32());
byte a = 0; byte a = 0;
byte b = 1; byte b = 1;
byte expected = 2; byte expected = 2;
......
This diff is collapsed.
...@@ -76,22 +76,25 @@ void CheckExceptionInfos(Handle<Object> exc, ...@@ -76,22 +76,25 @@ void CheckExceptionInfos(Handle<Object> exc,
// Call from JS to WASM to JS and throw an Error from JS. // Call from JS to WASM to JS and throw an Error from JS.
TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs; TestSignatures sigs;
TestingModule module;
uint32_t js_throwing_index = r.module().AddJsFunction( // Initialize WasmFunctionCompiler first, since it sets up the HandleScope.
WasmFunctionCompiler comp1(sigs.v_v(), &module);
uint32_t js_throwing_index = module.AddJsFunction(
sigs.v_v(), sigs.v_v(),
"(function js() {\n function a() {\n throw new Error(); };\n a(); })"); "(function js() {\n function a() {\n throw new Error(); };\n a(); })");
// Add a nop such that we don't always get position 1. // Add a nop such that we don't always get position 1.
BUILD(r, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index)); BUILD(comp1, WASM_NOP, WASM_CALL_FUNCTION0(js_throwing_index));
uint32_t wasm_index_1 = r.function()->func_index; uint32_t wasm_index = comp1.CompileAndAdd();
WasmFunctionCompiler& f2 = r.NewFunction<void>(); WasmFunctionCompiler comp2(sigs.v_v(), &module);
BUILD(f2, WASM_CALL_FUNCTION0(wasm_index_1)); BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = f2.function_index(); uint32_t wasm_index_2 = comp2.CompileAndAdd();
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
...@@ -111,7 +114,7 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { ...@@ -111,7 +114,7 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
ExceptionInfo expected_exceptions[] = { ExceptionInfo expected_exceptions[] = {
{"a", 3, 8}, // - {"a", 3, 8}, // -
{"js", 4, 2}, // - {"js", 4, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 3}, // - {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 3}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // -
{"callFn", 1, 24} // - {"callFn", 1, 24} // -
}; };
...@@ -121,18 +124,21 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) { ...@@ -121,18 +124,21 @@ TEST(CollectDetailedWasmStack_ExplicitThrowFromJs) {
// Trigger a trap in WASM, stack should be JS -> WASM -> WASM. // Trigger a trap in WASM, stack should be JS -> WASM -> WASM.
TEST(CollectDetailedWasmStack_WasmError) { TEST(CollectDetailedWasmStack_WasmError) {
TestSignatures sigs; TestSignatures sigs;
WasmRunner<int> r(kExecuteCompiled); TestingModule module;
// Set the execution context, such that a runtime error can be thrown.
r.SetModuleContext();
BUILD(r, WASM_UNREACHABLE); WasmFunctionCompiler comp1(sigs.i_v(), &module,
uint32_t wasm_index_1 = r.function()->func_index; ArrayVector("exec_unreachable"));
// Set the execution context, such that a runtime error can be thrown.
comp1.SetModuleContext();
BUILD(comp1, WASM_UNREACHABLE);
uint32_t wasm_index = comp1.CompileAndAdd();
WasmFunctionCompiler& f2 = r.NewFunction<int>(); WasmFunctionCompiler comp2(sigs.i_v(), &module,
BUILD(f2, WASM_CALL_FUNCTION0(0)); ArrayVector("call_exec_unreachable"));
uint32_t wasm_index_2 = f2.function_index(); BUILD(comp2, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = comp2.CompileAndAdd();
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
...@@ -150,7 +156,7 @@ TEST(CollectDetailedWasmStack_WasmError) { ...@@ -150,7 +156,7 @@ TEST(CollectDetailedWasmStack_WasmError) {
// Line and column are 1-based, so add 1 for the expected wasm output. // Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = { ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 2}, // - {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 2}, // -
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // - {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 2}, // -
{"callFn", 1, 24} //- {"callFn", 1, 24} //-
}; };
......
...@@ -62,15 +62,17 @@ void CheckExceptionInfos(Handle<Object> exc, ...@@ -62,15 +62,17 @@ void CheckExceptionInfos(Handle<Object> exc,
// Trigger a trap for executing unreachable. // Trigger a trap for executing unreachable.
TEST(Unreachable) { TEST(Unreachable) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs; TestSignatures sigs;
// Set the execution context, such that a runtime error can be thrown. TestingModule module;
r.SetModuleContext();
BUILD(r, WASM_UNREACHABLE); WasmFunctionCompiler comp1(sigs.v_v(), &module,
uint32_t wasm_index = r.function()->func_index; ArrayVector("exec_unreachable"));
// Set the execution context, such that a runtime error can be thrown.
comp1.SetModuleContext();
BUILD(comp1, WASM_UNREACHABLE);
uint32_t wasm_index = comp1.CompileAndAdd();
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index); Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
...@@ -96,22 +98,23 @@ TEST(Unreachable) { ...@@ -96,22 +98,23 @@ TEST(Unreachable) {
// Trigger a trap for loading from out-of-bounds. // Trigger a trap for loading from out-of-bounds.
TEST(IllegalLoad) { TEST(IllegalLoad) {
WasmRunner<void> r(kExecuteCompiled);
TestSignatures sigs; TestSignatures sigs;
// Set the execution context, such that a runtime error can be thrown. TestingModule module;
r.SetModuleContext();
BUILD(r, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(), WasmFunctionCompiler comp1(sigs.v_v(), &module, ArrayVector("mem_oob"));
WASM_I32V_1(-3)), // Set the execution context, such that a runtime error can be thrown.
WASM_DROP))); comp1.SetModuleContext();
uint32_t wasm_index_1 = r.function()->func_index; BUILD(comp1, WASM_IF(WASM_ONE, WASM_SEQ(WASM_LOAD_MEM(MachineType::Int32(),
WASM_I32V_1(-3)),
WASM_DROP)));
uint32_t wasm_index = comp1.CompileAndAdd();
WasmFunctionCompiler& f2 = r.NewFunction<void>(); WasmFunctionCompiler comp2(sigs.v_v(), &module, ArrayVector("call_mem_oob"));
// Insert a NOP such that the position of the call is not one. // Insert a NOP such that the position of the call is not one.
BUILD(f2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index_1)); BUILD(comp2, WASM_NOP, WASM_CALL_FUNCTION0(wasm_index));
uint32_t wasm_index_2 = f2.function_index(); uint32_t wasm_index_2 = comp2.CompileAndAdd();
Handle<JSFunction> js_wasm_wrapper = r.module().WrapCode(wasm_index_2); Handle<JSFunction> js_wasm_wrapper = module.WrapCode(wasm_index_2);
Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast( Handle<JSFunction> js_trampoline = Handle<JSFunction>::cast(
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast( v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
...@@ -129,7 +132,7 @@ TEST(IllegalLoad) { ...@@ -129,7 +132,7 @@ TEST(IllegalLoad) {
// Line and column are 1-based, so add 1 for the expected wasm output. // Line and column are 1-based, so add 1 for the expected wasm output.
ExceptionInfo expected_exceptions[] = { ExceptionInfo expected_exceptions[] = {
{"<WASM UNNAMED>", static_cast<int>(wasm_index_1) + 1, 8}, // -- {"<WASM UNNAMED>", static_cast<int>(wasm_index) + 1, 8}, // --
{"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // -- {"<WASM UNNAMED>", static_cast<int>(wasm_index_2) + 1, 3}, // --
{"callFn", 1, 24} // -- {"callFn", 1, 24} // --
}; };
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment