• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "Target.h"
2 
3 #include <cassert>
4 #include <memory>
5 
6 #include "MCTargetDesc/AArch64MCTargetDesc.h"
7 #include "llvm/Support/TargetRegistry.h"
8 #include "llvm/Support/TargetSelect.h"
9 #include "gmock/gmock.h"
10 #include "gtest/gtest.h"
11 
12 namespace exegesis {
13 
14 void InitializeAArch64ExegesisTarget();
15 
16 namespace {
17 
18 using testing::Gt;
19 using testing::NotNull;
20 using testing::SizeIs;
21 
22 constexpr const char kTriple[] = "aarch64-unknown-linux";
23 
24 class AArch64TargetTest : public ::testing::Test {
25 protected:
AArch64TargetTest()26   AArch64TargetTest()
27       : ExegesisTarget_(ExegesisTarget::lookup(llvm::Triple(kTriple))) {
28     EXPECT_THAT(ExegesisTarget_, NotNull());
29     std::string error;
30     Target_ = llvm::TargetRegistry::lookupTarget(kTriple, error);
31     EXPECT_THAT(Target_, NotNull());
32   }
SetUpTestCase()33   static void SetUpTestCase() {
34     LLVMInitializeAArch64TargetInfo();
35     LLVMInitializeAArch64Target();
36     LLVMInitializeAArch64TargetMC();
37     InitializeAArch64ExegesisTarget();
38   }
39 
40   const llvm::Target *Target_;
41   const ExegesisTarget *const ExegesisTarget_;
42 };
43 
TEST_F(AArch64TargetTest,SetRegToConstant)44 TEST_F(AArch64TargetTest, SetRegToConstant) {
45   const std::unique_ptr<llvm::MCSubtargetInfo> STI(
46       Target_->createMCSubtargetInfo(kTriple, "generic", ""));
47   // The AArch64 target currently doesn't know how to set register values
48   const auto Insts = ExegesisTarget_->setRegToConstant(*STI, llvm::AArch64::X0);
49   EXPECT_THAT(Insts, SizeIs(0));
50 }
51 
52 } // namespace
53 } // namespace exegesis
54