Significant improvement: GEP used by a load or store no longer generates
[oota-llvm.git] / utils / Burg / main.c
1 char rcsid_main[] = "$Id$";
2
3 #include <math.h>
4 #include <stdio.h>
5 #include "b.h"
6 #include "fe.h"
7
8 int debugTables = 0;
9 static int simpleTables = 0;
10 static int internals = 0;
11 static int diagnostics = 0;
12
13 static char *inFileName;
14 static char *outFileName;
15
16 static char version[] = "BURG, Version 1.0";
17
18 extern void main ARGS((int argc, char **argv));
19
20 void
21 main(argc, argv) int argc; char **argv;
22 {
23         int i;
24         extern int atoi ARGS((char *));
25
26         for (i = 1; argv[i]; i++) {
27                 char **needStr = 0;
28                 int *needInt = 0;
29
30                 if (argv[i][0] == '-') {
31                         switch (argv[i][1]) {
32                         case 'V':
33                                 fprintf(stderr, "%s\n", version);
34                                 break;
35                         case 'p':
36                                 needStr = &prefix;
37                                 break;
38                         case 'o':
39                                 needStr = &outFileName;
40                                 break;
41                         case 'I':
42                                 internals = 1;
43                                 break;
44                         case 'T':
45                                 simpleTables = 1;
46                                 break;
47                         case '=':
48 #ifdef NOLEX
49                                 fprintf(stderr, "'%s' was not compiled to support lexicographic ordering\n", argv[0]);
50 #else
51                                 lexical = 1;
52 #endif /* NOLEX */
53                                 break;
54                         case 'O':
55                                 needInt = &principleCost;
56                                 break;
57                         case 'c':
58                                 needInt = &prevent_divergence;
59                                 break;
60                         case 'e':
61                                 needInt = &exceptionTolerance;
62                                 break;
63                         case 'd':
64                                 diagnostics = 1;
65                                 break;
66                         case 'S':
67                                 speedflag = 1;
68                                 break;
69                         case 't':
70                                 trimflag = 1;
71                                 break;
72                         case 'G':
73                                 grammarflag = 1;
74                                 break;
75                         default:
76                                 fprintf(stderr, "Bad option (%s)\n", argv[i]);
77                                 exit(1);
78                         }
79                 } else {
80                         if (inFileName) {
81                                 fprintf(stderr, "Unexpected Filename (%s) after (%s)\n", argv[i], inFileName);
82                                 exit(1);
83                         }
84                         inFileName = argv[i];
85                 }
86                 if (needInt || needStr) {
87                         char *v;
88                         char *opt = argv[i];
89
90                         if (argv[i][2]) {
91                                 v = &argv[i][2];
92                         } else {
93                                 v = argv[++i];
94                                 if (!v) {
95                                         fprintf(stderr, "Expection argument after %s\n", opt);
96                                         exit(1);
97                                 }
98                         }
99                         if (needInt) {
100                                 *needInt = atoi(v);
101                         } else if (needStr) {
102                                 *needStr = v;
103                         }
104                 }
105         }
106
107         if (inFileName) {
108                 if(freopen(inFileName, "r", stdin)==NULL) {
109                         fprintf(stderr, "Failed opening (%s)", inFileName);
110                         exit(1);
111                 }
112         }
113
114         if (outFileName) {
115                 if ((outfile = fopen(outFileName, "w")) == NULL) {
116                         fprintf(stderr, "Failed opening (%s)", outFileName);
117                         exit(1);
118                 }
119         } else {
120                 outfile = stdout;
121         }
122
123
124         yyparse();
125
126         if (!rules) {
127                 fprintf(stderr, "ERROR: No rules present\n");
128                 exit(1);
129         }
130
131         findChainRules();
132         findAllPairs();
133         doGrammarNts();
134         build();
135
136         debug(debugTables, foreachList((ListFn) dumpOperator_l, operators));
137         debug(debugTables, printf("---final set of states ---\n"));
138         debug(debugTables, dumpMapping(globalMap));
139
140
141         startBurm();
142         makeNts();
143         if (simpleTables) {
144                 makeSimple();
145         } else {
146                 makePlanks();
147         }
148
149         startOptional();
150         makeLabel();
151         makeKids();
152
153         if (internals) {
154                 makeChild();
155                 makeOpLabel();
156                 makeStateLabel();
157         }
158         endOptional();
159
160         makeOperatorVector();
161         makeNonterminals();
162         if (internals) {
163                 makeOperators();
164                 makeStringArray();
165                 makeRuleDescArray();
166                 makeCostArray();
167                 makeDeltaCostArray();
168                 makeStateStringArray();
169                 makeNonterminalArray();
170                 /*
171                 makeLHSmap();
172                 */
173         }
174         makeClosureArray();
175
176         if (diagnostics) {
177                 reportDiagnostics();
178         }
179
180         yypurge();
181         exit(0);
182 }