1
Fork 0

Implement asm goto in MIR and MIR lowering

This commit is contained in:
Gary Guo 2023-12-26 16:07:35 +00:00
parent b044aaa905
commit 3b1dd1bfa9
13 changed files with 53 additions and 17 deletions

View file

@ -400,6 +400,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
line_spans,
}) => {
use rustc_middle::{mir, thir};
let destination_block = this.cfg.start_new_block();
let mut targets = if options.contains(InlineAsmOptions::NORETURN) {
vec![]
} else {
vec![destination_block]
};
let operands = operands
.into_iter()
.map(|op| match *op {
@ -455,17 +463,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
thir::InlineAsmOperand::SymStatic { def_id } => {
mir::InlineAsmOperand::SymStatic { def_id }
}
thir::InlineAsmOperand::Label { .. } => {
todo!()
thir::InlineAsmOperand::Label { block } => {
let target = this.cfg.start_new_block();
let target_index = targets.len();
targets.push(target);
let tmp = this.get_unit_temp();
let target = unpack!(this.ast_block(tmp, target, block, source_info));
this.cfg.terminate(
target,
source_info,
TerminatorKind::Goto { target: destination_block },
);
mir::InlineAsmOperand::Label { target_index }
}
})
.collect();
if !options.contains(InlineAsmOptions::NORETURN) {
if !expr.ty.is_never() {
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
}
let destination_block = this.cfg.start_new_block();
this.cfg.terminate(
block,
source_info,
@ -474,11 +493,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
operands,
options,
line_spans,
targets: if options.contains(InlineAsmOptions::NORETURN) {
Vec::new()
} else {
vec![destination_block]
},
targets,
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
UnwindAction::Continue
} else {