d: Merge upstream dmd 568496d5b, druntime 178c44ff, phobos 574bf883b.
[official-gcc.git] / gcc / d / dmd / target.h
blob6a75ccc5ebd8d60d98c4f4476954f8f8c16d4978
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 2013-2021 by The D Language Foundation, All Rights Reserved
4 * written by Iain Buclaw
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/target.h
9 */
11 #pragma once
13 // This file contains a data structure that describes a back-end target.
14 // At present it is incomplete, but in future it should grow to contain
15 // most or all target machine and target O/S specific information.
16 #include "globals.h"
17 #include "tokens.h"
19 class ClassDeclaration;
20 class Dsymbol;
21 class Expression;
22 class FuncDeclaration;
23 class Parameter;
24 class Statement;
25 class Type;
26 class TypeTuple;
27 class TypeFunction;
29 enum class CPU
31 x87,
32 mmx,
33 sse,
34 sse2,
35 sse3,
36 ssse3,
37 sse4_1,
38 sse4_2,
39 avx, // AVX1 instruction set
40 avx2, // AVX2 instruction set
41 avx512, // AVX-512 instruction set
43 // Special values that don't survive past the command line processing
44 baseline, // (default) the minimum capability CPU
45 native // the machine the compiler is being run on
48 struct TargetC
50 enum class Runtime : unsigned char
52 Unspecified,
53 Bionic,
54 DigitalMars,
55 Glibc,
56 Microsoft,
57 Musl,
58 Newlib,
59 UClibc,
60 WASI,
63 enum class BitFieldStyle : unsigned char
65 Unspecified,
66 DM, // Digital Mars 32 bit C compiler
67 MS, // Microsoft 32 and 64 bit C compilers
68 // https://docs.microsoft.com/en-us/cpp/c-language/c-bit-fields?view=msvc-160
69 // https://docs.microsoft.com/en-us/cpp/cpp/cpp-bit-fields?view=msvc-160
70 Gcc_Clang, // gcc and clang
73 uint8_t longsize; // size of a C 'long' or 'unsigned long' type
74 uint8_t long_doublesize; // size of a C 'long double'
75 uint8_t wchar_tsize; // size of a C 'wchar_t' type
76 Runtime runtime;
77 BitFieldStyle bitFieldStyle; // different C compilers do it differently
80 struct TargetCPP
82 enum class Runtime : unsigned char
84 Unspecified,
85 Clang,
86 DigitalMars,
87 Gcc,
88 Microsoft,
89 Sun
91 bool reverseOverloads; // with dmc and cl, overloaded functions are grouped and in reverse order
92 bool exceptions; // set if catching C++ exceptions is supported
93 bool twoDtorInVtable; // target C++ ABI puts deleting and non-deleting destructor into vtable
94 bool wrapDtorInExternD; // set if C++ dtors require a D wrapper to be callable from runtime
95 Runtime runtime;
97 const char *toMangle(Dsymbol *s);
98 const char *typeInfoMangle(ClassDeclaration *cd);
99 const char *thunkMangle(FuncDeclaration *fd, int offset);
100 const char *typeMangle(Type *t);
101 Type *parameterType(Parameter *p);
102 bool fundamentalType(const Type *t, bool& isFundamental);
103 unsigned derivedClassOffset(ClassDeclaration *baseClass);
106 struct TargetObjC
108 bool supported; // set if compiler can interface with Objective-C
111 struct Target
113 typedef unsigned char OS;
114 enum
116 /* These are mutually exclusive; one and only one is set.
117 * Match spelling and casing of corresponding version identifiers
119 OS_Freestanding = 0,
120 OS_linux = 1,
121 OS_Windows = 2,
122 OS_OSX = 4,
123 OS_OpenBSD = 8,
124 OS_FreeBSD = 0x10,
125 OS_Solaris = 0x20,
126 OS_DragonFlyBSD = 0x40,
128 // Combination masks
129 all = OS_linux | OS_Windows | OS_OSX | OS_OpenBSD | OS_FreeBSD | OS_Solaris | OS_DragonFlyBSD,
130 Posix = OS_linux | OS_OSX | OS_OpenBSD | OS_FreeBSD | OS_Solaris | OS_DragonFlyBSD,
133 OS os;
134 uint8_t osMajor;
135 // D ABI
136 uint8_t ptrsize;
137 uint8_t realsize; // size a real consumes in memory
138 uint8_t realpad; // 'padding' added to the CPU real size to bring it up to realsize
139 uint8_t realalignsize; // alignment for reals
140 uint8_t classinfosize; // size of 'ClassInfo'
141 uint64_t maxStaticDataSize; // maximum size of static data
143 // C ABI
144 TargetC c;
146 // C++ ABI
147 TargetCPP cpp;
149 // Objective-C ABI
150 TargetObjC objc;
152 DString architectureName; // name of the platform architecture (e.g. X86_64)
153 CPU cpu; // CPU instruction set to target
154 bool is64bit; // generate 64 bit code for x86_64; true by default for 64 bit dmd
155 bool isLP64; // pointers are 64 bits
157 // Environmental
158 DString obj_ext; /// extension for object files
159 DString lib_ext; /// extension for static library files
160 DString dll_ext; /// extension for dynamic library files
161 bool run_noext; /// allow -run sources without extensions
162 bool mscoff; /// for Win32: write COFF object files instead of OMF
164 template <typename T>
165 struct FPTypeProperties
167 real_t max;
168 real_t min_normal;
169 real_t nan;
170 real_t infinity;
171 real_t epsilon;
173 d_int64 dig;
174 d_int64 mant_dig;
175 d_int64 max_exp;
176 d_int64 min_exp;
177 d_int64 max_10_exp;
178 d_int64 min_10_exp;
181 FPTypeProperties<float> FloatProperties;
182 FPTypeProperties<double> DoubleProperties;
183 FPTypeProperties<real_t> RealProperties;
185 private:
186 Type *tvalist;
187 const Param *params;
189 public:
190 void _init(const Param& params);
191 // Type sizes and support.
192 void setTriple(const char* _triple);
193 unsigned alignsize(Type *type);
194 unsigned fieldalign(Type *type);
195 Type *va_listType(const Loc &loc, Scope *sc); // get type of va_list
196 int isVectorTypeSupported(int sz, Type *type);
197 bool isVectorOpSupported(Type *type, unsigned op, Type *t2 = NULL);
198 // ABI and backend.
199 LINK systemLinkage();
200 TypeTuple *toArgTypes(Type *t);
201 bool isReturnOnStack(TypeFunction *tf, bool needsThis);
202 d_uns64 parameterSize(const Loc& loc, Type *t);
203 bool preferPassByRef(Type *t);
204 Expression *getTargetInfo(const char* name, const Loc& loc);
205 bool isCalleeDestroyingArgs(TypeFunction* tf);
206 bool libraryObjectMonitors(FuncDeclaration *fd, Statement *fbody);
207 void addPredefinedGlobalIdentifiers() const;
210 extern Target target;