From a714c7847e7ad0c5677340926a28ddac8cf0c183 Mon Sep 17 00:00:00 2001
From: Erick Ochoa <eochoa@gcc.gnu.org>
Date: Wed, 8 Sep 2021 21:31:00 +0200
Subject: [PATCH 3/4] Printing better

---
 gcc/ipa-hash.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/gcc/ipa-hash.c b/gcc/ipa-hash.c
index 58d9157a124..9cee5ba5f14 100644
--- a/gcc/ipa-hash.c
+++ b/gcc/ipa-hash.c
@@ -26,8 +26,24 @@
 #include "lto-streamer.h"
 #include "ipa-hash.h"
 
+class printable
+{
+public:
+  virtual char* str () = 0;
+  void print (void);
+};
+
+void
+printable::print (void)
+{
+  if (!dump_file) return;
+  char* _str = str ();
+  fprintf (dump_file, "%s\n", _str);
+  free (_str);
+}
+
 class symtab_wrapper_traits;
-class symtab_wrapper
+class symtab_wrapper : public printable
 {
 private:
   symtab_node *_symtab_node;
@@ -40,11 +56,12 @@ public:
     : _symtab_node (s)
   { gcc_assert (s); }
 
-  void print (void)
+  virtual char* str (void)
   {
-    if (!dump_file) return;
     gcc_assert (_symtab_node);
-    fprintf (dump_file, "%s\n", _symtab_node->name ());
+    char *retval = NULL;
+    asprintf (&retval, "%sn", _symtab_node->name ());
+    return retval;
   }
 };
 
-- 
2.25.1

