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