Skip to content

Commit 49a8a56

Browse files
author
Bar Soloveychik
committed
added helper function
1 parent 93e01de commit 49a8a56

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lldb/source/Plugins/Instruction/RISCV/EmulateInstructionRISCV.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ static uint32_t FPREncodingToLLDB(uint32_t reg_encode) {
112112
return LLDB_INVALID_REGNUM;
113113
}
114114

115+
// Helper function to get register info from GPR encoding
116+
static std::optional<RegisterInfo>
117+
GPREncodingToRegisterInfo(EmulateInstructionRISCV &emulator,
118+
uint32_t reg_encode) {
119+
uint32_t lldb_reg = GPREncodingToLLDB(reg_encode);
120+
return emulator.GetRegisterInfo(eRegisterKindLLDB, lldb_reg);
121+
}
122+
115123
bool Rd::Write(EmulateInstructionRISCV &emulator, uint64_t value) {
116124
uint32_t lldb_reg = GPREncodingToLLDB(rd);
117125
EmulateInstruction::Context ctx;
@@ -239,9 +247,8 @@ Load(EmulateInstructionRISCV &emulator, I inst, uint64_t (*extend)(E)) {
239247
EmulateInstructionRISCV::Context context;
240248

241249
// Get register info for base register
242-
uint32_t rs1_lldb = GPREncodingToLLDB(inst.rs1.rs);
243250
std::optional<RegisterInfo> reg_info_rs1 =
244-
emulator.GetRegisterInfo(eRegisterKindLLDB, rs1_lldb);
251+
GPREncodingToRegisterInfo(emulator, inst.rs1.rs);
245252

246253
if (!reg_info_rs1)
247254
return false;
@@ -276,12 +283,10 @@ Store(EmulateInstructionRISCV &emulator, I inst) {
276283
EmulateInstructionRISCV::Context context;
277284

278285
// Get register info for source and base registers
279-
uint32_t rs1_lldb = GPREncodingToLLDB(inst.rs1.rs);
280-
uint32_t rs2_lldb = GPREncodingToLLDB(inst.rs2.rs);
281286
std::optional<RegisterInfo> reg_info_rs1 =
282-
emulator.GetRegisterInfo(eRegisterKindLLDB, rs1_lldb);
287+
GPREncodingToRegisterInfo(emulator, inst.rs1.rs);
283288
std::optional<RegisterInfo> reg_info_rs2 =
284-
emulator.GetRegisterInfo(eRegisterKindLLDB, rs2_lldb);
289+
GPREncodingToRegisterInfo(emulator, inst.rs2.rs);
285290

286291
if (!reg_info_rs1 || !reg_info_rs2)
287292
return false;

0 commit comments

Comments
 (0)