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