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