Skip to content

Commit

Permalink
feat(memory): consistent formatting for PAddr/VAddr
Browse files Browse the repository at this point in the history
Closes #101. Sorry y'all, I was tired of waiting.
  • Loading branch information
hawkw committed Jun 6, 2017
1 parent c989b4d commit adebcff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion memory/src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub const HUGE_PAGE_SIZE: u64 = 1024 * 1024 * 1024;

macro_attr! {
/// A physical (linear) memory address is a 64-bit unsigned integer
#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd, Addr!(u64))]
#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd, Addr!(u64, 'P'))]
#[repr(C)]
pub struct PAddr(u64);
}
Expand Down
2 changes: 1 addition & 1 deletion memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub trait Addr: ops::Add<Self> + ops::Sub<Self>

macro_attr! {
/// A virtual address is a machine-sized unsigned integer
#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd, Addr!(usize))]
#[derive(Copy, Clone, Eq, Ord, PartialEq, PartialOrd, Addr!(usize, 'V'))]
pub struct VAddr(usize);
}

Expand Down
16 changes: 8 additions & 8 deletions memory/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@
//! Macros to make our custom address types require a lot less repetitive code.
#[macro_export]
macro_rules! Addr {
(($size:ty) $(pub)* enum $name:ident $($tail:tt)*) => {
Addr! { @impl $name, $size }
(($size:ty, $letter:expr) $(pub)* enum $name:ident $($tail:tt)*) => {
Addr! { @impl $name, $size, $letter }
};
(($size:ty) $(pub)* struct $name:ident $($tail:tt)*) => {
Addr! { @impl $name, $size }
(($size:ty, $letter:expr) $(pub)* struct $name:ident $($tail:tt)*) => {
Addr! { @impl $name, $size, $letter }
};
(@impl $ty:ident, $size:ty) => {
(@impl $ty:ident, $size:ty, $letter:expr) => {

impl ::core::fmt::Debug for $ty {
fn fmt(&self, f: &mut ::core::fmt::Formatter)
-> ::core::fmt::Result {
write!(f, "{}({:#x})", stringify!($ty), self.0)
write!(f, "{}x{:x}", $letter, self.0)
}
}

impl ::core::fmt::Pointer for $ty {
fn fmt(&self, f: &mut ::core::fmt::Formatter)
#[inline] fn fmt(&self, f: &mut ::core::fmt::Formatter)
-> ::core::fmt::Result {
write!(f, "{:#x}", self.0)
write!(f, "{:?}", self)
}
}

Expand Down

0 comments on commit adebcff

Please sign in to comment.