Support for const string interpolation into inline assembly
@dingxiangfei2009 is already working on this.
Since Oct 23, 2024.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.