]>
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"
33 #include "print_graph.h"
37 static FILE *fgraph
= NULL
;
39 /* This part will construct the label of nodes. */
41 print_core (int state
, struct obstack
*node_obstack
)
44 short *sitems
= state_table
[state
]->items
;
45 int snitems
= state_table
[state
]->nitems
;
47 /* Output all the items of a state, not only its kernel. */
48 closure (sitems
, snitems
);
52 obstack_fgrow1 (node_obstack
, "%2d: ", state
);
53 for (i
= 0; i
< snitems
; i
++)
59 sp1
= sp
= ritem
+ sitems
[i
];
67 obstack_sgrow (node_obstack
, "\n ");
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
, '.');
76 for (/* Nothing */; *sp
> 0; ++sp
)
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
)
92 shifts
*shiftp
= state_table
[state
]->shifts
;
93 reductions
*redp
= state_table
[state
]->reductions
;
95 errs
*errp
= state_table
[state
]->errs
;
101 if (!shiftp
->nshifts
&& !redp
)
104 if (final_state
== state
)
105 obstack_sgrow (node_obstack
, "$default: accept");
107 obstack_sgrow (node_obstack
, "NO ACTIONS");
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
;
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 red. */
128 edge
.color
= SHIFT_IS_SHIFT(shiftp
, i
) ? blue
: red
;
129 edge
.label
= tags
[symbol
];
130 output_edge (&edge
, fgraph
);
141 for (j
= 0; j
< nerrs
; j
++)
145 symbol
= errp
->errs
[j
];
146 /* If something has been added in the NODE_OBSTACK after
147 the declaration of the label, then we need a `\n'.
148 if (obstack_object_size (node_obstack) > node_output_size)
149 obstack_sgrow (node_obstack, "\n");
151 obstack_fgrow1 (node_obstack
, _("%-4s\terror (nonassociative)"),
155 obstack_1grow (node_obstack
, '\n');
158 if (state_table
[state
]->consistent
&& redp
)
160 rule
= redp
->rules
[0];
161 symbol
= rule_table
[rule
].lhs
;
163 if (obstack_object_size (node_obstack) > node_output_size)
164 obstack_sgrow (node_obstack, "\n");
166 obstack_fgrow2 (node_obstack
, _("$default\treduce using rule %d (%s)"),
173 /*-------------------------------------------------------------.
174 | Output in FGRAPH the current node specifications and exiting |
176 `-------------------------------------------------------------*/
179 print_state (int state
)
181 static char name
[10];
182 struct obstack node_obstack
;
185 /* The labels of the nodes are their the items. */
186 obstack_init (&node_obstack
);
188 sprintf (name
, "%d", state
);
190 print_core (state
, &node_obstack
);
191 obstack_1grow (&node_obstack
, '\0');
192 node
.label
= obstack_finish (&node_obstack
);
195 output_node (&node
, fgraph
);
198 /* Output the edges. */
199 print_actions (state
, name
);
201 obstack_free (&node_obstack
, 0);
211 fgraph
= xfopen (spec_graph_file
, "w");
216 graph
.smanhattan_edges
= yes
;
217 graph
.manhattan_edges
= yes
;
220 graph
.display_edge_labels
= yes
;
221 graph
.layoutalgorithm
= normal
;
223 graph
.port_sharing
= no
;
224 graph
.finetuning
= yes
;
225 graph
.straight_phase
= yes
;
226 graph
.priority_phase
= yes
;
229 graph
.crossing_weight
= median
;
231 /* Output graph options. */
233 output_graph (&graph
, fgraph
);
235 /* Output nodes and edges. */
236 new_closure (nitems
);
237 for (i
= 0; i
< nstates
; i
++)
242 close_graph (&graph
, fgraph
);