main.c (1525B)
1 static char sccsid[] = "@(#) ./cc1/main.c"; 2 #include <setjmp.h> 3 #include <stdlib.h> 4 #include <string.h> 5 #include <errno.h> 6 7 #include "../inc/arg.h" 8 #include "../inc/scc.h" 9 #include "cc1.h" 10 11 char *argv0, *infile; 12 13 int warnings; 14 jmp_buf recover; 15 16 static struct items uflags; 17 int onlycpp, onlyheader; 18 19 20 extern int failure; 21 22 static void 23 defmacro(char *macro) 24 { 25 char *p = strchr(macro, '='); 26 27 if (p) 28 *p++ = '\0'; 29 else 30 p = "1"; 31 32 defdefine(macro, p, "command-line"); 33 } 34 35 static void 36 usage(void) 37 { 38 die("usage: cc1 [-Ewd] [-D def[=val]]... [-U def]... " 39 "[-I dir]... [-o output] [input]"); 40 } 41 42 int 43 main(int argc, char *argv[]) 44 { 45 int i; 46 47 ilex(); 48 icpp(); 49 icode(); 50 ibuilts(); 51 52 ARGBEGIN { 53 case 'D': 54 defmacro(EARGF(usage())); 55 break; 56 case 'M': 57 onlyheader = 1; 58 break; 59 case 'E': 60 onlycpp = 1; 61 break; 62 case 'I': 63 incdir(EARGF(usage())); 64 break; 65 case 'U': 66 newitem(&uflags, EARGF(usage())); 67 break; 68 case 'd': 69 DBGON(); 70 break; 71 case 'w': 72 warnings = 1; 73 break; 74 default: 75 usage(); 76 } ARGEND 77 78 if (argc > 1) 79 usage(); 80 81 for (i = 0; i < uflags.n; ++i) 82 undefmacro(uflags.s[i]); 83 84 infile = (*argv) ? *argv : "<stdin>"; 85 if (!addinput(*argv, NULL, NULL)) { 86 die("error: failed to open input file '%s': %s", 87 *argv, strerror(errno)); 88 } 89 90 /* 91 * we cannot initialize arch until we have an 92 * output stream, because we maybe want to emit new types 93 */ 94 iarch(); 95 if (onlycpp || onlyheader) { 96 outcpp(); 97 } else { 98 for (next(); yytoken != EOFTOK; decl()) 99 /* nothing */; 100 } 101 102 return failure; 103 }