Open
Description
Related to this comment.
Maybe related to #93332
This feature request targets the inline assembly macro asm!
and globally scope assembly global_asm!
to support direct string interpolation into the assembly template.
The semantic works very much like a format!
in a narrower sense, that only constant string is supported. The proposed macro word is interpolate $expr
where $expr
is a const-evaluatable expression that yields a &'static str
constant value.
An example of how it would work is as follows.
trait Helper {
const SRC: &'static str;
}
fn make_it_work<H: Helper>(h: &H, x: i64) {
asm!(
"mov {0}, {1}",
in(reg) x,
interpolate H::SRC
);
}
struct H;
impl Helper for H {
const SRC: &'static str = "MAGIC";
}
fn invoke() {
make_it_work(&H, 42);
}
The one and only instantiation of asm!
macro, when completely expanded through codegen, might have yield the following assembly line.
mov rcx, MAGIC