Mercurial > projects > ddmd
annotate main.d @ 34:544b922227c7
update to work with dmd 2.048
author | korDen |
---|---|
date | Sat, 21 Aug 2010 05:46:08 +0400 |
parents | 3f834bed4f13 |
children | 6bdecc3f4569 |
rev | line source |
---|---|
0 | 1 module main; |
2 | |
3 import dmd.Array; | |
4 import dmd.Module; | |
5 import dmd.Global; | |
6 import dmd.VersionCondition; | |
7 import dmd.DebugCondition; | |
8 import dmd.Loc; | |
9 import dmd.Lexer; | |
10 import dmd.OutBuffer; | |
11 import dmd.FileName; | |
12 import dmd.Type; | |
13 import dmd.File; | |
14 import dmd.Id; | |
15 import dmd.Identifier; | |
16 import dmd.Library; | |
17 import dmd.TOK; | |
18 import dmd.String; | |
19 import dmd.backend.glue; | |
20 | |
21 import std.stdarg; | |
22 import std.string : toStringz; | |
34 | 23 import std.exception; |
0 | 24 |
25 import core.stdc.string; | |
26 import core.stdc.stdio; | |
27 import core.stdc.ctype; | |
28 import core.stdc.errno; | |
29 import core.stdc.stdlib; | |
30 import core.stdc.limits; | |
31 | |
32 import core.memory; | |
33 | |
34 import dlib.CrashHandler; | |
35 import dbg.ui.CrashWindow; | |
36 | |
37 import dmd.Util; | |
38 | |
39 enum ExitCode | |
40 { | |
41 EXIT_SUCCESS = 0, | |
42 } | |
43 | |
34 | 44 extern (C) extern __gshared bool rt_trapExceptions; |
0 | 45 |
34 | 46 static this() { |
47 rt_trapExceptions = false; | |
0 | 48 } |
25 | 49 |
0 | 50 int main(string[] args) |
51 { | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
14
diff
changeset
|
52 GC.disable(); |
34 | 53 CrashHandlerInit(); |
54 | |
0 | 55 Array files = new Array(); |
56 Array libmodules = new Array(); | |
57 Module m; | |
58 int status = ExitCode.EXIT_SUCCESS; | |
59 int argcstart = args.length; | |
60 int setdebuglib = 0; | |
61 | |
62 global = new Global(); | |
63 | |
64 /// if (response_expand(&argc,&argv)) // expand response files | |
65 /// error("can't open response file"); | |
66 | |
67 files.reserve(args.length - 1); | |
68 | |
69 // Set default values | |
70 global.params.argv0 = args[0]; | |
71 global.params.link = 1; | |
72 global.params.useAssert = 1; | |
73 global.params.useInvariants = 1; | |
74 global.params.useIn = 1; | |
75 global.params.useOut = 1; | |
76 global.params.useArrayBounds = 1; | |
77 global.params.useSwitchError = 1; | |
78 global.params.useInline = 0; | |
79 global.params.obj = 1; | |
80 global.params.Dversion = 2; | |
81 global.params.quiet = 1; | |
82 | |
83 global.params.linkswitches = new Array(); | |
84 global.params.libfiles = new Array(); | |
85 global.params.objfiles = new Array(); | |
86 global.params.ddocfiles = new Array(); | |
87 | |
88 version (TARGET_WINDOS) { | |
89 global.params.defaultlibname = "phobos"; | |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
90 } else version (POSIX) { //#elif TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 91 global.params.defaultlibname = "phobos2"; |
92 } else version (TARGET_NET) { | |
93 } else { | |
94 static assert(false, "fix this"); | |
95 } | |
96 | |
97 // Predefine version identifiers | |
98 VersionCondition.addPredefinedGlobalIdent("DigitalMars"); | |
99 | |
100 version (TARGET_WINDOS) { | |
101 VersionCondition.addPredefinedGlobalIdent("Windows"); | |
102 global.params.isWindows = 1; | |
103 version (TARGET_NET) { | |
104 // TARGET_NET macro is NOT mutually-exclusive with TARGET_WINDOS | |
105 VersionCondition.addPredefinedGlobalIdent("D_NET"); | |
106 } | |
107 } else version (TARGET_LINUX) { | |
108 VersionCondition.addPredefinedGlobalIdent("Posix"); | |
109 VersionCondition.addPredefinedGlobalIdent("linux"); | |
110 global.params.isLinux = 1; | |
111 } else version (TARGET_OSX) { | |
112 VersionCondition.addPredefinedGlobalIdent("Posix"); | |
113 VersionCondition.addPredefinedGlobalIdent("OSX"); | |
114 global.params.isOSX = 1; | |
115 | |
116 // For legacy compatibility | |
117 VersionCondition.addPredefinedGlobalIdent("darwin"); | |
118 } else version (TARGET_FREEBSD) { | |
119 VersionCondition.addPredefinedGlobalIdent("Posix"); | |
120 VersionCondition.addPredefinedGlobalIdent("FreeBSD"); | |
121 global.params.isFreeBSD = 1; | |
122 } else version (TARGET_SOLARIS) { | |
123 VersionCondition.addPredefinedGlobalIdent("Posix"); | |
124 VersionCondition.addPredefinedGlobalIdent("Solaris"); | |
125 global.params.isSolaris = 1; | |
126 } else { | |
127 static assert (false, "fix this"); | |
128 } | |
129 | |
130 VersionCondition.addPredefinedGlobalIdent("LittleEndian"); | |
131 //VersionCondition.addPredefinedGlobalIdent("D_Bits"); | |
132 version (DMDV2) { | |
133 VersionCondition.addPredefinedGlobalIdent("D_Version2"); | |
134 } | |
135 VersionCondition.addPredefinedGlobalIdent("all"); | |
136 | |
137 version (_WIN32) { | |
138 inifile(args[0], "sc.ini"); | |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
139 } else version (POSIX) {///linux || __APPLE__ || __FreeBSD__ || __sun&&__SVR4 |
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
140 inifile(args[0], "dmd.conf"); |
0 | 141 } else { |
142 static assert (false, "fix this"); | |
143 } | |
144 args = getenv_setargv("DFLAGS", args); | |
145 | |
146 version (disabled) { | |
147 for (i = 0; i < argc; i++) | |
148 { | |
149 writef("argv[%d] = '%s'\n", i, argv[i]); | |
150 } | |
151 } | |
152 | |
153 foreach(i; 1..args.length) | |
154 { | |
155 auto arg = args[i]; | |
156 auto p = arg.ptr; | |
157 if (*p == '-') | |
158 { | |
159 arg = arg[1..$]; | |
160 if (arg == "d") | |
161 global.params.useDeprecated = 1; | |
162 else if (arg == "c") | |
163 global.params.link = 0; | |
164 else if (arg == "cov") | |
165 global.params.cov = 1; | |
166 ///version (XXX) {// TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS | |
167 /// else if (arg == "fPIC") | |
168 /// global.params.pic = 1; | |
169 ///} | |
170 else if (arg == "multiobj") | |
171 global.params.multiobj = 1; | |
172 else if (arg == "g") | |
173 global.params.symdebug = 1; | |
174 else if (arg == "gc") | |
175 global.params.symdebug = 2; | |
176 else if (arg == "gt") | |
177 { error("use -profile instead of -gt\n"); | |
178 global.params.trace = 1; | |
179 } | |
180 else if (arg == "m64") | |
181 global.params.isX86_64 = 1; | |
182 else if (arg == "profile") | |
183 global.params.trace = 1; | |
184 else if (arg == "v") | |
185 global.params.verbose = 1; | |
186 ///version (DMDV2) { | |
187 else if (arg == "vtls") | |
188 global.params.vtls = 1; | |
189 ///} | |
190 else if (arg == "v1") | |
191 { | |
192 version (DMDV1) { | |
193 global.params.Dversion = 1; | |
194 } else { | |
195 error("use DMD 1.0 series compilers for -v1 switch"); | |
196 break; | |
197 } | |
198 } | |
199 else if (arg == "w") | |
200 global.params.warnings = 1; | |
201 else if (arg == "O") | |
202 global.params.optimize = 1; | |
203 else if (p[1] == 'o') | |
204 { | |
205 switch (p[2]) | |
206 { | |
207 case '-': | |
208 global.params.obj = 0; | |
209 break; | |
210 | |
211 case 'd': | |
212 if (!p[3]) | |
213 goto Lnoarg; | |
214 global.params.objdir = arg[(p - arg.ptr) + 3..$]; | |
215 break; | |
216 | |
217 case 'f': | |
218 { | |
219 if (!p[3]) | |
220 goto Lnoarg; | |
221 | |
222 global.params.objname = arg[(p - arg.ptr) + 3..$]; | |
223 break; | |
224 } | |
225 | |
226 case 'p': | |
227 if (p[3]) | |
228 goto Lerror; | |
229 global.params.preservePaths = 1; | |
230 break; | |
231 | |
232 case 0: | |
233 error("-o no longer supported, use -of or -od"); | |
234 break; | |
235 | |
236 default: | |
237 goto Lerror; | |
238 } | |
239 } | |
240 else if (p[1] == 'D') | |
241 { global.params.doDocComments = 1; | |
242 switch (p[2]) | |
243 { | |
244 case 'd': | |
245 if (!p[3]) | |
246 goto Lnoarg; | |
247 global.params.docdir = arg[(p - arg.ptr) + 3..$]; | |
248 break; | |
249 case 'f': | |
250 if (!p[3]) | |
251 goto Lnoarg; | |
252 global.params.docname = arg[(p - arg.ptr) + 3..$]; | |
253 break; | |
254 | |
255 case 0: | |
256 break; | |
257 | |
258 default: | |
259 goto Lerror; | |
260 } | |
261 } | |
262 ///version (_DH) { | |
263 else if (p[1] == 'H') | |
264 { global.params.doHdrGeneration = 1; | |
265 switch (p[2]) | |
266 { | |
267 case 'd': | |
268 if (!p[3]) | |
269 goto Lnoarg; | |
270 global.params.hdrdir = arg[(p - arg.ptr) + 3..$]; | |
271 break; | |
272 | |
273 case 'f': | |
274 if (!p[3]) | |
275 goto Lnoarg; | |
276 global.params.hdrname = arg[(p - arg.ptr) + 3..$]; | |
277 break; | |
278 | |
279 case 0: | |
280 break; | |
281 | |
282 default: | |
283 goto Lerror; | |
284 } | |
285 } | |
286 ///} | |
287 else if (arg == "ignore") | |
288 global.params.ignoreUnsupportedPragmas = 1; | |
289 else if (arg == "inline") | |
290 global.params.useInline = 1; | |
291 else if (arg == "lib") | |
292 global.params.lib = 1; | |
293 else if (arg == "nofloat") | |
294 global.params.nofloat = 1; | |
295 else if (arg == "quiet") | |
296 global.params.quiet = 1; | |
297 else if (arg == "release") | |
298 global.params.release = 1; | |
299 ///version (DMDV2) { | |
300 else if (arg == "safe") | |
301 global.params.safe = 1; | |
302 ///} | |
303 else if (arg == "unittest") | |
304 global.params.useUnitTests = 1; | |
305 else if (p[1] == 'I') | |
306 { | |
307 if (!global.params.imppath) | |
308 global.params.imppath = new Array(); | |
309 global.params.imppath.push(cast(void*)new String(arg[(p - arg.ptr) + 2..$])); /// | |
310 } | |
311 else if (p[1] == 'J') | |
312 { | |
313 if (!global.params.fileImppath) | |
314 global.params.fileImppath = new Array(); | |
315 global.params.fileImppath.push(cast(void*)new String(arg[(p - arg.ptr) + 2..$])); | |
316 } | |
317 else if (memcmp(p + 1, "debug".ptr, 5) == 0 && p[6] != 'l') | |
318 { | |
319 // Parse: | |
320 // -debug | |
321 // -debug=number | |
322 // -debug=identifier | |
323 if (p[6] == '=') | |
324 { | |
325 if (isdigit(p[7])) | |
326 { long level; | |
327 | |
328 errno = 0; | |
329 level = strtol(p + 7, cast(char**)&p, 10); | |
330 if (*p || errno || level > INT_MAX) | |
331 goto Lerror; | |
332 DebugCondition.setGlobalLevel(cast(int)level); | |
333 } | |
334 else if (Lexer.isValidIdentifier(arg[(p - arg.ptr) + 7..$])) /// | |
335 DebugCondition.addGlobalIdent(p + 7); | |
336 else | |
337 goto Lerror; | |
338 } | |
339 else if (p[6]) | |
340 goto Lerror; | |
341 else | |
342 global.params.debuglevel = 1; | |
343 } | |
344 else if (memcmp(p + 1, "version".ptr, 5) == 0) | |
345 { | |
346 // Parse: | |
347 // -version=number | |
348 // -version=identifier | |
349 if (p[8] == '=') | |
350 { | |
351 if (isdigit(p[9])) | |
352 { long level; | |
353 | |
354 errno = 0; | |
355 level = strtol(p + 9, cast(char**)&p, 10); /// | |
356 if (*p || errno || level > INT_MAX) | |
357 goto Lerror; | |
358 VersionCondition.setGlobalLevel(cast(int)level); | |
359 } | |
360 else if (Lexer.isValidIdentifier(arg[(p - arg.ptr) + 9..$])) /// | |
361 VersionCondition.addGlobalIdent(arg[(p - arg.ptr) + 9..$]); | |
362 else | |
363 goto Lerror; | |
364 } | |
365 else | |
366 goto Lerror; | |
367 } | |
368 else if (arg == "-b") | |
369 global.params.debugb = 1; | |
370 else if (arg == "-c") | |
371 global.params.debugc = 1; | |
372 else if (arg == "-f") | |
373 global.params.debugf = 1; | |
374 else if (arg == "-help") | |
375 { usage(); | |
376 exit(EXIT_SUCCESS); | |
377 } | |
378 else if (arg == "-r") | |
379 global.params.debugr = 1; | |
380 else if (arg == "-x") | |
381 global.params.debugx = 1; | |
382 else if (arg == "-y") | |
383 global.params.debugy = 1; | |
384 else if (p[1] == 'L') | |
385 { | |
386 global.params.linkswitches.push(cast(void*)p + 2); | |
387 } | |
388 else if (memcmp(p + 1, "defaultlib=".ptr, 11) == 0) | |
389 { | |
390 global.params.defaultlibname = p + 1 + 11; | |
391 } | |
392 else if (memcmp(p + 1, "debuglib=".ptr, 9) == 0) | |
393 { | |
394 setdebuglib = 1; | |
395 global.params.debuglibname = p + 1 + 9; | |
396 } | |
397 else if (memcmp(p + 1, "deps=".ptr, 5) == 0) | |
398 { | |
399 global.params.moduleDepsFile = arg[(p - arg.ptr) + 1 + 5..$]; | |
400 if (!global.params.moduleDepsFile[0]) | |
401 goto Lnoarg; | |
402 global.params.moduleDeps = new OutBuffer; | |
403 } | |
404 else if (memcmp(p + 1, "man".ptr, 3) == 0) | |
405 { | |
406 version (_WIN32) { | |
407 version (DMDV1) { | |
408 browse("http://www.digitalmars.com/d/1.0/dmd-windows.html"); | |
409 } else { | |
410 browse("http://www.digitalmars.com/d/2.0/dmd-windows.html"); | |
411 } | |
412 } | |
413 version (linux) { | |
414 version (DMDV1) { | |
415 browse("http://www.digitalmars.com/d/1.0/dmd-linux.html"); | |
416 } else { | |
417 browse("http://www.digitalmars.com/d/2.0/dmd-linux.html"); | |
418 } | |
419 } | |
420 version (__APPLE__) { | |
421 version (DMDV1) { | |
422 browse("http://www.digitalmars.com/d/1.0/dmd-osx.html"); | |
423 } else { | |
424 browse("http://www.digitalmars.com/d/2.0/dmd-osx.html"); | |
425 } | |
426 } | |
427 version (__FreeBSD__) { | |
428 version (DMDV1) { | |
429 browse("http://www.digitalmars.com/d/1.0/dmd-freebsd.html"); | |
430 } else { | |
431 browse("http://www.digitalmars.com/d/2.0/dmd-freebsd.html"); | |
432 } | |
433 } | |
434 exit(EXIT_SUCCESS); | |
435 } | |
436 else if (arg == "run") | |
437 { global.params.run = 1; | |
438 global.params.runargs_length = ((i >= argcstart) ? args.length : argcstart) - i - 1; | |
439 if (global.params.runargs_length) | |
440 { | |
441 files.push(cast(void*)args[i + 1].ptr); | |
442 global.params.runargs = args[i + 2..$]; | |
443 i += global.params.runargs_length; | |
444 global.params.runargs_length--; | |
445 } | |
446 else | |
447 { global.params.run = 0; | |
448 goto Lnoarg; | |
449 } | |
450 } | |
451 else | |
452 { | |
453 Lerror: | |
454 error("unrecognized switch '%s'", args[i]); | |
455 continue; | |
456 | |
457 Lnoarg: | |
458 error("argument expected for switch '%s'", args[i]); | |
459 continue; | |
460 } | |
461 } | |
462 else | |
463 { | |
464 version (TARGET_WINDOS) { | |
465 string ext = FileName.ext(p[0..arg.length]); | |
466 if (ext != null && FileName.compare(ext, "exe") == 0) | |
467 { | |
468 global.params.objname = arg[(p - arg.ptr)..$]; | |
469 continue; | |
470 } | |
471 } | |
472 files.push(cast(void*)new String(arg[(p - arg.ptr)..$])); | |
473 } | |
474 } | |
475 if (global.errors) | |
476 { | |
477 fatal(); | |
478 } | |
479 if (files.dim == 0) | |
480 { usage(); | |
481 return EXIT_FAILURE; | |
482 } | |
483 | |
484 if (!setdebuglib) | |
485 global.params.debuglibname = global.params.defaultlibname; | |
486 | |
487 version (TARGET_OSX) { | |
488 global.params.pic = 1; | |
489 } | |
490 | |
491 if (global.params.release) | |
492 { global.params.useInvariants = 0; | |
493 global.params.useIn = 0; | |
494 global.params.useOut = 0; | |
495 global.params.useAssert = 0; | |
496 global.params.useArrayBounds = 0; | |
497 global.params.useSwitchError = 0; | |
498 } | |
499 | |
500 if (global.params.run) | |
501 global.params.quiet = 1; | |
502 | |
503 if (global.params.useUnitTests) | |
504 global.params.useAssert = 1; | |
505 | |
506 if (!global.params.obj || global.params.lib) | |
507 global.params.link = 0; | |
508 | |
509 if (global.params.link) | |
510 { | |
511 global.params.exefile = global.params.objname; | |
512 global.params.oneobj = 1; | |
513 if (global.params.objname) | |
514 { | |
515 /* Use this to name the one object file with the same | |
516 * name as the exe file. | |
517 */ | |
518 global.params.objname = FileName.forceExt(global.params.objname, global.obj_ext).toChars(); | |
519 | |
520 /* If output directory is given, use that path rather than | |
521 * the exe file path. | |
522 */ | |
523 if (global.params.objdir) | |
524 { | |
525 string name = FileName.name(global.params.objname); | |
526 global.params.objname = FileName.combine(global.params.objdir, name); | |
527 } | |
528 } | |
529 } | |
530 else if (global.params.lib) | |
531 { | |
532 global.params.libname = global.params.objname; | |
533 global.params.objname = null; | |
534 | |
535 // Haven't investigated handling these options with multiobj | |
536 if (!global.params.cov && !global.params.trace) | |
537 global.params.multiobj = 1; | |
538 } | |
539 else if (global.params.run) | |
540 { | |
541 error("flags conflict with -run"); | |
542 fatal(); | |
543 } | |
544 else | |
545 { | |
546 if (global.params.objname && files.dim > 1) | |
547 { | |
548 global.params.oneobj = 1; | |
549 //error("multiple source files, but only one .obj name"); | |
550 //fatal(); | |
551 } | |
552 } | |
553 if (global.params.isX86_64) | |
554 { | |
555 VersionCondition.addPredefinedGlobalIdent("D_InlineAsm_X86_64"); | |
556 VersionCondition.addPredefinedGlobalIdent("X86_64"); | |
557 VersionCondition.addPredefinedGlobalIdent("D_LP64"); | |
558 version (TARGET_WINDOS) { | |
559 VersionCondition.addPredefinedGlobalIdent("Win64"); | |
560 } | |
561 } | |
562 else | |
563 { | |
564 VersionCondition.addPredefinedGlobalIdent("D_InlineAsm"); | |
565 VersionCondition.addPredefinedGlobalIdent("D_InlineAsm_X86"); | |
566 VersionCondition.addPredefinedGlobalIdent("X86"); | |
567 version (TARGET_WINDOS) { | |
568 VersionCondition.addPredefinedGlobalIdent("Win32"); | |
569 } | |
570 } | |
571 if (global.params.doDocComments) | |
572 VersionCondition.addPredefinedGlobalIdent("D_Ddoc"); | |
573 if (global.params.cov) | |
574 VersionCondition.addPredefinedGlobalIdent("D_Coverage"); | |
575 if (global.params.pic) | |
576 VersionCondition.addPredefinedGlobalIdent("D_PIC"); | |
577 version (DMDV2) { | |
578 if (global.params.useUnitTests) | |
579 VersionCondition.addPredefinedGlobalIdent("unittest"); | |
580 } | |
581 | |
582 // Initialization | |
583 Type.init(); | |
584 Id.initialize(); | |
585 Module.init(); | |
586 initPrecedence(); | |
587 | |
588 backend_init(); | |
589 | |
590 //printf("%d source files\n",files.dim); | |
591 | |
592 // Build import search path | |
593 if (global.params.imppath) | |
594 { | |
595 for (int i = 0; i < global.params.imppath.dim; i++) | |
596 { | |
597 string path = (cast(String)global.params.imppath.data[i]).str; | |
598 string[] a = FileName.splitPath(path); | |
599 | |
600 global.path ~= a; | |
601 } | |
602 } | |
603 | |
604 // Build string import search path | |
605 if (global.params.fileImppath) | |
606 { | |
607 for (int i = 0; i < global.params.fileImppath.dim; i++) | |
608 { | |
609 string path = (cast(String)global.params.fileImppath.data[i]).str; | |
610 string[] a = FileName.splitPath(path); | |
611 | |
612 global.filePath ~= a; | |
613 } | |
614 } | |
615 | |
616 // Create Modules | |
617 Array modules = new Array(); | |
618 modules.reserve(files.dim); | |
619 int firstmodule = 1; | |
620 for (int i = 0; i < files.dim; i++) | |
621 { | |
622 string ext; | |
623 string name; | |
624 | |
625 String s = cast(String) files.data[i]; | |
626 string mp = s.str; | |
627 | |
628 version (_WIN32) { | |
629 char[] copy = null; | |
630 // Convert / to \ so linker will work | |
631 foreach (j, c; mp) | |
632 { | |
633 if (c == '/') { | |
634 if (copy is null) copy = mp.dup; | |
635 copy[j] = '\\'; | |
636 } | |
637 } | |
638 | |
639 if (copy !is null) mp = assumeUnique(copy); | |
640 } | |
641 string p = mp; | |
642 | |
643 p = FileName.name(p); // strip path | |
644 ext = FileName.ext(p); | |
645 | |
646 if (ext.length != 0) | |
647 { /* Deduce what to do with a file based on its extension | |
648 */ | |
649 if (FileName.equals(ext, global.obj_ext)) | |
650 { | |
651 global.params.objfiles.push(files.data[i]); | |
652 libmodules.push(files.data[i]); | |
653 continue; | |
654 } | |
655 | |
656 if (FileName.equals(ext, global.lib_ext)) | |
657 { | |
658 global.params.libfiles.push(files.data[i]); | |
659 libmodules.push(files.data[i]); | |
660 continue; | |
661 } | |
662 | |
663 if (ext == global.ddoc_ext) | |
664 { | |
665 global.params.ddocfiles.push(files.data[i]); | |
666 continue; | |
667 } | |
668 | |
669 version (TARGET_WINDOS) { | |
670 if (FileName.equals(ext, "res")) | |
671 { | |
672 global.params.resfile = (cast(immutable(char)*)files.data[i])[0..0]; /// !!! | |
673 continue; | |
674 } | |
675 | |
676 if (FileName.equals(ext, "def")) | |
677 { | |
678 global.params.deffile = (cast(immutable(char)*)files.data[i])[0..0]; | |
679 continue; | |
680 } | |
681 | |
682 if (FileName.equals(ext, "exe")) | |
683 { | |
684 assert(0); // should have already been handled | |
685 } | |
686 } | |
687 | |
688 /* Examine extension to see if it is a valid | |
689 * D source file extension | |
690 */ | |
691 if (FileName.equals(ext, global.mars_ext) || | |
692 FileName.equals(ext, global.hdr_ext) || | |
693 FileName.equals(ext, "dd") || | |
694 FileName.equals(ext, "htm") || | |
695 FileName.equals(ext, "html") || | |
696 FileName.equals(ext, "xhtml")) | |
697 { | |
698 immutable(char)* e = ext.ptr; | |
699 e--; // skip onto '.' | |
700 assert(*e == '.'); | |
701 | |
702 immutable(char)* n = p.ptr; | |
703 | |
704 name = n[0..(e-n)]; // strip extension | |
705 | |
706 if (name.length == 0 || name == ".." || name == ".") | |
707 { | |
708 Linvalid: | |
709 error("invalid file name '%s'", (cast(String)files.data[i]).str); | |
710 fatal(); | |
711 } | |
712 } | |
713 else | |
714 { error("unrecognized file extension %s\n", ext); | |
715 fatal(); | |
716 } | |
717 } | |
718 else | |
719 { | |
720 name = p; | |
721 if (!*name) | |
722 goto Linvalid; | |
723 } | |
724 | |
725 /* At this point, name is the D source file name stripped of | |
726 * its path and extension. | |
727 */ | |
728 | |
729 Identifier id = new Identifier(name, TOK.TOKreserved); | |
730 m = new Module((cast(String) files.data[i]).str, id, global.params.doDocComments, global.params.doHdrGeneration); | |
731 modules.push(cast(void*)m); | |
732 | |
733 if (firstmodule) | |
734 { | |
735 global.params.objfiles.push(cast(void*)m.objfile.name); | |
736 firstmodule = 0; | |
737 } | |
738 } | |
739 | |
740 // Read files | |
741 //version = ASYNCREAD; | |
742 version (ASYNCREAD) { | |
743 // Multi threaded | |
744 AsyncRead *aw = AsyncRead.create(modules.dim); | |
745 for (i = 0; i < modules.dim; i++) | |
746 { | |
747 m = cast(Module *)modules.data[i]; | |
748 aw.addFile(m.srcfile); | |
749 } | |
750 aw.start(); | |
751 } else { | |
752 // Single threaded | |
753 for (int i = 0; i < modules.dim; i++) | |
754 { | |
755 m = cast(Module)modules.data[i]; | |
756 m.read(Loc(0)); | |
757 } | |
758 } | |
759 | |
760 // Parse files | |
761 int anydocfiles = 0; | |
762 for (int i = 0; i < modules.dim; i++) | |
763 { | |
764 m = cast(Module)modules.data[i]; | |
765 if (global.params.verbose) | |
766 writef("parse %s\n", m.toChars()); | |
767 if (!Module.rootModule) | |
768 Module.rootModule = m; | |
769 m.importedFrom = m; | |
770 if (!global.params.oneobj || i == 0 || m.isDocFile) | |
771 m.deleteObjFile(); | |
772 version (ASYNCREAD) { | |
773 if (aw.read(i)) | |
774 { | |
775 error("cannot read file %s", m.srcfile.name.toChars()); | |
776 } | |
777 } | |
778 | |
779 //while (loop) {} | |
780 m.parse(); | |
781 if (m.isDocFile) | |
782 { | |
783 anydocfiles = 1; | |
784 m.gendocfile(); | |
785 | |
786 // Remove m from list of modules | |
787 modules.remove(i); | |
788 i--; | |
789 | |
790 // Remove m's object file from list of object files | |
791 for (int j = 0; j < global.params.objfiles.dim; j++) | |
792 { | |
793 if (m.objfile.name.str == (cast(FileName)global.params.objfiles.data[j]).str) | |
794 { | |
795 global.params.objfiles.remove(j); | |
796 break; | |
797 } | |
798 } | |
799 | |
800 if (global.params.objfiles.dim == 0) | |
801 global.params.link = 0; | |
802 } | |
803 } | |
804 version (ASYNCREAD) { | |
805 AsyncRead.dispose(aw); | |
806 } | |
807 | |
808 if (anydocfiles && modules.dim && | |
809 (global.params.oneobj || global.params.objname)) | |
810 { | |
811 error("conflicting Ddoc and obj generation options"); | |
812 fatal(); | |
813 } | |
814 if (global.errors) | |
815 fatal(); | |
816 version (_DH) { | |
817 if (global.params.doHdrGeneration) | |
818 { | |
819 /* Generate 'header' import files. | |
820 * Since 'header' import files must be independent of command | |
821 * line switches and what else is imported, they are generated | |
822 * before any semantic analysis. | |
823 */ | |
824 for (i = 0; i < modules.dim; i++) | |
825 { | |
826 m = cast(Module *)modules.data[i]; | |
827 if (global.params.verbose) | |
828 writef("import %s\n", m.toChars()); | |
829 m.genhdrfile(); | |
830 } | |
831 } | |
832 if (global.errors) | |
833 fatal(); | |
834 } | |
835 | |
836 // Do semantic analysis | |
837 for (int i = 0; i < modules.dim; i++) | |
838 { | |
839 m = cast(Module)modules.data[i]; | |
840 if (global.params.verbose) | |
841 writef("semantic %s\n", m.toChars()); | |
842 m.semantic(); | |
843 } | |
844 if (global.errors) | |
845 fatal(); | |
846 | |
847 // Do pass 2 semantic analysis | |
848 for (int i = 0; i < modules.dim; i++) | |
849 { | |
850 m = cast(Module)modules.data[i]; | |
851 if (global.params.verbose) | |
852 writef("semantic2 %s\n", m.toChars()); | |
853 m.semantic2(); | |
854 } | |
855 if (global.errors) | |
856 fatal(); | |
857 | |
858 // Do pass 3 semantic analysis | |
859 for (int i = 0; i < modules.dim; i++) | |
860 { | |
861 m = cast(Module)modules.data[i]; | |
862 if (global.params.verbose) | |
863 writef("semantic3 %s\n", m.toChars()); | |
864 m.semantic3(); | |
865 } | |
866 if (global.errors) | |
867 fatal(); | |
868 | |
869 if (global.params.moduleDeps !is null) | |
870 { | |
871 assert(global.params.moduleDepsFile !is null); | |
872 | |
873 File deps = new File(global.params.moduleDepsFile); | |
874 OutBuffer ob = global.params.moduleDeps; | |
875 deps.setbuffer(cast(void*)ob.data, ob.offset); | |
876 deps.writev(); | |
877 } | |
878 | |
879 | |
880 // Scan for functions to inline | |
881 if (global.params.useInline) | |
882 { | |
883 /* The problem with useArrayBounds and useAssert is that the | |
884 * module being linked to may not have generated them, so if | |
885 * we inline functions from those modules, the symbols for them will | |
886 * not be found at link time. | |
887 */ | |
888 if (!global.params.useArrayBounds && !global.params.useAssert) | |
889 { | |
890 // Do pass 3 semantic analysis on all imported modules, | |
891 // since otherwise functions in them cannot be inlined | |
892 for (int i = 0; i < Module.amodules.dim; i++) | |
893 { | |
894 m = cast(Module)Module.amodules.data[i]; | |
895 if (global.params.verbose) | |
896 writef("semantic3 %s\n", m.toChars()); | |
897 m.semantic3(); | |
898 } | |
899 if (global.errors) | |
900 fatal(); | |
901 } | |
902 | |
903 for (int i = 0; i < modules.dim; i++) | |
904 { | |
905 m = cast(Module)modules.data[i]; | |
906 if (global.params.verbose) | |
907 writef("inline scan %s\n", m.toChars()); | |
908 | |
909 m.inlineScan(); | |
910 } | |
911 } | |
912 if (global.errors) | |
913 fatal(); | |
914 | |
915 Library library = null; | |
916 if (global.params.lib) | |
917 { | |
918 library = new Library(); | |
919 library.setFilename(global.params.objdir, global.params.libname); | |
920 | |
921 // Add input object and input library files to output library | |
922 for (int i = 0; i < libmodules.dim; i++) | |
923 { | |
924 string p = (cast(String)libmodules.data[i]).str; | |
925 library.addObject(p, null, 0); | |
926 } | |
927 } | |
928 | |
929 // Generate output files | |
930 if (global.params.oneobj) | |
931 { | |
932 for (int i = 0; i < modules.dim; i++) | |
933 { | |
934 m = cast(Module)modules.data[i]; | |
935 if (global.params.verbose) | |
936 writef("code %s\n", m.toChars()); | |
937 if (i == 0) | |
938 obj_start(cast(char*)toStringz(m.srcfile.toChars())); | |
939 m.genobjfile(0); | |
940 if (!global.errors && global.params.doDocComments) | |
941 m.gendocfile(); | |
942 } | |
943 if (!global.errors && modules.dim) | |
944 { | |
945 obj_end(library, (cast(Module)modules.data[0]).objfile); | |
946 } | |
947 } | |
948 else | |
949 { | |
950 for (int i = 0; i < modules.dim; i++) | |
951 { | |
952 m = cast(Module)modules.data[i]; | |
953 if (global.params.verbose) | |
954 writef("code %s\n", m.toChars()); | |
955 if (global.params.obj) | |
956 { | |
957 obj_start(cast(char*)toStringz(m.srcfile.toChars())); | |
958 m.genobjfile(global.params.multiobj); | |
959 obj_end(library, m.objfile); | |
960 obj_write_deferred(library); | |
961 } | |
962 if (global.errors) | |
963 { | |
964 if (!global.params.lib) | |
965 m.deleteObjFile(); | |
966 } | |
967 else | |
968 { | |
969 if (global.params.doDocComments) | |
970 m.gendocfile(); | |
971 } | |
972 } | |
973 } | |
974 | |
975 if (global.params.lib && !global.errors) | |
976 library.write(); | |
977 | |
978 backend_term(); | |
979 if (global.errors) | |
980 fatal(); | |
981 | |
982 if (!global.params.objfiles.dim) | |
983 { | |
984 if (global.params.link) | |
985 error("no object files to link"); | |
986 } | |
987 else | |
988 { | |
989 if (global.params.link) | |
990 status = runLINK(); | |
991 | |
992 if (global.params.run) | |
993 { | |
994 if (!status) | |
995 { | |
996 status = runProgram(); | |
997 | |
998 /* Delete .obj files and .exe file | |
999 */ | |
1000 for (int i = 0; i < modules.dim; i++) | |
1001 { | |
1002 m = cast(Module)modules.data[i]; | |
1003 m.deleteObjFile(); | |
1004 if (global.params.oneobj) | |
1005 break; | |
1006 } | |
1007 deleteExeFile(); | |
1008 } | |
1009 } | |
1010 } | |
1011 | |
1012 return status; | |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
1013 } |