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