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 | 9 |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
11 #include "src/objects.h" | 11 #include "src/objects.h" |
12 #include "src/property-descriptor.h" | 12 #include "src/property-descriptor.h" |
13 #include "src/simulator.h" | 13 #include "src/simulator.h" |
14 #include "src/snapshot/snapshot.h" | 14 #include "src/snapshot/snapshot.h" |
15 #include "src/v8.h" | 15 #include "src/v8.h" |
16 | 16 |
17 #include "src/wasm/ast-decoder.h" | 17 #include "src/wasm/ast-decoder.h" |
18 #include "src/wasm/module-decoder.h" | 18 #include "src/wasm/module-decoder.h" |
19 #include "src/wasm/wasm-js.h" | 19 #include "src/wasm/wasm-js.h" |
20 #include "src/wasm/wasm-module.h" | 20 #include "src/wasm/wasm-module.h" |
21 #include "src/wasm/wasm-objects.h" | 21 #include "src/wasm/wasm-objects.h" |
22 #include "src/wasm/wasm-result.h" | 22 #include "src/wasm/wasm-result.h" |
23 #include "src/wasm/wasm-text.h" | |
24 | 23 |
25 #include "src/compiler/wasm-compiler.h" | 24 #include "src/compiler/wasm-compiler.h" |
26 | 25 |
27 using namespace v8::internal; | 26 using namespace v8::internal; |
28 using namespace v8::internal::wasm; | 27 using namespace v8::internal::wasm; |
29 namespace base = v8::base; | 28 namespace base = v8::base; |
30 | 29 |
31 #define TRACE(...) \ | 30 #define TRACE(...) \ |
32 do { \ | 31 do { \ |
33 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ | 32 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ |
(...skipping 1958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1992 return compiled_module->has_asm_js_offset_table(); | 1991 return compiled_module->has_asm_js_offset_table(); |
1993 } | 1992 } |
1994 | 1993 |
1995 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { | 1994 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { |
1996 WasmCompiledModule* compiled_module = | 1995 WasmCompiledModule* compiled_module = |
1997 WasmInstanceObject::cast(*instance)->get_compiled_module(); | 1996 WasmInstanceObject::cast(*instance)->get_compiled_module(); |
1998 DCHECK(compiled_module->has_script()); | 1997 DCHECK(compiled_module->has_script()); |
1999 return compiled_module->script(); | 1998 return compiled_module->script(); |
2000 } | 1999 } |
2001 | 2000 |
2002 // TODO(clemensh): Make this a non-static method of WasmCompiledModule. | |
2003 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> | |
2004 wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module, | |
2005 int func_index) { | |
2006 DisallowHeapAllocation no_gc; | |
2007 | |
2008 if (func_index < 0 || | |
2009 static_cast<uint32_t>(func_index) >= | |
2010 compiled_module->module()->functions.size()) | |
2011 return {}; | |
2012 | |
2013 SeqOneByteString* module_bytes_str = compiled_module->ptr_to_module_bytes(); | |
2014 Vector<const byte> module_bytes(module_bytes_str->GetChars(), | |
2015 module_bytes_str->length()); | |
2016 | |
2017 std::ostringstream disassembly_os; | |
2018 std::vector<std::tuple<uint32_t, int, int>> offset_table; | |
2019 | |
2020 PrintWasmText(compiled_module->module(), module_bytes, | |
2021 static_cast<uint32_t>(func_index), disassembly_os, | |
2022 &offset_table); | |
2023 | |
2024 return {disassembly_os.str(), std::move(offset_table)}; | |
2025 } | |
2026 | |
2027 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> object) { | 2001 Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> object) { |
2028 auto instance = Handle<WasmInstanceObject>::cast(object); | 2002 auto instance = Handle<WasmInstanceObject>::cast(object); |
2029 if (instance->has_debug_info()) { | 2003 if (instance->has_debug_info()) { |
2030 Handle<WasmDebugInfo> info(instance->get_debug_info(), | 2004 Handle<WasmDebugInfo> info(instance->get_debug_info(), |
2031 instance->GetIsolate()); | 2005 instance->GetIsolate()); |
2032 return info; | 2006 return info; |
2033 } | 2007 } |
2034 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(instance); | 2008 Handle<WasmDebugInfo> new_info = WasmDebugInfo::New(instance); |
2035 instance->set_debug_info(*new_info); | 2009 instance->set_debug_info(*new_info); |
2036 return new_info; | 2010 return new_info; |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2383 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 2357 MaybeHandle<String> WasmCompiledModule::GetFunctionName( |
2384 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 2358 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { |
2385 DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 2359 DCHECK_LT(func_index, compiled_module->module()->functions.size()); |
2386 WasmFunction& function = compiled_module->module()->functions[func_index]; | 2360 WasmFunction& function = compiled_module->module()->functions[func_index]; |
2387 Isolate* isolate = compiled_module->GetIsolate(); | 2361 Isolate* isolate = compiled_module->GetIsolate(); |
2388 MaybeHandle<String> string = ExtractStringFromModuleBytes( | 2362 MaybeHandle<String> string = ExtractStringFromModuleBytes( |
2389 isolate, compiled_module, function.name_offset, function.name_length); | 2363 isolate, compiled_module, function.name_offset, function.name_length); |
2390 if (!string.is_null()) return string.ToHandleChecked(); | 2364 if (!string.is_null()) return string.ToHandleChecked(); |
2391 return {}; | 2365 return {}; |
2392 } | 2366 } |
OLD | NEW |