diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 17:15:32 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-03-01 17:15:32 +0000 |
commit | 68e2300ad965bf08af11ae363bb85e3badf964dc (patch) | |
tree | 3d9a08599949ad01020884d9a6770616a3afd85b /lib/Support/APInt.cpp | |
parent | 9dd9abd87f77da4e523db02a396721e34631ef32 (diff) |
Add methods for bit width modification: sextOrTrunc, zextOrTrunc.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34789 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/APInt.cpp')
-rw-r--r-- | lib/Support/APInt.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 93442f344c..50b0dc34fe 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -985,6 +985,22 @@ APInt &APInt::zext(uint32_t width) { 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. /// @brief Arithmetic right-shift function. APInt APInt::ashr(uint32_t shiftAmt) const { |