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 | |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame^] | 18 | using llvm::APInt; |
| 19 | using llvm::MCInst; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 20 | using testing::Gt; |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame^] | 21 | using testing::IsEmpty; |
| 22 | using testing::Not; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 23 | using testing::NotNull; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 24 | |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame^] | 25 | static const char kTriple[] = "aarch64-unknown-linux"; |
| 26 | static const char kGenericCpu[] = "generic"; |
| 27 | static const char kNoFeatures[] = ""; |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 28 | |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 29 | class AArch64TargetTest : public ::testing::Test { |
| 30 | protected: |
| 31 | AArch64TargetTest() |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 32 | : ExegesisTarget_(ExegesisTarget::lookup(llvm::Triple(kTriple))) { |
| 33 | EXPECT_THAT(ExegesisTarget_, NotNull()); |
| 34 | std::string error; |
| 35 | Target_ = llvm::TargetRegistry::lookupTarget(kTriple, error); |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 36 | EXPECT_THAT(Target_, NotNull()); |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame^] | 37 | STI_.reset( |
| 38 | Target_->createMCSubtargetInfo(kTriple, kGenericCpu, kNoFeatures)); |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 39 | } |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame^] | 40 | |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 41 | static void SetUpTestCase() { |
| 42 | LLVMInitializeAArch64TargetInfo(); |
| 43 | LLVMInitializeAArch64Target(); |
| 44 | LLVMInitializeAArch64TargetMC(); |
| 45 | InitializeAArch64ExegesisTarget(); |
| 46 | } |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 47 | |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame^] | 48 | std::vector<MCInst> setRegTo(unsigned Reg, const APInt &Value) { |
| 49 | return ExegesisTarget_->setRegTo(*STI_, Reg, Value); |
| 50 | } |
| 51 | |
John Brawn | b371ccc | 2018-07-03 10:52:20 +0000 | [diff] [blame] | 52 | const llvm::Target *Target_; |
| 53 | const ExegesisTarget *const ExegesisTarget_; |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame^] | 54 | std::unique_ptr<llvm::MCSubtargetInfo> STI_; |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
Guillaume Chatelet | c96a97b | 2018-09-20 12:22:18 +0000 | [diff] [blame^] | 57 | TEST_F(AArch64TargetTest, SetRegToConstant) { |
| 58 | // The AArch64 target currently doesn't know how to set register values. |
| 59 | const auto Insts = setRegTo(llvm::AArch64::X0, llvm::APInt()); |
| 60 | EXPECT_THAT(Insts, Not(IsEmpty())); |
| 61 | } |
| 62 | |
John Brawn | c4ed600 | 2018-07-03 10:10:29 +0000 | [diff] [blame] | 63 | } // namespace |
| 64 | } // namespace exegesis |