77 lines
2.1 KiB
Rust
77 lines
2.1 KiB
Rust
// © 2023 John Breaux
|
|
//! Builder API for [`EncodingParser`]
|
|
use super::*;
|
|
#[derive(Debug, Default)]
|
|
pub struct SingleBuilder {
|
|
width: Option<Width>,
|
|
dst: Option<PrimaryOperand>,
|
|
}
|
|
impl SingleBuilder {
|
|
pub fn width(mut self, width: bool) -> Self {
|
|
self.width = Some(width.into());
|
|
self
|
|
}
|
|
/// Sets the [PrimaryOperand] field
|
|
pub fn operand(mut self, dst: PrimaryOperand) -> Self {
|
|
self.dst = Some(dst);
|
|
self
|
|
}
|
|
/// Build
|
|
pub fn end(&self) -> EncodingParser { EncodingParser::Single { width: self.width, dst: self.dst } }
|
|
}
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct JumpBuilder {
|
|
target: Option<JumpTarget>,
|
|
}
|
|
impl JumpBuilder {
|
|
pub fn target(mut self, target: JumpTarget) -> Self {
|
|
self.target = Some(target);
|
|
self
|
|
}
|
|
pub fn end(&self) -> EncodingParser { EncodingParser::Jump { target: self.target } }
|
|
}
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct DoubleBuilder {
|
|
width: Option<Width>,
|
|
src: Option<PrimaryOperand>,
|
|
dst: Option<SecondaryOperand>,
|
|
}
|
|
impl DoubleBuilder {
|
|
/// Sets the [Width] field
|
|
pub fn width(mut self, width: bool) -> Self {
|
|
self.width = Some(width.into());
|
|
self
|
|
}
|
|
/// Sets the [PrimaryOperand] field
|
|
pub fn src(mut self, src: PrimaryOperand) -> Self {
|
|
self.src = Some(src);
|
|
self
|
|
}
|
|
/// Sets the [PrimaryOperand] field
|
|
pub fn dst(mut self, dst: SecondaryOperand) -> Self {
|
|
self.dst = Some(dst);
|
|
self
|
|
}
|
|
pub fn end(&self) -> EncodingParser { EncodingParser::Double { width: self.width, src: self.src, dst: self.dst } }
|
|
}
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct ReflexiveBuilder {
|
|
width: Option<Width>,
|
|
reg: Option<SecondaryOperand>,
|
|
}
|
|
impl ReflexiveBuilder {
|
|
/// Sets the [Width] field
|
|
pub fn width(mut self, width: bool) -> Self {
|
|
self.width = Some(width.into());
|
|
self
|
|
}
|
|
pub fn reg(mut self, reg: SecondaryOperand) -> Self {
|
|
self.reg = Some(reg);
|
|
self
|
|
}
|
|
pub fn end(&self) -> EncodingParser { EncodingParser::Reflexive { width: self.width, reg: self.reg } }
|
|
}
|