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" |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 WasmModule* module = compiled_module->module(); | 590 WasmModule* module = compiled_module->module(); |
591 if (func_index < 0 || | 591 if (func_index < 0 || |
592 static_cast<size_t>(func_index) > module->functions.size()) { | 592 static_cast<size_t>(func_index) > module->functions.size()) { |
593 return {0, 0}; | 593 return {0, 0}; |
594 } | 594 } |
595 WasmFunction& func = module->functions[func_index]; | 595 WasmFunction& func = module->functions[func_index]; |
596 return {static_cast<int>(func.code_start_offset), | 596 return {static_cast<int>(func.code_start_offset), |
597 static_cast<int>(func.code_end_offset - func.code_start_offset)}; | 597 static_cast<int>(func.code_end_offset - func.code_start_offset)}; |
598 } | 598 } |
599 | 599 |
600 Vector<const uint8_t> GetFunctionBytes( | |
601 Handle<WasmCompiledModule> compiled_module, int func_index) { | |
602 int offset, length; | |
603 std::tie(offset, length) = | |
604 GetFunctionOffsetAndLength(compiled_module, func_index); | |
605 return Vector<const uint8_t>( | |
606 compiled_module->module_bytes()->GetChars() + offset, length); | |
607 } | |
608 | |
600 } // namespace | 609 } // namespace |
601 | 610 |
602 const char* wasm::SectionName(WasmSectionCode code) { | 611 const char* wasm::SectionName(WasmSectionCode code) { |
603 switch (code) { | 612 switch (code) { |
604 case kUnknownSectionCode: | 613 case kUnknownSectionCode: |
605 return "Unknown"; | 614 return "Unknown"; |
606 case kTypeSectionCode: | 615 case kTypeSectionCode: |
607 return "Type"; | 616 return "Type"; |
608 case kImportSectionCode: | 617 case kImportSectionCode: |
609 return "Import"; | 618 return "Import"; |
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1874 return compiled_module->has_asm_js_offset_tables(); | 1883 return compiled_module->has_asm_js_offset_tables(); |
1875 } | 1884 } |
1876 | 1885 |
1877 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { | 1886 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { |
1878 DCHECK(IsWasmInstance(*instance)); | 1887 DCHECK(IsWasmInstance(*instance)); |
1879 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); | 1888 WasmCompiledModule* compiled_module = GetCompiledModule(*instance); |
1880 DCHECK(compiled_module->has_script()); | 1889 DCHECK(compiled_module->has_script()); |
1881 return compiled_module->script(); | 1890 return compiled_module->script(); |
1882 } | 1891 } |
1883 | 1892 |
1893 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> | |
1894 wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module, | |
1895 int func_index) { | |
1896 std::ostringstream disassembly_os; | |
1897 std::vector<std::tuple<uint32_t, int, int>> offset_table; | |
1898 | |
1899 Vector<const uint8_t> func_bytes = | |
1900 GetFunctionBytes(compiled_module, func_index); | |
1901 DisallowHeapAllocation no_gc; | |
1902 if (func_bytes.is_empty()) return {}; | |
1903 | |
1904 AccountingAllocator allocator; | |
1905 bool ok = PrintAst( | |
1906 &allocator, FunctionBodyForTesting(func_bytes.start(), func_bytes.end()), | |
1907 disassembly_os, &offset_table); | |
1908 DCHECK(ok); | |
titzer
2016/11/16 14:23:59
Bah, just make it a CHECK() so you don't need the
Clemens Hammacher
2016/11/16 15:21:19
Done.
We only call it for already compiled functio
| |
1909 USE(ok); | |
1910 | |
1911 return {disassembly_os.str(), std::move(offset_table)}; | |
1912 } | |
1913 | |
1884 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, | 1914 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, |
1885 int byte_offset) { | 1915 int byte_offset) { |
1886 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance), | 1916 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance), |
1887 func_index, byte_offset); | 1917 func_index, byte_offset); |
1888 } | 1918 } |
1889 | 1919 |
1890 Handle<SeqOneByteString> wasm::GetWasmBytes(Handle<JSObject> object) { | 1920 Handle<SeqOneByteString> wasm::GetWasmBytes(Handle<JSObject> object) { |
1891 return Handle<WasmInstanceObject>::cast(object) | 1921 return Handle<WasmInstanceObject>::cast(object) |
1892 ->get_compiled_module() | 1922 ->get_compiled_module() |
1893 ->module_bytes(); | 1923 ->module_bytes(); |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2179 MaybeHandle<String> WasmCompiledModule::GetFunctionName( | 2209 MaybeHandle<String> WasmCompiledModule::GetFunctionName( |
2180 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { | 2210 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { |
2181 DCHECK_LT(func_index, compiled_module->module()->functions.size()); | 2211 DCHECK_LT(func_index, compiled_module->module()->functions.size()); |
2182 WasmFunction& function = compiled_module->module()->functions[func_index]; | 2212 WasmFunction& function = compiled_module->module()->functions[func_index]; |
2183 Isolate* isolate = compiled_module->GetIsolate(); | 2213 Isolate* isolate = compiled_module->GetIsolate(); |
2184 MaybeHandle<String> string = ExtractStringFromModuleBytes( | 2214 MaybeHandle<String> string = ExtractStringFromModuleBytes( |
2185 isolate, compiled_module, function.name_offset, function.name_length); | 2215 isolate, compiled_module, function.name_offset, function.name_length); |
2186 if (!string.is_null()) return string.ToHandleChecked(); | 2216 if (!string.is_null()) return string.ToHandleChecked(); |
2187 return {}; | 2217 return {}; |
2188 } | 2218 } |
OLD | NEW |