mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Add Call terminator to SMIR
This commit is contained in:
parent
7e23d180c1
commit
2f503345b4
@ -128,6 +128,18 @@ fn rustc_place_to_place(place: &rustc_middle::mir::Place<'_>) -> stable_mir::mir
|
||||
stable_mir::mir::Place { local: place.local.as_usize() }
|
||||
}
|
||||
|
||||
fn rustc_unwind_to_unwind(
|
||||
unwind: &rustc_middle::mir::UnwindAction,
|
||||
) -> stable_mir::mir::UnwindAction {
|
||||
use rustc_middle::mir::UnwindAction;
|
||||
match unwind {
|
||||
UnwindAction::Continue => stable_mir::mir::UnwindAction::Continue,
|
||||
UnwindAction::Unreachable => stable_mir::mir::UnwindAction::Unreachable,
|
||||
UnwindAction::Terminate => stable_mir::mir::UnwindAction::Terminate,
|
||||
UnwindAction::Cleanup(bb) => stable_mir::mir::UnwindAction::Cleanup(bb.as_usize()),
|
||||
}
|
||||
}
|
||||
|
||||
fn rustc_terminator_to_terminator(
|
||||
terminator: &rustc_middle::mir::Terminator<'_>,
|
||||
) -> stable_mir::mir::Terminator {
|
||||
@ -151,7 +163,15 @@ fn rustc_terminator_to_terminator(
|
||||
Return => Terminator::Return,
|
||||
Unreachable => Terminator::Unreachable,
|
||||
Drop { .. } => todo!(),
|
||||
Call { .. } => todo!(),
|
||||
Call { func, args, destination, target, unwind, from_hir_call: _, fn_span: _ } => {
|
||||
Terminator::Call {
|
||||
func: rustc_op_to_op(func),
|
||||
args: args.iter().map(|arg| rustc_op_to_op(arg)).collect(),
|
||||
destination: rustc_place_to_place(destination),
|
||||
target: target.map(|t| t.as_usize()),
|
||||
unwind: rustc_unwind_to_unwind(unwind),
|
||||
}
|
||||
}
|
||||
Assert { .. } => todo!(),
|
||||
Yield { .. } => todo!(),
|
||||
GeneratorDrop => todo!(),
|
||||
|
@ -33,7 +33,7 @@ pub enum Terminator {
|
||||
args: Vec<Operand>,
|
||||
destination: Place,
|
||||
target: Option<usize>,
|
||||
cleanup: Option<usize>,
|
||||
unwind: UnwindAction,
|
||||
},
|
||||
Assert {
|
||||
cond: Operand,
|
||||
@ -44,6 +44,14 @@ pub enum Terminator {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum UnwindAction {
|
||||
Continue,
|
||||
Unreachable,
|
||||
Terminate,
|
||||
Cleanup(usize),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Statement {
|
||||
Assign(Place, Operand),
|
||||
|
@ -33,7 +33,6 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
|
||||
|
||||
// Find items in the local crate.
|
||||
let items = stable_mir::all_local_items();
|
||||
assert!(get_item(tcx, &items, (DefKind::Fn, "foo_bar")).is_some());
|
||||
assert!(get_item(tcx, &items, (DefKind::Fn, "foo::bar")).is_some());
|
||||
|
||||
// Find the `std` crate.
|
||||
@ -52,6 +51,15 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
|
||||
stable_mir::mir::Terminator::Return => {}
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
|
||||
let foo_bar = get_item(tcx, &items, (DefKind::Fn, "foo_bar")).unwrap();
|
||||
let body = foo_bar.body();
|
||||
assert_eq!(body.blocks.len(), 4);
|
||||
let block = &body.blocks[0];
|
||||
match &block.terminator {
|
||||
stable_mir::mir::Terminator::Call { .. } => {}
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
}
|
||||
|
||||
// Use internal API to find a function in a crate.
|
||||
|
Loading…
Reference in New Issue
Block a user