wasmer/src/macros.rs

27 lines
952 B
Rust
Raw Normal View History

/// Retrieve a WebAssembly function given a Instance and a FuncIndex
/// Example:
2018-10-16 15:01:47 +00:00
/// let func: fn(i32) -> i32 = get_instance_function!(instance, func_index);
#[macro_export]
macro_rules! get_instance_function {
2018-10-17 09:22:45 +00:00
($instance:expr, $func_index:expr) => {{
use std::mem;
let func_addr = $instance.get_function_pointer($func_index);
unsafe { mem::transmute(func_addr) }
}};
2018-10-16 15:01:47 +00:00
}
2018-10-17 14:45:24 +00:00
#[macro_export]
macro_rules! include_wast2wasm_bytes {
($x:expr) => {{
use wabt::wat2wasm;
2018-11-06 14:51:01 +00:00
const WAST_BYTES: &[u8] = include_bytes!($x);
wat2wasm(WAST_BYTES.to_vec()).expect(&format!("Can't convert {} file to wasm", $x))
}};
}
2018-10-16 15:01:47 +00:00
#[macro_export]
macro_rules! debug {
2018-11-26 19:47:33 +00:00
($fmt:expr) => (if cfg!(any(debug_assertions, feature="debug")) { println!(concat!("Wasmer::", $fmt)) });
($fmt:expr, $($arg:tt)*) => (if cfg!(any(debug_assertions, feature="debug")) { println!(concat!("Wasmer::", $fmt, "\n"), $($arg)*) });
2018-11-22 09:43:38 +00:00
}