1 2 /* Compiler implementation of the D programming language 3 * Copyright (C) 1999-2021 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 typedef unsigned char CHECKENABLE; 32 enum 33 { 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 38 }; 39 40 typedef unsigned char CHECKACTION; 41 enum 42 { 43 CHECKACTION_D, // call D assert on failure 44 CHECKACTION_C, // call C assert on failure 45 CHECKACTION_halt // cause program halt on failure 46 }; 47 48 enum CPU 49 { 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 61 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 65 }; 66 67 enum CppStdRevision 68 { 69 CppStdRevisionCpp98 = 199711, 70 CppStdRevisionCpp11 = 201103, 71 CppStdRevisionCpp14 = 201402, 72 CppStdRevisionCpp17 = 201703 73 }; 74 75 // Put command line switches in here 76 struct Param 77 { 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 vsafe; // use enhanced @safe checking 130 unsigned cplusplus; // version of C++ name mangling to support 131 bool showGaggedErrors; // print gagged errors anyway 132 133 CPU cpu; // CPU instruction set to target 134 135 CHECKENABLE useInvariants; // generate class invariant checks 136 CHECKENABLE useIn; // generate precondition checks 137 CHECKENABLE useOut; // generate postcondition checks 138 CHECKENABLE useArrayBounds; // when to generate code for array bounds checks 139 CHECKENABLE useAssert; // when to generate code for assert()'s 140 CHECKENABLE useSwitchError; // check for switches without a default 141 CHECKENABLE boundscheck; // state of -boundscheck switch 142 143 CHECKACTION checkAction; // action to take when bounds, asserts or switch defaults are violated 144 145 unsigned errorLimit; 146 147 DString argv0; // program name 148 Array<const char *> modFileAliasStrings; // array of char*'s of -I module filename alias strings 149 Array<const char *> *imppath; // array of char*'s of where to look for import modules 150 Array<const char *> *fileImppath; // array of char*'s of where to look for file import modules 151 DString objdir; // .obj/.lib file output directory 152 DString objname; // .obj file output name 153 DString libname; // .lib file output name 154 155 bool doDocComments; // process embedded documentation comments 156 DString docdir; // write documentation file to docdir directory 157 DString docname; // write documentation file to docname 158 Array<const char *> ddocfiles; // macro include files for Ddoc 159 160 bool doHdrGeneration; // process embedded documentation comments 161 DString hdrdir; // write 'header' file to docdir directory 162 DString hdrname; // write 'header' file to docname 163 bool hdrStripPlainFunctions; // strip the bodies of plain (non-template) functions 164 165 bool doJsonGeneration; // write JSON file 166 DString jsonfilename; // write JSON file to jsonfilename 167 168 unsigned debuglevel; // debug level 169 Array<const char *> *debugids; // debug identifiers 170 171 unsigned versionlevel; // version level 172 Array<const char *> *versionids; // version identifiers 173 174 DString defaultlibname; // default library for non-debug builds 175 DString debuglibname; // default library for debug builds 176 DString mscrtlib; // MS C runtime library 177 178 DString moduleDepsFile; // filename for deps output 179 OutBuffer *moduleDeps; // contents to be written to deps file 180 181 // Hidden debug switches 182 bool debugb; 183 bool debugc; 184 bool debugf; 185 bool debugr; 186 bool debugx; 187 bool debugy; 188 189 bool run; // run resulting executable 190 Strings runargs; // arguments for executable 191 192 // Linker stuff 193 Array<const char *> objfiles; 194 Array<const char *> linkswitches; 195 Array<const char *> libfiles; 196 Array<const char *> dllfiles; 197 DString deffile; 198 DString resfile; 199 DString exefile; 200 DString mapfile; 201 }; 202 203 typedef unsigned structalign_t; 204 // magic value means "match whatever the underlying C compiler does" 205 // other values are all powers of 2 206 #define STRUCTALIGN_DEFAULT ((structalign_t) ~0) 207 208 struct Global 209 { 210 DString inifilename; 211 DString mars_ext; 212 DString obj_ext; 213 DString lib_ext; 214 DString dll_ext; 215 DString doc_ext; // for Ddoc generated files 216 DString ddoc_ext; // for Ddoc macro include files 217 DString hdr_ext; // for D 'header' import files 218 DString cxxhdr_ext; // for C/C++ 'header' files 219 DString json_ext; // for JSON files 220 DString map_ext; // for .map files 221 bool run_noext; // allow -run sources without extensions. 222 223 DString copyright; 224 DString written; 225 const char *main_d; // dummy filename for dummy main() 226 Array<const char *> *path; // Array of char*'s which form the import lookup path 227 Array<const char *> *filePath; // Array of char*'s which form the file import lookup path 228 229 DString version; // Compiler version string 230 DString vendor; // Compiler backend name 231 232 Param params; 233 unsigned errors; // number of errors reported so far 234 unsigned warnings; // number of warnings reported so far 235 FILE *stdmsg; // where to send verbose messages 236 unsigned gag; // !=0 means gag reporting of errors & warnings 237 unsigned gaggedErrors; // number of errors reported while gagged 238 unsigned gaggedWarnings; // number of warnings reported while gagged 239 240 void* console; // opaque pointer to console for controlling text attributes 241 242 Array<class Identifier*>* versionids; // command line versions and predefined versions 243 Array<class Identifier*>* debugids; // command line debug versions and predefined versions 244 245 enum { recursionLimit = 500 }; // number of recursive template expansions before abort 246 247 /* Start gagging. Return the current number of gagged errors 248 */ 249 unsigned startGagging(); 250 251 /* End gagging, restoring the old gagged state. 252 * Return true if errors occurred while gagged. 253 */ 254 bool endGagging(unsigned oldGagged); 255 256 /* Increment the error count to record that an error 257 * has occurred in the current context. An error message 258 * may or may not have been printed. 259 */ 260 void increaseErrorCount(); 261 262 void _init(); 263 }; 264 265 extern Global global; 266 267 // Be careful not to care about sign when using dinteger_t 268 // use this instead of integer_t to 269 // avoid conflicts with system #include's 270 typedef uint64_t dinteger_t; 271 // Signed and unsigned variants 272 typedef int64_t sinteger_t; 273 typedef uint64_t uinteger_t; 274 275 typedef int8_t d_int8; 276 typedef uint8_t d_uns8; 277 typedef int16_t d_int16; 278 typedef uint16_t d_uns16; 279 typedef int32_t d_int32; 280 typedef uint32_t d_uns32; 281 typedef int64_t d_int64; 282 typedef uint64_t d_uns64; 283 284 // file location 285 struct Loc 286 { 287 const char *filename; // either absolute or relative to cwd 288 unsigned linnum; 289 unsigned charnum; 290 LocLoc291 Loc() 292 { 293 linnum = 0; 294 charnum = 0; 295 filename = NULL; 296 } 297 298 Loc(const char *filename, unsigned linnum, unsigned charnum); 299 300 const char *toChars() const; 301 bool equals(const Loc& loc); 302 }; 303 304 enum LINK 305 { 306 LINKdefault, 307 LINKd, 308 LINKc, 309 LINKcpp, 310 LINKwindows, 311 LINKobjc, 312 LINKsystem 313 }; 314 315 enum CPPMANGLE 316 { 317 CPPMANGLEdefault, 318 CPPMANGLEstruct, 319 CPPMANGLEclass 320 }; 321 322 enum MATCH 323 { 324 MATCHnomatch, // no match 325 MATCHconvert, // match with conversions 326 MATCHconst, // match with conversion to const 327 MATCHexact // exact match 328 }; 329 330 enum PINLINE 331 { 332 PINLINEdefault, // as specified on the command line 333 PINLINEnever, // never inline 334 PINLINEalways // always inline 335 }; 336 337 typedef uinteger_t StorageClass; 338