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