add span to terminator
This commit is contained in:
parent
9130484db9
commit
999a354a81
@ -815,52 +815,83 @@ 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() },
|
||||||
discr: discr.stable(tables),
|
span: self.source_info.span.stable(tables),
|
||||||
targets: targets
|
|
||||||
.iter()
|
|
||||||
.map(|(value, target)| stable_mir::mir::SwitchTarget {
|
|
||||||
value,
|
|
||||||
target: target.as_usize(),
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
otherwise: targets.otherwise().as_usize(),
|
|
||||||
},
|
},
|
||||||
UnwindResume => Terminator::Resume,
|
SwitchInt { discr, targets } => Terminator {
|
||||||
UnwindTerminate(_) => Terminator::Abort,
|
kind: TerminatorKind::SwitchInt {
|
||||||
Return => Terminator::Return,
|
discr: discr.stable(tables),
|
||||||
Unreachable => Terminator::Unreachable,
|
targets: targets
|
||||||
Drop { place, target, unwind, replace: _ } => Terminator::Drop {
|
.iter()
|
||||||
place: place.stable(tables),
|
.map(|(value, target)| stable_mir::mir::SwitchTarget {
|
||||||
target: target.as_usize(),
|
value,
|
||||||
unwind: unwind.stable(tables),
|
target: target.as_usize(),
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
otherwise: targets.otherwise().as_usize(),
|
||||||
|
},
|
||||||
|
span: self.source_info.span.stable(tables),
|
||||||
|
},
|
||||||
|
UnwindResume => Terminator {
|
||||||
|
kind: TerminatorKind::Resume,
|
||||||
|
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),
|
||||||
|
target: target.as_usize(),
|
||||||
|
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 {
|
||||||
func: func.stable(tables),
|
kind: TerminatorKind::Call {
|
||||||
args: args.iter().map(|arg| arg.stable(tables)).collect(),
|
func: func.stable(tables),
|
||||||
destination: destination.stable(tables),
|
args: args.iter().map(|arg| arg.stable(tables)).collect(),
|
||||||
target: target.map(|t| t.as_usize()),
|
destination: destination.stable(tables),
|
||||||
unwind: unwind.stable(tables),
|
target: target.map(|t| t.as_usize()),
|
||||||
|
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 {
|
||||||
cond: cond.stable(tables),
|
kind: TerminatorKind::Assert {
|
||||||
expected: *expected,
|
cond: cond.stable(tables),
|
||||||
msg: msg.stable(tables),
|
expected: *expected,
|
||||||
target: target.as_usize(),
|
msg: msg.stable(tables),
|
||||||
unwind: unwind.stable(tables),
|
target: target.as_usize(),
|
||||||
|
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 {
|
||||||
template: format!("{template:?}"),
|
kind: TerminatorKind::InlineAsm {
|
||||||
operands: operands.iter().map(|operand| operand.stable(tables)).collect(),
|
template: format!("{template:?}"),
|
||||||
options: format!("{options:?}"),
|
operands: operands.iter().map(|operand| operand.stable(tables)).collect(),
|
||||||
line_spans: format!("{line_spans:?}"),
|
options: format!("{options:?}"),
|
||||||
destination: destination.map(|d| d.as_usize()),
|
line_spans: format!("{line_spans:?}"),
|
||||||
unwind: unwind.stable(tables),
|
destination: destination.map(|d| d.as_usize()),
|
||||||
|
unwind: unwind.stable(tables),
|
||||||
|
},
|
||||||
|
span: self.source_info.span.stable(tables),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
|
Yield { .. } | GeneratorDrop | FalseEdge { .. } | FalseUnwind { .. } => unreachable!(),
|
||||||
|
@ -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,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user