]> git.saurik.com Git - bison.git/blob - src/main.c
Steal GCC's --time-report support.
[bison.git] / src / main.c
1 /* Top level entry point of bison,
2 Copyright 1984, 1986, 1989, 1992, 1995, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4
5 This file is part of Bison, the GNU Compiler Compiler.
6
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.
11
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.
16
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. */
21
22
23 #include "system.h"
24 #include "bitset_stats.h"
25 #include "bitset.h"
26 #include "getargs.h"
27 #include "symtab.h"
28 #include "gram.h"
29 #include "files.h"
30 #include "complain.h"
31 #include "derives.h"
32 #include "output.h"
33 #include "reader.h"
34 #include "lalr.h"
35 #include "reduce.h"
36 #include "nullable.h"
37 #include "print.h"
38 #include "LR0.h"
39 #include "conflicts.h"
40 #include "print_graph.h"
41 #include "muscle_tab.h"
42
43 /* The name this program was run with, for messages. */
44 char *program_name;
45
46
47
48 int
49 main (int argc, char *argv[])
50 {
51 program_name = argv[0];
52 setlocale (LC_ALL, "");
53 bindtextdomain (PACKAGE, LOCALEDIR);
54 textdomain (PACKAGE);
55
56 getargs (argc, argv);
57
58 time_report = trace_flag & trace_time;
59 init_timevar ();
60 timevar_start (TV_TOTAL);
61
62 if (trace_flag & trace_bitsets)
63 bitset_stats_enable ();
64
65 muscle_init ();
66
67 /* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE
68 and FATTRS. In file reader.c. The other parts are recorded in
69 the grammar; see gram.h. */
70
71 timevar_push (TV_READER);
72 reader ();
73 timevar_pop (TV_READER);
74
75 if (complain_message_count)
76 exit (1);
77
78 /* Find useless nonterminals and productions and reduce the grammar. */
79 timevar_push (TV_REDUCE);
80 reduce_grammar ();
81 timevar_pop (TV_REDUCE);
82
83 /* Record other info about the grammar. In files derives and
84 nullable. */
85 timevar_push (TV_SETS);
86 set_derives ();
87 set_nullable ();
88 timevar_pop (TV_SETS);
89
90 /* Convert to nondeterministic finite state machine. In file LR0.
91 See state.h for more info. */
92 timevar_push (TV_LR0);
93 generate_states ();
94 timevar_pop (TV_LR0);
95
96 /* make it deterministic. In file lalr. */
97 timevar_push (TV_LALR);
98 lalr ();
99 timevar_pop (TV_LALR);
100
101 /* Find and record any conflicts: places where one token of
102 lookahead is not enough to disambiguate the parsing. In file
103 conflicts. Also resolve s/r conflicts based on precedence
104 declarations. */
105 timevar_push (TV_CONFLICTS);
106 conflicts_solve ();
107 conflicts_print ();
108 timevar_pop (TV_CONFLICTS);
109
110 /* Output file names. */
111 compute_output_file_names ();
112
113 /* Output the detailed report on the grammar. */
114 if (report_flag)
115 {
116 timevar_push (TV_REPORT);
117 print_results ();
118 timevar_pop (TV_REPORT);
119 }
120
121 /* Stop if there were errors, to avoid trashing previous output
122 files. */
123 if (complain_message_count)
124 exit (1);
125
126 /* Output the VCG graph. */
127 if (graph_flag)
128 {
129 timevar_push (TV_GRAPH);
130 print_graph ();
131 timevar_pop (TV_GRAPH);
132 }
133
134 /* Output the tables and the parser to ftable. In file output. */
135 timevar_push (TV_PARSER);
136 output ();
137 timevar_pop (TV_PARSER);
138
139 timevar_push (TV_FREE);
140 states_free ();
141 reduce_free ();
142 conflicts_free ();
143 free_nullable ();
144 free_derives ();
145 grammar_free ();
146
147 /* The scanner memory cannot be released right after parsing, as it
148 contains things such as user actions, prologue, epilogue etc. */
149 scanner_free ();
150 muscle_free ();
151 /* If using alloca.c, flush the alloca'ed memory for the benefit of
152 people running Bison as a library in IDEs. */
153 #if C_ALLOCA
154 alloca (0);
155 #endif
156 timevar_pop (TV_FREE);
157
158 if (trace_flag & trace_bitsets)
159 bitset_stats_dump (stderr);
160
161 /* Stop timing and print the times. */
162 timevar_stop (TV_TOTAL);
163 timevar_print (stderr);
164
165 return complain_message_count ? EXIT_FAILURE : EXIT_SUCCESS;
166 }