| OLD | NEW |
| 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 #ifndef WASM_RUN_UTILS_H | 5 #ifndef WASM_RUN_UTILS_H |
| 6 #define WASM_RUN_UTILS_H | 6 #define WASM_RUN_UTILS_H |
| 7 | 7 |
| 8 #include <setjmp.h> | 8 #include <setjmp.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 uint32_t index = AddFunction(sig, Handle<Code>::null(), nullptr); | 215 uint32_t index = AddFunction(sig, Handle<Code>::null(), nullptr); |
| 216 Handle<Code> code = CompileWasmToJSWrapper( | 216 Handle<Code> code = CompileWasmToJSWrapper( |
| 217 isolate_, jsfunc, sig, index, Handle<String>::null(), | 217 isolate_, jsfunc, sig, index, Handle<String>::null(), |
| 218 Handle<String>::null(), module->origin); | 218 Handle<String>::null(), module->origin); |
| 219 instance->function_code[index] = code; | 219 instance->function_code[index] = code; |
| 220 return index; | 220 return index; |
| 221 } | 221 } |
| 222 | 222 |
| 223 Handle<JSFunction> WrapCode(uint32_t index) { | 223 Handle<JSFunction> WrapCode(uint32_t index) { |
| 224 // Wrap the code so it can be called as a JS function. | 224 // Wrap the code so it can be called as a JS function. |
| 225 Handle<WasmInstanceObject> instance_obj(0, isolate_); | |
| 226 Handle<Code> code = instance->function_code[index]; | 225 Handle<Code> code = instance->function_code[index]; |
| 227 Handle<Code> ret_code = | 226 Handle<Code> ret_code = |
| 228 compiler::CompileJSToWasmWrapper(isolate_, &module_, code, index); | 227 compiler::CompileJSToWasmWrapper(isolate_, &module_, code, index); |
| 229 Handle<JSFunction> ret = WasmExportedFunction::New( | 228 Handle<JSFunction> ret = WasmExportedFunction::New( |
| 230 isolate_, instance_obj, MaybeHandle<String>(), static_cast<int>(index), | 229 isolate_, instance_object(), MaybeHandle<String>(), |
| 230 static_cast<int>(index), |
| 231 static_cast<int>(this->module->functions[index].sig->parameter_count()), | 231 static_cast<int>(this->module->functions[index].sig->parameter_count()), |
| 232 ret_code); | 232 ret_code); |
| 233 |
| 234 // Add weak reference to exported functions. |
| 235 Handle<WasmCompiledModule> compiled_module( |
| 236 instance_object()->compiled_module(), isolate_); |
| 237 Handle<FixedArray> weak_exported_functions = |
| 238 compiled_module->weak_exported_functions(); |
| 239 Handle<WeakCell> weak_fn = isolate_->factory()->NewWeakCell(ret); |
| 240 FixedArray::SetAndGrow(weak_exported_functions, |
| 241 weak_exported_functions->length(), weak_fn); |
| 242 compiled_module->set_weak_exported_functions(weak_exported_functions); |
| 243 |
| 233 return ret; | 244 return ret; |
| 234 } | 245 } |
| 235 | 246 |
| 236 void SetFunctionCode(uint32_t index, Handle<Code> code) { | 247 void SetFunctionCode(uint32_t index, Handle<Code> code) { |
| 237 instance->function_code[index] = code; | 248 instance->function_code[index] = code; |
| 238 } | 249 } |
| 239 | 250 |
| 240 void AddIndirectFunctionTable(uint16_t* function_indexes, | 251 void AddIndirectFunctionTable(uint16_t* function_indexes, |
| 241 uint32_t table_size) { | 252 uint32_t table_size) { |
| 242 module_.function_tables.push_back({table_size, table_size, true, | 253 module_.function_tables.push_back({table_size, table_size, true, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 Handle<WasmSharedModuleData> shared_module_data = | 336 Handle<WasmSharedModuleData> shared_module_data = |
| 326 WasmSharedModuleData::New(isolate_, module_wrapper, empty_string, | 337 WasmSharedModuleData::New(isolate_, module_wrapper, empty_string, |
| 327 script, Handle<ByteArray>::null()); | 338 script, Handle<ByteArray>::null()); |
| 328 Handle<WasmCompiledModule> compiled_module = | 339 Handle<WasmCompiledModule> compiled_module = |
| 329 WasmCompiledModule::New(isolate_, shared_module_data); | 340 WasmCompiledModule::New(isolate_, shared_module_data); |
| 330 // Minimally initialize the compiled module such that IsWasmCompiledModule | 341 // Minimally initialize the compiled module such that IsWasmCompiledModule |
| 331 // passes. | 342 // passes. |
| 332 // If tests need more (correct) information, add it later. | 343 // If tests need more (correct) information, add it later. |
| 333 compiled_module->set_min_mem_pages(0); | 344 compiled_module->set_min_mem_pages(0); |
| 334 compiled_module->set_max_mem_pages(Smi::kMaxValue); | 345 compiled_module->set_max_mem_pages(Smi::kMaxValue); |
| 346 Handle<FixedArray> code_table = isolate_->factory()->NewFixedArray(0); |
| 347 compiled_module->set_code_table(code_table); |
| 348 Handle<FixedArray> weak_exported = isolate_->factory()->NewFixedArray(0); |
| 349 compiled_module->set_weak_exported_functions(weak_exported); |
| 335 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); | 350 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); |
| 336 return WasmInstanceObject::New(isolate_, compiled_module); | 351 return WasmInstanceObject::New(isolate_, compiled_module); |
| 337 } | 352 } |
| 338 }; | 353 }; |
| 339 | 354 |
| 340 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, | 355 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, |
| 341 FunctionSig* sig, | 356 FunctionSig* sig, |
| 342 SourcePositionTable* source_position_table, | 357 SourcePositionTable* source_position_table, |
| 343 const byte* start, const byte* end) { | 358 const byte* start, const byte* end) { |
| 344 compiler::WasmGraphBuilder builder(module, zone, jsgraph, sig, | 359 compiler::WasmGraphBuilder builder(module, zone, jsgraph, sig, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 // Add the code to the interpreter. | 547 // Add the code to the interpreter. |
| 533 CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end)); | 548 CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end)); |
| 534 return; | 549 return; |
| 535 } | 550 } |
| 536 | 551 |
| 537 // Build the TurboFan graph. | 552 // Build the TurboFan graph. |
| 538 TestBuildingGraph(zone(), &jsgraph, testing_module_, sig, | 553 TestBuildingGraph(zone(), &jsgraph, testing_module_, sig, |
| 539 &source_position_table_, start, end); | 554 &source_position_table_, start, end); |
| 540 Handle<Code> code = Compile(); | 555 Handle<Code> code = Compile(); |
| 541 testing_module_->SetFunctionCode(function_index(), code); | 556 testing_module_->SetFunctionCode(function_index(), code); |
| 557 |
| 558 // Add to code table. |
| 559 Handle<WasmCompiledModule> compiled_module( |
| 560 testing_module_->instance_object()->compiled_module(), isolate()); |
| 561 Handle<FixedArray> code_table = compiled_module->code_table(); |
| 562 code_table = FixedArray::SetAndGrow(code_table, function_index(), code); |
| 563 compiled_module->set_code_table(code_table); |
| 542 } | 564 } |
| 543 | 565 |
| 544 byte AllocateLocal(ValueType type) { | 566 byte AllocateLocal(ValueType type) { |
| 545 uint32_t index = local_decls.AddLocals(1, type); | 567 uint32_t index = local_decls.AddLocals(1, type); |
| 546 byte result = static_cast<byte>(index); | 568 byte result = static_cast<byte>(index); |
| 547 DCHECK_EQ(index, result); | 569 DCHECK_EQ(index, result); |
| 548 return result; | 570 return result; |
| 549 } | 571 } |
| 550 | 572 |
| 551 void SetSigIndex(int sig_index) { function_->sig_index = sig_index; } | 573 void SetSigIndex(int sig_index) { function_->sig_index = sig_index; } |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 void RunWasm_##name(WasmExecutionMode execution_mode) | 833 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 812 | 834 |
| 813 #define WASM_EXEC_COMPILED_TEST(name) \ | 835 #define WASM_EXEC_COMPILED_TEST(name) \ |
| 814 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 836 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
| 815 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 837 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
| 816 void RunWasm_##name(WasmExecutionMode execution_mode) | 838 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 817 | 839 |
| 818 } // namespace | 840 } // namespace |
| 819 | 841 |
| 820 #endif | 842 #endif |
| OLD | NEW |