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