Mercurial > projects > ldc
annotate dmd/mars.c @ 237:a168a2c3ea48 trunk
[svn r253] Removed -inlineasm option. inline asm is now enabled by default unless the new -noasm option is passed.
Tried adding a stack trace print when compiler crashes, not sure it's working though.
Changed data layouts to match that of llvm-gcc.
Fixed casting function pointers.
Added support checks in AsmStatement.
author | lindquist |
---|---|
date | Sun, 08 Jun 2008 19:09:24 +0200 |
parents | ccc2e6898a78 |
children | fc9c1a0eabbd |
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; | |
319 #elif linux | |
320 VersionCondition::addPredefinedGlobalIdent("linux"); | |
321 global.params.isLinux = 1; | |
322 tt_os = "-unknown-linux-gnu"; | |
323 #else | |
324 #error | |
325 #endif /* linux */ | |
326 | |
327 //VersionCondition::addPredefinedGlobalIdent("D_Bits"); | |
328 VersionCondition::addPredefinedGlobalIdent("all"); | |
329 | |
330 #if _WIN32 | |
331 inifile(argv[0], "llvmdc.ini"); | |
332 #endif | |
333 #if linux | |
334 inifile(argv[0], "llvmdc.conf"); | |
335 #else | |
336 #error | |
337 #endif | |
338 getenv_setargv("DFLAGS", &argc, &argv); | |
339 | |
340 #if 0 | |
341 for (i = 0; i < argc; i++) | |
342 { | |
343 printf("argv[%d] = '%s'\n", i, argv[i]); | |
344 } | |
345 #endif | |
346 | |
347 for (i = 1; i < argc; i++) | |
348 { | |
349 p = argv[i]; | |
350 if (*p == '-') | |
351 { | |
352 if (strcmp(p + 1, "d") == 0) | |
353 global.params.useDeprecated = 1; | |
354 else if (strcmp(p + 1, "c") == 0) | |
355 global.params.link = 0; | |
356 else if (strcmp(p + 1, "cov") == 0) | |
357 global.params.cov = 1; | |
358 else if (strcmp(p + 1, "fPIC") == 0) | |
359 global.params.pic = 1; | |
360 else if (strcmp(p + 1, "g") == 0) | |
361 global.params.symdebug = 1; | |
362 else if (strcmp(p + 1, "gc") == 0) | |
363 global.params.symdebug = 2; | |
364 else if (strcmp(p + 1, "gt") == 0) | |
365 { error("use -profile instead of -gt\n"); | |
366 global.params.trace = 1; | |
367 } | |
368 else if (strcmp(p + 1, "profile") == 0) | |
369 global.params.trace = 1; | |
370 else if (strcmp(p + 1, "v") == 0) | |
371 global.params.verbose = 1; | |
372 else if (strcmp(p + 1, "vv") == 0) { | |
373 Logger::enable(); | |
374 very_verbose = true; | |
375 } | |
376 else if (strcmp(p + 1, "v1") == 0) | |
377 global.params.Dversion = 1; | |
378 else if (strcmp(p + 1, "w") == 0) | |
379 global.params.warnings = 1; | |
380 else if (p[1] == 'O') | |
381 { | |
382 global.params.optimize = 1; | |
383 global.params.optimizeLevel = 2; | |
384 if (p[2] != 0) { | |
385 int optlevel = atoi(p+2); | |
386 if (optlevel < 0 || optlevel > 5) { | |
387 error("Optimization level must be between 0 and 5. Using default (%d)", | |
388 global.params.optimizeLevel); | |
389 } | |
390 else { | |
391 global.params.optimizeLevel = optlevel; | |
392 } | |
393 } | |
394 } | |
395 else if (strcmp(p + 1, "forcebe") == 0) | |
396 global.params.forceBE = 1; | |
397 else if (strcmp(p + 1, "noruntime") == 0) | |
398 global.params.noruntime = 1; | |
399 else if (strcmp(p + 1, "noverify") == 0) | |
400 global.params.novalidate = 1; | |
401 else if (strcmp(p + 1, "dis") == 0) | |
402 global.params.disassemble = 1; | |
403 else if (strcmp(p + 1, "annotate") == 0) | |
404 global.params.llvmAnnotate = 1; | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
405 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
|
406 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
|
407 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
|
408 global.params.useInlineAsm = 0; |
159 | 409 else if (p[1] == 'o') |
410 { | |
411 switch (p[2]) | |
412 { | |
413 case '-': | |
414 global.params.obj = 0; | |
415 break; | |
416 | |
417 case 'd': | |
418 if (!p[3]) | |
419 goto Lnoarg; | |
420 global.params.objdir = p + 3; | |
421 break; | |
422 | |
423 case 'f': | |
424 if (!p[3]) | |
425 goto Lnoarg; | |
426 global.params.objname = p + 3; | |
427 break; | |
428 | |
429 case 'p': | |
430 if (p[3]) | |
431 goto Lerror; | |
432 global.params.preservePaths = 1; | |
433 break; | |
434 | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
435 case 'q': |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
436 if (p[3]) |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
437 goto Lerror; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
438 global.params.fqnPaths = 1; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
439 break; |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
440 |
159 | 441 case 0: |
442 error("-o no longer supported, use -of or -od"); | |
443 break; | |
444 | |
445 default: | |
446 goto Lerror; | |
447 } | |
448 } | |
449 else if (p[1] == 'D') | |
450 { global.params.doDocComments = 1; | |
451 switch (p[2]) | |
452 { | |
453 case 'd': | |
454 if (!p[3]) | |
455 goto Lnoarg; | |
456 global.params.docdir = p + 3; | |
457 break; | |
458 case 'f': | |
459 if (!p[3]) | |
460 goto Lnoarg; | |
461 global.params.docname = p + 3; | |
462 break; | |
463 | |
464 case 0: | |
465 break; | |
466 | |
467 default: | |
468 goto Lerror; | |
469 } | |
470 } | |
471 #ifdef _DH | |
472 else if (p[1] == 'H') | |
473 { global.params.doHdrGeneration = 1; | |
474 switch (p[2]) | |
475 { | |
476 case 'd': | |
477 if (!p[3]) | |
478 goto Lnoarg; | |
479 global.params.hdrdir = p + 3; | |
480 break; | |
481 | |
482 case 'f': | |
483 if (!p[3]) | |
484 goto Lnoarg; | |
485 global.params.hdrname = p + 3; | |
486 break; | |
487 | |
488 case 0: | |
489 break; | |
490 | |
491 default: | |
492 goto Lerror; | |
493 } | |
494 } | |
495 #endif | |
496 else if (strcmp(p + 1, "ignore") == 0) | |
497 global.params.ignoreUnsupportedPragmas = 1; | |
498 else if (strcmp(p + 1, "inline") == 0) { | |
499 // TODO | |
500 // the ast rewrites dmd does for inlining messes up the ast. | |
501 // someday maybe we can support it, for now llvm does an excellent job at inlining | |
502 global.params.useInline = 0; //1 | |
503 global.params.llvmInline = 1; | |
504 } | |
505 else if (strcmp(p + 1, "nofloat") == 0) | |
506 global.params.nofloat = 1; | |
507 else if (strcmp(p + 1, "quiet") == 0) | |
508 global.params.quiet = 1; | |
509 else if (strcmp(p + 1, "release") == 0) | |
510 global.params.release = 1; | |
511 else if (strcmp(p + 1, "unittest") == 0) | |
512 global.params.useUnitTests = 1; | |
513 else if (p[1] == 'I') | |
514 { | |
515 if (!global.params.imppath) | |
516 global.params.imppath = new Array(); | |
517 global.params.imppath->push(p + 2); | |
518 } | |
519 else if (p[1] == 'J') | |
520 { | |
521 if (!global.params.fileImppath) | |
522 global.params.fileImppath = new Array(); | |
523 global.params.fileImppath->push(p + 2); | |
524 } | |
525 else if (p[1] == 'R') | |
526 { | |
527 global.params.runtimePath = p+2; | |
528 } | |
529 else if (memcmp(p + 1, "debug", 5) == 0 && p[6] != 'l') | |
530 { | |
531 // Parse: | |
532 // -debug | |
533 // -debug=number | |
534 // -debug=identifier | |
535 if (p[6] == '=') | |
536 { | |
537 if (isdigit(p[7])) | |
538 { long level; | |
539 | |
540 errno = 0; | |
541 level = strtol(p + 7, &p, 10); | |
542 if (*p || errno || level > INT_MAX) | |
543 goto Lerror; | |
544 DebugCondition::setGlobalLevel((int)level); | |
545 } | |
546 else if (Lexer::isValidIdentifier(p + 7)) | |
547 DebugCondition::addGlobalIdent(p + 7); | |
548 else | |
549 goto Lerror; | |
550 } | |
551 else if (p[6]) | |
552 goto Lerror; | |
553 else | |
554 global.params.debuglevel = 1; | |
555 } | |
556 else if (memcmp(p + 1, "version", 5) == 0) | |
557 { | |
558 // Parse: | |
559 // -version=number | |
560 // -version=identifier | |
561 if (p[8] == '=') | |
562 { | |
563 if (isdigit(p[9])) | |
564 { long level; | |
565 | |
566 errno = 0; | |
567 level = strtol(p + 9, &p, 10); | |
568 if (*p || errno || level > INT_MAX) | |
569 goto Lerror; | |
570 VersionCondition::setGlobalLevel((int)level); | |
571 } | |
572 else if (Lexer::isValidIdentifier(p + 9)) | |
573 VersionCondition::addGlobalIdent(p + 9); | |
574 else | |
575 goto Lerror; | |
576 } | |
577 else | |
578 goto Lerror; | |
579 } | |
580 else if (strcmp(p + 1, "-b") == 0) | |
581 global.params.debugb = 1; | |
582 else if (strcmp(p + 1, "-c") == 0) | |
583 global.params.debugc = 1; | |
584 else if (strcmp(p + 1, "-f") == 0) | |
585 global.params.debugf = 1; | |
586 else if (strcmp(p + 1, "-help") == 0) | |
587 { usage(); | |
588 exit(EXIT_SUCCESS); | |
589 } | |
590 else if (strcmp(p + 1, "-r") == 0) | |
591 global.params.debugr = 1; | |
592 else if (strcmp(p + 1, "-x") == 0) | |
593 global.params.debugx = 1; | |
594 else if (strcmp(p + 1, "-y") == 0) | |
595 global.params.debugy = 1; | |
596 else if (p[1] == 'L') | |
597 { | |
598 global.params.linkswitches->push(p + 2); | |
599 } | |
600 else if (memcmp(p + 1, "defaultlib=", 11) == 0) | |
601 { | |
602 global.params.defaultlibname = p + 1 + 11; | |
603 } | |
604 else if (memcmp(p + 1, "debuglib=", 9) == 0) | |
605 { | |
606 global.params.debuglibname = p + 1 + 9; | |
607 } | |
608 else if (strcmp(p + 1, "run") == 0) | |
609 { global.params.run = 1; | |
610 global.params.runargs_length = ((i >= argcstart) ? argc : argcstart) - i - 1; | |
611 if (global.params.runargs_length) | |
612 { | |
613 files.push(argv[i + 1]); | |
614 global.params.runargs = &argv[i + 2]; | |
615 i += global.params.runargs_length; | |
616 global.params.runargs_length--; | |
617 } | |
618 else | |
619 { global.params.run = 0; | |
620 goto Lnoarg; | |
621 } | |
622 } | |
623 else if (p[1] == 'm') | |
624 { | |
625 global.params.llvmArch = p+2; | |
626 } | |
627 else | |
628 { | |
629 Lerror: | |
630 error("unrecognized switch '%s'", argv[i]); | |
631 continue; | |
632 | |
633 Lnoarg: | |
634 error("argument expected for switch '%s'", argv[i]); | |
635 continue; | |
636 } | |
637 } | |
638 else | |
639 files.push(p); | |
640 } | |
641 if (global.errors) | |
642 { | |
643 fatal(); | |
644 } | |
645 if (files.dim == 0) | |
646 { usage(); | |
647 return EXIT_FAILURE; | |
648 } | |
649 | |
650 if (global.params.release) | |
651 { global.params.useInvariants = 0; | |
652 global.params.useIn = 0; | |
653 global.params.useOut = 0; | |
654 global.params.useAssert = 0; | |
655 global.params.useArrayBounds = 0; | |
656 global.params.useSwitchError = 0; | |
657 } | |
658 | |
659 if (global.params.run) | |
660 global.params.quiet = 1; | |
661 | |
662 if (global.params.useUnitTests) | |
663 global.params.useAssert = 1; | |
664 | |
665 if (!global.params.obj) | |
666 global.params.link = 0; | |
667 | |
668 if (global.params.link) | |
669 { | |
670 global.params.exefile = global.params.objname; | |
671 global.params.objname = NULL; | |
672 } | |
673 else if (global.params.run) | |
674 { | |
675 error("flags conflict with -run"); | |
676 fatal(); | |
677 } | |
678 else | |
679 { | |
680 if (global.params.objname && files.dim > 1) | |
681 { | |
682 error("multiple source files, but only one .obj name"); | |
683 fatal(); | |
684 } | |
685 } | |
686 if (global.params.cov) | |
687 VersionCondition::addPredefinedGlobalIdent("D_Coverage"); | |
688 | |
689 bool allowForceEndianness = false; | |
690 | |
691 if (global.params.llvmArch == 0) { | |
692 std::string err_str; | |
693 const llvm::TargetMachineRegistry::entry* e = llvm::TargetMachineRegistry::getClosestTargetForJIT(err_str); | |
694 if (e == 0) { | |
695 error("Failed to find a default target machine: %s", err_str.c_str()); | |
696 fatal(); | |
697 } | |
698 else { | |
699 global.params.llvmArch = const_cast<char*>(e->Name); | |
700 if (global.params.verbose || very_verbose) | |
701 printf("Default target found: %s\n", global.params.llvmArch); | |
702 if (very_verbose) { | |
703 int X = sizeof(va_list); | |
704 printf("valist.sizeof = %d\n", X); | |
705 } | |
706 } | |
707 } | |
708 | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
709 bool is_x86 = false; |
159 | 710 if (strcmp(global.params.llvmArch,"x86")==0) { |
711 VersionCondition::addPredefinedGlobalIdent("X86"); | |
712 //VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86"); | |
713 global.params.isLE = true; | |
714 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
|
715 global.params.cpu = ARCHx86; |
159 | 716 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
|
717 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
|
718 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
|
719 |
159 | 720 } |
721 else if (strcmp(global.params.llvmArch,"x86-64")==0) { | |
722 VersionCondition::addPredefinedGlobalIdent("X86_64"); | |
723 //VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86_64"); | |
724 global.params.isLE = true; | |
725 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
|
726 global.params.cpu = ARCHx86_64; |
159 | 727 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
|
728 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 | 729 } |
730 else if (strcmp(global.params.llvmArch,"ppc32")==0) { | |
731 VersionCondition::addPredefinedGlobalIdent("PPC"); | |
732 global.params.isLE = false; | |
733 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
|
734 global.params.cpu = ARCHppc; |
159 | 735 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
|
736 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 | 737 } |
738 else if (strcmp(global.params.llvmArch,"ppc64")==0) { | |
739 VersionCondition::addPredefinedGlobalIdent("PPC64"); | |
740 global.params.isLE = false; | |
741 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
|
742 global.params.cpu = ARCHppc_64; |
159 | 743 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
|
744 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 | 745 } |
746 else { | |
747 assert(0 && "Invalid arch"); | |
748 } | |
749 | |
750 if (allowForceEndianness && global.params.forceBE) { | |
751 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
752 global.params.isLE = false; | |
753 } | |
754 else if (global.params.isLE) { | |
755 VersionCondition::addPredefinedGlobalIdent("LittleEndian"); | |
756 } | |
757 else { | |
758 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
759 } | |
760 | |
761 if (global.params.is64bit) { | |
762 VersionCondition::addPredefinedGlobalIdent("LLVM64"); | |
763 } | |
764 | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
765 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
|
766 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
|
767 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
|
768 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
|
769 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
770 VersionCondition::addPredefinedGlobalIdent("LLVM_X86_FP80"); |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
771 } |
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
|
772 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
|
773 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
|
774 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
|
775 } |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
776 |
159 | 777 assert(tt_arch != 0); |
778 assert(tt_os != 0); | |
779 assert(data_layout != 0); | |
780 global.params.tt_arch = tt_arch; | |
781 global.params.tt_os = tt_os; | |
782 global.params.data_layout = data_layout; | |
783 | |
784 // Initialization | |
785 Type::init(); | |
786 Id::initialize(); | |
787 Module::init(); | |
788 initPrecedence(); | |
789 | |
790 backend_init(); | |
791 | |
792 //printf("%d source files\n",files.dim); | |
793 | |
794 // Build import search path | |
795 if (global.params.imppath) | |
796 { | |
797 for (i = 0; i < global.params.imppath->dim; i++) | |
798 { | |
799 char *path = (char *)global.params.imppath->data[i]; | |
800 Array *a = FileName::splitPath(path); | |
801 | |
802 if (a) | |
803 { | |
804 if (!global.path) | |
805 global.path = new Array(); | |
806 global.path->append(a); | |
807 } | |
808 } | |
809 } | |
810 | |
811 // Build string import search path | |
812 if (global.params.fileImppath) | |
813 { | |
814 for (i = 0; i < global.params.fileImppath->dim; i++) | |
815 { | |
816 char *path = (char *)global.params.fileImppath->data[i]; | |
817 Array *a = FileName::splitPath(path); | |
818 | |
819 if (a) | |
820 { | |
821 if (!global.filePath) | |
822 global.filePath = new Array(); | |
823 global.filePath->append(a); | |
824 } | |
825 } | |
826 } | |
827 | |
828 // Create Modules | |
829 Array modules; | |
830 modules.reserve(files.dim); | |
831 for (i = 0; i < files.dim; i++) | |
832 { Identifier *id; | |
833 char *ext; | |
834 char *name; | |
835 | |
836 p = (char *) files.data[i]; | |
837 | |
838 #if _WIN32 | |
839 // Convert / to \ so linker will work | |
840 for (int i = 0; p[i]; i++) | |
841 { | |
842 if (p[i] == '/') | |
843 p[i] = '\\'; | |
844 } | |
845 #endif | |
846 | |
847 p = FileName::name(p); // strip path | |
848 ext = FileName::ext(p); | |
849 if (ext) | |
850 { | |
851 #if IN_LLVM | |
852 if (strcmp(ext, global.nativeobj_ext) == 0 || | |
853 strcmp(ext, global.obj_ext) == 0) | |
854 #elif TARGET_LINUX | |
855 if (strcmp(ext, global.obj_ext) == 0) | |
856 #else | |
857 if (stricmp(ext, global.obj_ext) == 0) | |
858 #endif | |
859 { | |
860 global.params.objfiles->push(files.data[i]); | |
861 continue; | |
862 } | |
863 | |
864 #if TARGET_LINUX | |
865 if (strcmp(ext, "a") == 0) | |
866 #else | |
867 if (stricmp(ext, "lib") == 0) | |
868 #endif | |
869 { | |
870 global.params.libfiles->push(files.data[i]); | |
871 continue; | |
872 } | |
873 | |
874 if (strcmp(ext, global.ddoc_ext) == 0) | |
875 { | |
876 global.params.ddocfiles->push(files.data[i]); | |
877 continue; | |
878 } | |
879 | |
880 #if !TARGET_LINUX | |
881 if (stricmp(ext, "res") == 0) | |
882 { | |
883 global.params.resfile = (char *)files.data[i]; | |
884 continue; | |
885 } | |
886 | |
887 if (stricmp(ext, "def") == 0) | |
888 { | |
889 global.params.deffile = (char *)files.data[i]; | |
890 continue; | |
891 } | |
892 | |
893 if (stricmp(ext, "exe") == 0) | |
894 { | |
895 global.params.exefile = (char *)files.data[i]; | |
896 continue; | |
897 } | |
898 #endif | |
899 | |
900 if (stricmp(ext, global.mars_ext) == 0 || | |
901 stricmp(ext, "htm") == 0 || | |
902 stricmp(ext, "html") == 0 || | |
903 stricmp(ext, "xhtml") == 0) | |
904 { | |
905 ext--; // skip onto '.' | |
906 assert(*ext == '.'); | |
907 name = (char *)mem.malloc((ext - p) + 1); | |
908 memcpy(name, p, ext - p); | |
909 name[ext - p] = 0; // strip extension | |
910 | |
911 if (name[0] == 0 || | |
912 strcmp(name, "..") == 0 || | |
913 strcmp(name, ".") == 0) | |
914 { | |
915 Linvalid: | |
916 error("invalid file name '%s'", (char *)files.data[i]); | |
917 fatal(); | |
918 } | |
919 } | |
920 else | |
921 { error("unrecognized file extension %s\n", ext); | |
922 fatal(); | |
923 } | |
924 } | |
925 else | |
926 { name = p; | |
927 if (!*name) | |
928 goto Linvalid; | |
929 } | |
930 | |
931 id = new Identifier(name, 0); | |
932 m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration); | |
933 modules.push(m); | |
934 | |
935 global.params.objfiles->push(m->objfile->name->str); | |
936 } | |
937 | |
938 #if _WIN32 | |
939 __try | |
940 { | |
941 #endif | |
942 // Read files, parse them | |
943 for (i = 0; i < modules.dim; i++) | |
944 { | |
945 m = (Module *)modules.data[i]; | |
946 if (global.params.verbose) | |
947 printf("parse %s\n", m->toChars()); | |
948 if (!Module::rootModule) | |
949 Module::rootModule = m; | |
950 m->importedFrom = m; | |
951 m->deleteObjFile(); | |
952 m->read(0); | |
953 m->parse(); | |
954 if (m->isDocFile) | |
955 { | |
956 m->gendocfile(); | |
957 | |
958 // Remove m from list of modules | |
959 modules.remove(i); | |
960 i--; | |
961 | |
962 // Remove m's object file from list of object files | |
963 for (int j = 0; j < global.params.objfiles->dim; j++) | |
964 { | |
965 if (m->objfile->name->str == global.params.objfiles->data[j]) | |
966 { | |
967 global.params.objfiles->remove(j); | |
968 break; | |
969 } | |
970 } | |
971 | |
972 if (global.params.objfiles->dim == 0) | |
973 global.params.link = 0; | |
974 } | |
975 } | |
976 if (global.errors) | |
977 fatal(); | |
978 #ifdef _DH | |
979 if (global.params.doHdrGeneration) | |
980 { | |
981 /* Generate 'header' import files. | |
982 * Since 'header' import files must be independent of command | |
983 * line switches and what else is imported, they are generated | |
984 * before any semantic analysis. | |
985 */ | |
986 for (i = 0; i < modules.dim; i++) | |
987 { | |
988 m = (Module *)modules.data[i]; | |
989 if (global.params.verbose) | |
990 printf("import %s\n", m->toChars()); | |
991 m->genhdrfile(); | |
992 } | |
993 } | |
994 if (global.errors) | |
995 fatal(); | |
996 #endif | |
997 | |
998 // Do semantic analysis | |
999 for (i = 0; i < modules.dim; i++) | |
1000 { | |
1001 m = (Module *)modules.data[i]; | |
1002 if (global.params.verbose) | |
1003 printf("semantic %s\n", m->toChars()); | |
1004 m->semantic(); | |
1005 } | |
1006 if (global.errors) | |
1007 fatal(); | |
1008 | |
1009 // Do pass 2 semantic analysis | |
1010 for (i = 0; i < modules.dim; i++) | |
1011 { | |
1012 m = (Module *)modules.data[i]; | |
1013 if (global.params.verbose) | |
1014 printf("semantic2 %s\n", m->toChars()); | |
1015 m->semantic2(); | |
1016 } | |
1017 if (global.errors) | |
1018 fatal(); | |
1019 | |
1020 // Do pass 3 semantic analysis | |
1021 for (i = 0; i < modules.dim; i++) | |
1022 { | |
1023 m = (Module *)modules.data[i]; | |
1024 if (global.params.verbose) | |
1025 printf("semantic3 %s\n", m->toChars()); | |
1026 m->semantic3(); | |
1027 } | |
1028 if (global.errors) | |
1029 fatal(); | |
1030 | |
1031 #if !IN_LLVM | |
1032 // Scan for functions to inline | |
1033 if (global.params.useInline) | |
1034 { | |
1035 /* The problem with useArrayBounds and useAssert is that the | |
1036 * module being linked to may not have generated them, so if | |
1037 * we inline functions from those modules, the symbols for them will | |
1038 * not be found at link time. | |
1039 */ | |
1040 if (!global.params.useArrayBounds && !global.params.useAssert) | |
1041 { | |
1042 #endif | |
1043 // Do pass 3 semantic analysis on all imported modules, | |
1044 // since otherwise functions in them cannot be inlined | |
1045 for (i = 0; i < Module::amodules.dim; i++) | |
1046 { | |
1047 m = (Module *)Module::amodules.data[i]; | |
1048 if (global.params.verbose) | |
1049 printf("semantic3 %s\n", m->toChars()); | |
1050 m->semantic3(); | |
1051 } | |
1052 if (global.errors) | |
1053 fatal(); | |
1054 #if !IN_LLVM | |
1055 } | |
1056 | |
1057 for (i = 0; i < modules.dim; i++) | |
1058 { | |
1059 m = (Module *)modules.data[i]; | |
1060 if (global.params.verbose) | |
1061 printf("inline scan %s\n", m->toChars()); | |
1062 m->inlineScan(); | |
1063 } | |
1064 } | |
1065 if (global.errors) | |
1066 fatal(); | |
1067 #endif | |
1068 | |
1069 // Generate output files | |
1070 for (i = 0; i < modules.dim; i++) | |
1071 { | |
1072 m = (Module *)modules.data[i]; | |
1073 if (global.params.verbose) | |
1074 printf("code %s\n", m->toChars()); | |
1075 if (global.params.obj) | |
1076 m->genobjfile(); | |
1077 if (global.errors) | |
1078 m->deleteObjFile(); | |
1079 else | |
1080 { | |
1081 if (global.params.doDocComments) | |
1082 m->gendocfile(); | |
1083 } | |
1084 } | |
1085 #if _WIN32 | |
1086 } | |
1087 __except (__ehfilter(GetExceptionInformation())) | |
1088 { | |
1089 printf("Stack overflow\n"); | |
1090 fatal(); | |
1091 } | |
1092 #endif | |
1093 backend_term(); | |
1094 if (global.errors) | |
1095 fatal(); | |
1096 | |
1097 if (!global.params.objfiles->dim) | |
1098 { | |
1099 if (global.params.link) | |
1100 error("no object files to link"); | |
1101 } | |
1102 else | |
1103 { | |
1104 if (global.params.link) | |
1105 status = runLINK(); | |
1106 | |
1107 if (global.params.run) | |
1108 { | |
1109 if (!status) | |
1110 { | |
1111 status = runProgram(); | |
1112 | |
1113 /* Delete .obj files and .exe file | |
1114 */ | |
1115 for (i = 0; i < modules.dim; i++) | |
1116 { | |
1117 m = (Module *)modules.data[i]; | |
1118 m->deleteObjFile(); | |
1119 } | |
1120 deleteExeFile(); | |
1121 } | |
1122 } | |
1123 } | |
1124 | |
1125 return status; | |
1126 } | |
1127 | |
1128 | |
1129 | |
1130 /*********************************** | |
1131 * Parse and append contents of environment variable envvar | |
1132 * to argc and argv[]. | |
1133 * The string is separated into arguments, processing \ and ". | |
1134 */ | |
1135 | |
1136 void getenv_setargv(const char *envvar, int *pargc, char** *pargv) | |
1137 { | |
1138 char *env; | |
1139 char *p; | |
1140 Array *argv; | |
1141 int argc; | |
1142 | |
1143 int wildcard; // do wildcard expansion | |
1144 int instring; | |
1145 int slash; | |
1146 char c; | |
1147 int j; | |
1148 | |
1149 env = getenv(envvar); | |
1150 if (!env) | |
1151 return; | |
1152 | |
1153 env = mem.strdup(env); // create our own writable copy | |
1154 | |
1155 argc = *pargc; | |
1156 argv = new Array(); | |
1157 argv->setDim(argc); | |
1158 | |
1159 for (int i = 0; i < argc; i++) | |
1160 argv->data[i] = (void *)(*pargv)[i]; | |
1161 | |
1162 j = 1; // leave argv[0] alone | |
1163 while (1) | |
1164 { | |
1165 wildcard = 1; | |
1166 switch (*env) | |
1167 { | |
1168 case ' ': | |
1169 case '\t': | |
1170 env++; | |
1171 break; | |
1172 | |
1173 case 0: | |
1174 goto Ldone; | |
1175 | |
1176 case '"': | |
1177 wildcard = 0; | |
1178 default: | |
1179 argv->push(env); // append | |
1180 //argv->insert(j, env); // insert at position j | |
1181 j++; | |
1182 argc++; | |
1183 p = env; | |
1184 slash = 0; | |
1185 instring = 0; | |
1186 c = 0; | |
1187 | |
1188 while (1) | |
1189 { | |
1190 c = *env++; | |
1191 switch (c) | |
1192 { | |
1193 case '"': | |
1194 p -= (slash >> 1); | |
1195 if (slash & 1) | |
1196 { p--; | |
1197 goto Laddc; | |
1198 } | |
1199 instring ^= 1; | |
1200 slash = 0; | |
1201 continue; | |
1202 | |
1203 case ' ': | |
1204 case '\t': | |
1205 if (instring) | |
1206 goto Laddc; | |
1207 *p = 0; | |
1208 //if (wildcard) | |
1209 //wildcardexpand(); // not implemented | |
1210 break; | |
1211 | |
1212 case '\\': | |
1213 slash++; | |
1214 *p++ = c; | |
1215 continue; | |
1216 | |
1217 case 0: | |
1218 *p = 0; | |
1219 //if (wildcard) | |
1220 //wildcardexpand(); // not implemented | |
1221 goto Ldone; | |
1222 | |
1223 default: | |
1224 Laddc: | |
1225 slash = 0; | |
1226 *p++ = c; | |
1227 continue; | |
1228 } | |
1229 break; | |
1230 } | |
1231 } | |
1232 } | |
1233 | |
1234 Ldone: | |
1235 *pargc = argc; | |
1236 *pargv = (char **)argv->data; | |
1237 } | |
1238 | |
1239 #if _WIN32 | |
1240 | |
1241 long __cdecl __ehfilter(LPEXCEPTION_POINTERS ep) | |
1242 { | |
1243 //printf("%x\n", ep->ExceptionRecord->ExceptionCode); | |
1244 if (ep->ExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW) | |
1245 { | |
1246 #ifndef DEBUG | |
1247 return EXCEPTION_EXECUTE_HANDLER; | |
1248 #endif | |
1249 } | |
1250 return EXCEPTION_CONTINUE_SEARCH; | |
1251 } | |
1252 | |
1253 #endif |