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