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