Skip to content

Commit

Permalink
feat(x86): Add GPR
Browse files Browse the repository at this point in the history
  • Loading branch information
chorman0773 committed Jun 2, 2024
1 parent b3bd523 commit 3d34de4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions arch-ops/src/x86.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
use target_tuples::Target;

#[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)]
pub enum X86Gpr {
Ax,
Cx,
Dx,
Bx,
Sp,
Bp,
Si,
Di,
}

#[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)]
#[non_exhaustive]
pub enum X86RegisterClass {
Expand Down Expand Up @@ -57,6 +70,19 @@ impl X86RegisterClass {
_ => None,
}
}

pub fn as_gpr(self, gpr_no: X86Gpr) -> X86Register {
let regno = gpr_no as u8;
match self {
Self::Byte if regno < 4 => {
X86Register::from_class(self, regno).expect("We have a valid GPR Number")
}
Self::ByteRex | Self::Word | Self::Double | Self::Quad => {
X86Register::from_class(self, regno).expect("We have a valid GPR Number")
}
cl => panic!("Cannot produce a GPR for {:?}", cl),
}
}
}

#[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)]
Expand Down

0 comments on commit 3d34de4

Please sign in to comment.