Add pretty param and local info comments to clif

This commit is contained in:
bjorn3 2018-12-22 17:42:38 +01:00
parent 9882576497
commit 0b4ede39e5
2 changed files with 77 additions and 28 deletions

View File

@ -18,7 +18,6 @@ fn bcd(b: bool, a: u8) -> u8 {
}
}
// FIXME make calls work
fn call() {
abc(42);
}
@ -33,14 +32,12 @@ enum BoolOption {
None,
}
/*
fn option_unwrap_or(o: BoolOption, d: bool) -> bool {
match o {
BoolOption::Some(b) => b,
BoolOption::None => d,
}
}
*/
fn ret_42() -> u8 {
42
@ -62,18 +59,18 @@ fn cmp_raw_ptr(a: *const u8, b: *const u8) -> bool {
a == b
}
/*fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
fn int_cast(a: u16, b: i16) -> (u8, u16, u32, usize, i8, i16, i32, isize, u8, u32) {
(
a as u8, a as u16, a as u32, a as usize, a as i8, a as i16, a as i32, a as isize, b as u8,
b as u32,
)
}*/
}
fn char_cast(c: char) -> u8 {
c as u8
}
struct DebugTuple(());
pub struct DebugTuple(());
fn debug_tuple() -> DebugTuple {
DebugTuple(())
@ -87,14 +84,14 @@ fn use_size_of() -> usize {
size_of::<u64>()
}
/*unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) {
unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) {
intrinsics::copy::<u8>(src, dst, 1);
}*/
}
/*unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) {
let copy2 = &copy::<u8>;
unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) {
let copy2 = &intrinsics::copy::<u8>;
copy2(src, dst, 1);
}*/
}
const Abc: u8 = 6 * 7;
@ -102,32 +99,36 @@ fn use_const() -> u8 {
Abc
}
fn call_closure_3arg() {
pub fn call_closure_3arg() {
(|_, _, _| {})(0u8, 42u16, 0u8)
}
fn call_closure_2arg() {
pub fn call_closure_2arg() {
(|_, _| {})(0u8, 42u16)
}
struct IsNotEmpty;
impl<'a, 'b> FnOnce<(&'a &'b [u16],)> for IsNotEmpty {
type Output = bool;
type Output = (u8, u8);
#[inline]
extern "rust-call" fn call_once(mut self, arg: (&'a &'b [u16],)) -> bool {
extern "rust-call" fn call_once(mut self, arg: (&'a &'b [u16],)) -> (u8, u8) {
self.call_mut(arg)
}
}
impl<'a, 'b> FnMut<(&'a &'b [u16],)> for IsNotEmpty {
#[inline]
extern "rust-call" fn call_mut(&mut self, arg: (&'a &'b [u16],)) -> bool {
true
extern "rust-call" fn call_mut(&mut self, arg: (&'a &'b [u16],)) -> (u8, u8) {
(0, 42)
}
}
pub fn call_is_not_empty() {
IsNotEmpty.call_once((&(&[0u16] as &[_]),));
}
fn eq_char(a: char, b: char) -> bool {
a == b
}
@ -140,7 +141,6 @@ unsafe fn call_uninit() -> u8 {
intrinsics::uninit()
}
// TODO: enable when fat pointers are supported
unsafe fn deref_str_ptr(s: *const str) -> &'static str {
&*s
}
@ -157,9 +157,9 @@ fn array_as_slice(arr: &[u8; 3]) -> &[u8] {
arr
}
/*unsafe fn use_ctlz_nonzero(a: u16) -> u16 {
unsafe fn use_ctlz_nonzero(a: u16) -> u16 {
intrinsics::ctlz_nonzero(a)
}*/
}
fn ptr_as_usize(ptr: *const u8) -> usize {
ptr as usize
@ -169,9 +169,9 @@ fn float_cast(a: f32, b: f64) -> (f64, f32) {
(a as f64, b as f32)
}
/*fn int_to_float(a: u8, b: i32) -> (f64, f32) {
fn int_to_float(a: u8, b: i32) -> (f64, f32) {
(a as f64, b as f32)
}*/
}
fn make_array() -> [u8; 3] {
[42, 0, 5]

View File

@ -1,3 +1,4 @@
use std::borrow::Cow;
use std::iter;
use rustc::hir;
@ -270,6 +271,41 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
}
}
fn add_local_comment<'a, 'tcx: 'a>(
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
msg: &str,
local: mir::Local,
local_field: Option<usize>,
param: Option<Value>,
pass_mode: Option<PassMode>,
ssa: crate::analyze::Flags,
ty: Ty<'tcx>,
) {
let local_field = if let Some(local_field) = local_field {
Cow::Owned(format!(".{}", local_field))
} else {
Cow::Borrowed("")
};
let param = if let Some(param) = param {
Cow::Owned(format!("= {:?}", param))
} else {
Cow::Borrowed("-")
};
let pass_mode = if let Some(pass_mode) = pass_mode {
Cow::Owned(format!("{:?}", pass_mode))
} else {
Cow::Borrowed("-")
};
fx.add_global_comment(format!(
"{msg:5} {local:>3}{local_field:<5} {param:10} {pass_mode:20} {ssa:10} {ty:?}",
msg=msg, local=format!("{:?}", local), local_field=local_field, param=param, pass_mode=pass_mode, ssa=format!("{:?}", ssa), ty=ty,
));
}
fn add_local_header_comment(fx: &mut FunctionCx<impl Backend>) {
fx.add_global_comment(format!("msg loc.idx param pass mode ssa flags ty"));
}
pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
start_ebb: Ebb,
@ -331,12 +367,6 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
fx.add_global_comment(format!("ssa {:?}", ssa_analyzed));
for local in fx.mir.args_iter() {
let arg_ty = fx.monomorphize(&fx.mir.local_decls[local].ty);
let pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, arg_ty, false);
fx.add_global_comment(format!("pass {:?}: {:?} {:?}", local, arg_ty, pass_mode));
}
match output_pass_mode {
PassMode::NoPass => {
let null = fx.bcx.ins().iconst(fx.pointer_type, 0);
@ -359,9 +389,26 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
}
}
add_local_header_comment(fx);
add_local_comment(fx, "ret", RETURN_PLACE, None, ret_param, Some(output_pass_mode), ssa_analyzed[&RETURN_PLACE], ret_layout.ty);
for (local, arg_kind, ty) in func_params {
let layout = fx.layout_of(ty);
match arg_kind {
ArgKind::Normal(ebb_param) => {
let pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, ty, false);
add_local_comment(fx, "arg", local, None, Some(ebb_param), Some(pass_mode), ssa_analyzed[&local], ty);
}
ArgKind::Spread(ref ebb_params) => {
for (i, &ebb_param) in ebb_params.iter().enumerate() {
let sub_layout = layout.field(fx, i);
let pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, sub_layout.ty, false);
add_local_comment(fx, "arg", local, Some(i), Some(ebb_param), Some(pass_mode), ssa_analyzed[&local], sub_layout.ty);
}
}
}
if let ArgKind::Normal(ebb_param) = arg_kind {
if !ssa_analyzed
.get(&local)
@ -422,6 +469,8 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
let ty = fx.mir.local_decls[local].ty;
let layout = fx.layout_of(ty);
add_local_comment(fx, "local", local, None, None, None, ssa_analyzed[&local], ty);
let place = if ssa_analyzed
.get(&local)
.unwrap()