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