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