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/property-descriptor.h" | 7 #include "src/property-descriptor.h" |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/simulator.h" | 10 #include "src/simulator.h" |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 | 549 |
550 // First pass: compile each function and initialize the code table. | 550 // First pass: compile each function and initialize the code table. |
551 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); | 551 for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); |
552 i++) { | 552 i++) { |
553 const WasmFunction& func = functions[i]; | 553 const WasmFunction& func = functions[i]; |
554 if (thrower.error()) break; | 554 if (thrower.error()) break; |
555 DCHECK_EQ(i, func.func_index); | 555 DCHECK_EQ(i, func.func_index); |
556 | 556 |
557 WasmName str = GetName(func.name_offset, func.name_length); | 557 WasmName str = GetName(func.name_offset, func.name_length); |
558 WasmName str_null = {nullptr, 0}; | 558 WasmName str_null = {nullptr, 0}; |
559 Handle<String> name = factory->InternalizeUtf8String(str); | |
560 Handle<Code> code = Handle<Code>::null(); | 559 Handle<Code> code = Handle<Code>::null(); |
561 Handle<JSFunction> function = Handle<JSFunction>::null(); | 560 Handle<JSFunction> function = Handle<JSFunction>::null(); |
562 if (func.external) { | 561 if (func.external) { |
563 // Lookup external function in FFI object. | 562 // Lookup external function in FFI object. |
564 MaybeHandle<JSFunction> function = | 563 MaybeHandle<JSFunction> function = |
565 LookupFunction(thrower, factory, ffi, i, str, str_null); | 564 LookupFunction(thrower, factory, ffi, i, str, str_null); |
566 if (function.is_null()) return MaybeHandle<JSObject>(); | 565 if (function.is_null()) return MaybeHandle<JSObject>(); |
567 code = compiler::CompileWasmToJSWrapper(isolate, &module_env, | 566 code = compiler::CompileWasmToJSWrapper(isolate, &module_env, |
568 function.ToHandleChecked(), | 567 function.ToHandleChecked(), |
569 func.sig, str, str_null); | 568 func.sig, str, str_null); |
570 } else { | 569 } else { |
571 if (FLAG_wasm_parallel_compilation) { | 570 if (FLAG_wasm_parallel_compilation) { |
572 code = results[i]; | 571 code = results[i]; |
573 } else { | 572 } else { |
574 // Compile the function. | 573 // Compile the function. |
575 code = compiler::CompileWasmFunction(&thrower, isolate, &module_env, | 574 code = compiler::CompileWasmFunction(&thrower, isolate, &module_env, |
576 &func); | 575 &func); |
577 } | 576 } |
578 if (code.is_null()) { | 577 if (code.is_null()) { |
579 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(), | 578 thrower.Error("Compilation of #%d:%.*s failed.", i, str.length(), |
580 str.start()); | 579 str.start()); |
581 return MaybeHandle<JSObject>(); | 580 return MaybeHandle<JSObject>(); |
582 } | 581 } |
583 if (func.exported) { | 582 if (func.exported) { |
583 Handle<String> name = factory->InternalizeUtf8String(str); | |
584 function = compiler::CompileJSToWasmWrapper( | 584 function = compiler::CompileJSToWasmWrapper( |
585 isolate, &module_env, name, code, instance.js_object, i); | 585 isolate, &module_env, name, code, instance.js_object, i); |
586 record_code_size(function->code()); | 586 record_code_size(function->code()); |
587 } | 587 } |
588 } | 588 } |
589 if (!code.is_null()) { | 589 if (!code.is_null()) { |
590 // Install the code into the linker table. | 590 // Install the code into the linker table. |
591 linker.Finish(i, code); | 591 linker.Finish(i, code); |
592 code_table->set(i, *code); | 592 code_table->set(i, *code); |
593 record_code_size(*code); | 593 record_code_size(*code); |
594 } | 594 } |
595 if (func.exported) { | 595 if (!function.is_null()) { |
596 // Exported functions are installed as read-only properties on the | 596 // Exported functions are installed as read-only properties on the |
597 // module. | 597 // module. |
598 desc.set_value(function); | 598 desc.set_value(function); |
599 Maybe<bool> status = JSReceiver::DefineOwnProperty( | 599 Maybe<bool> status = JSReceiver::DefineOwnProperty( |
600 isolate, instance.js_object, name, &desc, Object::THROW_ON_ERROR); | 600 isolate, instance.js_object, JSFunction::GetName(function), &desc, |
titzer
2016/05/12 08:29:14
I think it's better to pull out the name handle in
Clemens Hammacher
2016/05/12 11:21:41
Done.
| |
601 Object::THROW_ON_ERROR); | |
601 if (!status.IsJust()) | 602 if (!status.IsJust()) |
602 thrower.Error("export of %.*s failed.", str.length(), str.start()); | 603 thrower.Error("export of %.*s failed.", str.length(), str.start()); |
603 } | 604 } |
604 } | 605 } |
605 | 606 |
606 // Second pass: patch all direct call sites. | 607 // Second pass: patch all direct call sites. |
607 linker.Link(instance.function_table, this->function_table); | 608 linker.Link(instance.function_table, this->function_table); |
608 instance.js_object->SetInternalField(kWasmModuleFunctionTable, | 609 instance.js_object->SetInternalField(kWasmModuleFunctionTable, |
609 Smi::FromInt(0)); | 610 Smi::FromInt(0)); |
610 | 611 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate()); | 816 wasm->GetInternalField(kWasmFunctionNamesArray), wasm->GetIsolate()); |
816 if (func_names_arr_obj->IsUndefined()) | 817 if (func_names_arr_obj->IsUndefined()) |
817 return func_names_arr_obj; // Return undefined. | 818 return func_names_arr_obj; // Return undefined. |
818 return GetWasmFunctionNameFromTable( | 819 return GetWasmFunctionNameFromTable( |
819 Handle<ByteArray>::cast(func_names_arr_obj), func_index); | 820 Handle<ByteArray>::cast(func_names_arr_obj), func_index); |
820 } | 821 } |
821 | 822 |
822 } // namespace wasm | 823 } // namespace wasm |
823 } // namespace internal | 824 } // namespace internal |
824 } // namespace v8 | 825 } // namespace v8 |
OLD | NEW |