Commit 09b50113 authored by clemensh's avatar clemensh Committed by Commit bot

Move two test-internal functions up to header file

... such that they can be reused from other tests.

R=ahaas@chromium.org, jfb@chromium.org, titzer@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1876783002

Cr-Commit-Position: refs/heads/master@{#35617}
parent 473280f8
......@@ -49,22 +49,6 @@ class PredictableInputValues {
};
uint32_t AddJsFunction(TestingModule* module, FunctionSig* sig,
const char* source) {
Handle<JSFunction> jsfunc = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(CompileRun(source))));
module->AddFunction(sig, Handle<Code>::null());
uint32_t index = static_cast<uint32_t>(module->module->functions.size() - 1);
Isolate* isolate = CcTest::InitIsolateOnce();
WasmName module_name = {"test", 4};
WasmName function_name = {nullptr, 0};
Handle<Code> code = CompileWasmToJSWrapper(isolate, module, jsfunc, sig,
module_name, function_name);
module->instance->function_code[index] = code;
return index;
}
uint32_t AddJSSelector(TestingModule* module, FunctionSig* sig, int which) {
const int kMaxParams = 11;
static const char* formals[kMaxParams] = {"",
......@@ -86,19 +70,7 @@ uint32_t AddJSSelector(TestingModule* module, FunctionSig* sig, int which) {
SNPrintF(source, "(function(%s) { return %c; })",
formals[sig->parameter_count()], param);
return AddJsFunction(module, sig, source.start());
}
Handle<JSFunction> WrapCode(ModuleEnv* module, uint32_t index) {
Isolate* isolate = module->module->shared_isolate;
// Wrap the code so it can be called as a JS function.
Handle<String> name = isolate->factory()->NewStringFromStaticChars("main");
Handle<JSObject> module_object = Handle<JSObject>(0, isolate);
Handle<Code> code = module->instance->function_code[index];
WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context());
return compiler::CompileJSToWasmWrapper(isolate, module, name, code,
module_object, index);
return module->AddJsFunction(sig, source.start());
}
......@@ -134,7 +106,7 @@ TEST(Run_Int32Sub_jswrapped) {
TestingModule module;
WasmFunctionCompiler t(sigs.i_ii(), &module);
BUILD(t, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(33, jsfunc, 44, 11);
EXPECT_CALL(-8723487, jsfunc, -8000000, 723487);
......@@ -146,7 +118,7 @@ TEST(Run_Float32Div_jswrapped) {
TestingModule module;
WasmFunctionCompiler t(sigs.f_ff(), &module);
BUILD(t, WASM_F32_DIV(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(92, jsfunc, 46, 0.5);
EXPECT_CALL(64, jsfunc, -16, -0.25);
......@@ -158,7 +130,7 @@ TEST(Run_Float64Add_jswrapped) {
TestingModule module;
WasmFunctionCompiler t(sigs.d_dd(), &module);
BUILD(t, WASM_F64_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(3, jsfunc, 2, 1);
EXPECT_CALL(-5.5, jsfunc, -5.25, -0.25);
......@@ -170,13 +142,11 @@ TEST(Run_I32Popcount_jswrapped) {
TestingModule module;
WasmFunctionCompiler t(sigs.i_i(), &module);
BUILD(t, WASM_I32_POPCNT(WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(2, jsfunc, 9, 0);
EXPECT_CALL(3, jsfunc, 11, 0);
EXPECT_CALL(6, jsfunc, 0x3F, 0);
USE(AddJsFunction);
}
......@@ -185,10 +155,10 @@ TEST(Run_CallJS_Add_jswrapped) {
TestingModule module;
WasmFunctionCompiler t(sigs.i_i(), &module);
uint32_t js_index =
AddJsFunction(&module, sigs.i_i(), "(function(a) { return a + 99; })");
module.AddJsFunction(sigs.i_i(), "(function(a) { return a + 99; })");
BUILD(t, WASM_CALL_FUNCTION(js_index, WASM_GET_LOCAL(0)));
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
EXPECT_CALL(101, jsfunc, 2, -8);
EXPECT_CALL(199, jsfunc, 100, -1);
......@@ -223,7 +193,7 @@ void RunJSSelectTest(int which) {
t.Build(&code[0], &code[end]);
}
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
double expected = inputs.arg_d(which);
EXPECT_CALL(expected, jsfunc, 0.0, 0.0);
}
......@@ -260,7 +230,7 @@ void RunWASMSelectTest(int which) {
TestingModule module;
WasmFunctionCompiler t(&sig, &module);
BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = {
isolate->factory()->NewNumber(inputs.arg_d(0)),
......@@ -310,7 +280,7 @@ void RunWASMSelectAlignTest(int num_args, int num_params) {
TestingModule module;
WasmFunctionCompiler t(&sig, &module);
BUILD(t, WASM_GET_LOCAL(which));
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = {isolate->factory()->NewNumber(inputs.arg_d(0)),
isolate->factory()->NewNumber(inputs.arg_d(1)),
......@@ -418,7 +388,7 @@ void RunJSSelectAlignTest(int num_args, int num_params) {
WasmFunctionCompiler t(&sig, &module);
t.Build(&code[0], &code[end]);
Handle<JSFunction> jsfunc = WrapCode(&module, t.CompileAndAdd());
Handle<JSFunction> jsfunc = module.WrapCode(t.CompileAndAdd());
Handle<Object> args[] = {
factory->NewNumber(inputs.arg_d(0)),
......
......@@ -159,7 +159,7 @@ class TestingModule : public ModuleEnv {
rng.NextBytes(raw, end - raw);
}
int AddFunction(FunctionSig* sig, Handle<Code> code) {
uint32_t AddFunction(FunctionSig* sig, Handle<Code> code) {
if (module->functions.size() == 0) {
// TODO(titzer): Reserving space here to avoid the underlying WasmFunction
// structs from moving.
......@@ -173,6 +173,30 @@ class TestingModule : public ModuleEnv {
return index;
}
uint32_t AddJsFunction(FunctionSig* sig, const char* source) {
Handle<JSFunction> jsfunc = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
*v8::Local<v8::Function>::Cast(CompileRun(source))));
uint32_t index = AddFunction(sig, Handle<Code>::null());
Isolate* isolate = module->shared_isolate;
WasmName module_name = {"test", 4};
WasmName function_name = {nullptr, 0};
Handle<Code> code = CompileWasmToJSWrapper(isolate, this, jsfunc, sig,
module_name, function_name);
instance->function_code[index] = code;
return index;
}
Handle<JSFunction> WrapCode(uint32_t index) {
Isolate* isolate = module->shared_isolate;
// Wrap the code so it can be called as a JS function.
Handle<String> name = isolate->factory()->NewStringFromStaticChars("main");
Handle<JSObject> module_object = Handle<JSObject>(0, isolate);
Handle<Code> code = instance->function_code[index];
WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context());
return compiler::CompileJSToWasmWrapper(isolate, this, name, code,
module_object, index);
}
void SetFunctionCode(uint32_t index, Handle<Code> code) {
instance->function_code[index] = code;
}
......
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