diff options
Diffstat (limited to 'include/llvm/ADT')
-rw-r--r-- | include/llvm/ADT/APInt.h | 37 | ||||
-rw-r--r-- | include/llvm/ADT/APSInt.h | 18 |
2 files changed, 39 insertions, 16 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 9e8119d..c475cf3 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -17,6 +17,7 @@ #include "llvm/Support/DataTypes.h" #include <cassert> +#include <iosfwd> #include <string> namespace llvm { @@ -24,6 +25,9 @@ namespace llvm { class Deserializer; class FoldingSetNodeID; + template<typename T> + class SmallVectorImpl; + /* An unsigned host type used as a single part of a multi-part bignum. */ typedef uint64_t integerPart; @@ -468,7 +472,7 @@ public: /// Performs logical negation operation on this APInt. /// @returns true if *this is zero, false otherwise. /// @brief Logical negation operator. - bool operator !() const; + bool operator!() const; /// @} /// @name Assignment Operators @@ -972,25 +976,29 @@ public: /// @name Conversion Functions /// @{ - /// 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, bool wantSigned) const; + void print(std::ostream &OS, bool isSigned) const; + + /// toString - Converts an APInt to a string and append it to Str. Str is + /// commonly a SmallString. + void toString(SmallVectorImpl<char> &Str, unsigned Radix, bool Signed) const; /// Considers the APInt to be unsigned and converts it into a string in the /// radix given. The radix can be 2, 8, 10 or 16. - /// @returns a character interpretation of the APInt - /// @brief Convert unsigned APInt to string representation. - std::string toStringUnsigned(uint8_t radix = 10) const { - return toString(radix, false); + void toStringUnsigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const { + return toString(Str, Radix, false); } /// Considers the APInt to be signed and converts it into a string in the /// radix given. The radix can be 2, 8, 10 or 16. - /// @returns a character interpretation of the APInt - /// @brief Convert signed APInt to string representation. - std::string toStringSigned(uint8_t radix = 10) const { - return toString(radix, true); + void toStringSigned(SmallVectorImpl<char> &Str, unsigned Radix = 10) const { + return toString(Str, Radix, true); } + + /// toString - This returns the APInt as a std::string. Note that this is an + /// inefficient method. It is better to pass in a SmallVector/SmallString + /// to the methods above to avoid thrashing the heap for the string. + std::string toString(unsigned Radix, bool Signed) const; + /// @returns a byte-swapped representation of this APInt Value. APInt byteSwap() const; @@ -1237,6 +1245,11 @@ inline bool operator!=(uint64_t V1, const APInt& V2) { return V2 != V1; } +inline std::ostream &operator<<(std::ostream &OS, const APInt &I) { + I.print(OS, true); + return OS; +} + namespace APIntOps { /// @brief Determine the smaller of two APInts considered to be signed. diff --git a/include/llvm/ADT/APSInt.h b/include/llvm/ADT/APSInt.h index edb36ba..00bece6 100644 --- a/include/llvm/ADT/APSInt.h +++ b/include/llvm/ADT/APSInt.h @@ -19,7 +19,6 @@ namespace llvm { - class APSInt : public APInt { bool IsUnsigned; public: @@ -58,11 +57,16 @@ public: 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 { + /// toString - Append this APSInt to the specified SmallString. + void toString(SmallVectorImpl<char> &Str, unsigned Radix = 10) const { + return APInt::toString(Str, Radix, isSigned()); + } + /// toString - Converts an APInt to a std::string. This is an inefficient + /// method, your should prefer passing in a SmallString instead. + std::string toString(unsigned Radix) const { return APInt::toString(Radix, isSigned()); } + using APInt::toString; APSInt& extend(uint32_t width) { if (IsUnsigned) @@ -235,6 +239,12 @@ public: void Profile(FoldingSetNodeID& ID) const; }; +inline std::ostream &operator<<(std::ostream &OS, const APSInt &I) { + I.print(OS, I.isSigned()); + return OS; +} + + } // end namespace llvm #endif |