use new apis and add new function
This commit is contained in:
parent
71c990470a
commit
92657f163a
5 changed files with 20 additions and 17 deletions
|
@ -12,7 +12,7 @@ pub fn write_smir_pretty<'tcx, W: io::Write>(tcx: TyCtxt<'tcx>, w: &mut W) -> io
|
||||||
w,
|
w,
|
||||||
"// If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir."
|
"// If you find a bug or want to improve the output open a issue at https://github.com/rust-lang/project-stable-mir."
|
||||||
)?;
|
)?;
|
||||||
run(tcx, || {
|
let _ = run(tcx, || {
|
||||||
let items = stable_mir::all_local_items();
|
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.dump(w) }).collect::<Vec<_>>();
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
//!
|
//!
|
||||||
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
||||||
|
|
||||||
use crate::rustc_internal::{IndexMap, RustcInternal};
|
use crate::rustc_internal::{internal, IndexMap, RustcInternal};
|
||||||
use crate::rustc_smir::stable_mir::ty::{BoundRegion, Region};
|
use crate::rustc_smir::stable_mir::ty::{BoundRegion, Region};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
|
@ -105,6 +105,10 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
|
||||||
tables.tcx.type_of(item.internal(&mut *tables)).instantiate_identity().stable(&mut *tables)
|
tables.tcx.type_of(item.internal(&mut *tables)).instantiate_identity().stable(&mut *tables)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn const_literal(&self, cnst: &stable_mir::ty::Const) -> String {
|
||||||
|
internal(cnst).to_string()
|
||||||
|
}
|
||||||
|
|
||||||
fn span_of_an_item(&self, def_id: stable_mir::DefId) -> Span {
|
fn span_of_an_item(&self, def_id: stable_mir::DefId) -> Span {
|
||||||
let mut tables = self.0.borrow_mut();
|
let mut tables = self.0.borrow_mut();
|
||||||
tables.tcx.def_span(tables[def_id]).stable(&mut *tables)
|
tables.tcx.def_span(tables[def_id]).stable(&mut *tables)
|
||||||
|
|
|
@ -36,12 +36,12 @@ pub mod mir;
|
||||||
pub mod ty;
|
pub mod ty;
|
||||||
pub mod visitor;
|
pub mod visitor;
|
||||||
|
|
||||||
use crate::ty::{AdtDef, AdtKind, ClosureDef, ClosureKind};
|
|
||||||
use crate::mir::pretty::function_name;
|
use crate::mir::pretty::function_name;
|
||||||
use crate::mir::Mutability;
|
use crate::mir::Mutability;
|
||||||
|
use crate::ty::{AdtDef, AdtKind, ClosureDef, ClosureKind};
|
||||||
pub use error::*;
|
pub use error::*;
|
||||||
use mir::mono::Instance;
|
use mir::mono::Instance;
|
||||||
use ty::{FnDef, GenericArgs};
|
use ty::{Const, FnDef, GenericArgs};
|
||||||
|
|
||||||
/// Use String for now but we should replace it.
|
/// Use String for now but we should replace it.
|
||||||
pub type Symbol = String;
|
pub type Symbol = String;
|
||||||
|
@ -230,6 +230,9 @@ pub trait Context {
|
||||||
/// Returns the type of given crate item.
|
/// Returns the type of given crate item.
|
||||||
fn def_ty(&self, item: DefId) -> Ty;
|
fn def_ty(&self, item: DefId) -> Ty;
|
||||||
|
|
||||||
|
/// Returns literal value of a const as a string.
|
||||||
|
fn const_literal(&self, cnst: &Const) -> String;
|
||||||
|
|
||||||
/// `Span` of an item
|
/// `Span` of an item
|
||||||
fn span_of_an_item(&self, def_id: DefId) -> Span;
|
fn span_of_an_item(&self, def_id: DefId) -> Span;
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,7 @@ impl Body {
|
||||||
|
|
||||||
pub fn dump<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
|
pub fn dump<W: io::Write>(&self, w: &mut W) -> io::Result<()> {
|
||||||
writeln!(w, "{}", function_body(self))?;
|
writeln!(w, "{}", function_body(self))?;
|
||||||
let _ = self
|
self.blocks
|
||||||
.blocks
|
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, block)| -> io::Result<()> {
|
.map(|(index, block)| -> io::Result<()> {
|
||||||
|
@ -77,7 +76,7 @@ impl Body {
|
||||||
writeln!(w, " }}").unwrap();
|
writeln!(w, " }}").unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::mir::{Operand, Rvalue, StatementKind};
|
use crate::mir::{Operand, Rvalue, StatementKind};
|
||||||
use crate::ty::{DynKind, FloatTy, IntTy, RigidTy, TyKind, UintTy};
|
use crate::ty::{DynKind, FloatTy, IntTy, RigidTy, TyKind, UintTy};
|
||||||
use crate::{Body, CrateItem, Mutability};
|
use crate::{with, Body, CrateItem, Mutability};
|
||||||
|
|
||||||
pub fn function_name(item: CrateItem) -> String {
|
pub fn function_name(item: CrateItem) -> String {
|
||||||
let mut pretty_name = String::new();
|
let mut pretty_name = String::new();
|
||||||
|
@ -80,10 +80,9 @@ pub fn pretty_operand(operand: &Operand) -> String {
|
||||||
pretty.push_str("move ");
|
pretty.push_str("move ");
|
||||||
pretty.push_str(format!("_{}", mv.local).as_str());
|
pretty.push_str(format!("_{}", mv.local).as_str());
|
||||||
}
|
}
|
||||||
Operand::Constant(_) => {
|
Operand::Constant(cnst) => {
|
||||||
// FIXME: Once https://github.com/rust-lang/rust/pull/117688 we will have ability to replace this
|
|
||||||
pretty.push_str("const ");
|
pretty.push_str("const ");
|
||||||
//pretty.push_str(internal(&cnst.literal).to_string().as_str());
|
pretty.push_str(with(|cx| cx.const_literal(&cnst.literal)).as_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pretty
|
pretty
|
||||||
|
@ -196,14 +195,12 @@ pub fn pretty_ty(ty: TyKind) -> String {
|
||||||
FloatTy::F32 => "f32".to_string(),
|
FloatTy::F32 => "f32".to_string(),
|
||||||
FloatTy::F64 => "f64".to_string(),
|
FloatTy::F64 => "f64".to_string(),
|
||||||
},
|
},
|
||||||
RigidTy::Adt(_, _) => {
|
RigidTy::Adt(def, _) => {
|
||||||
// FIXME: Once https://github.com/rust-lang/rust/pull/117688 we will have ability to replace this
|
format!("{:#?}", with(|cx| cx.def_ty(def.0)))
|
||||||
format!("{rigid_ty:#?}")
|
|
||||||
}
|
}
|
||||||
RigidTy::Str => "str".to_string(),
|
RigidTy::Str => "str".to_string(),
|
||||||
RigidTy::Array(ty, len) => {
|
RigidTy::Array(ty, len) => {
|
||||||
// FIXME: Once https://github.com/rust-lang/rust/pull/117688 we will have ability to replace this
|
format!("[{}; {}]", pretty_ty(ty.kind()), with(|cx| cx.const_literal(&len)))
|
||||||
format!("[{}; {:#?}]", pretty_ty(ty.kind()), len)
|
|
||||||
}
|
}
|
||||||
RigidTy::Slice(ty) => {
|
RigidTy::Slice(ty) => {
|
||||||
format!("[{}]", pretty_ty(ty.kind()))
|
format!("[{}]", pretty_ty(ty.kind()))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue