Skip to content

Commit

Permalink
regs: add convenience setter methods for a registers
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Oct 18, 2024
1 parent 677dfc4 commit 7658b9d
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/reg/core_regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,78 @@ impl CoreRegs {
/// Get value from `a128` register.
pub fn a128(&self, idx: impl Into<Reg32>) -> Option<u128> { self.a128[idx.into().to_usize()] }

Check warning on line 223 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L223

Added line #L223 was not covered by tests

/// Sets `a8` register to a given value. Returns previous register value.
pub fn set_a8(&mut self, idx: impl Into<Reg32>, val: u8) -> Option<u8> {
let idx = idx.into().to_usize();
let prev = self.a8[idx];
self.a8[idx] = Some(val);
prev
}

Check warning on line 231 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L226-L231

Added lines #L226 - L231 were not covered by tests
/// Sets `a16` register to a given value. Returns previous register value.
pub fn set_a16(&mut self, idx: impl Into<Reg32>, val: u16) -> Option<u16> {
let idx = idx.into().to_usize();
let prev = self.a16[idx];
self.a16[idx] = Some(val);
prev
}

Check warning on line 238 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L233-L238

Added lines #L233 - L238 were not covered by tests
/// Sets `a32` register to a given value. Returns previous register value.
pub fn set_a32(&mut self, idx: impl Into<Reg32>, val: u32) -> Option<u32> {
let idx = idx.into().to_usize();
let prev = self.a32[idx];
self.a32[idx] = Some(val);
prev
}

Check warning on line 245 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L240-L245

Added lines #L240 - L245 were not covered by tests
/// Sets `a64` register to a given value. Returns previous register value.
pub fn set_a64(&mut self, idx: impl Into<Reg32>, val: u64) -> Option<u64> {
let idx = idx.into().to_usize();
let prev = self.a64[idx];
self.a64[idx] = Some(val);
prev
}

Check warning on line 252 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L247-L252

Added lines #L247 - L252 were not covered by tests
/// Sets `a128` register to a given value. Returns previous register value.
pub fn set_a128(&mut self, idx: impl Into<Reg32>, val: u128) -> Option<u128> {
let idx = idx.into().to_usize();
let prev = self.a128[idx];
self.a128[idx] = Some(val);
prev
}

Check warning on line 259 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L254-L259

Added lines #L254 - L259 were not covered by tests

/// Clears `a8` register (sets its value to `None`). Returns previous register value.
pub fn clr_a8(&mut self, idx: impl Into<Reg32>) -> Option<u8> {
let idx = idx.into().to_usize();
let prev = self.a8[idx];
self.a8[idx] = None;
prev
}

Check warning on line 267 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L262-L267

Added lines #L262 - L267 were not covered by tests
/// Clears `a16` register (sets its value to `None`). Returns previous register value.
pub fn clr_a16(&mut self, idx: impl Into<Reg32>) -> Option<u16> {
let idx = idx.into().to_usize();
let prev = self.a16[idx];
self.a16[idx] = None;
prev
}

Check warning on line 274 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L269-L274

Added lines #L269 - L274 were not covered by tests
/// Clears `a32` register (sets its value to `None`). Returns previous register value.
pub fn clr_a32(&mut self, idx: impl Into<Reg32>) -> Option<u32> {
let idx = idx.into().to_usize();
let prev = self.a32[idx];
self.a32[idx] = None;
prev
}

Check warning on line 281 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L276-L281

Added lines #L276 - L281 were not covered by tests
/// Clears `a64` register (sets its value to `None`). Returns previous register value.
pub fn clr_a64(&mut self, idx: impl Into<Reg32>) -> Option<u64> {
let idx = idx.into().to_usize();
let prev = self.a64[idx];
self.a64[idx] = None;
prev
}

Check warning on line 288 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L283-L288

Added lines #L283 - L288 were not covered by tests
/// Clears `a128` register (sets its value to `None`). Returns previous register value.
pub fn clr_a128(&mut self, idx: impl Into<Reg32>) -> Option<u128> {
let idx = idx.into().to_usize();
let prev = self.a128[idx];
self.a128[idx] = None;
prev
}

Check warning on line 295 in src/reg/core_regs.rs

View check run for this annotation

Codecov / codecov/patch

src/reg/core_regs.rs#L290-L295

Added lines #L290 - L295 were not covered by tests

/// Extracts value for any type of registers
pub fn get(&self, reg: impl Into<Reg>) -> RegValue {
match reg.into() {
Expand Down

0 comments on commit 7658b9d

Please sign in to comment.