]>
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. */
27 #include "conflicts.h"
34 #include "print_graph.h"
38 static FILE *fgraph
= NULL
;
40 static inline const char *
41 escape (const char *s
)
43 return quotearg_n_style (1, escape_quoting_style
, s
);
47 /* This part will construct the label of nodes. */
49 print_core (state_t
*state
, struct obstack
*node_obstack
)
52 short *sitems
= state
->items
;
53 int snitems
= state
->nitems
;
55 /* Output all the items of a state, not only its kernel. */
58 closure (sitems
, snitems
);
63 obstack_fgrow1 (node_obstack
, "state %2d\n", state
->number
);
64 for (i
= 0; i
< snitems
; i
++)
70 sp1
= sp
= ritem
+ sitems
[i
];
78 obstack_1grow (node_obstack
, '\n');
79 obstack_fgrow1 (node_obstack
, " %s -> ",
80 escape (tags
[rule_table
[rule
].lhs
]));
82 for (sp
= ritem
+ rule_table
[rule
].rhs
; sp
< sp1
; sp
++)
83 obstack_fgrow1 (node_obstack
, "%s ", escape (tags
[*sp
]));
85 obstack_1grow (node_obstack
, '.');
87 for (/* Nothing */; *sp
>= 0; ++sp
)
88 obstack_fgrow1 (node_obstack
, " %s", escape (tags
[*sp
]));
93 /*---------------------------------------------------------------.
94 | Output in graph_obstack edges specifications in incidence with |
96 `---------------------------------------------------------------*/
99 print_actions (state_t
*state
, const char *node_name
)
103 shifts
*shiftp
= state
->shifts
;
104 reductions
*redp
= state
->reductions
;
106 static char buff
[10];
109 if (!shiftp
->nshifts
&& !redp
)
112 for (i
= 0; i
< shiftp
->nshifts
; i
++)
113 if (!SHIFT_IS_DISABLED (shiftp
, i
))
115 int state1
= shiftp
->shifts
[i
];
116 int symbol
= state_table
[state1
]->accessing_symbol
;
120 if (state
->number
> state1
)
121 edge
.type
= back_edge
;
122 open_edge (&edge
, fgraph
);
123 /* The edge source is the current node. */
124 edge
.sourcename
= node_name
;
125 sprintf (buff
, "%d", state1
);
126 edge
.targetname
= buff
;
127 /* Shifts are blue, gotos are green, and error is red. */
128 if (SHIFT_IS_ERROR (shiftp
, i
))
131 edge
.color
= SHIFT_IS_SHIFT(shiftp
, i
) ? blue
: green
;
132 edge
.label
= escape (tags
[symbol
]);
133 output_edge (&edge
, fgraph
);
139 /*-------------------------------------------------------------.
140 | Output in FGRAPH the current node specifications and exiting |
142 `-------------------------------------------------------------*/
145 print_state (state_t
*state
)
147 static char name
[10];
148 struct obstack node_obstack
;
151 /* The labels of the nodes are their the items. */
152 obstack_init (&node_obstack
);
154 sprintf (name
, "%d", state
->number
);
156 print_core (state
, &node_obstack
);
157 obstack_1grow (&node_obstack
, '\0');
158 node
.label
= obstack_finish (&node_obstack
);
161 output_node (&node
, fgraph
);
164 /* Output the edges. */
165 print_actions (state
, name
);
167 obstack_free (&node_obstack
, 0);
177 fgraph
= xfopen (spec_graph_file
, "w");
182 graph
.smanhattan_edges
= yes
;
183 graph
.manhattan_edges
= yes
;
186 graph
.display_edge_labels
= yes
;
187 graph
.layoutalgorithm
= normal
;
189 graph
.port_sharing
= no
;
190 graph
.finetuning
= yes
;
191 graph
.straight_phase
= yes
;
192 graph
.priority_phase
= yes
;
195 graph
.crossing_weight
= median
;
197 /* Output graph options. */
199 output_graph (&graph
, fgraph
);
201 /* Output nodes and edges. */
202 new_closure (nritems
);
203 for (i
= 0; i
< nstates
; i
++)
204 print_state (state_table
[i
]);
208 close_graph (&graph
, fgraph
);