1 //===-- RegisterValueTest.cpp ---------------------------------------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Utility/RegisterValue.h" 10 #include "gtest/gtest.h" 11 12 using namespace lldb_private; 13 using llvm::APInt; 14 15 TEST(RegisterValueTest, GetSet8) { 16 RegisterValue R8(uint8_t(47)); 17 EXPECT_EQ(47u, R8.GetAsUInt8()); 18 R8 = uint8_t(42); 19 EXPECT_EQ(42u, R8.GetAsUInt8()); 20 EXPECT_EQ(42u, R8.GetAsUInt16()); 21 EXPECT_EQ(42u, R8.GetAsUInt32()); 22 EXPECT_EQ(42u, R8.GetAsUInt64()); 23 } 24 25 TEST(RegisterValueTest, GetScalarValue) { 26 using RV = RegisterValue; 27 const auto &Get = [](const RV &V) -> llvm::Optional<Scalar> { 28 Scalar S; 29 if (V.GetScalarValue(S)) 30 return S; 31 return llvm::None; 32 }; 33 EXPECT_EQ(Get(RV(uint8_t(47))), Scalar(47)); 34 EXPECT_EQ(Get(RV(uint16_t(4747))), Scalar(4747)); 35 EXPECT_EQ(Get(RV(uint32_t(47474242))), Scalar(47474242)); 36 EXPECT_EQ(Get(RV(uint64_t(4747424247474242))), Scalar(4747424247474242)); 37 EXPECT_EQ(Get(RV(APInt::getMaxValue(128))), Scalar(APInt::getMaxValue(128))); 38 EXPECT_EQ(Get(RV(47.5f)), Scalar(47.5f)); 39 EXPECT_EQ(Get(RV(47.5)), Scalar(47.5)); 40 EXPECT_EQ(Get(RV(47.5L)), Scalar(47.5L)); 41 EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc}, lldb::eByteOrderLittle)), 42 Scalar(0xccddeeff)); 43 EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc}, lldb::eByteOrderBig)), 44 Scalar(0xffeeddcc)); 45 EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 46 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}, 47 lldb::eByteOrderLittle)), 48 Scalar((APInt(128, 0x0011223344556677ull) << 64) | 49 APInt(128, 0x8899aabbccddeeff))); 50 EXPECT_EQ(Get(RV({0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x77, 0x66, 51 0x55, 0x44, 0x33, 0x22, 0x11, 0x00}, 52 lldb::eByteOrderBig)), 53 Scalar((APInt(128, 0xffeeddccbbaa9988ull) << 64) | 54 APInt(128, 0x7766554433221100))); 55 } 56