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