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