Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn debug module into macros
Browse files Browse the repository at this point in the history
axic committed Jun 4, 2019
1 parent 61d2ff9 commit 3929527
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
@@ -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)]
::print32($e)
};
}

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

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

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

0 comments on commit 3929527

Please sign in to comment.