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