Mercurial > projects > ldc
annotate dmd/mars.c @ 700:716684a0d63f
Updated rebuild profile for .o output as default, compiler needs to be fixed still.
Fixed segfault with ' ldc foo.o -offoo '.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Mon, 13 Oct 2008 18:19:43 +0200 |
parents | ed9a9e6dd1cc |
children | fd5665da3a27 |
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); |
700
716684a0d63f
Updated rebuild profile for .o output as default, compiler needs to be fixed still.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
699
diff
changeset
|
469 if (!ext) { |
716684a0d63f
Updated rebuild profile for .o output as default, compiler needs to be fixed still.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
699
diff
changeset
|
470 global.params.link = 1; |
716684a0d63f
Updated rebuild profile for .o output as default, compiler needs to be fixed still.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
699
diff
changeset
|
471 global.params.output_o = 1; |
716684a0d63f
Updated rebuild profile for .o output as default, compiler needs to be fixed still.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
699
diff
changeset
|
472 } else if (strcmp(ext, global.ll_ext) == 0) { |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
690
diff
changeset
|
473 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; |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
835 //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
|
836 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
|
837 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
|
838 } |
159 | 839 } |
840 else if (strcmp(global.params.llvmArch,"x86-64")==0) { | |
841 VersionCondition::addPredefinedGlobalIdent("X86_64"); | |
842 global.params.isLE = true; | |
843 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
|
844 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
|
845 //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 | 846 } |
847 else if (strcmp(global.params.llvmArch,"ppc32")==0) { | |
848 VersionCondition::addPredefinedGlobalIdent("PPC"); | |
849 global.params.isLE = false; | |
850 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
|
851 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
|
852 //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 | 853 } |
854 else if (strcmp(global.params.llvmArch,"ppc64")==0) { | |
855 VersionCondition::addPredefinedGlobalIdent("PPC64"); | |
856 global.params.isLE = false; | |
857 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
|
858 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
|
859 //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 | 860 } |
861 else { | |
862 assert(0 && "Invalid arch"); | |
863 } | |
864 | |
566
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
865 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
|
866 |
159 | 867 if (allowForceEndianness && global.params.forceBE) { |
868 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
869 global.params.isLE = false; | |
870 } | |
871 else if (global.params.isLE) { | |
872 VersionCondition::addPredefinedGlobalIdent("LittleEndian"); | |
873 } | |
874 else { | |
875 VersionCondition::addPredefinedGlobalIdent("BigEndian"); | |
876 } | |
877 | |
878 if (global.params.is64bit) { | |
879 VersionCondition::addPredefinedGlobalIdent("LLVM64"); | |
880 } | |
881 | |
534
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 // 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
|
884 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
|
885 { |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
886 case OSWindows: |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
887 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
|
888 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
|
889 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
|
890 break; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
891 |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
892 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
|
893 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
|
894 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
|
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 OSMacOSX: |
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
898 VersionCondition::addPredefinedGlobalIdent("darwin"); |
541
4b7925bc1605
Fixed some osx mistakes.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
536
diff
changeset
|
899 VersionCondition::addPredefinedGlobalIdent("Posix"); |
542
1e9ca2889b07
Missing 'break' in osx code path.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
541
diff
changeset
|
900 break; |
536
0d2db7efa105
Add isnan for __APPLE__ and darwin version ident for OSX.
Christian Kamm <kamm incasoftware de>
parents:
535
diff
changeset
|
901 |
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
|
902 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
|
903 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
|
904 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
|
905 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
|
906 |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
907 default: |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
908 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
|
909 } |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
530
diff
changeset
|
910 |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
911 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
|
912 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
|
913 |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
695
diff
changeset
|
914 Logger::println("Target triple: %s", global.params.targetTriple); |
159 | 915 |
916 // Initialization | |
917 Type::init(); | |
918 Id::initialize(); | |
919 Module::init(); | |
920 initPrecedence(); | |
921 | |
922 backend_init(); | |
923 | |
924 //printf("%d source files\n",files.dim); | |
925 | |
926 // Build import search path | |
927 if (global.params.imppath) | |
928 { | |
929 for (i = 0; i < global.params.imppath->dim; i++) | |
930 { | |
931 char *path = (char *)global.params.imppath->data[i]; | |
932 Array *a = FileName::splitPath(path); | |
933 | |
934 if (a) | |
935 { | |
936 if (!global.path) | |
937 global.path = new Array(); | |
938 global.path->append(a); | |
939 } | |
940 } | |
941 } | |
942 | |
943 // Build string import search path | |
944 if (global.params.fileImppath) | |
945 { | |
946 for (i = 0; i < global.params.fileImppath->dim; i++) | |
947 { | |
948 char *path = (char *)global.params.fileImppath->data[i]; | |
949 Array *a = FileName::splitPath(path); | |
950 | |
951 if (a) | |
952 { | |
953 if (!global.filePath) | |
954 global.filePath = new Array(); | |
955 global.filePath->append(a); | |
956 } | |
957 } | |
958 } | |
959 | |
960 // Create Modules | |
961 Array modules; | |
962 modules.reserve(files.dim); | |
963 for (i = 0; i < files.dim; i++) | |
964 { Identifier *id; | |
965 char *ext; | |
966 char *name; | |
967 | |
968 p = (char *) files.data[i]; | |
969 | |
970 p = FileName::name(p); // strip path | |
971 ext = FileName::ext(p); | |
972 if (ext) | |
973 { | |
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
|
974 #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
|
975 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
|
976 strcmp(ext, global.bc_ext) == 0) |
159 | 977 #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
|
978 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
|
979 stricmp(ext, global.bc_ext) == 0) |
159 | 980 #endif |
981 { | |
982 global.params.objfiles->push(files.data[i]); | |
983 continue; | |
984 } | |
985 | |
279
a137ed004205
[svn r300] Removed some win32 stuff that was causing problems on mingw32.
lindquist
parents:
277
diff
changeset
|
986 #if TARGET_LINUX || __MINGW32__ |
159 | 987 if (strcmp(ext, "a") == 0) |
988 #else | |
989 if (stricmp(ext, "lib") == 0) | |
990 #endif | |
991 { | |
992 global.params.libfiles->push(files.data[i]); | |
993 continue; | |
994 } | |
995 | |
996 if (strcmp(ext, global.ddoc_ext) == 0) | |
997 { | |
998 global.params.ddocfiles->push(files.data[i]); | |
999 continue; | |
1000 } | |
1001 | |
1002 #if !TARGET_LINUX | |
1003 if (stricmp(ext, "res") == 0) | |
1004 { | |
1005 global.params.resfile = (char *)files.data[i]; | |
1006 continue; | |
1007 } | |
1008 | |
1009 if (stricmp(ext, "def") == 0) | |
1010 { | |
1011 global.params.deffile = (char *)files.data[i]; | |
1012 continue; | |
1013 } | |
1014 | |
1015 if (stricmp(ext, "exe") == 0) | |
1016 { | |
1017 global.params.exefile = (char *)files.data[i]; | |
1018 continue; | |
1019 } | |
1020 #endif | |
1021 | |
1022 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
|
1023 stricmp(ext, global.hdr_ext) == 0 || |
159 | 1024 stricmp(ext, "htm") == 0 || |
1025 stricmp(ext, "html") == 0 || | |
1026 stricmp(ext, "xhtml") == 0) | |
1027 { | |
1028 ext--; // skip onto '.' | |
1029 assert(*ext == '.'); | |
1030 name = (char *)mem.malloc((ext - p) + 1); | |
1031 memcpy(name, p, ext - p); | |
1032 name[ext - p] = 0; // strip extension | |
1033 | |
1034 if (name[0] == 0 || | |
1035 strcmp(name, "..") == 0 || | |
1036 strcmp(name, ".") == 0) | |
1037 { | |
1038 Linvalid: | |
1039 error("invalid file name '%s'", (char *)files.data[i]); | |
1040 fatal(); | |
1041 } | |
1042 } | |
1043 else | |
1044 { error("unrecognized file extension %s\n", ext); | |
1045 fatal(); | |
1046 } | |
1047 } | |
1048 else | |
1049 { name = p; | |
1050 if (!*name) | |
1051 goto Linvalid; | |
1052 } | |
1053 | |
1054 id = new Identifier(name, 0); | |
1055 m = new Module((char *) files.data[i], id, global.params.doDocComments, global.params.doHdrGeneration); | |
1056 modules.push(m); | |
1057 } | |
1058 | |
1059 // Read files, parse them | |
1060 for (i = 0; i < modules.dim; i++) | |
1061 { | |
1062 m = (Module *)modules.data[i]; | |
1063 if (global.params.verbose) | |
1064 printf("parse %s\n", m->toChars()); | |
1065 if (!Module::rootModule) | |
1066 Module::rootModule = m; | |
1067 m->importedFrom = m; | |
1068 m->read(0); | |
1069 m->parse(); | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1070 m->buildTargetFiles(); |
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1071 m->deleteObjFile(); |
159 | 1072 if (m->isDocFile) |
1073 { | |
1074 m->gendocfile(); | |
1075 | |
1076 // Remove m from list of modules | |
1077 modules.remove(i); | |
1078 i--; | |
1079 } | |
1080 } | |
1081 if (global.errors) | |
1082 fatal(); | |
1083 #ifdef _DH | |
1084 if (global.params.doHdrGeneration) | |
1085 { | |
1086 /* Generate 'header' import files. | |
1087 * Since 'header' import files must be independent of command | |
1088 * line switches and what else is imported, they are generated | |
1089 * before any semantic analysis. | |
1090 */ | |
1091 for (i = 0; i < modules.dim; i++) | |
1092 { | |
1093 m = (Module *)modules.data[i]; | |
1094 if (global.params.verbose) | |
1095 printf("import %s\n", m->toChars()); | |
1096 m->genhdrfile(); | |
1097 } | |
1098 } | |
1099 if (global.errors) | |
1100 fatal(); | |
1101 #endif | |
1102 | |
1103 // Do semantic analysis | |
1104 for (i = 0; i < modules.dim; i++) | |
1105 { | |
1106 m = (Module *)modules.data[i]; | |
1107 if (global.params.verbose) | |
1108 printf("semantic %s\n", m->toChars()); | |
1109 m->semantic(); | |
1110 } | |
1111 if (global.errors) | |
1112 fatal(); | |
1113 | |
1114 // Do pass 2 semantic analysis | |
1115 for (i = 0; i < modules.dim; i++) | |
1116 { | |
1117 m = (Module *)modules.data[i]; | |
1118 if (global.params.verbose) | |
1119 printf("semantic2 %s\n", m->toChars()); | |
1120 m->semantic2(); | |
1121 } | |
1122 if (global.errors) | |
1123 fatal(); | |
1124 | |
1125 // Do pass 3 semantic analysis | |
1126 for (i = 0; i < modules.dim; i++) | |
1127 { | |
1128 m = (Module *)modules.data[i]; | |
1129 if (global.params.verbose) | |
1130 printf("semantic3 %s\n", m->toChars()); | |
1131 m->semantic3(); | |
1132 } | |
1133 if (global.errors) | |
1134 fatal(); | |
1135 | |
1136 #if !IN_LLVM | |
1137 // Scan for functions to inline | |
1138 if (global.params.useInline) | |
1139 { | |
1140 /* The problem with useArrayBounds and useAssert is that the | |
1141 * module being linked to may not have generated them, so if | |
1142 * we inline functions from those modules, the symbols for them will | |
1143 * not be found at link time. | |
1144 */ | |
1145 if (!global.params.useArrayBounds && !global.params.useAssert) | |
1146 { | |
1147 #endif | |
1148 // Do pass 3 semantic analysis on all imported modules, | |
1149 // since otherwise functions in them cannot be inlined | |
1150 for (i = 0; i < Module::amodules.dim; i++) | |
1151 { | |
1152 m = (Module *)Module::amodules.data[i]; | |
1153 if (global.params.verbose) | |
1154 printf("semantic3 %s\n", m->toChars()); | |
1155 m->semantic3(); | |
1156 } | |
1157 if (global.errors) | |
1158 fatal(); | |
1159 #if !IN_LLVM | |
1160 } | |
1161 | |
1162 for (i = 0; i < modules.dim; i++) | |
1163 { | |
1164 m = (Module *)modules.data[i]; | |
1165 if (global.params.verbose) | |
1166 printf("inline scan %s\n", m->toChars()); | |
1167 m->inlineScan(); | |
1168 } | |
1169 } | |
1170 if (global.errors) | |
1171 fatal(); | |
1172 #endif | |
1173 | |
1174 // Generate output files | |
1175 for (i = 0; i < modules.dim; i++) | |
1176 { | |
1177 m = (Module *)modules.data[i]; | |
1178 if (global.params.verbose) | |
1179 printf("code %s\n", m->toChars()); | |
1180 if (global.params.obj) | |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1181 { |
676
1f0a78174598
Make ldc call gcc to assemble.
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
1182 m->genobjfile(0, envp); |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
572
diff
changeset
|
1183 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
|
1184 } |
159 | 1185 if (global.errors) |
1186 m->deleteObjFile(); | |
1187 else | |
1188 { | |
1189 if (global.params.doDocComments) | |
1190 m->gendocfile(); | |
1191 } | |
1192 } | |
279
a137ed004205
[svn r300] Removed some win32 stuff that was causing problems on mingw32.
lindquist
parents:
277
diff
changeset
|
1193 |
159 | 1194 backend_term(); |
1195 if (global.errors) | |
1196 fatal(); | |
1197 | |
1198 if (!global.params.objfiles->dim) | |
1199 { | |
1200 if (global.params.link) | |
1201 error("no object files to link"); | |
1202 } | |
1203 else | |
1204 { | |
1205 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
|
1206 //status = runLINK(); |
677
075c1272a01d
Link using gcc instead.
Christian Kamm <kamm incasoftware de>
parents:
676
diff
changeset
|
1207 linkObjToExecutable(global.params.argv0); |
159 | 1208 |
1209 if (global.params.run) | |
1210 { | |
1211 if (!status) | |
1212 { | |
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
|
1213 status = runExectuable(); |
159 | 1214 |
1215 /* Delete .obj files and .exe file | |
1216 */ | |
1217 for (i = 0; i < modules.dim; i++) | |
1218 { | |
1219 m = (Module *)modules.data[i]; | |
1220 m->deleteObjFile(); | |
1221 } | |
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
|
1222 deleteExecutable(); |
159 | 1223 } |
1224 } | |
1225 } | |
1226 | |
1227 return status; | |
1228 } | |
1229 | |
1230 | |
1231 | |
1232 /*********************************** | |
1233 * Parse and append contents of environment variable envvar | |
1234 * to argc and argv[]. | |
1235 * The string is separated into arguments, processing \ and ". | |
1236 */ | |
1237 | |
1238 void getenv_setargv(const char *envvar, int *pargc, char** *pargv) | |
1239 { | |
1240 char *env; | |
1241 char *p; | |
1242 Array *argv; | |
1243 int argc; | |
1244 | |
1245 int wildcard; // do wildcard expansion | |
1246 int instring; | |
1247 int slash; | |
1248 char c; | |
1249 int j; | |
1250 | |
1251 env = getenv(envvar); | |
1252 if (!env) | |
1253 return; | |
1254 | |
1255 env = mem.strdup(env); // create our own writable copy | |
1256 | |
1257 argc = *pargc; | |
1258 argv = new Array(); | |
1259 argv->setDim(argc); | |
1260 | |
1261 for (int i = 0; i < argc; i++) | |
1262 argv->data[i] = (void *)(*pargv)[i]; | |
1263 | |
1264 j = 1; // leave argv[0] alone | |
1265 while (1) | |
1266 { | |
1267 wildcard = 1; | |
1268 switch (*env) | |
1269 { | |
1270 case ' ': | |
1271 case '\t': | |
1272 env++; | |
1273 break; | |
1274 | |
1275 case 0: | |
1276 goto Ldone; | |
1277 | |
1278 case '"': | |
1279 wildcard = 0; | |
1280 default: | |
1281 argv->push(env); // append | |
1282 //argv->insert(j, env); // insert at position j | |
1283 j++; | |
1284 argc++; | |
1285 p = env; | |
1286 slash = 0; | |
1287 instring = 0; | |
1288 c = 0; | |
1289 | |
1290 while (1) | |
1291 { | |
1292 c = *env++; | |
1293 switch (c) | |
1294 { | |
1295 case '"': | |
1296 p -= (slash >> 1); | |
1297 if (slash & 1) | |
1298 { p--; | |
1299 goto Laddc; | |
1300 } | |
1301 instring ^= 1; | |
1302 slash = 0; | |
1303 continue; | |
1304 | |
1305 case ' ': | |
1306 case '\t': | |
1307 if (instring) | |
1308 goto Laddc; | |
1309 *p = 0; | |
1310 //if (wildcard) | |
1311 //wildcardexpand(); // not implemented | |
1312 break; | |
1313 | |
1314 case '\\': | |
1315 slash++; | |
1316 *p++ = c; | |
1317 continue; | |
1318 | |
1319 case 0: | |
1320 *p = 0; | |
1321 //if (wildcard) | |
1322 //wildcardexpand(); // not implemented | |
1323 goto Ldone; | |
1324 | |
1325 default: | |
1326 Laddc: | |
1327 slash = 0; | |
1328 *p++ = c; | |
1329 continue; | |
1330 } | |
1331 break; | |
1332 } | |
1333 } | |
1334 } | |
1335 | |
1336 Ldone: | |
1337 *pargc = argc; | |
1338 *pargv = (char **)argv->data; | |
1339 } |