xref: /llvm-project/llvm/unittests/Target/AArch64/AArch64InstPrinterTest.cpp (revision b6c22a4e58f9dd38644368dd5d5de237703a360d)
1 //===- AArch64InstPrinterTest.cpp - AArch64InstPrinter unit tests----------===//
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 "llvm/MC/MCAsmInfo.h"
10 #include "llvm/MC/MCContext.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCInst.h"
13 #include "llvm/MC/MCInstrInfo.h"
14 #include "llvm/MC/MCRegisterInfo.h"
15 #include "llvm/MC/MCSubtargetInfo.h"
16 #include "llvm/Support/raw_ostream.h"
17 
18 #include "MCTargetDesc/AArch64InstPrinter.h"
19 
20 #include "gtest/gtest.h"
21 
22 using namespace llvm;
23 
24 class AArch64InstPrinterTest : public AArch64InstPrinter {
25 public:
26   AArch64InstPrinterTest(const MCAsmInfo &MAI, const MCInstrInfo &MII,
27                          const MCRegisterInfo &MRI)
28       : AArch64InstPrinter(MAI, MII, MRI) {}
29   void printAlignedLabel(const MCInst *MI, uint64_t Address, unsigned OpNum,
30                          const MCSubtargetInfo &STI, raw_ostream &O) {
31     AArch64InstPrinter::printAlignedLabel(MI, Address, OpNum, STI, O);
32   }
33 };
34 
35 static std::string AArch64InstPrinterTestPrintAlignedLabel(uint64_t value) {
36   MCAsmInfo MAI;
37   MCInstrInfo MII;
38   MCRegisterInfo MRI;
39   MCSubtargetInfo STI(Triple(""), "", "", "", {},
40                       ArrayRef((SubtargetFeatureKV *)NULL, (size_t)0),
41                       ArrayRef((SubtargetSubTypeKV *)NULL, (size_t)0), NULL,
42                       NULL, NULL, NULL, NULL, NULL);
43   MCContext Ctx(Triple(""), &MAI, &MRI, &STI);
44   MCInst MI;
45 
46   MI.addOperand(MCOperand::createExpr(MCConstantExpr::create(value, Ctx)));
47 
48   std::string str;
49   raw_string_ostream O(str);
50   AArch64InstPrinterTest(MAI, MII, MRI).printAlignedLabel(&MI, 0, 0, STI, O);
51   return str;
52 }
53 
54 TEST(AArch64InstPrinterTest, PrintAlignedLabel) {
55   EXPECT_EQ(AArch64InstPrinterTestPrintAlignedLabel(0x0), "0x0");
56   EXPECT_EQ(AArch64InstPrinterTestPrintAlignedLabel(0xffffffff001200eb),
57             "0xffffffff001200eb");
58   EXPECT_EQ(AArch64InstPrinterTestPrintAlignedLabel(0x7c01445bcc10f),
59             "0x7c01445bcc10f");
60 }
61