8
8
9
9
namespace zasm
10
10
{
11
- class Imm
11
+ class Imm
12
12
{
13
- union
14
- {
15
- std::int64_t s;
16
- std::uint64_t u;
17
- };
13
+ std::int64_t _value;
18
14
19
15
public:
20
16
constexpr Imm () noexcept
21
- : s {}
17
+ : _value {}
22
18
{
23
19
}
24
20
constexpr Imm (std::uint32_t imm) noexcept
25
- : u{ imm }
21
+ : _value{ static_cast <std:: int32_t >( imm) }
26
22
{
27
23
}
28
24
constexpr Imm (std::int32_t imm) noexcept
29
- : s { imm }
25
+ : _value { imm }
30
26
{
31
27
}
32
28
constexpr Imm (std::int64_t imm) noexcept
33
- : s { imm }
29
+ : _value { imm }
34
30
{
35
31
}
36
32
constexpr Imm (std::uint64_t imm) noexcept
37
- : u{ imm }
33
+ : _value{ static_cast <std:: int64_t >( imm) }
38
34
{
39
35
}
40
36
41
37
constexpr bool operator ==(const Imm& other) const noexcept
42
38
{
43
- return u == other.u ;
39
+ return _value == other._value ;
44
40
}
45
41
46
42
constexpr bool operator !=(const Imm& other) const noexcept
47
43
{
48
- return u != other.u ;
44
+ return _value != other._value ;
49
45
}
50
46
51
47
template <typename T> constexpr T value () const noexcept
52
48
{
53
- return static_cast <T>(s );
49
+ return static_cast <T>(_value );
54
50
}
55
51
56
52
template <typename T> Imm& setValue (const T val)
57
53
{
58
- s = static_cast <std::int64_t >(val);
54
+ _value = static_cast <std::int64_t >(val);
59
55
60
56
return *this ;
61
57
}
62
58
63
59
constexpr BitSize getBitSize () const noexcept
64
60
{
65
- if (math::abs (s ) > std::numeric_limits<std::uint32_t >::max ())
61
+ if (math::abs (_value ) > std::numeric_limits<std::uint32_t >::max ())
66
62
{
67
63
return BitSize::_64;
68
64
}
69
- if (math::abs (s ) > std::numeric_limits<std::uint16_t >::max ())
65
+ if (math::abs (_value ) > std::numeric_limits<std::uint16_t >::max ())
70
66
{
71
67
return BitSize::_32;
72
68
}
73
- if (math::abs (s ) > std::numeric_limits<std::uint8_t >::max ())
69
+ if (math::abs (_value ) > std::numeric_limits<std::uint8_t >::max ())
74
70
{
75
71
return BitSize::_16;
76
72
}
@@ -85,7 +81,7 @@ namespace zasm
85
81
86
82
namespace detail
87
83
{
88
- template <typename T> class ImmT final : public Imm
84
+ template <typename T> class ImmT final : public Imm
89
85
{
90
86
public:
91
87
template <typename T2>
0 commit comments