Mercurial > projects > ldc
annotate dmd/mars.h @ 708:fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Thu, 16 Oct 2008 22:07:02 +0200 |
parents | ed9a9e6dd1cc |
children | 55f6c2e454d7 |
rev | line source |
---|---|
159 | 1 |
2 // Compiler implementation of the D programming language | |
3 // Copyright (c) 1999-2007 by Digital Mars | |
4 // All Rights Reserved | |
5 // written by Walter Bright | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
11 #ifndef DMD_MARS_H | |
12 #define DMD_MARS_H | |
13 | |
14 #ifdef __DMC__ | |
15 #pragma once | |
16 #endif /* __DMC__ */ | |
17 | |
18 #include <stdint.h> | |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
19 #include <stdarg.h> |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
20 #define __STDC_FORMAT_MACROS 1 |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
21 #include <inttypes.h> |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
22 #include <stdarg.h> |
159 | 23 |
24 #ifdef __DMC__ | |
25 #ifdef DEBUG | |
26 #undef assert | |
27 #define assert(e) (static_cast<void>((e) || (printf("assert %s(%d) %s\n", __FILE__, __LINE__, #e), halt()))) | |
28 #endif | |
29 #endif | |
30 | |
31 #ifdef IN_GCC | |
32 /* Changes for the GDC compiler by David Friedman */ | |
33 #endif | |
34 | |
336 | 35 #define DMDV2 0 // Version 2.0 features |
159 | 36 #define BREAKABI 1 // 0 if not ready to break the ABI just yet |
37 | |
38 struct Array; | |
39 | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
651
diff
changeset
|
40 // LDC |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
41 enum ARCH |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
42 { |
566
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
43 ARCHinvalid, |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
44 ARCHx86, |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
45 ARCHx86_64, |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
46 ARCHppc, |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
47 ARCHppc_64 |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
48 }; |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
49 enum OUTPUTFLAG |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
50 { |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
51 OUTPUTFLAGno, |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
52 OUTPUTFLAGdefault, // for the .o default |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
53 OUTPUTFLAGset // for -output |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
54 }; |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
55 |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
56 enum OS |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
57 { |
566
68d7df3f9b05
Added some sanity checks for target detection.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
550
diff
changeset
|
58 OSinvalid, |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
59 OSLinux, |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
60 OSWindows, |
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:
580
diff
changeset
|
61 OSMacOSX, |
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:
580
diff
changeset
|
62 OSFreeBSD |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
63 }; |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
64 |
159 | 65 // Put command line switches in here |
66 struct Param | |
67 { | |
68 char obj; // write object file | |
69 char link; // perform link | |
70 char quiet; // suppress non-error messages | |
71 char verbose; // verbose compile | |
72 char symdebug; // insert debug symbolic information | |
73 char optimize; // run optimizer | |
74 char optimizeLevel; // optimization level | |
534
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
75 ARCH cpu; // target CPU |
7e2867ed70d9
Get rid of isLinux and isWindows in favor of global.params.os.
Christian Kamm <kamm incasoftware de>
parents:
445
diff
changeset
|
76 OS os; // target OS |
159 | 77 char is64bit; // generate 64 bit code |
78 char isLE; // generate little endian code | |
79 char scheduler; // which scheduler to use | |
80 char useDeprecated; // allow use of deprecated features | |
81 char useAssert; // generate runtime code for assert()'s | |
82 char useInvariants; // generate class invariant checks | |
83 char useIn; // generate precondition checks | |
84 char useOut; // generate postcondition checks | |
85 char useArrayBounds; // generate array bounds checks | |
86 char useSwitchError; // check for switches without a default | |
87 char useUnitTests; // generate unittest code | |
88 char useInline; // inline expand functions | |
89 char preservePaths; // !=0 means don't strip path from source file | |
90 char warnings; // enable warnings | |
91 char pic; // generate position-independent-code for shared libs | |
92 char noruntime; // code is not allowed to make implicit calls to the runtime | |
93 char novalidate;// no bitcode validation | |
94 char Dversion; // D version number | |
95 char ignoreUnsupportedPragmas; // rather than error on them | |
96 | |
97 char *argv0; // program name | |
98 Array *imppath; // array of char*'s of where to look for import modules | |
99 Array *fileImppath; // array of char*'s of where to look for file import modules | |
100 char *runtimeImppath; // char* of where to look for the core runtime | |
101 char *objdir; // .obj file output directory | |
102 char *objname; // .obj file output name | |
103 | |
104 char doDocComments; // process embedded documentation comments | |
105 char *docdir; // write documentation file to docdir directory | |
106 char *docname; // write documentation file to docname | |
107 Array *ddocfiles; // macro include files for Ddoc | |
108 | |
109 char doHdrGeneration; // process embedded documentation comments | |
110 char *hdrdir; // write 'header' file to docdir directory | |
111 char *hdrname; // write 'header' file to docname | |
112 | |
113 unsigned debuglevel; // debug level | |
114 Array *debugids; // debug identifiers | |
115 | |
116 unsigned versionlevel; // version level | |
117 Array *versionids; // version identifiers | |
118 | |
119 bool dump_source; | |
120 | |
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
|
121 Array *defaultlibnames; // default libraries for non-debug builds |
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
|
122 Array *debuglibnames; // default libraries for debug builds |
159 | 123 |
124 char *xmlname; // filename for XML output | |
125 | |
126 // Hidden debug switches | |
127 char debuga; | |
128 char debugb; | |
129 char debugc; | |
130 char debugf; | |
131 char debugr; | |
132 char debugw; | |
133 char debugx; | |
134 char debugy; | |
135 | |
136 char run; // run resulting executable | |
137 size_t runargs_length; | |
138 char** runargs; // arguments for executable | |
139 | |
140 // Linker stuff | |
141 Array *objfiles; | |
142 Array *linkswitches; | |
143 Array *libfiles; | |
144 char *deffile; | |
145 char *resfile; | |
146 char *exefile; | |
147 | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
651
diff
changeset
|
148 // LDC stuff |
159 | 149 char *llvmArch; |
150 char forceBE; | |
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
|
151 char output_ll; |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
152 char output_bc; |
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
153 char output_s; |
694
931333ea35c6
Allow output of only bc, ll, or s by making -of set the output type depending
Christian Kamm <kamm incasoftware de>
parents:
675
diff
changeset
|
154 char output_o; |
159 | 155 char llvmInline; |
156 char llvmAnnotate; | |
220
ccc2e6898a78
[svn r236] added initial codegen of inline asm, pretty buggy and incomplete still. see the tangotests/asm1.d test for a sample of what does
lindquist
parents:
217
diff
changeset
|
157 char useInlineAsm; |
580
7824c21a58e3
Restructure path handling a bit. Fixes #66.
Christian Kamm <kamm incasoftware de>
parents:
568
diff
changeset
|
158 char fqnNames; // use fully qualified object names |
651
5709381df7e8
Added -nodefaultlib switch do disable implicitly linked standard lib modules
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
637
diff
changeset
|
159 char noDefaultLib; |
699
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
694
diff
changeset
|
160 |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
694
diff
changeset
|
161 // target stuff |
ed9a9e6dd1cc
Started changing target triple stuff, part of fixing #97
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
694
diff
changeset
|
162 char *targetTriple; |
159 | 163 }; |
164 | |
165 struct Global | |
166 { | |
167 char *mars_ext; | |
168 char *sym_ext; | |
169 char *obj_ext; | |
708
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
170 #if _WIN32 |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
171 char *obj_ext_alt; |
fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
Christian Kamm <kamm incasoftware de>
parents:
699
diff
changeset
|
172 #endif |
159 | 173 char *ll_ext; |
174 char *bc_ext; | |
675
bfe5229f9d8e
Disable bc output by default. Remove -dis. Add -output-bc, -output-ll, -output-s.
Christian Kamm <kamm incasoftware de>
parents:
663
diff
changeset
|
175 char *s_ext; |
159 | 176 char *doc_ext; // for Ddoc generated files |
177 char *ddoc_ext; // for Ddoc macro include files | |
178 char *hdr_ext; // for D 'header' import files | |
179 char *copyright; | |
180 char *written; | |
181 Array *path; // Array of char*'s which form the import lookup path | |
182 Array *filePath; // Array of char*'s which form the file import lookup path | |
183 int structalign; | |
184 char *version; | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
651
diff
changeset
|
185 char *ldc_version; |
159 | 186 |
187 Param params; | |
188 unsigned errors; // number of errors reported so far | |
189 unsigned gag; // !=0 means gag reporting of errors | |
190 | |
191 Global(); | |
192 }; | |
193 | |
194 extern Global global; | |
195 | |
196 #if __GNUC__ | |
197 //#define memicmp strncasecmp | |
198 //#define stricmp strcasecmp | |
199 #endif | |
200 | |
201 #ifdef __DMC__ | |
202 typedef _Complex long double complex_t; | |
203 #else | |
204 #ifndef IN_GCC | |
205 #include "complex_t.h" | |
206 #endif | |
207 #ifdef __APPLE__ | |
208 //#include "complex.h"//This causes problems with include the c++ <complex> and not the C "complex.h" | |
209 #define integer_t dmd_integer_t | |
210 #endif | |
211 #endif | |
212 | |
213 // Be careful not to care about sign when using integer_t | |
214 typedef uint64_t integer_t; | |
215 | |
216 // Signed and unsigned variants | |
217 typedef int64_t sinteger_t; | |
218 typedef uint64_t uinteger_t; | |
219 | |
220 typedef int8_t d_int8; | |
221 typedef uint8_t d_uns8; | |
222 typedef int16_t d_int16; | |
223 typedef uint16_t d_uns16; | |
224 typedef int32_t d_int32; | |
225 typedef uint32_t d_uns32; | |
226 typedef int64_t d_int64; | |
227 typedef uint64_t d_uns64; | |
228 | |
229 typedef float d_float32; | |
230 typedef double d_float64; | |
231 typedef long double d_float80; | |
232 | |
233 typedef d_uns8 d_char; | |
234 typedef d_uns16 d_wchar; | |
235 typedef d_uns32 d_dchar; | |
236 | |
237 #ifdef IN_GCC | |
238 #include "d-gcc-real.h" | |
239 #else | |
240 typedef long double real_t; | |
241 #endif | |
242 | |
243 // Modify OutBuffer::writewchar to write the correct size of wchar | |
244 #if _WIN32 | |
245 #define writewchar writeword | |
246 #else | |
247 // This needs a configuration test... | |
248 #define writewchar write4 | |
249 #endif | |
250 | |
251 #ifdef IN_GCC | |
252 #include "d-gcc-complex_t.h" | |
253 #endif | |
254 | |
305
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
255 // taken from GDC |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
256 // for handling printf incompatibilities |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
257 #if __MSVCRT__ |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
258 #define PRIuSIZE "Iu" |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
259 #define PRIxSIZE "Ix" |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
260 #elif __MINGW32__ |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
261 #define PRIuSIZE "u" |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
262 #define PRIxSIZE "x" |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
263 #else |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
264 #define PRIuSIZE "zu" |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
265 #define PRIxSIZE "zx" |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
266 #endif |
2b72433d5c8c
[svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents:
277
diff
changeset
|
267 |
159 | 268 struct Module; |
269 | |
270 //typedef unsigned Loc; // file location | |
271 struct Loc | |
272 { | |
273 char *filename; | |
274 unsigned linnum; | |
275 | |
276 Loc() | |
277 { | |
278 linnum = 0; | |
279 filename = NULL; | |
280 } | |
281 | |
282 Loc(int x) | |
283 { | |
284 linnum = x; | |
285 filename = NULL; | |
286 } | |
287 | |
288 Loc(Module *mod, unsigned linnum); | |
289 | |
290 char *toChars() const; | |
291 }; | |
292 | |
293 #ifndef GCC_SAFE_DMD | |
294 #define TRUE 1 | |
295 #define FALSE 0 | |
296 #endif | |
297 | |
298 #define INTERFACE_OFFSET 0 // if 1, put classinfo as first entry | |
299 // in interface vtbl[]'s | |
300 #define INTERFACE_VIRTUAL 0 // 1 means if an interface appears | |
301 // in the inheritance graph multiple | |
302 // times, only one is used | |
303 | |
304 enum LINK | |
305 { | |
306 LINKdefault, | |
307 LINKd, | |
308 LINKc, | |
309 LINKcpp, | |
310 LINKwindows, | |
311 LINKpascal, | |
312 }; | |
313 | |
314 enum DYNCAST | |
315 { | |
316 DYNCAST_OBJECT, | |
317 DYNCAST_EXPRESSION, | |
318 DYNCAST_DSYMBOL, | |
319 DYNCAST_TYPE, | |
320 DYNCAST_IDENTIFIER, | |
321 DYNCAST_TUPLE, | |
322 }; | |
323 | |
324 enum MATCH | |
325 { | |
326 MATCHnomatch, // no match | |
327 MATCHconvert, // match with conversions | |
336 | 328 #if DMDV2 |
159 | 329 MATCHconst, // match with conversion to const |
330 #endif | |
331 MATCHexact // exact match | |
332 }; | |
333 | |
334 void error(Loc loc, const char *format, ...); | |
335 void verror(Loc loc, const char *format, va_list); | |
336 void fatal(); | |
337 void err_nomem(); | |
338 void inifile(char *argv0, char *inifile); | |
339 void halt(); | |
340 | |
341 /*** Where to send error messages ***/ | |
342 #if IN_GCC | |
343 #define stdmsg stderr | |
344 #else | |
345 #define stdmsg stdout | |
346 #endif | |
347 | |
348 #endif /* DMD_MARS_H */ |