1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===-- llvm/ADT/APSInt.h - Arbitrary Precision Signed Int -----*- C++ -*--===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file implements the APSInt class, which is a simple class that 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// represents an arbitrary sized integer that knows its signedness. 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_APSINT_H 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_APSINT_H 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/ADT/APInt.h" 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass APSInt : public APInt { 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool IsUnsigned; 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic: 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// Default constructor that creates an uninitialized APInt. 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman explicit APSInt() {} 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// APSInt ctor - Create an APSInt with the specified width, default to 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// unsigned. 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman explicit APSInt(uint32_t BitWidth, bool isUnsigned = true) 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman : APInt(BitWidth, 0), IsUnsigned(isUnsigned) {} 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman explicit APSInt(const APInt &I, bool isUnsigned = true) 34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman : APInt(I), IsUnsigned(isUnsigned) {} 35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt &operator=(const APSInt &RHS) { 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APInt::operator=(RHS); 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman IsUnsigned = RHS.IsUnsigned; 39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt &operator=(const APInt &RHS) { 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Retain our current sign. 44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APInt::operator=(RHS); 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt &operator=(uint64_t RHS) { 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Retain our current sign. 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APInt::operator=(RHS); 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Query sign information. 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool isSigned() const { return !IsUnsigned; } 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool isUnsigned() const { return IsUnsigned; } 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setIsUnsigned(bool Val) { IsUnsigned = Val; } 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setIsSigned(bool Val) { IsUnsigned = !Val; } 59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// toString - Append this APSInt to the specified SmallString. 61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void toString(SmallVectorImpl<char> &Str, unsigned Radix = 10) const { 62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APInt::toString(Str, Radix, isSigned()); 63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// toString - Converts an APInt to a std::string. This is an inefficient 65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// method, your should prefer passing in a SmallString instead. 66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman std::string toString(unsigned Radix) const { 67894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APInt::toString(Radix, isSigned()); 68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman using APInt::toString; 70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 7119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman APSInt trunc(uint32_t width) const { 7219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return APSInt(APInt::trunc(width), IsUnsigned); 7319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 7419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman APSInt extend(uint32_t width) const { 76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman if (IsUnsigned) 7719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return APSInt(zext(width), IsUnsigned); 78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman else 7919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return APSInt(sext(width), IsUnsigned); 80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 8219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman APSInt extOrTrunc(uint32_t width) const { 83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman if (IsUnsigned) 8419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return APSInt(zextOrTrunc(width), IsUnsigned); 85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman else 8619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman return APSInt(sextOrTrunc(width), IsUnsigned); 87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 88894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 89894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const APSInt &operator%=(const APSInt &RHS) { 90894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 91894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman if (IsUnsigned) 92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman *this = urem(RHS); 93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman else 94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman *this = srem(RHS); 95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const APSInt &operator/=(const APSInt &RHS) { 98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman if (IsUnsigned) 100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman *this = udiv(RHS); 101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman else 102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman *this = sdiv(RHS); 103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator%(const APSInt &RHS) const { 106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return IsUnsigned ? APSInt(urem(RHS), true) : APSInt(srem(RHS), false); 108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator/(const APSInt &RHS) const { 110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return IsUnsigned ? APSInt(udiv(RHS), true) : APSInt(sdiv(RHS), false); 112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator>>(unsigned Amt) const { 115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return IsUnsigned ? APSInt(lshr(Amt), true) : APSInt(ashr(Amt), false); 116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator>>=(unsigned Amt) { 118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman *this = *this >> Amt; 119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman inline bool operator<(const APSInt& RHS) const { 123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return IsUnsigned ? ult(RHS) : slt(RHS); 125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman inline bool operator>(const APSInt& RHS) const { 127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return IsUnsigned ? ugt(RHS) : sgt(RHS); 129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman inline bool operator<=(const APSInt& RHS) const { 131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return IsUnsigned ? ule(RHS) : sle(RHS); 133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman inline bool operator>=(const APSInt& RHS) const { 135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return IsUnsigned ? uge(RHS) : sge(RHS); 137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // The remaining operators just wrap the logic of APInt, but retain the 140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // signedness information. 141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator<<(unsigned Bits) const { 143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(static_cast<const APInt&>(*this) << Bits, IsUnsigned); 144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator<<=(unsigned Amt) { 146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman *this = *this << Amt; 147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator++() { 151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static_cast<APInt&>(*this)++; 152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator--() { 155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static_cast<APInt&>(*this)--; 156894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 157894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator++(int) { 159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(++static_cast<APInt&>(*this), IsUnsigned); 160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator--(int) { 162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(--static_cast<APInt&>(*this), IsUnsigned); 163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator-() const { 165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(-static_cast<const APInt&>(*this), IsUnsigned); 166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator+=(const APSInt& RHS) { 168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static_cast<APInt&>(*this) += RHS; 170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator-=(const APSInt& RHS) { 173894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 174894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static_cast<APInt&>(*this) -= RHS; 175894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator*=(const APSInt& RHS) { 178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static_cast<APInt&>(*this) *= RHS; 180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 182894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator&=(const APSInt& RHS) { 183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static_cast<APInt&>(*this) &= RHS; 185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator|=(const APSInt& RHS) { 188894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static_cast<APInt&>(*this) |= RHS; 190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt& operator^=(const APSInt& RHS) { 193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static_cast<APInt&>(*this) ^= RHS; 195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return *this; 196894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator&(const APSInt& RHS) const { 199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(static_cast<const APInt&>(*this) & RHS, IsUnsigned); 201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt And(const APSInt& RHS) const { 203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return this->operator&(RHS); 204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 205894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 206894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator|(const APSInt& RHS) const { 207894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(static_cast<const APInt&>(*this) | RHS, IsUnsigned); 209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt Or(const APSInt& RHS) const { 211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return this->operator|(RHS); 212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator^(const APSInt& RHS) const { 216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(static_cast<const APInt&>(*this) ^ RHS, IsUnsigned); 218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt Xor(const APSInt& RHS) const { 220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return this->operator^(RHS); 221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator*(const APSInt& RHS) const { 224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(static_cast<const APInt&>(*this) * RHS, IsUnsigned); 226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator+(const APSInt& RHS) const { 228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(static_cast<const APInt&>(*this) + RHS, IsUnsigned); 230894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 231894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator-(const APSInt& RHS) const { 232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); 233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(static_cast<const APInt&>(*this) - RHS, IsUnsigned); 234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 235894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman APSInt operator~() const { 236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(~static_cast<const APInt&>(*this), IsUnsigned); 237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 238894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 239894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getMaxValue - Return the APSInt representing the maximum integer value 240894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// with the given bit width and signedness. 241894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static APSInt getMaxValue(uint32_t numBits, bool Unsigned) { 242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(Unsigned ? APInt::getMaxValue(numBits) 243894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman : APInt::getSignedMaxValue(numBits), Unsigned); 244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 245894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 246894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getMinValue - Return the APSInt representing the minimum integer value 247894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// with the given bit width and signedness. 248894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static APSInt getMinValue(uint32_t numBits, bool Unsigned) { 249894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return APSInt(Unsigned ? APInt::getMinValue(numBits) 250894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman : APInt::getSignedMinValue(numBits), Unsigned); 251894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 252894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 253894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// Profile - Used to insert APSInt objects, or objects that contain APSInt 254894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// objects, into FoldingSets. 255894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void Profile(FoldingSetNodeID& ID) const; 256894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}; 257894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 258894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumaninline raw_ostream &operator<<(raw_ostream &OS, const APSInt &I) { 259894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman I.print(OS, I.isSigned()); 260894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return OS; 261894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 262894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 263894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 264894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // end namespace llvm 265894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 266894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif 267