Struct macro_asm_builder::Assembler
source · pub struct Assembler<'a> {
pub align_pattern: Vec<u8>,
pub start_address: usize,
pub implementation_macro: &'a dyn Fn(&Vec<String>) -> Result<Option<String>, String>,
pub micro_assembly: &'a dyn Fn(&Vec<String>) -> Result<Vec<u8>, String>,
/* private fields */
}
Expand description
The collection of the assembly code tree and all the mutable context needed to process it
Fields§
§align_pattern: Vec<u8>
The pattern that will be put as padding to replace @align
directives
start_address: usize
Address of the first instruction of first data in the resulting binary
implementation_macro: &'a dyn Fn(&Vec<String>) -> Result<Option<String>, String>
A function that expand implementation-specifics macros. Takes a vector
of tokens from a line of code and return Ok
micro_assembly: &'a dyn Fn(&Vec<String>) -> Result<Vec<u8>, String>
A function used to compile assembly source code into machine code. It
is implementation-specific. It takes a vector if tokens from a line of
code and return Ok
Implementations§
source§impl Assembler<'_>
impl Assembler<'_>
sourcepub fn from_text(text: &str) -> Self
pub fn from_text(text: &str) -> Self
Takes some assembly code as input and set up the assembler state with it
sourcepub fn from_file(path: &str) -> Self
pub fn from_file(path: &str) -> Self
Initialize the assembler state to be ready to read the input file
sourcepub fn set_word_size(&mut self, wordsize: usize) -> Option<&str>
pub fn set_word_size(&mut self, wordsize: usize) -> Option<&str>
Set the wordsize of the assembler given it in bits. Return None if the value is valid and an error message otherwise.
sourcepub fn add_text_before(&mut self, txt: &str, name: &str)
pub fn add_text_before(&mut self, txt: &str, name: &str)
Add some text at the beginning of the tree.
sourcepub fn add_text_after(&mut self, txt: &str, name: &str)
pub fn add_text_after(&mut self, txt: &str, name: &str)
Add some text at the end of the tree.
sourcepub fn assemble(&mut self) -> Result<Vec<u8>, String>
pub fn assemble(&mut self) -> Result<Vec<u8>, String>
Perform a complete assembly process. Return a vector of bytes of the resulting binary in case of success and an error message in case of error.
sourcepub fn label_dump(&mut self) -> String
pub fn label_dump(&mut self) -> String
Return a label dump of the tree