]>
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. */
56 closure (sitems
, snitems
);
60 obstack_fgrow1 (node_obstack
, "state %2d\n", state
->number
);
61 for (i
= 0; i
< snitems
; i
++)
67 sp1
= sp
= ritem
+ sitems
[i
];
75 obstack_1grow (node_obstack
, '\n');
76 obstack_fgrow1 (node_obstack
, " %s -> ",
77 escape (tags
[rule_table
[rule
].lhs
]));
79 for (sp
= ritem
+ rule_table
[rule
].rhs
; sp
< sp1
; sp
++)
80 obstack_fgrow1 (node_obstack
, "%s ", escape (tags
[*sp
]));
82 obstack_1grow (node_obstack
, '.');
84 for (/* Nothing */; *sp
> 0; ++sp
)
85 obstack_fgrow1 (node_obstack
, " %s", escape (tags
[*sp
]));
90 /*---------------------------------------------------------------.
91 | Output in graph_obstack edges specifications in incidence with |
93 `---------------------------------------------------------------*/
96 print_actions (state_t
*state
, const char *node_name
)
100 shifts
*shiftp
= state
->shifts
;
101 reductions
*redp
= state
->reductions
;
103 static char buff
[10];
106 if (!shiftp
->nshifts
&& !redp
)
109 for (i
= 0; i
< shiftp
->nshifts
; i
++)
110 if (!SHIFT_IS_DISABLED (shiftp
, i
))
112 int state1
= shiftp
->shifts
[i
];
113 int symbol
= state_table
[state1
]->accessing_symbol
;
117 if (state
->number
> state1
)
118 edge
.type
= back_edge
;
119 open_edge (&edge
, fgraph
);
120 /* The edge source is the current node. */
121 edge
.sourcename
= node_name
;
122 sprintf (buff
, "%d", state1
);
123 edge
.targetname
= buff
;
124 /* Shifts are blue, gotos are green, and error is red. */
125 if (SHIFT_IS_ERROR (shiftp
, i
))
128 edge
.color
= SHIFT_IS_SHIFT(shiftp
, i
) ? blue
: green
;
129 edge
.label
= escape (tags
[symbol
]);
130 output_edge (&edge
, fgraph
);
136 /*-------------------------------------------------------------.
137 | Output in FGRAPH the current node specifications and exiting |
139 `-------------------------------------------------------------*/
142 print_state (state_t
*state
)
144 static char name
[10];
145 struct obstack node_obstack
;
148 /* The labels of the nodes are their the items. */
149 obstack_init (&node_obstack
);
151 sprintf (name
, "%d", state
->number
);
153 print_core (state
, &node_obstack
);
154 obstack_1grow (&node_obstack
, '\0');
155 node
.label
= obstack_finish (&node_obstack
);
158 output_node (&node
, fgraph
);
161 /* Output the edges. */
162 print_actions (state
, name
);
164 obstack_free (&node_obstack
, 0);
174 fgraph
= xfopen (spec_graph_file
, "w");
179 graph
.smanhattan_edges
= yes
;
180 graph
.manhattan_edges
= yes
;
183 graph
.display_edge_labels
= yes
;
184 graph
.layoutalgorithm
= normal
;
186 graph
.port_sharing
= no
;
187 graph
.finetuning
= yes
;
188 graph
.straight_phase
= yes
;
189 graph
.priority_phase
= yes
;
192 graph
.crossing_weight
= median
;
194 /* Output graph options. */
196 output_graph (&graph
, fgraph
);
198 /* Output nodes and edges. */
199 new_closure (nitems
);
200 for (i
= 0; i
< nstates
; i
++)
201 print_state (state_table
[i
]);
205 close_graph (&graph
, fgraph
);