mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 22:28:18 +00:00
As Chris suggested, fixed some problems. (This is the first part.)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33986 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -45,7 +45,7 @@ class APInt {
|
|||||||
friend double APIntToDouble(const APInt& APIVal);
|
friend double APIntToDouble(const APInt& APIVal);
|
||||||
friend float APIntToFloat(const APInt& APIVal);
|
friend float APIntToFloat(const APInt& APIVal);
|
||||||
|
|
||||||
unsigned bitsnum; ///< The number of bits.
|
unsigned BitsNum; ///< The number of bits.
|
||||||
bool isSigned; ///< The sign flag for this APInt.
|
bool isSigned; ///< The sign flag for this APInt.
|
||||||
|
|
||||||
/// This union is used to store the integer value. When the
|
/// This union is used to store the integer value. When the
|
||||||
@@ -64,22 +64,22 @@ class APInt {
|
|||||||
/// Here one word's bitwidth equals to that of uint64_t.
|
/// Here one word's bitwidth equals to that of uint64_t.
|
||||||
/// @returns the number of words to hold the integer value of this APInt.
|
/// @returns the number of words to hold the integer value of this APInt.
|
||||||
/// @brief Get the number of words.
|
/// @brief Get the number of words.
|
||||||
inline unsigned numWords() const {
|
inline unsigned getNumWords() const {
|
||||||
return bitsnum < 1 ? 0 : (bitsnum + APINT_BITS_PER_WORD - 1) /
|
return (BitsNum + APINT_BITS_PER_WORD - 1) / APINT_BITS_PER_WORD;
|
||||||
APINT_BITS_PER_WORD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns true if the number of bits <= 64, false otherwise.
|
/// @returns true if the number of bits <= 64, false otherwise.
|
||||||
/// @brief Determine if this APInt just has one word to store value.
|
/// @brief Determine if this APInt just has one word to store value.
|
||||||
inline bool isSingleWord() const
|
inline bool isSingleWord() const
|
||||||
{ return bitsnum <= APINT_BITS_PER_WORD; }
|
{ return BitsNum <= APINT_BITS_PER_WORD; }
|
||||||
|
|
||||||
/// @returns the word position for the specified bit position.
|
/// @returns the word position for the specified bit position.
|
||||||
static inline unsigned whichWord(unsigned bitPosition)
|
static inline unsigned whichWord(unsigned bitPosition)
|
||||||
{ return bitPosition / APINT_BITS_PER_WORD; }
|
{ return bitPosition / APINT_BITS_PER_WORD; }
|
||||||
|
|
||||||
/// @returns the byte position for the specified bit position.
|
/// @returns the byte position for the specified bit position.
|
||||||
static inline unsigned whichByte(unsigned bitPosition);
|
static inline unsigned whichByte(unsigned bitPosition)
|
||||||
|
{ return (bitPosition % APINT_BITS_PER_WORD) / 8; }
|
||||||
|
|
||||||
/// @returns the bit position in a word for the specified bit position
|
/// @returns the bit position in a word for the specified bit position
|
||||||
/// in APInt.
|
/// in APInt.
|
||||||
@@ -93,10 +93,10 @@ class APInt {
|
|||||||
|
|
||||||
inline void TruncToBits() {
|
inline void TruncToBits() {
|
||||||
if (isSingleWord())
|
if (isSingleWord())
|
||||||
VAL &= ~uint64_t(0ULL) >> (APINT_BITS_PER_WORD - bitsnum);
|
VAL &= ~uint64_t(0ULL) >> (APINT_BITS_PER_WORD - BitsNum);
|
||||||
else
|
else
|
||||||
pVal[numWords() - 1] &= ~uint64_t(0ULL) >>
|
pVal[getNumWords() - 1] &= ~uint64_t(0ULL) >>
|
||||||
(APINT_BITS_PER_WORD - (whichBit(bitsnum - 1) + 1));
|
(APINT_BITS_PER_WORD - (whichBit(BitsNum - 1) + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns the corresponding word for the specified bit position.
|
/// @returns the corresponding word for the specified bit position.
|
||||||
@@ -108,6 +108,9 @@ class APInt {
|
|||||||
inline uint64_t getWord(unsigned bitPosition) const
|
inline uint64_t getWord(unsigned bitPosition) const
|
||||||
{ return isSingleWord() ? VAL : pVal[whichWord(bitPosition)]; }
|
{ return isSingleWord() ? VAL : pVal[whichWord(bitPosition)]; }
|
||||||
|
|
||||||
|
/// @brief Converts a char array into an integer.
|
||||||
|
void StrToAPInt(const char *StrStart, unsigned slen, uint8_t radix);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// @brief Create a new APInt of numBits bit-width, and initialized as val.
|
/// @brief Create a new APInt of numBits bit-width, and initialized as val.
|
||||||
APInt(uint64_t val = 0, unsigned numBits = APINT_BITS_PER_WORD,
|
APInt(uint64_t val = 0, unsigned numBits = APINT_BITS_PER_WORD,
|
||||||
@@ -119,7 +122,11 @@ public:
|
|||||||
|
|
||||||
/// @brief Create a new APInt by translating the string represented
|
/// @brief Create a new APInt by translating the string represented
|
||||||
/// integer value.
|
/// integer value.
|
||||||
APInt(std::string& Val, uint8_t radix = 10, bool sign = false);
|
APInt(const std::string& Val, uint8_t radix = 10, bool sign = false);
|
||||||
|
|
||||||
|
/// @brief Create a new APInt by translating the char array represented
|
||||||
|
/// integer value.
|
||||||
|
APInt(const char StrStart[], unsigned slen, uint8_t radix, bool sign = false);
|
||||||
|
|
||||||
/// @brief Copy Constructor.
|
/// @brief Copy Constructor.
|
||||||
APInt(const APInt& API);
|
APInt(const APInt& API);
|
||||||
@@ -136,7 +143,10 @@ public:
|
|||||||
|
|
||||||
/// Increments the APInt by one.
|
/// Increments the APInt by one.
|
||||||
/// @brief Postfix increment operator.
|
/// @brief Postfix increment operator.
|
||||||
const APInt operator++(int);
|
inline const APInt operator++(int) {
|
||||||
|
APInt API(*this);
|
||||||
|
return ++API;
|
||||||
|
}
|
||||||
|
|
||||||
/// Increments the APInt by one.
|
/// Increments the APInt by one.
|
||||||
/// @brief Prefix increment operator.
|
/// @brief Prefix increment operator.
|
||||||
@@ -144,7 +154,10 @@ public:
|
|||||||
|
|
||||||
/// Decrements the APInt by one.
|
/// Decrements the APInt by one.
|
||||||
/// @brief Postfix decrement operator.
|
/// @brief Postfix decrement operator.
|
||||||
const APInt operator--(int);
|
inline const APInt operator--(int) {
|
||||||
|
APInt API(*this);
|
||||||
|
return --API;
|
||||||
|
}
|
||||||
|
|
||||||
/// Decrements the APInt by one.
|
/// Decrements the APInt by one.
|
||||||
/// @brief Prefix decrement operator.
|
/// @brief Prefix decrement operator.
|
||||||
@@ -264,11 +277,25 @@ public:
|
|||||||
/// @brief Equality operator.
|
/// @brief Equality operator.
|
||||||
bool operator==(const APInt& RHS) const;
|
bool operator==(const APInt& RHS) const;
|
||||||
|
|
||||||
|
/// Compare this APInt with the given uint64_t value
|
||||||
|
/// for the validity of the equality relationship.
|
||||||
|
/// @brief Equality operator.
|
||||||
|
bool operator==(uint64_t Val) const;
|
||||||
|
|
||||||
/// Compare this APInt with the given APInt& RHS
|
/// Compare this APInt with the given APInt& RHS
|
||||||
/// for the validity of the inequality relationship.
|
/// for the validity of the inequality relationship.
|
||||||
/// @brief Inequality operator.
|
/// @brief Inequality operator.
|
||||||
bool operator!=(const APInt& RHS) const;
|
inline bool operator!=(const APInt& RHS) const {
|
||||||
|
return !((*this) == RHS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Compare this APInt with the given uint64_t value
|
||||||
|
/// for the validity of the inequality relationship.
|
||||||
|
/// @brief Inequality operator.
|
||||||
|
inline bool operator!=(uint64_t Val) const {
|
||||||
|
return !((*this) == Val);
|
||||||
|
}
|
||||||
|
|
||||||
/// Compare this APInt with the given APInt& RHS for
|
/// Compare this APInt with the given APInt& RHS for
|
||||||
/// the validity of the less-than relationship.
|
/// the validity of the less-than relationship.
|
||||||
/// @brief Less-than operator.
|
/// @brief Less-than operator.
|
||||||
@@ -293,11 +320,10 @@ public:
|
|||||||
/// word, just returns VAL, otherwise pVal[0].
|
/// word, just returns VAL, otherwise pVal[0].
|
||||||
inline uint64_t getValue() {
|
inline uint64_t getValue() {
|
||||||
if (isSingleWord())
|
if (isSingleWord())
|
||||||
return isSigned ? ((int64_t(VAL) << (APINT_BITS_PER_WORD - bitsnum)) >>
|
return isSigned ? ((int64_t(VAL) << (APINT_BITS_PER_WORD - BitsNum)) >>
|
||||||
(APINT_BITS_PER_WORD - bitsnum)) :
|
(APINT_BITS_PER_WORD - BitsNum)) :
|
||||||
VAL;
|
VAL;
|
||||||
else
|
assert(0 && "This APInt's bitwidth > 64");
|
||||||
return pVal[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @returns the largest value for an APInt of the specified bit-width and
|
/// @returns the largest value for an APInt of the specified bit-width and
|
||||||
@@ -344,12 +370,12 @@ public:
|
|||||||
/// @returns a character interpretation of the APInt.
|
/// @returns a character interpretation of the APInt.
|
||||||
std::string to_string(uint8_t radix = 10) const;
|
std::string to_string(uint8_t radix = 10) const;
|
||||||
|
|
||||||
/// Get an APInt with the same bitsnum as this APInt, just zero mask
|
/// Get an APInt with the same BitsNum as this APInt, just zero mask
|
||||||
/// the low bits and right shift to the least significant bit.
|
/// the low bits and right shift to the least significant bit.
|
||||||
/// @returns the high "numBits" bits of this APInt.
|
/// @returns the high "numBits" bits of this APInt.
|
||||||
APInt HiBits(unsigned numBits) const;
|
APInt HiBits(unsigned numBits) const;
|
||||||
|
|
||||||
/// Get an APInt with the same bitsnum as this APInt, just zero mask
|
/// Get an APInt with the same BitsNum as this APInt, just zero mask
|
||||||
/// the high bits.
|
/// the high bits.
|
||||||
/// @returns the low "numBits" bits of this APInt.
|
/// @returns the low "numBits" bits of this APInt.
|
||||||
APInt LoBits(unsigned numBits) const;
|
APInt LoBits(unsigned numBits) const;
|
||||||
@@ -372,7 +398,7 @@ public:
|
|||||||
|
|
||||||
/// @returns the total number of bits.
|
/// @returns the total number of bits.
|
||||||
inline unsigned getNumBits() const
|
inline unsigned getNumBits() const
|
||||||
{ return bitsnum; }
|
{ return BitsNum; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -404,7 +430,7 @@ APInt ByteSwap(const APInt& APIVal);
|
|||||||
|
|
||||||
/// @returns the floor log base 2 of the specified APInt value.
|
/// @returns the floor log base 2 of the specified APInt value.
|
||||||
inline APInt LogBase2(const APInt& APIVal) {
|
inline APInt LogBase2(const APInt& APIVal) {
|
||||||
return APIVal.numWords() * APInt::APINT_BITS_PER_WORD -
|
return APIVal.getNumWords() * APInt::APINT_BITS_PER_WORD -
|
||||||
APIVal.CountLeadingZeros();
|
APIVal.CountLeadingZeros();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user