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