1 //===-- RegisterValueTest.cpp ---------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/RegisterValue.h"
10 #include "gtest/gtest.h"
13 using namespace lldb_private
;
16 TEST(RegisterValueTest
, GetSet8
) {
17 RegisterValue
R8(uint8_t(47));
18 EXPECT_EQ(47u, R8
.GetAsUInt8());
20 EXPECT_EQ(42u, R8
.GetAsUInt8());
21 EXPECT_EQ(42u, R8
.GetAsUInt16());
22 EXPECT_EQ(42u, R8
.GetAsUInt32());
23 EXPECT_EQ(42u, R8
.GetAsUInt64());
26 TEST(RegisterValueTest
, GetScalarValue
) {
27 using RV
= RegisterValue
;
28 const auto &Get
= [](const RV
&V
) -> std::optional
<Scalar
> {
30 if (V
.GetScalarValue(S
))
34 EXPECT_EQ(Get(RV(uint8_t(47))), Scalar(47));
35 EXPECT_EQ(Get(RV(uint16_t(4747))), Scalar(4747));
36 EXPECT_EQ(Get(RV(uint32_t(47474242))), Scalar(47474242));
37 EXPECT_EQ(Get(RV(uint64_t(4747424247474242))), Scalar(4747424247474242));
38 EXPECT_EQ(Get(RV(APInt::getMaxValue(128))), Scalar(APInt::getMaxValue(128)));
39 EXPECT_EQ(Get(RV(47.5f
)), Scalar(47.5f
));
40 EXPECT_EQ(Get(RV(47.5)), Scalar(47.5));
41 EXPECT_EQ(Get(RV(47.5L)), Scalar(47.5L));
42 EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc}, lldb::eByteOrderLittle
)),
44 EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc}, lldb::eByteOrderBig
)),
46 EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66,
47 0x55, 0x44, 0x33, 0x22, 0x11, 0x00},
48 lldb::eByteOrderLittle
)),
49 Scalar((APInt(128, 0x0011223344556677ull
) << 64) |
50 APInt(128, 0x8899aabbccddeeff)));
51 EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66,
52 0x55, 0x44, 0x33, 0x22, 0x11, 0x00},
53 lldb::eByteOrderBig
)),
54 Scalar((APInt(128, 0xffeeddccbbaa9988ull
) << 64) |
55 APInt(128, 0x7766554433221100)));