19 |
Boston, MA 02111-1307, USA. */ |
Boston, MA 02111-1307, USA. */ |
20 |
|
|
21 |
#include "system.h" |
#include "system.h" |
|
#include "xalloc.h" |
|
22 |
#include "files.h" |
#include "files.h" |
23 |
#include "gram.h" |
#include "gram.h" |
24 |
#include "LR0.h" |
#include "LR0.h" |
34 |
#include "quotearg.h" |
#include "quotearg.h" |
35 |
|
|
36 |
static graph_t graph; |
static graph_t graph; |
37 |
|
static FILE *fgraph = NULL; |
38 |
|
|
39 |
static unsigned node_output_size = 0; |
static size_t node_output_size = 0; |
40 |
|
|
41 |
/* Return an unambiguous printable representated, allocated in slot 0, |
/* Return an unambiguous printable representated, allocated in slot 0, |
42 |
for NAME, suitable for C strings. */ |
for NAME, suitable for C strings. */ |
136 |
|
|
137 |
if (state > state1) |
if (state > state1) |
138 |
edge.type = back_edge; |
edge.type = back_edge; |
139 |
open_edge (&edge, &graph_obstack); |
open_edge (&edge, fgraph); |
140 |
/* The edge source is the current node. */ |
/* The edge source is the current node. */ |
141 |
edge.sourcename = node_name; |
edge.sourcename = node_name; |
142 |
sprintf (buff, "%d", state1); |
sprintf (buff, "%d", state1); |
145 |
/* FIXME: Be aware that quote uses static memory. The string |
/* FIXME: Be aware that quote uses static memory. The string |
146 |
must be output immediately (which is the case here). */ |
must be output immediately (which is the case here). */ |
147 |
edge.label = tags[symbol] ? quote (tags[symbol]) : NULL; |
edge.label = tags[symbol] ? quote (tags[symbol]) : NULL; |
148 |
output_edge (&edge, &graph_obstack); |
output_edge (&edge, fgraph); |
149 |
close_edge (&graph_obstack); |
close_edge (fgraph); |
150 |
} |
} |
151 |
} |
} |
152 |
} |
} |
198 |
symbol = accessing_symbol[state1]; |
symbol = accessing_symbol[state1]; |
199 |
|
|
200 |
new_edge (&edge); |
new_edge (&edge); |
201 |
open_edge (&edge, &graph_obstack); |
open_edge (&edge, fgraph); |
202 |
edge.sourcename = node_name; |
edge.sourcename = node_name; |
203 |
sprintf (buff, "%d", state1); |
sprintf (buff, "%d", state1); |
204 |
edge.targetname = buff; |
edge.targetname = buff; |
205 |
edge.color = red; |
edge.color = red; |
206 |
edge.label = tags[symbol] ? quote (tags[symbol]) : NULL; |
edge.label = tags[symbol] ? quote (tags[symbol]) : NULL; |
207 |
output_edge (&edge, &graph_obstack); |
output_edge (&edge, fgraph); |
208 |
close_edge (&graph_obstack); |
close_edge (fgraph); |
209 |
} |
} |
210 |
} |
} |
211 |
} |
} |
223 |
new_node (&node); /* Set node attributs default value. */ |
new_node (&node); /* Set node attributs default value. */ |
224 |
sprintf (name, "%d", state); |
sprintf (name, "%d", state); |
225 |
node.title = name; /* Give a name to the node. */ |
node.title = name; /* Give a name to the node. */ |
|
open_node (&node_obstack); |
|
|
/* Output a VCG formatted attributs list. */ |
|
|
output_node (&node, &node_obstack); |
|
226 |
|
|
227 |
{ |
{ |
228 |
/* Here we begin to compute the node label. */ |
/* Here we begin to compute the node label. */ |
238 |
print_actions (state, node.title, &node_obstack); |
print_actions (state, node.title, &node_obstack); |
239 |
|
|
240 |
obstack_sgrow (&node_obstack, "\"\n"); /* Close Label. */ |
obstack_sgrow (&node_obstack, "\"\n"); /* Close Label. */ |
241 |
|
} |
242 |
close_node (&node_obstack); |
|
243 |
} |
open_node (fgraph); |
244 |
|
/* Output a VCG formatted attributs list. */ |
245 |
/* `obstack_cat' NODE_OBSTACK to GRAPH_OBSTACK. */ |
output_node (&node, fgraph); |
246 |
obstack_grow (&graph_obstack, |
/* Save the node label. */ |
247 |
obstack_base (&node_obstack), |
fwrite (obstack_base (&node_obstack), |
248 |
obstack_object_size (&node_obstack)); |
obstack_object_size (&node_obstack), 1, fgraph); |
249 |
obstack_finish (&node_obstack); |
close_node (fgraph); |
250 |
|
|
251 |
|
obstack_free (&node_obstack, 0); |
252 |
} |
} |
253 |
|
|
254 |
|
|
256 |
print_graph (void) |
print_graph (void) |
257 |
{ |
{ |
258 |
int i; |
int i; |
259 |
|
|
260 |
if (!graph_flag) |
if (!graph_flag) |
261 |
return; |
return; |
262 |
|
|
263 |
|
/* Output file. */ |
264 |
|
fgraph = xfopen (spec_graph_file, "w"); |
265 |
|
|
266 |
new_graph (&graph); |
new_graph (&graph); |
267 |
|
|
268 |
#if 0 |
#if 0 |
271 |
#endif |
#endif |
272 |
|
|
273 |
graph.display_edge_labels = yes; |
graph.display_edge_labels = yes; |
274 |
graph.layoutalgorithm = 0; |
graph.layoutalgorithm = normal; |
275 |
|
|
276 |
graph.port_sharing = no; |
graph.port_sharing = no; |
277 |
graph.finetuning = yes; |
graph.finetuning = yes; |
282 |
graph.crossing_weight = median; |
graph.crossing_weight = median; |
283 |
|
|
284 |
/* Output graph options. */ |
/* Output graph options. */ |
285 |
open_graph (&graph_obstack); |
open_graph (fgraph); |
286 |
output_graph (&graph, &graph_obstack); |
output_graph (&graph, fgraph); |
287 |
|
|
288 |
for (i = 0; i < nstates; i++) |
for (i = 0; i < nstates; i++) |
289 |
/* Output nodes & edges. */ |
/* Output nodes & edges. */ |
290 |
print_state (i); |
print_state (i); |
291 |
|
|
292 |
/* Close graph. */ |
/* Close graph. */ |
293 |
close_graph (&graph, &graph_obstack); |
close_graph (&graph, fgraph); |
294 |
|
xfclose (fgraph); |
295 |
} |
} |