pub struct Assembler<'a, R, W>{
pub symbol_table: HashMap<String, u16>,
pub instructions: Vec<Instruction>,
/* private fields */
}Expand description
Struct to represent the Assembler’s internal logic.
Contains the file references, symbol table, and other necessary state.
Can be constructed using the build function.
Fields§
§symbol_table: HashMap<String, u16>Symbol table to store the addresses of labels and variables.
The symbol table is populated during the build of the Assembler.
instructions: Vec<Instruction>Vector of Instruction(s) used to store the parsed instructions from the source file.
The vector is populated on build and can be used in tandem with the symbol table for custom implementations.
Implementations§
Source§impl<'a, R, W> Assembler<'a, R, W>
impl<'a, R, W> Assembler<'a, R, W>
Sourcepub fn build(
in_file: &'a mut R,
out_file: &'a mut W,
symbol_file: Option<&'a mut W>,
) -> Result<Assembler<'a, R, W>, Box<dyn Error>>
pub fn build( in_file: &'a mut R, out_file: &'a mut W, symbol_file: Option<&'a mut W>, ) -> Result<Assembler<'a, R, W>, Box<dyn Error>>
Sourcepub fn advance_once(&mut self)
pub fn advance_once(&mut self)
Function to advance the assembler by one instruction, this encoded instruction is then immediately written to the output file.
Sourcepub fn advance_to_end(&mut self)
pub fn advance_to_end(&mut self)
Function to advance the assembler to the end of the file, encoding all instructions and writing them all at once to the output file.
Sourcepub fn get_next_encoded_instruction(&mut self) -> Option<String>
pub fn get_next_encoded_instruction(&mut self) -> Option<String>
Function to get the next encoded instruction from the assembler.
Used internally by the Assembler::advance_once and Assembler::advance_to_end functions.
But can also be used to get the encoded instructions as strings rather than being written to a file.
Returns None if there are no more instructions to encode.
Either use this function, or the Assembler::advance_once and Assembler::advance_to_end functions, mixing the two may result in unexpected behavior.