]>
git.saurik.com Git - bison.git/blob - src/print_graph.c
1 /* Output a VCG description on generated parser, for Bison,
3 Copyright (C) 2001, 2002 Free Software Foundation, Inc.
5 This file is part of Bison, the GNU Compiler Compiler.
7 Bison is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 Bison is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bison; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
30 #include "conflicts.h"
35 #include "print_graph.h"
41 static graph static_graph
;
42 static FILE *fgraph
= NULL
;
45 /*----------------------------.
46 | Construct the node labels. |
47 `----------------------------*/
50 print_core (struct obstack
*oout
, state
*s
)
53 item_number
*sitems
= s
->items
;
54 int snritems
= s
->nitems
;
56 /* Output all the items of a state, not only its kernel. */
57 if (report_flag
& report_itemsets
)
59 closure (sitems
, snritems
);
64 obstack_fgrow1 (oout
, "state %2d\n", s
->number
);
65 for (i
= 0; i
< snritems
; i
++)
71 sp1
= sp
= ritem
+ sitems
[i
];
76 r
= item_number_as_rule_number (*sp
);
79 obstack_1grow (oout
, '\n');
80 obstack_fgrow1 (oout
, " %s -> ",
83 for (sp
= rules
[r
].rhs
; sp
< sp1
; sp
++)
84 obstack_fgrow1 (oout
, "%s ", symbols
[*sp
]->tag
);
86 obstack_1grow (oout
, '.');
88 for (/* Nothing */; *sp
>= 0; ++sp
)
89 obstack_fgrow1 (oout
, " %s", symbols
[*sp
]->tag
);
91 /* Experimental feature: display the lookaheads. */
92 if (report_flag
& report_lookaheads
)
94 /* Find the reduction we are handling. */
95 reductions
*reds
= s
->reductions
;
96 int redno
= state_reduction_find (s
, &rules
[r
]);
98 /* Print them if there are. */
99 if (reds
->lookaheads
&& redno
!= -1)
101 bitset_iterator biter
;
104 obstack_sgrow (oout
, "[");
105 BITSET_FOR_EACH (biter
, reds
->lookaheads
[redno
], k
, 0)
106 obstack_fgrow2 (oout
, "%s%s",
107 not_first
++ ? ", " : "",
109 obstack_sgrow (oout
, "]");
116 /*---------------------------------------------------------------.
117 | Output in graph_obstack edges specifications in incidence with |
119 `---------------------------------------------------------------*/
122 print_actions (state
*s
, const char *node_name
)
126 transitions
*trans
= s
->transitions
;
127 reductions
*reds
= s
->reductions
;
129 static char buff
[10];
132 if (!trans
->num
&& !reds
)
135 for (i
= 0; i
< trans
->num
; i
++)
136 if (!TRANSITION_IS_DISABLED (trans
, i
))
138 state
*s1
= trans
->states
[i
];
139 symbol_number sym
= s1
->accessing_symbol
;
143 if (s
->number
> s1
->number
)
145 open_edge (&e
, fgraph
);
146 /* The edge source is the current node. */
147 e
.sourcename
= node_name
;
148 sprintf (buff
, "%d", s1
->number
);
150 /* Shifts are blue, gotos are green, and error is red. */
151 if (TRANSITION_IS_ERROR (trans
, i
))
154 e
.color
= TRANSITION_IS_SHIFT (trans
, i
) ? blue
: green
;
155 e
.label
= symbols
[sym
]->tag
;
156 output_edge (&e
, fgraph
);
162 /*-------------------------------------------------------------.
163 | Output in FGRAPH the current node specifications and exiting |
165 `-------------------------------------------------------------*/
168 print_state (state
*s
)
170 static char name
[10];
171 struct obstack node_obstack
;
174 /* The labels of the nodes are their the items. */
175 obstack_init (&node_obstack
);
177 sprintf (name
, "%d", s
->number
);
179 print_core (&node_obstack
, s
);
180 obstack_1grow (&node_obstack
, '\0');
181 n
.label
= obstack_finish (&node_obstack
);
184 output_node (&n
, fgraph
);
187 /* Output the edges. */
188 print_actions (s
, name
);
190 obstack_free (&node_obstack
, 0);
200 fgraph
= xfopen (spec_graph_file
, "w");
202 new_graph (&static_graph
);
205 static_graph
.smanhattan_edges
= yes
;
206 static_graph
.manhattan_edges
= yes
;
209 static_graph
.display_edge_labels
= yes
;
210 static_graph
.layoutalgorithm
= normal
;
212 static_graph
.port_sharing
= no
;
213 static_graph
.finetuning
= yes
;
214 static_graph
.long_straight_phase
= yes
;
215 static_graph
.priority_phase
= yes
;
216 static_graph
.splines
= yes
;
218 static_graph
.crossing_weight
= median
;
220 /* Output graph options. */
222 output_graph (&static_graph
, fgraph
);
224 /* Output nodes and edges. */
225 new_closure (nritems
);
226 for (i
= 0; i
< nstates
; i
++)
227 print_state (states
[i
]);
231 close_graph (&static_graph
, fgraph
);