From 2c814974a27423c8c68ad0c39ee380033b6a5e3e Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 21 Apr 2020 09:53:29 -0400
Subject: [PATCH 066/132] FIXME: improvements to dumping

---
 gcc/analyzer/region-model2.cc |  8 +++--
 gcc/analyzer/region-model2.h  |  2 ++
 gcc/analyzer/store2.cc        | 60 +++++++++++++++++++++++++----------
 gcc/analyzer/store2.h         |  4 +--
 4 files changed, 53 insertions(+), 21 deletions(-)

diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc
index 33b6481e3aa..0c84cb3d780 100644
--- a/gcc/analyzer/region-model2.cc
+++ b/gcc/analyzer/region-model2.cc
@@ -672,8 +672,9 @@ initial_svalue2::dump_to_pp (pretty_printer *pp, bool simple) const
 {
   if (simple)
     {
-      pp_string (pp, "initial value of ");
+      pp_string (pp, "INIT_VAL(");
       m_reg->dump_to_pp (pp, simple);
+      pp_string (pp, ")");
     }
   else
     {
@@ -731,7 +732,8 @@ unaryop_svalue2::dump_to_pp (pretty_printer *pp, bool simple) const
   if (simple)
     {
       pp_character (pp, '(');
-      pp_string (pp, op_symbol_code (m_op));
+      pp_string (pp, get_tree_code_name (m_op));
+      //pp_string (pp, op_symbol_code (m_op));
       m_arg->dump_to_pp (pp, simple);
       pp_character (pp, ')');
     }
@@ -3269,7 +3271,7 @@ void
 region_model2::dump_to_pp (pretty_printer *pp, bool summarize) const
 {
 #if 1
-  m_store.dump_to_pp (pp, summarize);
+  m_store.dump_to_pp (pp, summarize, true); // FIXME
 
 #else
   for (store_map_t::iterator iter = m_store_map.begin ();
diff --git a/gcc/analyzer/region-model2.h b/gcc/analyzer/region-model2.h
index 6781891e1a6..8b7f45c6bdf 100644
--- a/gcc/analyzer/region-model2.h
+++ b/gcc/analyzer/region-model2.h
@@ -682,6 +682,8 @@ public:
 
   enum kind get_kind () const FINAL OVERRIDE { return SK_BINOP; }
 
+  enum tree_code get_op () const { return m_op; }
+
 #if 0
   void dump_dot_to_pp (const region_model2 &model,
 		       pretty_printer *pp) const
diff --git a/gcc/analyzer/store2.cc b/gcc/analyzer/store2.cc
index 5535c299e02..8787b8e5f0e 100644
--- a/gcc/analyzer/store2.cc
+++ b/gcc/analyzer/store2.cc
@@ -162,7 +162,8 @@ binding_cluster2::operator== (const binding_cluster2 &other) const
 }
 
 void
-binding_cluster2::dump_to_pp (pretty_printer *pp, bool simple) const
+binding_cluster2::dump_to_pp (pretty_printer *pp, bool simple,
+			      bool multiline) const
 {
   auto_vec <const binding_key2 *> binding_key2s;
   for (map_t::iterator iter = m_map.begin ();
@@ -178,14 +179,31 @@ binding_cluster2::dump_to_pp (pretty_printer *pp, bool simple) const
   unsigned i;
   FOR_EACH_VEC_ELT (binding_key2s, i, key)
     {
-      if (i > 0)
-	pp_string (pp, ", ");
       svalue2 *value = *const_cast <map_t &> (m_map).get (key);
-      pp_string (pp, "binding key: {");
-      key->dump_to_pp (pp, simple);
-      pp_string (pp, "}, value: {");
-      value->dump_to_pp (pp, simple);
-      pp_string (pp, "}");
+      if (multiline)
+	{
+	  pp_string (pp, "  key:   {");
+	  key->dump_to_pp (pp, simple);
+	  pp_string (pp, "}");
+	  pp_newline (pp);
+	  pp_string (pp, "  value: ");
+	  if (tree t = value->get_type ())
+	    dump_quoted_tree (pp, t);
+	  pp_string (pp, " {");
+	  value->dump_to_pp (pp, simple);
+	  pp_string (pp, "}");
+	  pp_newline (pp);
+	}
+      else
+	{
+	  if (i > 0)
+	    pp_string (pp, ", ");
+	  pp_string (pp, "binding key: {");
+	  key->dump_to_pp (pp, simple);
+	  pp_string (pp, "}, value: {");
+	  value->dump_to_pp (pp, simple);
+	  pp_string (pp, "}");
+	}
     }
 }
 
@@ -349,7 +367,7 @@ store2::operator== (const store2 &other) const
 }
 
 void
-store2::dump_to_pp (pretty_printer *pp, bool summarize) const
+store2::dump_to_pp (pretty_printer *pp, bool summarize, bool multiline) const
 {
   /* Sort into some deterministic order.  */
   auto_vec<const region2 *> base_regions;
@@ -365,15 +383,25 @@ store2::dump_to_pp (pretty_printer *pp, bool summarize) const
   unsigned i;
   FOR_EACH_VEC_ELT (base_regions, i, base_reg)
     {
-      if (i > 0)
-	pp_string (pp, ", ");
       binding_cluster2 *cluster
 	= *const_cast<cluster_map_t &> (m_cluster_map).get (base_reg);
-      pp_string (pp, "base region: {");
-      base_reg->dump_to_pp (pp, summarize);
-      pp_string (pp, "} has cluster: {");
-      cluster->dump_to_pp (pp, summarize);
-      pp_string (pp, "}");
+      if (multiline)
+	{
+	  pp_string (pp, "cluster for: ");
+	  base_reg->dump_to_pp (pp, summarize);
+	  pp_newline (pp);
+	  cluster->dump_to_pp (pp, summarize, multiline);
+	}
+      else
+	{
+	  if (i > 0)
+	    pp_string (pp, ", ");
+	  pp_string (pp, "base region: {");
+	  base_reg->dump_to_pp (pp, summarize);
+	  pp_string (pp, "} has cluster: {");
+	  cluster->dump_to_pp (pp, summarize, multiline);
+	  pp_string (pp, "}");
+	}
     }
 }
 
diff --git a/gcc/analyzer/store2.h b/gcc/analyzer/store2.h
index 8dd7edca8b5..33c482c9afe 100644
--- a/gcc/analyzer/store2.h
+++ b/gcc/analyzer/store2.h
@@ -161,7 +161,7 @@ public:
     return !(*this == other);
   }
 
-  void dump_to_pp (pretty_printer *pp, bool simple) const;
+  void dump_to_pp (pretty_printer *pp, bool simple, bool multiline) const;
 
 #if 1
   void bind (store2_manager *mgr, region2 *, svalue2 *);
@@ -202,7 +202,7 @@ public:
     return !(*this == other);
   }
 
-  void dump_to_pp (pretty_printer *pp, bool summarize) const;
+  void dump_to_pp (pretty_printer *pp, bool summarize, bool multiline) const;
 
   svalue2 *get_direct_binding (store2_manager *mgr, region2 *reg);
   svalue2 *get_default_binding (store2_manager *mgr, region2 *reg);
-- 
2.21.0

