Debian Codegraph @

gcc/d/dmd/target.h

raw
1
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 2013-2025 by The D Language Foundation, All Rights Reserved
4 * written by Iain Buclaw
5 * https://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * https://www.boost.org/LICENSE_1_0.txt
8 * https://github.com/dlang/dmd/blob/master/src/dmd/target.h
9 */
10
11 #pragma once
12
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"
18
19 class BitFieldDeclaration;
20 class ClassDeclaration;
21 class Dsymbol;
22 class Expression;
23 class FuncDeclaration;
24 class Statement;
25 class Type;
26 class TypeTuple;
27 class TypeFunction;
28
29 enum class CPU : unsigned char
30 {
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
42
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
46 };
47
48 struct TargetC
49 {
50 enum class Runtime : unsigned char
51 {
52 Unspecified,
53 Bionic,
54 Glibc,
55 Microsoft,
56 Musl,
57 Newlib,
58 UClibc,
59 WASI,
60 };
61
62 enum class BitFieldStyle : unsigned char
63 {
64 Unspecified,
65 MS, // Microsoft 32 and 64 bit C compilers
66 // https://docs.microsoft.com/en-us/cpp/c-language/c-bit-fields?view=msvc-160
67 // https://docs.microsoft.com/en-us/cpp/cpp/cpp-bit-fields?view=msvc-160
68 Gcc_Clang, // gcc and clang
69 };
70
71 uint8_t crtDestructorsSupported; // Not all platforms support crt_destructor
72 uint8_t boolsize; // size of a C '_Bool' type
73 uint8_t shortsize; // size of a C 'short' or 'unsigned short' type
74 uint8_t intsize; // size of a C 'int' or 'unsigned int' type
75 uint8_t longsize; // size of a C 'long' or 'unsigned long' type
76 uint8_t long_longsize; // size of a C 'long long' or 'unsigned long long' type
77 uint8_t long_doublesize; // size of a C 'long double'
78 uint8_t wchar_tsize; // size of a C 'wchar_t' type
79 Runtime runtime;
80 BitFieldStyle bitFieldStyle; // different C compilers do it differently
81
82 bool contributesToAggregateAlignment(BitFieldDeclaration *bfd);
83 };
84
85 struct TargetCPP
86 {
87 enum class Runtime : unsigned char
88 {
89 Unspecified,
90 LLVM,
91 GNU,
92 Microsoft,
93 Sun
94 };
95 d_bool reverseOverloads; // with dmc and cl, overloaded functions are grouped and in reverse order
96 d_bool exceptions; // set if catching C++ exceptions is supported
97 d_bool twoDtorInVtable; // target C++ ABI puts deleting and non-deleting destructor into vtable
98 d_bool splitVBasetable; // set if C++ ABI uses separate tables for virtual functions and virtual bases
99 d_bool wrapDtorInExternD; // set if C++ dtors require a D wrapper to be callable from runtime
100 Runtime runtime;
101
102 const char *toMangle(Dsymbol *s);
103 const char *typeInfoMangle(ClassDeclaration *cd);
104 const char *thunkMangle(FuncDeclaration *fd, int offset);
105 const char *typeMangle(Type *t);
106 Type *parameterType(Type *p);
107 bool fundamentalType(const Type *t, bool& isFundamental);
108 unsigned derivedClassOffset(ClassDeclaration *baseClass);
109 };
110
111 struct TargetObjC
112 {
113 d_bool supported; // set if compiler can interface with Objective-C
114 };
115
116 struct Target
117 {
118 typedef unsigned char OS;
119 enum
120 {
121 /* These are mutually exclusive; one and only one is set.
122 * Match spelling and casing of corresponding version identifiers
123 */
124 OS_Freestanding = 0,
125 OS_linux = 1,
126 OS_Windows = 2,
127 OS_OSX = 4,
128 OS_OpenBSD = 8,
129 OS_FreeBSD = 0x10,
130 OS_Solaris = 0x20,
131 OS_DragonFlyBSD = 0x40,
132
133 // Combination masks
134 all = OS_linux | OS_Windows | OS_OSX | OS_OpenBSD | OS_FreeBSD | OS_Solaris | OS_DragonFlyBSD,
135 Posix = OS_linux | OS_OSX | OS_OpenBSD | OS_FreeBSD | OS_Solaris | OS_DragonFlyBSD,
136 };
137
138 OS os;
139 uint8_t osMajor;
140 // D ABI
141 uint8_t ptrsize;
142 uint8_t realsize; // size a real consumes in memory
143 uint8_t realpad; // 'padding' added to the CPU real size to bring it up to realsize
144 uint8_t realalignsize; // alignment for reals
145 uint8_t classinfosize; // size of 'ClassInfo'
146 uint64_t maxStaticDataSize; // maximum size of static data
147
148 // C ABI
149 TargetC c;
150
151 // C++ ABI
152 TargetCPP cpp;
153
154 // Objective-C ABI
155 TargetObjC objc;
156
157 DString architectureName; // name of the platform architecture (e.g. X86_64)
158 CPU cpu; // CPU instruction set to target
159 d_bool isAArch64; // generate 64 bit Arm code
160 d_bool isX86_64; // generate 64 bit code for x86_64; true by default for 64 bit dmd
161 d_bool isX86; // generate 32 bit Intel x86 code
162 d_bool isLP64; // pointers are 64 bits
163
164 // Environmental
165 DString obj_ext; /// extension for object files
166 DString lib_ext; /// extension for static library files
167 DString dll_ext; /// extension for dynamic library files
168 d_bool run_noext; /// allow -run sources without extensions
169
170 template <typename T>
171 struct FPTypeProperties
172 {
173 real_t max;
174 real_t min_normal;
175 real_t nan;
176 real_t infinity;
177 real_t epsilon;
178
179 int64_t dig;
180 int64_t mant_dig;
181 int64_t max_exp;
182 int64_t min_exp;
183 int64_t max_10_exp;
184 int64_t min_10_exp;
185 };
186
187 FPTypeProperties<float> FloatProperties;
188 FPTypeProperties<double> DoubleProperties;
189 FPTypeProperties<real_t> RealProperties;
190
191 private:
192 Type *tvalist;
193 const Param *params;
194
195 public:
196 void _init(const Param& params);
197 // Type sizes and support.
198 unsigned alignsize(Type *type);
199 unsigned fieldalign(Type *type);
200 Type *va_listType(Loc loc, Scope *sc); // get type of va_list
201 int isVectorTypeSupported(int sz, Type *type);
202 bool isVectorOpSupported(Type *type, EXP op, Type *t2 = nullptr);
203 // ABI and backend.
204 LINK systemLinkage();
205 TypeTuple *toArgTypes(Type *t);
206 bool isReturnOnStack(TypeFunction *tf, bool needsThis);
207 bool preferPassByRef(Type *t);
208 Expression *getTargetInfo(const char* name, Loc loc);
209 bool isCalleeDestroyingArgs(TypeFunction* tf);
210 bool libraryObjectMonitors(FuncDeclaration *fd, Statement *fbody);
211 bool supportsLinkerDirective() const;
212 void addPredefinedGlobalIdentifiers() const;
213 };
214
215 extern Target target;