]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/d/dmd/target.h
d: Merge upstream dmd 3982604c5, druntime bc58b1e9, phobos 12329adb6.
[thirdparty/gcc.git] / gcc / d / dmd / target.h
CommitLineData
b4c522fa
IB
1
2/* Compiler implementation of the D programming language
a3b38b77 3 * Copyright (C) 2013-2021 by The D Language Foundation, All Rights Reserved
b4c522fa
IB
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 */
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
19class ClassDeclaration;
20class Dsymbol;
21class Expression;
5d4b824f 22class FuncDeclaration;
f9ab59ff 23class Parameter;
5a0aa603 24class Statement;
b4c522fa 25class Type;
a1ccbae6 26class TypeTuple;
5fee5ec3
IB
27class TypeFunction;
28
9c7d5e88 29enum class CPU : unsigned char
5fee5ec3
IB
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};
b4c522fa 47
5905cbdb
IB
48struct TargetC
49{
5fee5ec3
IB
50 enum class Runtime : unsigned char
51 {
52 Unspecified,
53 Bionic,
54 DigitalMars,
55 Glibc,
56 Microsoft,
57 Musl,
58 Newlib,
59 UClibc,
60 WASI,
61 };
62
63 enum class BitFieldStyle : unsigned char
64 {
65 Unspecified,
0fb57034
IB
66 DM, // Digital Mars 32 bit C compiler
67 MS, // Microsoft 32 and 64 bit C compilers
5fee5ec3
IB
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
71 };
72
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
5905cbdb
IB
78};
79
80struct TargetCPP
81{
5fee5ec3
IB
82 enum class Runtime : unsigned char
83 {
84 Unspecified,
85 Clang,
86 DigitalMars,
87 Gcc,
88 Microsoft,
89 Sun
90 };
5905cbdb
IB
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
5fee5ec3
IB
94 bool wrapDtorInExternD; // set if C++ dtors require a D wrapper to be callable from runtime
95 Runtime runtime;
5905cbdb
IB
96
97 const char *toMangle(Dsymbol *s);
98 const char *typeInfoMangle(ClassDeclaration *cd);
5d4b824f 99 const char *thunkMangle(FuncDeclaration *fd, int offset);
5905cbdb
IB
100 const char *typeMangle(Type *t);
101 Type *parameterType(Parameter *p);
102 bool fundamentalType(const Type *t, bool& isFundamental);
5a0aa603 103 unsigned derivedClassOffset(ClassDeclaration *baseClass);
5905cbdb
IB
104};
105
106struct TargetObjC
107{
108 bool supported; // set if compiler can interface with Objective-C
109};
110
b4c522fa
IB
111struct Target
112{
5fee5ec3
IB
113 typedef unsigned char OS;
114 enum
115 {
116 /* These are mutually exclusive; one and only one is set.
117 * Match spelling and casing of corresponding version identifiers
118 */
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,
127
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,
131 };
132
133 OS os;
134 uint8_t osMajor;
5905cbdb 135 // D ABI
5fee5ec3
IB
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
5905cbdb
IB
142
143 // C ABI
144 TargetC c;
145
146 // C++ ABI
147 TargetCPP cpp;
148
149 // Objective-C ABI
150 TargetObjC objc;
b4c522fa 151
5fee5ec3
IB
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
156
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
163
b4c522fa
IB
164 template <typename T>
165 struct FPTypeProperties
166 {
5905cbdb
IB
167 real_t max;
168 real_t min_normal;
169 real_t nan;
5905cbdb
IB
170 real_t infinity;
171 real_t epsilon;
172
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;
b4c522fa
IB
179 };
180
5905cbdb
IB
181 FPTypeProperties<float> FloatProperties;
182 FPTypeProperties<double> DoubleProperties;
183 FPTypeProperties<real_t> RealProperties;
b4c522fa 184
5905cbdb
IB
185private:
186 Type *tvalist;
5fee5ec3 187 const Param *params;
5905cbdb
IB
188
189public:
190 void _init(const Param& params);
b4c522fa 191 // Type sizes and support.
5fee5ec3 192 void setTriple(const char* _triple);
5905cbdb
IB
193 unsigned alignsize(Type *type);
194 unsigned fieldalign(Type *type);
5905cbdb
IB
195 Type *va_listType(const Loc &loc, Scope *sc); // get type of va_list
196 int isVectorTypeSupported(int sz, Type *type);
9c7d5e88 197 bool isVectorOpSupported(Type *type, EXP op, Type *t2 = NULL);
b4c522fa 198 // ABI and backend.
5905cbdb
IB
199 LINK systemLinkage();
200 TypeTuple *toArgTypes(Type *t);
c5e94699 201 bool isReturnOnStack(TypeFunction *tf, bool needsThis);
5fee5ec3
IB
202 d_uns64 parameterSize(const Loc& loc, Type *t);
203 bool preferPassByRef(Type *t);
c5e94699 204 Expression *getTargetInfo(const char* name, const Loc& loc);
5fee5ec3 205 bool isCalleeDestroyingArgs(TypeFunction* tf);
5a0aa603 206 bool libraryObjectMonitors(FuncDeclaration *fd, Statement *fbody);
5fee5ec3 207 void addPredefinedGlobalIdentifiers() const;
b4c522fa 208};
5905cbdb
IB
209
210extern Target target;