From 15510fb42e03b71e39b42d08dfbc7f7a822a0a1e Mon Sep 17 00:00:00 2001 From: Diego Frias Date: Fri, 2 Aug 2024 17:22:47 -0700 Subject: [PATCH] LibWasm: Simplify downcasting in bytecode interpreter --- .../AbstractMachine/BytecodeInterpreter.cpp | 27 +++++-------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp index 22ecd12bbb4..e32bd3b93fd 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp +++ b/Userland/Libraries/LibWasm/AbstractMachine/BytecodeInterpreter.cpp @@ -30,13 +30,6 @@ namespace Wasm { } \ } while (false) -#define TRAP_IF_NOT_NORETURN(x) \ - do { \ - if (trap_if_not(x, #x##sv)) { \ - dbgln_if(WASM_TRACE_DEBUG, "Trapped because {} failed, at line {}", #x, __LINE__); \ - } \ - } while (false) - void BytecodeInterpreter::interpret(Configuration& configuration) { m_trap = Empty {}; @@ -284,12 +277,9 @@ void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAdd template void BytecodeInterpreter::binary_numeric_operation(Configuration& configuration, Args&&... args) { - auto rhs_entry = configuration.stack().pop(); + auto rhs = configuration.stack().pop().get().to(); auto& lhs_entry = configuration.stack().peek(); - auto rhs_ptr = rhs_entry.get_pointer(); - auto lhs_ptr = lhs_entry.get_pointer(); - auto rhs = rhs_ptr->to(); - auto lhs = lhs_ptr->to(); + auto lhs = lhs_entry.get().to(); PushType result; auto call_result = Operator { forward(args)... }(lhs.value(), rhs.value()); if constexpr (IsSpecializationOf) { @@ -309,8 +299,7 @@ template(); - auto value = entry_ptr->to(); + auto value = entry.get().to(); auto call_result = Operator { forward(args)... }(*value); PushType result; if constexpr (IsSpecializationOf) { @@ -433,13 +422,9 @@ Vector BytecodeInterpreter::pop_values(Configuration& configuration, size Vector results; results.resize(count); - for (size_t i = 0; i < count; ++i) { - auto top_of_stack = configuration.stack().pop(); - if (auto value = top_of_stack.get_pointer()) - results[i] = move(*value); - else - TRAP_IF_NOT_NORETURN(value); - } + for (size_t i = 0; i < count; ++i) + results[i] = configuration.stack().pop().get(); + return results; }