]>
git.saurik.com Git - bison.git/blob - src/print_graph.c
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
)
43 state_t
*statep
= state_table
[state
];
48 for (i
= 0; i
< statep
->nitems
; i
++)
54 sp1
= sp
= ritem
+ statep
->items
[i
];
62 obstack_1grow (node_obstack
, '\n');
63 obstack_fgrow1 (node_obstack
, "%d: ", rule
);
64 obstack_fgrow1 (node_obstack
, " %s -> ",
65 tags
[rule_table
[rule
].lhs
]);
67 for (sp
= ritem
+ rule_table
[rule
].rhs
; sp
< sp1
; sp
++)
68 obstack_fgrow1 (node_obstack
, "%s ", tags
[*sp
]);
70 obstack_1grow (node_obstack
, '.');
72 for (/* Nothing */; *sp
> 0; ++sp
)
73 obstack_fgrow1 (node_obstack
, " %s", tags
[*sp
]);
78 /*---------------------------------------------------------------.
79 | Output in graph_obstack edges specifications in incidence with |
81 `---------------------------------------------------------------*/
84 print_actions (int state
, const char *node_name
)
88 shifts
*shiftp
= state_table
[state
]->shifts
;
89 reductions
*redp
= state_table
[state
]->reductions
;
91 errs
*errp
= state_table
[state
]->errs
;
97 if (!shiftp
->nshifts
&& !redp
)
100 if (final_state
== state
)
101 obstack_sgrow (node_obstack
, "$default: accept");
103 obstack_sgrow (node_obstack
, "NO ACTIONS");
108 for (i
= 0; i
< shiftp
->nshifts
; i
++)
109 if (!SHIFT_IS_DISABLED (shiftp
, i
))
111 int state1
= shiftp
->shifts
[i
];
112 int symbol
= state_table
[state1
]->accessing_symbol
;
117 edge
.type
= back_edge
;
118 open_edge (&edge
, fgraph
);
119 /* The edge source is the current node. */
120 edge
.sourcename
= node_name
;
121 sprintf (buff
, "%d", state1
);
122 edge
.targetname
= buff
;
123 edge
.color
= (symbol
== 0) ? red
: blue
;
124 edge
.label
= tags
[symbol
];
125 output_edge (&edge
, fgraph
);
136 for (j
= 0; j
< nerrs
; j
++)
140 symbol
= errp
->errs
[j
];
141 /* If something has been added in the NODE_OBSTACK after
142 the declaration of the label, then we need a `\n'.
143 if (obstack_object_size (node_obstack) > node_output_size)
144 obstack_sgrow (node_obstack, "\n");
146 obstack_fgrow1 (node_obstack
, _("%-4s\terror (nonassociative)"),
150 obstack_1grow (node_obstack
, '\n');
153 if (state_table
[state
]->consistent
&& redp
)
155 rule
= redp
->rules
[0];
156 symbol
= rule_table
[rule
].lhs
;
158 if (obstack_object_size (node_obstack) > node_output_size)
159 obstack_sgrow (node_obstack, "\n");
161 obstack_fgrow2 (node_obstack
, _("$default\treduce using rule %d (%s)"),
166 if (i
< shiftp
->nshifts
)
167 for (; i
< shiftp
->nshifts
; i
++)
168 if (!SHIFT_IS_DISABLED (shiftp
, i
))
170 int state1
= shiftp
->shifts
[i
];
171 int symbol
= state_table
[state1
]->accessing_symbol
;
174 open_edge (&edge
, fgraph
);
175 edge
.sourcename
= node_name
;
176 sprintf (buff
, "%d", state1
);
177 edge
.targetname
= buff
;
179 edge
.label
= tags
[symbol
];
180 output_edge (&edge
, fgraph
);
186 /*-------------------------------------------------------------.
187 | Output in FGRAPH the current node specifications and exiting |
189 `-------------------------------------------------------------*/
192 print_state (int state
)
194 static char name
[10];
195 struct obstack node_obstack
;
198 /* The labels of the nodes are their the items. */
199 obstack_init (&node_obstack
);
201 sprintf (name
, "%d", state
);
203 print_core (state
, &node_obstack
);
204 obstack_1grow (&node_obstack
, '\0');
205 node
.label
= obstack_finish (&node_obstack
);
208 output_node (&node
, fgraph
);
211 /* Output the edges. */
212 print_actions (state
, name
);
214 obstack_free (&node_obstack
, 0);
227 fgraph
= xfopen (spec_graph_file
, "w");
232 graph
.smanhattan_edges
= yes
;
233 graph
.manhattan_edges
= yes
;
236 graph
.display_edge_labels
= yes
;
237 graph
.layoutalgorithm
= normal
;
239 graph
.port_sharing
= no
;
240 graph
.finetuning
= yes
;
241 graph
.straight_phase
= yes
;
242 graph
.priority_phase
= yes
;
245 graph
.crossing_weight
= median
;
247 /* Output graph options. */
249 output_graph (&graph
, fgraph
);
251 /* Output nodes and edges. */
252 for (i
= 0; i
< nstates
; i
++)
256 close_graph (&graph
, fgraph
);