Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn debug module into macros #67

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ qimalloc = { version = "0.1", optional = true }
[features]
default = ["std", "wee_alloc"]
std = []
debug = []
experimental = []
eth2 = []
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Other modules are available as well, outside of the prelude. Refer to the docume
`ewasm-rust-api` builds with various feature sets:
- `default`: Builds with `wee_alloc` as the global allocator and with the Rust standard library.
- `qimalloc`: Builds with [qimalloc](https://github.com/wasmx/qimalloc) as the global allocator.
- `debug`: Exposes the debugging interface.
- `experimental`: Exposes the experimental bignum system library API.

To enable specific features include the dependency as follows:
Expand Down
6 changes: 2 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ jobs:
cargo build --release --no-default-features --features qimalloc
# different feature sets
cargo build --release --no-default-features
cargo build --release --features debug
cargo build --release --no-default-features --features debug
cargo build --release --features experimental
cargo build --release --no-default-features --features experimental
cargo build --release --features experimental,debug
cargo build --release --no-default-features --features experimental,debug
cargo build --release --features eth2
cargo build --release --no-default-features --features eth2
cargo build --release --features experimental,eth2
cargo build --release --no-default-features --features experimental,eth2
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)
};
}
3 changes: 0 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//! library.
//! - `qimalloc`: Builds with [qimalloc](https://github.com/wasmx/qimalloc) as the global
//! allocator.
//! - `debug`: Exposes the debugging interface.
//! - `experimental`: Exposes the experimental bignum system library API.
//!
//! # Examples
Expand Down Expand Up @@ -58,7 +57,6 @@ mod utils;

pub mod types;

#[cfg(feature = "debug")]
pub mod debug;

#[cfg(feature = "experimental")]
Expand Down Expand Up @@ -86,7 +84,6 @@ pub mod prelude {
#[cfg(not(feature = "std"))]
pub use crate::convert::*;

#[cfg(feature = "debug")]
pub use crate::debug;

#[cfg(feature = "experimental")]
Expand Down