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