1 /* $Id: main.c,v 1.106 2011/01/22 22:08:23 ragge Exp $ */
4 * Copyright (c) 2002 Anders Magnusson. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 int sflag
, nflag
, oflag
, kflag
, pflag
;
42 int lflag
, odebug
, rdebug
, s2debug
, udebug
, x2debug
;
43 #if !defined(MULTIPASS) || defined(PASST)
46 int xdebug
, sdebug
, gflag
, c2debug
, pdebug
, g2debug
;
48 int funsigned_char
= 1;
50 int funsigned_char
= 0;
53 int xssaflag
, xtailcallflag
, xtemps
, xdeljumps
, xdce
, xinline
, xccp
;
55 int e2debug
, t2debug
, f2debug
, b2debug
;
58 * Ensure that this struct matches defines in manifest.h!
60 const struct attr2 btattr
[32] = {
61 #define BTA(x) { 0, ATTR_BASETYP, { { SZ##x }, { AL##x }, }, },
81 { 0, ATTR_BASETYP
}, /* VOID */
84 BTA(FLOAT
) /* FIMAG */
85 BTA(DOUBLE
) /* IMAG */
86 BTA(LDOUBLE
) /* LIMAG */
87 BTA(FLOAT
) /* FCOMPLEX */
88 BTA(DOUBLE
) /* COMPLEX */
89 BTA(LDOUBLE
) /* LCOMPLEX */
94 static void prtstats(void);
99 (void)fprintf(stderr
, "usage: %s [option] [infile] [outfile]...\n",
110 snprintf(buf
, sizeof buf
, "%sinternal compiler error: %s, line %d\n",
111 nerrors
? "" : "major ", ftitle
, lineno
);
112 dummy
= write(STDERR_FILENO
, buf
, strlen(buf
));
121 if (strncmp("no-", str
, 3) == 0) {
126 if (strcmp(str
, "signed-char") == 0)
127 funsigned_char
= !flagval
;
128 else if (strcmp(str
, "unsigned-char") == 0)
129 funsigned_char
= flagval
;
130 else if (strcmp(str
, "stack-protector") == 0)
132 else if (strcmp(str
, "stack-protector-all") == 0)
134 else if (strncmp(str
, "pack-struct", 11) == 0)
135 pragma_allpacked
= (strlen(str
) > 12 ? atoi(str
+12) : 1);
137 fprintf(stderr
, "unrecognised option '%s'\n", str
);
142 /* control multiple files */
144 main(int argc
, char *argv
[])
150 struct timeval t1
, t2
;
152 (void)gettimeofday(&t1
, NULL
);
157 while ((ch
= getopt(argc
, argv
, "OT:VW:X:Z:f:gklm:psvwx:")) != -1)
159 #if !defined(MULTIPASS) || defined(PASS1)
163 case 'd': ++ddebug
; break; /* declarations */
164 case 'i': ++idebug
; break; /* initializations */
165 case 'b': ++bdebug
; break; /* buildtree */
166 case 't': ++tdebug
; break; /* type match */
167 case 'e': ++edebug
; break; /* pass1 exit */
168 case 'x': ++xdebug
; break; /* MD code */
169 case 's': ++sdebug
; break; /* inline */
170 case 'n': ++nflag
; break; /* node alloc */
171 case 'o': ++oflag
; break; /* optim */
172 case 'p': ++pdebug
; break; /* prototype */
174 fprintf(stderr
, "unknown X flag '%c'\n",
180 #if !defined(MULTIPASS) || defined(PASST)
184 case 'i': ++iTflag
; break;
185 case 'o': ++oTflag
; break;
186 case 'n': ++nflag
; break;
188 fprintf(stderr
, "unknown T flag '%c'\n",
194 #if !defined(MULTIPASS) || defined(PASS2)
198 case 'f': /* instruction matching */
201 case 'e': /* print tree upon pass2 enter */
204 case 'o': ++odebug
; break;
205 case 'r': /* register alloc/graph coloring */
208 case 'b': /* basic block and SSA building */
211 case 'c': /* code printout */
214 case 't': ++t2debug
; break;
215 case 's': /* shape matching */
218 case 'u': /* Sethi-Ullman debugging */
221 case 'x': ++x2debug
; break;
222 case 'g': /* print flow graphs */
225 case 'n': ++nflag
; break;
227 fprintf(stderr
, "unknown Z flag '%c'\n",
234 case 'f': /* Language */
238 case 'g': /* Debugging */
242 case 'k': /* PIC code */
246 case 'l': /* Linenos */
250 case 'm': /* Target-specific */
254 case 'p': /* Profiling */
258 case 's': /* Statistics */
262 case 'W': /* Enable different warnings */
266 case 'x': /* Different optimizations */
267 if (strcmp(optarg
, "ssa") == 0)
269 else if (strcmp(optarg
, "tailcall") == 0)
271 else if (strcmp(optarg
, "temps") == 0)
273 else if (strcmp(optarg
, "deljumps") == 0)
275 else if (strcmp(optarg
, "dce") == 0)
277 else if (strcmp(optarg
, "inline") == 0)
279 else if (strcmp(optarg
, "ccp") == 0)
285 printf("ccom: %s\n", VERSSTR
);
295 if (argc
> 0 && strcmp(argv
[0], "-") != 0) {
296 if (freopen(argv
[0], "r", stdin
) == NULL
) {
297 fprintf(stderr
, "open input file '%s':",
303 if (argc
> 1 && strcmp(argv
[1], "-") != 0) {
304 if (freopen(argv
[1], "w", stdout
) == NULL
) {
305 fprintf(stderr
, "open output file '%s':",
313 signal(SIGSEGV
, segvcatch
);
315 signal(SIGBUS
, segvcatch
);
317 fregs
= FREGS
; /* number of free registers */
323 /* starts past any of the above */
327 #ifndef TARGET_VALIST
329 NODE
*p
= block(NAME
, NIL
, NIL
, PTR
|CHAR
, NULL
, MKAP(CHAR
));
330 struct symtab
*sp
= lookup(addname("__builtin_va_list"), 0);
340 stabs_file(argc
? argv
[0] : "");
356 stabs_efile(argc
? argv
[0] : "");
359 ejobcode( nerrors
? 1 : 0 );
362 (void)gettimeofday(&t2
, NULL
);
363 t2
.tv_sec
-= t1
.tv_sec
;
364 t2
.tv_usec
-= t1
.tv_usec
;
365 if (t2
.tv_usec
< 0) {
366 t2
.tv_usec
+= 1000000;
369 fprintf(stderr
, "ccom total time: %ld s %ld us\n",
370 t2
.tv_sec
, t2
.tv_usec
);
382 extern int nametabs
, namestrlen
, tmpallocsize
, permallocsize
;
383 extern int lostmem
, arglistcnt
, dimfuncnt
, inlnodecnt
, inlstatcnt
;
384 extern int symtabcnt
, suedefcnt
;
386 fprintf(stderr
, "Name table entries: %d pcs\n", nametabs
);
387 fprintf(stderr
, "Name string size: %d B\n", namestrlen
);
388 fprintf(stderr
, "Permanent allocated memory: %d B\n", permallocsize
);
389 fprintf(stderr
, "Temporary allocated memory: %d B\n", tmpallocsize
);
390 fprintf(stderr
, "Lost memory: %d B\n", lostmem
);
391 fprintf(stderr
, "Argument list unions: %d pcs\n", arglistcnt
);
392 fprintf(stderr
, "Dimension/function unions: %d pcs\n", dimfuncnt
);
393 fprintf(stderr
, "Struct/union/enum blocks: %d pcs\n", suedefcnt
);
394 fprintf(stderr
, "Inline node count: %d pcs\n", inlnodecnt
);
395 fprintf(stderr
, "Inline control blocks: %d pcs\n", inlstatcnt
);
396 fprintf(stderr
, "Permanent symtab entries: %d pcs\n", symtabcnt
);