]>
git.saurik.com Git - bison.git/blob - src/print_graph.c
ced951b0386f16f02b4d8ba757642d7bbf274afe
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. */
26 #include "conflicts.h"
32 #include "print_graph.h"
36 static FILE *fgraph
= NULL
;
38 /* This part will construct the label of nodes. */
40 print_core (int state
, struct obstack
*node_obstack
)
49 statep
= state_table
[state
].state
;
55 for (i
= 0; i
< k
; i
++)
58 obstack_1grow (node_obstack
, '\n');
60 sp1
= sp
= ritem
+ statep
->items
[i
];
67 obstack_fgrow1 (node_obstack
, "%d: ", rule
);
68 obstack_fgrow1 (node_obstack
, " %s -> ",
69 tags
[rule_table
[rule
].lhs
]);
71 for (sp
= ritem
+ rule_table
[rule
].rhs
; sp
< sp1
; sp
++)
72 obstack_fgrow1 (node_obstack
, "%s ", tags
[*sp
]);
74 obstack_1grow (node_obstack
, '.');
77 obstack_fgrow1 (node_obstack
, " %s", tags
[*sp
++]);
82 /*---------------------------------------------------------------.
83 | Output in graph_obstack edges specifications in incidence with |
85 `---------------------------------------------------------------*/
88 print_actions (int state
, const char *node_name
)
101 shiftp
= state_table
[state
].shift_table
;
102 redp
= state_table
[state
].reduction_table
;
103 errp
= err_table
[state
];
105 if (!shiftp
&& !redp
)
108 if (final_state
== state
)
109 obstack_sgrow (node_obstack
, "$default: accept");
111 obstack_sgrow (node_obstack
, "NO ACTIONS");
120 for (i
= 0; i
< k
; i
++)
122 if (!shiftp
->shifts
[i
])
124 state1
= shiftp
->shifts
[i
];
125 symbol
= state_table
[state1
].accessing_symbol
;
134 edge
.type
= back_edge
;
135 open_edge (&edge
, fgraph
);
136 /* The edge source is the current node. */
137 edge
.sourcename
= node_name
;
138 sprintf (buff
, "%d", state1
);
139 edge
.targetname
= buff
;
140 edge
.color
= (symbol
== 0) ? red
: blue
;
141 edge
.label
= tags
[symbol
];
142 output_edge (&edge
, fgraph
);
160 for (j
= 0; j
< nerrs
; j
++)
164 symbol
= errp
->errs
[j
];
165 /* If something has been added in the NODE_OBSTACK after
166 the declaration of the label, then we need a `\n'.
167 if (obstack_object_size (node_obstack) > node_output_size)
168 obstack_sgrow (node_obstack, "\n");
170 obstack_fgrow1 (node_obstack
, _("%-4s\terror (nonassociative)"),
174 obstack_1grow (node_obstack
, '\n');
177 if (state_table
[state
].consistent
&& redp
)
179 rule
= redp
->rules
[0];
180 symbol
= rule_table
[rule
].lhs
;
182 if (obstack_object_size (node_obstack) > node_output_size)
183 obstack_sgrow (node_obstack, "\n");
185 obstack_fgrow2 (node_obstack
, _("$default\treduce using rule %d (%s)"),
194 if (!shiftp
->shifts
[i
])
196 state1
= shiftp
->shifts
[i
];
197 symbol
= state_table
[state1
].accessing_symbol
;
200 open_edge (&edge
, fgraph
);
201 edge
.sourcename
= node_name
;
202 sprintf (buff
, "%d", state1
);
203 edge
.targetname
= buff
;
205 edge
.label
= tags
[symbol
];
206 output_edge (&edge
, fgraph
);
213 /*-------------------------------------------------------------.
214 | Output in FGRAPH the current node specifications and exiting |
216 `-------------------------------------------------------------*/
219 print_state (int state
)
221 static char name
[10];
222 struct obstack node_obstack
;
225 /* The labels of the nodes are their the items. */
226 obstack_init (&node_obstack
);
228 sprintf (name
, "%d", state
);
230 print_core (state
, &node_obstack
);
231 obstack_1grow (&node_obstack
, '\0');
232 node
.label
= obstack_finish (&node_obstack
);
235 output_node (&node
, fgraph
);
238 /* Output the edges. */
239 print_actions (state
, name
);
241 obstack_free (&node_obstack
, 0);
254 fgraph
= xfopen (spec_graph_file
, "w");
259 graph
.smanhattan_edges
= yes
;
260 graph
.manhattan_edges
= yes
;
263 graph
.display_edge_labels
= yes
;
264 graph
.layoutalgorithm
= normal
;
266 graph
.port_sharing
= no
;
267 graph
.finetuning
= yes
;
268 graph
.straight_phase
= yes
;
269 graph
.priority_phase
= yes
;
272 graph
.crossing_weight
= median
;
274 /* Output graph options. */
276 output_graph (&graph
, fgraph
);
278 /* Output nodes and edges. */
279 for (i
= 0; i
< nstates
; i
++)
283 close_graph (&graph
, fgraph
);