]> granicus.if.org Git - clang/commitdiff
add helpful methods to TargetInfo for querying builtin integer type properties,
authorChris Lattner <sabre@nondot.org>
Wed, 21 Oct 2009 06:24:21 +0000 (06:24 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 21 Oct 2009 06:24:21 +0000 (06:24 +0000)
patch by Ken Dyck!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84746 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/TargetInfo.h
lib/Basic/TargetInfo.cpp

index 5f0230bc4c4970e2e2bcdb915873ab014b581ea4..b88e2aaba383b24aa01aca08be4a0d2aa67f1670 100644 (file)
@@ -98,6 +98,15 @@ public:
   IntType getChar32Type() const { return Char32Type; }
   IntType getInt64Type() const { return Int64Type; }
 
+
+  /// getTypeWidth - Return the width (in bits) of the specified integer type 
+  /// enum. For example, SignedInt -> getIntWidth().
+  unsigned getTypeWidth(IntType T) const;
+
+  /// getTypeSigned - Return whether an integer types is signed. Returns true if
+  /// the type is signed; false otherwise.
+  bool getTypeSigned(IntType T) const;
+
   /// getPointerWidth - Return the width of pointers on this target, for the
   /// specified address space.
   uint64_t getPointerWidth(unsigned AddrSpace) const {
@@ -186,6 +195,10 @@ public:
   /// For example, SignedShort -> "short".
   static const char *getTypeName(IntType T);
 
+  /// getTypeConstantSuffix - Return the constant suffix for the specified
+  /// integer type enum. For example, SignedLong -> "L".
+  static const char *getTypeConstantSuffix(IntType T);
+
   ///===---- Other target property query methods --------------------------===//
 
   /// getTargetDefines - Appends the target-specific #define values for this
@@ -193,6 +206,7 @@ public:
   virtual void getTargetDefines(const LangOptions &Opts,
                                 std::vector<char> &DefineBuffer) const = 0;
 
+
   /// getTargetBuiltins - Return information about target-specific builtins for
   /// the current primary target, and info about which builtins are non-portable
   /// across the current set of primary and secondary targets.
index f9e789c36d567f92fe9da8320a1fa689220b363b..8f3c777c2004c302bce7c9d915e154e870753049 100644 (file)
@@ -74,6 +74,57 @@ const char *TargetInfo::getTypeName(IntType T) {
   }
 }
 
+/// getTypeConstantSuffix - Return the constant suffix for the specified
+/// integer type enum. For example, SignedLong -> "L".
+const char *TargetInfo::getTypeConstantSuffix(IntType T) {
+  switch (T) {
+  default: assert(0 && "not an integer!");
+  case SignedShort:
+  case SignedInt:        return "";
+  case SignedLong:       return "L";
+  case SignedLongLong:   return "LL";
+  case UnsignedShort:
+  case UnsignedInt:      return "U";
+  case UnsignedLong:     return "UL";
+  case UnsignedLongLong: return "ULL";
+  }
+}
+
+/// getTypeWidth - Return the width (in bits) of the specified integer type 
+/// enum. For example, SignedInt -> getIntWidth().
+unsigned TargetInfo::getTypeWidth(IntType T) const {
+  switch (T) {
+  default: assert(0 && "not an integer!");
+  case SignedShort:      return getShortWidth();
+  case UnsignedShort:    return getShortWidth();
+  case SignedInt:        return getIntWidth();
+  case UnsignedInt:      return getIntWidth();
+  case SignedLong:       return getLongWidth();
+  case UnsignedLong:     return getLongWidth();
+  case SignedLongLong:   return getLongLongWidth();
+  case UnsignedLongLong: return getLongLongWidth();
+  };
+}
+
+/// getTypeSigned - Return whether an integer types is signed. Returns true if
+/// the type is signed; false otherwise.
+bool TargetInfo::getTypeSigned(IntType T) const {
+  switch (T) {
+  default: assert(0 && "not an integer!");
+  case SignedShort:
+  case SignedInt:
+  case SignedLong:
+  case SignedLongLong:   
+    return true;
+  case UnsignedShort:
+  case UnsignedInt:
+  case UnsignedLong:
+  case UnsignedLongLong: 
+    return false;
+  };
+}
+
+
 //===----------------------------------------------------------------------===//