1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Add methods for bit width modification: sextOrTrunc, zextOrTrunc.

llvm-svn: 34789
This commit is contained in:
Reid Spencer 2007-03-01 17:15:32 +00:00
parent eaf27d276a
commit 6a95676875
2 changed files with 26 additions and 0 deletions

View File

@ -423,6 +423,16 @@ public:
/// @brief Zero extend to a new width. /// @brief Zero extend to a new width.
APInt &zext(uint32_t width); APInt &zext(uint32_t width);
/// Make this APInt have the bit width given by \p width. The value is sign
/// extended, truncated, or left alone to make it that width.
/// @brief Sign extend or truncate to width
APInt &sextOrTrunc(uint32_t width);
/// Make this APInt have the bit width given by \p width. The value is zero
/// extended, truncated, or left alone to make it that width.
/// @brief Zero extend or truncate to width
APInt &zextOrTrunc(uint32_t width);
/// @brief Set every bit to 1. /// @brief Set every bit to 1.
APInt& set(); APInt& set();

View File

@ -985,6 +985,22 @@ APInt &APInt::zext(uint32_t width) {
return *this; return *this;
} }
APInt &APInt::zextOrTrunc(uint32_t width) {
if (BitWidth < width)
return zext(width);
if (BitWidth > width)
return trunc(width);
return *this;
}
APInt &APInt::sextOrTrunc(uint32_t width) {
if (BitWidth < width)
return sext(width);
if (BitWidth > width)
return trunc(width);
return *this;
}
/// Arithmetic right-shift this APInt by shiftAmt. /// Arithmetic right-shift this APInt by shiftAmt.
/// @brief Arithmetic right-shift function. /// @brief Arithmetic right-shift function.
APInt APInt::ashr(uint32_t shiftAmt) const { APInt APInt::ashr(uint32_t shiftAmt) const {