Improve emit stable mir body
This commit is contained in:
parent
3c85e56249
commit
ff504a09fe
9 changed files with 350 additions and 562 deletions
|
@ -10,7 +10,7 @@ use rustc_span::Symbol;
|
|||
use stable_mir::abi::Layout;
|
||||
use stable_mir::mir::alloc::AllocId;
|
||||
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
|
||||
use stable_mir::mir::{Mutability, Safety};
|
||||
use stable_mir::mir::{Mutability, Place, ProjectionElem, Safety};
|
||||
use stable_mir::ty::{
|
||||
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
|
||||
DynKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig,
|
||||
|
@ -492,6 +492,50 @@ impl RustcInternal for Layout {
|
|||
}
|
||||
}
|
||||
|
||||
impl RustcInternal for Place {
|
||||
type T<'tcx> = rustc_middle::mir::Place<'tcx>;
|
||||
|
||||
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
||||
rustc_middle::mir::Place {
|
||||
local: rustc_middle::mir::Local::from_usize(self.local),
|
||||
projection: tcx.mk_place_elems(&self.projection.internal(tables, tcx)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RustcInternal for ProjectionElem {
|
||||
type T<'tcx> = rustc_middle::mir::PlaceElem<'tcx>;
|
||||
|
||||
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
||||
match self {
|
||||
ProjectionElem::Deref => rustc_middle::mir::PlaceElem::Deref,
|
||||
ProjectionElem::Field(idx, ty) => {
|
||||
rustc_middle::mir::PlaceElem::Field((*idx).into(), ty.internal(tables, tcx))
|
||||
}
|
||||
ProjectionElem::Index(idx) => rustc_middle::mir::PlaceElem::Index((*idx).into()),
|
||||
ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
|
||||
rustc_middle::mir::PlaceElem::ConstantIndex {
|
||||
offset: *offset,
|
||||
min_length: *min_length,
|
||||
from_end: *from_end,
|
||||
}
|
||||
}
|
||||
ProjectionElem::Subslice { from, to, from_end } => {
|
||||
rustc_middle::mir::PlaceElem::Subslice { from: *from, to: *to, from_end: *from_end }
|
||||
}
|
||||
ProjectionElem::Downcast(idx) => {
|
||||
rustc_middle::mir::PlaceElem::Downcast(None, idx.internal(tables, tcx))
|
||||
}
|
||||
ProjectionElem::OpaqueCast(ty) => {
|
||||
rustc_middle::mir::PlaceElem::OpaqueCast(ty.internal(tables, tcx))
|
||||
}
|
||||
ProjectionElem::Subtype(ty) => {
|
||||
rustc_middle::mir::PlaceElem::Subtype(ty.internal(tables, tcx))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> RustcInternal for &T
|
||||
where
|
||||
T: RustcInternal,
|
||||
|
|
|
@ -14,7 +14,7 @@ pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io
|
|||
)?;
|
||||
let _ = run(tcx, || {
|
||||
let items = stable_mir::all_local_items();
|
||||
let _ = items.iter().map(|item| -> io::Result<()> { item.dump(w) }).collect::<Vec<_>>();
|
||||
let _ = items.iter().map(|item| -> io::Result<()> { item.emit_mir(w) }).collect::<Vec<_>>();
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ use stable_mir::abi::{FnAbi, Layout, LayoutShape};
|
|||
use stable_mir::compiler_interface::Context;
|
||||
use stable_mir::mir::alloc::GlobalAlloc;
|
||||
use stable_mir::mir::mono::{InstanceDef, StaticDef};
|
||||
use stable_mir::mir::Body;
|
||||
use stable_mir::mir::{Body, Place};
|
||||
use stable_mir::target::{MachineInfo, MachineSize};
|
||||
use stable_mir::ty::{
|
||||
AdtDef, AdtKind, Allocation, ClosureDef, ClosureKind, Const, FieldDef, FnDef, ForeignDef,
|
||||
|
@ -423,7 +423,7 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
def_ty.instantiate(tables.tcx, args).stable(&mut *tables)
|
||||
}
|
||||
|
||||
fn const_literal(&self, cnst: &stable_mir::ty::Const) -> String {
|
||||
fn const_pretty(&self, cnst: &stable_mir::ty::Const) -> String {
|
||||
let mut tables = self.0.borrow_mut();
|
||||
let tcx = tables.tcx;
|
||||
cnst.internal(&mut *tables, tcx).to_string()
|
||||
|
@ -434,6 +434,11 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
tables.tcx.def_span(tables[def_id]).stable(&mut *tables)
|
||||
}
|
||||
|
||||
fn ty_pretty(&self, ty: stable_mir::ty::Ty) -> String {
|
||||
let tables = self.0.borrow_mut();
|
||||
tables.types[ty].to_string()
|
||||
}
|
||||
|
||||
fn ty_kind(&self, ty: stable_mir::ty::Ty) -> TyKind {
|
||||
let mut tables = self.0.borrow_mut();
|
||||
tables.types[ty].kind().stable(&mut *tables)
|
||||
|
@ -654,6 +659,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
|||
let tcx = tables.tcx;
|
||||
id.internal(&mut *tables, tcx).0.stable(&mut *tables)
|
||||
}
|
||||
|
||||
fn place_debug(&self, place: &Place) -> String {
|
||||
let mut tables = self.0.borrow_mut();
|
||||
let tcx = tables.tcx;
|
||||
format!("{:?}", place.internal(&mut *tables, tcx))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TablesWrapper<'tcx>(pub RefCell<Tables<'tcx>>);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue