Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: test/cctest/wasm/wasm-module-runner.cc

Issue 2320723005: [wasm] Compilation/Instantiation pipeline works off module object (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/wasm/wasm-module-runner.h ('k') | test/fuzzer/wasm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 "test/cctest/wasm/wasm-module-runner.h" 5 #include "test/cctest/wasm/wasm-module-runner.h"
6 6
7 #include "src/handles.h" 7 #include "src/handles.h"
8 #include "src/isolate.h" 8 #include "src/isolate.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 #include "src/property-descriptor.h" 10 #include "src/property-descriptor.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 52
53 if (module->import_table.size() > 0) { 53 if (module->import_table.size() > 0) {
54 thrower.Error("Not supported: module has imports."); 54 thrower.Error("Not supported: module has imports.");
55 } 55 }
56 if (module->export_table.size() == 0) { 56 if (module->export_table.size() == 0) {
57 thrower.Error("Not supported: module has no exports."); 57 thrower.Error("Not supported: module has no exports.");
58 } 58 }
59 59
60 if (thrower.error()) return Handle<JSObject>::null(); 60 if (thrower.error()) return Handle<JSObject>::null();
61 61
62 MaybeHandle<FixedArray> compiled_module = 62 // Although we decoded the module for some pre-validation, run the bytes
63 module->CompileFunctions(isolate, &thrower); 63 // again through the normal pipeline.
64 64 MaybeHandle<JSObject> module_object = CreateModuleObjectFromBytes(
65 if (compiled_module.is_null()) return Handle<JSObject>::null(); 65 isolate, module->module_start, module->module_end, &thrower,
66 return WasmModule::Instantiate(isolate, compiled_module.ToHandleChecked(), 66 ModuleOrigin::kWasmOrigin);
67 if (module_object.is_null()) return Handle<JSObject>::null();
68 return WasmModule::Instantiate(isolate, module_object.ToHandleChecked(),
67 Handle<JSReceiver>::null(), 69 Handle<JSReceiver>::null(),
68 Handle<JSArrayBuffer>::null()) 70 Handle<JSArrayBuffer>::null())
69 .ToHandleChecked(); 71 .ToHandleChecked();
70 } 72 }
71 73
72 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, 74 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start,
73 const byte* module_end, bool asm_js) { 75 const byte* module_end, ModuleOrigin origin) {
74 HandleScope scope(isolate); 76 HandleScope scope(isolate);
75 Zone zone(isolate->allocator()); 77 Zone zone(isolate->allocator());
76 78
77 ErrorThrower thrower(isolate, "CompileAndRunWasmModule"); 79 ErrorThrower thrower(isolate, "CompileAndRunWasmModule");
78 std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting( 80 std::unique_ptr<const WasmModule> module(DecodeWasmModuleForTesting(
79 isolate, &zone, thrower, module_start, module_end, 81 isolate, &zone, thrower, module_start, module_end, origin));
80 asm_js ? kAsmJsOrigin : kWasmOrigin));
81 82
82 if (module == nullptr) { 83 if (module == nullptr) {
83 return -1; 84 return -1;
84 } 85 }
85 Handle<JSObject> instance = 86 Handle<JSObject> instance =
86 InstantiateModuleForTesting(isolate, thrower, module.get()); 87 InstantiateModuleForTesting(isolate, thrower, module.get());
87 if (instance.is_null()) { 88 if (instance.is_null()) {
88 return -1; 89 return -1;
89 } 90 }
90 return CallWasmFunctionForTesting(isolate, instance, thrower, 91 const char* f_name = origin == ModuleOrigin::kAsmJsOrigin ? "caller" : "main";
91 asm_js ? "caller" : "main", 0, nullptr, 92 return CallWasmFunctionForTesting(isolate, instance, thrower, f_name, 0,
92 asm_js); 93 nullptr, origin);
93 } 94 }
94 95
95 int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower& thrower, 96 int32_t InterpretWasmModule(Isolate* isolate, ErrorThrower& thrower,
96 const WasmModule* module, int function_index, 97 const WasmModule* module, int function_index,
97 WasmVal* args) { 98 WasmVal* args) {
98 CHECK(module != nullptr); 99 CHECK(module != nullptr);
99 100
100 Zone zone(isolate->allocator()); 101 Zone zone(isolate->allocator());
101 v8::internal::HandleScope scope(isolate); 102 v8::internal::HandleScope scope(isolate);
102 103
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return 0xdeadbeef; 144 return 0xdeadbeef;
144 } else { 145 } else {
145 thrower.Error("Interpreter did not finish execution within its step bound"); 146 thrower.Error("Interpreter did not finish execution within its step bound");
146 return -1; 147 return -1;
147 } 148 }
148 } 149 }
149 150
150 int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance, 151 int32_t CallWasmFunctionForTesting(Isolate* isolate, Handle<JSObject> instance,
151 ErrorThrower& thrower, const char* name, 152 ErrorThrower& thrower, const char* name,
152 int argc, Handle<Object> argv[], 153 int argc, Handle<Object> argv[],
153 bool asm_js) { 154 ModuleOrigin origin) {
154 Handle<JSObject> exports_object; 155 Handle<JSObject> exports_object;
155 if (asm_js) { 156 if (origin == ModuleOrigin::kAsmJsOrigin) {
156 exports_object = instance; 157 exports_object = instance;
157 } else { 158 } else {
158 Handle<Name> exports = isolate->factory()->InternalizeUtf8String("exports"); 159 Handle<Name> exports = isolate->factory()->InternalizeUtf8String("exports");
159 exports_object = Handle<JSObject>::cast( 160 exports_object = Handle<JSObject>::cast(
160 JSObject::GetProperty(instance, exports).ToHandleChecked()); 161 JSObject::GetProperty(instance, exports).ToHandleChecked());
161 } 162 }
162 Handle<Name> main_name = isolate->factory()->NewStringFromAsciiChecked(name); 163 Handle<Name> main_name = isolate->factory()->NewStringFromAsciiChecked(name);
163 PropertyDescriptor desc; 164 PropertyDescriptor desc;
164 Maybe<bool> property_found = JSReceiver::GetOwnPropertyDescriptor( 165 Maybe<bool> property_found = JSReceiver::GetOwnPropertyDescriptor(
165 isolate, exports_object, main_name, &desc); 166 isolate, exports_object, main_name, &desc);
(...skipping 19 matching lines...) Expand all
185 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); 186 return static_cast<int32_t>(HeapNumber::cast(*result)->value());
186 } 187 }
187 thrower.Error("WASM.compileRun() failed: Return value should be number"); 188 thrower.Error("WASM.compileRun() failed: Return value should be number");
188 return -1; 189 return -1;
189 } 190 }
190 191
191 } // namespace testing 192 } // namespace testing
192 } // namespace wasm 193 } // namespace wasm
193 } // namespace internal 194 } // namespace internal
194 } // namespace v8 195 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/wasm-module-runner.h ('k') | test/fuzzer/wasm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698