From 15a310345d955f06dcb989a510d6613be2443a6e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sun, 22 Dec 2019 15:27:25 +0100 Subject: [PATCH] Improve local ir comments --- src/abi/comments.rs | 54 ++++++++++++++++++++++----------------------- src/pointer.rs | 6 ++++- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/abi/comments.rs b/src/abi/comments.rs index a1634bdacfe..41c74ef4a33 100644 --- a/src/abi/comments.rs +++ b/src/abi/comments.rs @@ -45,7 +45,7 @@ pub fn add_arg_comment<'tcx>( pub fn add_locals_header_comment(fx: &mut FunctionCx) { fx.add_global_comment(String::new()); fx.add_global_comment(format!( - "kind local ty size align (abi,pref)" + "kind local ty size align (abi,pref)" )); } @@ -63,35 +63,33 @@ pub fn add_local_place_comments<'tcx>( fields: _, largest_niche: _, } = details; - match *place.inner() { + + let (kind, extra) = match *place.inner() { CPlaceInner::Var(var) => { assert_eq!(local, var); - fx.add_global_comment(format!( - "ssa {:5} {:20} {:4}b {}, {}", - format!("{:?}", local), - format!("{:?}", ty), - size.bytes(), - align.abi.bytes(), - align.pref.bytes(), - )); + ("ssa", std::borrow::Cow::Borrowed("")) } - CPlaceInner::NoPlace => fx.add_global_comment(format!( - "zst {:5} {:20} {:4}b {}, {}", - format!("{:?}", local), - format!("{:?}", ty), - size.bytes(), - align.abi.bytes(), - align.pref.bytes(), - )), - CPlaceInner::Addr(ptr, None) => fx.add_global_comment(format!( - "reuse {:5} {:20} {:4}b {}, {} storage={:?}", - format!("{:?}", local), - format!("{:?}", ty), - size.bytes(), - align.abi.bytes(), - align.pref.bytes(), - ptr, - )), + CPlaceInner::NoPlace => ("zst", "".into()), + CPlaceInner::Addr(ptr, None) => match ptr.base_and_offset() { + (crate::pointer::PointerBase::Addr(addr), offset) => { + ("reuse", format!("storage={}{}", addr, offset).into()) + } + (crate::pointer::PointerBase::Stack(stack_slot), offset) => { + ("stack", format!("storage={}{}", stack_slot, offset).into()) + } + }, CPlaceInner::Addr(_, Some(_)) => unreachable!(), - } + }; + + fx.add_global_comment(format!( + "{:<5} {:5} {:30} {:4}b {}, {}{}{}", + kind, + format!("{:?}", local), + format!("{:?}", ty), + size.bytes(), + align.abi.bytes(), + align.pref.bytes(), + if extra.is_empty() { "" } else { " " }, + extra, + )); } diff --git a/src/pointer.rs b/src/pointer.rs index 3899dd15fa4..f47d5e9be9b 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -9,7 +9,7 @@ pub struct Pointer { } #[derive(Copy, Clone, Debug)] -enum PointerBase { +pub enum PointerBase { Addr(Value), Stack(StackSlot), } @@ -37,6 +37,10 @@ pub fn const_addr<'a, 'tcx>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>, addr: i } } + pub fn base_and_offset(self) -> (PointerBase, Offset32) { + (self.base, self.offset) + } + pub fn get_addr<'a, 'tcx>(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> Value { match self.base { PointerBase::Addr(base_addr) => {