ASM register allocation access

I am writing a compiler extension right now in a proc macro for tool we have in C++. Proc macros seem to be more natural for the syntax we want to express and expand however I need to emit custom ASM! statements that our backend will be slow to support. In c++ I used to do this

asm(".word 0x0000000| (instr_op <<0) | (%N[Rs] << 5)", ...); // standard inout syntax

With the %N being the key bit here. That sequence let me defer that shift until register allocation happened to evaluate this word. However In rust I don't see a way of actually getting the allocated register to do something here. I wanted to know my options to get me close to some syntax similar to this.

let mut x = 0;
unsafe {
asm!( ".long {BITS}", const BITS=const_fn_bitgen(Rs), Rs = inout(reg) x )
}

I.e I need the Rs allocated register. I wasn't unable to directly include the ASM shift operators because the asm! takes a string literal. Maybe my proc macro can generate rather than a const function. Any feedback would be useful

I was silly I think I just needed to try :smiley:

1 Like