Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Inferno utils/cc/lex.c | 1 // Inferno utils/cc/lex.c |
2 // http://code.google.com/p/inferno-os/source/browse/utils/cc/lex.c | 2 // http://code.google.com/p/inferno-os/source/browse/utils/cc/lex.c |
3 // | 3 // |
4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. | 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. |
5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) | 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) |
6 // Portions Copyright © 1997-1999 Vita Nuova Limited | 6 // Portions Copyright © 1997-1999 Vita Nuova Limited |
7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov a.com) | 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov a.com) |
8 // Portions Copyright © 2004,2006 Bruce Ellis | 8 // Portions Copyright © 2004,2006 Bruce Ellis |
9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) | 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) |
10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others | 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 * -S print assembly | 79 * -S print assembly |
80 * -t print type trees | 80 * -t print type trees |
81 * -V enable void* conversion warnings | 81 * -V enable void* conversion warnings |
82 * -v verbose printing | 82 * -v verbose printing |
83 * -w print warnings | 83 * -w print warnings |
84 * -X abort on error | 84 * -X abort on error |
85 * -. Inhibit search for includes in source directory | 85 * -. Inhibit search for includes in source directory |
86 */ | 86 */ |
87 | 87 |
88 void | 88 void |
89 usage(void) | |
90 { | |
91 print("usage: %cc [options] file.c...\n", thechar); | |
92 flagprint(1); | |
93 errorexit(); | |
94 } | |
95 | |
96 void | |
97 dospim(void) | |
98 { | |
99 thechar = '0'; | |
100 thestring = "spim"; | |
101 } | |
102 | |
103 char **defs; | |
104 int ndef; | |
105 | |
106 void | |
107 dodef(char *p) | |
108 { | |
109 if(ndef%8 == 0) | |
110 defs = allocn(defs, ndef*sizeof(char *), | |
111 8*sizeof(char *)); | |
112 defs[ndef++] = p; | |
113 dodefine(p); | |
114 } | |
115 | |
116 void | |
89 main(int argc, char *argv[]) | 117 main(int argc, char *argv[]) |
90 { | 118 { |
91 » char **defs, *p; | 119 » int c; |
92 » int c, ndef; | |
93 | 120 |
94 ensuresymb(NSYMB); | 121 ensuresymb(NSYMB); |
95 memset(debug, 0, sizeof(debug)); | 122 memset(debug, 0, sizeof(debug)); |
96 tinit(); | 123 tinit(); |
97 cinit(); | 124 cinit(); |
98 ginit(); | 125 ginit(); |
99 arginit(); | 126 arginit(); |
100 | 127 |
101 tufield = simplet((1L<<tfield->etype) | BUNSIGNED); | 128 tufield = simplet((1L<<tfield->etype) | BUNSIGNED); |
102 ndef = 0; | 129 ndef = 0; |
103 defs = nil; | 130 defs = nil; |
104 outfile = 0; | 131 outfile = 0; |
105 setinclude("."); | 132 setinclude("."); |
106 ARGBEGIN { | |
107 default: | |
108 c = ARGC(); | |
109 if(c >= 0 && c < sizeof(debug)) | |
110 debug[c]++; | |
111 break; | |
112 | 133 |
113 » case 'l':» » » /* for little-endian mips */ | 134 » flagcount("+", "pass -+ to preprocessor", &debug['+']);» |
114 » » if(thechar != 'v'){ | 135 » flagcount(".", "pass -. to preprocessor", &debug['.']);» |
115 » » » print("can only use -l with vc\n"); | 136 » flagcount("<", "debug shift", &debug['<']); |
116 » » » errorexit(); | 137 » flagcount("A", "debug alignment", &debug['A']); |
117 » » } | 138 » flagcount("B", "allow pre-ANSI code", &debug['B']); |
118 » » thechar = '0'; | 139 » if(thechar == '5') |
119 » » thestring = "spim"; | 140 » » flagcount("C", "debug constant propagation", &debug['C']); |
120 » » break; | 141 » flagfn1("D", "name[=value]: add #define", dodef); |
142 » flagcount("F", "enable print format checks", &debug['F']); | |
143 » if(thechar == '5') | |
144 » » flagcount("H", "debug shift propagation", &debug['H']); | |
145 » flagfn1("I", "dir: add dir to include path", setinclude); | |
146 » flagcount("L", "debug lexer", &debug['L']); | |
147 » flagcount("M", "debug move generation", &debug['M']); | |
148 » flagcount("N", "disable optimizations", &debug['N']); | |
149 » flagcount("P", "debug peephole optimizer", &debug['P']); | |
150 » flagcount("Q", "print exported Go definitions", &debug['Q']); | |
151 » flagcount("R", "debug register optimizer", &debug['R']); | |
152 » flagcount("S", "print assembly", &debug['S']); | |
153 » flagcount("T", "enable type signatures", &debug['T']); | |
154 » flagcount("V", "enable pointer type checks", &debug['V']); | |
155 » flagcount("W", "debug switch generation", &debug['W']); | |
156 » flagcount("X", "abort on error", &debug['X']); | |
157 » flagcount("Y", "debug index generation", &debug['Y']); | |
minux1
2012/12/30 18:08:36
flagcount("Z", "cc/cc.y:138", &debug['Z']);
rsc
2013/01/02 20:51:21
Done.
| |
158 » flagcount("a", "print acid definitions", &debug['a']); | |
minux1
2012/12/30 18:08:36
flagcount("c", "cc/pgen.c:479", &debug['c']);
rsc
2013/01/02 20:51:21
Done.
| |
159 » flagcount("d", "debug declarations", &debug['d']); | |
160 » flagcount("e", "debug macro expansion", &debug['e']); | |
161 » flagcount("f", "debug pragmas", &debug['f']); | |
162 » flagcount("g", "debug code generation", &debug['g']); | |
minux1
2012/12/30 18:08:36
flagcount("h", "cc/sub.c:851, 5c/peep.c:827", &deb
rsc
2013/01/02 20:51:21
Done. (I deleted the references to debug['h'].)
| |
163 » flagcount("i", "debug initialization", &debug['i']); | |
164 » if(thechar == 'v') | |
165 » » flagfn0("l", "little-endian mips mode", dospim); | |
166 » flagcount("m", "debug multiplication", &debug['m']); | |
167 » flagcount("n", "print acid/Go to file, not stdout", &debug['n']); | |
168 » flagstr("o", "file: set output file", &outfile); | |
169 » flagcount("p", "invoke C preprocessor", &debug['p']);»·· | |
170 » flagcount("q", "print Go definitions", &debug['q']); | |
171 » flagcount("s", "print #define assembly offsets", &debug['s']); | |
172 » flagcount("t", "debug code generation", &debug['t']); | |
173 » flagcount("w", "enable warnings", &debug['w']); | |
174 » flagcount("v", "increase debug verbosity", &debug['v']);»······· | |
175 »······· | |
176 » flagparse(&argc, &argv, usage); | |
121 | 177 |
122 » case 'o': | 178 » if(argc < 1 && outfile == 0) |
123 » » outfile = ARGF(); | 179 » » usage(); |
124 » » break; | |
125 | 180 |
126 case 'D': | |
127 p = ARGF(); | |
128 if(p) { | |
129 if(ndef%8 == 0) | |
130 defs = allocn(defs, ndef*sizeof(char *), | |
131 8*sizeof(char *)); | |
132 defs[ndef++] = p; | |
133 dodefine(p); | |
134 } | |
135 break; | |
136 | |
137 case 'I': | |
138 p = ARGF(); | |
139 setinclude(p); | |
140 break; | |
141 } ARGEND | |
142 if(argc < 1 && outfile == 0) { | |
143 print("usage: %cc [-options] files\n", thechar); | |
144 errorexit(); | |
145 } | |
146 if(argc > 1){ | 181 if(argc > 1){ |
147 print("can't compile multiple files\n"); | 182 print("can't compile multiple files\n"); |
148 errorexit(); | 183 errorexit(); |
149 } | 184 } |
150 | 185 |
151 if(argc == 0) | 186 if(argc == 0) |
152 c = compile("stdin", defs, ndef); | 187 c = compile("stdin", defs, ndef); |
153 else | 188 else |
154 c = compile(argv[0], defs, ndef); | 189 c = compile(argv[0], defs, ndef); |
155 | 190 |
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1558 if(symb == nil) { | 1593 if(symb == nil) { |
1559 symb = alloc(NSYMB+1); | 1594 symb = alloc(NSYMB+1); |
1560 nsymb = NSYMB; | 1595 nsymb = NSYMB; |
1561 } | 1596 } |
1562 | 1597 |
1563 if(n > nsymb) { | 1598 if(n > nsymb) { |
1564 symb = allocn(symb, nsymb, n+1-nsymb); | 1599 symb = allocn(symb, nsymb, n+1-nsymb); |
1565 nsymb = n; | 1600 nsymb = n; |
1566 } | 1601 } |
1567 } | 1602 } |
OLD | NEW |