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