attempt to fix cc flags in tests
[qbe.git] / main.c
blobf8d367f8830171666c85209410a8b32d4cf4d20b
1 #include "all.h"
2 #include "config.h"
3 #include <ctype.h>
4 #include <getopt.h>
6 char debug['Z'+1] = {
7 ['P'] = 0, /* parsing */
8 ['A'] = 0, /* abi lowering */
9 ['I'] = 0, /* instruction selection */
10 ['L'] = 0, /* liveness */
11 ['M'] = 0, /* memory optimization */
12 ['N'] = 0, /* ssa construction */
13 ['C'] = 0, /* copy elimination */
14 ['F'] = 0, /* constant folding */
15 ['S'] = 0, /* spilling */
16 ['R'] = 0, /* reg. allocation */
19 static FILE *outf;
20 static int dbg;
22 static void
23 data(Dat *d)
25 if (dbg)
26 return;
27 if (d->type == DEnd) {
28 fputs("/* end data */\n\n", outf);
29 freeall();
31 emitdat(d, outf);
34 static void
35 func(Fn *fn)
37 int n;
39 if (dbg)
40 fprintf(stderr, "**** Function %s ****", fn->name);
41 if (debug['P']) {
42 fprintf(stderr, "\n> After parsing:\n");
43 printfn(fn, stderr);
45 fillrpo(fn);
46 fillpreds(fn);
47 filluse(fn);
48 /* memopt(fn); */
49 ssa(fn);
50 filluse(fn);
51 ssacheck(fn);
52 fillloop(fn);
53 fillalias(fn);
54 loadopt(fn);
55 filluse(fn);
56 ssacheck(fn);
57 copy(fn);
58 filluse(fn);
59 fold(fn);
60 abi(fn);
61 filluse(fn);
62 isel(fn);
63 fillrpo(fn);
64 filllive(fn);
65 fillcost(fn);
66 spill(fn);
67 rega(fn);
68 fillrpo(fn);
69 assert(fn->rpo[0] == fn->start);
70 for (n=0;; n++)
71 if (n == fn->nblk-1) {
72 fn->rpo[n]->link = 0;
73 break;
74 } else
75 fn->rpo[n]->link = fn->rpo[n+1];
76 if (!dbg) {
77 emitfn(fn, outf);
78 fprintf(outf, "/* end function %s */\n\n", fn->name);
79 } else
80 fprintf(stderr, "\n");
81 freeall();
84 int
85 main(int ac, char *av[])
87 FILE *inf;
88 char *f;
89 int c, asm;
91 asm = Defaultasm;
92 outf = stdout;
93 while ((c = getopt(ac, av, "hd:o:G:")) != -1)
94 switch (c) {
95 case 'd':
96 for (; *optarg; optarg++)
97 if (isalpha(*optarg)) {
98 debug[toupper(*optarg)] = 1;
99 dbg = 1;
101 break;
102 case 'o':
103 if (strcmp(optarg, "-") != 0)
104 outf = fopen(optarg, "w");
105 break;
106 case 'G':
107 if (strcmp(optarg, "e") == 0)
108 asm = Gaself;
109 else if (strcmp(optarg, "m") == 0)
110 asm = Gasmacho;
111 else {
112 fprintf(stderr, "unknown gas flavor '%s'\n", optarg);
113 exit(1);
115 break;
116 case 'h':
117 default:
118 fprintf(stderr, "%s [OPTIONS] {file.ssa, -}\n", av[0]);
119 fprintf(stderr, "\t%-10s prints this help\n", "-h");
120 fprintf(stderr, "\t%-10s output to file\n", "-o file");
121 fprintf(stderr, "\t%-10s generate gas (e) or osx (m) asm\n", "-G {e,m}");
122 fprintf(stderr, "\t%-10s dump debug information\n", "-d <flags>");
123 exit(c != 'h');
126 switch (asm) {
127 case Gaself:
128 locprefix = ".L";
129 symprefix = "";
130 break;
131 case Gasmacho:
132 locprefix = "L";
133 symprefix = "_";
134 break;
137 do {
138 f = av[optind];
139 if (!f || strcmp(f, "-") == 0) {
140 inf = stdin;
141 f = "-";
142 } else {
143 inf = fopen(f, "r");
144 if (!inf) {
145 fprintf(stderr, "cannot open '%s'\n", f);
146 exit(1);
149 parse(inf, f, data, func);
150 } while (++optind < ac);
152 if (!dbg)
153 emitfin(outf);
155 exit(0);