From 23a4448862c55f9206c0054e30c8ca447dd7b850 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 3 Jun 2021 18:29:30 +0200 Subject: [PATCH] LibJS: Add formatting helper for Bytecode::Register --- Userland/Libraries/LibJS/Bytecode/Op.cpp | 10 +++++----- Userland/Libraries/LibJS/Bytecode/Register.h | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index 017edd0f87..b1feea00e4 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -38,27 +38,27 @@ void SetVariable::execute(Bytecode::Interpreter& interpreter) const String Load::to_string() const { - return String::formatted("Load dst:r{}, value:{}", m_dst.index(), m_value.to_string_without_side_effects()); + return String::formatted("Load dst:{}, value:{}", m_dst, m_value.to_string_without_side_effects()); } String Add::to_string() const { - return String::formatted("Add dst:r{}, src1:r{}, src2:r{}", m_dst.index(), m_src1.index(), m_src2.index()); + return String::formatted("Add dst:{}, src1:{}, src2:{}", m_dst, m_src1, m_src2); } String NewString::to_string() const { - return String::formatted("NewString dst:r{}, string:\"{}\"", m_dst.index(), m_string); + return String::formatted("NewString dst:{}, string:\"{}\"", m_dst, m_string); } String GetVariable::to_string() const { - return String::formatted("GetVariable dst:r{}, identifier:{}", m_dst.index(), m_identifier); + return String::formatted("GetVariable dst:{}, identifier:{}", m_dst, m_identifier); } String SetVariable::to_string() const { - return String::formatted("SetVariable identifier:{}, src:r{}", m_identifier, m_src.index()); + return String::formatted("SetVariable identifier:{}, src:{}", m_identifier, m_src); } } diff --git a/Userland/Libraries/LibJS/Bytecode/Register.h b/Userland/Libraries/LibJS/Bytecode/Register.h index b3c8681fd9..d902a6ac86 100644 --- a/Userland/Libraries/LibJS/Bytecode/Register.h +++ b/Userland/Libraries/LibJS/Bytecode/Register.h @@ -6,7 +6,7 @@ #pragma once -#include +#include namespace JS::Bytecode { @@ -24,3 +24,11 @@ private: }; } + +template<> +struct AK::Formatter : AK::Formatter { + void format(FormatBuilder& builder, JS::Bytecode::Register const& value) + { + return AK::Formatter::format(builder, "r{}", value.index()); + } +};