Commit 4e55cbf7 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Make DisassembleFunction a method of WasmCompiledModule

Before, it was a method in wasm namespace, and received a
Handle<WasmCompiledModule>. As it does not allocate on the heap, we can
just make it a non-static method on WasmCompiledModule.

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2536373007
Cr-Commit-Position: refs/heads/master@{#41429}
parent 51b32c46
......@@ -9161,7 +9161,7 @@ DebugInterface::DisassembleWasmFunction(Isolate* v8_isolate,
if (script->type() != i::Script::TYPE_WASM) return {};
i::Handle<i::WasmCompiledModule> compiled_module(
i::WasmCompiledModule::cast(script->wasm_compiled_module()), isolate);
return i::wasm::DisassembleFunction(compiled_module, function_index);
return compiled_module->DisassembleFunction(function_index);
}
MaybeLocal<UnboundScript> DebugInterface::CompileInspectorScript(
......
......@@ -20,7 +20,6 @@
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-result.h"
#include "src/wasm/wasm-text.h"
#include "src/compiler/wasm-compiler.h"
......@@ -1999,31 +1998,6 @@ Handle<Script> wasm::GetScript(Handle<JSObject> instance) {
return compiled_module->script();
}
// TODO(clemensh): Make this a non-static method of WasmCompiledModule.
std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>>
wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module,
int func_index) {
DisallowHeapAllocation no_gc;
if (func_index < 0 ||
static_cast<uint32_t>(func_index) >=
compiled_module->module()->functions.size())
return {};
SeqOneByteString* module_bytes_str = compiled_module->ptr_to_module_bytes();
Vector<const byte> module_bytes(module_bytes_str->GetChars(),
module_bytes_str->length());
std::ostringstream disassembly_os;
std::vector<std::tuple<uint32_t, int, int>> offset_table;
PrintWasmText(compiled_module->module(), module_bytes,
static_cast<uint32_t>(func_index), disassembly_os,
&offset_table);
return {disassembly_os.str(), std::move(offset_table)};
}
Handle<WasmDebugInfo> wasm::GetDebugInfo(Handle<JSObject> object) {
auto instance = Handle<WasmInstanceObject>::cast(object);
if (instance->has_debug_info()) {
......
......@@ -410,14 +410,6 @@ bool WasmIsAsmJs(Object* instance, Isolate* isolate);
// it's of type TYPE_WASM.
Handle<Script> GetScript(Handle<JSObject> instance);
// Compute the disassembly of a wasm function.
// Returns the disassembly string and a list of <byte_offset, line, column>
// entries, mapping wasm byte offsets to line and column in the disassembly.
// The list is guaranteed to be ordered by the byte_offset.
// Returns an empty string and empty vector if the function index is invalid.
std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>>
DisassembleFunction(Handle<WasmCompiledModule> compiled_module, int func_index);
V8_EXPORT_PRIVATE MaybeHandle<WasmModuleObject> CreateModuleObjectFromBytes(
Isolate* isolate, const byte* start, const byte* end, ErrorThrower* thrower,
ModuleOrigin origin, Handle<Script> asm_js_script,
......
......@@ -6,6 +6,7 @@
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-text.h"
#define TRACE(...) \
do { \
......@@ -539,6 +540,27 @@ int WasmCompiledModule::GetAsmJsSourcePosition(
return offset_table->get_int(2 * left + 1);
}
std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>>
WasmCompiledModule::DisassembleFunction(int func_index) {
DisallowHeapAllocation no_gc;
if (func_index < 0 ||
static_cast<uint32_t>(func_index) >= module()->functions.size())
return {};
SeqOneByteString* module_bytes_str = ptr_to_module_bytes();
Vector<const byte> module_bytes(module_bytes_str->GetChars(),
module_bytes_str->length());
std::ostringstream disassembly_os;
std::vector<std::tuple<uint32_t, int, int>> offset_table;
PrintWasmText(module(), module_bytes, static_cast<uint32_t>(func_index),
disassembly_os, &offset_table);
return {disassembly_os.str(), std::move(offset_table)};
}
Handle<WasmInstanceWrapper> WasmInstanceWrapper::New(
Isolate* isolate, Handle<WasmInstanceObject> instance) {
Handle<FixedArray> array =
......
......@@ -297,6 +297,14 @@ class WasmCompiledModule : public FixedArray {
static int GetAsmJsSourcePosition(Handle<WasmCompiledModule> debug_info,
uint32_t func_index, uint32_t byte_offset);
// Compute the disassembly of a wasm function.
// Returns the disassembly string and a list of <byte_offset, line, column>
// entries, mapping wasm byte offsets to line and column in the disassembly.
// The list is guaranteed to be ordered by the byte_offset.
// Returns an empty string and empty vector if the function index is invalid.
std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>>
DisassembleFunction(int func_index);
private:
void InitId();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment