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