]> git.saurik.com Git - bison.git/blame - src/main.c
Change identifier spellings to avoid collisions with names
[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"
17ee7397
PE
24
25#include <bitset_stats.h>
26#include <bitset.h>
27#include <timevar.h>
28
29#include "LR0.h"
a0f6b076 30#include "complain.h"
17ee7397 31#include "conflicts.h"
cc84fd5d 32#include "derives.h"
17ee7397
PE
33#include "files.h"
34#include "getargs.h"
35#include "gram.h"
a70083a3 36#include "lalr.h"
17ee7397 37#include "muscle_tab.h"
3519ec76 38#include "nullable.h"
17ee7397 39#include "output.h"
07a58c13 40#include "print.h"
c4b66126 41#include "print_graph.h"
17ee7397
PE
42#include "reader.h"
43#include "reduce.h"
44#include "symtab.h"
45#include "tables.h"
46#include "uniqstr.h"
54bd0db4 47
a98ad01e 48/* The name this program was run with, for messages. */
54bd0db4
RS
49char *program_name;
50
caf23d24 51
caf23d24 52
54bd0db4 53int
d2729d44 54main (int argc, char *argv[])
54bd0db4
RS
55{
56 program_name = argv[0];
29340571 57 setlocale (LC_ALL, "");
c81bad89
PE
58 (void) bindtextdomain (PACKAGE, LOCALEDIR);
59 (void) textdomain (PACKAGE);
29340571 60
17ee7397 61 uniqstrs_new ();
95612cfa 62
cc84fd5d 63 getargs (argc, argv);
a0f6b076 64
17ee7397 65 timevar_report = trace_flag & trace_time;
1509d42f
AD
66 init_timevar ();
67 timevar_start (TV_TOTAL);
68
273a74fa 69 if (trace_flag & trace_bitsets)
613f5e1a
AD
70 bitset_stats_enable ();
71
11d82f03 72 muscle_init ();
54bd0db4 73
cc84fd5d
AD
74 /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE
75 and FATTRS. In file reader.c. The other parts are recorded in
76 the grammar; see gram.h. */
640748ee 77
1509d42f
AD
78 timevar_push (TV_READER);
79 reader ();
80 timevar_pop (TV_READER);
640748ee 81
5ca3209b 82 if (complaint_issued)
f6d0c239 83 goto finish;
54bd0db4 84
00238958 85 /* Find useless nonterminals and productions and reduce the grammar. */
1509d42f 86 timevar_push (TV_REDUCE);
cc84fd5d 87 reduce_grammar ();
1509d42f 88 timevar_pop (TV_REDUCE);
640748ee 89
7da99ede
AD
90 /* Record other info about the grammar. In files derives and
91 nullable. */
1509d42f 92 timevar_push (TV_SETS);
bb0027a9
AD
93 derives_compute ();
94 nullable_compute ();
1509d42f 95 timevar_pop (TV_SETS);
54bd0db4 96
7da99ede 97 /* Convert to nondeterministic finite state machine. In file LR0.
54bd0db4 98 See state.h for more info. */
1509d42f 99 timevar_push (TV_LR0);
cc84fd5d 100 generate_states ();
1509d42f 101 timevar_pop (TV_LR0);
54bd0db4
RS
102
103 /* make it deterministic. In file lalr. */
1509d42f 104 timevar_push (TV_LALR);
cc84fd5d 105 lalr ();
1509d42f 106 timevar_pop (TV_LALR);
54bd0db4 107
cc84fd5d
AD
108 /* Find and record any conflicts: places where one token of
109 lookahead is not enough to disambiguate the parsing. In file
110 conflicts. Also resolve s/r conflicts based on precedence
111 declarations. */
1509d42f 112 timevar_push (TV_CONFLICTS);
b408954b 113 conflicts_solve ();
0df87bb6 114 conflicts_print ();
1509d42f 115 timevar_pop (TV_CONFLICTS);
342b8b6e 116
c8f002c7
AD
117 /* Compute the parser tables. */
118 timevar_push (TV_ACTIONS);
119 tables_generate ();
120 timevar_pop (TV_ACTIONS);
121
122 grammar_rules_never_reduced_report
123 (_("rule never reduced because of conflicts"));
124
342b8b6e
AD
125 /* Output file names. */
126 compute_output_file_names ();
127
b7c49edf 128 /* Output the detailed report on the grammar. */
ec3bc396 129 if (report_flag)
1509d42f
AD
130 {
131 timevar_push (TV_REPORT);
132 print_results ();
133 timevar_pop (TV_REPORT);
134 }
b7c49edf 135
e8cb70b9 136 /* Output the VCG graph. */
64d15509 137 if (graph_flag)
1509d42f
AD
138 {
139 timevar_push (TV_GRAPH);
140 print_graph ();
141 timevar_pop (TV_GRAPH);
142 }
c4b66126 143
c8f002c7
AD
144 /* Stop if there were errors, to avoid trashing previous output
145 files. */
5ca3209b 146 if (complaint_issued)
f6d0c239 147 goto finish;
c6f1a33c 148
3325ddc4
AD
149 /* Lookaheads are no longer needed. */
150 timevar_push (TV_FREE);
151 lalr_free ();
152 timevar_pop (TV_FREE);
153
cc84fd5d 154 /* Output the tables and the parser to ftable. In file output. */
1509d42f 155 timevar_push (TV_PARSER);
cc84fd5d 156 output ();
1509d42f 157 timevar_pop (TV_PARSER);
a0f6b076 158
1509d42f 159 timevar_push (TV_FREE);
cd08e51e
AD
160 nullable_free ();
161 derives_free ();
c6f1a33c 162 tables_free ();
c7ca99d4 163 states_free ();
337c5bd1 164 reduce_free ();
b408954b 165 conflicts_free ();
76514394 166 grammar_free ();
4515534c
AD
167
168 /* The scanner memory cannot be released right after parsing, as it
169 contains things such as user actions, prologue, epilogue etc. */
170 scanner_free ();
592e8d4d 171 muscle_free ();
17ee7397 172 uniqstrs_free ();
722c4bfe
AD
173 /* If using alloca.c, flush the alloca'ed memory for the benefit of
174 people running Bison as a library in IDEs. */
175#if C_ALLOCA
640748ee 176 alloca (0);
722c4bfe 177#endif
1509d42f 178 timevar_pop (TV_FREE);
722c4bfe 179
273a74fa 180 if (trace_flag & trace_bitsets)
640748ee 181 bitset_stats_dump (stderr);
613f5e1a 182
f6d0c239
PE
183 finish:
184
1509d42f
AD
185 /* Stop timing and print the times. */
186 timevar_stop (TV_TOTAL);
187 timevar_print (stderr);
188
e95aed63 189 return complaint_issued ? EXIT_FAILURE : EXIT_SUCCESS;
54bd0db4 190}