X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_mir_build%2Fsrc%2Fbuild%2Fcustom%2Fparse%2Finstruction.rs;h=03206af33bfb5dc927da6348f64b84f7d4074a08;hb=b64d8670e4c512c29e6a58c73c0aba65f00bb800;hp=6d6176584f5f47d3cadcc769843afea83350679d;hpb=e83b4765c32b783dc7485a9f80ccb47ba893a7dd;p=rust.git diff --git a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs index 6d6176584f5..03206af33bf 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs @@ -1,10 +1,11 @@ +use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::{mir::*, thir::*, ty}; use super::{parse_by_kind, PResult, ParseCtxt}; impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { pub fn parse_statement(&self, expr_id: ExprId) -> PResult> { - parse_by_kind!(self, expr_id, "statement", + parse_by_kind!(self, expr_id, _, "statement", @call("mir_retag", args) => { Ok(StatementKind::Retag(RetagKind::Default, Box::new(self.parse_place(args[0])?))) }, @@ -20,7 +21,7 @@ pub fn parse_statement(&self, expr_id: ExprId) -> PResult> { } pub fn parse_terminator(&self, expr_id: ExprId) -> PResult> { - parse_by_kind!(self, expr_id, "terminator", + parse_by_kind!(self, expr_id, _, "terminator", @call("mir_return", _args) => { Ok(TerminatorKind::Return) }, @@ -31,7 +32,7 @@ pub fn parse_terminator(&self, expr_id: ExprId) -> PResult> } fn parse_rvalue(&self, expr_id: ExprId) -> PResult> { - parse_by_kind!(self, expr_id, "rvalue", + parse_by_kind!(self, expr_id, _, "rvalue", ExprKind::Borrow { borrow_kind, arg } => Ok( Rvalue::Ref(self.tcx.lifetimes.re_erased, *borrow_kind, self.parse_place(*arg)?) ), @@ -43,14 +44,26 @@ fn parse_rvalue(&self, expr_id: ExprId) -> PResult> { } fn parse_operand(&self, expr_id: ExprId) -> PResult> { - parse_by_kind!(self, expr_id, "operand", + parse_by_kind!(self, expr_id, expr, "operand", @call("mir_move", args) => self.parse_place(args[0]).map(Operand::Move), + @call("mir_static", args) => self.parse_static(args[0]), + @call("mir_static_mut", args) => self.parse_static(args[0]), + ExprKind::Literal { .. } + | ExprKind::NamedConst { .. } + | ExprKind::NonHirLiteral { .. } + | ExprKind::ZstLiteral { .. } + | ExprKind::ConstParam { .. } + | ExprKind::ConstBlock { .. } => { + Ok(Operand::Constant(Box::new( + crate::build::expr::as_constant::as_constant_inner(expr, |_| None, self.tcx) + ))) + }, _ => self.parse_place(expr_id).map(Operand::Copy), ) } fn parse_place(&self, expr_id: ExprId) -> PResult> { - parse_by_kind!(self, expr_id, "place", + parse_by_kind!(self, expr_id, _, "place", ExprKind::Deref { arg } => Ok( self.parse_place(*arg)?.project_deeper(&[PlaceElem::Deref], self.tcx) ), @@ -59,14 +72,34 @@ fn parse_place(&self, expr_id: ExprId) -> PResult> { } fn parse_local(&self, expr_id: ExprId) -> PResult { - parse_by_kind!(self, expr_id, "local", + parse_by_kind!(self, expr_id, _, "local", ExprKind::VarRef { id } => Ok(self.local_map[id]), ) } fn parse_block(&self, expr_id: ExprId) -> PResult { - parse_by_kind!(self, expr_id, "basic block", + parse_by_kind!(self, expr_id, _, "basic block", ExprKind::VarRef { id } => Ok(self.block_map[id]), ) } + + fn parse_static(&self, expr_id: ExprId) -> PResult> { + let expr_id = parse_by_kind!(self, expr_id, _, "static", + ExprKind::Deref { arg } => *arg, + ); + + parse_by_kind!(self, expr_id, expr, "static", + ExprKind::StaticRef { alloc_id, ty, .. } => { + let const_val = + ConstValue::Scalar(Scalar::from_pointer((*alloc_id).into(), &self.tcx)); + let literal = ConstantKind::Val(const_val, *ty); + + Ok(Operand::Constant(Box::new(Constant { + span: expr.span, + user_ty: None, + literal + }))) + }, + ) + } }