diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-07-06 13:01:28 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-06 17:55:00 +0430 |
commit | d2212a1f51b9f3f1917a0acbc33dfb902a46b284 (patch) | |
tree | efc3826621d568f927d6d251f92243650ad993cc | |
parent | f5d4e26ff7e306ed12e11987b5ef05496a04cd65 (diff) | |
download | serenity-d2212a1f51b9f3f1917a0acbc33dfb902a46b284.zip |
LibWasm: Jump to the default label in br_table with negative values
Also adds a forgotten Wasm::Printer implementation for printing table
branch arguments.
-rw-r--r-- | Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibWasm/Printer/Printer.cpp | 7 |
2 files changed, 11 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 8d8d846533..349974afa0 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -617,10 +617,11 @@ void BytecodeInterpreter::interpret(Configuration& configuration, InstructionPoi TRAP_IF_NOT(entry.has<Value>()); auto maybe_i = entry.get<Value>().to<i32>(); TRAP_IF_NOT(maybe_i.has_value()); - TRAP_IF_NOT(maybe_i.value() >= 0); - size_t i = *maybe_i; - if (i < arguments.labels.size()) - return branch_to_label(configuration, arguments.labels[i]); + if (0 <= *maybe_i) { + size_t i = *maybe_i; + if (i < arguments.labels.size()) + return branch_to_label(configuration, arguments.labels[i]); + } return branch_to_label(configuration, arguments.default_); } case Instructions::call.value(): { diff --git a/Userland/Libraries/LibWasm/Printer/Printer.cpp b/Userland/Libraries/LibWasm/Printer/Printer.cpp index 1467545bc6..43411456f8 100644 --- a/Userland/Libraries/LibWasm/Printer/Printer.cpp +++ b/Userland/Libraries/LibWasm/Printer/Printer.cpp @@ -435,7 +435,12 @@ void Printer::print(Wasm::Instruction const& instruction) [&](Instruction::IndirectCallArgs const& args) { print("(indirect (type index {}) (table index {}))", args.type.value(), args.table.value()); }, [&](Instruction::MemoryArgument const& args) { print("(memory (align {}) (offset {}))", args.align, args.offset); }, [&](Instruction::StructuredInstructionArgs const& args) { print("(structured (else {}) (end {}))", args.else_ip.has_value() ? String::number(args.else_ip->value()) : "(none)", args.end_ip.value()); }, - [&](Instruction::TableBranchArgs const&) { print("(table_branch ...)"); }, + [&](Instruction::TableBranchArgs const& args) { + print("(table_branch"); + for (auto& label : args.labels) + print(" (label {})", label.value()); + print(" (label {}))", args.default_.value()); + }, [&](Instruction::TableElementArgs const& args) { print("(table_element (table index {}) (element index {}))", args.table_index.value(), args.element_index.value()); }, [&](Instruction::TableTableArgs const& args) { print("(table_table (table index {}) (table index {}))", args.lhs.value(), args.rhs.value()); }, [&](ValueType const& type) { print(type); }, |