]>
Commit | Line | Data |
---|---|---|
a54a1bdc PE |
1 | /* Top level entry point of Bison. |
2 | ||
8dd162d3 | 3 | Copyright (C) 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002, 2004 |
ceed8467 | 4 | Free Software Foundation, Inc. |
54bd0db4 | 5 | |
e87b5700 | 6 | This file is part of Bison, the GNU Compiler Compiler. |
54bd0db4 | 7 | |
e87b5700 AD |
8 | Bison is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
54bd0db4 | 12 | |
e87b5700 AD |
13 | Bison is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
54bd0db4 | 17 | |
e87b5700 AD |
18 | You should have received a copy of the GNU General Public License |
19 | along with Bison; see the file COPYING. If not, write to | |
0fb669f9 PE |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. */ | |
54bd0db4 RS |
22 | |
23 | ||
54bd0db4 | 24 | #include "system.h" |
17ee7397 PE |
25 | |
26 | #include <bitset_stats.h> | |
27 | #include <bitset.h> | |
28 | #include <timevar.h> | |
29 | ||
30 | #include "LR0.h" | |
a0f6b076 | 31 | #include "complain.h" |
17ee7397 | 32 | #include "conflicts.h" |
cc84fd5d | 33 | #include "derives.h" |
17ee7397 PE |
34 | #include "files.h" |
35 | #include "getargs.h" | |
36 | #include "gram.h" | |
a70083a3 | 37 | #include "lalr.h" |
17ee7397 | 38 | #include "muscle_tab.h" |
3519ec76 | 39 | #include "nullable.h" |
17ee7397 | 40 | #include "output.h" |
07a58c13 | 41 | #include "print.h" |
c4b66126 | 42 | #include "print_graph.h" |
17ee7397 PE |
43 | #include "reader.h" |
44 | #include "reduce.h" | |
45 | #include "symtab.h" | |
46 | #include "tables.h" | |
47 | #include "uniqstr.h" | |
54bd0db4 | 48 | |
a98ad01e | 49 | /* The name this program was run with, for messages. */ |
54bd0db4 RS |
50 | char *program_name; |
51 | ||
caf23d24 | 52 | |
caf23d24 | 53 | |
54bd0db4 | 54 | int |
d2729d44 | 55 | main (int argc, char *argv[]) |
54bd0db4 RS |
56 | { |
57 | program_name = argv[0]; | |
29340571 | 58 | setlocale (LC_ALL, ""); |
f7ab6a50 PE |
59 | bindtextdomain (PACKAGE, LOCALEDIR); |
60 | bindtextdomain ("bison-runtime", LOCALEDIR); | |
61 | textdomain (PACKAGE); | |
29340571 | 62 | |
17ee7397 | 63 | uniqstrs_new (); |
95612cfa | 64 | |
cc84fd5d | 65 | getargs (argc, argv); |
a0f6b076 | 66 | |
17ee7397 | 67 | timevar_report = trace_flag & trace_time; |
1509d42f AD |
68 | init_timevar (); |
69 | timevar_start (TV_TOTAL); | |
70 | ||
273a74fa | 71 | if (trace_flag & trace_bitsets) |
613f5e1a AD |
72 | bitset_stats_enable (); |
73 | ||
11d82f03 | 74 | muscle_init (); |
54bd0db4 | 75 | |
cc84fd5d AD |
76 | /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE |
77 | and FATTRS. In file reader.c. The other parts are recorded in | |
78 | the grammar; see gram.h. */ | |
640748ee | 79 | |
1509d42f AD |
80 | timevar_push (TV_READER); |
81 | reader (); | |
82 | timevar_pop (TV_READER); | |
640748ee | 83 | |
5ca3209b | 84 | if (complaint_issued) |
f6d0c239 | 85 | goto finish; |
54bd0db4 | 86 | |
00238958 | 87 | /* Find useless nonterminals and productions and reduce the grammar. */ |
1509d42f | 88 | timevar_push (TV_REDUCE); |
cc84fd5d | 89 | reduce_grammar (); |
1509d42f | 90 | timevar_pop (TV_REDUCE); |
640748ee | 91 | |
7da99ede AD |
92 | /* Record other info about the grammar. In files derives and |
93 | nullable. */ | |
1509d42f | 94 | timevar_push (TV_SETS); |
bb0027a9 AD |
95 | derives_compute (); |
96 | nullable_compute (); | |
1509d42f | 97 | timevar_pop (TV_SETS); |
54bd0db4 | 98 | |
7da99ede | 99 | /* Convert to nondeterministic finite state machine. In file LR0. |
54bd0db4 | 100 | See state.h for more info. */ |
1509d42f | 101 | timevar_push (TV_LR0); |
cc84fd5d | 102 | generate_states (); |
1509d42f | 103 | timevar_pop (TV_LR0); |
54bd0db4 RS |
104 | |
105 | /* make it deterministic. In file lalr. */ | |
1509d42f | 106 | timevar_push (TV_LALR); |
cc84fd5d | 107 | lalr (); |
1509d42f | 108 | timevar_pop (TV_LALR); |
54bd0db4 | 109 | |
cc84fd5d | 110 | /* Find and record any conflicts: places where one token of |
8dd162d3 | 111 | look-ahead is not enough to disambiguate the parsing. In file |
cc84fd5d AD |
112 | conflicts. Also resolve s/r conflicts based on precedence |
113 | declarations. */ | |
1509d42f | 114 | timevar_push (TV_CONFLICTS); |
b408954b | 115 | conflicts_solve (); |
0df87bb6 | 116 | conflicts_print (); |
1509d42f | 117 | timevar_pop (TV_CONFLICTS); |
342b8b6e | 118 | |
c8f002c7 AD |
119 | /* Compute the parser tables. */ |
120 | timevar_push (TV_ACTIONS); | |
121 | tables_generate (); | |
122 | timevar_pop (TV_ACTIONS); | |
123 | ||
124 | grammar_rules_never_reduced_report | |
125 | (_("rule never reduced because of conflicts")); | |
126 | ||
342b8b6e AD |
127 | /* Output file names. */ |
128 | compute_output_file_names (); | |
129 | ||
b7c49edf | 130 | /* Output the detailed report on the grammar. */ |
ec3bc396 | 131 | if (report_flag) |
1509d42f AD |
132 | { |
133 | timevar_push (TV_REPORT); | |
134 | print_results (); | |
135 | timevar_pop (TV_REPORT); | |
136 | } | |
b7c49edf | 137 | |
e8cb70b9 | 138 | /* Output the VCG graph. */ |
64d15509 | 139 | if (graph_flag) |
1509d42f AD |
140 | { |
141 | timevar_push (TV_GRAPH); | |
142 | print_graph (); | |
143 | timevar_pop (TV_GRAPH); | |
144 | } | |
c4b66126 | 145 | |
c8f002c7 AD |
146 | /* Stop if there were errors, to avoid trashing previous output |
147 | files. */ | |
5ca3209b | 148 | if (complaint_issued) |
f6d0c239 | 149 | goto finish; |
c6f1a33c | 150 | |
8dd162d3 | 151 | /* Look-ahead tokens are no longer needed. */ |
3325ddc4 AD |
152 | timevar_push (TV_FREE); |
153 | lalr_free (); | |
154 | timevar_pop (TV_FREE); | |
155 | ||
cc84fd5d | 156 | /* Output the tables and the parser to ftable. In file output. */ |
1509d42f | 157 | timevar_push (TV_PARSER); |
cc84fd5d | 158 | output (); |
1509d42f | 159 | timevar_pop (TV_PARSER); |
a0f6b076 | 160 | |
1509d42f | 161 | timevar_push (TV_FREE); |
cd08e51e AD |
162 | nullable_free (); |
163 | derives_free (); | |
c6f1a33c | 164 | tables_free (); |
c7ca99d4 | 165 | states_free (); |
337c5bd1 | 166 | reduce_free (); |
b408954b | 167 | conflicts_free (); |
76514394 | 168 | grammar_free (); |
4515534c AD |
169 | |
170 | /* The scanner memory cannot be released right after parsing, as it | |
171 | contains things such as user actions, prologue, epilogue etc. */ | |
172 | scanner_free (); | |
592e8d4d | 173 | muscle_free (); |
17ee7397 | 174 | uniqstrs_free (); |
722c4bfe AD |
175 | /* If using alloca.c, flush the alloca'ed memory for the benefit of |
176 | people running Bison as a library in IDEs. */ | |
177 | #if C_ALLOCA | |
a54a1bdc PE |
178 | { |
179 | extern void *alloca (size_t); | |
180 | alloca (0); | |
181 | } | |
722c4bfe | 182 | #endif |
1509d42f | 183 | timevar_pop (TV_FREE); |
722c4bfe | 184 | |
273a74fa | 185 | if (trace_flag & trace_bitsets) |
640748ee | 186 | bitset_stats_dump (stderr); |
613f5e1a | 187 | |
f6d0c239 PE |
188 | finish: |
189 | ||
1509d42f AD |
190 | /* Stop timing and print the times. */ |
191 | timevar_stop (TV_TOTAL); | |
192 | timevar_print (stderr); | |
193 | ||
e95aed63 | 194 | return complaint_issued ? EXIT_FAILURE : EXIT_SUCCESS; |
54bd0db4 | 195 | } |