1+ // ===- bolt/unittest/Target/PowerPC/PPCMCPlusBuilderTest.cpp
2+ // -------------------------------===//
3+ //
4+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+ // See https://llvm.org/LICENSE.txt for license information.
6+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+ //
8+ // ===----------------------------------------------------------------------===//
9+
10+ #include " bolt/Target/PowerPC/PPCMCPlusBuilder.h"
11+ #include " bolt/Core/MCPlusBuilder.h"
12+ #include " llvm/MC/MCInst.h"
13+ #include " gtest/gtest.h"
14+ #define GET_INSTRINFO_ENUM
15+ #include " llvm/Target/PowerPC/PPCGenInstrInfo.inc"
16+ #define GET_REGINFO_ENUM
17+ #include " llvm/Target/PowerPC/PPCGenRegisterInfo.inc"
18+
19+ using namespace llvm ;
20+ using namespace bolt ;
21+
22+ namespace {
23+
24+ TEST (PPCMCPlusBuilderTest, CreatePushRegisters) {
25+ // Set up dummy input registers
26+ MCInst Inst1, Inst2;
27+ MCPhysReg Reg1 = PPC::R3; // Arbitary register
28+
29+ // Call the method under test
30+ PPCMCPlusBuilder::createPushRegisters (Inst1, Inst2, Reg1, /* Reg2=*/ PPC::R4);
31+
32+ // Check Inst1 is STDU R1, R1, -16
33+ EXPECT_EQ (Inst1.getOpcode (), PPC::STDU);
34+ ASSERT_EQ (Inst1.getNumOperands (), 3u );
35+ EXPECT_TRUE (Inst1.getOperand (0 ).isReg ());
36+ EXPECT_EQ (Inst1.getOperand (0 ).getReg (), PPC::R1);
37+ EXPECT_TRUE (Inst1.getOperand (1 ).isReg ());
38+ EXPECT_EQ (Inst1.getOperand (1 ).getReg (), PPC::R1);
39+ EXPECT_TRUE (Inst1.getOperand (2 ).isImm ());
40+ EXPECT_EQ (Inst1.getOperand (2 ).getImm (), -16 );
41+
42+ // Check Inst2 is STD Reg1, R1, 0
43+ EXPECT_EQ (Inst2.getOpcode (), PPC::STD);
44+ ASSERT_EQ (Inst2.getNumOperands (), 3u );
45+ EXPECT_TRUE (Inst2.getOperand (0 ).isReg ());
46+ EXPECT_EQ (Inst2.getOperand (0 ).getReg (), Reg1);
47+ EXPECT_TRUE (Inst2.getOperand (1 ).isReg ());
48+ EXPECT_EQ (Inst2.getOperand (1 ).getReg (), PPC::R1);
49+ EXPECT_TRUE (Inst2.getOperand (2 ).isImm ());
50+ EXPECT_EQ (Inst2.getOperand (2 ).getImm (), 0 );
51+ }
52+
53+ } // end anonymous namespace
0 commit comments