bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 08/22] cex: send traces to stderr, not stdout


From: Akim Demaille
Subject: [PATCH 08/22] cex: send traces to stderr, not stdout
Date: Sat, 23 Jan 2021 15:55:47 +0100

When comparing traces from different machines, the mixture of
stdout/stderr in the output are making things uselessly difficult.

* src/lssi.c, src/state-item.c: Output debug traces on stderr.
---
 src/lssi.c       | 13 +++++++------
 src/state-item.c | 34 ++++++++++++++++------------------
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/src/lssi.c b/src/lssi.c
index a5ab8a793..8c26ade0f 100644
--- a/src/lssi.c
+++ b/src/lssi.c
@@ -102,15 +102,16 @@ append_lssi (lssi *sn, Hash_table *visited, lssi_list 
queue)
 static void
 lssi_print (lssi *l)
 {
-  print_state_item (&state_items[l->si], stdout);
+  FILE *out = stderr;
+  print_state_item (&state_items[l->si], out);
   if (l->lookahead)
     {
-      printf ("FOLLOWL = { ");
+      fprintf (out, "FOLLOWL = { ");
       bitset_iterator biter;
       symbol_number sin;
       BITSET_FOR_EACH (biter, l->lookahead, sin, 0)
-        printf ("%s, \n", symbols[sin]->tag);
-      puts ("}");
+        fprintf (out, "%s, \n", symbols[sin]->tag);
+      fprintf (out, "}");
     }
 }
 #endif
@@ -252,11 +253,11 @@ shortest_path_from_start (state_item_number target, 
symbol_number next_sym)
 
   if (trace_flag & trace_cex)
     {
-      puts ("REDUCE ITEM PATH:");
+      fputs ("REDUCE ITEM PATH:", stderr);
       gl_list_iterator_t it = gl_list_iterator (res);
       const void *sip;
       while (gl_list_iterator_next (&it, &sip, NULL))
-        state_item_print ((state_item *) sip, stdout, "");
+        state_item_print ((state_item *) sip, stderr, "");
     }
   return res;
 }
diff --git a/src/state-item.c b/src/state-item.c
index a0c5a31aa..5080a4c89 100644
--- a/src/state-item.c
+++ b/src/state-item.c
@@ -486,27 +486,26 @@ state_item_print (const state_item *si, FILE *out, const 
char *prefix)
  * Report the state_item graph
  */
 static void
-state_items_report (void)
+state_items_report (FILE *out)
 {
-  printf ("# state items: %zu\n", nstate_items);
+  fprintf (out, "# state items: %zu\n", nstate_items);
   for (state_number i = 0; i < nstates; ++i)
     {
-      printf ("State %d:\n", i);
+      fprintf (out, "State %d:\n", i);
       for (state_item_number j = state_item_map[i]; j < state_item_map[i + 1]; 
++j)
         {
           state_item *si = &state_items[j];
-          item_print (si->item, NULL, stdout);
+          item_print (si->item, NULL, out);
           if (SI_DISABLED (j))
             {
-              item_print (si->item, NULL, stdout);
-              puts (" DISABLED");
+              item_print (si->item, NULL, out);
+              fputs (" DISABLED", out);
               continue;
             }
-          puts ("");
           if (si->trans >= 0)
             {
-              fputs ("    -> ", stdout);
-              state_item_print (&state_items[si->trans], stdout, "");
+              fputs ("    -> ", out);
+              state_item_print (&state_items[si->trans], out, "");
             }
 
           bitset sets[2] = { si->prods, si->revs };
@@ -520,24 +519,23 @@ state_items_report (void)
                   state_item_number sin;
                   BITSET_FOR_EACH (biter, b, sin, 0)
                     {
-                      fputs (txt[seti], stdout);
-                      state_item_print (&state_items[sin], stdout, "");
+                      fputs (txt[seti], out);
+                      state_item_print (&state_items[sin], out, "");
                     }
                 }
             }
-          puts ("");
         }
     }
-  printf ("FIRSTS\n");
+  fprintf (out, "FIRSTS\n");
   for (symbol_number i = ntokens; i < nsyms; ++i)
     {
-      printf ("  %s firsts\n", symbols[i]->tag);
+      fprintf (out, "  %s firsts\n", symbols[i]->tag);
       bitset_iterator iter;
       symbol_number j;
       BITSET_FOR_EACH (iter, FIRSTS (i), j, 0)
-        printf ("    %s\n", symbols[j]->tag);
+        fprintf (out, "    %s\n", symbols[j]->tag);
     }
-  puts ("\n");
+  fputc ('\n', out);
 }
 
 void
@@ -552,8 +550,8 @@ state_items_init (void)
   prune_disabled_paths ();
   if (trace_flag & trace_cex)
     {
-      printf ("init: %f\n", difftime (time (NULL), start));
-      state_items_report ();
+      fprintf (stderr, "init: %f\n", difftime (time (NULL), start));
+      state_items_report (stderr);
     }
 }
 
-- 
2.30.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]