Macro r3_portkit::pptext::pp_asm
source · pub macro pp_asm { ( @internal, unprocessed: [{ , $($unprocessed:tt)* }], code: [{ $($code:tt)* }], ) => { ... }, ( @internal, unprocessed: [{}], code: [{ $($code:tt)* }], ) => { ... }, ( @internal, unprocessed: [{ $fragment:tt $($unprocessed:tt)* }], code: [{ $($code:tt)* }], ) => { ... }, ( @done, unprocessed: [{ $($unprocessed:tt)* }], code: [{ $($code:tt)* }], ) => { ... }, ( // TODO: remove `$l:lit` $l:literal $($rest:tt)* ) => { ... }, }
Expand description
Preprocessed asm!
.
Examples
#![feature(decl_macro)]
#[macro_export] // work-around for mysterious macro hygienics behavior
macro_rules! the_ultimate_answer { () => { "42" }; }
// miri doesn't support inline assembly
#[cfg(not(miri))]
unsafe {
let output: usize;
r3_portkit::pptext::pp_asm!(
// The input fragments are simply concatenated. This means `mov`
// would be part of this line comment if it didn't include a line
// break.
"# hoge \n"
if cfg!(target_arch = "x86_64") {
"mov {}, " crate::the_ultimate_answer!()
}
if cfg!(any(target_arch = "aarch64", target_arch = "arm")) {
"mov {}, #" crate::the_ultimate_answer!()
}
if cfg!(any(target_arch = "riscv32", target_arch = "riscv64")) {
"li {}, " crate::the_ultimate_answer!()
},
out(reg) output
);
assert_eq!(output.to_string(), crate::the_ultimate_answer!());
}