14
14
#include " lldb/lldb-enumerations.h"
15
15
#include " lldb/lldb-private-types.h"
16
16
#include " llvm/ADT/APFloat.h"
17
- #include " llvm/ADT/APInt .h"
17
+ #include " llvm/ADT/APSInt .h"
18
18
#include < cstddef>
19
19
#include < cstdint>
20
20
#include < utility>
@@ -38,35 +38,35 @@ namespace lldb_private {
38
38
// and values before performing these operations. Type promotion currently
39
39
// follows the ANSI C type promotion rules.
40
40
class Scalar {
41
+ template <typename T>
42
+ static llvm::APSInt MakeAPSInt (T v) {
43
+ static_assert (std::is_integral<T>::value, " " );
44
+ static_assert (sizeof (T) <= sizeof (uint64_t ), " Conversion loses precision!" );
45
+ return llvm::APSInt (
46
+ llvm::APInt (sizeof (T) * 8 , uint64_t (v), std::is_signed<T>::value),
47
+ std::is_unsigned<T>::value);
48
+ }
49
+
41
50
public:
42
51
// FIXME: These are host types which seems to be an odd choice.
43
52
enum Type {
44
53
e_void = 0 ,
45
- e_sint,
46
- e_uint,
54
+ e_int,
47
55
e_float,
48
56
};
49
57
50
58
// Constructors and Destructors
51
59
Scalar () : m_type(e_void), m_float(0 .0f ) {}
52
- Scalar (int v)
53
- : m_type(e_sint), m_integer(sizeof (v) * 8 , uint64_t (v), true ),
54
- m_float (0 .0f ) {}
60
+ Scalar (int v) : m_type(e_int), m_integer(MakeAPSInt(v)), m_float(0 .0f ) {}
55
61
Scalar (unsigned int v)
56
- : m_type(e_uint), m_integer(sizeof (v) * 8, uint64_t(v), false),
57
- m_float(0 .0f ) {}
58
- Scalar (long v)
59
- : m_type(e_sint), m_integer(sizeof (v) * 8, uint64_t(v), true),
60
- m_float(0 .0f ) {}
62
+ : m_type(e_int), m_integer(MakeAPSInt(v)), m_float(0 .0f ) {}
63
+ Scalar (long v) : m_type(e_int), m_integer(MakeAPSInt(v)), m_float(0 .0f ) {}
61
64
Scalar (unsigned long v)
62
- : m_type(e_uint), m_integer(sizeof (v) * 8, uint64_t(v), false),
63
- m_float(0 .0f ) {}
65
+ : m_type(e_int), m_integer(MakeAPSInt(v)), m_float(0 .0f ) {}
64
66
Scalar (long long v)
65
- : m_type(e_sint), m_integer(sizeof (v) * 8, uint64_t(v), true),
66
- m_float(0 .0f ) {}
67
+ : m_type(e_int), m_integer(MakeAPSInt(v)), m_float(0 .0f ) {}
67
68
Scalar (unsigned long long v)
68
- : m_type(e_uint), m_integer(sizeof (v) * 8, uint64_t(v), false),
69
- m_float(0 .0f ) {}
69
+ : m_type(e_int), m_integer(MakeAPSInt(v)), m_float(0 .0f ) {}
70
70
Scalar (float v) : m_type(e_float), m_float(v) {}
71
71
Scalar (double v) : m_type(e_float), m_float(v) {}
72
72
Scalar (long double v) : m_type(e_float), m_float(double (v)) {
@@ -75,7 +75,7 @@ class Scalar {
75
75
llvm::APFloat::rmNearestTiesToEven, &ignore);
76
76
}
77
77
Scalar (llvm::APInt v)
78
- : m_type(e_sint ), m_integer(std::move(v)), m_float(0 .0f ) {}
78
+ : m_type(e_int ), m_integer(std::move(v), false ), m_float(0 .0f ) {}
79
79
80
80
bool SignExtend (uint32_t bit_pos);
81
81
@@ -108,14 +108,15 @@ class Scalar {
108
108
109
109
void GetValue (Stream *s, bool show_type) const ;
110
110
111
- bool IsValid () const { return (m_type >= e_sint ) && (m_type <= e_float); }
111
+ bool IsValid () const { return (m_type >= e_int ) && (m_type <= e_float); }
112
112
113
113
// / Convert to an integer with \p bits and the given signedness.
114
114
void TruncOrExtendTo (uint16_t bits, bool sign);
115
115
116
116
bool IntegralPromote (uint16_t bits, bool sign);
117
117
bool FloatPromote (const llvm::fltSemantics &semantics);
118
118
119
+ bool IsSigned () const ;
119
120
bool MakeSigned ();
120
121
121
122
bool MakeUnsigned ();
@@ -234,7 +235,7 @@ class Scalar {
234
235
235
236
// Classes that inherit from Scalar can see and modify these
236
237
Scalar::Type m_type;
237
- llvm::APInt m_integer;
238
+ llvm::APSInt m_integer;
238
239
llvm::APFloat m_float;
239
240
240
241
template <typename T> T GetAs (T fail_value) const ;
0 commit comments