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