From 4af500cb5bd2a3ab6745e6c049272be5d6825c18 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Wed, 20 Sep 2023 10:06:30 -0700 Subject: [PATCH] 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. --- include/oaknut/oaknut.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/oaknut/oaknut.hpp b/include/oaknut/oaknut.hpp index 29bd15f..63bb42c 100644 --- a/include/oaknut/oaknut.hpp +++ b/include/oaknut/oaknut.hpp @@ -53,6 +53,18 @@ struct Label { public: Label() = default; + bool is_bound() const + { + return m_addr.has_value(); + } + + template + T ptr() const + { + static_assert(std::is_pointer_v || std::is_same_v || std::is_same_v); + return reinterpret_cast(m_addr.value()); + } + private: template friend class BasicCodeGenerator;