Mercurial > projects > ldc
annotate dmd/mars.c @ 534:7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 24 Aug 2008 16:22:58 +0200 |
parents | d30c40f1128d |
children | f79bbd1d0b27 |
rev | line source |
---|---|
159 | 1 // Compiler implementation of the D programming language |
2 // Copyright (c) 1999-2008 by Digital Mars | |
3 // All Rights Reserved | |
4 // written by Walter Bright | |
5 // http://www.digitalmars.com | |
6 // License for redistribution is by either the Artistic License | |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
8 // See the included readme.txt for details. | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <ctype.h> | |
13 #include <assert.h> | |
14 #include <limits.h> | |
15 #include <string> | |
16 #include <cstdarg> | |
17 | |
18 #if __DMC__ | |
19 #include <dos.h> | |
20 #endif | |
21 | |
22 #if linux | |
23 #include <errno.h> | |
432 | 24 #elif _WIN32 |
25 #include <windows.h> | |
159 | 26 #endif |
27 | |
28 #include "mem.h" | |
29 #include "root.h" | |
30 | |
31 #include "mars.h" | |
32 #include "module.h" | |
33 #include "mtype.h" | |
34 #include "id.h" | |
35 #include "cond.h" | |
36 #include "expression.h" | |
37 #include "lexer.h" | |
38 | |
39 #include "gen/logger.h" | |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
40 #include "gen/linker.h" |
159 | 41 |
42 void getenv_setargv(const char *envvar, int *pargc, char** *pargv); | |
43 | |
284
70c370e97944
[svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents:
279
diff
changeset
|
44 // llvmdc |
70c370e97944
[svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents:
279
diff
changeset
|
45 void findDefaultTarget(); |
70c370e97944
[svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents:
279
diff
changeset
|
46 |
159 | 47 Global global; |
48 | |
49 Global::Global() | |
50 { | |
51 mars_ext = "d"; | |
52 sym_ext = "d"; | |
53 hdr_ext = "di"; | |
54 doc_ext = "html"; | |
55 ddoc_ext = "ddoc"; | |
56 | |
374
1f20b9f7de1b
Fix nativeobj extension for Windows.
Christian Kamm <kamm incasoftware de>
parents:
366
diff
changeset
|
57 // LLVMDC |
159 | 58 obj_ext = "bc"; |
59 ll_ext = "ll"; | |
60 bc_ext = "bc"; | |
374
1f20b9f7de1b
Fix nativeobj extension for Windows.
Christian Kamm <kamm incasoftware de>
parents:
366
diff
changeset
|
61 #if _WIN32 |
1f20b9f7de1b
Fix nativeobj extension for Windows.
Christian Kamm <kamm incasoftware de>
parents:
366
diff
changeset
|
62 nativeobj_ext = "obj"; |
1f20b9f7de1b
Fix nativeobj extension for Windows.
Christian Kamm <kamm incasoftware de>
parents:
366
diff
changeset
|
63 #elif linux |
159 | 64 nativeobj_ext = "o"; |
65 #else | |
66 #error "fix this" | |
67 #endif | |
68 | |
69 copyright = "Copyright (c) 1999-2008 by Digital Mars and Tomas Lindquist Olsen"; | |
70 written = "written by Walter Bright and Tomas Lindquist Olsen"; | |
366 | 71 version = "v1.033"; |
159 | 72 llvmdc_version = "0.1"; |
73 global.structalign = 8; | |
74 | |
75 memset(¶ms, 0, sizeof(Param)); | |
76 } | |
77 | |
78 char *Loc::toChars() const | |
79 { | |
80 OutBuffer buf; | |
81 char *p; | |
82 | |
83 if (filename) | |
84 { | |
85 buf.printf("%s", filename); | |
86 } | |
87 | |
88 if (linnum) | |
89 buf.printf("(%d)", linnum); | |
90 buf.writeByte(0); | |
91 return (char *)buf.extractData(); | |
92 } | |
93 | |
94 Loc::Loc(Module *mod, unsigned linnum) | |
95 { | |
96 this->linnum = linnum; | |
97 this->filename = mod ? mod->srcfile->toChars() : NULL; | |
98 } | |
99 | |
100 /************************************** | |
101 * Print error message and exit. | |
102 */ | |
103 | |
104 void error(Loc loc, const char *format, ...) | |
105 { | |
106 va_list ap; | |
107 va_start(ap, format); | |
108 verror(loc, format, ap); | |
109 va_end( ap ); | |
110 } | |
111 | |
112 void verror(Loc loc, const char *format, va_list ap) | |
113 { | |
114 if (!global.gag) | |
115 { | |
116 char *p = loc.toChars(); | |
117 | |
118 if (*p) | |
119 fprintf(stdmsg, "%s: ", p); | |
120 mem.free(p); | |
121 | |
122 fprintf(stdmsg, "Error: "); | |
123 vfprintf(stdmsg, format, ap); | |
124 fprintf(stdmsg, "\n"); | |
125 fflush(stdmsg); | |
126 } | |
127 global.errors++; | |
128 } | |
129 | |
130 /*************************************** | |
131 * Call this after printing out fatal error messages to clean up and exit | |
132 * the compiler. | |
133 */ | |
134 | |
135 void fatal() | |
136 { | |
137 #if 0 | |
138 halt(); | |
139 #endif | |
140 exit(EXIT_FAILURE); | |
141 } | |
142 | |
143 /************************************** | |
144 * Try to stop forgetting to remove the breakpoints from | |
145 * release builds. | |
146 */ | |
147 void halt() | |
148 { | |
149 #ifdef DEBUG | |
150 *(char*)0=0; | |
151 #endif | |
152 } | |
153 | |
154 extern void backend_init(); | |
155 extern void backend_term(); | |
156 | |
157 void usage() | |
158 { | |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
159
diff
changeset
|
159 printf("LLVM D Compiler %s (based on DMD %s and LLVM 2.3)\n%s\n%s\n", |
159 | 160 global.llvmdc_version, global.version, global.copyright, global.written); |
161 printf("\ | |
162 D Language Documentation: http://www.digitalmars.com/d/1.0/index.html\n\ | |
163 LLVMDC Homepage: http://www.dsource.org/projects/llvmdc\n\ | |
164 Usage:\n\ | |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
306
diff
changeset
|
165 llvmdc files.d ... { -switch }\n\ |
159 | 166 \n\ |
167 files.d D source files\n%s\ | |
168 -annotate annotate the bitcode with human readable source code\n\ | |
169 -c do not link\n\ | |
170 -cov do code coverage analysis\n\ | |
171 -D generate documentation\n\ | |
172 -Dd<docdir> write documentation file to <docdir> directory\n\ | |
173 -Df<filename> write documentation file to <filename>\n\ | |
174 -d allow deprecated features\n\ | |
175 -debug compile in debug code\n\ | |
176 -debug=level compile in debug code <= level\n\ | |
177 -debug=ident compile in debug code identified by ident\n\ | |
178 -debuglib=name set symbolic debug library to name\n\ | |
179 -defaultlib=name set default library to name\n\ | |
180 -dis disassemble module after compiling\n\ | |
181 -g add symbolic debug info\n\ | |
182 -gc add symbolic debug info, pretend to be C\n\ | |
183 -H generate 'header' file\n\ | |
184 -Hd<hdrdir> write 'header' file to <hdrdir> directory\n\ | |
185 -Hf<filename> write 'header' file to <filename>\n\ | |
186 --help print help\n\ | |
187 -I<path> where to look for imports\n\ | |
188 -J<path> where to look for string imports\n\ | |
189 -ignore ignore unsupported pragmas\n\ | |
190 -inline do function inlining\n\ | |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
306
diff
changeset
|
191 -L<linkerflag> pass <linkerflag> to llvm-ld\n\ |
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
306
diff
changeset
|
192 -m<arch> emit code specific to <arch> being one of:\n\ |
159 | 193 x86 x86-64 ppc32 ppc64\n\ |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
194 -noasm do not allow use of inline asm\n\ |
159 | 195 -nofloat do not emit reference to floating point\n\ |
196 -noruntime do not allow code that generates implicit runtime calls\n\ | |
197 -noverify do not run the validation pass before writing bitcode\n\ | |
198 -O optimize, same as -O2\n\ | |
199 -O<n> optimize at level <n> (0-5)\n\ | |
200 -o- do not write object file\n\ | |
201 -od<objdir> write object files to directory <objdir>\n\ | |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
306
diff
changeset
|
202 -of<filename> name output file to <filename>\n\ |
159 | 203 -op do not strip paths from source file\n\ |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
204 -oq write object files with fully qualified names\n\ |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
306
diff
changeset
|
205 -profile profile runtime performance of generated code\n\ |
159 | 206 -quiet suppress unnecessary messages\n\ |
323
0d52412d5b1a
[svn r344] Fixed some very minor issues with the usage listing when calling llvmdc with no arguments.
lindquist
parents:
306
diff
changeset
|
207 -release compile release version\n\ |
159 | 208 -run srcfile args... run resulting program, passing args\n\ |
209 -R<path> provide path to the directory containing the runtime library\n\ | |
210 -unittest compile in unit tests\n\ | |
211 -v verbose\n\ | |
212 -vv very verbose (does not include -v)\n\ | |
213 -v1 D language version 1\n\ | |
214 -version=level compile in version code >= level\n\ | |
215 -version=ident compile in version code identified by ident\n\ | |
216 -w enable warnings\n\ | |
217 ", | |
218 #if WIN32 | |
219 " @cmdfile read arguments from cmdfile\n" | |
220 #else | |
221 "" | |
222 #endif | |
223 ); | |
224 } | |
225 | |
226 int main(int argc, char *argv[]) | |
227 { | |
228 int i; | |
229 Array files; | |
230 char *p; | |
231 Module *m; | |
232 int status = EXIT_SUCCESS; | |
233 int argcstart = argc; | |
234 bool very_verbose = false; | |
235 | |
236 // Check for malformed input | |
237 if (argc < 1 || !argv) | |
238 { | |
239 Largs: | |
240 error("missing or null command line arguments"); | |
241 fatal(); | |
242 } | |
243 for (i = 0; i < argc; i++) | |
244 { | |
245 if (!argv[i]) | |
246 goto Largs; | |
247 } | |
248 | |
249 #if __DMC__ // DMC unique support for response files | |
250 if (response_expand(&argc,&argv)) // expand response files | |
251 error("can't open response file"); | |
252 #endif | |
253 | |
254 files.reserve(argc - 1); | |
255 | |
256 // Set default values | |
432 | 257 #if _WIN32 |
258 char buf[MAX_PATH]; | |
259 GetModuleFileName(NULL, buf, MAX_PATH); | |
260 global.params.argv0 = buf; | |
261 #else | |
159 | 262 global.params.argv0 = argv[0]; |
432 | 263 #endif |
159 | 264 global.params.link = 1; |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
510
diff
changeset
|
265 global.params.useAssert = 1; |
327
781af50846b2
[svn r348] Switch on class invariants (except in release mode).
ChristianK
parents:
323
diff
changeset
|
266 global.params.useInvariants = 1; |
159 | 267 global.params.useIn = 1; |
268 global.params.useOut = 1; | |
439
47b64d06eb9f
Enable array bounds check and emit them in IndexExp.
Christian Kamm <kamm incasoftware de>
parents:
432
diff
changeset
|
269 global.params.useArrayBounds = 1; |
331
04e1b4930975
[svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents:
327
diff
changeset
|
270 global.params.useSwitchError = 1; |
159 | 271 global.params.useInline = 0; // this one messes things up to a point where codegen breaks |
272 global.params.llvmInline = 0; // use this one instead to know if inline passes should be run | |
273 global.params.obj = 1; | |
274 global.params.Dversion = 2; | |
275 global.params.quiet = 1; | |
276 | |
277 global.params.linkswitches = new Array(); | |
278 global.params.libfiles = new Array(); | |
279 global.params.objfiles = new Array(); | |
280 global.params.ddocfiles = new Array(); | |
281 | |
282 global.params.is64bit = sizeof(void*) == 8 ? 1 : 0; | |
283 | |
284 uint16_t endiantest = 0xFF00; | |
285 uint8_t endianres = ((uint8_t*)&endiantest)[0]; | |
286 if (endianres == 0x00) | |
287 global.params.isLE = true; | |
288 else if (endianres == 0xFF) | |
289 global.params.isLE = false; | |
290 else { | |
291 error("Endian test is broken"); | |
292 fatal(); | |
293 } | |
294 | |
295 global.params.llvmArch = 0; | |
296 global.params.forceBE = 0; | |
297 global.params.noruntime = 0; | |
298 global.params.novalidate = 0; | |
299 global.params.optimizeLevel = -1; | |
300 global.params.runtimeImppath = 0; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
301 global.params.useInlineAsm = 1; |
159 | 302 |
303 global.params.defaultlibname = "phobos"; | |
304 global.params.debuglibname = global.params.defaultlibname; | |
305 | |
306 // Predefine version identifiers | |
307 #if IN_LLVM | |
308 VersionCondition::addPredefinedGlobalIdent("LLVM"); | |
309 VersionCondition::addPredefinedGlobalIdent("LLVMDC"); | |
310 #endif | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
484
diff
changeset
|
311 |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
312 // setup default target os to be build os |
159 | 313 #if _WIN32 |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
314 global.params.os = OSWindows; |
159 | 315 #elif linux |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
316 global.params.os = OSLinux; |
159 | 317 #else |
318 #error | |
319 #endif /* linux */ | |
320 | |
321 //VersionCondition::addPredefinedGlobalIdent("D_Bits"); | |
322 VersionCondition::addPredefinedGlobalIdent("all"); | |
323 | |
324 #if _WIN32 | |
432 | 325 inifile(global.params.argv0, "llvmdc.ini"); |
285
297690b5d4a5
[svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents:
284
diff
changeset
|
326 #elif linux |
432 | 327 inifile(global.params.argv0, "llvmdc.conf"); |
159 | 328 #else |
329 #error | |
330 #endif | |
331 getenv_setargv("DFLAGS", &argc, &argv); | |
332 | |
333 #if 0 | |
334 for (i = 0; i < argc; i++) | |
335 { | |
336 printf("argv[%d] = '%s'\n", i, argv[i]); | |
337 } | |
338 #endif | |
339 | |
340 for (i = 1; i < argc; i++) | |
341 { | |
342 p = argv[i]; | |
343 if (*p == '-') | |
344 { | |
345 if (strcmp(p + 1, "d") == 0) | |
346 global.params.useDeprecated = 1; | |
347 else if (strcmp(p + 1, "c") == 0) | |
348 global.params.link = 0; | |
349 else if (strcmp(p + 1, "cov") == 0) | |
350 global.params.cov = 1; | |
351 else if (strcmp(p + 1, "fPIC") == 0) | |
352 global.params.pic = 1; | |
353 else if (strcmp(p + 1, "g") == 0) | |
354 global.params.symdebug = 1; | |
355 else if (strcmp(p + 1, "gc") == 0) | |
356 global.params.symdebug = 2; | |
357 else if (strcmp(p + 1, "gt") == 0) | |
358 { error("use -profile instead of -gt\n"); | |
359 global.params.trace = 1; | |
360 } | |
361 else if (strcmp(p + 1, "profile") == 0) | |
362 global.params.trace = 1; | |
363 else if (strcmp(p + 1, "v") == 0) | |
364 global.params.verbose = 1; | |
365 else if (strcmp(p + 1, "vv") == 0) { | |
366 Logger::enable(); | |
367 very_verbose = true; | |
368 } | |
369 else if (strcmp(p + 1, "v1") == 0) | |
370 global.params.Dversion = 1; | |
371 else if (strcmp(p + 1, "w") == 0) | |
372 global.params.warnings = 1; | |
373 else if (p[1] == 'O') | |
374 { | |
375 global.params.optimize = 1; | |
376 global.params.optimizeLevel = 2; | |
377 if (p[2] != 0) { | |
378 int optlevel = atoi(p+2); | |
379 if (optlevel < 0 || optlevel > 5) { | |
380 error("Optimization level must be between 0 and 5. Using default (%d)", | |
381 global.params.optimizeLevel); | |
382 } | |
383 else { | |
384 global.params.optimizeLevel = optlevel; | |
385 } | |
386 } | |
387 } | |
388 else if (strcmp(p + 1, "forcebe") == 0) | |
389 global.params.forceBE = 1; | |
390 else if (strcmp(p + 1, "noruntime") == 0) | |
391 global.params.noruntime = 1; | |
392 else if (strcmp(p + 1, "noverify") == 0) | |
393 global.params.novalidate = 1; | |
394 else if (strcmp(p + 1, "dis") == 0) | |
395 global.params.disassemble = 1; | |
396 else if (strcmp(p + 1, "annotate") == 0) | |
397 global.params.llvmAnnotate = 1; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
398 else if (strcmp(p + 1, "noasm") == 0) |
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
399 global.params.useInlineAsm = 0; |
159 | 400 else if (p[1] == 'o') |
401 { | |
402 switch (p[2]) | |
403 { | |
404 case '-': | |
405 global.params.obj = 0; | |
406 break; | |
407 | |
408 case 'd': | |
409 if (!p[3]) | |
410 goto Lnoarg; | |
411 global.params.objdir = p + 3; | |
412 break; | |
413 | |
414 case 'f': | |
415 if (!p[3]) | |
416 goto Lnoarg; | |
417 global.params.objname = p + 3; | |
418 break; | |
419 | |
420 case 'p': | |
421 if (p[3]) | |
422 goto Lerror; | |
423 global.params.preservePaths = 1; | |
424 break; | |
425 | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
426 case 'q': |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
427 if (p[3]) |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
428 goto Lerror; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
429 global.params.fqnPaths = 1; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
430 break; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
431 |
159 | 432 case 0: |
433 error("-o no longer supported, use -of or -od"); | |
434 break; | |
435 | |
436 default: | |
437 goto Lerror; | |
438 } | |
439 } | |
440 else if (p[1] == 'D') | |
441 { global.params.doDocComments = 1; | |
442 switch (p[2]) | |
443 { | |
444 case 'd': | |
445 if (!p[3]) | |
446 goto Lnoarg; | |
447 global.params.docdir = p + 3; | |
448 break; | |
449 case 'f': | |
450 if (!p[3]) | |
451 goto Lnoarg; | |
452 global.params.docname = p + 3; | |
453 break; | |
454 | |
455 case 0: | |
456 break; | |
457 | |
458 default: | |
459 goto Lerror; | |
460 } | |
461 } | |
462 #ifdef _DH | |
463 else if (p[1] == 'H') | |
464 { global.params.doHdrGeneration = 1; | |
465 switch (p[2]) | |
466 { | |
467 case 'd': | |
468 if (!p[3]) | |
469 goto Lnoarg; | |
470 global.params.hdrdir = p + 3; | |
471 break; | |
472 | |
473 case 'f': | |
474 if (!p[3]) | |
475 goto Lnoarg; | |
476 global.params.hdrname = p + 3; | |
477 break; | |
478 | |
479 case 0: | |
480 break; | |
481 | |
482 default: | |
483 goto Lerror; | |
484 } | |
485 } | |
486 #endif | |
487 else if (strcmp(p + 1, "ignore") == 0) | |
488 global.params.ignoreUnsupportedPragmas = 1; | |
489 else if (strcmp(p + 1, "inline") == 0) { | |
490 // TODO | |
491 // the ast rewrites dmd does for inlining messes up the ast. | |
492 // someday maybe we can support it, for now llvm does an excellent job at inlining | |
493 global.params.useInline = 0; //1 | |
494 global.params.llvmInline = 1; | |
495 } | |
496 else if (strcmp(p + 1, "nofloat") == 0) | |
497 global.params.nofloat = 1; | |
498 else if (strcmp(p + 1, "quiet") == 0) | |
499 global.params.quiet = 1; | |
500 else if (strcmp(p + 1, "release") == 0) | |
501 global.params.release = 1; | |
502 else if (strcmp(p + 1, "unittest") == 0) | |
503 global.params.useUnitTests = 1; | |
504 else if (p[1] == 'I') | |
505 { | |
506 if (!global.params.imppath) | |
507 global.params.imppath = new Array(); | |
508 global.params.imppath->push(p + 2); | |
509 } | |
510 else if (p[1] == 'J') | |
511 { | |
512 if (!global.params.fileImppath) | |
513 global.params.fileImppath = new Array(); | |
514 global.params.fileImppath->push(p + 2); | |
515 } | |
516 else if (p[1] == 'R') | |
517 { | |
518 global.params.runtimePath = p+2; | |
519 } | |
520 else if (memcmp(p + 1, "debug", 5) == 0 && p[6] != 'l') | |
521 { | |
522 // Parse: | |
523 // -debug | |
524 // -debug=number | |
525 // -debug=identifier | |
526 if (p[6] == '=') | |
527 { | |
528 if (isdigit(p[7])) | |
529 { long level; | |
530 | |
531 errno = 0; | |
532 level = strtol(p + 7, &p, 10); | |
533 if (*p || errno || level > INT_MAX) | |
534 goto Lerror; | |
535 DebugCondition::setGlobalLevel((int)level); | |
536 } | |
537 else if (Lexer::isValidIdentifier(p + 7)) | |
538 DebugCondition::addGlobalIdent(p + 7); | |
539 else | |
540 goto Lerror; | |
541 } | |
542 else if (p[6]) | |
543 goto Lerror; | |
544 else | |
545 global.params.debuglevel = 1; | |
546 } | |
547 else if (memcmp(p + 1, "version", 5) == 0) | |
548 { | |
549 // Parse: | |
550 // -version=number | |
551 // -version=identifier | |
552 if (p[8] == '=') | |
553 { | |
554 if (isdigit(p[9])) | |
555 { long level; | |
556 | |
557 errno = 0; | |
558 level = strtol(p + 9, &p, 10); | |
559 if (*p || errno || level > INT_MAX) | |
560 goto Lerror; | |
561 VersionCondition::setGlobalLevel((int)level); | |
562 } | |
563 else if (Lexer::isValidIdentifier(p + 9)) | |
564 VersionCondition::addGlobalIdent(p + 9); | |
565 else | |
566 goto Lerror; | |
567 } | |
568 else | |
569 goto Lerror; | |
570 } | |
571 else if (strcmp(p + 1, "-b") == 0) | |
572 global.params.debugb = 1; | |
573 else if (strcmp(p + 1, "-c") == 0) | |
574 global.params.debugc = 1; | |
575 else if (strcmp(p + 1, "-f") == 0) | |
576 global.params.debugf = 1; | |
577 else if (strcmp(p + 1, "-help") == 0) | |
578 { usage(); | |
579 exit(EXIT_SUCCESS); | |
580 } | |
581 else if (strcmp(p + 1, "-r") == 0) | |
582 global.params.debugr = 1; | |
583 else if (strcmp(p + 1, "-x") == 0) | |
584 global.params.debugx = 1; | |
585 else if (strcmp(p + 1, "-y") == 0) | |
586 global.params.debugy = 1; | |
587 else if (p[1] == 'L') | |
588 { | |
589 global.params.linkswitches->push(p + 2); | |
590 } | |
591 else if (memcmp(p + 1, "defaultlib=", 11) == 0) | |
592 { | |
593 global.params.defaultlibname = p + 1 + 11; | |
594 } | |
595 else if (memcmp(p + 1, "debuglib=", 9) == 0) | |
596 { | |
597 global.params.debuglibname = p + 1 + 9; | |
598 } | |
599 else if (strcmp(p + 1, "run") == 0) | |
600 { global.params.run = 1; | |
601 global.params.runargs_length = ((i >= argcstart) ? argc : argcstart) - i - 1; | |
602 if (global.params.runargs_length) | |
603 { | |
604 files.push(argv[i + 1]); | |
605 global.params.runargs = &argv[i + 2]; | |
606 i += global.params.runargs_length; | |
607 global.params.runargs_length--; | |
608 } | |
609 else | |
610 { global.params.run = 0; | |
611 goto Lnoarg; | |
612 } | |
613 } | |
614 else if (p[1] == 'm') | |
615 { | |
616 global.params.llvmArch = p+2; | |
617 } | |
618 else | |
619 { | |
620 Lerror: | |
621 error("unrecognized switch '%s'", argv[i]); | |
622 continue; | |
623 | |
624 Lnoarg: | |
625 error("argument expected for switch '%s'", argv[i]); | |
626 continue; | |
627 } | |
628 } | |
629 else | |
630 files.push(p); | |
631 } | |
632 if (global.errors) | |
633 { | |
634 fatal(); | |
635 } | |
636 if (files.dim == 0) | |
637 { usage(); | |
638 return EXIT_FAILURE; | |
639 } | |
640 | |
641 if (global.params.release) | |
642 { global.params.useInvariants = 0; | |
643 global.params.useIn = 0; | |
644 global.params.useOut = 0; | |
645 global.params.useAssert = 0; | |
646 global.params.useArrayBounds = 0; | |
647 global.params.useSwitchError = 0; | |
648 } | |
649 | |
650 if (global.params.run) | |
651 global.params.quiet = 1; | |
652 | |
653 if (global.params.useUnitTests) | |
654 global.params.useAssert = 1; | |
655 | |
656 if (!global.params.obj) | |
657 global.params.link = 0; | |
658 | |
659 if (global.params.link) | |
660 { | |
661 global.params.exefile = global.params.objname; | |
662 global.params.objname = NULL; | |
663 } | |
664 else if (global.params.run) | |
665 { | |
666 error("flags conflict with -run"); | |
667 fatal(); | |
668 } | |
669 else | |
670 { | |
671 if (global.params.objname && files.dim > 1) | |
672 { | |
673 error("multiple source files, but only one .obj name"); | |
674 fatal(); | |
675 } | |
676 } | |
677 if (global.params.cov) | |
678 VersionCondition::addPredefinedGlobalIdent("D_Coverage"); | |
679 | |
680 bool allowForceEndianness = false; | |
681 | |
682 if (global.params.llvmArch == 0) { | |
284
70c370e97944
[svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents:
279
diff
changeset
|
683 findDefaultTarget(); |
159 | 684 } |
685 | |
686 if (strcmp(global.params.llvmArch,"x86")==0) { | |
687 VersionCondition::addPredefinedGlobalIdent("X86"); | |
688 global.params.isLE = true; | |
689 global.params.is64bit = false; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
690 global.params.cpu = ARCHx86; |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
691 global.params.tt_arch = "i686"; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
692 global.params.data_layout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-f80:32:32-v64:64:64-v128:128:128-a0:0:64"; |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
439
diff
changeset
|
693 if (global.params.useInlineAsm) { |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
439
diff
changeset
|
694 VersionCondition::addPredefinedGlobalIdent("D_InlineAsm"); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
439
diff
changeset
|
695 VersionCondition::addPredefinedGlobalIdent("D_InlineAsm_X86"); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
439
diff
changeset
|
696 } |
159 | 697 } |
698 else if (strcmp(global.params.llvmArch,"x86-64")==0) { | |
699 VersionCondition::addPredefinedGlobalIdent("X86_64"); | |
700 global.params.isLE = true; | |
701 global.params.is64bit = true; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
702 global.params.cpu = ARCHx86_64; |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
703 global.params.tt_arch = "x86_64"; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
704 global.params.data_layout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"; |
159 | 705 } |
706 else if (strcmp(global.params.llvmArch,"ppc32")==0) { | |
707 VersionCondition::addPredefinedGlobalIdent("PPC"); | |
708 global.params.isLE = false; | |
709 global.params.is64bit = false; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
710 global.params.cpu = ARCHppc; |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
711 global.params.tt_arch = "powerpc"; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
712 global.params.data_layout = "E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64"; |
159 | 713 } |
714 else if (strcmp(global.params.llvmArch,"ppc64")==0) { | |
715 VersionCondition::addPredefinedGlobalIdent("PPC64"); | |
716 global.params.isLE = false; | |
717 global.params.is64bit = true; | |
237
a168a2c3ea48
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
lindquist
parents:
220
diff
changeset
|
718 global.params.cpu = ARCHppc_64; |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
719 global.params.tt_arch = "powerpc64"; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
720 global.params.data_layout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64"; |
159 | 721 } |
722 else { | |
723 assert(0 && "Invalid arch"); | |
724 } | |
725 | |
726 if (allowForceEndianness && global.params.forceBE) { | |
727 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
728 global.params.isLE = false; | |
729 } | |
730 else if (global.params.isLE) { | |
731 VersionCondition::addPredefinedGlobalIdent("LittleEndian"); | |
732 } | |
733 else { | |
734 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
735 } | |
736 | |
737 if (global.params.is64bit) { | |
738 VersionCondition::addPredefinedGlobalIdent("LLVM64"); | |
739 } | |
740 | |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
741 |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
742 // setup version idents and tt_os for chosen target os |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
743 switch(global.params.os) |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
744 { |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
745 case OSWindows: |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
746 VersionCondition::addPredefinedGlobalIdent("Windows"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
747 VersionCondition::addPredefinedGlobalIdent("Win32"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
748 VersionCondition::addPredefinedGlobalIdent("mingw32"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
749 global.params.tt_os = "-pc-mingw32"; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
750 break; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
751 |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
752 case OSLinux: |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
753 VersionCondition::addPredefinedGlobalIdent("linux"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
754 VersionCondition::addPredefinedGlobalIdent("Posix"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
755 global.params.tt_os = "-pc-linux-gnu"; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
756 break; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
757 |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
758 default: |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
759 assert(false && "Target OS not supported"); |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
760 } |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
761 |
159 | 762 |
763 // Initialization | |
764 Type::init(); | |
765 Id::initialize(); | |
766 Module::init(); | |
767 initPrecedence(); | |
768 | |
769 backend_init(); | |
770 | |
771 //printf("%d source files\n",files.dim); | |
772 | |
773 // Build import search path | |
774 if (global.params.imppath) | |
775 { | |
776 for (i = 0; i < global.params.imppath->dim; i++) | |
777 { | |
778 char *path = (char *)global.params.imppath->data[i]; | |
779 Array *a = FileName::splitPath(path); | |
780 | |
781 if (a) | |
782 { | |
783 if (!global.path) | |
784 global.path = new Array(); | |
785 global.path->append(a); | |
786 } | |
787 } | |
788 } | |
789 | |
790 // Build string import search path | |
791 if (global.params.fileImppath) | |
792 { | |
793 for (i = 0; i < global.params.fileImppath->dim; i++) | |
794 { | |
795 char *path = (char *)global.params.fileImppath->data[i]; | |
796 Array *a = FileName::splitPath(path); | |
797 | |
798 if (a) | |
799 { | |
800 if (!global.filePath) | |
801 global.filePath = new Array(); | |
802 global.filePath->append(a); | |
803 } | |
804 } | |
805 } | |
806 | |
807 // Create Modules | |
808 Array modules; | |
809 modules.reserve(files.dim); | |
810 for (i = 0; i < files.dim; i++) | |
811 { Identifier *id; | |
812 char *ext; | |
813 char *name; | |
814 | |
815 p = (char *) files.data[i]; | |
816 | |
817 p = FileName::name(p); // strip path | |
818 ext = FileName::ext(p); | |
819 if (ext) | |
820 { | |
821 #if IN_LLVM | |
822 if (strcmp(ext, global.nativeobj_ext) == 0 || | |
823 strcmp(ext, global.obj_ext) == 0) | |
824 #elif TARGET_LINUX | |
825 if (strcmp(ext, global.obj_ext) == 0) | |
826 #else | |
827 if (stricmp(ext, global.obj_ext) == 0) | |
828 #endif | |
829 { | |
830 global.params.objfiles->push(files.data[i]); | |
831 continue; | |
832 } | |
833 | |
279
a137ed004205
[svn r300] Removed some win32 stuff that was causing problems on mingw32.
lindquist
parents:
277
diff
changeset
|
834 #if TARGET_LINUX || __MINGW32__ |
159 | 835 if (strcmp(ext, "a") == 0) |
836 #else | |
837 if (stricmp(ext, "lib") == 0) | |
838 #endif | |
839 { | |
840 global.params.libfiles->push(files.data[i]); | |
841 continue; | |
842 } | |
843 | |
844 if (strcmp(ext, global.ddoc_ext) == 0) | |
845 { | |
846 global.params.ddocfiles->push(files.data[i]); | |
847 continue; | |
848 } | |
849 | |
850 #if !TARGET_LINUX | |
851 if (stricmp(ext, "res") == 0) | |
852 { | |
853 global.params.resfile = (char *)files.data[i]; | |
854 continue; | |
855 } | |
856 | |
857 if (stricmp(ext, "def") == 0) | |
858 { | |
859 global.params.deffile = (char *)files.data[i]; | |
860 continue; | |
861 } | |
862 | |
863 if (stricmp(ext, "exe") == 0) | |
864 { | |
865 global.params.exefile = (char *)files.data[i]; | |
866 continue; | |
867 } | |
868 #endif | |
869 | |
870 if (stricmp(ext, global.mars_ext) == 0 || | |
510
6aee82889553
Merged DMD 1.034, array operations are not yet implemented ;)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
871 stricmp(ext, global.hdr_ext) == 0 || |
159 | 872 stricmp(ext, "htm") == 0 || |
873 stricmp(ext, "html") == 0 || | |
874 stricmp(ext, "xhtml") == 0) | |
875 { | |
876 ext--; // skip onto '.' | |
877 assert(*ext == '.'); | |
878 name = (char *)mem.malloc((ext - p) + 1); | |
879 memcpy(name, p, ext - p); | |
880 name[ext - p] = 0; // strip extension | |
881 | |
882 if (name[0] == 0 || | |
883 strcmp(name, "..") == 0 || | |
884 strcmp(name, ".") == 0) | |
885 { | |
886 Linvalid: | |
887 error("invalid file name '%s'", (char *)files.data[i]); | |
888 fatal(); | |
889 } | |
890 } | |
891 else | |
892 { error("unrecognized file extension %s\n", ext); | |
893 fatal(); | |
894 } | |
895 } | |
896 else | |
897 { name = p; | |
898 if (!*name) | |
899 goto Linvalid; | |
900 } | |
901 | |
902 id = new Identifier(name, 0); | |
903 m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration); | |
904 modules.push(m); | |
905 | |
906 global.params.objfiles->push(m->objfile->name->str); | |
907 } | |
908 | |
909 // Read files, parse them | |
910 for (i = 0; i < modules.dim; i++) | |
911 { | |
912 m = (Module *)modules.data[i]; | |
913 if (global.params.verbose) | |
914 printf("parse %s\n", m->toChars()); | |
915 if (!Module::rootModule) | |
916 Module::rootModule = m; | |
917 m->importedFrom = m; | |
918 m->deleteObjFile(); | |
919 m->read(0); | |
920 m->parse(); | |
921 if (m->isDocFile) | |
922 { | |
923 m->gendocfile(); | |
924 | |
925 // Remove m from list of modules | |
926 modules.remove(i); | |
927 i--; | |
928 | |
929 // Remove m's object file from list of object files | |
930 for (int j = 0; j < global.params.objfiles->dim; j++) | |
931 { | |
932 if (m->objfile->name->str == global.params.objfiles->data[j]) | |
933 { | |
934 global.params.objfiles->remove(j); | |
935 break; | |
936 } | |
937 } | |
938 | |
939 if (global.params.objfiles->dim == 0) | |
940 global.params.link = 0; | |
941 } | |
942 } | |
943 if (global.errors) | |
944 fatal(); | |
945 #ifdef _DH | |
946 if (global.params.doHdrGeneration) | |
947 { | |
948 /* Generate 'header' import files. | |
949 * Since 'header' import files must be independent of command | |
950 * line switches and what else is imported, they are generated | |
951 * before any semantic analysis. | |
952 */ | |
953 for (i = 0; i < modules.dim; i++) | |
954 { | |
955 m = (Module *)modules.data[i]; | |
956 if (global.params.verbose) | |
957 printf("import %s\n", m->toChars()); | |
958 m->genhdrfile(); | |
959 } | |
960 } | |
961 if (global.errors) | |
962 fatal(); | |
963 #endif | |
964 | |
965 // Do semantic analysis | |
966 for (i = 0; i < modules.dim; i++) | |
967 { | |
968 m = (Module *)modules.data[i]; | |
969 if (global.params.verbose) | |
970 printf("semantic %s\n", m->toChars()); | |
971 m->semantic(); | |
972 } | |
973 if (global.errors) | |
974 fatal(); | |
975 | |
976 // Do pass 2 semantic analysis | |
977 for (i = 0; i < modules.dim; i++) | |
978 { | |
979 m = (Module *)modules.data[i]; | |
980 if (global.params.verbose) | |
981 printf("semantic2 %s\n", m->toChars()); | |
982 m->semantic2(); | |
983 } | |
984 if (global.errors) | |
985 fatal(); | |
986 | |
987 // Do pass 3 semantic analysis | |
988 for (i = 0; i < modules.dim; i++) | |
989 { | |
990 m = (Module *)modules.data[i]; | |
991 if (global.params.verbose) | |
992 printf("semantic3 %s\n", m->toChars()); | |
993 m->semantic3(); | |
994 } | |
995 if (global.errors) | |
996 fatal(); | |
997 | |
998 #if !IN_LLVM | |
999 // Scan for functions to inline | |
1000 if (global.params.useInline) | |
1001 { | |
1002 /* The problem with useArrayBounds and useAssert is that the | |
1003 * module being linked to may not have generated them, so if | |
1004 * we inline functions from those modules, the symbols for them will | |
1005 * not be found at link time. | |
1006 */ | |
1007 if (!global.params.useArrayBounds && !global.params.useAssert) | |
1008 { | |
1009 #endif | |
1010 // Do pass 3 semantic analysis on all imported modules, | |
1011 // since otherwise functions in them cannot be inlined | |
1012 for (i = 0; i < Module::amodules.dim; i++) | |
1013 { | |
1014 m = (Module *)Module::amodules.data[i]; | |
1015 if (global.params.verbose) | |
1016 printf("semantic3 %s\n", m->toChars()); | |
1017 m->semantic3(); | |
1018 } | |
1019 if (global.errors) | |
1020 fatal(); | |
1021 #if !IN_LLVM | |
1022 } | |
1023 | |
1024 for (i = 0; i < modules.dim; i++) | |
1025 { | |
1026 m = (Module *)modules.data[i]; | |
1027 if (global.params.verbose) | |
1028 printf("inline scan %s\n", m->toChars()); | |
1029 m->inlineScan(); | |
1030 } | |
1031 } | |
1032 if (global.errors) | |
1033 fatal(); | |
1034 #endif | |
1035 | |
1036 // Generate output files | |
1037 for (i = 0; i < modules.dim; i++) | |
1038 { | |
1039 m = (Module *)modules.data[i]; | |
1040 if (global.params.verbose) | |
1041 printf("code %s\n", m->toChars()); | |
1042 if (global.params.obj) | |
336 | 1043 m->genobjfile(0); |
159 | 1044 if (global.errors) |
1045 m->deleteObjFile(); | |
1046 else | |
1047 { | |
1048 if (global.params.doDocComments) | |
1049 m->gendocfile(); | |
1050 } | |
1051 } | |
279
a137ed004205
[svn r300] Removed some win32 stuff that was causing problems on mingw32.
lindquist
parents:
277
diff
changeset
|
1052 |
159 | 1053 backend_term(); |
1054 if (global.errors) | |
1055 fatal(); | |
1056 | |
1057 if (!global.params.objfiles->dim) | |
1058 { | |
1059 if (global.params.link) | |
1060 error("no object files to link"); | |
1061 } | |
1062 else | |
1063 { | |
1064 if (global.params.link) | |
276
21f85bac0b1a
[svn r297] Fixed: rewrote linker code to use LLVM's Program facilities instead of DMD's oldschool broken "native" approach.
lindquist
parents:
262
diff
changeset
|
1065 //status = runLINK(); |
432 | 1066 linkExecutable(global.params.argv0); |
159 | 1067 |
1068 if (global.params.run) | |
1069 { | |
1070 if (!status) | |
1071 { | |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
1072 status = runExectuable(); |
159 | 1073 |
1074 /* Delete .obj files and .exe file | |
1075 */ | |
1076 for (i = 0; i < modules.dim; i++) | |
1077 { | |
1078 m = (Module *)modules.data[i]; | |
1079 m->deleteObjFile(); | |
1080 } | |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
1081 deleteExecutable(); |
159 | 1082 } |
1083 } | |
1084 } | |
1085 | |
1086 return status; | |
1087 } | |
1088 | |
1089 | |
1090 | |
1091 /*********************************** | |
1092 * Parse and append contents of environment variable envvar | |
1093 * to argc and argv[]. | |
1094 * The string is separated into arguments, processing \ and ". | |
1095 */ | |
1096 | |
1097 void getenv_setargv(const char *envvar, int *pargc, char** *pargv) | |
1098 { | |
1099 char *env; | |
1100 char *p; | |
1101 Array *argv; | |
1102 int argc; | |
1103 | |
1104 int wildcard; // do wildcard expansion | |
1105 int instring; | |
1106 int slash; | |
1107 char c; | |
1108 int j; | |
1109 | |
1110 env = getenv(envvar); | |
1111 if (!env) | |
1112 return; | |
1113 | |
1114 env = mem.strdup(env); // create our own writable copy | |
1115 | |
1116 argc = *pargc; | |
1117 argv = new Array(); | |
1118 argv->setDim(argc); | |
1119 | |
1120 for (int i = 0; i < argc; i++) | |
1121 argv->data[i] = (void *)(*pargv)[i]; | |
1122 | |
1123 j = 1; // leave argv[0] alone | |
1124 while (1) | |
1125 { | |
1126 wildcard = 1; | |
1127 switch (*env) | |
1128 { | |
1129 case ' ': | |
1130 case '\t': | |
1131 env++; | |
1132 break; | |
1133 | |
1134 case 0: | |
1135 goto Ldone; | |
1136 | |
1137 case '"': | |
1138 wildcard = 0; | |
1139 default: | |
1140 argv->push(env); // append | |
1141 //argv->insert(j, env); // insert at position j | |
1142 j++; | |
1143 argc++; | |
1144 p = env; | |
1145 slash = 0; | |
1146 instring = 0; | |
1147 c = 0; | |
1148 | |
1149 while (1) | |
1150 { | |
1151 c = *env++; | |
1152 switch (c) | |
1153 { | |
1154 case '"': | |
1155 p -= (slash >> 1); | |
1156 if (slash & 1) | |
1157 { p--; | |
1158 goto Laddc; | |
1159 } | |
1160 instring ^= 1; | |
1161 slash = 0; | |
1162 continue; | |
1163 | |
1164 case ' ': | |
1165 case '\t': | |
1166 if (instring) | |
1167 goto Laddc; | |
1168 *p = 0; | |
1169 //if (wildcard) | |
1170 //wildcardexpand(); // not implemented | |
1171 break; | |
1172 | |
1173 case '\\': | |
1174 slash++; | |
1175 *p++ = c; | |
1176 continue; | |
1177 | |
1178 case 0: | |
1179 *p = 0; | |
1180 //if (wildcard) | |
1181 //wildcardexpand(); // not implemented | |
1182 goto Ldone; | |
1183 | |
1184 default: | |
1185 Laddc: | |
1186 slash = 0; | |
1187 *p++ = c; | |
1188 continue; | |
1189 } | |
1190 break; | |
1191 } | |
1192 } | |
1193 } | |
1194 | |
1195 Ldone: | |
1196 *pargc = argc; | |
1197 *pargv = (char **)argv->data; | |
1198 } |