From 686ee85448eeea8e61bb7655bb2fa86da292f0a7 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 23 Dec 2025 15:10:35 +0100 Subject: kapi/memory: make address printable --- kapi/include/kapi/memory/address.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kapi/include/kapi/memory/address.hpp b/kapi/include/kapi/memory/address.hpp index d5496e4..4fdaf5a 100644 --- a/kapi/include/kapi/memory/address.hpp +++ b/kapi/include/kapi/memory/address.hpp @@ -3,10 +3,13 @@ // IWYU pragma: private, include "kapi/memory.hpp" +#include + #include #include #include #include +#include namespace teachos::memory { @@ -98,4 +101,32 @@ namespace teachos::memory } // namespace teachos::memory +namespace kstd +{ + + template + struct formatter> : kstd::formatter + { + constexpr auto static suffix = Type == teachos::memory::address_type::linear ? "%lin" : "%phy"; + + constexpr auto parse(std::string_view context) -> std::string_view + { + auto result = formatter::parse(context); + if (!this->specs.type) + { + this->specs.type = 'p'; + this->specs.alternative_form = true; + } + return result; + } + + auto format(teachos::memory::address const & address, format_context & context) const -> void + { + formatter::format(address.raw(), context); + context.push(suffix); + } + }; + +} // namespace kstd + #endif \ No newline at end of file -- cgit v1.2.3