diff options
author | John McCall <rjmccall@apple.com> | 2010-02-28 09:55:58 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-02-28 09:55:58 +0000 |
commit | 1e7ad3993d8700488895fa372ecad55443f53485 (patch) | |
tree | 559719ee3c95466fd921a748a0bddfb75670f6fd /include/llvm/ADT/APInt.h | |
parent | 5b0a7741ad262315d6365250a2da2edb8ba37e69 (diff) | |
download | llvm-1e7ad3993d8700488895fa372ecad55443f53485.tar.gz llvm-1e7ad3993d8700488895fa372ecad55443f53485.tar.bz2 llvm-1e7ad3993d8700488895fa372ecad55443f53485.tar.xz |
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/llvm/ADT/APInt.h')
-rw-r--r-- | include/llvm/ADT/APInt.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index ea940ad178..3f67ffb455 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. |