1
Fork 0

add span to terminator

This commit is contained in:
ouz-a 2023-09-30 16:52:10 +03:00
commit 999a354a81
2 changed files with 76 additions and 39 deletions

View file

@ -815,9 +815,14 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T { fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
use rustc_middle::mir::TerminatorKind::*; use rustc_middle::mir::TerminatorKind::*;
use stable_mir::mir::Terminator; use stable_mir::mir::Terminator;
use stable_mir::mir::TerminatorKind;
match &self.kind { match &self.kind {
Goto { target } => Terminator::Goto { target: target.as_usize() }, Goto { target } => Terminator {
SwitchInt { discr, targets } => Terminator::SwitchInt { kind: TerminatorKind::Goto { target: target.as_usize() },
span: self.source_info.span.stable(tables),
},
SwitchInt { discr, targets } => Terminator {
kind: TerminatorKind::SwitchInt {
discr: discr.stable(tables), discr: discr.stable(tables),
targets: targets targets: targets
.iter() .iter()
@ -828,39 +833,65 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
.collect(), .collect(),
otherwise: targets.otherwise().as_usize(), otherwise: targets.otherwise().as_usize(),
}, },
UnwindResume => Terminator::Resume, span: self.source_info.span.stable(tables),
UnwindTerminate(_) => Terminator::Abort, },
Return => Terminator::Return, UnwindResume => Terminator {
Unreachable => Terminator::Unreachable, kind: TerminatorKind::Resume,
Drop { place, target, unwind, replace: _ } => Terminator::Drop { span: self.source_info.span.stable(tables),
},
UnwindTerminate(_) => Terminator {
kind: TerminatorKind::Abort,
span: self.source_info.span.stable(tables),
},
Return => Terminator {
kind: TerminatorKind::Return,
span: self.source_info.span.stable(tables),
},
Unreachable => Terminator {
kind: TerminatorKind::Unreachable,
span: self.source_info.span.stable(tables),
},
Drop { place, target, unwind, replace: _ } => Terminator {
kind: TerminatorKind::Drop {
place: place.stable(tables), place: place.stable(tables),
target: target.as_usize(), target: target.as_usize(),
unwind: unwind.stable(tables), unwind: unwind.stable(tables),
}, },
span: self.source_info.span.stable(tables),
},
Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => { Call { func, args, destination, target, unwind, call_source: _, fn_span: _ } => {
Terminator::Call { Terminator {
kind: TerminatorKind::Call {
func: func.stable(tables), func: func.stable(tables),
args: args.iter().map(|arg| arg.stable(tables)).collect(), args: args.iter().map(|arg| arg.stable(tables)).collect(),
destination: destination.stable(tables), destination: destination.stable(tables),
target: target.map(|t| t.as_usize()), target: target.map(|t| t.as_usize()),
unwind: unwind.stable(tables), unwind: unwind.stable(tables),
},
span: self.source_info.span.stable(tables),
} }
} }
Assert { cond, expected, msg, target, unwind } => Terminator::Assert { Assert { cond, expected, msg, target, unwind } => Terminator {
kind: TerminatorKind::Assert {
cond: cond.stable(tables), cond: cond.stable(tables),
expected: *expected, expected: *expected,
msg: msg.stable(tables), msg: msg.stable(tables),
target: target.as_usize(), target: target.as_usize(),
unwind: unwind.stable(tables), unwind: unwind.stable(tables),
}, },
span: self.source_info.span.stable(tables),
},
InlineAsm { template, operands, options, line_spans, destination, unwind } => { InlineAsm { template, operands, options, line_spans, destination, unwind } => {
Terminator::InlineAsm { Terminator {
kind: TerminatorKind::InlineAsm {
template: format!("{template:?}"), template: format!("{template:?}"),
operands: operands.iter().map(|operand| operand.stable(tables)).collect(), operands: operands.iter().map(|operand| operand.stable(tables)).collect(),
options: format!("{options:?}"), options: format!("{options:?}"),
line_spans: format!("{line_spans:?}"), line_spans: format!("{line_spans:?}"),
destination: destination.map(|d| d.as_usize()), destination: destination.map(|d| d.as_usize()),
unwind: unwind.stable(tables), unwind: unwind.stable(tables),
},
span: self.source_info.span.stable(tables),
} }
} }
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(), Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),

View file

@ -21,7 +21,13 @@ pub struct BasicBlock {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum Terminator { pub struct Terminator {
pub kind: TerminatorKind,
pub span: Span,
}
#[derive(Clone, Debug)]
pub enum TerminatorKind {
Goto { Goto {
target: usize, target: usize,
}, },