diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-05-18 00:24:51 +0430 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-21 00:15:23 +0100 |
commit | 8cbdcffd05a7179ab20c49b1f058aa1a500faa58 (patch) | |
tree | c5372790e20baced51081b4d5c610b5779fd663a /Userland/Libraries | |
parent | 207379165f277cba25e3fce9032d93d6d66239a3 (diff) | |
download | serenity-8cbdcffd05a7179ab20c49b1f058aa1a500faa58.zip |
LibWasm: Print instruction arguments too
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibWasm/Printer/Printer.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWasm/Printer/Printer.cpp b/Userland/Libraries/LibWasm/Printer/Printer.cpp index 7fd0c3eda2..0fb8ff4412 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<u8>()) + if (instruction.arguments().has<u8>()) { 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<ValueType>&) { 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"); } |