Iterate over BB's and dump out some information along the way

This commit is contained in:
Jasper Bekkers 2020-07-24 14:17:35 +01:00
parent 0ba2d6deb1
commit 1e9d25e984
No known key found for this signature in database
GPG Key ID: C59CE25F4DA6625D
2 changed files with 54 additions and 17 deletions

View File

@ -29,6 +29,8 @@ use std::any::Any;
use std::path::Path; use std::path::Path;
use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility};
use rustc_middle::mir::Rvalue;
use rustc_middle::mir::StatementKind;
pub struct NoLlvmMetadataLoader; pub struct NoLlvmMetadataLoader;
@ -92,22 +94,57 @@ impl CodegenBackend for TheBackend {
let cgu = tcx.codegen_unit(cgu.name()); let cgu = tcx.codegen_unit(cgu.name());
let mono_items = cgu.items_in_deterministic_order(tcx); let mono_items = cgu.items_in_deterministic_order(tcx);
for (mono_item, (linkage, visibility)) in mono_items { for (mono_item, (linkage, visibility)) in mono_items {
match mono_item { match mono_item {
MonoItem::Fn(inst) => { MonoItem::Fn(instance) => {
let mut mir = ::std::io::Cursor::new(Vec::new()); {
let mut mir = ::std::io::Cursor::new(Vec::new());
crate::rustc_mir::util::write_mir_pretty( crate::rustc_mir::util::write_mir_pretty(
tcx, tcx,
Some(inst.def_id()), Some(instance.def_id()),
&mut mir, &mut mir,
).unwrap(); )
let s = String::from_utf8(mir.into_inner()).unwrap(); .unwrap();
println!("{}", s); let s = String::from_utf8(mir.into_inner()).unwrap();
}, println!("{}", s);
}
let mir = tcx.instance_mir(instance.def);
for (bb, bb_data) in mir.basic_blocks().iter_enumerated() {
for stmt in &bb_data.statements {
match &stmt.kind {
StatementKind::Assign(to_place_and_rval) => {
let place = to_place_and_rval.0; // jb-todo: iterate though place.projection & build OpAccessChain from it?
dbg!(&place);
for elem in place.projection {
match elem {
_ => {}
}
}
dbg!(&to_place_and_rval.1);
match &to_place_and_rval.1 {
Rvalue::Use(operand) => {
//let val = trans_operand(fx, operand);
//lval.write_cvalue(fx, val);
dbg!(operand);
}
_ => {}
}
//let lval = trans_place(fx, to_place_and_rval.0);
//dbg!(lval);
//println!("Assign");
}
_ => {}
}
}
}
}
_ => {} _ => {}
} }
} }
@ -136,8 +173,9 @@ impl CodegenBackend for TheBackend {
) -> Result<(), ErrorReported> { ) -> Result<(), ErrorReported> {
use rustc_session::{config::CrateType, output::out_filename}; use rustc_session::{config::CrateType, output::out_filename};
use std::io::Write; use std::io::Write;
let crate_name = let crate_name = codegen_results
codegen_results.downcast::<Symbol>().expect("in link: codegen_results is not a Symbol"); .downcast::<Symbol>()
.expect("in link: codegen_results is not a Symbol");
for &crate_type in sess.opts.crate_types.iter() { for &crate_type in sess.opts.crate_types.iter() {
if crate_type != CrateType::Rlib { if crate_type != CrateType::Rlib {
sess.fatal(&format!("Crate type is {:?}", crate_type)); sess.fatal(&format!("Crate type is {:?}", crate_type));
@ -154,4 +192,4 @@ impl CodegenBackend for TheBackend {
#[no_mangle] #[no_mangle]
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> { pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
Box::new(TheBackend) Box::new(TheBackend)
} }

View File

@ -29,7 +29,6 @@ unsafe impl<'a, T: ?Sized> Copy for &'a T {}
unsafe impl<T: ?Sized> Copy for *const T {} unsafe impl<T: ?Sized> Copy for *const T {}
unsafe impl<T: ?Sized> Copy for *mut T {} unsafe impl<T: ?Sized> Copy for *mut T {}
pub fn jasper() { pub fn jasper() {
let _ktest = 23; let _ktest = 666666666;
} }