]>
git.saurik.com Git - bison.git/blob - src/print_graph.c
be7e196ee467fb1c6f60f812ad85d5877fc57512
1 /* Output a VCG description on generated parser, for Bison,
2 Copyright 2001 Free Software Foundation, Inc.
4 This file is part of Bison, the GNU Compiler Compiler.
6 Bison is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 Bison is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Bison; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
28 #include "conflicts.h"
35 #include "print_graph.h"
39 static FILE *fgraph
= NULL
;
42 /*----------------------------.
43 | Construct the node labels. |
44 `----------------------------*/
47 print_core (struct obstack
*oout
, state_t
*state
)
50 item_number_t
*sitems
= state
->items
;
51 int snritems
= state
->nitems
;
53 /* Output all the items of a state, not only its kernel. */
54 if (report_flag
& report_itemsets
)
56 closure (sitems
, snritems
);
61 obstack_fgrow1 (oout
, "state %2d\n", state
->number
);
62 for (i
= 0; i
< snritems
; i
++)
68 sp1
= sp
= ritem
+ sitems
[i
];
73 rule
= item_number_as_rule_number (*sp
);
76 obstack_1grow (oout
, '\n');
77 obstack_fgrow1 (oout
, " %s -> ",
78 rules
[rule
].lhs
->tag
);
80 for (sp
= rules
[rule
].rhs
; sp
< sp1
; sp
++)
81 obstack_fgrow1 (oout
, "%s ", symbols
[*sp
]->tag
);
83 obstack_1grow (oout
, '.');
85 for (/* Nothing */; *sp
>= 0; ++sp
)
86 obstack_fgrow1 (oout
, " %s", symbols
[*sp
]->tag
);
88 /* Experimental feature: display the lookaheads. */
89 if ((report_flag
& report_lookaheads
)
90 && state
->nlookaheads
)
93 bitset_iterator biter
;
96 /* Look for lookaheads corresponding to this rule. */
97 for (j
= 0; j
< state
->nlookaheads
; ++j
)
98 BITSET_FOR_EACH (biter
, state
->lookaheads
[j
], k
, 0)
99 if (state
->lookaheads_rule
[j
]->number
== rule
)
104 obstack_sgrow (oout
, " [");
105 for (j
= 0; j
< state
->nlookaheads
; ++j
)
106 BITSET_FOR_EACH (biter
, state
->lookaheads
[j
], k
, 0)
107 if (state
->lookaheads_rule
[j
]->number
== rule
)
108 obstack_fgrow2 (oout
, "%s%s",
110 --nlookaheads
? ", " : "");
111 obstack_sgrow (oout
, "]");
118 /*---------------------------------------------------------------.
119 | Output in graph_obstack edges specifications in incidence with |
121 `---------------------------------------------------------------*/
124 print_actions (state_t
*state
, const char *node_name
)
128 transitions_t
*transitions
= state
->transitions
;
129 reductions_t
*redp
= state
->reductions
;
131 static char buff
[10];
134 if (!transitions
->num
&& !redp
)
137 for (i
= 0; i
< transitions
->num
; i
++)
138 if (!TRANSITION_IS_DISABLED (transitions
, i
))
140 state_number_t state1
= transitions
->states
[i
];
141 symbol_number_t symbol
= states
[state1
]->accessing_symbol
;
145 if (state
->number
> state1
)
146 edge
.type
= back_edge
;
147 open_edge (&edge
, fgraph
);
148 /* The edge source is the current node. */
149 edge
.sourcename
= node_name
;
150 sprintf (buff
, "%d", state1
);
151 edge
.targetname
= buff
;
152 /* Shifts are blue, gotos are green, and error is red. */
153 if (TRANSITION_IS_ERROR (transitions
, i
))
156 edge
.color
= TRANSITION_IS_SHIFT(transitions
, i
) ? blue
: green
;
157 edge
.label
= symbols
[symbol
]->tag
;
158 output_edge (&edge
, fgraph
);
164 /*-------------------------------------------------------------.
165 | Output in FGRAPH the current node specifications and exiting |
167 `-------------------------------------------------------------*/
170 print_state (state_t
*state
)
172 static char name
[10];
173 struct obstack node_obstack
;
176 /* The labels of the nodes are their the items. */
177 obstack_init (&node_obstack
);
179 sprintf (name
, "%d", state
->number
);
181 print_core (&node_obstack
, state
);
182 obstack_1grow (&node_obstack
, '\0');
183 node
.label
= obstack_finish (&node_obstack
);
186 output_node (&node
, fgraph
);
189 /* Output the edges. */
190 print_actions (state
, name
);
192 obstack_free (&node_obstack
, 0);
202 fgraph
= xfopen (spec_graph_file
, "w");
207 graph
.smanhattan_edges
= yes
;
208 graph
.manhattan_edges
= yes
;
211 graph
.display_edge_labels
= yes
;
212 graph
.layoutalgorithm
= normal
;
214 graph
.port_sharing
= no
;
215 graph
.finetuning
= yes
;
216 graph
.straight_phase
= yes
;
217 graph
.priority_phase
= yes
;
220 graph
.crossing_weight
= median
;
222 /* Output graph options. */
224 output_graph (&graph
, fgraph
);
226 /* Output nodes and edges. */
227 new_closure (nritems
);
228 for (i
= 0; i
< nstates
; i
++)
229 print_state (states
[i
]);
233 close_graph (&graph
, fgraph
);