2021-06-04 12:07:38 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
|
2021-06-04 12:07:38 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Format.h>
|
|
|
|
|
|
|
|
namespace JS::Bytecode {
|
|
|
|
|
2024-05-06 07:51:14 +02:00
|
|
|
class BasicBlock;
|
|
|
|
|
2025-07-19 10:41:08 -07:00
|
|
|
class Label {
|
2021-06-04 12:07:38 +02:00
|
|
|
public:
|
2024-05-06 08:06:56 +02:00
|
|
|
explicit Label(BasicBlock const&);
|
|
|
|
|
|
|
|
explicit Label(u32 basic_block_index)
|
|
|
|
: m_address_or_basic_block_index(basic_block_index)
|
2021-06-04 12:07:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-05-06 06:44:08 +02:00
|
|
|
// Used while compiling.
|
2024-05-06 08:06:56 +02:00
|
|
|
size_t basic_block_index() const { return m_address_or_basic_block_index; }
|
2024-05-06 06:44:08 +02:00
|
|
|
|
|
|
|
// Used after compiling.
|
2024-05-06 08:06:56 +02:00
|
|
|
size_t address() const { return m_address_or_basic_block_index; }
|
2024-05-06 06:44:08 +02:00
|
|
|
|
2024-05-06 08:06:56 +02:00
|
|
|
void set_address(size_t address) { m_address_or_basic_block_index = address; }
|
2021-06-04 12:07:38 +02:00
|
|
|
|
|
|
|
private:
|
2024-05-06 08:06:56 +02:00
|
|
|
u32 m_address_or_basic_block_index { 0 };
|
2021-06-04 12:07:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct AK::Formatter<JS::Bytecode::Label> : AK::Formatter<FormatString> {
|
2024-05-06 06:44:08 +02:00
|
|
|
ErrorOr<void> format(FormatBuilder& builder, JS::Bytecode::Label const& label)
|
2021-06-04 12:07:38 +02:00
|
|
|
{
|
2024-05-06 06:44:08 +02:00
|
|
|
return AK::Formatter<FormatString>::format(builder, "@{:x}"sv, label.address());
|
2021-06-04 12:07:38 +02:00
|
|
|
}
|
|
|
|
};
|