pub struct Assembler { /* private fields */ }
Expand description

Miden Assembler which can be used to convert Miden assembly source code into program MAST.

The assembler can be instantiated in several ways using a “builder” pattern. Specifically:

  • If with_kernel() or with_kernel_module() methods are not used, the assembler will be instantiated with a default empty kernel. Programs compiled using such assembler cannot make calls to kernel procedures via syscall instruction.

Implementations§

source§

impl Assembler

source

pub fn with_debug_mode(self, in_debug_mode: bool) -> Assembler

Puts the assembler into the debug mode.

source

pub fn with_library<L>(self, library: &L) -> Result<Assembler, AssemblyError>
where L: Library,

Adds the library to provide modules for the compilation.

source

pub fn with_libraries<I, L>( self, libraries: I ) -> Result<Assembler, AssemblyError>
where L: Library, I: Iterator<Item = L>,

Adds a library bundle to provide modules for the compilation.

source

pub fn with_kernel( self, kernel_source: &str ) -> Result<Assembler, AssemblyError>

Sets the kernel for the assembler to the kernel defined by the provided source.

§Errors

Returns an error if compiling kernel source results in an error.

§Panics

Panics if the assembler has already been used to compile programs.

source

pub fn with_kernel_module( self, module: ModuleAst ) -> Result<Assembler, AssemblyError>

Sets the kernel for the assembler to the kernel defined by the provided module.

§Errors

Returns an error if compiling kernel source results in an error.

source

pub fn in_debug_mode(&self) -> bool

Returns true if this assembler was instantiated in debug mode.

source

pub fn kernel(&self) -> &Kernel

Returns a reference to the kernel for this assembler.

If the assembler was instantiated without a kernel, the internal kernel will be empty.

source

pub fn compile<S>(&self, source: S) -> Result<Program, AssemblyError>
where S: AsRef<str>,

Compiles the provided source code into a Program. The resulting program can be executed on Miden VM.

§Errors

Returns an error if parsing or compilation of the specified program fails.

source

pub fn compile_ast( &self, program: &ProgramAst ) -> Result<Program, AssemblyError>

Compiles the provided abstract syntax tree into a Program. The resulting program can be executed on Miden VM.

§Errors

Returns an error if the compilation of the specified program fails.

source

pub fn compile_in_context( &self, program: &ProgramAst, context: &mut AssemblyContext ) -> Result<CodeBlock, AssemblyError>

Compiles the provided ProgramAst into a program and returns the program root (CodeBlock). Mutates the provided context by adding all of the call targets of the program to the [CallSet].

§Errors
  • If the provided context is not appropriate for compiling a program.
  • If any of the local procedures defined in the program are exported.
  • If compilation of any of the local procedures fails.
  • if compilation of the program body fails.
source

pub fn compile_module( &self, module: &ModuleAst, path: Option<&LibraryPath>, context: &mut AssemblyContext ) -> Result<Vec<RpoDigest>, AssemblyError>

Compiles all procedures in the specified module and adds them to the procedure cache. Returns a vector of procedure digests for all exported procedures in the module.

§Errors
  • If a module with the same path already exists in the module stack of the AssemblyContext.
  • If a lock to the [ProcedureCache] can not be attained.
source

pub fn build_cb_table( &self, context: AssemblyContext ) -> Result<CodeBlockTable, AssemblyError>

Returns the CodeBlockTable associated with the AssemblyContext.

§Errors

Returns an error if a required procedure is not found in the Assembler procedure cache.

Trait Implementations§

source§

impl Default for Assembler

source§

fn default() -> Assembler

Returns the “default value” for a type. Read more

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

§

type Output = T

Should always be Self
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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more