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