39 |
#include "conflicts.h" |
#include "conflicts.h" |
40 |
#include "print_graph.h" |
#include "print_graph.h" |
41 |
#include "muscle_tab.h" |
#include "muscle_tab.h" |
42 |
|
#include <malloc.h> |
43 |
|
#include <sys/times.h> |
44 |
|
|
45 |
/* The name this program was run with, for messages. */ |
/* The name this program was run with, for messages. */ |
46 |
char *program_name; |
char *program_name; |
47 |
|
|
48 |
|
static void |
49 |
|
stage (const char *title) |
50 |
|
{ |
51 |
|
struct mallinfo minfo = mallinfo (); |
52 |
|
struct tms tinfo; |
53 |
|
times (&tinfo); |
54 |
|
fprintf (stderr, "STAGE: %30s: %9d (%9d): %ldu %lds\n", |
55 |
|
title, |
56 |
|
minfo.uordblks, minfo.arena, |
57 |
|
tinfo.tms_utime, tinfo.tms_stime); |
58 |
|
} |
59 |
|
|
60 |
int |
int |
61 |
main (int argc, char *argv[]) |
main (int argc, char *argv[]) |
62 |
{ |
{ |
72 |
|
|
73 |
muscle_init (); |
muscle_init (); |
74 |
|
|
75 |
|
stage ("initialized muscles"); |
76 |
|
|
77 |
/* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE |
/* Read the input. Copy some parts of it to FGUARD, FACTION, FTABLE |
78 |
and FATTRS. In file reader.c. The other parts are recorded in |
and FATTRS. In file reader.c. The other parts are recorded in |
79 |
the grammar; see gram.h. */ |
the grammar; see gram.h. */ |
80 |
reader (); |
reader (); |
81 |
|
|
82 |
|
stage ("reader"); |
83 |
|
|
84 |
if (complain_message_count) |
if (complain_message_count) |
85 |
exit (1); |
exit (1); |
86 |
|
|
87 |
/* Find useless nonterminals and productions and reduce the grammar. */ |
/* Find useless nonterminals and productions and reduce the grammar. */ |
88 |
reduce_grammar (); |
reduce_grammar (); |
89 |
|
|
90 |
|
stage ("reduced grammar"); |
91 |
|
|
92 |
/* Record other info about the grammar. In files derives and |
/* Record other info about the grammar. In files derives and |
93 |
nullable. */ |
nullable. */ |
94 |
set_derives (); |
set_derives (); |
98 |
See state.h for more info. */ |
See state.h for more info. */ |
99 |
generate_states (); |
generate_states (); |
100 |
|
|
101 |
|
stage ("generated states"); |
102 |
/* make it deterministic. In file lalr. */ |
/* make it deterministic. In file lalr. */ |
103 |
lalr (); |
lalr (); |
104 |
|
|
105 |
|
stage ("lalred"); |
106 |
/* Find and record any conflicts: places where one token of |
/* Find and record any conflicts: places where one token of |
107 |
lookahead is not enough to disambiguate the parsing. In file |
lookahead is not enough to disambiguate the parsing. In file |
108 |
conflicts. Also resolve s/r conflicts based on precedence |
conflicts. Also resolve s/r conflicts based on precedence |
110 |
conflicts_solve (); |
conflicts_solve (); |
111 |
conflicts_print (); |
conflicts_print (); |
112 |
|
|
113 |
|
stage ("solved conflicts"); |
114 |
/* Output file names. */ |
/* Output file names. */ |
115 |
compute_output_file_names (); |
compute_output_file_names (); |
116 |
|
|
118 |
if (report_flag) |
if (report_flag) |
119 |
print_results (); |
print_results (); |
120 |
|
|
121 |
|
stage ("printed results"); |
122 |
/* Stop if there were errors, to avoid trashing previous output |
/* Stop if there were errors, to avoid trashing previous output |
123 |
files. */ |
files. */ |
124 |
if (complain_message_count) |
if (complain_message_count) |
130 |
|
|
131 |
/* Output the tables and the parser to ftable. In file output. */ |
/* Output the tables and the parser to ftable. In file output. */ |
132 |
output (); |
output (); |
133 |
|
stage ("made output"); |
134 |
|
|
135 |
states_free (); |
states_free (); |
136 |
|
stage ("freed states"); |
137 |
reduce_free (); |
reduce_free (); |
138 |
|
stage ("freed reduce"); |
139 |
conflicts_free (); |
conflicts_free (); |
140 |
|
stage ("freed conflicts"); |
141 |
free_nullable (); |
free_nullable (); |
142 |
|
stage ("freed nullable"); |
143 |
free_derives (); |
free_derives (); |
144 |
|
stage ("freed derives"); |
145 |
grammar_free (); |
grammar_free (); |
146 |
|
stage ("freed grammar"); |
147 |
|
|
148 |
/* The scanner memory cannot be released right after parsing, as it |
/* The scanner memory cannot be released right after parsing, as it |
149 |
contains things such as user actions, prologue, epilogue etc. */ |
contains things such as user actions, prologue, epilogue etc. */ |
150 |
scanner_free (); |
scanner_free (); |
151 |
|
stage ("freed scanner"); |
152 |
muscle_free (); |
muscle_free (); |
153 |
|
stage ("freed muscles"); |
154 |
/* If using alloca.c, flush the alloca'ed memory for the benefit of |
/* If using alloca.c, flush the alloca'ed memory for the benefit of |
155 |
people running Bison as a library in IDEs. */ |
people running Bison as a library in IDEs. */ |
156 |
#if C_ALLOCA |
#if C_ALLOCA |
157 |
alloca (0); |
alloca (0); |
158 |
#endif |
#endif |
159 |
|
|
160 |
if (trace_flag) |
if (trace_flag) |
161 |
bitset_stats_dump (stderr); |
bitset_stats_dump (stderr); |
162 |
|
|
163 |
return complain_message_count ? EXIT_FAILURE : EXIT_SUCCESS; |
return complain_message_count ? EXIT_FAILURE : EXIT_SUCCESS; |
164 |
} |
} |