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 if no macro expansion is needed, Ok to replace the text with txt, or Err to return an error message destined to the user.

§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 to return the machine code or Err to return an error message destined to the user. When this function is run, all code left in the tree should be raw assembly and not macros or directive. Thus, there is no way this function can ignore code.

Implementations§

source§

impl Assembler<'_>

source

pub fn from_text(text: &str) -> Self

Takes some assembly code as input and set up the assembler state with it

source

pub fn from_file(path: &str) -> Self

Initialize the assembler state to be ready to read the input file

source

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.

source

pub fn add_text_before(&mut self, txt: &str, name: &str)

Add some text at the beginning of the tree.

source

pub fn add_text_after(&mut self, txt: &str, name: &str)

Add some text at the end of the tree.

source

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.

source

pub fn label_dump(&mut self) -> String

Return a label dump of the tree

Auto Trait Implementations§

§

impl<'a> Freeze for Assembler<'a>

§

impl<'a> !RefUnwindSafe for Assembler<'a>

§

impl<'a> !Send for Assembler<'a>

§

impl<'a> !Sync for Assembler<'a>

§

impl<'a> Unpin for Assembler<'a>

§

impl<'a> !UnwindSafe for Assembler<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.