17#include "llvm/ADT/APSInt.h"
18#include "llvm/ADT/SmallString.h"
19#include "llvm/ADT/StringExtras.h"
40 llvm_unreachable(
"Unhandled category!");
44 static const llvm::fltSemantics *
const order[] = {
45 &APFloat::IEEEsingle(), &APFloat::IEEEdouble(),
46 &APFloat::x87DoubleExtended()};
47 for (
const auto &entry : llvm::enumerate(order)) {
48 if (entry.value() == &sem)
51 llvm_unreachable(
"Unsupported semantics!");
58 switch (b.GetType()) {
72 if (lhs_key > rhs_key)
74 else if (rhs_key > lhs_key)
91 auto buffer_up = std::make_unique<DataBufferHeap>(byte_size, 0);
95 if (limit_byte_size < byte_size) {
99 byte_size = limit_byte_size;
104 offset = byte_size - limit_byte_size;
105 byte_size = limit_byte_size;
109 data.
SetData(std::move(buffer_up), offset, byte_size);
117 const auto &store = [&](
const llvm::APInt &val) {
118 StoreIntToMemory(val, storage.data(), (val.getBitWidth() + 7) / 8);
127 store(
m_float.bitcastToAPInt());
137 return (
m_integer.getBitWidth() + 7) / 8;
139 return (
m_float.bitcastToAPInt().getBitWidth() + 7) / 8;
167 llvm::SmallString<24> string;
195 bool success =
false;
200 m_float = llvm::APFloat(semantics);
202 llvm::APFloat::rmNearestTiesToEven);
210 m_float.convert(semantics, llvm::APFloat::rmNearestTiesToEven, &ignore);
239 llvm_unreachable(
"Unrecognized type!");
243 bool success =
false;
261 bool success =
false;
280 llvm::APSInt result(
bits, is_unsigned);
282 f.convertToInteger(result, llvm::APFloat::rmTowardZero, &isExact);
283 return std::move(result);
291 APSInt ext =
m_integer.extOrTrunc(
sizeof(T) * 8);
293 return ext.getSExtValue();
294 return ext.getZExtValue();
297 return ToAPInt(
m_float,
sizeof(T) * 8, std::is_unsigned<T>::value)
304 return GetAs<signed char>(fail_value);
308 return GetAs<unsigned char>(fail_value);
312 return GetAs<short>(fail_value);
316 return GetAs<unsigned short>(fail_value);
319int Scalar::SInt(
int fail_value)
const {
return GetAs<int>(fail_value); }
322 return GetAs<unsigned int>(fail_value);
325long Scalar::SLong(
long fail_value)
const {
return GetAs<long>(fail_value); }
328 return GetAs<unsigned long>(fail_value);
332 return GetAs<long long>(fail_value);
336 return GetAs<unsigned long long>(fail_value);
369 return llvm::APIntOps::RoundSignedAPIntToFloat(
m_integer);
370 return llvm::APIntOps::RoundAPIntToFloat(
m_integer);
375 result.convert(APFloat::IEEEsingle(), APFloat::rmNearestTiesToEven,
377 return result.convertToFloat();
389 return llvm::APIntOps::RoundSignedAPIntToDouble(
m_integer);
390 return llvm::APIntOps::RoundAPIntToDouble(
m_integer);
395 result.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven,
397 return result.convertToDouble();
405 return static_cast<long double>(
Double(fail_value));
634 if (value_str ==
nullptr || value_str[0] ==
'\0') {
635 error.SetErrorString(
"Invalid c-string value string.");
640 error.SetErrorString(
"Invalid encoding.");
645 llvm::StringRef str = value_str;
647 bool is_negative = is_signed && str.consume_front(
"-");
649 if (str.getAsInteger(0,
integer)) {
650 error.SetErrorStringWithFormatv(
651 "'{0}' is not a valid integer string value", value_str);
659 fits =
integer.isSignedIntN(byte_size * 8);
661 fits =
integer.isIntN(byte_size * 8);
663 error.SetErrorStringWithFormatv(
664 "value {0} is too large to fit in a {1} byte integer value",
665 value_str, byte_size);
670 APSInt(std::move(
integer), !is_signed).extOrTrunc(8 * byte_size);
678 const llvm::fltSemantics &sem =
679 byte_size <= 4 ? APFloat::IEEEsingle()
680 : byte_size <= 8 ? APFloat::IEEEdouble()
681 : APFloat::x87DoubleExtended();
683 if (llvm::Expected<APFloat::opStatus> op =
684 f.convertFromString(value_str, APFloat::rmNearestTiesToEven)) {
688 error = op.takeError();
693 error.SetErrorString(
"vector encoding unsupported.");
707 error.SetErrorString(
"invalid encoding");
710 error.SetErrorString(
"vector encoding unsupported");
715 return Status(
"insufficient data");
718 APSInt(APInt::getZero(8 * byte_size), encoding ==
eEncodingUint);
722 std::vector<uint8_t> buffer(byte_size);
723 std::copy_n(data.
GetDataStart(), byte_size, buffer.rbegin());
724 llvm::LoadIntFromMemory(
m_integer, buffer.data(), byte_size);
731 if (byte_size ==
sizeof(
float))
733 else if (byte_size ==
sizeof(
double))
735 else if (byte_size ==
sizeof(
long double))
738 error.SetErrorStringWithFormat(
"unsupported float byte size: %" PRIu64
"",
739 static_cast<uint64_t
>(byte_size));
749 if (sign_bit_pos < max_bit_pos) {
756 if (sign_bit_pos < (max_bit_pos - 1)) {
757 llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
758 llvm::APInt bitwize_and =
m_integer & sign_bit;
759 if (bitwize_and.getBoolValue()) {
761 ~(sign_bit) + llvm::APInt(
m_integer.getBitWidth(), 1);
778 error.SetErrorString(
"invalid scalar value");
785 const size_t bytes_copied =
791 if (bytes_copied == 0)
792 error.SetErrorString(
"failed to copy data");
815 switch (basic_type) {
817 return llvm::APFloat(
819 ? llvm::APIntOps::RoundSignedAPIntToFloat(
m_integer)
820 : llvm::APIntOps::RoundAPIntToFloat(
m_integer));
824 return llvm::APFloat(
826 ? llvm::APIntOps::RoundSignedAPIntToDouble(
m_integer)
827 : llvm::APIntOps::RoundAPIntToDouble(
m_integer));
829 const llvm::fltSemantics &sem = APFloat::IEEEsingle();
830 return llvm::APFloat::getNaN(sem);
835 switch (basic_type) {
838 m_float.convert(llvm::APFloat::IEEEsingle(),
839 llvm::APFloat::rmNearestTiesToEven, &loses_info);
846 m_float.convert(llvm::APFloat::IEEEdouble(),
847 llvm::APFloat::rmNearestTiesToEven, &loses_info);
851 const llvm::fltSemantics &sem = APFloat::IEEEsingle();
852 return llvm::APFloat::getNaN(sem);
861 llvm::APFloat::cmpResult result;
869 if (result == llvm::APFloat::cmpEqual)
876 return !(lhs == rhs);
883 llvm::APFloat::cmpResult result;
891 if (result == llvm::APFloat::cmpLessThan)
static llvm::raw_ostream & error(Stream &strm)
static llvm::APInt ToAPInt(const llvm::APFloat &f, unsigned bits, bool is_unsigned)
unsigned int UInt(unsigned int fail_value=0) const
llvm::APFloat CreateAPFloatFromAPFloat(lldb::BasicType basic_type)
void GetValue(Stream &s, bool show_type) const
llvm::APFloat CreateAPFloatFromAPSInt(lldb::BasicType basic_type)
const char * GetTypeAsCString() const
bool IntegralPromote(uint16_t bits, bool sign)
bool SetBit(uint32_t bit)
int SInt(int fail_value=0) const
long SLong(long fail_value=0) const
size_t GetByteSize() const
unsigned char UChar(unsigned char fail_value=0) const
Status SetValueFromData(const DataExtractor &data, lldb::Encoding encoding, size_t byte_size)
bool SignExtend(uint32_t bit_pos)
short SShort(short fail_value=0) const
T GetAs(T fail_value) const
void TruncOrExtendTo(uint16_t bits, bool sign)
Convert to an integer with bits and the given signedness.
unsigned long long ULongLong(unsigned long long fail_value=0) const
Scalar::Type GetType() const
unsigned long ULong(unsigned long fail_value=0) const
size_t GetAsMemoryData(void *dst, size_t dst_len, lldb::ByteOrder dst_byte_order, Status &error) const
void GetBytes(llvm::MutableArrayRef< uint8_t > storage) const
Store the binary representation of this value into the given storage.
bool GetData(DataExtractor &data, size_t limit_byte_size=UINT32_MAX) const
signed char SChar(signed char fail_value=0) const
bool FloatPromote(const llvm::fltSemantics &semantics)
bool ClearBit(uint32_t bit)
static PromotionKey GetFloatPromoKey(const llvm::fltSemantics &semantics)
float Float(float fail_value=0.0f) const
Scalar & operator&=(const Scalar &rhs)
long long SLongLong(long long fail_value=0) const
static const char * GetValueTypeAsCString(Scalar::Type value_type)
bool ExtractBitfield(uint32_t bit_size, uint32_t bit_offset)
std::tuple< Type, unsigned, bool > PromotionKey
double Double(double fail_value=0.0) const
Scalar & operator<<=(const Scalar &rhs)
Status SetValueFromCString(const char *s, lldb::Encoding encoding, size_t byte_size)
static Type PromoteToMaxType(Scalar &lhs, Scalar &rhs)
llvm::APInt SInt128(const llvm::APInt &fail_value) const
unsigned short UShort(unsigned short fail_value=0) const
Scalar & operator+=(Scalar rhs)
bool ShiftRightLogical(const Scalar &rhs)
PromotionKey GetPromoKey() const
long double LongDouble(long double fail_value=0.0) const
Scalar & operator>>=(const Scalar &rhs)
llvm::APInt UInt128(const llvm::APInt &fail_value) const
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
lldb::ByteOrder InlHostByteOrder()
A class that represents a running process on the host machine.
const Scalar operator&(Scalar lhs, Scalar rhs)
const Scalar operator*(Scalar lhs, Scalar rhs)
bool operator<=(const Scalar &lhs, const Scalar &rhs)
const Scalar operator/(Scalar lhs, Scalar rhs)
bool operator!=(const Address &lhs, const Address &rhs)
bool operator>(const Address &lhs, const Address &rhs)
const Scalar operator>>(const Scalar &lhs, const Scalar &rhs)
const Scalar operator%(Scalar lhs, Scalar rhs)
Stream & operator<<(Stream &s, const Mangled &obj)
AdaptedConstIterator< C, E, A > operator+(typename AdaptedConstIterator< C, E, A >::BackingIterator::difference_type offset, AdaptedConstIterator< C, E, A > &rhs)
const Scalar operator^(Scalar lhs, Scalar rhs)
bool operator==(const Address &lhs, const Address &rhs)
const Scalar operator|(Scalar lhs, Scalar rhs)
bool operator<(const Address &lhs, const Address &rhs)
static uint32_t bits(const uint32_t val, const uint32_t msbit, const uint32_t lsbit)
bool operator>=(const Scalar &lhs, const Scalar &rhs)
AdaptedConstIterator< C, E, A >::BackingIterator::difference_type operator-(AdaptedConstIterator< C, E, A > &lhs, AdaptedConstIterator< C, E, A > &rhs)
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
Encoding
Register encoding definitions.
@ eEncodingVector
vector registers
@ eEncodingUint
unsigned integer
@ eEncodingSint
signed integer
ByteOrder
Byte ordering definitions.