From 97e27e0f0b5550b545482829a39004205437516b Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 29 May 2019 12:10:16 +0100 Subject: [PATCH] Turn debug module into macros --- src/debug.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index ae2e659..ca8f5d2 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -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) + }; +}