Use vector for child storage instead of map. This will also make
[oota-llvm.git] / include / llvm / ADT / APSInt.h
index d75c7094cd4324be8206393bd73effdfd12d122b..4339cd08149e4fa548d1a0a64f30fbb5b79e7c9a 100644 (file)
@@ -1,4 +1,4 @@
-//===-- llvm/Support/APSInt.h - Arbitrary Precision Signed Int -*- C++ -*--===//
+//===-- llvm/ADT/APSInt.h - Arbitrary Precision Signed Int -----*- C++ -*--===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -25,7 +25,7 @@ class APSInt : public APInt {
 public:
   /// APSInt ctor - Create an APSInt with the specified width, default to
   /// unsigned.
-  explicit APSInt(unsigned BitWidth) : APInt(BitWidth, 0), IsUnsigned(true) {}
+  explicit APSInt(uint32_t BitWidth) : APInt(BitWidth, 0), IsUnsigned(true) {}
   APSInt(const APInt &I) : APInt(I), IsUnsigned(true) {}
 
   APSInt &operator=(const APSInt &RHS) {
@@ -50,6 +50,13 @@ public:
   bool isSigned() const { return !IsUnsigned; }
   bool isUnsigned() const { return IsUnsigned; }
   void setIsUnsigned(bool Val) { IsUnsigned = Val; }
+  void setIsSigned(bool Val) { IsUnsigned = !Val; }
+  
+  /// This is used internally to convert an APInt to a string.
+  /// @brief Converts an APInt to a std::string
+  std::string toString(uint8_t Radix = 10) const {
+    return APInt::toString(Radix, isSigned());
+  }
   
   
   const APSInt &operator%=(const APSInt &RHS) {
@@ -68,13 +75,37 @@ public:
       *this = sdiv(RHS);
     return *this;
   }
+  APSInt operator%(const APSInt &RHS) const {
+    assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
+    return IsUnsigned ? urem(RHS) : srem(RHS);
+  }
+  APSInt operator/(const APSInt &RHS) const {
+    assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!");
+    return IsUnsigned ? udiv(RHS) : sdiv(RHS);
+  }
   
   const APSInt &operator>>=(unsigned Amt) {
     *this = *this >> Amt;
     return *this;
   }
   
-  APSInt operator>>(unsigned Amt) {
+  APSInt& extend(uint32_t width) {
+    if (IsUnsigned)
+      zext(width);
+    else
+      sext(width);
+    return *this;
+  }
+  
+  APSInt& extOrTrunc(uint32_t width) {
+      if (IsUnsigned)
+        zextOrTrunc(width);
+      else
+        sextOrTrunc(width);
+      return *this;
+  }
+  
+  APSInt operator>>(unsigned Amt) const {
     return IsUnsigned ? lshr(Amt) : ashr(Amt);
   }