using llvm::APInt;
using llvm::APSInt;
-Scalar::Category Scalar::GetCategory(Scalar::Type type) {
- switch (type) {
- case Scalar::e_void:
- return Category::Void;
- case Scalar::e_float:
- return Category::Float;
- case Scalar::e_int:
- return Category::Integral;
- }
- llvm_unreachable("Unhandled type!");
-}
-
Scalar::PromotionKey Scalar::GetPromoKey() const {
- Category cat = GetCategory(m_type);
- switch (cat) {
- case Category::Void:
- return PromotionKey{cat, 0, false};
- case Category::Integral:
- return PromotionKey{cat, m_integer.getBitWidth(), m_integer.isUnsigned()};
- case Category::Float:
+ switch (m_type) {
+ case e_void:
+ return PromotionKey{e_void, 0, false};
+ case e_int:
+ return PromotionKey{e_int, m_integer.getBitWidth(), m_integer.isUnsigned()};
+ case e_float:
return GetFloatPromoKey(m_float.getSemantics());
}
llvm_unreachable("Unhandled category!");
&APFloat::x87DoubleExtended()};
for (const auto &entry : llvm::enumerate(order)) {
if (entry.value() == &sem)
- return PromotionKey{Category::Float, entry.index(), false};
+ return PromotionKey{e_float, entry.index(), false};
}
llvm_unreachable("Unsupported semantics!");
}
// expressions.
Scalar::Type Scalar::PromoteToMaxType(Scalar &lhs, Scalar &rhs) {
const auto &Promote = [](Scalar &a, const Scalar &b) {
- switch (GetCategory(b.GetType())) {
- case Category::Void:
+ switch (b.GetType()) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
a.IntegralPromote(b.m_integer.getBitWidth(), b.m_integer.isSigned());
break;
- case Category::Float:
+ case e_float:
a.FloatPromote(b.m_float.getSemantics());
}
};
const auto &store = [&](const llvm::APInt &val) {
StoreIntToMemory(val, storage.data(), (val.getBitWidth() + 7) / 8);
};
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
store(m_integer);
break;
- case Category::Float:
+ case e_float:
store(m_float.bitcastToAPInt());
break;
}
}
bool Scalar::IsZero() const {
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
return m_integer.isNullValue();
- case Category::Float:
+ case e_float:
return m_float.isZero();
}
return false;
if (show_type)
s->Printf("(%s) ", GetTypeAsCString());
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
s->PutCString(m_integer.toString(10));
break;
- case Category::Float:
+ case e_float:
llvm::SmallString<24> string;
m_float.toString(string);
s->PutCString(string);
}
bool Scalar::IntegralPromote(uint16_t bits, bool sign) {
- switch (GetCategory(m_type)) {
- case Category::Void:
- case Category::Float:
+ switch (m_type) {
+ case e_void:
+ case e_float:
break;
- case Category::Integral:
- if (GetPromoKey() > PromotionKey(Category::Integral, bits, !sign))
+ case e_int:
+ if (GetPromoKey() > PromotionKey(e_int, bits, !sign))
break;
m_integer = m_integer.extOrTrunc(bits);
m_integer.setIsSigned(sign);
bool Scalar::FloatPromote(const llvm::fltSemantics &semantics) {
bool success = false;
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
m_float = llvm::APFloat(semantics);
m_float.convertFromAPInt(m_integer, m_integer.isSigned(),
llvm::APFloat::rmNearestTiesToEven);
success = true;
break;
- case Category::Float:
+ case e_float:
if (GetFloatPromoKey(semantics) < GetFloatPromoKey(m_float.getSemantics()))
break;
bool ignore;
}
template <typename T> T Scalar::GetAs(T fail_value) const {
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral: {
+ case e_int: {
APSInt ext = m_integer.extOrTrunc(sizeof(T) * 8);
if (ext.isSigned())
return ext.getSExtValue();
return ext.getZExtValue();
}
- case Category::Float:
+ case e_float:
return ToAPInt(m_float, sizeof(T) * 8, std::is_unsigned<T>::value)
.getSExtValue();
}
}
llvm::APInt Scalar::SInt128(const llvm::APInt &fail_value) const {
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
return m_integer;
- case Category::Float:
+ case e_float:
return ToAPInt(m_float, 128, /*is_unsigned=*/false);
}
return fail_value;
}
llvm::APInt Scalar::UInt128(const llvm::APInt &fail_value) const {
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
return m_integer;
- case Category::Float:
+ case e_float:
return ToAPInt(m_float, 128, /*is_unsigned=*/true);
}
return fail_value;
}
float Scalar::Float(float fail_value) const {
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
if (m_integer.isSigned())
return llvm::APIntOps::RoundSignedAPIntToFloat(m_integer);
return llvm::APIntOps::RoundAPIntToFloat(m_integer);
- case Category::Float: {
+ case e_float: {
APFloat result = m_float;
bool losesInfo;
result.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven,
}
double Scalar::Double(double fail_value) const {
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
if (m_integer.isSigned())
return llvm::APIntOps::RoundSignedAPIntToDouble(m_integer);
return llvm::APIntOps::RoundAPIntToDouble(m_integer);
- case Category::Float: {
+ case e_float: {
APFloat result = m_float;
bool losesInfo;
result.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
Scalar &Scalar::operator+=(Scalar rhs) {
Scalar copy = *this;
if ((m_type = PromoteToMaxType(copy, rhs)) != Scalar::e_void) {
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
m_integer = copy.m_integer + rhs.m_integer;
break;
- case Category::Float:
+ case e_float:
m_float = copy.m_float + rhs.m_float;
break;
}
}
Scalar &Scalar::operator<<=(const Scalar &rhs) {
- if (GetCategory(m_type) == Category::Integral &&
- GetCategory(rhs.m_type) == Category::Integral)
+ if (m_type == e_int && rhs.m_type == e_int)
static_cast<APInt &>(m_integer) <<= rhs.m_integer;
else
m_type = e_void;
}
bool Scalar::ShiftRightLogical(const Scalar &rhs) {
- if (GetCategory(m_type) == Category::Integral &&
- GetCategory(rhs.m_type) == Category::Integral) {
+ if (m_type == e_int && rhs.m_type == e_int) {
m_integer = m_integer.lshr(rhs.m_integer);
return true;
}
}
Scalar &Scalar::operator&=(const Scalar &rhs) {
- if (GetCategory(m_type) == Category::Integral &&
- GetCategory(rhs.m_type) == Category::Integral)
+ if (m_type == e_int && rhs.m_type == e_int)
m_integer &= rhs.m_integer;
else
m_type = e_void;
}
bool Scalar::UnaryNegate() {
- switch (GetCategory(m_type)) {
- case Category::Void:
+ switch (m_type) {
+ case e_void:
break;
- case Category::Integral:
+ case e_int:
m_integer = -m_integer;
return true;
- case Category::Float:
+ case e_float:
m_float.changeSign();
return true;
}
}
bool Scalar::OnesComplement() {
- if (GetCategory(m_type) == Category::Integral) {
+ if (m_type == e_int) {
m_integer = ~m_integer;
return true;
}
const Scalar lldb_private::operator-(Scalar lhs, Scalar rhs) {
Scalar result;
if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void) {
- switch (Scalar::GetCategory(result.m_type)) {
- case Scalar::Category::Void:
+ switch (result.m_type) {
+ case Scalar::e_void:
break;
- case Scalar::Category::Integral:
+ case Scalar::e_int:
result.m_integer = lhs.m_integer - rhs.m_integer;
break;
- case Scalar::Category::Float:
+ case Scalar::e_float:
result.m_float = lhs.m_float - rhs.m_float;
break;
}
Scalar result;
if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void &&
!rhs.IsZero()) {
- switch (Scalar::GetCategory(result.m_type)) {
- case Scalar::Category::Void:
+ switch (result.m_type) {
+ case Scalar::e_void:
break;
- case Scalar::Category::Integral:
+ case Scalar::e_int:
result.m_integer = lhs.m_integer / rhs.m_integer;
return result;
- case Scalar::Category::Float:
+ case Scalar::e_float:
result.m_float = lhs.m_float / rhs.m_float;
return result;
}
const Scalar lldb_private::operator*(Scalar lhs, Scalar rhs) {
Scalar result;
if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void) {
- switch (Scalar::GetCategory(result.m_type)) {
- case Scalar::Category::Void:
+ switch (result.m_type) {
+ case Scalar::e_void:
break;
- case Scalar::Category::Integral:
+ case Scalar::e_int:
result.m_integer = lhs.m_integer * rhs.m_integer;
break;
- case Scalar::Category::Float:
+ case Scalar::e_float:
result.m_float = lhs.m_float * rhs.m_float;
break;
}
const Scalar lldb_private::operator&(Scalar lhs, Scalar rhs) {
Scalar result;
if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void) {
- if (Scalar::GetCategory(result.m_type) == Scalar::Category::Integral)
+ if (result.m_type == Scalar::e_int)
result.m_integer = lhs.m_integer & rhs.m_integer;
else
result.m_type = Scalar::e_void;
const Scalar lldb_private::operator|(Scalar lhs, Scalar rhs) {
Scalar result;
if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void) {
- if (Scalar::GetCategory(result.m_type) == Scalar::Category::Integral)
+ if (result.m_type == Scalar::e_int)
result.m_integer = lhs.m_integer | rhs.m_integer;
else
result.m_type = Scalar::e_void;
const Scalar lldb_private::operator%(Scalar lhs, Scalar rhs) {
Scalar result;
if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void) {
- if (!rhs.IsZero() &&
- Scalar::GetCategory(result.m_type) == Scalar::Category::Integral) {
+ if (!rhs.IsZero() && result.m_type == Scalar::e_int) {
result.m_integer = lhs.m_integer % rhs.m_integer;
return result;
}
const Scalar lldb_private::operator^(Scalar lhs, Scalar rhs) {
Scalar result;
if ((result.m_type = Scalar::PromoteToMaxType(lhs, rhs)) != Scalar::e_void) {
- if (Scalar::GetCategory(result.m_type) == Scalar::Category::Integral)
+ if (result.m_type == Scalar::e_int)
result.m_integer = lhs.m_integer ^ rhs.m_integer;
else
result.m_type = Scalar::e_void;