blob: cf3c11a9fdefca7c2a4167a6eaf45773698bc641 [file] [log] [blame]
John Brawnc4ed6002018-07-03 10:10:29 +00001#include "Target.h"
2
3#include <cassert>
4#include <memory>
5
6#include "MCTargetDesc/AArch64MCTargetDesc.h"
John Brawnb371ccc2018-07-03 10:52:20 +00007#include "llvm/Support/TargetRegistry.h"
8#include "llvm/Support/TargetSelect.h"
John Brawnc4ed6002018-07-03 10:10:29 +00009#include "gmock/gmock.h"
10#include "gtest/gtest.h"
11
12namespace exegesis {
13
14void InitializeAArch64ExegesisTarget();
15
16namespace {
17
18using testing::Gt;
19using testing::NotNull;
20using testing::SizeIs;
21
John Brawnb371ccc2018-07-03 10:52:20 +000022constexpr const char kTriple[] = "aarch64-unknown-linux";
23
John Brawnc4ed6002018-07-03 10:10:29 +000024class AArch64TargetTest : public ::testing::Test {
25protected:
26 AArch64TargetTest()
John Brawnb371ccc2018-07-03 10:52:20 +000027 : ExegesisTarget_(ExegesisTarget::lookup(llvm::Triple(kTriple))) {
28 EXPECT_THAT(ExegesisTarget_, NotNull());
29 std::string error;
30 Target_ = llvm::TargetRegistry::lookupTarget(kTriple, error);
John Brawnc4ed6002018-07-03 10:10:29 +000031 EXPECT_THAT(Target_, NotNull());
32 }
John Brawnb371ccc2018-07-03 10:52:20 +000033 static void SetUpTestCase() {
34 LLVMInitializeAArch64TargetInfo();
35 LLVMInitializeAArch64Target();
36 LLVMInitializeAArch64TargetMC();
37 InitializeAArch64ExegesisTarget();
38 }
John Brawnc4ed6002018-07-03 10:10:29 +000039
John Brawnb371ccc2018-07-03 10:52:20 +000040 const llvm::Target *Target_;
41 const ExegesisTarget *const ExegesisTarget_;
John Brawnc4ed6002018-07-03 10:10:29 +000042};
43
44TEST_F(AArch64TargetTest, SetRegToConstant) {
John Brawnb371ccc2018-07-03 10:52:20 +000045 const std::unique_ptr<llvm::MCSubtargetInfo> STI(
46 Target_->createMCSubtargetInfo(kTriple, "generic", ""));
John Brawnc4ed6002018-07-03 10:10:29 +000047 // The AArch64 target currently doesn't know how to set register values
John Brawnb371ccc2018-07-03 10:52:20 +000048 const auto Insts = ExegesisTarget_->setRegToConstant(*STI, llvm::AArch64::X0);
John Brawnc4ed6002018-07-03 10:10:29 +000049 EXPECT_THAT(Insts, SizeIs(0));
50}
51
52} // namespace
53} // namespace exegesis