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