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>
|
|
19 #include <string>
|
|
20 #include <cstdarg>
|
|
21
|
|
22 #ifdef __DMC__
|
|
23 #ifdef DEBUG
|
|
24 #undef assert
|
|
25 #define assert(e) (static_cast<void>((e) || (printf("assert %s(%d) %s\n", __FILE__, __LINE__, #e), halt())))
|
|
26 #endif
|
|
27 #endif
|
|
28
|
|
29 #ifdef IN_GCC
|
|
30 /* Changes for the GDC compiler by David Friedman */
|
|
31 #endif
|
|
32
|
|
33 #define V2 0 // Version 2.0 features
|
|
34 #define BREAKABI 1 // 0 if not ready to break the ABI just yet
|
|
35
|
|
36 struct Array;
|
|
37
|
|
38 // Put command line switches in here
|
|
39 struct Param
|
|
40 {
|
|
41 char obj; // write object file
|
|
42 char link; // perform link
|
|
43 char trace; // insert profiling hooks
|
|
44 char quiet; // suppress non-error messages
|
|
45 char verbose; // verbose compile
|
|
46 char symdebug; // insert debug symbolic information
|
|
47 char optimize; // run optimizer
|
|
48 char optimizeLevel; // optimization level
|
|
49 char cpu; // target CPU
|
|
50 char is64bit; // generate 64 bit code
|
|
51 char isLE; // generate little endian code
|
|
52 char isLinux; // generate code for linux
|
|
53 char isWindows; // generate code for Windows
|
|
54 char scheduler; // which scheduler to use
|
|
55 char useDeprecated; // allow use of deprecated features
|
|
56 char useAssert; // generate runtime code for assert()'s
|
|
57 char useInvariants; // generate class invariant checks
|
|
58 char useIn; // generate precondition checks
|
|
59 char useOut; // generate postcondition checks
|
|
60 char useArrayBounds; // generate array bounds checks
|
|
61 char useSwitchError; // check for switches without a default
|
|
62 char useUnitTests; // generate unittest code
|
|
63 char useInline; // inline expand functions
|
|
64 char release; // build release version
|
|
65 char preservePaths; // !=0 means don't strip path from source file
|
|
66 char warnings; // enable warnings
|
|
67 char pic; // generate position-independent-code for shared libs
|
|
68 char cov; // generate code coverage data
|
|
69 char nofloat; // code should not pull in floating point support
|
|
70 char noruntime; // code is not allowed to make implicit calls to the runtime
|
|
71 char novalidate;// no bitcode validation
|
|
72 char Dversion; // D version number
|
|
73 char ignoreUnsupportedPragmas; // rather than error on them
|
|
74
|
|
75 char *argv0; // program name
|
|
76 Array *imppath; // array of char*'s of where to look for import modules
|
|
77 Array *fileImppath; // array of char*'s of where to look for file import modules
|
|
78 char *runtimeImppath; // char* of where to look for the core runtime
|
|
79 char *objdir; // .obj file output directory
|
|
80 char *objname; // .obj file output name
|
|
81
|
|
82 char doDocComments; // process embedded documentation comments
|
|
83 char *docdir; // write documentation file to docdir directory
|
|
84 char *docname; // write documentation file to docname
|
|
85 Array *ddocfiles; // macro include files for Ddoc
|
|
86
|
|
87 char doHdrGeneration; // process embedded documentation comments
|
|
88 char *hdrdir; // write 'header' file to docdir directory
|
|
89 char *hdrname; // write 'header' file to docname
|
|
90
|
|
91 unsigned debuglevel; // debug level
|
|
92 Array *debugids; // debug identifiers
|
|
93
|
|
94 unsigned versionlevel; // version level
|
|
95 Array *versionids; // version identifiers
|
|
96
|
|
97 bool dump_source;
|
|
98
|
|
99 char *defaultlibname; // default library for non-debug builds
|
|
100 char *debuglibname; // default library for debug builds
|
|
101
|
|
102 char *xmlname; // filename for XML output
|
|
103
|
|
104 // Hidden debug switches
|
|
105 char debuga;
|
|
106 char debugb;
|
|
107 char debugc;
|
|
108 char debugf;
|
|
109 char debugr;
|
|
110 char debugw;
|
|
111 char debugx;
|
|
112 char debugy;
|
|
113
|
|
114 char run; // run resulting executable
|
|
115 size_t runargs_length;
|
|
116 char** runargs; // arguments for executable
|
|
117
|
|
118 // Linker stuff
|
|
119 Array *objfiles;
|
|
120 Array *linkswitches;
|
|
121 Array *libfiles;
|
|
122 char *deffile;
|
|
123 char *resfile;
|
|
124 char *exefile;
|
|
125
|
|
126 // LLVM stuff
|
|
127 char *llvmArch;
|
|
128 char forceBE;
|
|
129 char *tt_arch;
|
|
130 char *tt_os;
|
|
131 char *data_layout;
|
|
132 char disassemble;
|
|
133 char llvmInline;
|
|
134 char llvmAnnotate;
|
|
135 char *runtimePath;
|
|
136 };
|
|
137
|
|
138 struct Global
|
|
139 {
|
|
140 char *mars_ext;
|
|
141 char *sym_ext;
|
|
142 char *obj_ext;
|
|
143 char *ll_ext;
|
|
144 char *bc_ext;
|
|
145 char *nativeobj_ext;
|
|
146 char *doc_ext; // for Ddoc generated files
|
|
147 char *ddoc_ext; // for Ddoc macro include files
|
|
148 char *hdr_ext; // for D 'header' import files
|
|
149 char *copyright;
|
|
150 char *written;
|
|
151 Array *path; // Array of char*'s which form the import lookup path
|
|
152 Array *filePath; // Array of char*'s which form the file import lookup path
|
|
153 int structalign;
|
|
154 char *version;
|
|
155 char *llvmdc_version;
|
|
156
|
|
157 Param params;
|
|
158 unsigned errors; // number of errors reported so far
|
|
159 unsigned gag; // !=0 means gag reporting of errors
|
|
160
|
|
161 Global();
|
|
162 };
|
|
163
|
|
164 extern Global global;
|
|
165
|
|
166 #if __GNUC__
|
|
167 //#define memicmp strncasecmp
|
|
168 //#define stricmp strcasecmp
|
|
169 #endif
|
|
170
|
|
171 #ifdef __DMC__
|
|
172 typedef _Complex long double complex_t;
|
|
173 #else
|
|
174 #ifndef IN_GCC
|
|
175 #include "complex_t.h"
|
|
176 #endif
|
|
177 #ifdef __APPLE__
|
|
178 //#include "complex.h"//This causes problems with include the c++ <complex> and not the C "complex.h"
|
|
179 #define integer_t dmd_integer_t
|
|
180 #endif
|
|
181 #endif
|
|
182
|
|
183 // Be careful not to care about sign when using integer_t
|
|
184 typedef uint64_t integer_t;
|
|
185
|
|
186 // Signed and unsigned variants
|
|
187 typedef int64_t sinteger_t;
|
|
188 typedef uint64_t uinteger_t;
|
|
189
|
|
190 typedef int8_t d_int8;
|
|
191 typedef uint8_t d_uns8;
|
|
192 typedef int16_t d_int16;
|
|
193 typedef uint16_t d_uns16;
|
|
194 typedef int32_t d_int32;
|
|
195 typedef uint32_t d_uns32;
|
|
196 typedef int64_t d_int64;
|
|
197 typedef uint64_t d_uns64;
|
|
198
|
|
199 typedef float d_float32;
|
|
200 typedef double d_float64;
|
|
201 typedef long double d_float80;
|
|
202
|
|
203 typedef d_uns8 d_char;
|
|
204 typedef d_uns16 d_wchar;
|
|
205 typedef d_uns32 d_dchar;
|
|
206
|
|
207 #ifdef IN_GCC
|
|
208 #include "d-gcc-real.h"
|
|
209 #else
|
|
210 typedef long double real_t;
|
|
211 #endif
|
|
212
|
|
213 // Modify OutBuffer::writewchar to write the correct size of wchar
|
|
214 #if _WIN32
|
|
215 #define writewchar writeword
|
|
216 #else
|
|
217 // This needs a configuration test...
|
|
218 #define writewchar write4
|
|
219 #endif
|
|
220
|
|
221 #ifdef IN_GCC
|
|
222 #include "d-gcc-complex_t.h"
|
|
223 #endif
|
|
224
|
|
225 struct Module;
|
|
226
|
|
227 //typedef unsigned Loc; // file location
|
|
228 struct Loc
|
|
229 {
|
|
230 char *filename;
|
|
231 unsigned linnum;
|
|
232
|
|
233 Loc()
|
|
234 {
|
|
235 linnum = 0;
|
|
236 filename = NULL;
|
|
237 }
|
|
238
|
|
239 Loc(int x)
|
|
240 {
|
|
241 linnum = x;
|
|
242 filename = NULL;
|
|
243 }
|
|
244
|
|
245 Loc(Module *mod, unsigned linnum);
|
|
246
|
|
247 char *toChars() const;
|
|
248 };
|
|
249
|
|
250 #ifndef GCC_SAFE_DMD
|
|
251 #define TRUE 1
|
|
252 #define FALSE 0
|
|
253 #endif
|
|
254
|
|
255 #define INTERFACE_OFFSET 0 // if 1, put classinfo as first entry
|
|
256 // in interface vtbl[]'s
|
|
257 #define INTERFACE_VIRTUAL 0 // 1 means if an interface appears
|
|
258 // in the inheritance graph multiple
|
|
259 // times, only one is used
|
|
260
|
|
261 enum LINK
|
|
262 {
|
|
263 LINKdefault,
|
|
264 LINKd,
|
|
265 LINKc,
|
|
266 LINKcpp,
|
|
267 LINKwindows,
|
|
268 LINKpascal,
|
|
269 };
|
|
270
|
|
271 enum DYNCAST
|
|
272 {
|
|
273 DYNCAST_OBJECT,
|
|
274 DYNCAST_EXPRESSION,
|
|
275 DYNCAST_DSYMBOL,
|
|
276 DYNCAST_TYPE,
|
|
277 DYNCAST_IDENTIFIER,
|
|
278 DYNCAST_TUPLE,
|
|
279 };
|
|
280
|
|
281 enum MATCH
|
|
282 {
|
|
283 MATCHnomatch, // no match
|
|
284 MATCHconvert, // match with conversions
|
|
285 #if V2
|
|
286 MATCHconst, // match with conversion to const
|
|
287 #endif
|
|
288 MATCHexact // exact match
|
|
289 };
|
|
290
|
|
291 void error(Loc loc, const char *format, ...);
|
|
292 void verror(Loc loc, const char *format, va_list);
|
|
293 void fatal();
|
|
294 void err_nomem();
|
|
295 int runLINK();
|
|
296 void deleteExeFile();
|
|
297 int runProgram();
|
|
298 void inifile(char *argv0, char *inifile);
|
|
299 void halt();
|
|
300
|
|
301 /*** Where to send error messages ***/
|
|
302 #if IN_GCC
|
|
303 #define stdmsg stderr
|
|
304 #else
|
|
305 #define stdmsg stdout
|
|
306 #endif
|
|
307
|
|
308 #endif /* DMD_MARS_H */
|