Struct evmil::bytecode::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

Mechanism for constructing a bytecode Assembly by allowing instructions to be patched before the final assembly is built. For example, consider the problem of constructing an assembly from this assembly language:

   push lab
   jump
   stop
lab:
   jumpdest

The challenge is that, when constructing the push lab instruction, we don’t yet know the instruction offset of lab. A Builder allows one to register a label and create an instance of PUSH which is later patched to ensure it has the correct instruction offset.

Implementations§

source§

impl Builder

source

pub fn new() -> Self

source

pub fn len(&self) -> usize

Determine the number of instructions currently pushed into this builder.

source

pub fn is_empty(&self) -> bool

Returns true if no instructions have yet been pushed into this builder.

source

pub fn get_label(&mut self, label: &str) -> usize

Get the label index associated with a particular label. If such an index does not already exist, then a new label is registered.

source

pub fn set_label(&mut self, label: &str, offset: usize) -> Result<(), ()>

Set the instruction offset associated with a given label. If the label does not yet exist (i.e. as not yet been assigned an index), then it will be.

source

pub fn mark_label(&mut self, label: &str) -> Result<(), ()>

Mark a label at the current instruction offset. If the label does not yet exist (i.e. as not yet been assigned an index), then it will be.

source

pub fn push_labeled(&mut self, insn: Instruction)

Push a new instruction onto the builder.

source

pub fn push(&mut self, insn: Instruction)

Push a new instruction onto the builder.

source

pub fn to_insns(self) -> Vec<Instruction>

Construct the final assembly by patching all labels used within instructions.

Auto Trait Implementations§

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.