root/trunk/src/mars.h

Revision 559, 12.4 kB (checked in by walter, 2 years ago)

bugzilla 4080 Patch for building dynamic libraries on Mac OS X

  • Property svn:eol-style set to native
Line 
1 // Compiler implementation of the D programming language
2 // Copyright (c) 1999-2010 by Digital Mars
3 // All Rights Reserved
4 // written by Walter Bright
5 // http://www.digitalmars.com
6 // License for redistribution is by either the Artistic License
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
8 // See the included readme.txt for details.
9
10 #ifndef DMD_MARS_H
11 #define DMD_MARS_H
12
13 #ifdef __DMC__
14 #pragma once
15 #endif
16
17 /*
18 It is very important to use version control macros correctly - the
19 idea is that host and target are independent. If these are done
20 correctly, cross compilers can be built.
21 The host compiler and host operating system are also different,
22 and are predefined by the host compiler. The ones used in
23 dmd are:
24
25 Macros defined by the compiler, not the code:
26
27     Compiler:
28         __DMC__         Digital Mars compiler
29         _MSC_VER        Microsoft compiler
30         __GNUC__        Gnu compiler
31
32     Host operating system:
33         _WIN32          Microsoft NT, Windows 95, Windows 98, Win32s,
34                         Windows 2000, Win XP, Vista
35         _WIN64          Windows for AMD64
36         linux           Linux
37         __APPLE__       Mac OSX
38         __FreeBSD__     FreeBSD
39         __sun&&__SVR4   Solaris, OpenSolaris (yes, both macros are necessary)
40
41 For the target systems, there are the target operating system and
42 the target object file format:
43
44     Target operating system:
45         TARGET_WINDOS   Covers 32 bit windows and 64 bit windows
46         TARGET_LINUX    Covers 32 and 64 bit linux
47         TARGET_OSX      Covers 32 and 64 bit Mac OSX
48         TARGET_FREEBSD  Covers 32 and 64 bit FreeBSD
49         TARGET_SOLARIS  Covers 32 and 64 bit Solaris
50         TARGET_NET      Covers .Net
51
52     It is expected that the compiler for each platform will be able
53     to generate 32 and 64 bit code from the same compiler binary.
54
55     Target object module format:
56         OMFOBJ          Intel Object Module Format, used on Windows
57         ELFOBJ          Elf Object Module Format, used on linux, FreeBSD and Solaris
58         MACHOBJ         Mach-O Object Module Format, used on Mac OSX
59
60     There are currently no macros for byte endianness order.
61  */
62
63
64 #include <stdio.h>
65 #include <stdint.h>
66 #include <stdarg.h>
67
68 #ifdef __DMC__
69 #ifdef DEBUG
70 #undef assert
71 #define assert(e) (static_cast<void>((e) || (printf("assert %s(%d) %s\n", __FILE__, __LINE__, #e), halt())))
72 #endif
73 #endif
74
75 #ifdef DEBUG
76 #define UNITTEST 1
77 #endif
78 void unittests();
79
80 #ifdef IN_GCC
81 /* Changes for the GDC compiler by David Friedman */
82 #endif
83
84 #define DMDV1   0
85 #define DMDV2   1       // Version 2.0 features
86 #define BREAKABI 1      // 0 if not ready to break the ABI just yet
87 #define STRUCTTHISREF DMDV2     // if 'this' for struct is a reference, not a pointer
88 #define SNAN_DEFAULT_INIT DMDV2 // if floats are default initialized to signalling NaN
89 #define SARRAYVALUE DMDV2       // static arrays are value types
90 #define MODULEINFO_IS_STRUCT DMDV2   // if ModuleInfo is a struct rather than a class
91
92 // Set if C++ mangling is done by the front end
93 #define CPP_MANGLE (DMDV2 && (TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS))
94
95 /* Other targets are TARGET_LINUX, TARGET_OSX, TARGET_FREEBSD and
96  * TARGET_SOLARIS, which are
97  * set on the command line via the compiler makefile.
98  */
99
100 #if _WIN32
101 #define TARGET_WINDOS 1         // Windows dmd generates Windows targets
102 #define OMFOBJ 1
103 #endif
104
105 #if TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS
106 #ifndef ELFOBJ
107 #define ELFOBJ 1
108 #endif
109 #endif
110
111 #if TARGET_OSX
112 #ifndef MACHOBJ
113 #define MACHOBJ 1
114 #endif
115 #endif
116
117
118 struct Array;
119 struct OutBuffer;
120
121 // Put command line switches in here
122 struct Param
123 {
124     char obj;           // write object file
125     char link;          // perform link
126     char dll;           // generate shared dynamic library
127     char lib;           // write library file instead of object file(s)
128     char multiobj;      // break one object file into multiple ones
129     char oneobj;        // write one object file instead of multiple ones
130     char trace;         // insert profiling hooks
131     char quiet;         // suppress non-error messages
132     char verbose;       // verbose compile
133     char vtls;          // identify thread local variables
134     char symdebug;      // insert debug symbolic information
135     char optimize;      // run optimizer
136     char map;           // generate linker .map file
137     char cpu;           // target CPU
138     char isX86_64;      // generate X86_64 bit code
139     char isLinux;       // generate code for linux
140     char isOSX;         // generate code for Mac OSX
141     char isWindows;     // generate code for Windows
142     char isFreeBSD;     // generate code for FreeBSD
143     char isSolaris;     // generate code for Solaris
144     char scheduler;     // which scheduler to use
145     char useDeprecated; // allow use of deprecated features
146     char useAssert;     // generate runtime code for assert()'s
147     char useInvariants; // generate class invariant checks
148     char useIn;         // generate precondition checks
149     char useOut;        // generate postcondition checks
150     char useArrayBounds; // 0: no array bounds checks
151                          // 1: array bounds checks for safe functions only
152                          // 2: array bounds checks for all functions
153     char noboundscheck; // no array bounds checking at all
154     char useSwitchError; // check for switches without a default
155     char useUnitTests;  // generate unittest code
156     char useInline;     // inline expand functions
157     char release;       // build release version
158     char preservePaths; // !=0 means don't strip path from source file
159     char warnings;      // 0: enable warnings
160                         // 1: warnings as errors
161                         // 2: informational warnings (no errors)
162     char pic;           // generate position-independent-code for shared libs
163     char cov;           // generate code coverage data
164     char nofloat;       // code should not pull in floating point support
165     char Dversion;      // D version number
166     char ignoreUnsupportedPragmas;      // rather than error on them
167
168     char *argv0;        // program name
169     Array *imppath;     // array of char*'s of where to look for import modules
170     Array *fileImppath; // array of char*'s of where to look for file import modules
171     char *objdir;       // .obj/.lib file output directory
172     char *objname;      // .obj file output name
173     char *libname;      // .lib file output name
174
175     char doDocComments; // process embedded documentation comments
176     char *docdir;       // write documentation file to docdir directory
177     char *docname;      // write documentation file to docname
178     Array *ddocfiles;   // macro include files for Ddoc
179
180     char doHdrGeneration;       // process embedded documentation comments
181     char *hdrdir;               // write 'header' file to docdir directory
182     char *hdrname;              // write 'header' file to docname
183
184     char doXGeneration;         // write JSON file
185     char *xfilename;            // write JSON file to xfilename
186
187     unsigned debuglevel;        // debug level
188     Array *debugids;            // debug identifiers
189
190     unsigned versionlevel;      // version level
191     Array *versionids;          // version identifiers
192
193     bool dump_source;
194
195     const char *defaultlibname; // default library for non-debug builds
196     const char *debuglibname;   // default library for debug builds
197
198     char *moduleDepsFile;       // filename for deps output
199     OutBuffer *moduleDeps;      // contents to be written to deps file
200
201     // Hidden debug switches
202     char debuga;
203     char debugb;
204     char debugc;
205     char debugf;
206     char debugr;
207     char debugw;
208     char debugx;
209     char debugy;
210
211     char run;           // run resulting executable
212     size_t runargs_length;
213     char** runargs;     // arguments for executable
214
215     // Linker stuff
216     Array *objfiles;
217     Array *linkswitches;
218     Array *libfiles;
219     char *deffile;
220     char *resfile;
221     char *exefile;
222     char *mapfile;
223 };
224
225 struct Global
226 {
227     const char *mars_ext;
228     const char *sym_ext;
229     const char *obj_ext;
230     const char *lib_ext;
231     const char *dll_ext;
232     const char *doc_ext;        // for Ddoc generated files
233     const char *ddoc_ext;       // for Ddoc macro include files
234     const char *hdr_ext;        // for D 'header' import files
235     const char *json_ext;       // for JSON files
236     const char *map_ext;        // for .map files
237     const char *copyright;
238     const char *written;
239     Array *path;        // Array of char*'s which form the import lookup path
240     Array *filePath;    // Array of char*'s which form the file import lookup path
241     int structalign;
242     const char *version;
243
244     Param params;
245     unsigned errors;    // number of errors reported so far
246     unsigned warnings;  // number of warnings reported so far
247     unsigned gag;       // !=0 means gag reporting of errors & warnings
248
249     Global();
250 };
251
252 extern Global global;
253
254 /* Set if Windows Structured Exception Handling C extensions are supported.
255  * Apparently, VC has dropped support for these?
256  */
257 #define WINDOWS_SEH     (_WIN32 && __DMC__)
258
259
260 #ifdef __DMC__
261  typedef _Complex long double complex_t;
262 #else
263  #ifndef IN_GCC
264   #include "complex_t.h"
265  #endif
266  #ifdef __APPLE__
267   //#include "complex.h"//This causes problems with include the c++ <complex> and not the C "complex.h"
268  #endif
269 #endif
270
271 // Be careful not to care about sign when using dinteger_t
272 //typedef uint64_t integer_t;
273 typedef uint64_t dinteger_t;    // use this instead of integer_t to
274                                 // avoid conflicts with system #include's
275
276 // Signed and unsigned variants
277 typedef int64_t sinteger_t;
278 typedef uint64_t uinteger_t;
279
280 typedef int8_t                  d_int8;
281 typedef uint8_t                 d_uns8;
282 typedef int16_t                 d_int16;
283 typedef uint16_t                d_uns16;
284 typedef int32_t                 d_int32;
285 typedef uint32_t                d_uns32;
286 typedef int64_t                 d_int64;
287 typedef uint64_t                d_uns64;
288
289 typedef float                   d_float32;
290 typedef double                  d_float64;
291 typedef long double             d_float80;
292
293 typedef d_uns8                  d_char;
294 typedef d_uns16                 d_wchar;
295 typedef d_uns32                 d_dchar;
296
297 #ifdef IN_GCC
298 #include "d-gcc-real.h"
299 #else
300 typedef long double real_t;
301 #endif
302
303 // Modify OutBuffer::writewchar to write the correct size of wchar
304 #if _WIN32
305 #define writewchar writeword
306 #else
307 // This needs a configuration test...
308 #define writewchar write4
309 #endif
310
311 #ifdef IN_GCC
312 #include "d-gcc-complex_t.h"
313 #endif
314
315 struct Module;
316
317 //typedef unsigned Loc;         // file location
318 struct Loc
319 {
320     const char *filename;
321     unsigned linnum;
322
323     Loc()
324     {
325         linnum = 0;
326         filename = NULL;
327     }
328
329     Loc(int x)
330     {
331         linnum = x;
332         filename = NULL;
333     }
334
335     Loc(Module *mod, unsigned linnum);
336
337     char *toChars();
338     bool equals(const Loc& loc);
339 };
340
341 #ifndef GCC_SAFE_DMD
342 #define TRUE    1
343 #define FALSE   0
344 #endif
345
346 #define INTERFACE_OFFSET        0       // if 1, put classinfo as first entry
347                                         // in interface vtbl[]'s
348 #define INTERFACE_VIRTUAL       0       // 1 means if an interface appears
349                                         // in the inheritance graph multiple
350                                         // times, only one is used
351
352 enum LINK
353 {
354     LINKdefault,
355     LINKd,
356     LINKc,
357     LINKcpp,
358     LINKwindows,
359     LINKpascal,
360 };
361
362 enum DYNCAST
363 {
364     DYNCAST_OBJECT,
365     DYNCAST_EXPRESSION,
366     DYNCAST_DSYMBOL,
367     DYNCAST_TYPE,
368     DYNCAST_IDENTIFIER,
369     DYNCAST_TUPLE,
370 };
371
372 enum MATCH
373 {
374     MATCHnomatch,       // no match
375     MATCHconvert,       // match with conversions
376 #if DMDV2
377     MATCHconst,         // match with conversion to const
378 #endif
379     MATCHexact          // exact match
380 };
381
382 typedef uint64_t StorageClass;
383
384
385 void warning(Loc loc, const char *format, ...);
386 void error(Loc loc, const char *format, ...);
387 void verror(Loc loc, const char *format, va_list);
388 void vwarning(Loc loc, const char *format, va_list);
389 void fatal();
390 void err_nomem();
391 int runLINK();
392 void deleteExeFile();
393 int runProgram();
394 const char *inifile(const char *argv0, const char *inifile);
395 void halt();
396 void util_progress();
397
398 /*** Where to send error messages ***/
399 #if IN_GCC
400 #define stdmsg stderr
401 #else
402 #define stdmsg stderr
403 #endif
404
405 struct Dsymbol;
406 struct Library;
407 struct File;
408 void obj_start(char *srcfile);
409 void obj_end(Library *library, File *objfile);
410 void obj_append(Dsymbol *s);
411 void obj_write_deferred(Library *library);
412
413 const char *importHint(const char *s);
414
415 #endif /* DMD_MARS_H */
Note: See TracBrowser for help on using the browser.