]>
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 (state_t
*state
, struct obstack
*node_obstack
)
44 short *sitems
= state
->items
;
45 int snitems
= 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
->number
);
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 (state_t
*state
, const char *node_name
)
92 shifts
*shiftp
= state
->shifts
;
93 reductions
*redp
= state
->reductions
;
98 if (!shiftp
->nshifts
&& !redp
)
101 for (i
= 0; i
< shiftp
->nshifts
; i
++)
102 if (!SHIFT_IS_DISABLED (shiftp
, i
))
104 int state1
= shiftp
->shifts
[i
];
105 int symbol
= state_table
[state1
]->accessing_symbol
;
109 if (state
->number
> state1
)
110 edge
.type
= back_edge
;
111 open_edge (&edge
, fgraph
);
112 /* The edge source is the current node. */
113 edge
.sourcename
= node_name
;
114 sprintf (buff
, "%d", state1
);
115 edge
.targetname
= buff
;
116 /* Shifts are blue, gotos are red. */
117 edge
.color
= SHIFT_IS_SHIFT(shiftp
, i
) ? blue
: red
;
118 edge
.label
= tags
[symbol
];
119 output_edge (&edge
, fgraph
);
125 /*-------------------------------------------------------------.
126 | Output in FGRAPH the current node specifications and exiting |
128 `-------------------------------------------------------------*/
131 print_state (state_t
*state
)
133 static char name
[10];
134 struct obstack node_obstack
;
137 /* The labels of the nodes are their the items. */
138 obstack_init (&node_obstack
);
140 sprintf (name
, "%d", state
->number
);
142 print_core (state
, &node_obstack
);
143 obstack_1grow (&node_obstack
, '\0');
144 node
.label
= obstack_finish (&node_obstack
);
147 output_node (&node
, fgraph
);
150 /* Output the edges. */
151 print_actions (state
, name
);
153 obstack_free (&node_obstack
, 0);
163 fgraph
= xfopen (spec_graph_file
, "w");
168 graph
.smanhattan_edges
= yes
;
169 graph
.manhattan_edges
= yes
;
172 graph
.display_edge_labels
= yes
;
173 graph
.layoutalgorithm
= normal
;
175 graph
.port_sharing
= no
;
176 graph
.finetuning
= yes
;
177 graph
.straight_phase
= yes
;
178 graph
.priority_phase
= yes
;
181 graph
.crossing_weight
= median
;
183 /* Output graph options. */
185 output_graph (&graph
, fgraph
);
187 /* Output nodes and edges. */
188 new_closure (nitems
);
189 for (i
= 0; i
< nstates
; i
++)
190 print_state (state_table
[i
]);
194 close_graph (&graph
, fgraph
);