Mercurial > projects > ldc
comparison dmd2/mars.h @ 1452:638d16625da2
LDC 2 compiles again.
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Sat, 30 May 2009 17:23:32 +0100 |
parents | e40c65bd8c5d |
children | f62347c22d81 |
comparison
equal
deleted
inserted
replaced
1423:42bd767ec5a4 | 1452:638d16625da2 |
---|---|
1 | 1 |
2 // Compiler implementation of the D programming language | 2 // Compiler implementation of the D programming language |
3 // Copyright (c) 1999-2007 by Digital Mars | 3 // Copyright (c) 1999-2009 by Digital Mars |
4 // All Rights Reserved | 4 // All Rights Reserved |
5 // written by Walter Bright | 5 // written by Walter Bright |
6 // http://www.digitalmars.com | 6 // http://www.digitalmars.com |
7 // License for redistribution is by either the Artistic License | 7 // License for redistribution is by either the Artistic License |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | 8 // in artistic.txt, or the GNU General Public License in gnu.txt. |
11 #ifndef DMD_MARS_H | 11 #ifndef DMD_MARS_H |
12 #define DMD_MARS_H | 12 #define DMD_MARS_H |
13 | 13 |
14 #ifdef __DMC__ | 14 #ifdef __DMC__ |
15 #pragma once | 15 #pragma once |
16 #endif /* __DMC__ */ | 16 #endif |
17 | 17 |
18 /* | |
19 It is very important to use version control macros correctly - the | |
20 idea is that host and target are independent. If these are done | |
21 correctly, cross compilers can be built. | |
22 The host compiler and host operating system are also different, | |
23 and are predefined by the host compiler. The ones used in | |
24 dmd are: | |
25 | |
26 Macros defined by the compiler, not the code: | |
27 | |
28 Compiler: | |
29 __DMC__ Digital Mars compiler | |
30 _MSC_VER Microsoft compiler | |
31 __GNUC__ Gnu compiler | |
32 | |
33 Host operating system: | |
34 _WIN32 Microsoft NT, Windows 95, Windows 98, Win32s, | |
35 Windows 2000, Win XP, Vista | |
36 _WIN64 Windows for AMD64 | |
37 linux Linux | |
38 __APPLE__ Mac OSX | |
39 __FreeBSD__ FreeBSD | |
40 __sun&&__SVR4 Solaris, OpenSolaris (yes, both macros are necessary) | |
41 | |
42 For the target systems, there are the target operating system and | |
43 the target object file format: | |
44 | |
45 Target operating system: | |
46 TARGET_WINDOS Covers 32 bit windows and 64 bit windows | |
47 TARGET_LINUX Covers 32 and 64 bit linux | |
48 TARGET_OSX Covers 32 and 64 bit Mac OSX | |
49 TARGET_FREEBSD Covers 32 and 64 bit FreeBSD | |
50 TARGET_SOLARIS Covers 32 and 64 bit Solaris | |
51 TARGET_NET Covers .Net | |
52 | |
53 It is expected that the compiler for each platform will be able | |
54 to generate 32 and 64 bit code from the same compiler binary. | |
55 | |
56 Target object module format: | |
57 OMFOBJ Intel Object Module Format, used on Windows | |
58 ELFOBJ Elf Object Module Format, used on linux, FreeBSD and Solaris | |
59 MACHOBJ Mach-O Object Module Format, used on Mac OSX | |
60 | |
61 There are currently no macros for byte endianness order. | |
62 */ | |
63 | |
64 | |
65 #include <stdio.h> | |
18 #include <stdint.h> | 66 #include <stdint.h> |
19 #include <stdarg.h> | 67 #include <stdarg.h> |
20 #include <stddef.h> | 68 #include <stddef.h> |
21 #define __STDC_FORMAT_MACROS 1 | 69 #define __STDC_FORMAT_MACROS 1 |
22 #include <inttypes.h> | 70 #include <inttypes.h> |
27 #undef assert | 75 #undef assert |
28 #define assert(e) (static_cast<void>((e) || (printf("assert %s(%d) %s\n", __FILE__, __LINE__, #e), halt()))) | 76 #define assert(e) (static_cast<void>((e) || (printf("assert %s(%d) %s\n", __FILE__, __LINE__, #e), halt()))) |
29 #endif | 77 #endif |
30 #endif | 78 #endif |
31 | 79 |
80 #ifndef IS_PRINTF | |
81 # ifdef __GNUC__ | |
82 # define IS_PRINTF(FMTARG) __attribute((__format__ (__printf__, (FMTARG), (FMTARG)+1) )) | |
83 # else | |
84 # define IS_PRINTF(FMTARG) | |
85 # endif | |
86 #endif | |
87 | |
32 #ifdef IN_GCC | 88 #ifdef IN_GCC |
33 /* Changes for the GDC compiler by David Friedman */ | 89 /* Changes for the GDC compiler by David Friedman */ |
34 #endif | 90 #endif |
35 | 91 |
36 #define BREAKABI 1 // 0 if not ready to break the ABI just yet | 92 #define DMDV1 0 |
37 #define STRUCTTHISREF V2 // if 'this' for struct is a reference, not a pointer | 93 #define DMDV2 1 // Version 2.0 features |
94 #define BREAKABI 1 // 0 if not ready to break the ABI just yet | |
95 #define STRUCTTHISREF DMDV2 // if 'this' for struct is a reference, not a pointer | |
96 #define SNAN_DEFAULT_INIT DMDV2 // if floats are default initialized to signalling NaN | |
97 | |
98 /* Other targets are TARGET_LINUX, TARGET_OSX, TARGET_FREEBSD and | |
99 * TARGET_SOLARIS, which are | |
100 * set on the command line via the compiler makefile. | |
101 */ | |
102 | |
103 #if _WIN32 | |
104 #define TARGET_WINDOS 1 // Windows dmd generates Windows targets | |
105 #define OMFOBJ 1 | |
106 #endif | |
107 | |
108 #if TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS | |
109 #ifndef ELFOBJ | |
110 #define ELFOBJ 1 | |
111 #endif | |
112 #endif | |
113 | |
114 #if TARGET_OSX | |
115 #ifndef MACHOBJ | |
116 #define MACHOBJ 1 | |
117 #endif | |
118 #endif | |
119 | |
38 | 120 |
39 struct Array; | 121 struct Array; |
40 | 122 struct OutBuffer; |
41 // LDC | 123 |
124 #if IN_LLVM | |
42 enum ARCH | 125 enum ARCH |
43 { | 126 { |
44 ARCHinvalid, | 127 ARCHinvalid, |
45 ARCHx86, | 128 ARCHx86, |
46 ARCHx86_64, | 129 ARCHx86_64, |
64 OSMacOSX, | 147 OSMacOSX, |
65 OSFreeBSD, | 148 OSFreeBSD, |
66 OSSolaris, | 149 OSSolaris, |
67 }; | 150 }; |
68 | 151 |
152 typedef unsigned char ubyte; | |
153 #endif | |
154 | |
69 // Put command line switches in here | 155 // Put command line switches in here |
70 struct Param | 156 struct Param |
71 { | 157 { |
72 bool obj; // write object file | 158 bool obj; // write object file |
73 bool link; // perform link | 159 bool link; // perform link |
74 bool verbose; // verbose compile | 160 bool verbose; // verbose compile |
75 char symdebug; // insert debug symbolic information | 161 bool vtls; // identify thread local variables |
162 ubyte symdebug; // insert debug symbolic information | |
76 #if !IN_LLVM | 163 #if !IN_LLVM |
77 // LDC uses a different mechanism | 164 // LDC uses a different mechanism |
78 bool optimize; // run optimizer | 165 bool optimize; // run optimizer |
79 char optimizeLevel; // optimization level | 166 char optimizeLevel; // optimization level |
80 #endif | 167 #endif |
81 ARCH cpu; // target CPU | 168 ARCH cpu; // target CPU |
82 OS os; // target OS | 169 OS os; |
83 bool is64bit; // generate 64 bit code | 170 bool is64bit; // generate X86_64 bit code |
84 bool isLE; // generate little endian code | 171 bool isLE; // generate little endian code |
85 bool useDeprecated; // allow use of deprecated features | 172 bool useDeprecated; // allow use of deprecated features |
86 bool useAssert; // generate runtime code for assert()'s | 173 bool useAssert; // generate runtime code for assert()'s |
87 bool useInvariants; // generate class invariant checks | 174 bool useInvariants; // generate class invariant checks |
88 bool useIn; // generate precondition checks | 175 bool useIn; // generate precondition checks |
89 bool useOut; // generate postcondition checks | 176 bool useOut; // generate postcondition checks |
90 bool useArrayBounds; // generate array bounds checks | 177 bool useArrayBounds; // generate array bounds checks |
91 bool useSwitchError; // check for switches without a default | 178 bool useSwitchError; // check for switches without a default |
92 bool useUnitTests; // generate unittest code | 179 bool useUnitTests; // generate unittest code |
93 bool useInline; // inline expand functions | 180 bool useInline; // inline expand functions |
94 bool warnings; // enable warnings | 181 bool warnings; // enable warnings |
95 bool safe; // enforce safe memory model | 182 ubyte Dversion; // D version number |
96 char Dversion; // D version number | 183 char safe; // enforce safe memory model |
97 | 184 |
98 char *argv0; // program name | 185 char *argv0; // program name |
99 Array *imppath; // array of char*'s of where to look for import modules | 186 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 | 187 Array *fileImppath; // array of char*'s of where to look for file import modules |
101 char *objdir; // .obj file output directory | 188 char *objdir; // .obj file output directory |
102 char *objname; // .obj file output name | 189 char *objname; // .obj file output name |
103 | 190 |
104 bool doDocComments; // process embedded documentation comments | 191 bool doDocComments; // process embedded documentation comments |
105 char *docdir; // write documentation file to docdir directory | 192 char *docdir; // write documentation file to docdir directory |
106 char *docname; // write documentation file to docname | 193 char *docname; // write documentation file to docname |
107 Array *ddocfiles; // macro include files for Ddoc | 194 Array *ddocfiles; // macro include files for Ddoc |
108 | 195 |
109 bool doHdrGeneration; // process embedded documentation comments | 196 bool doHdrGeneration; // process embedded documentation comments |
110 char *hdrdir; // write 'header' file to docdir directory | 197 char *hdrdir; // write 'header' file to docdir directory |
111 char *hdrname; // write 'header' file to docname | 198 char *hdrname; // write 'header' file to docname |
112 | 199 |
113 unsigned debuglevel; // debug level | 200 unsigned debuglevel; // debug level |
114 Array *debugids; // debug identifiers | 201 Array *debugids; // debug identifiers |
115 | 202 |
116 unsigned versionlevel; // version level | 203 unsigned versionlevel; // version level |
117 Array *versionids; // version identifiers | 204 Array *versionids; // version identifiers |
118 | 205 |
119 bool dump_source; | 206 bool dump_source; |
120 | 207 |
121 Array *defaultlibnames; // default libraries for non-debug builds | 208 Array *defaultlibnames; // default libraries for non-debug builds |
122 Array *debuglibnames; // default libraries for debug builds | 209 Array *debuglibnames; // default libraries for debug builds |
123 | 210 |
124 char *xmlname; // filename for XML output | 211 const char *xmlname; // filename for XML output |
125 | 212 |
213 OutBuffer *moduleDeps; // buffer and filename for emitting module deps | |
214 char *moduleDepsFile; | |
215 | |
126 // Hidden debug switches | 216 // Hidden debug switches |
127 bool debuga; | 217 bool debuga; |
128 bool debugb; | 218 bool debugb; |
129 bool debugc; | 219 bool debugc; |
130 bool debugf; | 220 bool debugf; |
141 Array *libfiles; | 231 Array *libfiles; |
142 char *deffile; | 232 char *deffile; |
143 char *resfile; | 233 char *resfile; |
144 char *exefile; | 234 char *exefile; |
145 | 235 |
236 #if IN_LLVM | |
146 // LDC stuff | 237 // LDC stuff |
147 OUTPUTFLAG output_ll; | 238 OUTPUTFLAG output_ll; |
148 OUTPUTFLAG output_bc; | 239 OUTPUTFLAG output_bc; |
149 OUTPUTFLAG output_s; | 240 OUTPUTFLAG output_s; |
150 OUTPUTFLAG output_o; | 241 OUTPUTFLAG output_o; |
151 bool llvmAnnotate; | 242 bool llvmAnnotate; |
152 bool useInlineAsm; | 243 bool useInlineAsm; |
244 bool verbose_cg; | |
153 | 245 |
154 // target stuff | 246 // target stuff |
155 const char* llvmArch; | 247 const char* llvmArch; |
156 const char *targetTriple; | 248 const char *targetTriple; |
157 const char *dataLayout; | 249 const char *dataLayout; |
250 #endif | |
158 }; | 251 }; |
159 | 252 |
160 struct Global | 253 struct Global |
161 { | 254 { |
162 char *mars_ext; | 255 const char *mars_ext; |
163 char *sym_ext; | 256 const char *sym_ext; |
164 char *obj_ext; | 257 const char *obj_ext; |
258 #if IN_LLVM | |
165 #if _WIN32 | 259 #if _WIN32 |
166 char *obj_ext_alt; | 260 char *obj_ext_alt; |
167 #endif | 261 #endif |
168 char *ll_ext; | 262 char *ll_ext; |
169 char *bc_ext; | 263 char *bc_ext; |
170 char *s_ext; | 264 char *s_ext; |
171 char *doc_ext; // for Ddoc generated files | 265 #endif |
172 char *ddoc_ext; // for Ddoc macro include files | 266 const char *lib_ext; |
173 char *hdr_ext; // for D 'header' import files | 267 const char *doc_ext; // for Ddoc generated files |
174 char *copyright; | 268 const char *ddoc_ext; // for Ddoc macro include files |
175 char *written; | 269 const char *hdr_ext; // for D 'header' import files |
176 Array *path; // Array of char*'s which form the import lookup path | 270 const char *copyright; |
177 Array *filePath; // Array of char*'s which form the file import lookup path | 271 const char *written; |
272 Array *path; // Array of char*'s which form the import lookup path | |
273 Array *filePath; // Array of char*'s which form the file import lookup path | |
178 int structalign; | 274 int structalign; |
179 char *version; | 275 const char *version; |
276 #if IN_LLVM | |
180 char *ldc_version; | 277 char *ldc_version; |
181 char *llvm_version; | 278 char *llvm_version; |
279 #endif | |
182 | 280 |
183 Param params; | 281 Param params; |
184 unsigned errors; // number of errors reported so far | 282 unsigned errors; // number of errors reported so far |
185 unsigned gag; // !=0 means gag reporting of errors | 283 unsigned gag; // !=0 means gag reporting of errors |
186 | 284 |
187 Global(); | 285 Global(); |
188 }; | 286 }; |
189 | 287 |
190 extern Global global; | 288 extern Global global; |
191 | 289 |
192 /* Set if Windows Structured Exception Handling C extensions are supported. | 290 /* Set if Windows Structured Exception Handling C extensions are supported. |
193 * Apparently, VC has dropped support for these? | 291 * Apparently, VC has dropped support for these? |
194 */ | 292 */ |
195 #define WINDOWS_SEH (_WIN32 && __DMC__) | 293 #define WINDOWS_SEH (_WIN32 && __DMC__) |
196 | 294 |
197 | |
198 #if __GNUC__ | |
199 //#define memicmp strncasecmp | |
200 //#define stricmp strcasecmp | |
201 #endif | |
202 | 295 |
203 #ifdef __DMC__ | 296 #ifdef __DMC__ |
204 typedef _Complex long double complex_t; | 297 typedef _Complex long double complex_t; |
205 #else | 298 #else |
206 #ifndef IN_GCC | 299 #ifndef IN_GCC |
207 #include "complex_t.h" | 300 #include "complex_t.h" |
208 #endif | 301 #endif |
209 #ifdef __APPLE__ | 302 #ifdef __APPLE__ |
210 //#include "complex.h"//This causes problems with include the c++ <complex> and not the C "complex.h" | 303 //#include "complex.h"//This causes problems with include the c++ <complex> and not the C "complex.h" |
211 #define integer_t dmd_integer_t | |
212 #endif | 304 #endif |
213 #endif | 305 #endif |
214 | 306 |
215 // Be careful not to care about sign when using integer_t | 307 // Be careful not to care about sign when using dinteger_t |
216 typedef uint64_t integer_t; | 308 //typedef uint64_t integer_t; |
309 typedef uint64_t dinteger_t; // use this instead of integer_t to | |
310 // avoid conflicts with system #include's | |
217 | 311 |
218 // Signed and unsigned variants | 312 // Signed and unsigned variants |
219 typedef int64_t sinteger_t; | 313 typedef int64_t sinteger_t; |
220 typedef uint64_t uinteger_t; | 314 typedef uint64_t uinteger_t; |
221 | 315 |
222 typedef int8_t d_int8; | 316 typedef int8_t d_int8; |
223 typedef uint8_t d_uns8; | 317 typedef uint8_t d_uns8; |
224 typedef int16_t d_int16; | 318 typedef int16_t d_int16; |
225 typedef uint16_t d_uns16; | 319 typedef uint16_t d_uns16; |
226 typedef int32_t d_int32; | 320 typedef int32_t d_int32; |
227 typedef uint32_t d_uns32; | 321 typedef uint32_t d_uns32; |
228 typedef int64_t d_int64; | 322 typedef int64_t d_int64; |
229 typedef uint64_t d_uns64; | 323 typedef uint64_t d_uns64; |
230 | 324 |
231 typedef float d_float32; | 325 typedef float d_float32; |
232 typedef double d_float64; | 326 typedef double d_float64; |
233 typedef long double d_float80; | 327 typedef long double d_float80; |
234 | 328 |
235 typedef d_uns8 d_char; | 329 typedef d_uns8 d_char; |
236 typedef d_uns16 d_wchar; | 330 typedef d_uns16 d_wchar; |
237 typedef d_uns32 d_dchar; | 331 typedef d_uns32 d_dchar; |
238 | 332 |
239 #ifdef IN_GCC | 333 #ifdef IN_GCC |
240 #include "d-gcc-real.h" | 334 #include "d-gcc-real.h" |
241 #else | 335 #else |
242 typedef long double real_t; | 336 typedef long double real_t; |
252 | 346 |
253 #ifdef IN_GCC | 347 #ifdef IN_GCC |
254 #include "d-gcc-complex_t.h" | 348 #include "d-gcc-complex_t.h" |
255 #endif | 349 #endif |
256 | 350 |
257 // taken from GDC | |
258 // for handling printf incompatibilities | |
259 #if __MSVCRT__ | |
260 #define PRIuSIZE "Iu" | |
261 #define PRIxSIZE "Ix" | |
262 #elif __MINGW32__ | |
263 #define PRIuSIZE "u" | |
264 #define PRIxSIZE "x" | |
265 #else | |
266 #define PRIuSIZE "zu" | |
267 #define PRIxSIZE "zx" | |
268 #endif | |
269 | |
270 struct Module; | 351 struct Module; |
271 | 352 |
272 //typedef unsigned Loc; // file location | 353 //typedef unsigned Loc; // file location |
273 struct Loc | 354 struct Loc |
274 { | 355 { |
275 char *filename; | 356 const char *filename; |
276 unsigned linnum; | 357 unsigned linnum; |
277 | 358 |
278 Loc() | 359 Loc() |
279 { | 360 { |
280 linnum = 0; | 361 linnum = 0; |
281 filename = NULL; | 362 filename = NULL; |
282 } | 363 } |
283 | 364 |
284 Loc(int x) | 365 Loc(int x) |
285 { | 366 { |
286 linnum = x; | 367 linnum = x; |
287 filename = NULL; | 368 filename = NULL; |
288 } | 369 } |
289 | 370 |
290 Loc(Module *mod, unsigned linnum); | 371 Loc(Module *mod, unsigned linnum); |
291 | 372 |
292 char *toChars() const; | 373 char *toChars(); |
374 bool equals(const Loc& loc); | |
293 }; | 375 }; |
294 | 376 |
295 #ifndef GCC_SAFE_DMD | 377 #ifndef GCC_SAFE_DMD |
296 #define TRUE 1 | 378 #define TRUE 1 |
297 #define FALSE 0 | 379 #define FALSE 0 |
298 #endif | 380 #endif |
299 | 381 |
300 #define INTERFACE_OFFSET 0 // if 1, put classinfo as first entry | 382 #define INTERFACE_OFFSET 0 // if 1, put classinfo as first entry |
301 // in interface vtbl[]'s | 383 // in interface vtbl[]'s |
302 #define INTERFACE_VIRTUAL 0 // 1 means if an interface appears | 384 #define INTERFACE_VIRTUAL 0 // 1 means if an interface appears |
303 // in the inheritance graph multiple | 385 // in the inheritance graph multiple |
304 // times, only one is used | 386 // times, only one is used |
305 | 387 |
306 enum LINK | 388 enum LINK |
307 { | 389 { |
308 LINKdefault, | 390 LINKdefault, |
309 LINKd, | 391 LINKd, |
310 LINKc, | 392 LINKc, |
311 LINKcpp, | 393 LINKcpp, |
312 LINKwindows, | 394 LINKwindows, |
313 LINKpascal, | 395 LINKpascal, |
314 | 396 |
315 // LDC | 397 #if IN_LLVM |
316 LINKintrinsic, | 398 LINKintrinsic, |
399 #endif | |
317 }; | 400 }; |
318 | 401 |
319 enum DYNCAST | 402 enum DYNCAST |
320 { | 403 { |
321 DYNCAST_OBJECT, | 404 DYNCAST_OBJECT, |
326 DYNCAST_TUPLE, | 409 DYNCAST_TUPLE, |
327 }; | 410 }; |
328 | 411 |
329 enum MATCH | 412 enum MATCH |
330 { | 413 { |
331 MATCHnomatch, // no match | 414 MATCHnomatch, // no match |
332 MATCHconvert, // match with conversions | 415 MATCHconvert, // match with conversions |
333 #if DMDV2 | 416 #if DMDV2 |
334 MATCHconst, // match with conversion to const | 417 MATCHconst, // match with conversion to const |
335 #endif | 418 #endif |
336 MATCHexact // exact match | 419 MATCHexact // exact match |
337 }; | 420 }; |
338 | 421 |
339 void error(Loc loc, const char *format, ...); | 422 void warning(Loc loc, const char *format, ...) IS_PRINTF(2); |
423 void vwarning(Loc loc, const char *format, va_list); | |
424 void error(Loc loc, const char *format, ...) IS_PRINTF(2); | |
340 void verror(Loc loc, const char *format, va_list); | 425 void verror(Loc loc, const char *format, va_list); |
341 void fatal(); | 426 void fatal(); |
342 void err_nomem(); | 427 void err_nomem(); |
428 #if IN_LLVM | |
343 void inifile(char *argv0, const char *inifile); | 429 void inifile(char *argv0, const char *inifile); |
430 #else | |
431 int runLINK(); | |
432 void deleteExeFile(); | |
433 int runProgram(); | |
434 void inifile(const char *argv0, const char *inifile); | |
435 #endif | |
344 void halt(); | 436 void halt(); |
437 #if !IN_LLVM | |
438 void util_progress(); | |
439 #endif | |
345 | 440 |
346 /*** Where to send error messages ***/ | 441 /*** Where to send error messages ***/ |
347 #if IN_GCC || IN_LLVM | 442 #if IN_GCC || IN_LLVM |
348 #define stdmsg stderr | 443 #define stdmsg stderr |
349 #else | 444 #else |
350 #define stdmsg stdout | 445 #define stdmsg stdout |
351 #endif | 446 #endif |
352 | 447 |
448 #if !IN_LLVM | |
449 struct Dsymbol; | |
450 struct Library; | |
451 struct File; | |
452 void obj_start(char *srcfile); | |
453 void obj_end(Library *library, File *objfile); | |
454 void obj_append(Dsymbol *s); | |
455 void obj_write_deferred(Library *library); | |
456 #endif | |
457 | |
353 #endif /* DMD_MARS_H */ | 458 #endif /* DMD_MARS_H */ |