Mercurial > projects > ldc
annotate dmd/mars.c @ 777:961e249eb2aa
Include x86-32 fiber fixes in tango patch again.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 22 Nov 2008 13:41:36 +0100 |
parents | 4ac97ec7c18e |
children | ac39e5449ca5 |
rev | line source |
---|---|
159 | 1 // Compiler implementation of the D programming language |
2 // Copyright (c) 1999-2008 by Digital Mars | |
3 // All Rights Reserved | |
4 // written by Walter Bright | |
5 // http://www.digitalmars.com | |
6 // License for redistribution is by either the Artistic License | |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
8 // See the included readme.txt for details. | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <ctype.h> | |
13 #include <assert.h> | |
14 #include <limits.h> | |
15 #include <string> | |
16 #include <cstdarg> | |
17 | |
18 #if __DMC__ | |
19 #include <dos.h> | |
20 #endif | |
21 | |
571
cbd6c8073a32
Changed all '#if linux || __APPLE__' to '#if POSIX' so we can support other platforms too, thanx for the suggestion anders.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
568
diff
changeset
|
22 #if POSIX |
159 | 23 #include <errno.h> |
432 | 24 #elif _WIN32 |
25 #include <windows.h> | |
159 | 26 #endif |
27 | |
28 #include "mem.h" | |
29 #include "root.h" | |
30 | |
31 #include "mars.h" | |
32 #include "module.h" | |
33 #include "mtype.h" | |
34 #include "id.h" | |
35 #include "cond.h" | |
36 #include "expression.h" | |
37 #include "lexer.h" | |
38 | |
39 #include "gen/logger.h" | |
277
90a8c798b0db
[svn r298] Eliminated the dmd/link.c source file entirely in favor of a llvm::sys based approach to the same functionality.
lindquist
parents:
276
diff
changeset
|
40 #include "gen/linker.h" |
159 | 41 |
42 void getenv_setargv(const char *envvar, int *pargc, char** *pargv); | |
43 | |
44 Global global; | |
45 | |
46 Global::Global() | |
47 { | |
48 mars_ext = "d"; | |
49 sym_ext = "d"; | |
50 hdr_ext = "di"; | |
51 doc_ext = "html"; | |
52 ddoc_ext = "ddoc"; | |
53 | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
54 // LDC |
159 | 55 ll_ext = "ll"; |
56 bc_ext = "bc"; | |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
57 s_ext = "s"; |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
58 obj_ext = "o"; |
374
1f20b9f7de1b
Fix nativeobj extension for Windows.
Christian Kamm <kamm incasoftware de>
parents:
366
diff
changeset
|
59 #if _WIN32 |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
60 obj_ext_alt = "obj"; |
159 | 61 #endif |
62 | |
63 copyright = "Copyright (c) 1999-2008 by Digital Mars and Tomas Lindquist Olsen"; | |
64 written = "written by Walter Bright and Tomas Lindquist Olsen"; | |
717
a26b0c5d5942
Merged DMD 1.036.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
713
diff
changeset
|
65 version = "v1.036"; |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
66 ldc_version = "0.1"; |
159 | 67 global.structalign = 8; |
68 | |
69 memset(¶ms, 0, sizeof(Param)); | |
70 } | |
71 | |
72 char *Loc::toChars() const | |
73 { | |
74 OutBuffer buf; | |
75 char *p; | |
76 | |
77 if (filename) | |
78 { | |
79 buf.printf("%s", filename); | |
80 } | |
81 | |
82 if (linnum) | |
83 buf.printf("(%d)", linnum); | |
84 buf.writeByte(0); | |
85 return (char *)buf.extractData(); | |
86 } | |
87 | |
88 Loc::Loc(Module *mod, unsigned linnum) | |
89 { | |
90 this->linnum = linnum; | |
91 this->filename = mod ? mod->srcfile->toChars() : NULL; | |
92 } | |
93 | |
94 /************************************** | |
95 * Print error message and exit. | |
96 */ | |
97 | |
98 void error(Loc loc, const char *format, ...) | |
99 { | |
100 va_list ap; | |
101 va_start(ap, format); | |
102 verror(loc, format, ap); | |
103 va_end( ap ); | |
104 } | |
105 | |
106 void verror(Loc loc, const char *format, va_list ap) | |
107 { | |
108 if (!global.gag) | |
109 { | |
110 char *p = loc.toChars(); | |
111 | |
112 if (*p) | |
113 fprintf(stdmsg, "%s: ", p); | |
114 mem.free(p); | |
115 | |
116 fprintf(stdmsg, "Error: "); | |
117 vfprintf(stdmsg, format, ap); | |
118 fprintf(stdmsg, "\n"); | |
119 fflush(stdmsg); | |
120 } | |
121 global.errors++; | |
122 } | |
123 | |
124 /*************************************** | |
125 * Call this after printing out fatal error messages to clean up and exit | |
126 * the compiler. | |
127 */ | |
128 | |
129 void fatal() | |
130 { | |
131 #if 0 | |
132 halt(); | |
133 #endif | |
134 exit(EXIT_FAILURE); | |
135 } | |
136 | |
137 /************************************** | |
138 * Try to stop forgetting to remove the breakpoints from | |
139 * release builds. | |
140 */ | |
141 void halt() | |
142 { | |
143 #ifdef DEBUG | |
144 *(char*)0=0; | |
145 #endif | |
146 } | |
147 | |
148 extern void backend_init(); | |
149 extern void backend_term(); | |
150 | |
151 void usage() | |
152 { | |
546
406aee3416bb
Removed D_InlineAsm and D_InlineAsm_X86 versions.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
542
diff
changeset
|
153 printf("LLVM D Compiler %s (based on DMD %s and LLVM 2.4svn)\n%s\n%s\n", |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
154 global.ldc_version, global.version, global.copyright, global.written); |
159 | 155 printf("\ |
156 D Language Documentation: http://www.digitalmars.com/d/1.0/index.html\n\ | |
690 | 157 LDC Homepage: http://www.dsource.org/projects/ldc\n\ |
159 | 158 Usage:\n\ |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
159 ldc files.d ... { -switch }\n\ |
159 | 160 \n\ |
161 files.d D source files\n%s\ | |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
162 -o- do not write object file\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
163 -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
|
164 -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
|
165 -oq write object files with fully qualified names\n\ |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
166 -of<filename> name output file to <filename>\n\ |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
167 if -c and extension of <filename> is known, it determines the output type\n\ |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
168 \n\ |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
169 -output-ll write LLVM IR\n\ |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
170 -output-bc write LLVM bitcode\n\ |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
171 -output-s write native assembly\n\ |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
172 -output-o write native object (default if no -output switch passed)\n\ |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
173 \n\ |
159 | 174 -c do not link\n\ |
695
a51fed3de34e
Some cleanups in command line argument descriptions.
Christian Kamm <kamm incasoftware de>
parents:
694
diff
changeset
|
175 -L<linkerflag> pass <linkerflag> to linker\n\ |
547
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 -w enable warnings\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
178 \n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
179 -H generate 'header' file\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
180 -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
|
181 -Hf<filename> write 'header' file to <filename>\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
182 \n\ |
159 | 183 -D generate documentation\n\ |
184 -Dd<docdir> write documentation file to <docdir> directory\n\ | |
185 -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
|
186 \n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
187 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
|
188 -m<arch> emit code specific to <arch> being one of:\n\ |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
189 x86 x86-64 ppc32 ppc64 arm thumb\n\ |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
190 -t<os> emit code specific to <os> being one of:\n\ |
638
94b01f15814f
Added FreeBSD support to the -t switch
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
637
diff
changeset
|
191 Linux, Windows, MacOSX, FreeBSD\n\ |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
192 \n\ |
695
a51fed3de34e
Some cleanups in command line argument descriptions.
Christian Kamm <kamm incasoftware de>
parents:
694
diff
changeset
|
193 -g, -gc add symbolic debug info\n\ |
a51fed3de34e
Some cleanups in command line argument descriptions.
Christian Kamm <kamm incasoftware de>
parents:
694
diff
changeset
|
194 \n\ |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
195 -O optimize, same as -O2\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
196 -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
|
197 -inline do function inlining\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
198 \n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
199 -debug enables asserts, invariants, contracts, boundscheck\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
200 and sets debug=1\n\ |
695
a51fed3de34e
Some cleanups in command line argument descriptions.
Christian Kamm <kamm incasoftware de>
parents:
694
diff
changeset
|
201 -release disables asserts, invariants, contracts, boundscheck\n\ |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
202 \n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
203 -enable-<feature> and\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
204 -disable-<feature> where <feature> is one of\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
205 asserts assert statements (default: on)\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
206 invariants class and struct invariants (default: on)\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
207 contracts function contracts (default: on)\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
208 boundscheck array bounds checking (default: on)\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
209 -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
|
210 -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
|
211 -version=level compile in version code >= level\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
212 -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
|
213 \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
|
214 -noasm do not allow use of inline asm\n\ |
159 | 215 -noruntime do not allow code that generates implicit runtime calls\n\ |
216 -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
|
217 -unittest compile in unit tests\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
218 -d allow deprecated features\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
219 \n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
220 -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
|
221 -ignore ignore unsupported pragmas\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
222 \n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
223 Path options:\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
224 -I<path> where to look for imports\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
225 -J<path> where to look for string imports\n\ |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
226 -defaultlib=name set default library for non-debug build\n\ |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
227 -debuglib=name set default library for debug build\n\ |
651
5709381df7e8
Added -nodefaultlib switch do disable implicitly linked standard lib modules
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
638
diff
changeset
|
228 -nodefaultlib don't add a default library for linking implicitly\n\ |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
229 \n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
230 Misc options:\n\ |
159 | 231 -v verbose\n\ |
232 -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
|
233 -quiet suppress unnecessary messages\n\ |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
234 -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
|
235 --help print help\n\ |
159 | 236 ", |
237 #if WIN32 | |
238 " @cmdfile read arguments from cmdfile\n" | |
239 #else | |
240 "" | |
241 #endif | |
242 ); | |
243 } | |
244 | |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
245 int main(int argc, char *argv[], char** envp) |
159 | 246 { |
247 int i; | |
248 Array files; | |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
249 char *p, *ext; |
159 | 250 Module *m; |
251 int status = EXIT_SUCCESS; | |
252 int argcstart = argc; | |
253 bool very_verbose = false; | |
254 | |
255 // Check for malformed input | |
256 if (argc < 1 || !argv) | |
257 { | |
258 Largs: | |
259 error("missing or null command line arguments"); | |
260 fatal(); | |
261 } | |
262 for (i = 0; i < argc; i++) | |
263 { | |
264 if (!argv[i]) | |
265 goto Largs; | |
266 } | |
267 | |
268 #if __DMC__ // DMC unique support for response files | |
269 if (response_expand(&argc,&argv)) // expand response files | |
270 error("can't open response file"); | |
271 #endif | |
272 | |
273 files.reserve(argc - 1); | |
274 | |
275 // Set default values | |
432 | 276 #if _WIN32 |
277 char buf[MAX_PATH]; | |
278 GetModuleFileName(NULL, buf, MAX_PATH); | |
279 global.params.argv0 = buf; | |
280 #else | |
159 | 281 global.params.argv0 = argv[0]; |
432 | 282 #endif |
159 | 283 global.params.link = 1; |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
510
diff
changeset
|
284 global.params.useAssert = 1; |
327
781af50846b2
[svn r348] Switch on class invariants (except in release mode).
ChristianK
parents:
323
diff
changeset
|
285 global.params.useInvariants = 1; |
159 | 286 global.params.useIn = 1; |
287 global.params.useOut = 1; | |
439
47b64d06eb9f
Enable array bounds check and emit them in IndexExp.
Christian Kamm <kamm incasoftware de>
parents:
432
diff
changeset
|
288 global.params.useArrayBounds = 1; |
331
04e1b4930975
[svn r352] Implement SwitchErrorStatement. Fixes #52.
ChristianK
parents:
327
diff
changeset
|
289 global.params.useSwitchError = 1; |
159 | 290 global.params.useInline = 0; // this one messes things up to a point where codegen breaks |
291 global.params.llvmInline = 0; // use this one instead to know if inline passes should be run | |
292 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
|
293 global.params.Dversion = 2; |
159 | 294 global.params.quiet = 1; |
295 | |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
296 global.params.output_o = OUTPUTFLAGdefault; |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
297 |
159 | 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 // Predefine version identifiers | |
325 #if IN_LLVM | |
326 VersionCondition::addPredefinedGlobalIdent("LLVM"); | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
327 VersionCondition::addPredefinedGlobalIdent("LDC"); |
159 | 328 #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
|
329 |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
330 // setup default target os to be build os |
159 | 331 #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
|
332 global.params.os = OSWindows; |
159 | 333 #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
|
334 global.params.os = OSLinux; |
541
4b7925bc1605
Fixed some osx mistakes.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
536
diff
changeset
|
335 #elif __APPLE__ |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
336 global.params.os = OSMacOSX; |
637
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
337 #elif __FreeBSD__ |
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
338 global.params.os = OSFreeBSD; |
159 | 339 #else |
637
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
340 #error Unsupported OS |
159 | 341 #endif /* linux */ |
342 | |
566
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
343 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
|
344 |
159 | 345 //VersionCondition::addPredefinedGlobalIdent("D_Bits"); |
346 VersionCondition::addPredefinedGlobalIdent("all"); | |
347 | |
348 #if _WIN32 | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
349 inifile(global.params.argv0, "ldc.ini"); |
571
cbd6c8073a32
Changed all '#if linux || __APPLE__' to '#if POSIX' so we can support other platforms too, thanx for the suggestion anders.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
568
diff
changeset
|
350 #elif POSIX |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
351 inifile(global.params.argv0, "ldc.conf"); |
159 | 352 #else |
353 #error | |
354 #endif | |
355 getenv_setargv("DFLAGS", &argc, &argv); | |
356 | |
357 #if 0 | |
358 for (i = 0; i < argc; i++) | |
359 { | |
360 printf("argv[%d] = '%s'\n", i, argv[i]); | |
361 } | |
362 #endif | |
363 | |
364 for (i = 1; i < argc; i++) | |
365 { | |
366 p = argv[i]; | |
367 if (*p == '-') | |
368 { | |
369 if (strcmp(p + 1, "d") == 0) | |
370 global.params.useDeprecated = 1; | |
371 else if (strcmp(p + 1, "c") == 0) | |
372 global.params.link = 0; | |
373 else if (strcmp(p + 1, "fPIC") == 0) | |
374 global.params.pic = 1; | |
695
a51fed3de34e
Some cleanups in command line argument descriptions.
Christian Kamm <kamm incasoftware de>
parents:
694
diff
changeset
|
375 else if (strcmp(p + 1, "g") == 0 || strcmp(p + 1, "gc") == 0) |
159 | 376 global.params.symdebug = 1; |
377 else if (strcmp(p + 1, "v") == 0) | |
378 global.params.verbose = 1; | |
379 else if (strcmp(p + 1, "vv") == 0) { | |
380 Logger::enable(); | |
381 very_verbose = true; | |
382 } | |
383 else if (strcmp(p + 1, "v1") == 0) | |
384 global.params.Dversion = 1; | |
385 else if (strcmp(p + 1, "w") == 0) | |
386 global.params.warnings = 1; | |
387 else if (p[1] == 'O') | |
388 { | |
389 global.params.optimize = 1; | |
390 global.params.optimizeLevel = 2; | |
391 if (p[2] != 0) { | |
392 int optlevel = atoi(p+2); | |
393 if (optlevel < 0 || optlevel > 5) { | |
394 error("Optimization level must be between 0 and 5. Using default (%d)", | |
395 global.params.optimizeLevel); | |
396 } | |
397 else { | |
398 global.params.optimizeLevel = optlevel; | |
399 } | |
400 } | |
401 } | |
402 else if (strcmp(p + 1, "forcebe") == 0) | |
403 global.params.forceBE = 1; | |
404 else if (strcmp(p + 1, "noruntime") == 0) | |
405 global.params.noruntime = 1; | |
406 else if (strcmp(p + 1, "noverify") == 0) | |
407 global.params.novalidate = 1; | |
408 else if (strcmp(p + 1, "annotate") == 0) | |
409 global.params.llvmAnnotate = 1; | |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
410 else if (strncmp(p + 1, "enable-", 7) == 0 || |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
411 strncmp(p + 1, "disable-", 8) == 0) |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
412 { |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
413 bool enable = (p[1] == 'e'); |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
414 char* feature = p + 1 + (enable ? 7 : 8); |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
415 if (strcmp(feature, "asserts") == 0) |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
416 global.params.useAssert = enable; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
417 else if (strcmp(feature, "boundscheck") == 0) |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
418 global.params.useArrayBounds = enable; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
419 else if (strcmp(feature, "contracts") == 0) |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
420 { |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
421 global.params.useIn = enable; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
422 global.params.useOut = enable; |
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 else if (strcmp(feature, "invariants") == 0) |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
425 global.params.useInvariants = enable; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
426 else |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
427 error("unrecognized feature '%s'", feature); |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
428 } |
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
|
429 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
|
430 global.params.useInlineAsm = 0; |
651
5709381df7e8
Added -nodefaultlib switch do disable implicitly linked standard lib modules
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
638
diff
changeset
|
431 else if (strcmp(p + 1, "nodefaultlib") == 0) |
5709381df7e8
Added -nodefaultlib switch do disable implicitly linked standard lib modules
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
638
diff
changeset
|
432 global.params.noDefaultLib = 1; |
159 | 433 else if (p[1] == 'o') |
434 { | |
435 switch (p[2]) | |
436 { | |
437 case '-': | |
438 global.params.obj = 0; | |
439 break; | |
440 | |
441 case 'd': | |
442 if (!p[3]) | |
443 goto Lnoarg; | |
444 global.params.objdir = p + 3; | |
445 break; | |
446 | |
447 case 'f': | |
448 if (!p[3]) | |
449 goto Lnoarg; | |
450 global.params.objname = p + 3; | |
451 break; | |
452 | |
453 case 'p': | |
454 if (p[3]) | |
455 goto Lerror; | |
456 global.params.preservePaths = 1; | |
457 break; | |
458 | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
459 case 'q': |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
460 if (p[3]) |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
461 goto Lerror; |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
462 global.params.fqnNames = 1; |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
463 break; |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
205
diff
changeset
|
464 |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
465 case 'u': |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
466 if (strncmp(p+1, "output-", 7) != 0) |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
467 goto Lerror; |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
468 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
469 // remove default output |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
470 if (global.params.output_o == OUTPUTFLAGdefault) |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
471 global.params.output_o = OUTPUTFLAGno; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
472 |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
473 if (strcmp(p+8, global.ll_ext) == 0) |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
474 global.params.output_ll = OUTPUTFLAGset; |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
475 else if (strcmp(p+8, global.bc_ext) == 0) |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
476 global.params.output_bc = OUTPUTFLAGset; |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
477 else if (strcmp(p+8, global.s_ext) == 0) |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
478 global.params.output_s = OUTPUTFLAGset; |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
479 else if (strcmp(p+8, global.obj_ext) == 0) |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
480 global.params.output_o = OUTPUTFLAGset; |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
481 else |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
482 goto Lerror; |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
483 |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
484 break; |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
485 |
159 | 486 case 0: |
487 error("-o no longer supported, use -of or -od"); | |
488 break; | |
489 | |
490 default: | |
491 goto Lerror; | |
492 } | |
493 } | |
494 else if (p[1] == 'D') | |
495 { global.params.doDocComments = 1; | |
496 switch (p[2]) | |
497 { | |
498 case 'd': | |
499 if (!p[3]) | |
500 goto Lnoarg; | |
501 global.params.docdir = p + 3; | |
502 break; | |
503 case 'f': | |
504 if (!p[3]) | |
505 goto Lnoarg; | |
506 global.params.docname = p + 3; | |
507 break; | |
508 | |
509 case 0: | |
510 break; | |
511 | |
512 default: | |
513 goto Lerror; | |
514 } | |
515 } | |
516 #ifdef _DH | |
517 else if (p[1] == 'H') | |
518 { global.params.doHdrGeneration = 1; | |
519 switch (p[2]) | |
520 { | |
521 case 'd': | |
522 if (!p[3]) | |
523 goto Lnoarg; | |
524 global.params.hdrdir = p + 3; | |
525 break; | |
526 | |
527 case 'f': | |
528 if (!p[3]) | |
529 goto Lnoarg; | |
530 global.params.hdrname = p + 3; | |
531 break; | |
532 | |
533 case 0: | |
534 break; | |
535 | |
536 default: | |
537 goto Lerror; | |
538 } | |
539 } | |
540 #endif | |
541 else if (strcmp(p + 1, "ignore") == 0) | |
542 global.params.ignoreUnsupportedPragmas = 1; | |
543 else if (strcmp(p + 1, "inline") == 0) { | |
544 // TODO | |
545 // the ast rewrites dmd does for inlining messes up the ast. | |
546 // someday maybe we can support it, for now llvm does an excellent job at inlining | |
547 global.params.useInline = 0; //1 | |
548 global.params.llvmInline = 1; | |
549 } | |
550 else if (strcmp(p + 1, "quiet") == 0) | |
551 global.params.quiet = 1; | |
552 else if (strcmp(p + 1, "release") == 0) | |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
553 { |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
554 global.params.useInvariants = 0; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
555 global.params.useIn = 0; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
556 global.params.useOut = 0; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
557 global.params.useAssert = 0; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
558 global.params.useArrayBounds = 0; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
559 } |
159 | 560 else if (strcmp(p + 1, "unittest") == 0) |
561 global.params.useUnitTests = 1; | |
562 else if (p[1] == 'I') | |
563 { | |
564 if (!global.params.imppath) | |
565 global.params.imppath = new Array(); | |
566 global.params.imppath->push(p + 2); | |
567 } | |
568 else if (p[1] == 'J') | |
569 { | |
570 if (!global.params.fileImppath) | |
571 global.params.fileImppath = new Array(); | |
572 global.params.fileImppath->push(p + 2); | |
573 } | |
574 else if (memcmp(p + 1, "debug", 5) == 0 && p[6] != 'l') | |
575 { | |
576 // Parse: | |
577 // -debug | |
578 // -debug=number | |
579 // -debug=identifier | |
580 if (p[6] == '=') | |
581 { | |
582 if (isdigit(p[7])) | |
583 { long level; | |
584 | |
585 errno = 0; | |
586 level = strtol(p + 7, &p, 10); | |
587 if (*p || errno || level > INT_MAX) | |
588 goto Lerror; | |
589 DebugCondition::setGlobalLevel((int)level); | |
590 } | |
591 else if (Lexer::isValidIdentifier(p + 7)) | |
592 DebugCondition::addGlobalIdent(p + 7); | |
593 else | |
594 goto Lerror; | |
595 } | |
596 else if (p[6]) | |
597 goto Lerror; | |
598 else | |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
599 { |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
600 global.params.useInvariants = 1; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
601 global.params.useIn = 1; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
602 global.params.useOut = 1; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
603 global.params.useAssert = 1; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
604 global.params.useArrayBounds = 1; |
159 | 605 global.params.debuglevel = 1; |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
606 } |
159 | 607 } |
608 else if (memcmp(p + 1, "version", 5) == 0) | |
609 { | |
610 // Parse: | |
611 // -version=number | |
612 // -version=identifier | |
613 if (p[8] == '=') | |
614 { | |
615 if (isdigit(p[9])) | |
616 { long level; | |
617 | |
618 errno = 0; | |
619 level = strtol(p + 9, &p, 10); | |
620 if (*p || errno || level > INT_MAX) | |
621 goto Lerror; | |
622 VersionCondition::setGlobalLevel((int)level); | |
623 } | |
624 else if (Lexer::isValidIdentifier(p + 9)) | |
625 VersionCondition::addGlobalIdent(p + 9); | |
626 else | |
627 goto Lerror; | |
628 } | |
629 else | |
630 goto Lerror; | |
631 } | |
632 else if (strcmp(p + 1, "-b") == 0) | |
633 global.params.debugb = 1; | |
634 else if (strcmp(p + 1, "-c") == 0) | |
635 global.params.debugc = 1; | |
636 else if (strcmp(p + 1, "-f") == 0) | |
637 global.params.debugf = 1; | |
638 else if (strcmp(p + 1, "-help") == 0) | |
639 { usage(); | |
640 exit(EXIT_SUCCESS); | |
641 } | |
642 else if (strcmp(p + 1, "-r") == 0) | |
643 global.params.debugr = 1; | |
644 else if (strcmp(p + 1, "-x") == 0) | |
645 global.params.debugx = 1; | |
646 else if (strcmp(p + 1, "-y") == 0) | |
647 global.params.debugy = 1; | |
648 else if (p[1] == 'L') | |
649 { | |
650 global.params.linkswitches->push(p + 2); | |
651 } | |
652 else if (memcmp(p + 1, "defaultlib=", 11) == 0) | |
653 { | |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
654 if(!global.params.defaultlibnames) |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
655 global.params.defaultlibnames = new Array(); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
656 global.params.defaultlibnames->push(p + 1 + 11); |
159 | 657 } |
658 else if (memcmp(p + 1, "debuglib=", 9) == 0) | |
659 { | |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
660 if(!global.params.debuglibnames) |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
661 global.params.debuglibnames = new Array(); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
662 global.params.debuglibnames->push(p + 1 + 9); |
159 | 663 } |
664 else if (strcmp(p + 1, "run") == 0) | |
665 { global.params.run = 1; | |
666 global.params.runargs_length = ((i >= argcstart) ? argc : argcstart) - i - 1; | |
667 if (global.params.runargs_length) | |
668 { | |
669 files.push(argv[i + 1]); | |
670 global.params.runargs = &argv[i + 2]; | |
671 i += global.params.runargs_length; | |
672 global.params.runargs_length--; | |
673 } | |
674 else | |
675 { global.params.run = 0; | |
676 goto Lnoarg; | |
677 } | |
678 } | |
679 else if (p[1] == 'm') | |
680 { | |
681 global.params.llvmArch = p+2; | |
682 } | |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
683 else if (p[1] == 't') |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
684 { |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
685 if(strcmp(p + 2, "Linux") == 0) |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
686 global.params.os = OSLinux; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
687 else if(strcmp(p + 2, "Windows") == 0) |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
688 global.params.os = OSWindows; |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
689 else if(strcmp(p + 2, "MacOSX") == 0) |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
690 global.params.os = OSMacOSX; |
638
94b01f15814f
Added FreeBSD support to the -t switch
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
637
diff
changeset
|
691 else if(strcmp(p + 2, "FreeBSD") == 0) |
94b01f15814f
Added FreeBSD support to the -t switch
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
637
diff
changeset
|
692 global.params.os = OSFreeBSD; |
547
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
693 else |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
694 error("unrecognized target os '%s'", p + 2); |
b0005772a88e
Add -enable/-disable for specific features.
Christian Kamm <kamm incasoftware de>
parents:
546
diff
changeset
|
695 } |
159 | 696 else |
697 { | |
698 Lerror: | |
699 error("unrecognized switch '%s'", argv[i]); | |
700 continue; | |
701 | |
702 Lnoarg: | |
703 error("argument expected for switch '%s'", argv[i]); | |
704 continue; | |
705 } | |
706 } | |
707 else | |
708 files.push(p); | |
709 } | |
710 if (global.errors) | |
711 { | |
712 fatal(); | |
713 } | |
714 if (files.dim == 0) | |
715 { usage(); | |
716 return EXIT_FAILURE; | |
717 } | |
718 | |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
719 Array* libs; |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
720 if (global.params.symdebug) |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
721 libs = global.params.debuglibnames; |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
722 else |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
723 libs = global.params.defaultlibnames; |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
724 |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
725 if (libs) |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
726 { |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
727 for (int i = 0; i < libs->dim; i++) |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
728 { |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
729 char *arg = (char *)mem.malloc(64); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
730 strcpy(arg, "-l"); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
731 strncat(arg, (char *)libs->data[i], 64); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
732 global.params.linkswitches->push(arg); |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
733 } |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
734 } |
651
5709381df7e8
Added -nodefaultlib switch do disable implicitly linked standard lib modules
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
638
diff
changeset
|
735 else if (!global.params.noDefaultLib) |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
736 { |
569
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
737 char *arg; |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
738 arg = (char *)mem.malloc(64); |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
739 strcpy(arg, "-lldc-runtime"); |
569
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
740 global.params.linkswitches->push(arg); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
741 arg = (char *)mem.malloc(64); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
742 strcpy(arg, "-ltango-cc-tango"); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
743 global.params.linkswitches->push(arg); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
744 arg = (char *)mem.malloc(64); |
926a03711ca8
Split runtime into three parts again.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
745 strcpy(arg, "-ltango-gc-basic"); |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
746 global.params.linkswitches->push(arg); |
679
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
747 // pass the runtime again to resolve issues |
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
748 // with linking order |
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
749 arg = (char *)mem.malloc(64); |
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
750 strcpy(arg, "-lldc-runtime"); |
dc078dd8d2e1
Fix remaining make files. Fix linking order for static libs.
Christian Kamm <kamm incasoftware de>
parents:
677
diff
changeset
|
751 global.params.linkswitches->push(arg); |
567
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
752 } |
aaba4f7c6d8a
Get rid of runtime path. Allow defaultlib and debuglib switches to be given multiple times.
Christian Kamm <kamm incasoftware de>
parents:
550
diff
changeset
|
753 |
159 | 754 if (global.params.run) |
755 global.params.quiet = 1; | |
756 | |
757 if (global.params.useUnitTests) | |
758 global.params.useAssert = 1; | |
759 | |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
760 // LDC output determination |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
761 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
762 // if we don't link, autodetect target from extension |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
763 if(!global.params.link && global.params.objname) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
764 ext = FileName::ext(global.params.objname); |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
765 bool autofound = false; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
766 if (!ext) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
767 // keep things as they are |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
768 } else if (strcmp(ext, global.ll_ext) == 0) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
769 global.params.output_ll = OUTPUTFLAGset; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
770 autofound = true; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
771 } else if (strcmp(ext, global.bc_ext) == 0) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
772 global.params.output_bc = OUTPUTFLAGset; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
773 autofound = true; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
774 } else if (strcmp(ext, global.s_ext) == 0) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
775 global.params.output_s = OUTPUTFLAGset; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
776 autofound = true; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
777 } else if (strcmp(ext, global.obj_ext) == 0) { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
778 global.params.output_o = OUTPUTFLAGset; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
779 autofound = true; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
780 } else { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
781 // append dot, so forceExt won't change existing name even if it contains dots |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
782 size_t len = strlen(global.params.objname); |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
783 size_t extlen = strlen("."); |
713
b3dc22526289
Use malloc instead of alloca.
Christian Kamm <kamm incasoftware de>
parents:
712
diff
changeset
|
784 char* s = (char *)mem.malloc(len + 1 + extlen + 1); |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
785 memcpy(s, global.params.objname, len); |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
786 s[len] = '.'; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
787 s[len+1+extlen] = 0; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
788 global.params.objname = s; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
789 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
790 } |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
791 if(autofound && global.params.output_o == OUTPUTFLAGdefault) |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
792 global.params.output_o = OUTPUTFLAGno; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
793 } |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
794 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
795 // only link if possible |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
700
diff
changeset
|
796 if (!global.params.obj || !global.params.output_o) |
159 | 797 global.params.link = 0; |
798 | |
799 if (global.params.link) | |
800 { | |
801 global.params.exefile = global.params.objname; | |
712
8c0d3ec8dbbb
Fix -of with multiple input files.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
802 if (files.dim > 1) |
8c0d3ec8dbbb
Fix -of with multiple input files.
Christian Kamm <kamm incasoftware de>
parents:
708
diff
changeset
|
803 global.params.objname = NULL; |
159 | 804 } |
805 else if (global.params.run) | |
806 { | |
807 error("flags conflict with -run"); | |
808 fatal(); | |
809 } | |
810 else | |
811 { | |
812 if (global.params.objname && files.dim > 1) | |
813 { | |
814 error("multiple source files, but only one .obj name"); | |
815 fatal(); | |
816 } | |
817 } | |
818 | |
819 bool allowForceEndianness = false; | |
820 | |
821 if (global.params.llvmArch == 0) { | |
583
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
822 #if defined(__x86_64__) || defined(_M_X64) |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
823 global.params.llvmArch = "x86-64"; |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
824 #elif defined(__i386__) || defined(_M_IX86) |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
825 global.params.llvmArch = "x86"; |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
826 #elif defined(__ppc__) || defined(_M_PPC) |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
827 if (global.params.is64bit) |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
828 global.params.llvmArch = "ppc64"; |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
829 else |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
830 global.params.llvmArch = "ppc32"; |
734
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
831 #elif defined(__arm__) |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
832 global.params.llvmArch = "arm"; |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
833 #elif defined(__thumb__) |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
834 global.params.llvmArch = "thumb"; |
583
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
835 #else |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
836 #error |
12bda38ea366
Fixed choosing default target machine without needing to link in targets.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
580
diff
changeset
|
837 #endif |
159 | 838 } |
839 | |
840 if (strcmp(global.params.llvmArch,"x86")==0) { | |
841 VersionCondition::addPredefinedGlobalIdent("X86"); | |
842 global.params.isLE = true; | |
843 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
|
844 global.params.cpu = ARCHx86; |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
439
diff
changeset
|
845 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
|
846 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
|
847 } |
159 | 848 } |
849 else if (strcmp(global.params.llvmArch,"x86-64")==0) { | |
850 VersionCondition::addPredefinedGlobalIdent("X86_64"); | |
851 global.params.isLE = true; | |
852 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
|
853 global.params.cpu = ARCHx86_64; |
741
4ac97ec7c18e
Applied easy part from wilsonk's x86-64 patch in #107
Christian Kamm <kamm incasoftware de>
parents:
735
diff
changeset
|
854 if (global.params.useInlineAsm) { |
4ac97ec7c18e
Applied easy part from wilsonk's x86-64 patch in #107
Christian Kamm <kamm incasoftware de>
parents:
735
diff
changeset
|
855 VersionCondition::addPredefinedGlobalIdent("LLVM_InlineAsm_X86_64"); |
4ac97ec7c18e
Applied easy part from wilsonk's x86-64 patch in #107
Christian Kamm <kamm incasoftware de>
parents:
735
diff
changeset
|
856 } |
159 | 857 } |
858 else if (strcmp(global.params.llvmArch,"ppc32")==0) { | |
859 VersionCondition::addPredefinedGlobalIdent("PPC"); | |
860 global.params.isLE = false; | |
861 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
|
862 global.params.cpu = ARCHppc; |
159 | 863 } |
864 else if (strcmp(global.params.llvmArch,"ppc64")==0) { | |
865 VersionCondition::addPredefinedGlobalIdent("PPC64"); | |
866 global.params.isLE = false; | |
867 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
|
868 global.params.cpu = ARCHppc_64; |
159 | 869 } |
734
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
870 else if (strcmp(global.params.llvmArch,"arm")==0) { |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
871 VersionCondition::addPredefinedGlobalIdent("ARM"); |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
872 global.params.isLE = true; |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
873 global.params.is64bit = false; |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
874 global.params.cpu = ARCHarm; |
6dcab994ddc3
Fold in mandel's patch for ARM from #106
Christian Kamm <kamm incasoftware de>
parents:
717
diff
changeset
|
875 } |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
876 else if (strcmp(global.params.llvmArch,"thumb")==0) { |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
877 VersionCondition::addPredefinedGlobalIdent("Thumb"); |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
878 global.params.isLE = true; |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
879 global.params.is64bit = false; |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
880 global.params.cpu = ARCHthumb; |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
881 } |
159 | 882 else { |
883 assert(0 && "Invalid arch"); | |
884 } | |
885 | |
566
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
886 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
|
887 |
159 | 888 if (allowForceEndianness && global.params.forceBE) { |
889 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
890 global.params.isLE = false; | |
891 } | |
892 else if (global.params.isLE) { | |
893 VersionCondition::addPredefinedGlobalIdent("LittleEndian"); | |
894 } | |
895 else { | |
896 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
897 } | |
898 | |
899 if (global.params.is64bit) { | |
900 VersionCondition::addPredefinedGlobalIdent("LLVM64"); | |
901 } | |
902 | |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
903 |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
904 // 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
|
905 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
|
906 { |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
907 case OSWindows: |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
908 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
|
909 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
|
910 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
|
911 break; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
912 |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
913 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
|
914 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
|
915 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
|
916 break; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
917 |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
918 case OSMacOSX: |
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
919 VersionCondition::addPredefinedGlobalIdent("darwin"); |
541
4b7925bc1605
Fixed some osx mistakes.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
536
diff
changeset
|
920 VersionCondition::addPredefinedGlobalIdent("Posix"); |
542
1e9ca2889b07
Missing 'break' in osx code path.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
541
diff
changeset
|
921 break; |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
922 |
637
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
923 case OSFreeBSD: |
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
924 VersionCondition::addPredefinedGlobalIdent("freebsd"); |
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
925 VersionCondition::addPredefinedGlobalIdent("Posix"); |
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
926 break; |
29dc68c949b0
Applied the FreeBSD patch from Ralith, closes ticket #95 , slightly changed but basically the same. Thanx Ralith :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
583
diff
changeset
|
927 |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
928 default: |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
929 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
|
930 } |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
931 |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
932 if (!global.params.targetTriple) |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
933 global.params.targetTriple = DEFAULT_TARGET_TRIPLE; |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
934 |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
935 Logger::println("Target triple: %s", global.params.targetTriple); |
159 | 936 |
735
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
937 // build a minimal data layout so llvm can find the target |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
938 global.params.dataLayout = global.params.isLE |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
939 ? (char*)(global.params.is64bit ? "e-p:64:64" : "e-p:32:32") |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
940 : (char*)(global.params.is64bit ? "E-p:64:64" : "E-p:32:32"); |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
941 Logger::println("Layout: %s", global.params.dataLayout); |
eee9efe5b51f
Attempt at getting LLVM to provide a proper target data layout. Should assert now if things are borked.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
734
diff
changeset
|
942 |
159 | 943 // Initialization |
944 Type::init(); | |
945 Id::initialize(); | |
946 Module::init(); | |
947 initPrecedence(); | |
948 | |
949 backend_init(); | |
950 | |
951 //printf("%d source files\n",files.dim); | |
952 | |
953 // Build import search path | |
954 if (global.params.imppath) | |
955 { | |
956 for (i = 0; i < global.params.imppath->dim; i++) | |
957 { | |
958 char *path = (char *)global.params.imppath->data[i]; | |
959 Array *a = FileName::splitPath(path); | |
960 | |
961 if (a) | |
962 { | |
963 if (!global.path) | |
964 global.path = new Array(); | |
965 global.path->append(a); | |
966 } | |
967 } | |
968 } | |
969 | |
970 // Build string import search path | |
971 if (global.params.fileImppath) | |
972 { | |
973 for (i = 0; i < global.params.fileImppath->dim; i++) | |
974 { | |
975 char *path = (char *)global.params.fileImppath->data[i]; | |
976 Array *a = FileName::splitPath(path); | |
977 | |
978 if (a) | |
979 { | |
980 if (!global.filePath) | |
981 global.filePath = new Array(); | |
982 global.filePath->append(a); | |
983 } | |
984 } | |
985 } | |
986 | |
987 // Create Modules | |
988 Array modules; | |
989 modules.reserve(files.dim); | |
990 for (i = 0; i < files.dim; i++) | |
991 { Identifier *id; | |
992 char *ext; | |
993 char *name; | |
994 | |
995 p = (char *) files.data[i]; | |
996 | |
997 p = FileName::name(p); // strip path | |
998 ext = FileName::ext(p); | |
999 if (ext) | |
1000 { | |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
1001 #if TARGET_LINUX |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
1002 if (strcmp(ext, global.obj_ext) == 0 || |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
1003 strcmp(ext, global.bc_ext) == 0) |
159 | 1004 #else |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
1005 if (stricmp(ext, global.obj_ext) == 0 || |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
1006 stricmp(ext, global.bc_ext) == 0) |
159 | 1007 #endif |
1008 { | |
1009 global.params.objfiles->push(files.data[i]); | |
1010 continue; | |
1011 } | |
1012 | |
279
a137ed004205
[svn r300] Removed some win32 stuff that was causing problems on mingw32.
lindquist
parents:
277
diff
changeset
|
1013 #if TARGET_LINUX || __MINGW32__ |
159 | 1014 if (strcmp(ext, "a") == 0) |
1015 #else | |
1016 if (stricmp(ext, "lib") == 0) | |
1017 #endif | |
1018 { | |
1019 global.params.libfiles->push(files.data[i]); | |
1020 continue; | |
1021 } | |
1022 | |
1023 if (strcmp(ext, global.ddoc_ext) == 0) | |
1024 { | |
1025 global.params.ddocfiles->push(files.data[i]); | |
1026 continue; | |
1027 } | |
1028 | |
1029 #if !TARGET_LINUX | |
1030 if (stricmp(ext, "res") == 0) | |
1031 { | |
1032 global.params.resfile = (char *)files.data[i]; | |
1033 continue; | |
1034 } | |
1035 | |
1036 if (stricmp(ext, "def") == 0) | |
1037 { | |
1038 global.params.deffile = (char *)files.data[i]; | |
1039 continue; | |
1040 } | |
1041 | |
1042 if (stricmp(ext, "exe") == 0) | |
1043 { | |
1044 global.params.exefile = (char *)files.data[i]; | |
1045 continue; | |
1046 } | |
1047 #endif | |
1048 | |
1049 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
|
1050 stricmp(ext, global.hdr_ext) == 0 || |
159 | 1051 stricmp(ext, "htm") == 0 || |
1052 stricmp(ext, "html") == 0 || | |
1053 stricmp(ext, "xhtml") == 0) | |
1054 { | |
1055 ext--; // skip onto '.' | |
1056 assert(*ext == '.'); | |
1057 name = (char *)mem.malloc((ext - p) + 1); | |
1058 memcpy(name, p, ext - p); | |
1059 name[ext - p] = 0; // strip extension | |
1060 | |
1061 if (name[0] == 0 || | |
1062 strcmp(name, "..") == 0 || | |
1063 strcmp(name, ".") == 0) | |
1064 { | |
1065 Linvalid: | |
1066 error("invalid file name '%s'", (char *)files.data[i]); | |
1067 fatal(); | |
1068 } | |
1069 } | |
1070 else | |
1071 { error("unrecognized file extension %s\n", ext); | |
1072 fatal(); | |
1073 } | |
1074 } | |
1075 else | |
1076 { name = p; | |
1077 if (!*name) | |
1078 goto Linvalid; | |
1079 } | |
1080 | |
1081 id = new Identifier(name, 0); | |
1082 m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration); | |
1083 modules.push(m); | |
1084 } | |
1085 | |
1086 // Read files, parse them | |
1087 for (i = 0; i < modules.dim; i++) | |
1088 { | |
1089 m = (Module *)modules.data[i]; | |
1090 if (global.params.verbose) | |
1091 printf("parse %s\n", m->toChars()); | |
1092 if (!Module::rootModule) | |
1093 Module::rootModule = m; | |
1094 m->importedFrom = m; | |
1095 m->read(0); | |
1096 m->parse(); | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1097 m->buildTargetFiles(); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1098 m->deleteObjFile(); |
159 | 1099 if (m->isDocFile) |
1100 { | |
1101 m->gendocfile(); | |
1102 | |
1103 // Remove m from list of modules | |
1104 modules.remove(i); | |
1105 i--; | |
1106 } | |
1107 } | |
1108 if (global.errors) | |
1109 fatal(); | |
1110 #ifdef _DH | |
1111 if (global.params.doHdrGeneration) | |
1112 { | |
1113 /* Generate 'header' import files. | |
1114 * Since 'header' import files must be independent of command | |
1115 * line switches and what else is imported, they are generated | |
1116 * before any semantic analysis. | |
1117 */ | |
1118 for (i = 0; i < modules.dim; i++) | |
1119 { | |
1120 m = (Module *)modules.data[i]; | |
1121 if (global.params.verbose) | |
1122 printf("import %s\n", m->toChars()); | |
1123 m->genhdrfile(); | |
1124 } | |
1125 } | |
1126 if (global.errors) | |
1127 fatal(); | |
1128 #endif | |
1129 | |
1130 // Do semantic analysis | |
1131 for (i = 0; i < modules.dim; i++) | |
1132 { | |
1133 m = (Module *)modules.data[i]; | |
1134 if (global.params.verbose) | |
1135 printf("semantic %s\n", m->toChars()); | |
1136 m->semantic(); | |
1137 } | |
1138 if (global.errors) | |
1139 fatal(); | |
1140 | |
1141 // Do pass 2 semantic analysis | |
1142 for (i = 0; i < modules.dim; i++) | |
1143 { | |
1144 m = (Module *)modules.data[i]; | |
1145 if (global.params.verbose) | |
1146 printf("semantic2 %s\n", m->toChars()); | |
1147 m->semantic2(); | |
1148 } | |
1149 if (global.errors) | |
1150 fatal(); | |
1151 | |
1152 // Do pass 3 semantic analysis | |
1153 for (i = 0; i < modules.dim; i++) | |
1154 { | |
1155 m = (Module *)modules.data[i]; | |
1156 if (global.params.verbose) | |
1157 printf("semantic3 %s\n", m->toChars()); | |
1158 m->semantic3(); | |
1159 } | |
1160 if (global.errors) | |
1161 fatal(); | |
1162 | |
1163 #if !IN_LLVM | |
1164 // Scan for functions to inline | |
1165 if (global.params.useInline) | |
1166 { | |
1167 /* The problem with useArrayBounds and useAssert is that the | |
1168 * module being linked to may not have generated them, so if | |
1169 * we inline functions from those modules, the symbols for them will | |
1170 * not be found at link time. | |
1171 */ | |
1172 if (!global.params.useArrayBounds && !global.params.useAssert) | |
1173 { | |
1174 #endif | |
1175 // Do pass 3 semantic analysis on all imported modules, | |
1176 // since otherwise functions in them cannot be inlined | |
1177 for (i = 0; i < Module::amodules.dim; i++) | |
1178 { | |
1179 m = (Module *)Module::amodules.data[i]; | |
1180 if (global.params.verbose) | |
1181 printf("semantic3 %s\n", m->toChars()); | |
1182 m->semantic3(); | |
1183 } | |
1184 if (global.errors) | |
1185 fatal(); | |
1186 #if !IN_LLVM | |
1187 } | |
1188 | |
1189 for (i = 0; i < modules.dim; i++) | |
1190 { | |
1191 m = (Module *)modules.data[i]; | |
1192 if (global.params.verbose) | |
1193 printf("inline scan %s\n", m->toChars()); | |
1194 m->inlineScan(); | |
1195 } | |
1196 } | |
1197 if (global.errors) | |
1198 fatal(); | |
1199 #endif | |
1200 | |
1201 // Generate output files | |
1202 for (i = 0; i < modules.dim; i++) | |
1203 { | |
1204 m = (Module *)modules.data[i]; | |
1205 if (global.params.verbose) | |
1206 printf("code %s\n", m->toChars()); | |
1207 if (global.params.obj) | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1208 { |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
1209 m->genobjfile(0, envp); |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1210 global.params.objfiles->push(m->objfile->name->str); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1211 } |
159 | 1212 if (global.errors) |
1213 m->deleteObjFile(); | |
1214 else | |
1215 { | |
1216 if (global.params.doDocComments) | |
1217 m->gendocfile(); | |
1218 } | |
1219 } | |
279
a137ed004205
[svn r300] Removed some win32 stuff that was causing problems on mingw32.
lindquist
parents:
277
diff
changeset
|
1220 |
159 | 1221 backend_term(); |
1222 if (global.errors) | |
1223 fatal(); | |
1224 | |
1225 if (!global.params.objfiles->dim) | |
1226 { | |
1227 if (global.params.link) | |
1228 error("no object files to link"); | |
1229 } | |
1230 else | |
1231 { | |
1232 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
|
1233 //status = runLINK(); |
677
075c1272a01d
Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents:
676
diff
changeset
|
1234 linkObjToExecutable(global.params.argv0); |
159 | 1235 |
1236 if (global.params.run) | |
1237 { | |
1238 if (!status) | |
1239 { | |
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
|
1240 status = runExectuable(); |
159 | 1241 |
1242 /* Delete .obj files and .exe file | |
1243 */ | |
1244 for (i = 0; i < modules.dim; i++) | |
1245 { | |
1246 m = (Module *)modules.data[i]; | |
1247 m->deleteObjFile(); | |
1248 } | |
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
|
1249 deleteExecutable(); |
159 | 1250 } |
1251 } | |
1252 } | |
1253 | |
1254 return status; | |
1255 } | |
1256 | |
1257 | |
1258 | |
1259 /*********************************** | |
1260 * Parse and append contents of environment variable envvar | |
1261 * to argc and argv[]. | |
1262 * The string is separated into arguments, processing \ and ". | |
1263 */ | |
1264 | |
1265 void getenv_setargv(const char *envvar, int *pargc, char** *pargv) | |
1266 { | |
1267 char *env; | |
1268 char *p; | |
1269 Array *argv; | |
1270 int argc; | |
1271 | |
1272 int wildcard; // do wildcard expansion | |
1273 int instring; | |
1274 int slash; | |
1275 char c; | |
1276 int j; | |
1277 | |
1278 env = getenv(envvar); | |
1279 if (!env) | |
1280 return; | |
1281 | |
1282 env = mem.strdup(env); // create our own writable copy | |
1283 | |
1284 argc = *pargc; | |
1285 argv = new Array(); | |
1286 argv->setDim(argc); | |
1287 | |
1288 for (int i = 0; i < argc; i++) | |
1289 argv->data[i] = (void *)(*pargv)[i]; | |
1290 | |
1291 j = 1; // leave argv[0] alone | |
1292 while (1) | |
1293 { | |
1294 wildcard = 1; | |
1295 switch (*env) | |
1296 { | |
1297 case ' ': | |
1298 case '\t': | |
1299 env++; | |
1300 break; | |
1301 | |
1302 case 0: | |
1303 goto Ldone; | |
1304 | |
1305 case '"': | |
1306 wildcard = 0; | |
1307 default: | |
1308 argv->push(env); // append | |
1309 //argv->insert(j, env); // insert at position j | |
1310 j++; | |
1311 argc++; | |
1312 p = env; | |
1313 slash = 0; | |
1314 instring = 0; | |
1315 c = 0; | |
1316 | |
1317 while (1) | |
1318 { | |
1319 c = *env++; | |
1320 switch (c) | |
1321 { | |
1322 case '"': | |
1323 p -= (slash >> 1); | |
1324 if (slash & 1) | |
1325 { p--; | |
1326 goto Laddc; | |
1327 } | |
1328 instring ^= 1; | |
1329 slash = 0; | |
1330 continue; | |
1331 | |
1332 case ' ': | |
1333 case '\t': | |
1334 if (instring) | |
1335 goto Laddc; | |
1336 *p = 0; | |
1337 //if (wildcard) | |
1338 //wildcardexpand(); // not implemented | |
1339 break; | |
1340 | |
1341 case '\\': | |
1342 slash++; | |
1343 *p++ = c; | |
1344 continue; | |
1345 | |
1346 case 0: | |
1347 *p = 0; | |
1348 //if (wildcard) | |
1349 //wildcardexpand(); // not implemented | |
1350 goto Ldone; | |
1351 | |
1352 default: | |
1353 Laddc: | |
1354 slash = 0; | |
1355 *p++ = c; | |
1356 continue; | |
1357 } | |
1358 break; | |
1359 } | |
1360 } | |
1361 } | |
1362 | |
1363 Ldone: | |
1364 *pargc = argc; | |
1365 *pargv = (char **)argv->data; | |
1366 } |