Custom MIR: Support storage statements

This commit is contained in:
Tomasz Miąsko 2023-01-19 00:00:00 +00:00
parent 65d2f2a5f9
commit ca3d55e32d
4 changed files with 17 additions and 5 deletions

View File

@ -12,6 +12,12 @@ use super::{parse_by_kind, PResult, ParseCtxt};
impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
pub fn parse_statement(&self, expr_id: ExprId) -> PResult<StatementKind<'tcx>> {
parse_by_kind!(self, expr_id, _, "statement",
@call("mir_storage_live", args) => {
Ok(StatementKind::StorageLive(self.parse_local(args[0])?))
},
@call("mir_storage_dead", args) => {
Ok(StatementKind::StorageDead(self.parse_local(args[0])?))
},
@call("mir_retag", args) => {
Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?)))
},

View File

@ -259,6 +259,8 @@ define!("mir_unreachable", fn Unreachable() -> BasicBlock);
define!("mir_drop", fn Drop<T>(place: T, goto: BasicBlock));
define!("mir_drop_and_replace", fn DropAndReplace<T>(place: T, value: T, goto: BasicBlock));
define!("mir_call", fn Call<T>(place: T, goto: BasicBlock, call: T));
define!("mir_storage_live", fn StorageLive<T>(local: T));
define!("mir_storage_dead", fn StorageDead<T>(local: T));
define!("mir_retag", fn Retag<T>(place: T));
define!("mir_move", fn Move<T>(place: T) -> T);
define!("mir_static", fn Static<T>(s: T) -> &'static T);

View File

@ -11,12 +11,14 @@ pub fn simple(x: i32) -> i32 {
let temp2: _;
{
StorageLive(temp1);
temp1 = x;
Goto(exit)
}
exit = {
temp2 = Move(temp1);
StorageDead(temp1);
RET = temp2;
Return()
}

View File

@ -6,13 +6,15 @@ fn simple(_1: i32) -> i32 {
let mut _3: i32; // in scope 0 at $SRC_DIR/core/src/intrinsics/mir.rs:LL:COL
bb0: {
_2 = _1; // scope 0 at $DIR/simple_assign.rs:+6:13: +6:22
goto -> bb1; // scope 0 at $DIR/simple_assign.rs:+7:13: +7:23
StorageLive(_2); // scope 0 at $DIR/simple_assign.rs:+6:13: +6:31
_2 = _1; // scope 0 at $DIR/simple_assign.rs:+7:13: +7:22
goto -> bb1; // scope 0 at $DIR/simple_assign.rs:+8:13: +8:23
}
bb1: {
_3 = move _2; // scope 0 at $DIR/simple_assign.rs:+11:13: +11:32
_0 = _3; // scope 0 at $DIR/simple_assign.rs:+12:13: +12:24
return; // scope 0 at $DIR/simple_assign.rs:+13:13: +13:21
_3 = move _2; // scope 0 at $DIR/simple_assign.rs:+12:13: +12:32
StorageDead(_2); // scope 0 at $DIR/simple_assign.rs:+13:13: +13:31
_0 = _3; // scope 0 at $DIR/simple_assign.rs:+14:13: +14:24
return; // scope 0 at $DIR/simple_assign.rs:+15:13: +15:21
}
}