Commit 1545a716 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by V8 LUCI CQ

[wasm] Add ModuleDisassembler

Unused as of this CL; users will follow.

Bug: v8:12917
Change-Id: I6c615fc53e782f7f00c8a20a00aabea08f3e4605
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3742699Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81566}
parent a4fdd9f5
......@@ -15,6 +15,7 @@
#include "src/wasm/names-provider.h"
#include "src/wasm/string-builder-multiline.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/zone/zone.h"
namespace v8 {
namespace internal {
......@@ -28,6 +29,7 @@ using IndexAsComment = NamesProvider::IndexAsComment;
////////////////////////////////////////////////////////////////////////////////
// Configuration flags for aspects of behavior where we might want to change
// our minds. {true} is the legacy DevTools behavior.
constexpr bool kSkipFunctionTypesInTypeSection = true;
constexpr IndexAsComment kIndicesAsComments = NamesProvider::kIndexAsComment;
constexpr bool kSkipDataSegmentNames = true;
......@@ -118,6 +120,47 @@ class FunctionBodyDisassembler : public WasmDecoder<Decoder::kFullValidation> {
uint32_t label_generation_index_ = 0;
};
////////////////////////////////////////////////////////////////////////////////
// ModuleDisassembler.
class ModuleDisassembler {
public:
ModuleDisassembler(MultiLineStringBuilder& out, const WasmModule* module,
NamesProvider* names, const ModuleWireBytes wire_bytes,
AccountingAllocator* allocator)
: out_(out),
module_(module),
names_(names),
wire_bytes_(wire_bytes),
start_(wire_bytes_.start()),
zone_(allocator, "disassembler zone") {}
void PrintTypeDefinition(uint32_t type_index, Indentation indendation,
IndexAsComment index_as_comment);
void PrintModule(Indentation indentation);
private:
void PrintImportName(const WasmImport& import);
void PrintExportName(ImportExportKindCode kind, uint32_t index);
void PrintMutableType(bool mutability, ValueType type);
void PrintTable(const WasmTable& table);
void PrintMemory();
void PrintGlobal(const WasmGlobal& global);
void PrintInitExpression(const ConstantExpression& init,
ValueType expected_type);
void PrintTagSignature(const FunctionSig* sig);
void PrintString(WireBytesRef ref);
void PrintStringAsJSON(WireBytesRef ref);
void LineBreakOrSpace(bool break_lines, Indentation indentation);
MultiLineStringBuilder& out_;
const WasmModule* module_;
NamesProvider* names_;
const ModuleWireBytes wire_bytes_;
const byte* start_;
Zone zone_;
};
} // namespace wasm
} // namespace internal
} // namespace v8
......
This diff is collapsed.
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