1 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 */ 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 ClassDeclaration; 20 class Dsymbol; 21 class Expression; 22 class FuncDeclaration; 23 class Parameter; 24 class Statement; 25 class Type; 26 class TypeFunction; 27 class TypeTuple; 28 struct OutBuffer; 29 30 struct TargetC 31 { 32 unsigned longsize; // size of a C 'long' or 'unsigned long' type 33 unsigned long_doublesize; // size of a C 'long double' 34 Type *twchar_t; // C 'wchar_t' type 35 }; 36 37 struct TargetCPP 38 { 39 bool reverseOverloads; // with dmc and cl, overloaded functions are grouped and in reverse order 40 bool exceptions; // set if catching C++ exceptions is supported 41 bool twoDtorInVtable; // target C++ ABI puts deleting and non-deleting destructor into vtable 42 43 const char *toMangle(Dsymbol *s); 44 const char *typeInfoMangle(ClassDeclaration *cd); 45 const char *thunkMangle(FuncDeclaration *fd, int offset); 46 const char *typeMangle(Type *t); 47 Type *parameterType(Parameter *p); 48 bool fundamentalType(const Type *t, bool& isFundamental); 49 unsigned derivedClassOffset(ClassDeclaration *baseClass); 50 }; 51 52 struct TargetObjC 53 { 54 bool supported; // set if compiler can interface with Objective-C 55 }; 56 57 struct Target 58 { 59 // D ABI 60 unsigned ptrsize; 61 unsigned realsize; // size a real consumes in memory 62 unsigned realpad; // 'padding' added to the CPU real size to bring it up to realsize 63 unsigned realalignsize; // alignment for reals 64 unsigned classinfosize; // size of 'ClassInfo' 65 unsigned long long maxStaticDataSize; // maximum size of static data 66 67 // C ABI 68 TargetC c; 69 70 // C++ ABI 71 TargetCPP cpp; 72 73 // Objective-C ABI 74 TargetObjC objc; 75 76 template <typename T> 77 struct FPTypeProperties 78 { 79 real_t max; 80 real_t min_normal; 81 real_t nan; 82 real_t snan; 83 real_t infinity; 84 real_t epsilon; 85 86 d_int64 dig; 87 d_int64 mant_dig; 88 d_int64 max_exp; 89 d_int64 min_exp; 90 d_int64 max_10_exp; 91 d_int64 min_10_exp; 92 }; 93 94 FPTypeProperties<float> FloatProperties; 95 FPTypeProperties<double> DoubleProperties; 96 FPTypeProperties<real_t> RealProperties; 97 98 private: 99 Type *tvalist; 100 101 public: 102 void _init(const Param& params); 103 // Type sizes and support. 104 unsigned alignsize(Type *type); 105 unsigned fieldalign(Type *type); 106 Type *va_listType(const Loc &loc, Scope *sc); // get type of va_list 107 int isVectorTypeSupported(int sz, Type *type); 108 bool isVectorOpSupported(Type *type, TOK op, Type *t2 = NULL); 109 // ABI and backend. 110 LINK systemLinkage(); 111 TypeTuple *toArgTypes(Type *t); 112 bool isReturnOnStack(TypeFunction *tf, bool needsThis); 113 Expression *getTargetInfo(const char* name, const Loc& loc); 114 bool libraryObjectMonitors(FuncDeclaration *fd, Statement *fbody); 115 }; 116 117 extern Target target; 118