ladybird/Userland/Libraries/LibJS/Bytecode/Register.h
sin-ack 3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00

51 lines
1.1 KiB
C++

/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Format.h>
namespace JS::Bytecode {
class Register {
public:
constexpr static u32 accumulator_index = 0;
constexpr static u32 global_object_index = 1;
static Register accumulator()
{
static Register accumulator(accumulator_index);
return accumulator;
}
static Register global_object()
{
static Register global_object(global_object_index);
return global_object;
}
explicit Register(u32 index)
: m_index(index)
{
}
u32 index() const { return m_index; }
private:
u32 m_index;
};
}
template<>
struct AK::Formatter<JS::Bytecode::Register> : AK::Formatter<FormatString> {
ErrorOr<void> format(FormatBuilder& builder, JS::Bytecode::Register const& value)
{
if (value.index() == JS::Bytecode::Register::accumulator_index)
return builder.put_string("acc"sv);
return AK::Formatter<FormatString>::format(builder, "${}"sv, value.index());
}
};