pub struct Assembler { /* private fields */ }
Expand description
The Assembler is the primary interface for compiling Miden Assembly to the Merkelized Abstract Syntax Tree (MAST).
§Usage
Depending on your needs, there are multiple ways of using the assembler, and whether or not you want to provide a custom kernel.
- If you have a single executable module you want to compile, just call Assembler::assemble_program.
- If you want to link your executable to a few other modules that implement supporting procedures, build the assembler with them first, using the various builder methods on Assembler, e.g. Assembler::with_module, Assembler::with_library, etc. Then, call Assembler::assemble_program to get your compiled program.
Implementations§
impl Assembler
Procedure Invocation
impl Assembler
Instruction Compilation
Source§impl Assembler
Constructors
impl Assembler
Constructors
Sourcepub fn new(source_manager: Arc<dyn SourceManager + Send + Sync>) -> Assembler
pub fn new(source_manager: Arc<dyn SourceManager + Send + Sync>) -> Assembler
Start building an Assembler
Sourcepub fn with_kernel(
source_manager: Arc<dyn SourceManager + Send + Sync>,
kernel_lib: KernelLibrary,
) -> Assembler
pub fn with_kernel( source_manager: Arc<dyn SourceManager + Send + Sync>, kernel_lib: KernelLibrary, ) -> Assembler
Start building an Assembler
with a kernel defined by the provided KernelLibrary.
Sourcepub fn with_warnings_as_errors(self, yes: bool) -> Assembler
pub fn with_warnings_as_errors(self, yes: bool) -> Assembler
Sets the default behavior of this assembler with regard to warning diagnostics.
When true, any warning diagnostics that are emitted will be promoted to errors.
Sourcepub fn with_debug_mode(self, yes: bool) -> Assembler
pub fn with_debug_mode(self, yes: bool) -> Assembler
Puts the assembler into the debug mode.
Sourcepub fn set_debug_mode(&mut self, yes: bool)
pub fn set_debug_mode(&mut self, yes: bool)
Sets the debug mode flag of the assembler
Sourcepub fn with_module(self, module: impl Compile) -> Result<Assembler, Report>
pub fn with_module(self, module: impl Compile) -> Result<Assembler, Report>
Adds module
to the module graph of the assembler.
The given module must be a library module, or an error will be returned.
Sourcepub fn with_module_and_options(
self,
module: impl Compile,
options: Options,
) -> Result<Assembler, Report>
pub fn with_module_and_options( self, module: impl Compile, options: Options, ) -> Result<Assembler, Report>
Adds module
to the module graph of the assembler with the given options.
The given module must be a library module, or an error will be returned.
Sourcepub fn add_module(
&mut self,
module: impl Compile,
) -> Result<ModuleIndex, Report>
pub fn add_module( &mut self, module: impl Compile, ) -> Result<ModuleIndex, Report>
Adds module
to the module graph of the assembler.
The given module must be a library module, or an error will be returned.
Sourcepub fn add_module_with_options(
&mut self,
module: impl Compile,
options: Options,
) -> Result<ModuleIndex, Report>
pub fn add_module_with_options( &mut self, module: impl Compile, options: Options, ) -> Result<ModuleIndex, Report>
Adds module
to the module graph of the assembler, using the provided options.
The given module must be a library or kernel module, or an error will be returned.
Sourcepub fn add_modules_with_options(
&mut self,
modules: impl IntoIterator<Item = impl Compile>,
options: Options,
) -> Result<Vec<ModuleIndex>, Report>
pub fn add_modules_with_options( &mut self, modules: impl IntoIterator<Item = impl Compile>, options: Options, ) -> Result<Vec<ModuleIndex>, Report>
Adds a set of modules to the module graph of the assembler, using the provided options.
The modules must all be library or kernel modules, or an error will be returned.
Sourcepub fn add_modules_from_dir(
&mut self,
namespace: LibraryNamespace,
dir: &Path,
) -> Result<(), Report>
pub fn add_modules_from_dir( &mut self, namespace: LibraryNamespace, dir: &Path, ) -> Result<(), Report>
Adds all modules (defined by “.masm” files) from the specified directory to the module of this assembler graph.
The modules will be added under the specified namespace, but otherwise preserving the
structure of the directory. Any module named mod.masm
will be added using parent
directory path For example, if namespace
= “ns”, modules from the ~/masm directory
will be added as follows:
- ~/masm/foo.masm -> “ns::foo”
- ~/masm/bar/mod.masm -> “ns::bar”
- ~/masm/bar/baz.masm -> “ns::bar::baz”
Sourcepub fn add_library(
&mut self,
library: impl AsRef<Library>,
) -> Result<(), Report>
pub fn add_library( &mut self, library: impl AsRef<Library>, ) -> Result<(), Report>
Adds the compiled library to provide modules for the compilation.
All calls to the library’s procedures will be compiled down to a
vm_core::mast::ExternalNode
(i.e. a reference to the procedure’s MAST root).
The library’s source code is expected to be loaded in the processor at execution time.
This means that when executing a program compiled against a library, the processor will not
be able to differentiate procedures with the same MAST root but different decorators.
Hence, it is not recommended to export two procedures that have the same MAST root (i.e. are identical except for their decorators). Note however that we don’t expect this scenario to be frequent in practice. For example, this could occur when APIs are being renamed and/or moved between modules, and for some deprecation period, the same is exported under both its old and new paths. Or possibly with common small functions that are implemented by the main program and one of its dependencies.
Sourcepub fn with_library(
self,
library: impl AsRef<Library>,
) -> Result<Assembler, Report>
pub fn with_library( self, library: impl AsRef<Library>, ) -> Result<Assembler, Report>
Adds the compiled library to provide modules for the compilation.
See Self::add_library
for more detailed information.
Sourcepub fn add_vendored_library(
&mut self,
library: impl AsRef<Library>,
) -> Result<(), Report>
pub fn add_vendored_library( &mut self, library: impl AsRef<Library>, ) -> Result<(), Report>
Adds a compiled library from which procedures will be vendored into the assembled code.
Vendoring in this context means that when a procedure from this library is invoked from the assembled code, the entire procedure MAST will be copied into the assembled code. Thus, when the resulting code is executed on the VM, the vendored library does not need to be provided to the VM to resolve external calls.
Source§impl Assembler
Public Accessors
impl Assembler
Public Accessors
Sourcepub fn warnings_as_errors(&self) -> bool
pub fn warnings_as_errors(&self) -> bool
Returns true if this assembler promotes warning diagnostics as errors by default.
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 source_manager(&self) -> Arc<dyn SourceManager + Send + Sync>
pub fn source_manager(&self) -> Arc<dyn SourceManager + Send + Sync>
Returns a link to the source manager used by this assembler.
Source§impl Assembler
Compilation/Assembly
impl Assembler
Compilation/Assembly
Sourcepub fn assemble_library(
self,
modules: impl IntoIterator<Item = impl Compile>,
) -> Result<Library, Report>
pub fn assemble_library( self, modules: impl IntoIterator<Item = impl Compile>, ) -> Result<Library, Report>
Sourcepub fn assemble_kernel(
self,
module: impl Compile,
) -> Result<KernelLibrary, Report>
pub fn assemble_kernel( self, module: impl Compile, ) -> Result<KernelLibrary, Report>
Assembles the provided module into a KernelLibrary intended to be used as a Kernel.
§Errors
Returns an error if parsing or compilation of the specified modules fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Assembler
impl !RefUnwindSafe for Assembler
impl !Send for Assembler
impl !Sync for Assembler
impl Unpin for Assembler
impl !UnwindSafe for Assembler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more