From 8cbdcffd05a7179ab20c49b1f058aa1a500faa58 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 18 May 2021 00:24:51 +0430 Subject: [PATCH] LibWasm: Print instruction arguments too --- .../Libraries/LibWasm/Printer/Printer.cpp | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWasm/Printer/Printer.cpp b/Userland/Libraries/LibWasm/Printer/Printer.cpp index 7fd0c3eda22..0fb8ff44121 100644 --- a/Userland/Libraries/LibWasm/Printer/Printer.cpp +++ b/Userland/Libraries/LibWasm/Printer/Printer.cpp @@ -376,11 +376,12 @@ void Printer::print(const Wasm::GlobalSection::Global& entry) void Printer::print(const Wasm::GlobalType& type) { print_indent(); - print("(type global {}mutable", type.is_mutable() ? "" : "im"); + print("(type global {}mutable\n", type.is_mutable() ? "" : "im"); { TemporaryChange change { m_indent, m_indent + 1 }; print(type.type()); } + print_indent(); print(")\n"); } @@ -418,10 +419,31 @@ void Printer::print(const Wasm::Instruction& instruction) { print_indent(); print("({}", instruction_name(instruction.opcode())); - if (instruction.arguments().has()) + if (instruction.arguments().has()) { print(")\n"); - else - print("...)\n"); + } else { + print(" "); + instruction.arguments().visit( + [&](const BlockType& type) { print(type); }, + [&](const DataIndex& index) { print("(data index {})", index.value()); }, + [&](const ElementIndex& index) { print("(element index {})", index.value()); }, + [&](const FunctionIndex& index) { print("(function index {})", index.value()); }, + [&](const GlobalIndex& index) { print("(global index {})", index.value()); }, + [&](const LabelIndex& index) { print("(label index {})", index.value()); }, + [&](const LocalIndex& index) { print("(local index {})", index.value()); }, + [&](const TableIndex& index) { print("(table index {})", index.value()); }, + [&](const Instruction::IndirectCallArgs& args) { print("(indirect (type index {}) (table index {}))", args.type.value(), args.table.value()); }, + [&](const Instruction::MemoryArgument& args) { print("(memory (align {}) (offset {}))", args.align, args.offset); }, + [&](const Instruction::StructuredInstructionArgs& args) { print("(structured (else {}) (end {}))", args.else_ip.has_value() ? String::number(args.else_ip->value()) : "(none)", args.end_ip.value()); }, + [&](const Instruction::TableBranchArgs&) { print("(table_branch ...)"); }, + [&](const Instruction::TableElementArgs& args) { print("(table_element (table index {}) (element index {}))", args.table_index.value(), args.element_index.value()); }, + [&](const Instruction::TableTableArgs& args) { print("(table_table (table index {}) (table index {}))", args.lhs.value(), args.rhs.value()); }, + [&](const ValueType& type) { print(type); }, + [&](const Vector&) { print("(types...)"); }, + [&](const auto& value) { print("{}", value); }); + + print(")\n"); + } } void Printer::print(const Wasm::Limits& limits) @@ -431,7 +453,7 @@ void Printer::print(const Wasm::Limits& limits) if (limits.max().has_value()) print(" max={}", limits.max().value()); else - print("unbounded"); + print(" unbounded"); print(")\n"); }