Skip to content

Commit 960d71e

Browse files
authored
Rollup merge of #112395 - spastorino:smir-terminator-3, r=oli-obk
Add Terminator::InlineAsm conversion from MIR to SMIR This is the last variant that needed to be covered for Terminator. As we've discussed with ``@oli-obk`` I've made a lot of it's fields be `String`s. r? ``@oli-obk``
2 parents 17cc282 + 313143b commit 960d71e

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,27 @@ fn rustc_generator_to_generator(
287287
}
288288
}
289289

290+
fn rustc_inline_asm_operand_to_inline_asm_operand(
291+
operand: &rustc_middle::mir::InlineAsmOperand<'_>,
292+
) -> stable_mir::mir::InlineAsmOperand {
293+
use rustc_middle::mir::InlineAsmOperand;
294+
295+
let (in_value, out_place) = match operand {
296+
InlineAsmOperand::In { value, .. } => (Some(rustc_op_to_op(value)), None),
297+
InlineAsmOperand::Out { place, .. } => {
298+
(None, place.map(|place| rustc_place_to_place(&place)))
299+
}
300+
InlineAsmOperand::InOut { in_value, out_place, .. } => {
301+
(Some(rustc_op_to_op(in_value)), out_place.map(|place| rustc_place_to_place(&place)))
302+
}
303+
InlineAsmOperand::Const { .. }
304+
| InlineAsmOperand::SymFn { .. }
305+
| InlineAsmOperand::SymStatic { .. } => (None, None),
306+
};
307+
308+
stable_mir::mir::InlineAsmOperand { in_value, out_place, raw_rpr: format!("{:?}", operand) }
309+
}
310+
290311
fn rustc_terminator_to_terminator(
291312
terminator: &rustc_middle::mir::Terminator<'_>,
292313
) -> stable_mir::mir::Terminator {
@@ -330,7 +351,19 @@ fn rustc_terminator_to_terminator(
330351
target: target.as_usize(),
331352
unwind: rustc_unwind_to_unwind(unwind),
332353
},
333-
InlineAsm { .. } => todo!(),
354+
InlineAsm { template, operands, options, line_spans, destination, unwind } => {
355+
Terminator::InlineAsm {
356+
template: format!("{:?}", template),
357+
operands: operands
358+
.iter()
359+
.map(|operand| rustc_inline_asm_operand_to_inline_asm_operand(operand))
360+
.collect(),
361+
options: format!("{:?}", options),
362+
line_spans: format!("{:?}", line_spans),
363+
destination: destination.map(|d| d.as_usize()),
364+
unwind: rustc_unwind_to_unwind(unwind),
365+
}
366+
}
334367
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
335368
}
336369
}

compiler/rustc_smir/src/stable_mir/mir/body.rs

+17
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,23 @@ pub enum Terminator {
4646
unwind: UnwindAction,
4747
},
4848
GeneratorDrop,
49+
InlineAsm {
50+
template: String,
51+
operands: Vec<InlineAsmOperand>,
52+
options: String,
53+
line_spans: String,
54+
destination: Option<usize>,
55+
unwind: UnwindAction,
56+
},
57+
}
58+
59+
#[derive(Clone, Debug)]
60+
pub struct InlineAsmOperand {
61+
pub in_value: Option<Operand>,
62+
pub out_place: Option<Place>,
63+
// This field has a raw debug representation of MIR's InlineAsmOperand.
64+
// For now we care about place/operand + the rest in a debug format.
65+
pub raw_rpr: String,
4966
}
5067

5168
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)