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