John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 1 | #include "Target.h" |
| 2 | |
| 3 | #include <cassert> |
| 4 | #include <memory> |
| 5 | |
| 6 | #include "MCTargetDesc/AArch64MCTargetDesc.h" |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame^] | 7 | #include "llvm/Support/TargetRegistry.h" |
| 8 | #include "llvm/Support/TargetSelect.h" |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 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 | |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame^] | 22 | constexpr const char kTriple[] = "aarch64-unknown-linux"; |
| 23 | |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 24 | class AArch64TargetTest : public ::testing::Test { |
| 25 | protected: |
| 26 | AArch64TargetTest() |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame^] | 27 | : ExegesisTarget_(ExegesisTarget::lookup(llvm::Triple(kTriple))) { |
| 28 | EXPECT_THAT(ExegesisTarget_, NotNull()); |
| 29 | std::string error; |
| 30 | Target_ = llvm::TargetRegistry::lookupTarget(kTriple, error); |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 31 | EXPECT_THAT(Target_, NotNull()); |
| 32 | } |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame^] | 33 | static void SetUpTestCase() { |
| 34 | LLVMInitializeAArch64TargetInfo(); |
| 35 | LLVMInitializeAArch64Target(); |
| 36 | LLVMInitializeAArch64TargetMC(); |
| 37 | InitializeAArch64ExegesisTarget(); |
| 38 | } |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 39 | |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame^] | 40 | const llvm::Target *Target_; |
| 41 | const ExegesisTarget *const ExegesisTarget_; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | TEST_F(AArch64TargetTest, SetRegToConstant) { |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame^] | 45 | const std::unique_ptr<llvm::MCSubtargetInfo> STI( |
| 46 | Target_->createMCSubtargetInfo(kTriple, "generic", "")); |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 47 | // The AArch64 target currently doesn't know how to set register values |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame^] | 48 | const auto Insts = ExegesisTarget_->setRegToConstant(*STI, llvm::AArch64::X0); |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 49 | EXPECT_THAT(Insts, SizeIs(0)); |
| 50 | } |
| 51 | |
| 52 | } // namespace |
| 53 | } // namespace exegesis |