diff --git a/src/ielr.c b/src/ielr.c index e0f53c21..11aa4d58 100644 --- a/src/ielr.c +++ b/src/ielr.c @@ -196,10 +196,7 @@ ielr_compute_internal_follow_edges (bitset ritem_sees_lookahead_set, relation_transpose (edgesp, ngotos); if (trace_flag & trace_ielr) - { - fprintf (stderr, "internal_follow_edges:\n"); - relation_print (*edgesp, ngotos, NULL, stderr); - } + relation_print ("internal_follow_edges", *edgesp, ngotos, NULL, stderr); } /** @@ -304,8 +301,7 @@ ielr_compute_always_follows (goto_number ***edgesp, if (trace_flag & trace_ielr) { - fprintf (stderr, "always follow edges:\n"); - relation_print (*edgesp, ngotos, NULL, stderr); + relation_print ("always follow edges", *edgesp, ngotos, NULL, stderr); fprintf (stderr, "always_follows:\n"); debug_bitsetv (*always_followsp); } diff --git a/src/lalr.c b/src/lalr.c index fd239dc3..3837eed4 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -68,7 +68,7 @@ static goto_number **includes; static goto_list **lookback; static void -goto_print (goto_number i, FILE* out) +goto_print (goto_number i, FILE *out) { const state_number src = from_state[i]; const state_number dst = to_state[i]; @@ -193,6 +193,8 @@ initialize_goto_follows (void) } } + if (trace_flag & trace_automaton) + relation_print ("reads", reads, ngotos, goto_print, stderr); relation_digraph (reads, ngotos, goto_follows); for (goto_number i = 0; i < ngotos; ++i) @@ -282,15 +284,12 @@ build_relations (void) relation_transpose (&includes, ngotos); if (trace_flag & trace_automaton) - { - fprintf (stderr, "includes:\n"); - relation_print (includes, ngotos, goto_print, stderr); - } + relation_print ("includes", includes, ngotos, goto_print, stderr); } /* Print FOLLOWS for debugging. */ static void -follows_print (FILE* out) +follows_print (FILE *out) { for (goto_number i = 0; i < ngotos; ++i) { diff --git a/src/relation.c b/src/relation.c index 0e9db9d8..24f7a473 100644 --- a/src/relation.c +++ b/src/relation.c @@ -27,17 +27,21 @@ #include "relation.h" void -relation_print (relation r, relation_node size, +relation_print (const char *title, + relation r, relation_node size, relation_node_print print, FILE *out) { + if (title) + fprintf (out, "%s:\n", title); for (size_t i = 0; i < size; ++i) - { - if (print) - print (i, out); - else - fprintf (out, "%3lu", (unsigned long) i); - fputc (':', out); - if (r[i]) + if (r[i]) + { + fputs (" ", out); + if (print) + print (i, out); + else + fprintf (out, "%3lu", (unsigned long) i); + fputc (':', out); for (relation_node j = 0; r[i][j] != END_NODE; ++j) { fputc (' ', out); @@ -46,8 +50,8 @@ relation_print (relation r, relation_node size, else fprintf (out, "%3lu", (unsigned long) r[i][j]); } - fputc ('\n', out); - } + fputc ('\n', out); + } fputc ('\n', out); } @@ -130,10 +134,7 @@ relation_transpose (relation *R_arg, relation_node size) relation r = *R_arg; if (trace_flag & trace_sets) - { - fputs ("relation_transpose: input\n", stderr); - relation_print (r, size, NULL, stderr); - } + relation_print ("relation_transpose", r, size, NULL, stderr); /* Count. */ /* NEDGES[I] -- total size of NEW_R[I]. */ @@ -175,10 +176,7 @@ relation_transpose (relation *R_arg, relation_node size) free (r); if (trace_flag & trace_sets) - { - fputs ("relation_transpose: output\n", stderr); - relation_print (new_R, size, NULL, stderr); - } + relation_print ("relation_transpose: output", new_R, size, NULL, stderr); *R_arg = new_R; } diff --git a/src/relation.h b/src/relation.h index e90c052f..81d766c1 100644 --- a/src/relation.h +++ b/src/relation.h @@ -36,7 +36,8 @@ typedef relation_nodes *relation; typedef void (relation_node_print) (relation_node node, FILE* out); /* Report a relation R that has SIZE vertices. */ -void relation_print (relation r, size_t size, +void relation_print (const char *title, + relation r, size_t size, relation_node_print print, FILE *out); /* Compute the transitive closure of the FUNCTION on the relation R