// © 2023 John Breaux //! Builder API for [`EncodingParser`] use super::*; #[derive(Debug, Default)] pub struct SingleBuilder { width: Option, dst: Option, } 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, } 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, src: Option, dst: Option, } 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, reg: Option, } 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 } } }