Chromium Code Reviews| Index: src/wasm/wasm-module.cc |
| diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc |
| index 79b99fe04d90f0618cfdf557ff3dd10f14809d34..23413a1b9f2ffc28a3e5966c5e989cd40d412e56 100644 |
| --- a/src/wasm/wasm-module.cc |
| +++ b/src/wasm/wasm-module.cc |
| @@ -597,6 +597,15 @@ std::pair<int, int> GetFunctionOffsetAndLength( |
| static_cast<int>(func.code_end_offset - func.code_start_offset)}; |
| } |
| +Vector<const uint8_t> GetFunctionBytes( |
| + Handle<WasmCompiledModule> compiled_module, int func_index) { |
| + int offset, length; |
| + std::tie(offset, length) = |
| + GetFunctionOffsetAndLength(compiled_module, func_index); |
| + return Vector<const uint8_t>( |
| + compiled_module->module_bytes()->GetChars() + offset, length); |
| +} |
| + |
| } // namespace |
| const char* wasm::SectionName(WasmSectionCode code) { |
| @@ -1881,6 +1890,27 @@ Handle<Script> wasm::GetScript(Handle<JSObject> instance) { |
| return compiled_module->script(); |
| } |
| +std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> |
| +wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module, |
| + int func_index) { |
| + std::ostringstream disassembly_os; |
| + std::vector<std::tuple<uint32_t, int, int>> offset_table; |
| + |
| + Vector<const uint8_t> func_bytes = |
| + GetFunctionBytes(compiled_module, func_index); |
| + DisallowHeapAllocation no_gc; |
| + if (func_bytes.is_empty()) return {}; |
| + |
| + AccountingAllocator allocator; |
| + bool ok = PrintAst( |
| + &allocator, FunctionBodyForTesting(func_bytes.start(), func_bytes.end()), |
| + disassembly_os, &offset_table); |
| + 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
|
| + USE(ok); |
| + |
| + return {disassembly_os.str(), std::move(offset_table)}; |
| +} |
| + |
| int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, |
| int byte_offset) { |
| return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance), |