Skip to content

Commit b1693fd

Browse files
committed
More rust cleanup
- Allow calling conventions to be registered for multiple architectures - Swapped a unreachable statement to an unimplemented statement
1 parent 31ea072 commit b1693fd

File tree

3 files changed

+142
-102
lines changed

3 files changed

+142
-102
lines changed

arch/riscv/src/lib.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,70 +2671,68 @@ impl<D: 'static + RiscVDisassembler + Send + Sync> RiscVCC<D> {
26712671
}
26722672

26732673
impl<D: 'static + RiscVDisassembler + Send + Sync> CallingConvention for RiscVCC<D> {
2674-
type Arch = RiscVArch<D>;
2675-
2676-
fn caller_saved_registers(&self) -> Vec<Register<D>> {
2674+
fn caller_saved_registers(&self) -> Vec<RegisterId> {
26772675
let mut regs = Vec::with_capacity(36);
26782676
let int_reg_count = <D::RegFile as RegFile>::int_reg_count();
26792677

26802678
for i in &[
26812679
1u32, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 28, 29, 30, 31,
26822680
] {
26832681
if i < &int_reg_count {
2684-
regs.push(Register::new(RegisterId(*i)));
2682+
regs.push(RegisterId(*i));
26852683
}
26862684
}
26872685

26882686
if <D::RegFile as RegFile>::Float::present() {
26892687
for i in &[
26902688
0u32, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 28, 29, 30, 31,
26912689
] {
2692-
regs.push(Register::new(RegisterId(*i + int_reg_count)));
2690+
regs.push(RegisterId(*i + int_reg_count));
26932691
}
26942692
}
26952693

26962694
regs
26972695
}
26982696

2699-
fn callee_saved_registers(&self) -> Vec<Register<D>> {
2697+
fn callee_saved_registers(&self) -> Vec<RegisterId> {
27002698
let mut regs = Vec::with_capacity(24);
27012699
let int_reg_count = <D::RegFile as RegFile>::int_reg_count();
27022700

27032701
for i in &[8u32, 9, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27] {
27042702
if i < &int_reg_count {
2705-
regs.push(Register::new(RegisterId(*i)));
2703+
regs.push(RegisterId(*i));
27062704
}
27072705
}
27082706

27092707
if <D::RegFile as RegFile>::Float::present() {
27102708
for i in &[8u32, 9, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27] {
2711-
regs.push(Register::new(RegisterId(*i + int_reg_count)));
2709+
regs.push(RegisterId(*i + int_reg_count));
27122710
}
27132711
}
27142712

27152713
regs
27162714
}
27172715

2718-
fn int_arg_registers(&self) -> Vec<Register<D>> {
2716+
fn int_arg_registers(&self) -> Vec<RegisterId> {
27192717
let mut regs = Vec::with_capacity(8);
27202718
let int_reg_count = <D::RegFile as RegFile>::int_reg_count();
27212719

27222720
for i in &[10, 11, 12, 13, 14, 15, 16, 17] {
27232721
if i < &int_reg_count {
2724-
regs.push(Register::new(RegisterId(*i)));
2722+
regs.push(RegisterId(*i));
27252723
}
27262724
}
27272725

27282726
regs
27292727
}
27302728

2731-
fn float_arg_registers(&self) -> Vec<Register<D>> {
2729+
fn float_arg_registers(&self) -> Vec<RegisterId> {
27322730
let mut regs = Vec::with_capacity(8);
27332731

27342732
if <D::RegFile as RegFile>::Float::present() {
27352733
let int_reg_count = <D::RegFile as RegFile>::int_reg_count();
27362734
for i in &[10, 11, 12, 13, 14, 15, 16, 17] {
2737-
regs.push(Register::new(RegisterId(*i + int_reg_count)));
2735+
regs.push(RegisterId(*i + int_reg_count));
27382736
}
27392737
}
27402738

@@ -2757,29 +2755,29 @@ impl<D: 'static + RiscVDisassembler + Send + Sync> CallingConvention for RiscVCC
27572755
}
27582756

27592757
// a0 == x10
2760-
fn return_int_reg(&self) -> Option<Register<D>> {
2761-
Some(Register::new(RegisterId(10)))
2758+
fn return_int_reg(&self) -> Option<RegisterId> {
2759+
Some(RegisterId(10))
27622760
}
27632761
// a1 == x11
2764-
fn return_hi_int_reg(&self) -> Option<Register<D>> {
2765-
Some(Register::new(RegisterId(11)))
2762+
fn return_hi_int_reg(&self) -> Option<RegisterId> {
2763+
Some(RegisterId(11))
27662764
}
27672765

2768-
fn return_float_reg(&self) -> Option<Register<D>> {
2766+
fn return_float_reg(&self) -> Option<RegisterId> {
27692767
if <D::RegFile as RegFile>::Float::present() {
27702768
let int_reg_count = <D::RegFile as RegFile>::int_reg_count();
2771-
Some(Register::new(RegisterId(10 + int_reg_count)))
2769+
Some(RegisterId(10 + int_reg_count))
27722770
} else {
27732771
None
27742772
}
27752773
}
27762774

27772775
// gp == x3
2778-
fn global_pointer_reg(&self) -> Option<Register<D>> {
2779-
Some(Register::new(RegisterId(3)))
2776+
fn global_pointer_reg(&self) -> Option<RegisterId> {
2777+
Some(RegisterId(3))
27802778
}
27812779

2782-
fn implicitly_defined_registers(&self) -> Vec<Register<D>> {
2780+
fn implicitly_defined_registers(&self) -> Vec<RegisterId> {
27832781
Vec::new()
27842782
}
27852783
fn are_argument_registers_used_for_var_args(&self) -> bool {
@@ -2995,9 +2993,17 @@ pub extern "C" fn CorePluginInit() -> bool {
29952993
arch32.register_function_recognizer(RiscVELFPLTRecognizer);
29962994
arch64.register_function_recognizer(RiscVELFPLTRecognizer);
29972995

2998-
let cc32 = register_calling_convention(arch32, "default", RiscVCC::new());
2996+
let cc32 = register_calling_convention(
2997+
arch32,
2998+
"default",
2999+
RiscVCC::<RiscVIMACDisassembler<Rv32GRegs>>::new(),
3000+
);
29993001
arch32.set_default_calling_convention(&cc32);
3000-
let cc64 = register_calling_convention(arch64, "default", RiscVCC::new());
3002+
let cc64 = register_calling_convention(
3003+
arch64,
3004+
"default",
3005+
RiscVCC::<RiscVIMACDisassembler<Rv64GRegs>>::new(),
3006+
);
30013007
arch64.set_default_calling_convention(&cc64);
30023008

30033009
if let Ok(bvt) = BinaryViewType::by_name("ELF") {

0 commit comments

Comments
 (0)