aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-02-28 09:55:58 +0000
committerJohn McCall <rjmccall@apple.com>2010-02-28 09:55:58 +0000
commit2f1affab0af559475d87a3ff24be66f0fc508156 (patch)
tree559719ee3c95466fd921a748a0bddfb75670f6fd /include
parent297637c4f42bb8fb4347b13bd39fef0896a09f33 (diff)
downloadexternal_llvm-2f1affab0af559475d87a3ff24be66f0fc508156.zip
external_llvm-2f1affab0af559475d87a3ff24be66f0fc508156.tar.gz
external_llvm-2f1affab0af559475d87a3ff24be66f0fc508156.tar.bz2
Add an override to StringRef::getAsInteger which parses into an APInt.
It gets its own implementation totally divorced from the (presumably performance-sensitive) routines which parse into a uint64_t. Add APInt::operator|=(uint64_t), which is situationally much better than using a full APInt. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97381 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/APInt.h25
-rw-r--r--include/llvm/ADT/StringRef.h14
2 files changed, 39 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h
index ea940ad..3f67ffb 100644
--- a/include/llvm/ADT/APInt.h
+++ b/include/llvm/ADT/APInt.h
@@ -150,7 +150,17 @@ class APInt {
return isSingleWord() ? VAL : pVal[whichWord(bitPosition)];
}
+ /// Converts a string into a number. The string must be non-empty
+ /// and well-formed as a number of the given base. The bit-width
+ /// must be sufficient to hold the result.
+ ///
/// This is used by the constructors that take string arguments.
+ ///
+ /// StringRef::getAsInteger is superficially similar but (1) does
+ /// not assume that the string is well-formed and (2) grows the
+ /// result to hold the input.
+ ///
+ /// @param radix 2, 8, 10, or 16
/// @brief Convert a char array into an APInt
void fromString(unsigned numBits, const StringRef &str, uint8_t radix);
@@ -571,6 +581,21 @@ public:
/// @brief Bitwise OR assignment operator.
APInt& operator|=(const APInt& RHS);
+ /// Performs a bitwise OR operation on this APInt and RHS. RHS is
+ /// logically zero-extended or truncated to match the bit-width of
+ /// the LHS.
+ ///
+ /// @brief Bitwise OR assignment operator.
+ APInt& operator|=(uint64_t RHS) {
+ if (isSingleWord()) {
+ VAL |= RHS;
+ clearUnusedBits();
+ } else {
+ pVal[0] |= RHS;
+ }
+ return *this;
+ }
+
/// Performs a bitwise XOR operation on this APInt and RHS. The result is
/// assigned to *this.
/// @returns *this after XORing with RHS.
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h
index 61cb558..9257770 100644
--- a/include/llvm/ADT/StringRef.h
+++ b/include/llvm/ADT/StringRef.h
@@ -18,6 +18,7 @@
namespace llvm {
template<typename T>
class SmallVectorImpl;
+ class APInt;
/// StringRef - Represent a constant reference to a string, i.e. a character
/// array and a length, which need not be null terminated.
@@ -273,6 +274,19 @@ namespace llvm {
// TODO: Provide overloads for int/unsigned that check for overflow.
+ /// getAsInteger - Parse the current string as an integer of the
+ /// specified radix, or of an autosensed radix if the radix given
+ /// is 0. The current value in Result is discarded, and the
+ /// storage is changed to be wide enough to store the parsed
+ /// integer.
+ ///
+ /// Returns true if the string does not solely consist of a valid
+ /// non-empty number in the appropriate base.
+ ///
+ /// APInt::fromString is superficially similar but assumes the
+ /// string is well-formed in the given radix.
+ bool getAsInteger(unsigned Radix, APInt &Result) const;
+
/// @}
/// @name Substring Operations
/// @{