59 lines · cpp
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-exception6//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 22using namespace llvm;23 24class AArch64InstPrinterTest : public AArch64InstPrinter {25public: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 35static std::string AArch64InstPrinterTestPrintAlignedLabel(uint64_t value) {36 MCAsmInfo MAI;37 MCInstrInfo MII;38 MCRegisterInfo MRI;39 MCSubtargetInfo STI(Triple(""), "", "", "", {}, {}, {}, nullptr, nullptr,40 nullptr, nullptr, nullptr, nullptr);41 MCContext Ctx(Triple(""), &MAI, &MRI, &STI);42 MCInst MI;43 44 MI.addOperand(MCOperand::createExpr(MCConstantExpr::create(value, Ctx)));45 46 std::string str;47 raw_string_ostream O(str);48 AArch64InstPrinterTest(MAI, MII, MRI).printAlignedLabel(&MI, 0, 0, STI, O);49 return str;50}51 52TEST(AArch64InstPrinterTest, PrintAlignedLabel) {53 EXPECT_EQ(AArch64InstPrinterTestPrintAlignedLabel(0x0), "0x0");54 EXPECT_EQ(AArch64InstPrinterTestPrintAlignedLabel(0xffffffff001200eb),55 "0xffffffff001200eb");56 EXPECT_EQ(AArch64InstPrinterTestPrintAlignedLabel(0x7c01445bcc10f),57 "0x7c01445bcc10f");58}59