oaknut: Add ptr accessor to Label

Accesses the underlying `m_addr` for a `Label`. Allows client code to
derive the actual memory location of a `Label`. Also adds `is_bound` to
ensure the Label has an actual address.
This commit is contained in:
Wunkolo 2023-09-20 10:06:30 -07:00 committed by merry
parent bccb06669f
commit 4af500cb5b

View file

@ -53,6 +53,18 @@ struct Label {
public:
Label() = default;
bool is_bound() const
{
return m_addr.has_value();
}
template<typename T>
T ptr() const
{
static_assert(std::is_pointer_v<T> || std::is_same_v<T, std::uintptr_t> || std::is_same_v<T, std::intptr_t>);
return reinterpret_cast<T>(m_addr.value());
}
private:
template<typename Policy>
friend class BasicCodeGenerator;