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