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