Skip to content

Commit

Permalink
Turn debug module into macros
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jun 19, 2019
1 parent 92d14a6 commit 97e27e0
Showing 1 changed file with 52 additions and 6 deletions.
58 changes: 52 additions & 6 deletions src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,77 @@ mod native {
}

/// Prints an unsigned 32-bit int.
pub fn print32(value: u32) {
fn print32(value: u32) {
unsafe { native::debug_print32(value) }
}

/// Prints an unsigned 64-bit int.
pub fn print64(value: u64) {
fn print64(value: u64) {
unsafe { native::debug_print64(value) }
}

/// Prints the contents of a slice.
pub fn print_mem(slice: &[u8]) {
fn print_mem(slice: &[u8]) {
unsafe { native::debug_printMem(slice.as_ptr() as *const u32, slice.len() as u32) }
}

/// Prints the contents of a slice in hexadecimal format.
pub fn print_mem_hex(slice: &[u8]) {
fn print_mem_hex(slice: &[u8]) {
unsafe { native::debug_printMemHex(slice.as_ptr() as *const u32, slice.len() as u32) }
}

/// Prints the value of a storage key.
pub fn print_storage(key: &StorageKey) {
fn print_storage(key: &StorageKey) {
unsafe { native::debug_printStorage(key.bytes.as_ptr() as *const u32) }
}

/// Prints the value of a storage key in hexadecimal format.
pub fn print_storage_hex(key: &StorageKey) {
fn print_storage_hex(key: &StorageKey) {
unsafe { native::debug_printStorageHex(key.bytes.as_ptr() as *const u32) }
}

#[macro_export]
macro_rules! print32 {
($e:expr) => {
#[cfg(debug_assertions)]
$crate::debug::native::print32($e)
};
}

#[macro_export]
macro_rules! print64 {
($e:expr) => {
#[cfg(debug_assertions)]
$crate::debug::native::print64($e)
};
}

#[macro_export]
macro_rules! print_mem {
($e:expr) => {
#[cfg(debug_assertions)]
$crate::debug::native::print_mem($e)
};
}

#[macro_export]
macro_rules! print_mem_hex {
($e:expr) => {
#[cfg(debug_assertions)]
$crate::debug::native::print_mem_hex($e)
};
}
#[macro_export]
macro_rules! print_storage {
($e:expr) => {
#[cfg(debug_assertions)]
$crate::debug::native::print_storage($e)
};
}
#[macro_export]
macro_rules! print_storage_hex {
($e:expr) => {
#[cfg(debug_assertions)]
$crate::debug::native::print_storage_hex($e)
};
}

0 comments on commit 97e27e0

Please sign in to comment.