Lately I've been reading the rustc development guide https://rustc-dev-guide.rust-lang.org/ . Not because I want to contribute, but out of interest. Now I wanted to play with this knowledge a little bit, but got stuck trying to alter the MIR Body of a function.
What I am trying to accomplish is to add an new Basic Block into the MIR, which has a Terminator of kind TerminatorKind::InlineAsm. Ultimately I want this to have the same effect like having an inline assembly expression
asm!(".."); in the source code, but only by changing the MIR.
The Problem I have is that in order to create a
Terminator of kind
TerminatorKind::InlineAsm for the Basic Block, an argument
template: &'tcx [InlineAsmTemplatePiece] is required. And I don't know the right way to create an
InlineAsmTemplatePiece with the appropriate lifetime, being
'tcx. I assume that I have to store an instance of
InlineAsmTemplatePiece somehow in the Typing Context
TyCtxt and then use it, but I don't know how.
I am using a custom MirPass and the visitor pattern to achieve this task.