diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-12-23 15:10:35 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-12-23 15:10:35 +0100 |
| commit | 686ee85448eeea8e61bb7655bb2fa86da292f0a7 (patch) | |
| tree | c6520fcb612515105474bc7d9955be86e0f5184f | |
| parent | 90a8c0f72fc115fe25be39b9f761bb62486d61fb (diff) | |
| download | teachos-686ee85448eeea8e61bb7655bb2fa86da292f0a7.tar.xz teachos-686ee85448eeea8e61bb7655bb2fa86da292f0a7.zip | |
kapi/memory: make address printable
| -rw-r--r-- | kapi/include/kapi/memory/address.hpp | 31 |
1 files changed, 31 insertions, 0 deletions
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 <kstd/format> + #include <bit> #include <compare> #include <cstddef> #include <cstdint> +#include <string_view> namespace teachos::memory { @@ -98,4 +101,32 @@ namespace teachos::memory } // namespace teachos::memory +namespace kstd +{ + + template<teachos::memory::address_type Type> + struct formatter<teachos::memory::address<Type>> : kstd::formatter<std::uintptr_t> + { + 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<std::uintptr_t>::parse(context); + if (!this->specs.type) + { + this->specs.type = 'p'; + this->specs.alternative_form = true; + } + return result; + } + + auto format(teachos::memory::address<Type> const & address, format_context & context) const -> void + { + formatter<std::uintptr_t>::format(address.raw(), context); + context.push(suffix); + } + }; + +} // namespace kstd + #endif
\ No newline at end of file |
