2018-10-24 02:17:05 +02:00
|
|
|
/// Retrieve a WebAssembly function given a Instance and a FuncIndex
|
|
|
|
/// Example:
|
2018-10-16 17:01:47 +02:00
|
|
|
/// let func: fn(i32) -> i32 = get_instance_function!(instance, func_index);
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! get_instance_function {
|
2018-10-17 11:22:45 +02: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 17:01:47 +02:00
|
|
|
}
|
|
|
|
|
2018-10-17 16:45:24 +02:00
|
|
|
#[macro_export]
|
2018-10-17 16:08:31 +02:00
|
|
|
macro_rules! include_wast2wasm_bytes {
|
|
|
|
($x:expr) => {{
|
|
|
|
use wabt::wat2wasm;
|
2018-11-06 15:51:01 +01:00
|
|
|
const WAST_BYTES: &[u8] = include_bytes!($x);
|
|
|
|
wat2wasm(WAST_BYTES.to_vec()).expect(&format!("Can't convert {} file to wasm", $x))
|
2018-10-17 16:08:31 +02:00
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2018-10-16 17:01:47 +02:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! debug {
|
2018-11-23 00:13:20 -05:00
|
|
|
($fmt:expr) => (if cfg!(debug_assertions) { println!(concat!("Wasmer::", $fmt)) });
|
|
|
|
($fmt:expr, $($arg:tt)*) => (if cfg!(debug_assertions) { println!(concat!("Wasmer::", $fmt, "\n"), $($arg)*) });
|
|
|
|
}
|