#include "lldb/Core/Address.h"
#include "lldb/Core/Disassembler.h"
#include "lldb/Core/PluginManager.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/RegisterValue.h"
#include "gtest/gtest.h"
#include "Plugins/Instruction/LoongArch/EmulateInstructionLoongArch.h"
#include "Plugins/Process/Utility/RegisterInfoPOSIX_loongarch64.h"
#include "Plugins/Process/Utility/lldb-loongarch-register-enums.h"
usingnamespacellvm;
usingnamespacelldb;
usingnamespacelldb_private;
#define GEN_BCOND_TEST(bit, name, rj_val, rd_val_branched, rd_val_continued) …
#define GEN_BZCOND_TEST(bit, name, rj_val_branched, rj_val_continued) …
#define GEN_BCZCOND_TEST(bit, name, cj_val_branched, cj_val_continued) …
struct LoongArch64EmulatorTester : public EmulateInstructionLoongArch,
testing::Test { … };
static uint32_t EncodeBcondType(uint32_t opcode, uint32_t rj, uint32_t rd,
uint32_t offs16) { … }
static uint32_t BEQ(uint32_t rj, uint32_t rd, int32_t offs16) { … }
static uint32_t BNE(uint32_t rj, uint32_t rd, int32_t offs16) { … }
static uint32_t BLT(uint32_t rj, uint32_t rd, int32_t offs16) { … }
static uint32_t BGE(uint32_t rj, uint32_t rd, int32_t offs16) { … }
static uint32_t BLTU(uint32_t rj, uint32_t rd, int32_t offs16) { … }
static uint32_t BGEU(uint32_t rj, uint32_t rd, int32_t offs16) { … }
static uint32_t EncodeBZcondType(uint32_t opcode, uint32_t rj,
uint32_t offs21) { … }
static uint32_t BEQZ(uint32_t rj, int32_t offs21) { … }
static uint32_t BNEZ(uint32_t rj, int32_t offs21) { … }
static uint32_t EncodeBCZcondType(uint32_t opcode, uint8_t cj,
uint32_t offs21) { … }
static uint32_t BCEQZ(uint8_t cj, int32_t offs21) { … }
static uint32_t BCNEZ(uint8_t cj, int32_t offs21) { … }
EncoderBcond;
EncoderBZcond;
EncoderBCZcond;
TEST_F(LoongArch64EmulatorTester, testJIRL) { … }
TEST_F(LoongArch64EmulatorTester, testB) { … }
TEST_F(LoongArch64EmulatorTester, testBL) { … }
static void testBcondBranch(LoongArch64EmulatorTester *tester,
EncoderBcond encoder, bool branched,
uint64_t rj_val, uint64_t rd_val) { … }
static void testBZcondBranch(LoongArch64EmulatorTester *tester,
EncoderBZcond encoder, bool branched,
uint64_t rj_val) { … }
static void testBCZcondBranch(LoongArch64EmulatorTester *tester,
EncoderBCZcond encoder, bool branched,
uint32_t cj_val) { … }
GEN_BCOND_TEST(64, BEQ, 1, 1, 0)
GEN_BCOND_TEST(64, BNE, 1, 0, 1)
GEN_BCOND_TEST(64, BLT, -2, 1, -3)
GEN_BCOND_TEST(64, BGE, -2, -3, 1)
GEN_BCOND_TEST(64, BLTU, -2, -1, 1)
GEN_BCOND_TEST(64, BGEU, -2, 1, -1)
GEN_BZCOND_TEST(64, BEQZ, 0, 1)
GEN_BZCOND_TEST(64, BNEZ, 1, 0)
GEN_BCZCOND_TEST(64, BCEQZ, 0, 1)
GEN_BCZCOND_TEST(64, BCNEZ, 1, 0)