Struct miden_objects::assembly::Assembler
source · 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()orwith_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 viasyscallinstruction.
Implementations§
source§impl Assembler
impl Assembler
sourcepub fn with_debug_mode(self, in_debug_mode: bool) -> Assembler
pub fn with_debug_mode(self, in_debug_mode: bool) -> Assembler
Puts the assembler into the debug mode.
sourcepub fn with_library<L>(self, library: &L) -> Result<Assembler, AssemblyError>where
L: Library,
pub fn with_library<L>(self, library: &L) -> Result<Assembler, AssemblyError>where
L: Library,
Adds the library to provide modules for the compilation.
sourcepub fn with_libraries<I, L>(
self,
libraries: I
) -> Result<Assembler, AssemblyError>
pub fn with_libraries<I, L>( self, libraries: I ) -> Result<Assembler, AssemblyError>
Adds a library bundle to provide modules for the compilation.
sourcepub fn with_kernel(
self,
kernel_source: &str
) -> Result<Assembler, AssemblyError>
pub fn with_kernel( self, kernel_source: &str ) -> Result<Assembler, AssemblyError>
sourcepub fn with_kernel_module(
self,
module: ModuleAst
) -> Result<Assembler, AssemblyError>
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.
sourcepub fn in_debug_mode(&self) -> bool
pub fn in_debug_mode(&self) -> bool
Returns true if this assembler was instantiated in debug mode.
sourcepub fn kernel(&self) -> &Kernel
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.
sourcepub fn compile<S>(&self, source: S) -> Result<Program, AssemblyError>
pub fn compile<S>(&self, source: S) -> Result<Program, AssemblyError>
sourcepub fn compile_ast(
&self,
program: &ProgramAst
) -> Result<Program, AssemblyError>
pub fn compile_ast( &self, program: &ProgramAst ) -> Result<Program, AssemblyError>
sourcepub fn compile_in_context(
&self,
program: &ProgramAst,
context: &mut AssemblyContext
) -> Result<CodeBlock, AssemblyError>
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.
sourcepub fn compile_module(
&self,
module: &ModuleAst,
path: Option<&LibraryPath>,
context: &mut AssemblyContext
) -> Result<Vec<RpoDigest>, AssemblyError>
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.
sourcepub fn build_cb_table(
&self,
context: AssemblyContext
) -> Result<CodeBlockTable, AssemblyError>
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.