xref: /netbsd/external/gpl3/gcc.old/dist/gcc/d/dmd/globals.h (revision 0bfacb9b)
1 
2 /* Compiler implementation of the D programming language
3  * Copyright (C) 1999-2019 by The D Language Foundation, All Rights Reserved
4  * written by Walter Bright
5  * http://www.digitalmars.com
6  * Distributed under the Boost Software License, Version 1.0.
7  * http://www.boost.org/LICENSE_1_0.txt
8  * https://github.com/dlang/dmd/blob/master/src/dmd/globals.h
9  */
10 
11 #pragma once
12 
13 #include "root/dcompat.h"
14 #include "root/ctfloat.h"
15 #include "root/outbuffer.h"
16 #include "root/filename.h"
17 #include "compiler.h"
18 
19 // Can't include arraytypes.h here, need to declare these directly.
20 template <typename TYPE> struct Array;
21 
22 typedef unsigned char Diagnostic;
23 enum
24 {
25     DIAGNOSTICerror,  // generate an error
26     DIAGNOSTICinform, // generate a warning
27     DIAGNOSTICoff     // disable diagnostic
28 };
29 
30 // The state of array bounds checking
31 enum BOUNDSCHECK
32 {
33     BOUNDSCHECKdefault, // initial value
34     BOUNDSCHECKoff,     // never do bounds checking
35     BOUNDSCHECKon,      // always do bounds checking
36     BOUNDSCHECKsafeonly // do bounds checking only in @safe functions
37 };
38 
39 typedef unsigned char CHECKACTION;
40 enum
41 {
42     CHECKACTION_D,        // call D assert on failure
43     CHECKACTION_C,        // call C assert on failure
44     CHECKACTION_halt      // cause program halt on failure
45 };
46 
47 enum CPU
48 {
49     x87,
50     mmx,
51     sse,
52     sse2,
53     sse3,
54     ssse3,
55     sse4_1,
56     sse4_2,
57     avx,                // AVX1 instruction set
58     avx2,               // AVX2 instruction set
59     avx512,             // AVX-512 instruction set
60 
61     // Special values that don't survive past the command line processing
62     baseline,           // (default) the minimum capability CPU
63     native              // the machine the compiler is being run on
64 };
65 
66 enum CppStdRevision
67 {
68     CppStdRevisionCpp98 = 199711,
69     CppStdRevisionCpp11 = 201103,
70     CppStdRevisionCpp14 = 201402,
71     CppStdRevisionCpp17 = 201703
72 };
73 
74 // Put command line switches in here
75 struct Param
76 {
77     bool obj;           // write object file
78     bool link;          // perform link
79     bool dll;           // generate shared dynamic library
80     bool lib;           // write library file instead of object file(s)
81     bool multiobj;      // break one object file into multiple ones
82     bool oneobj;        // write one object file instead of multiple ones
83     bool trace;         // insert profiling hooks
84     bool tracegc;       // instrument calls to 'new'
85     bool verbose;       // verbose compile
86     bool vcg_ast;       // write-out codegen-ast
87     bool showColumns;   // print character (column) numbers in diagnostics
88     bool vtls;          // identify thread local variables
89     char vgc;           // identify gc usage
90     bool vfield;        // identify non-mutable field variables
91     bool vcomplex;      // identify complex/imaginary type usage
92     char symdebug;      // insert debug symbolic information
93     bool symdebugref;   // insert debug information for all referenced types, too
94     bool alwaysframe;   // always emit standard stack frame
95     bool optimize;      // run optimizer
96     bool map;           // generate linker .map file
97     bool is64bit;       // generate 64 bit code
98     bool isLP64;        // generate code for LP64
99     bool isLinux;       // generate code for linux
100     bool isOSX;         // generate code for Mac OSX
101     bool isWindows;     // generate code for Windows
102     bool isFreeBSD;     // generate code for FreeBSD
103     bool isOpenBSD;     // generate code for OpenBSD
104     bool isSolaris;     // generate code for Solaris
105     bool hasObjectiveC; // target supports Objective-C
106     bool mscoff;        // for Win32: write COFF object files instead of OMF
107     Diagnostic useDeprecated;
108     bool useAssert;     // generate runtime code for assert()'s
109     bool useInvariants; // generate class invariant checks
110     bool useIn;         // generate precondition checks
111     bool useOut;        // generate postcondition checks
112     bool stackstomp;    // add stack stomping code
113     bool useSwitchError; // check for switches without a default
114     bool useUnitTests;  // generate unittest code
115     bool useInline;     // inline expand functions
116     bool useDIP25;      // implement http://wiki.dlang.org/DIP25
117     bool release;       // build release version
118     bool preservePaths; // true means don't strip path from source file
119     Diagnostic warnings;
120     bool pic;           // generate position-independent-code for shared libs
121     bool color;         // use ANSI colors in console output
122     bool cov;           // generate code coverage data
123     unsigned char covPercent;   // 0..100 code coverage percentage required
124     bool nofloat;       // code should not pull in floating point support
125     bool ignoreUnsupportedPragmas;      // rather than error on them
126     bool enforcePropertySyntax;
127     bool useModuleInfo; // generate runtime module information
128     bool useTypeInfo;   // generate runtime type information
129     bool useExceptions; // support exception handling
130     bool betterC;       // be a "better C" compiler; no dependency on D runtime
131     bool addMain;       // add a default main() function
132     bool allInst;       // generate code for all template instantiations
133     bool check10378;    // check for issues transitioning to 10738
134     bool bug10378;      // use pre-bugzilla 10378 search strategy
135     bool vsafe;         // use enhanced @safe checking
136     unsigned cplusplus;     // version of C++ name mangling to support
137     bool showGaggedErrors;  // print gagged errors anyway
138 
139     CPU cpu;                // CPU instruction set to target
140 
141     BOUNDSCHECK useArrayBounds;    // when to generate code for array bounds checks
142     CHECKACTION checkAction;       // action to take when bounds, asserts or switch defaults are violated
143 
144     const char *argv0;    // program name
145     Array<const char *> *modFileAliasStrings; // array of char*'s of -I module filename alias strings
146     Array<const char *> *imppath;     // array of char*'s of where to look for import modules
147     Array<const char *> *fileImppath; // array of char*'s of where to look for file import modules
148     const char *objdir;   // .obj/.lib file output directory
149     const char *objname;  // .obj file output name
150     const char *libname;  // .lib file output name
151 
152     bool doDocComments;  // process embedded documentation comments
153     const char *docdir;  // write documentation file to docdir directory
154     const char *docname; // write documentation file to docname
155     Array<const char *> *ddocfiles;  // macro include files for Ddoc
156 
157     bool doHdrGeneration;  // process embedded documentation comments
158     const char *hdrdir;    // write 'header' file to docdir directory
159     const char *hdrname;   // write 'header' file to docname
160     bool hdrStripPlainFunctions; // strip the bodies of plain (non-template) functions
161 
162     bool doJsonGeneration;    // write JSON file
163     const char *jsonfilename; // write JSON file to jsonfilename
164 
165     unsigned debuglevel;   // debug level
166     Array<const char *> *debugids;     // debug identifiers
167 
168     unsigned versionlevel; // version level
169     Array<const char *> *versionids;   // version identifiers
170 
171     const char *defaultlibname; // default library for non-debug builds
172     const char *debuglibname;   // default library for debug builds
173     const char *mscrtlib;       // MS C runtime library
174 
175     const char *moduleDepsFile; // filename for deps output
176     OutBuffer *moduleDeps;      // contents to be written to deps file
177 
178     // Hidden debug switches
179     bool debugb;
180     bool debugc;
181     bool debugf;
182     bool debugr;
183     bool debugx;
184     bool debugy;
185 
186     bool run;           // run resulting executable
187     Strings runargs;    // arguments for executable
188 
189     // Linker stuff
190     Array<const char *> *objfiles;
191     Array<const char *> *linkswitches;
192     Array<const char *> *libfiles;
193     Array<const char *> *dllfiles;
194     const char *deffile;
195     const char *resfile;
196     const char *exefile;
197     const char *mapfile;
198 };
199 
200 typedef unsigned structalign_t;
201 // magic value means "match whatever the underlying C compiler does"
202 // other values are all powers of 2
203 #define STRUCTALIGN_DEFAULT ((structalign_t) ~0)
204 
205 struct Global
206 {
207     const char *inifilename;
208     const char *mars_ext;
209     const char *obj_ext;
210     const char *lib_ext;
211     const char *dll_ext;
212     const char *doc_ext;        // for Ddoc generated files
213     const char *ddoc_ext;       // for Ddoc macro include files
214     const char *hdr_ext;        // for D 'header' import files
215     const char *json_ext;       // for JSON files
216     const char *map_ext;        // for .map files
217     bool run_noext;             // allow -run sources without extensions.
218 
219     const char *copyright;
220     const char *written;
221     const char *main_d;         // dummy filename for dummy main()
222     Array<const char *> *path;        // Array of char*'s which form the import lookup path
223     Array<const char *> *filePath;    // Array of char*'s which form the file import lookup path
224 
225     const char *version;     // Compiler version string
226     const char *vendor;      // Compiler backend name
227 
228     Param params;
229     unsigned errors;       // number of errors reported so far
230     unsigned warnings;     // number of warnings reported so far
231     FILE *stdmsg;          // where to send verbose messages
232     unsigned gag;          // !=0 means gag reporting of errors & warnings
233     unsigned gaggedErrors; // number of errors reported while gagged
234 
235     unsigned errorLimit;
236 
237     void* console;         // opaque pointer to console for controlling text attributes
238 
239     enum { recursionLimit = 500 }; // number of recursive template expansions before abort
240 
241     /* Start gagging. Return the current number of gagged errors
242      */
243     unsigned startGagging();
244 
245     /* End gagging, restoring the old gagged state.
246      * Return true if errors occurred while gagged.
247      */
248     bool endGagging(unsigned oldGagged);
249 
250     /*  Increment the error count to record that an error
251      *  has occurred in the current context. An error message
252      *  may or may not have been printed.
253      */
254     void increaseErrorCount();
255 
256     void _init();
257 };
258 
259 extern Global global;
260 
261 // Be careful not to care about sign when using dinteger_t
262 // use this instead of integer_t to
263 // avoid conflicts with system #include's
264 typedef uint64_t dinteger_t;
265 // Signed and unsigned variants
266 typedef int64_t sinteger_t;
267 typedef uint64_t uinteger_t;
268 
269 typedef int8_t                  d_int8;
270 typedef uint8_t                 d_uns8;
271 typedef int16_t                 d_int16;
272 typedef uint16_t                d_uns16;
273 typedef int32_t                 d_int32;
274 typedef uint32_t                d_uns32;
275 typedef int64_t                 d_int64;
276 typedef uint64_t                d_uns64;
277 
278 // file location
279 struct Loc
280 {
281     const char *filename;
282     unsigned linnum;
283     unsigned charnum;
284 
LocLoc285     Loc()
286     {
287         linnum = 0;
288         charnum = 0;
289         filename = NULL;
290     }
291 
292     Loc(const char *filename, unsigned linnum, unsigned charnum);
293 
294     const char *toChars() const;
295     bool equals(const Loc& loc);
296 };
297 
298 enum LINK
299 {
300     LINKdefault,
301     LINKd,
302     LINKc,
303     LINKcpp,
304     LINKwindows,
305     LINKpascal,
306     LINKobjc,
307     LINKsystem
308 };
309 
310 enum CPPMANGLE
311 {
312     CPPMANGLEdefault,
313     CPPMANGLEstruct,
314     CPPMANGLEclass
315 };
316 
317 enum MATCH
318 {
319     MATCHnomatch,       // no match
320     MATCHconvert,       // match with conversions
321     MATCHconst,         // match with conversion to const
322     MATCHexact          // exact match
323 };
324 
325 enum PINLINE
326 {
327     PINLINEdefault,      // as specified on the command line
328     PINLINEnever,        // never inline
329     PINLINEalways        // always inline
330 };
331 
332 typedef uinteger_t StorageClass;
333