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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "src/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/compiler/wasm-compiler.h" | 9 #include "src/compiler/wasm-compiler.h" |
10 #include "src/debug/interface-types.h" | 10 #include "src/debug/interface-types.h" |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
970 } | 970 } |
971 } | 971 } |
972 DCHECK(found == 1); | 972 DCHECK(found == 1); |
973 return code; | 973 return code; |
974 } | 974 } |
975 | 975 |
976 static Handle<Code> CompileImportWrapper(Isolate* isolate, int index, | 976 static Handle<Code> CompileImportWrapper(Isolate* isolate, int index, |
977 FunctionSig* sig, | 977 FunctionSig* sig, |
978 Handle<JSReceiver> target, | 978 Handle<JSReceiver> target, |
979 Handle<String> module_name, | 979 Handle<String> module_name, |
980 MaybeHandle<String> import_name) { | 980 MaybeHandle<String> import_name, |
| 981 ModuleOrigin origin) { |
981 Handle<Code> code; | 982 Handle<Code> code; |
982 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); | 983 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); |
983 if (other_func) { | 984 if (other_func) { |
984 if (sig->Equals(other_func->sig)) { | 985 if (sig->Equals(other_func->sig)) { |
985 // Signature matched. Unwrap the JS->WASM wrapper and return the raw | 986 // Signature matched. Unwrap the JS->WASM wrapper and return the raw |
986 // WASM function code. | 987 // WASM function code. |
987 return UnwrapImportWrapper(target); | 988 return UnwrapImportWrapper(target); |
988 } else { | 989 } else { |
989 return Handle<Code>::null(); | 990 return Handle<Code>::null(); |
990 } | 991 } |
991 } else { | 992 } else { |
992 // Signature mismatch. Compile a new wrapper for the new signature. | 993 // Signature mismatch. Compile a new wrapper for the new signature. |
993 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, | 994 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, |
994 module_name, import_name); | 995 module_name, import_name, origin); |
995 } | 996 } |
996 } | 997 } |
997 | 998 |
998 static void UpdateDispatchTablesInternal(Isolate* isolate, | 999 static void UpdateDispatchTablesInternal(Isolate* isolate, |
999 Handle<FixedArray> dispatch_tables, | 1000 Handle<FixedArray> dispatch_tables, |
1000 int index, WasmFunction* function, | 1001 int index, WasmFunction* function, |
1001 Handle<Code> code) { | 1002 Handle<Code> code) { |
1002 DCHECK_EQ(0, dispatch_tables->length() % 3); | 1003 DCHECK_EQ(0, dispatch_tables->length() % 3); |
1003 for (int i = 0; i < dispatch_tables->length(); i += 3) { | 1004 for (int i = 0; i < dispatch_tables->length(); i += 3) { |
1004 int table_index = Smi::cast(dispatch_tables->get(i + 1))->value(); | 1005 int table_index = Smi::cast(dispatch_tables->get(i + 1))->value(); |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 // Function imports must be callable. | 1542 // Function imports must be callable. |
1542 Handle<Object> function = result.ToHandleChecked(); | 1543 Handle<Object> function = result.ToHandleChecked(); |
1543 if (!function->IsCallable()) { | 1544 if (!function->IsCallable()) { |
1544 ReportFFIError("function import requires a callable", index, | 1545 ReportFFIError("function import requires a callable", index, |
1545 module_name, function_name); | 1546 module_name, function_name); |
1546 return -1; | 1547 return -1; |
1547 } | 1548 } |
1548 | 1549 |
1549 Handle<Code> import_wrapper = CompileImportWrapper( | 1550 Handle<Code> import_wrapper = CompileImportWrapper( |
1550 isolate_, index, module_->functions[import.index].sig, | 1551 isolate_, index, module_->functions[import.index].sig, |
1551 Handle<JSReceiver>::cast(function), module_name, function_name); | 1552 Handle<JSReceiver>::cast(function), module_name, function_name, |
| 1553 module_->origin); |
1552 if (import_wrapper.is_null()) { | 1554 if (import_wrapper.is_null()) { |
1553 ReportFFIError("imported function does not match the expected type", | 1555 ReportFFIError("imported function does not match the expected type", |
1554 index, module_name, function_name); | 1556 index, module_name, function_name); |
1555 return -1; | 1557 return -1; |
1556 } | 1558 } |
1557 code_table->set(num_imported_functions, *import_wrapper); | 1559 code_table->set(num_imported_functions, *import_wrapper); |
1558 RecordStats(isolate_, *import_wrapper); | 1560 RecordStats(isolate_, *import_wrapper); |
1559 num_imported_functions++; | 1561 num_imported_functions++; |
1560 break; | 1562 break; |
1561 } | 1563 } |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2373 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 2375 MaybeHandle<String> WasmCompiledModule::GetFunctionName( |
2374 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 2376 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { |
2375 DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 2377 DCHECK_LT(func_index, compiled_module->module()->functions.size()); |
2376 WasmFunction& function = compiled_module->module()->functions[func_index]; | 2378 WasmFunction& function = compiled_module->module()->functions[func_index]; |
2377 Isolate* isolate = compiled_module->GetIsolate(); | 2379 Isolate* isolate = compiled_module->GetIsolate(); |
2378 MaybeHandle<String> string = ExtractStringFromModuleBytes( | 2380 MaybeHandle<String> string = ExtractStringFromModuleBytes( |
2379 isolate, compiled_module, function.name_offset, function.name_length); | 2381 isolate, compiled_module, function.name_offset, function.name_length); |
2380 if (!string.is_null()) return string.ToHandleChecked(); | 2382 if (!string.is_null()) return string.ToHandleChecked(); |
2381 return {}; | 2383 return {}; |
2382 } | 2384 } |
OLD | NEW |