disable pie for arm64 tests
[qbe.git] / main.c
blob56529c9e33ee5a8ef16ac254470f48d907d853f3
1 #include "all.h"
2 #include "config.h"
3 #include <ctype.h>
4 #include <getopt.h>
6 Target T;
8 extern Target T_amd64_sysv;
9 extern Target T_arm64;
11 static struct TMap {
12 char *name;
13 Target *T;
14 } tmap[] = {
15 { "amd64_sysv", &T_amd64_sysv },
16 { "arm64", &T_arm64 },
17 { 0, 0 }
20 enum Asm {
21 Gasmacho,
22 Gaself,
25 char debug['Z'+1] = {
26 ['P'] = 0, /* parsing */
27 ['A'] = 0, /* abi lowering */
28 ['I'] = 0, /* instruction selection */
29 ['L'] = 0, /* liveness */
30 ['M'] = 0, /* memory optimization */
31 ['N'] = 0, /* ssa construction */
32 ['C'] = 0, /* copy elimination */
33 ['F'] = 0, /* constant folding */
34 ['S'] = 0, /* spilling */
35 ['R'] = 0, /* reg. allocation */
38 static FILE *outf;
39 static int dbg;
41 static void
42 data(Dat *d)
44 if (dbg)
45 return;
46 if (d->type == DEnd) {
47 fputs("/* end data */\n\n", outf);
48 freeall();
50 gasemitdat(d, outf);
53 static void
54 func(Fn *fn)
56 uint n;
58 if (dbg)
59 fprintf(stderr, "**** Function %s ****", fn->name);
60 if (debug['P']) {
61 fprintf(stderr, "\n> After parsing:\n");
62 printfn(fn, stderr);
64 fillrpo(fn);
65 fillpreds(fn);
66 filluse(fn);
67 memopt(fn);
68 filluse(fn);
69 ssa(fn);
70 filluse(fn);
71 ssacheck(fn);
72 fillalias(fn);
73 loadopt(fn);
74 filluse(fn);
75 ssacheck(fn);
76 copy(fn);
77 filluse(fn);
78 fold(fn);
79 T.abi(fn);
80 fillpreds(fn);
81 filluse(fn);
82 T.isel(fn);
83 fillrpo(fn);
84 filllive(fn);
85 fillloop(fn);
86 fillcost(fn);
87 spill(fn);
88 rega(fn);
89 fillrpo(fn);
90 simpljmp(fn);
91 fillpreds(fn);
92 fillrpo(fn);
93 assert(fn->rpo[0] == fn->start);
94 for (n=0;; n++)
95 if (n == fn->nblk-1) {
96 fn->rpo[n]->link = 0;
97 break;
98 } else
99 fn->rpo[n]->link = fn->rpo[n+1];
100 if (!dbg) {
101 T.emitfn(fn, outf);
102 fprintf(outf, "/* end function %s */\n\n", fn->name);
103 } else
104 fprintf(stderr, "\n");
105 freeall();
109 main(int ac, char *av[])
111 struct TMap *tm;
112 FILE *inf, *hf;
113 char *f, *sep;
114 int c, asm;
116 asm = Defasm;
117 T = Deftgt;
118 outf = stdout;
119 while ((c = getopt(ac, av, "hd:o:G:t:")) != -1)
120 switch (c) {
121 case 'd':
122 for (; *optarg; optarg++)
123 if (isalpha(*optarg)) {
124 debug[toupper(*optarg)] = 1;
125 dbg = 1;
127 break;
128 case 'o':
129 if (strcmp(optarg, "-") != 0)
130 outf = fopen(optarg, "w");
131 break;
132 case 't':
133 for (tm=tmap;; tm++) {
134 if (!tm->name) {
135 fprintf(stderr, "unknown target '%s'\n", optarg);
136 exit(1);
138 if (strcmp(optarg, tm->name) == 0) {
139 T = *tm->T;
140 break;
143 break;
144 case 'G':
145 if (strcmp(optarg, "e") == 0)
146 asm = Gaself;
147 else if (strcmp(optarg, "m") == 0)
148 asm = Gasmacho;
149 else {
150 fprintf(stderr, "unknown gas flavor '%s'\n", optarg);
151 exit(1);
153 break;
154 case 'h':
155 default:
156 hf = c != 'h' ? stderr : stdout;
157 fprintf(hf, "%s [OPTIONS] {file.ssa, -}\n", av[0]);
158 fprintf(hf, "\t%-11s prints this help\n", "-h");
159 fprintf(hf, "\t%-11s output to file\n", "-o file");
160 fprintf(hf, "\t%-11s generate for a target among:\n", "-t <target>");
161 fprintf(hf, "\t%-11s ", "");
162 for (tm=tmap, sep=""; tm->name; tm++, sep=", ")
163 fprintf(hf, "%s%s", sep, tm->name);
164 fprintf(hf, "\n");
165 fprintf(hf, "\t%-11s generate gas (e) or osx (m) asm\n", "-G {e,m}");
166 fprintf(hf, "\t%-11s dump debug information\n", "-d <flags>");
167 exit(c != 'h');
170 switch (asm) {
171 case Gaself:
172 gasloc = ".L";
173 gassym = "";
174 break;
175 case Gasmacho:
176 gasloc = "L";
177 gassym = "_";
178 break;
181 do {
182 f = av[optind];
183 if (!f || strcmp(f, "-") == 0) {
184 inf = stdin;
185 f = "-";
186 } else {
187 inf = fopen(f, "r");
188 if (!inf) {
189 fprintf(stderr, "cannot open '%s'\n", f);
190 exit(1);
193 parse(inf, f, data, func);
194 } while (++optind < ac);
196 if (!dbg)
197 gasemitfin(outf);
199 exit(0);