OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 "src/macro-assembler.h" | 5 #include "src/macro-assembler.h" |
6 #include "src/objects.h" | 6 #include "src/objects.h" |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/simulator.h" | 9 #include "src/simulator.h" |
10 | 10 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 271 |
272 WasmModule::WasmModule() | 272 WasmModule::WasmModule() |
273 : shared_isolate(nullptr), | 273 : shared_isolate(nullptr), |
274 module_start(nullptr), | 274 module_start(nullptr), |
275 module_end(nullptr), | 275 module_end(nullptr), |
276 min_mem_size_log2(0), | 276 min_mem_size_log2(0), |
277 max_mem_size_log2(0), | 277 max_mem_size_log2(0), |
278 mem_export(false), | 278 mem_export(false), |
279 mem_external(false), | 279 mem_external(false), |
280 start_function_index(-1), | 280 start_function_index(-1), |
| 281 origin(kWasmOrigin), |
281 globals(nullptr), | 282 globals(nullptr), |
282 signatures(nullptr), | 283 signatures(nullptr), |
283 functions(nullptr), | 284 functions(nullptr), |
284 data_segments(nullptr), | 285 data_segments(nullptr), |
285 function_table(nullptr), | 286 function_table(nullptr), |
286 import_table(nullptr), | 287 import_table(nullptr), |
287 export_table(nullptr) {} | 288 export_table(nullptr) {} |
288 | 289 |
289 WasmModule::~WasmModule() { | 290 WasmModule::~WasmModule() { |
290 if (globals) delete globals; | 291 if (globals) delete globals; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 //------------------------------------------------------------------------- | 383 //------------------------------------------------------------------------- |
383 // Compile wrappers to imported functions. | 384 // Compile wrappers to imported functions. |
384 //------------------------------------------------------------------------- | 385 //------------------------------------------------------------------------- |
385 uint32_t index = 0; | 386 uint32_t index = 0; |
386 instance.function_table = BuildFunctionTable(isolate, this); | 387 instance.function_table = BuildFunctionTable(isolate, this); |
387 WasmLinker linker(isolate, functions->size()); | 388 WasmLinker linker(isolate, functions->size()); |
388 ModuleEnv module_env; | 389 ModuleEnv module_env; |
389 module_env.module = this; | 390 module_env.module = this; |
390 module_env.instance = &instance; | 391 module_env.instance = &instance; |
391 module_env.linker = &linker; | 392 module_env.linker = &linker; |
392 module_env.asm_js = false; | 393 module_env.origin = origin; |
393 | 394 |
394 if (import_table->size() > 0) { | 395 if (import_table->size() > 0) { |
395 instance.import_code = &import_code; | 396 instance.import_code = &import_code; |
396 instance.import_code->reserve(import_table->size()); | 397 instance.import_code->reserve(import_table->size()); |
397 for (const WasmImport& import : *import_table) { | 398 for (const WasmImport& import : *import_table) { |
398 const char* cstr = GetName(import.function_name_offset); | 399 const char* cstr = GetName(import.function_name_offset); |
399 Handle<String> name = factory->InternalizeUtf8String(cstr); | 400 Handle<String> name = factory->InternalizeUtf8String(cstr); |
400 MaybeHandle<JSFunction> function = | 401 MaybeHandle<JSFunction> function = |
401 LookupFunction(thrower, ffi, index, name, cstr); | 402 LookupFunction(thrower, ffi, index, name, cstr); |
402 if (function.is_null()) return MaybeHandle<JSObject>(); | 403 if (function.is_null()) return MaybeHandle<JSObject>(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 return GetWasmCallDescriptor(zone, function->sig); | 532 return GetWasmCallDescriptor(zone, function->sig); |
532 } | 533 } |
533 | 534 |
534 | 535 |
535 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, | 536 int32_t CompileAndRunWasmModule(Isolate* isolate, const byte* module_start, |
536 const byte* module_end, bool asm_js) { | 537 const byte* module_end, bool asm_js) { |
537 HandleScope scope(isolate); | 538 HandleScope scope(isolate); |
538 Zone zone; | 539 Zone zone; |
539 // Decode the module, but don't verify function bodies, since we'll | 540 // Decode the module, but don't verify function bodies, since we'll |
540 // be compiling them anyway. | 541 // be compiling them anyway. |
541 ModuleResult result = | 542 ModuleResult result = DecodeWasmModule(isolate, &zone, module_start, |
542 DecodeWasmModule(isolate, &zone, module_start, module_end, false, false); | 543 module_end, false, kWasmOrigin); |
543 if (result.failed()) { | 544 if (result.failed()) { |
544 // Module verification failed. throw. | 545 // Module verification failed. throw. |
545 std::ostringstream str; | 546 std::ostringstream str; |
546 str << "WASM.compileRun() failed: " << result; | 547 str << "WASM.compileRun() failed: " << result; |
547 isolate->Throw( | 548 isolate->Throw( |
548 *isolate->factory()->NewStringFromAsciiChecked(str.str().c_str())); | 549 *isolate->factory()->NewStringFromAsciiChecked(str.str().c_str())); |
549 return -1; | 550 return -1; |
550 } | 551 } |
551 | 552 |
552 int32_t retval = CompileAndRunWasmModule(isolate, result.val); | 553 int32_t retval = CompileAndRunWasmModule(isolate, result.val); |
(...skipping 19 matching lines...) Expand all Loading... |
572 | 573 |
573 // Build the function table. | 574 // Build the function table. |
574 instance.function_table = BuildFunctionTable(isolate, module); | 575 instance.function_table = BuildFunctionTable(isolate, module); |
575 | 576 |
576 // Create module environment. | 577 // Create module environment. |
577 WasmLinker linker(isolate, module->functions->size()); | 578 WasmLinker linker(isolate, module->functions->size()); |
578 ModuleEnv module_env; | 579 ModuleEnv module_env; |
579 module_env.module = module; | 580 module_env.module = module; |
580 module_env.instance = &instance; | 581 module_env.instance = &instance; |
581 module_env.linker = &linker; | 582 module_env.linker = &linker; |
582 module_env.asm_js = false; | 583 module_env.origin = module->origin; |
583 | 584 |
584 // Compile all functions. | 585 // Compile all functions. |
585 Handle<Code> main_code = Handle<Code>::null(); // record last code. | 586 Handle<Code> main_code = Handle<Code>::null(); // record last code. |
586 uint32_t index = 0; | 587 uint32_t index = 0; |
587 int main_index = 0; | 588 int main_index = 0; |
588 for (const WasmFunction& func : *module->functions) { | 589 for (const WasmFunction& func : *module->functions) { |
589 DCHECK_EQ(index, func.func_index); | 590 DCHECK_EQ(index, func.func_index); |
590 if (!func.external) { | 591 if (!func.external) { |
591 // Compile the function and install it in the code table. | 592 // Compile the function and install it in the code table. |
592 Handle<Code> code = | 593 Handle<Code> code = |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 } | 633 } |
633 if (result->IsHeapNumber()) { | 634 if (result->IsHeapNumber()) { |
634 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 635 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
635 } | 636 } |
636 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 637 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
637 return -1; | 638 return -1; |
638 } | 639 } |
639 } // namespace wasm | 640 } // namespace wasm |
640 } // namespace internal | 641 } // namespace internal |
641 } // namespace v8 | 642 } // namespace v8 |
OLD | NEW |