TargetInfo.h revision 927686fe8c968ca786fa44d2353eebf59c4f5b8a
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 interface.
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  // Target values set by the ctor of the actual target implementation.  Default
36  // values are specified by the TargetInfo constructor.
37  bool CharIsSigned;
38  unsigned char PointerWidth, PointerAlign;
39  unsigned char WCharWidth, WCharAlign;
40  unsigned char IntWidth, IntAlign;
41  unsigned char DoubleWidth, DoubleAlign;
42  unsigned char LongWidth, LongAlign;
43  unsigned char LongLongWidth, LongLongAlign;
44
45  const llvm::fltSemantics *FloatFormat, *DoubleFormat, *LongDoubleFormat;
46
47  // TargetInfo Constructor.  Default initializes all fields.
48  TargetInfo(const std::string &T);
49
50public:
51  /// CreateTargetInfo - Return the target info object for the specified target
52  /// triple.
53  static TargetInfo* CreateTargetInfo(const std::string &Triple);
54
55  virtual ~TargetInfo();
56
57  ///===---- Target Data Type Query Methods -------------------------------===//
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 { return CharIsSigned; }
63
64  /// getPointerWidth - Return the width of pointers on this target, for the
65  /// specified address space.
66  uint64_t getPointerWidth(unsigned AddrSpace) const {
67    return AddrSpace == 0 ? PointerWidth : getPointerWidthV(AddrSpace);
68  }
69  uint64_t getPointerAlign(unsigned AddrSpace) const {
70    return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
71  }
72  virtual uint64_t getPointerWidthV(unsigned AddrSpace) const {
73    return PointerWidth;
74  }
75  virtual uint64_t getPointerAlignV(unsigned AddrSpace) const {
76    return PointerAlign;
77  }
78
79  /// getBoolWidth/Align - Return the size of '_Bool' and C++ 'bool' for this
80  /// target, in bits.
81  unsigned getBoolWidth(bool isWide = false) const { return 8; }  // FIXME
82  unsigned getBoolAlign(bool isWide = false) const { return 8; }  // FIXME
83
84  unsigned getCharWidth(bool isWide = false) const {
85    return isWide ? getWCharWidth() : 8; // FIXME
86  }
87  unsigned getCharAlign(bool isWide = false) const {
88    return isWide ? getWCharAlign() : 8; // FIXME
89  }
90
91  /// getShortWidth/Align - Return the size of 'signed short' and
92  /// 'unsigned short' for this target, in bits.
93  unsigned getShortWidth() const { return 16; } // FIXME
94  unsigned getShortAlign() const { return 16; } // FIXME
95
96  /// getIntWidth/Align - Return the size of 'signed int' and 'unsigned int' for
97  /// this target, in bits.
98  unsigned getIntWidth() const { return IntWidth; }
99  unsigned getIntAlign() const { return IntAlign; }
100
101  /// getLongWidth/Align - Return the size of 'signed long' and 'unsigned long'
102  /// for this target, in bits.
103  unsigned getLongWidth() const { return LongWidth; }
104  unsigned getLongAlign() const { return LongAlign; }
105
106  /// getLongLongWidth/Align - Return the size of 'signed long long' and
107  /// 'unsigned long long' for this target, in bits.
108  unsigned getLongLongWidth() const { return LongLongWidth; }
109  unsigned getLongLongAlign() const { return LongLongAlign; }
110
111  /// getWcharWidth/Align - Return the size of 'wchar_t' for this target, in
112  /// bits.
113  unsigned getWCharWidth() const { return WCharWidth; }
114  unsigned getWCharAlign() const { return WCharAlign; }
115
116  /// getFloatWidth/Align/Format - Return the size/align/format of 'float'.
117  unsigned getFloatWidth() const { return 32; } // FIXME
118  unsigned getFloatAlign() const { return 32; } // FIXME
119  const llvm::fltSemantics *getFloatFormat() const { return FloatFormat; }
120
121  /// getDoubleWidth/Align/Format - Return the size/align/format of 'double'.
122  unsigned getDoubleWidth() const { return DoubleWidth; }
123  unsigned getDoubleAlign() const { return DoubleAlign; }
124  const llvm::fltSemantics *getDoubleFormat() const { return DoubleFormat; }
125
126  /// getLongDoubleWidth/Align/Format - Return the size/align/format of 'long
127  /// double'.
128  unsigned getLongDoubleWidth() const { return 64; } // FIXME
129  unsigned getLongDoubleAlign() const { return 64; } // FIXME
130  const llvm::fltSemantics *getLongDoubleFormat() const {
131    return LongDoubleFormat;
132  }
133
134  /// getIntMaxTWidth - Return the size of intmax_t and uintmax_t for this
135  /// target, in bits.
136  unsigned getIntMaxTWidth() const {
137    // FIXME: implement correctly.
138    return 64;
139  }
140
141  ///===---- Other target property query methods --------------------------===//
142
143  /// getTargetDefines - Appends the target-specific #define values for this
144  /// target set to the specified buffer.
145  virtual void getTargetDefines(std::vector<char> &DefineBuffer) const = 0;
146
147  /// getTargetBuiltins - Return information about target-specific builtins for
148  /// the current primary target, and info about which builtins are non-portable
149  /// across the current set of primary and secondary targets.
150  virtual void getTargetBuiltins(const Builtin::Info *&Records,
151                                 unsigned &NumRecords) const = 0;
152
153  /// getVAListDeclaration - Return the declaration to use for
154  /// __builtin_va_list, which is target-specific.
155  virtual const char *getVAListDeclaration() const = 0;
156
157  /// isValidGCCRegisterName - Returns whether the passed in string
158  /// is a valid register name according to GCC. This is used by Sema for
159  /// inline asm statements.
160  bool isValidGCCRegisterName(const char *Name) const;
161
162  // getNormalizedGCCRegisterName - Returns the "normalized" GCC register name.
163  // For example, on x86 it will return "ax" when "eax" is passed in.
164  const char *getNormalizedGCCRegisterName(const char *Name) const;
165
166  enum ConstraintInfo {
167    CI_None = 0x00,
168    CI_AllowsMemory = 0x01,
169    CI_AllowsRegister = 0x02,
170    CI_ReadWrite = 0x04
171  };
172
173  // validateOutputConstraint, validateInputConstraint - Checks that
174  // a constraint is valid and provides information about it.
175  // FIXME: These should return a real error instead of just true/false.
176  bool validateOutputConstraint(const char *Name, ConstraintInfo &Info) const;
177  bool validateInputConstraint (const char *Name, unsigned NumOutputs,
178                                ConstraintInfo &info) const;
179
180  virtual std::string convertConstraint(const char Constraint) const {
181    return std::string(1, Constraint);
182  }
183
184  // Returns a string of target-specific clobbers, in LLVM format.
185  virtual const char *getClobbers() const = 0;
186
187
188  /// getTargetPrefix - Return the target prefix used for identifying
189  /// llvm intrinsics.
190  virtual const char *getTargetPrefix() const = 0;
191
192  /// getTargetTriple - Return the target triple of the primary target.
193  const char *getTargetTriple() const {
194    return Triple.c_str();
195  }
196
197  const char *getTargetDescription() const {
198    // FIXME !
199    // Hard code darwin-x86 for now.
200    return "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:\
20132-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128";
202  }
203
204  struct GCCRegAlias {
205    const char * const Aliases[5];
206    const char * const Register;
207  };
208
209  virtual bool useGlobalsForAutomaticVariables() const {return false;}
210
211protected:
212  virtual void getGCCRegNames(const char * const *&Names,
213                              unsigned &NumNames) const = 0;
214  virtual void getGCCRegAliases(const GCCRegAlias *&Aliases,
215                                unsigned &NumAliases) const = 0;
216  virtual bool validateAsmConstraint(char c,
217                                     TargetInfo::ConstraintInfo &info) const= 0;
218};
219
220}  // end namespace clang
221
222#endif
223