From 1e9d25e98477d0740d6fb85b6b78985fe0b33a13 Mon Sep 17 00:00:00 2001 From: Jasper Bekkers Date: Fri, 24 Jul 2020 14:17:35 +0100 Subject: [PATCH] Iterate over BB's and dump out some information along the way --- src/lib.rs | 66 +++++++++++++++++++++++++++++++++++++++----------- tests/empty.rs | 5 ++-- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b99ba40694..2d08845ccb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,8 @@ use std::any::Any; use std::path::Path; use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; +use rustc_middle::mir::Rvalue; +use rustc_middle::mir::StatementKind; pub struct NoLlvmMetadataLoader; @@ -92,22 +94,57 @@ impl CodegenBackend for TheBackend { let cgu = tcx.codegen_unit(cgu.name()); let mono_items = cgu.items_in_deterministic_order(tcx); - + for (mono_item, (linkage, visibility)) in mono_items { match mono_item { - MonoItem::Fn(inst) => { - let mut mir = ::std::io::Cursor::new(Vec::new()); + MonoItem::Fn(instance) => { + { + let mut mir = ::std::io::Cursor::new(Vec::new()); - crate::rustc_mir::util::write_mir_pretty( - tcx, - Some(inst.def_id()), - &mut mir, - ).unwrap(); - let s = String::from_utf8(mir.into_inner()).unwrap(); + crate::rustc_mir::util::write_mir_pretty( + tcx, + Some(instance.def_id()), + &mut mir, + ) + .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> { use rustc_session::{config::CrateType, output::out_filename}; use std::io::Write; - let crate_name = - codegen_results.downcast::().expect("in link: codegen_results is not a Symbol"); + let crate_name = codegen_results + .downcast::() + .expect("in link: codegen_results is not a Symbol"); for &crate_type in sess.opts.crate_types.iter() { if crate_type != CrateType::Rlib { sess.fatal(&format!("Crate type is {:?}", crate_type)); @@ -154,4 +192,4 @@ impl CodegenBackend for TheBackend { #[no_mangle] pub fn __rustc_codegen_backend() -> Box { Box::new(TheBackend) -} \ No newline at end of file +} diff --git a/tests/empty.rs b/tests/empty.rs index 7ef3479b34..a19d485979 100644 --- a/tests/empty.rs +++ b/tests/empty.rs @@ -29,7 +29,6 @@ unsafe impl<'a, T: ?Sized> Copy for &'a T {} unsafe impl Copy for *const T {} unsafe impl Copy for *mut T {} - pub fn jasper() { - let _ktest = 23; -} \ No newline at end of file + let _ktest = 666666666; +}