pub struct InstructionBuilder {
pub opcode: OpCode,
pub cdcode: CondCode,
pub update: bool,
pub args: Vec<Argument>,
}
Expand description
A builder pattern for Instructions that ensures they are always valid when instantiated.
Fields§
§opcode: OpCode
A code representing the instruction executed on the processor.
cdcode: CondCode
A code which specifies under which conditions to execute.
update: bool
Whether the status register should be updated.
args: Vec<Argument>
Arguments provided to the instruction, interpreted as specified in OpCode
Implementations§
Source§impl InstructionBuilder
impl InstructionBuilder
Sourcepub fn condition(self, cond: CondCode) -> Self
pub fn condition(self, cond: CondCode) -> Self
Sets the condition of an existing instruction to the chosen condition code. Can be chained with other methods.
Sourcepub fn argument(self, arg: Argument) -> Self
pub fn argument(self, arg: Argument) -> Self
Appends an argument to an existing instruction. Can be chained with other methods operating on InstructionBuilder.
Sourcepub fn update(self) -> Self
pub fn update(self) -> Self
Sets the s-bit of an existing instruction. Can be chained with other methods.
Sourcepub fn replace(&mut self, label: &str, value: Argument)
pub fn replace(&mut self, label: &str, value: Argument)
Replaces any labels with the same name as the value provided with a copy of the argument provided.
Sourcepub fn build(self) -> Result<Instruction, InstructionError>
pub fn build(self) -> Result<Instruction, InstructionError>
Attempts to build a valid, encodable instruction from the arguments in the InstructionBuilder. Will return an InstructionError on invalid instructions.
use cfd16_lib::prelude::*;
let wrong = InstructionBuilder::new(OpCode::Ret)
.argument(Argument::Reg(Register::B))
.build();
assert!(wrong.is_err());
Trait Implementations§
Source§impl Clone for InstructionBuilder
impl Clone for InstructionBuilder
Source§fn clone(&self) -> InstructionBuilder
fn clone(&self) -> InstructionBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more