]> git.lizzy.rs Git - rust.git/commitdiff
Improve local ir comments
authorbjorn3 <bjorn3@users.noreply.github.com>
Sun, 22 Dec 2019 14:27:25 +0000 (15:27 +0100)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sun, 22 Dec 2019 16:04:33 +0000 (17:04 +0100)
src/abi/comments.rs
src/pointer.rs

index a1634bdacfe7d4aa0b99b8a61d57fa51f8c5eae5..41c74ef4a33405722de01f3b79a25a622fe227a6 100644 (file)
@@ -45,7 +45,7 @@ pub fn add_arg_comment<'tcx>(
 pub fn add_locals_header_comment(fx: &mut FunctionCx<impl Backend>) {
     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,
+    ));
 }
index 3899dd15fa43d0f2711e1a6c1dbb906f65614a53..f47d5e9be9ba1c795703a25c4d51ce79c14201af 100644 (file)
@@ -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) => {