Mercurial > projects > ldc
comparison dmd2/mars.h @ 988:2667e3a145be
- Fixed LLVM style CL args for D2.
- Moved main() into its own file gen/main.cpp
- Fixed basic cross compilation
- removed the option for setting OS
- added support for llc's mattr, mcpu and mtriple switches
- added basic ABI abstraction for return value rewrites, it's not perfect and will probably be completely rewritten once I get to handling parameter rewrites as well.
- x86-64 extern(C) abi for cfloat returns now match (llvm-)gcc.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Thu, 26 Feb 2009 14:11:49 +0100 |
parents | a4fcc13da3cd |
children | f0b6549055ab |
comparison
equal
deleted
inserted
replaced
987:73ff89728d85 | 988:2667e3a145be |
---|---|
15 #pragma once | 15 #pragma once |
16 #endif /* __DMC__ */ | 16 #endif /* __DMC__ */ |
17 | 17 |
18 #include <stdint.h> | 18 #include <stdint.h> |
19 #include <stdarg.h> | 19 #include <stdarg.h> |
20 #include <stddef.h> | |
20 #define __STDC_FORMAT_MACROS 1 | 21 #define __STDC_FORMAT_MACROS 1 |
21 #include <inttypes.h> | 22 #include <inttypes.h> |
22 #include <stdarg.h> | 23 #include <stdarg.h> |
23 | 24 |
24 #ifdef __DMC__ | 25 #ifdef __DMC__ |
30 | 31 |
31 #ifdef IN_GCC | 32 #ifdef IN_GCC |
32 /* Changes for the GDC compiler by David Friedman */ | 33 /* Changes for the GDC compiler by David Friedman */ |
33 #endif | 34 #endif |
34 | 35 |
35 #define BREAKABI 1 // 0 if not ready to break the ABI just yet | 36 #define BREAKABI 1 // 0 if not ready to break the ABI just yet |
36 #define STRUCTTHISREF V2 // if 'this' for struct is a reference, not a pointer | 37 #define STRUCTTHISREF V2 // if 'this' for struct is a reference, not a pointer |
37 | 38 |
38 struct Array; | 39 struct Array; |
39 | 40 |
40 // LDC | 41 // LDC |
41 enum ARCH | 42 enum ARCH |
70 #define TYPEINFO_LINKAGE_TYPE llvm::GlobalValue::LinkOnceLinkage | 71 #define TYPEINFO_LINKAGE_TYPE llvm::GlobalValue::LinkOnceLinkage |
71 | 72 |
72 // Put command line switches in here | 73 // Put command line switches in here |
73 struct Param | 74 struct Param |
74 { | 75 { |
75 char obj; // write object file | 76 bool obj; // write object file |
76 char link; // perform link | 77 bool link; // perform link |
77 char lib; // write library file instead of object file(s) | 78 bool verbose; // verbose compile |
78 char multiobj; // break one object file into multiple ones | 79 char symdebug; // insert debug symbolic information |
79 char oneobj; // write one object file instead of multiple ones | 80 bool optimize; // run optimizer |
80 char trace; // insert profiling hooks | |
81 char quiet; // suppress non-error messages | |
82 char verbose; // verbose compile | |
83 char symdebug; // insert debug symbolic information | |
84 char optimize; // run optimizer | |
85 char optimizeLevel; // optimization level | 81 char optimizeLevel; // optimization level |
86 ARCH cpu; // target CPU | 82 ARCH cpu; // target CPU |
87 OS os; // target OS | 83 OS os; // target OS |
88 char is64bit; // generate 64 bit code | 84 bool is64bit; // generate 64 bit code |
89 char isLE; // generate little endian code | 85 bool isLE; // generate little endian code |
90 char scheduler; // which scheduler to use | 86 bool useDeprecated; // allow use of deprecated features |
91 char useDeprecated; // allow use of deprecated features | 87 bool useAssert; // generate runtime code for assert()'s |
92 char useAssert; // generate runtime code for assert()'s | 88 bool useInvariants; // generate class invariant checks |
93 char useInvariants; // generate class invariant checks | 89 bool useIn; // generate precondition checks |
94 char useIn; // generate precondition checks | 90 bool useOut; // generate postcondition checks |
95 char useOut; // generate postcondition checks | 91 bool useArrayBounds; // generate array bounds checks |
96 char useArrayBounds; // generate array bounds checks | 92 bool useSwitchError; // check for switches without a default |
97 char useSwitchError; // check for switches without a default | 93 bool useUnitTests; // generate unittest code |
98 char useUnitTests; // generate unittest code | 94 bool useInline; // inline expand functions |
99 char useInline; // inline expand functions | 95 bool warnings; // enable warnings |
100 char release; // build release version | 96 bool safe; // enforce safe memory model |
101 char preservePaths; // !=0 means don't strip path from source file | 97 char Dversion; // D version number |
102 char warnings; // enable warnings | 98 |
103 char pic; // generate position-independent-code for shared libs | 99 char *argv0; // program name |
104 char noruntime; // code is not allowed to make implicit calls to the runtime | 100 Array *imppath; // array of char*'s of where to look for import modules |
105 char novalidate;// no bitcode validation | 101 Array *fileImppath; // array of char*'s of where to look for file import modules |
106 char Dversion; // D version number | 102 char *objdir; // .obj file output directory |
107 char ignoreUnsupportedPragmas; // rather than error on them | 103 char *objname; // .obj file output name |
108 char safe; // enforce safe memory model | 104 |
109 | 105 bool doDocComments; // process embedded documentation comments |
110 char *argv0; // program name | 106 char *docdir; // write documentation file to docdir directory |
111 Array *imppath; // array of char*'s of where to look for import modules | 107 char *docname; // write documentation file to docname |
112 Array *fileImppath; // array of char*'s of where to look for file import modules | 108 Array *ddocfiles; // macro include files for Ddoc |
113 char *runtimeImppath; // char* of where to look for the core runtime | 109 |
114 char *objdir; // .obj file output directory | 110 bool doHdrGeneration; // process embedded documentation comments |
115 char *objname; // .obj file output name | 111 char *hdrdir; // write 'header' file to docdir directory |
116 | 112 char *hdrname; // write 'header' file to docname |
117 char doDocComments; // process embedded documentation comments | 113 |
118 char *docdir; // write documentation file to docdir directory | 114 unsigned debuglevel; // debug level |
119 char *docname; // write documentation file to docname | 115 Array *debugids; // debug identifiers |
120 Array *ddocfiles; // macro include files for Ddoc | 116 |
121 | 117 unsigned versionlevel; // version level |
122 char doHdrGeneration; // process embedded documentation comments | 118 Array *versionids; // version identifiers |
123 char *hdrdir; // write 'header' file to docdir directory | |
124 char *hdrname; // write 'header' file to docname | |
125 | |
126 unsigned debuglevel; // debug level | |
127 Array *debugids; // debug identifiers | |
128 | |
129 unsigned versionlevel; // version level | |
130 Array *versionids; // version identifiers | |
131 | 119 |
132 bool dump_source; | 120 bool dump_source; |
133 | 121 |
134 Array *defaultlibnames; // default libraries for non-debug builds | 122 Array *defaultlibnames; // default libraries for non-debug builds |
135 Array *debuglibnames; // default libraries for debug builds | 123 Array *debuglibnames; // default libraries for debug builds |
136 | 124 |
137 const char *xmlname; // filename for XML output | 125 char *xmlname; // filename for XML output |
138 | 126 |
139 // Hidden debug switches | 127 // Hidden debug switches |
140 char debuga; | 128 bool debuga; |
141 char debugb; | 129 bool debugb; |
142 char debugc; | 130 bool debugc; |
143 char debugf; | 131 bool debugf; |
144 char debugr; | 132 bool debugr; |
145 char debugw; | 133 bool debugw; |
146 char debugx; | 134 bool debugx; |
147 char debugy; | 135 bool debugy; |
148 | 136 |
149 char run; // run resulting executable | 137 bool run; // run resulting executable |
150 size_t runargs_length; | |
151 char** runargs; // arguments for executable | |
152 | 138 |
153 // Linker stuff | 139 // Linker stuff |
154 Array *objfiles; | 140 Array *objfiles; |
155 Array *linkswitches; | 141 Array *linkswitches; |
156 Array *libfiles; | 142 Array *libfiles; |
157 char *deffile; | 143 char *deffile; |
158 char *resfile; | 144 char *resfile; |
159 char *exefile; | 145 char *exefile; |
160 | 146 |
161 // LDC stuff | 147 // LDC stuff |
162 const char *llvmArch; | 148 OUTPUTFLAG output_ll; |
163 char forceBE; | 149 OUTPUTFLAG output_bc; |
164 char output_ll; | 150 OUTPUTFLAG output_s; |
165 char output_bc; | 151 OUTPUTFLAG output_o; |
166 char output_s; | 152 bool llvmInline; |
167 char output_o; | 153 bool llvmAnnotate; |
168 char llvmInline; | 154 bool useInlineAsm; |
169 char llvmAnnotate; | |
170 char useInlineAsm; | |
171 char fqnNames; // use fully qualified object names | |
172 char noDefaultLib; | |
173 | 155 |
174 // target stuff | 156 // target stuff |
157 const char* llvmArch; | |
175 const char *targetTriple; | 158 const char *targetTriple; |
176 const char *dataLayout; | 159 const char *dataLayout; |
177 }; | 160 }; |
178 | 161 |
179 struct Global | 162 struct Global |
180 { | 163 { |
181 const char *mars_ext; | 164 char *mars_ext; |
182 const char *sym_ext; | 165 char *sym_ext; |
183 const char *obj_ext; | 166 char *obj_ext; |
184 #if _WIN32 | 167 #if _WIN32 |
185 const char *obj_ext_alt; | 168 char *obj_ext_alt; |
186 #endif | 169 #endif |
187 const char *ll_ext; | 170 char *ll_ext; |
188 const char *bc_ext; | 171 char *bc_ext; |
189 const char *s_ext; | 172 char *s_ext; |
190 const char *lib_ext; | 173 char *doc_ext; // for Ddoc generated files |
191 const char *doc_ext; // for Ddoc generated files | 174 char *ddoc_ext; // for Ddoc macro include files |
192 const char *ddoc_ext; // for Ddoc macro include files | 175 char *hdr_ext; // for D 'header' import files |
193 const char *hdr_ext; // for D 'header' import files | 176 char *copyright; |
194 const char *copyright; | 177 char *written; |
195 const char *written; | 178 Array *path; // Array of char*'s which form the import lookup path |
196 Array *path; // Array of char*'s which form the import lookup path | 179 Array *filePath; // Array of char*'s which form the file import lookup path |
197 Array *filePath; // Array of char*'s which form the file import lookup path | |
198 int structalign; | 180 int structalign; |
199 const char *version; | 181 char *version; |
200 const char *ldc_version; | 182 char *ldc_version; |
201 const char *llvm_version; | 183 char *llvm_version; |
202 | 184 |
203 Param params; | 185 Param params; |
204 unsigned errors; // number of errors reported so far | 186 unsigned errors; // number of errors reported so far |
205 unsigned gag; // !=0 means gag reporting of errors | 187 unsigned gag; // !=0 means gag reporting of errors |
206 | 188 |
207 Global(); | 189 Global(); |
208 }; | 190 }; |
209 | 191 |
210 extern Global global; | 192 extern Global global; |
211 | 193 |
212 /* Set if Windows Structured Exception Handling C extensions are supported. | 194 /* Set if Windows Structured Exception Handling C extensions are supported. |
213 * Apparently, VC has dropped support for these? | 195 * Apparently, VC has dropped support for these? |
214 */ | 196 */ |
215 #define WINDOWS_SEH _WIN32 && __DMC__ | 197 #define WINDOWS_SEH (_WIN32 && __DMC__) |
216 | 198 |
217 | 199 |
218 #if __GNUC__ | 200 #if __GNUC__ |
219 //#define memicmp strncasecmp | 201 //#define memicmp strncasecmp |
220 //#define stricmp strcasecmp | 202 //#define stricmp strcasecmp |
237 | 219 |
238 // Signed and unsigned variants | 220 // Signed and unsigned variants |
239 typedef int64_t sinteger_t; | 221 typedef int64_t sinteger_t; |
240 typedef uint64_t uinteger_t; | 222 typedef uint64_t uinteger_t; |
241 | 223 |
242 typedef int8_t d_int8; | 224 typedef int8_t d_int8; |
243 typedef uint8_t d_uns8; | 225 typedef uint8_t d_uns8; |
244 typedef int16_t d_int16; | 226 typedef int16_t d_int16; |
245 typedef uint16_t d_uns16; | 227 typedef uint16_t d_uns16; |
246 typedef int32_t d_int32; | 228 typedef int32_t d_int32; |
247 typedef uint32_t d_uns32; | 229 typedef uint32_t d_uns32; |
248 typedef int64_t d_int64; | 230 typedef int64_t d_int64; |
249 typedef uint64_t d_uns64; | 231 typedef uint64_t d_uns64; |
250 | 232 |
251 typedef float d_float32; | 233 typedef float d_float32; |
252 typedef double d_float64; | 234 typedef double d_float64; |
253 typedef long double d_float80; | 235 typedef long double d_float80; |
254 | 236 |
255 typedef d_uns8 d_char; | 237 typedef d_uns8 d_char; |
256 typedef d_uns16 d_wchar; | 238 typedef d_uns16 d_wchar; |
257 typedef d_uns32 d_dchar; | 239 typedef d_uns32 d_dchar; |
258 | 240 |
259 #ifdef IN_GCC | 241 #ifdef IN_GCC |
260 #include "d-gcc-real.h" | 242 #include "d-gcc-real.h" |
261 #else | 243 #else |
262 typedef long double real_t; | 244 typedef long double real_t; |
287 #define PRIxSIZE "zx" | 269 #define PRIxSIZE "zx" |
288 #endif | 270 #endif |
289 | 271 |
290 struct Module; | 272 struct Module; |
291 | 273 |
292 //typedef unsigned Loc; // file location | 274 //typedef unsigned Loc; // file location |
293 struct Loc | 275 struct Loc |
294 { | 276 { |
295 char *filename; | 277 char *filename; |
296 unsigned linnum; | 278 unsigned linnum; |
297 | 279 |
298 Loc() | 280 Loc() |
299 { | 281 { |
300 linnum = 0; | 282 linnum = 0; |
301 filename = NULL; | 283 filename = NULL; |
302 } | 284 } |
303 | 285 |
304 Loc(int x) | 286 Loc(int x) |
305 { | 287 { |
306 linnum = x; | 288 linnum = x; |
307 filename = NULL; | 289 filename = NULL; |
308 } | 290 } |
309 | 291 |
310 Loc(Module *mod, unsigned linnum); | 292 Loc(Module *mod, unsigned linnum); |
311 | 293 |
312 char *toChars() const; | 294 char *toChars() const; |
313 }; | 295 }; |
314 | 296 |
315 #ifndef GCC_SAFE_DMD | 297 #ifndef GCC_SAFE_DMD |
316 #define TRUE 1 | 298 #define TRUE 1 |
317 #define FALSE 0 | 299 #define FALSE 0 |
318 #endif | 300 #endif |
319 | 301 |
320 #define INTERFACE_OFFSET 0 // if 1, put classinfo as first entry | 302 #define INTERFACE_OFFSET 0 // if 1, put classinfo as first entry |
321 // in interface vtbl[]'s | 303 // in interface vtbl[]'s |
322 #define INTERFACE_VIRTUAL 0 // 1 means if an interface appears | 304 #define INTERFACE_VIRTUAL 0 // 1 means if an interface appears |
323 // in the inheritance graph multiple | 305 // in the inheritance graph multiple |
324 // times, only one is used | 306 // times, only one is used |
325 | 307 |
326 enum LINK | 308 enum LINK |
327 { | 309 { |
328 LINKdefault, | 310 LINKdefault, |
329 LINKd, | 311 LINKd, |
346 DYNCAST_TUPLE, | 328 DYNCAST_TUPLE, |
347 }; | 329 }; |
348 | 330 |
349 enum MATCH | 331 enum MATCH |
350 { | 332 { |
351 MATCHnomatch, // no match | 333 MATCHnomatch, // no match |
352 MATCHconvert, // match with conversions | 334 MATCHconvert, // match with conversions |
353 #if DMDV2 | 335 #if DMDV2 |
354 MATCHconst, // match with conversion to const | 336 MATCHconst, // match with conversion to const |
355 #endif | 337 #endif |
356 MATCHexact // exact match | 338 MATCHexact // exact match |
357 }; | 339 }; |
358 | 340 |
359 void error(Loc loc, const char *format, ...); | 341 void error(Loc loc, const char *format, ...); |
360 void verror(Loc loc, const char *format, va_list); | 342 void verror(Loc loc, const char *format, va_list); |
361 void fatal(); | 343 void fatal(); |
362 void err_nomem(); | 344 void err_nomem(); |
363 void inifile(const char *argv0, const char *inifile); | 345 void inifile(char *argv0, const char *inifile); |
364 void halt(); | 346 void halt(); |
365 | 347 |
366 /*** Where to send error messages ***/ | 348 /*** Where to send error messages ***/ |
367 #if IN_GCC || IN_LLVM | 349 #if IN_GCC || IN_LLVM |
368 #define stdmsg stderr | 350 #define stdmsg stderr |