summaryrefslogtreecommitdiff
path: root/include/lldb/Utility/Scalar.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/lldb/Utility/Scalar.h')
-rw-r--r--include/lldb/Utility/Scalar.h113
1 files changed, 46 insertions, 67 deletions
diff --git a/include/lldb/Utility/Scalar.h b/include/lldb/Utility/Scalar.h
index c23b2f8be25e..62ee9f666e89 100644
--- a/include/lldb/Utility/Scalar.h
+++ b/include/lldb/Utility/Scalar.h
@@ -1,9 +1,8 @@
//===-- Scalar.h ------------------------------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -13,6 +12,7 @@
#include "lldb/Utility/Status.h"
#include "lldb/lldb-enumerations.h"
#include "lldb/lldb-private-types.h"
+#include "lldb/Utility/LLDBAssert.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include <cstddef>
@@ -27,15 +27,15 @@ class Stream;
#define BITWIDTH_INT128 128
#define NUM_OF_WORDS_INT256 4
#define BITWIDTH_INT256 256
+#define NUM_OF_WORDS_INT512 8
+#define BITWIDTH_INT512 512
namespace lldb_private {
-//----------------------------------------------------------------------
// A class designed to hold onto values and their corresponding types.
// Operators are defined and Scalar objects will correctly promote their types
// and values before performing these operations. Type promotion currently
// follows the ANSI C type promotion rules.
-//----------------------------------------------------------------------
class Scalar {
public:
enum Type {
@@ -50,31 +50,32 @@ public:
e_uint128,
e_sint256,
e_uint256,
+ e_sint512,
+ e_uint512,
e_float,
e_double,
e_long_double
};
- //------------------------------------------------------------------
// Constructors and Destructors
- //------------------------------------------------------------------
Scalar();
- Scalar(int v) : m_type(e_sint), m_float((float)0) {
+ Scalar(int v) : m_type(e_sint), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(int) * 8, v, true);
}
- Scalar(unsigned int v) : m_type(e_uint), m_float((float)0) {
+ Scalar(unsigned int v) : m_type(e_uint), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(int) * 8, v);
}
- Scalar(long v) : m_type(e_slong), m_float((float)0) {
+ Scalar(long v) : m_type(e_slong), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(long) * 8, v, true);
}
- Scalar(unsigned long v) : m_type(e_ulong), m_float((float)0) {
+ Scalar(unsigned long v) : m_type(e_ulong), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(long) * 8, v);
}
- Scalar(long long v) : m_type(e_slonglong), m_float((float)0) {
+ Scalar(long long v) : m_type(e_slonglong), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(long long) * 8, v, true);
}
- Scalar(unsigned long long v) : m_type(e_ulonglong), m_float((float)0) {
+ Scalar(unsigned long long v)
+ : m_type(e_ulonglong), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(sizeof(long long) * 8, v);
}
Scalar(float v) : m_type(e_float), m_float(v) { m_float = llvm::APFloat(v); }
@@ -82,48 +83,42 @@ public:
m_float = llvm::APFloat(v);
}
Scalar(long double v, bool ieee_quad)
- : m_type(e_long_double), m_float((float)0), m_ieee_quad(ieee_quad) {
+ : m_type(e_long_double), m_float(static_cast<float>(0)),
+ m_ieee_quad(ieee_quad) {
if (ieee_quad)
- m_float = llvm::APFloat(llvm::APFloat::IEEEquad(),
- llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
- ((type128 *)&v)->x));
+ m_float =
+ llvm::APFloat(llvm::APFloat::IEEEquad(),
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ (reinterpret_cast<type128 *>(&v))->x));
else
- m_float = llvm::APFloat(llvm::APFloat::x87DoubleExtended(),
- llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
- ((type128 *)&v)->x));
+ m_float =
+ llvm::APFloat(llvm::APFloat::x87DoubleExtended(),
+ llvm::APInt(BITWIDTH_INT128, NUM_OF_WORDS_INT128,
+ (reinterpret_cast<type128 *>(&v))->x));
}
- Scalar(llvm::APInt v) : m_type(), m_float((float)0) {
+ Scalar(llvm::APInt v) : m_type(), m_float(static_cast<float>(0)) {
m_integer = llvm::APInt(v);
switch (m_integer.getBitWidth()) {
case 8:
case 16:
case 32:
- if (m_integer.isSignedIntN(sizeof(sint_t) * 8))
- m_type = e_sint;
- else
- m_type = e_uint;
- break;
+ m_type = e_sint;
+ return;
case 64:
- if (m_integer.isSignedIntN(sizeof(slonglong_t) * 8))
- m_type = e_slonglong;
- else
- m_type = e_ulonglong;
- break;
+ m_type = e_slonglong;
+ return;
case 128:
- if (m_integer.isSignedIntN(BITWIDTH_INT128))
- m_type = e_sint128;
- else
- m_type = e_uint128;
- break;
+ m_type = e_sint128;
+ return;
case 256:
- if (m_integer.isSignedIntN(BITWIDTH_INT256))
- m_type = e_sint256;
- else
- m_type = e_uint256;
- break;
+ m_type = e_sint256;
+ return;
+ case 512:
+ m_type = e_sint512;
+ return;
}
+ lldbassert(false && "unsupported bitwidth");
}
- Scalar(const Scalar &rhs);
// Scalar(const RegisterValue& reg_value);
virtual ~Scalar();
@@ -175,12 +170,10 @@ public:
static Scalar::Type GetValueTypeForFloatWithByteSize(size_t byte_size);
- //----------------------------------------------------------------------
// All operators can benefits from the implicit conversions that will happen
// automagically by the compiler, so no temporary objects will need to be
// created. As a result, we currently don't need a variety of overloaded set
// value accessors.
- //----------------------------------------------------------------------
Scalar &operator=(const int i);
Scalar &operator=(unsigned int v);
Scalar &operator=(long v);
@@ -197,41 +190,29 @@ public:
Scalar &operator>>=(const Scalar &rhs); // Shift right (arithmetic)
Scalar &operator&=(const Scalar &rhs);
- //----------------------------------------------------------------------
// Shifts the current value to the right without maintaining the current sign
// of the value (if it is signed).
- //----------------------------------------------------------------------
bool ShiftRightLogical(const Scalar &rhs); // Returns true on success
- //----------------------------------------------------------------------
// Takes the absolute value of the current value if it is signed, else the
// value remains unchanged. Returns false if the contained value has a void
// type.
- //----------------------------------------------------------------------
bool AbsoluteValue(); // Returns true on success
- //----------------------------------------------------------------------
// Negates the current value (even for unsigned values). Returns false if the
// contained value has a void type.
- //----------------------------------------------------------------------
bool UnaryNegate(); // Returns true on success
- //----------------------------------------------------------------------
// Inverts all bits in the current value as long as it isn't void or a
// float/double/long double type. Returns false if the contained value has a
// void/float/double/long double type, else the value is inverted and true is
// returned.
- //----------------------------------------------------------------------
bool OnesComplement(); // Returns true on success
- //----------------------------------------------------------------------
// Access the type of the current value.
- //----------------------------------------------------------------------
Scalar::Type GetType() const { return m_type; }
- //----------------------------------------------------------------------
// Returns a casted value of the current contained data without modifying the
// current value. FAIL_VALUE will be returned if the type of the value is
// void or invalid.
- //----------------------------------------------------------------------
int SInt(int fail_value = 0) const;
unsigned char UChar(unsigned char fail_value = 0) const;
@@ -256,10 +237,6 @@ public:
llvm::APInt UInt128(const llvm::APInt &fail_value) const;
- llvm::APInt SInt256(llvm::APInt &fail_value) const;
-
- llvm::APInt UInt256(const llvm::APInt &fail_value) const;
-
float Float(float fail_value = 0.0f) const;
double Double(double fail_value = 0.0) const;
@@ -279,7 +256,9 @@ public:
if (total_byte_size == 8)
return true;
- const uint64_t max = ((uint64_t)1 << (uint64_t)(total_byte_size * 8)) - 1;
+ const uint64_t max = (static_cast<uint64_t>(1)
+ << static_cast<uint64_t>(total_byte_size * 8)) -
+ 1;
return uval64 <= max;
}
@@ -290,7 +269,9 @@ public:
if (total_byte_size == 8)
return true;
- const int64_t max = ((int64_t)1 << (uint64_t)(total_byte_size * 8 - 1)) - 1;
+ const int64_t max = (static_cast<int64_t>(1)
+ << static_cast<uint64_t>(total_byte_size * 8 - 1)) -
+ 1;
const int64_t min = ~(max);
return min <= sval64 && sval64 <= max;
}
@@ -310,9 +291,7 @@ protected:
typedef double double_t;
typedef long double long_double_t;
- //------------------------------------------------------------------
// Classes that inherit from Scalar can see and modify these
- //------------------------------------------------------------------
Scalar::Type m_type;
llvm::APInt m_integer;
llvm::APFloat m_float;
@@ -337,7 +316,6 @@ private:
friend bool operator>=(const Scalar &lhs, const Scalar &rhs);
};
-//----------------------------------------------------------------------
// Split out the operators into a format where the compiler will be able to
// implicitly convert numbers into Scalar objects.
//
@@ -351,7 +329,6 @@ private:
// Item 19 of "Effective C++ Second Edition" by Scott Meyers
// Differentiate among members functions, non-member functions, and
// friend functions
-//----------------------------------------------------------------------
const Scalar operator+(const Scalar &lhs, const Scalar &rhs);
const Scalar operator-(const Scalar &lhs, const Scalar &rhs);
const Scalar operator/(const Scalar &lhs, const Scalar &rhs);
@@ -369,6 +346,8 @@ bool operator<=(const Scalar &lhs, const Scalar &rhs);
bool operator>(const Scalar &lhs, const Scalar &rhs);
bool operator>=(const Scalar &lhs, const Scalar &rhs);
+llvm::raw_ostream &operator<<(llvm::raw_ostream &os, const Scalar &scalar);
+
} // namespace lldb_private
#endif // LLDB_UTILITY_SCALAR_H