TargetInfo.h revision f72a44330b9d9a4b2d93e9b91cfb8ab7bd4a0643
1//===--- TargetInfo.h - Expose information about the target -----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the TargetInfo and TargetInfoImpl interfaces. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_BASIC_TARGETINFO_H 15#define LLVM_CLANG_BASIC_TARGETINFO_H 16 17#include "llvm/Support/DataTypes.h" 18#include <vector> 19#include <string> 20 21namespace llvm { struct fltSemantics; } 22 23namespace clang { 24 25class Diagnostic; 26class SourceManager; 27 28namespace Builtin { struct Info; } 29 30/// TargetInfo - This class exposes information about the current target. 31/// 32class TargetInfo { 33 std::string Triple; 34protected: 35 /// These are all caches for target values. 36 unsigned WCharWidth, WCharAlign; 37 38 //==----------------------------------------------------------------==/ 39 // TargetInfo Construction. 40 //==----------------------------------------------------------------==/ 41 TargetInfo(const std::string &T) : Triple(T) { 42 // Set defaults. 43 WCharWidth = WCharAlign = 32; 44 } 45 46public: 47 /// CreateTargetInfo - Return the target info object for the specified target 48 /// triple. 49 static TargetInfo* CreateTargetInfo(const std::string &Triple); 50 51 virtual ~TargetInfo(); 52 53 ///===---- Target property query methods --------------------------------===// 54 55 /// getTargetDefines - Appends the target-specific #define values for this 56 /// target set to the specified buffer. 57 virtual void getTargetDefines(std::vector<char> &DefineBuffer) const = 0; 58 59 /// isCharSigned - Return true if 'char' is 'signed char' or false if it is 60 /// treated as 'unsigned char'. This is implementation defined according to 61 /// C99 6.2.5p15. In our implementation, this is target-specific. 62 bool isCharSigned() const { 63 // FIXME: implement correctly. 64 return true; 65 } 66 67 /// getPointerWidth - Return the width of pointers on this target, for the 68 /// specified address space. FIXME: implement correctly. 69 uint64_t getPointerWidth(unsigned AddrSpace) const { return 32; } 70 uint64_t getPointerAlign(unsigned AddrSpace) const { return 32; } 71 72 /// getBoolInfo - Return the size of '_Bool' and C++ 'bool' for this target, 73 /// in bits. 74 void getBoolInfo(uint64_t &Size, unsigned &Align) const { 75 Size = Align = 8; // FIXME: implement correctly: wrong for ppc32. 76 } 77 78 /// getCharInfo - Return the size of 'char', 'signed char' and 79 /// 'unsigned char' for this target, in bits. 80 void getCharInfo(uint64_t &Size, unsigned &Align) const { 81 Size = Align = 8; // FIXME: implement correctly. 82 } 83 84 /// getShortInfo - Return the size of 'signed short' and 'unsigned short' for 85 /// this target, in bits. 86 void getShortInfo(uint64_t &Size, unsigned &Align) const { 87 Size = Align = 16; // FIXME: implement correctly. 88 } 89 90 /// getIntInfo - Return the size of 'signed int' and 'unsigned int' for this 91 /// target, in bits. 92 void getIntInfo(uint64_t &Size, unsigned &Align) const { 93 Size = Align = 32; // FIXME: implement correctly. 94 } 95 96 /// getLongInfo - Return the size of 'signed long' and 'unsigned long' for 97 /// this target, in bits. 98 void getLongInfo(uint64_t &Size, unsigned &Align) const { 99 Size = Align = 32; // FIXME: implement correctly: wrong for ppc64/x86-64 100 } 101 102 /// getLongLongInfo - Return the size of 'signed long long' and 103 /// 'unsigned long long' for this target, in bits. 104 void getLongLongInfo(uint64_t &Size, unsigned &Align) const { 105 Size = Align = 64; // FIXME: implement correctly. 106 } 107 108 /// getFloatInfo - Characterize 'float' for this target. 109 void getFloatInfo(uint64_t &Size, unsigned &Align, 110 const llvm::fltSemantics *&Format) const; 111 112 /// getDoubleInfo - Characterize 'double' for this target. 113 void getDoubleInfo(uint64_t &Size, unsigned &Align, 114 const llvm::fltSemantics *&Format) const; 115 116 /// getLongDoubleInfo - Characterize 'long double' for this target. 117 void getLongDoubleInfo(uint64_t &Size, unsigned &Align, 118 const llvm::fltSemantics *&Format) const; 119 120 unsigned getWCharWidth() const { return WCharWidth; } 121 unsigned getWCharAlign() const { return WCharAlign; } 122 123 /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this 124 /// target, in bits. 125 unsigned getIntMaxTWidth() const { 126 // FIXME: implement correctly. 127 return 64; 128 } 129 130 /// getTargetBuiltins - Return information about target-specific builtins for 131 /// the current primary target, and info about which builtins are non-portable 132 /// across the current set of primary and secondary targets. 133 virtual void getTargetBuiltins(const Builtin::Info *&Records, 134 unsigned &NumRecords) const = 0; 135 136 /// getVAListDeclaration - Return the declaration to use for 137 /// __builtin_va_list, which is target-specific. 138 virtual const char *getVAListDeclaration() const = 0; 139 140 /// isValidGCCRegisterName - Returns whether the passed in string 141 /// is a valid register name according to GCC. This is used by Sema for 142 /// inline asm statements. 143 bool isValidGCCRegisterName(const char *Name) const; 144 145 // getNormalizedGCCRegisterName - Returns the "normalized" GCC register name. 146 // For example, on x86 it will return "ax" when "eax" is passed in. 147 const char *getNormalizedGCCRegisterName(const char *Name) const; 148 149 enum ConstraintInfo { 150 CI_None = 0x00, 151 CI_AllowsMemory = 0x01, 152 CI_AllowsRegister = 0x02, 153 CI_ReadWrite = 0x04 154 }; 155 156 // validateOutputConstraint, validateInputConstraint - Checks that 157 // a constraint is valid and provides information about it. 158 // FIXME: These should return a real error instead of just true/false. 159 bool validateOutputConstraint(const char *Name, ConstraintInfo &Info) const; 160 bool validateInputConstraint (const char *Name, unsigned NumOutputs, 161 ConstraintInfo &info) const; 162 163 virtual std::string convertConstraint(const char Constraint) const { 164 return std::string(1, Constraint); 165 } 166 167 // Returns a string of target-specific clobbers, in LLVM format. 168 virtual const char *getClobbers() const = 0; 169 170 ///===---- Some helper methods ------------------------------------------===// 171 172 unsigned getBoolWidth() const { 173 uint64_t Size; unsigned Align; 174 getBoolInfo(Size, Align); 175 return static_cast<unsigned>(Size); 176 } 177 178 unsigned getCharWidth(bool isWide = false) const { 179 if (isWide) 180 return WCharWidth; 181 uint64_t Size; unsigned Align; 182 getCharInfo(Size, Align); 183 return static_cast<unsigned>(Size); 184 } 185 186 187 unsigned getIntWidth() const { 188 uint64_t Size; unsigned Align; 189 getIntInfo(Size, Align); 190 return static_cast<unsigned>(Size); 191 } 192 193 unsigned getLongWidth() const { 194 uint64_t Size; unsigned Align; 195 getLongInfo(Size, Align); 196 return static_cast<unsigned>(Size); 197 } 198 199 unsigned getLongLongWidth() const { 200 uint64_t Size; unsigned Align; 201 getLongLongInfo(Size, Align); 202 return static_cast<unsigned>(Size); 203 } 204 205 /// getTargetPrefix - Return the target prefix used for identifying 206 /// llvm intrinsics. 207 virtual const char *getTargetPrefix() const = 0; 208 209 /// getTargetTriple - Return the target triple of the primary target. 210 virtual const char *getTargetTriple() const { 211 return Triple.c_str(); 212 } 213 214 const char *getTargetDescription() const { 215 // FIXME ! 216 // Hard code darwin-x86 for now. 217 return "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:\ 21832-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"; 219 } 220 221 struct GCCRegAlias { 222 const char * const Aliases[5]; 223 const char * const Register; 224 }; 225 226protected: 227 virtual void getGCCRegNames(const char * const *&Names, 228 unsigned &NumNames) const = 0; 229 virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 230 unsigned &NumAliases) const = 0; 231 virtual bool validateAsmConstraint(char c, 232 TargetInfo::ConstraintInfo &info) const= 0; 233}; 234 235} // end namespace clang 236 237#endif 238