pub struct Assembler { /* private fields */ }Expand description
The Assembler produces a Merkelized Abstract Syntax Tree (MAST) from Miden Assembly sources,
as a Package artifact. In general, packages come in three primary varieties:
- A kernel library (i.e.
TargetType::Kernel) - A program (see
TargetType::Executable) - A library (all other target types)
Assembled artifacts can additionally reference or include code from previously assembled libraries.
§Usage
Depending on your needs, there are multiple ways of using the assembler, starting with the type of artifact you want to produce:
- If you wish to produce an executable program, you will call
Self::assemble_programwith the source module which contains the program entrypoint. - If you wish to produce a library for use in other executables, you will call
Self::assemble_librarywith the source module(s) whose exports form the public API of the library. - If you wish to produce a kernel library, you will call
Self::assemble_kernelwith the source module(s) whose exports form the public API of the kernel.
In the case where you are assembling a library or program, you also need to determine if you need to specify a kernel. You will need to do so if any of your code needs to call into the kernel directly.
- If a kernel is needed, you should construct an
AssemblerusingAssembler::with_kernel - Otherwise, you should construct an
AssemblerusingAssembler::new
Lastly, you need to provide inputs to the assembler which it will use at link time to resolve
references to procedures which are externally-defined (i.e. not defined in any of the modules
provided to the assemble_* function you called). There are a few different ways to do this:
- If you have source code, or a
ast::Module, seeSelf::compile_and_statically_link - If you need to reference procedures from a previously assembled package, but do not want to
include the MAST of those procedures in the assembled artifact, you want to dynamically link
that library, see
Linkage::Dynamicfor more. - If you want to incorporate referenced procedures from a previously assembled package into the
assembled artifact, you want to statically link that library, see
Linkage::Staticfor more.
Implementations§
Source§impl Assembler
Constructors
impl Assembler
Constructors
Sourcepub fn new(source_manager: Arc<dyn SourceManager>) -> Self
pub fn new(source_manager: Arc<dyn SourceManager>) -> Self
Start building an Assembler
Sourcepub fn with_kernel(
source_manager: Arc<dyn SourceManager>,
kernel: Arc<Package>,
) -> Result<Self, Report>
pub fn with_kernel( source_manager: Arc<dyn SourceManager>, kernel: Arc<Package>, ) -> Result<Self, Report>
Start building an Assembler with a kernel defined by the provided kernel package.
Sourcepub fn with_warnings_as_errors(self, yes: bool) -> Self
pub fn with_warnings_as_errors(self, yes: bool) -> Self
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.
Source§impl Assembler
Dependency Management
impl Assembler
Dependency Management
Sourcepub fn compile_and_statically_link(
&mut self,
module: impl Parse,
) -> Result<&mut Self, Report>
pub fn compile_and_statically_link( &mut self, module: impl Parse, ) -> Result<&mut Self, Report>
Ensures module is compiled, and then statically links it into the final artifact.
The given module must be a library module, or an error will be returned.
Sourcepub fn compile_and_statically_link_all(
&mut self,
modules: impl IntoIterator<Item = impl Parse>,
) -> Result<&mut Self, Report>
pub fn compile_and_statically_link_all( &mut self, modules: impl IntoIterator<Item = impl Parse>, ) -> Result<&mut Self, Report>
Ensures every module in modules is compiled, and then statically links them into the final
artifact.
All of the given modules must be library modules, or an error will be returned.
Sourcepub fn compile_and_statically_link_from_root(
&mut self,
root: impl AsRef<Path>,
namespace: Option<&Path>,
) -> Result<(), Report>
pub fn compile_and_statically_link_from_root( &mut self, root: impl AsRef<Path>, namespace: Option<&Path>, ) -> Result<(), Report>
Compiles and statically links all Miden Assembly modules reachable from the provided root
module. The namespace of the resulting modules will be derived from an explicit namespace
declaration in the root module, or from namespace if provided - if both are present, they
must agree.
The module structure is determined by mod declarations reachable from the root module,
i.e. if the root module contains the line mod foo, then a submodule foo in the namespace
of the root module will be located and parsed.
If provided namespace can be any valid Miden Assembly path, e.g. std is a valid path, as
is std::math::u64 - there is no requirement that the namespace be a single identifier.
This allows defining multiple projects relative to a common root namespace without conflict.
For example, let’s say I call this function like so:
use miden_assembly::{Assembler, Path};
let mut assembler = Assembler::default();
assembler.compile_and_statically_link_from_root("~/masm/core/lib.masm", None);And lib.masm contains:
namespace miden::core
pub mod sys;
pub mod math;Then either of the following directory layouts would be parsed successfully, with the namespacing shown:
Layout 1: Submodules are defined at the same level as the parent, named after their module name:
- ~/masm/core/lib.masm -> Parsed as “miden::core”
- ~/masm/core/sys.masm -> Parsed as “miden::core::sys”
- ~/masm/core/math.masm -> Parsed as “miden::core::math”
- ~/masm/core/math/README.md -> Ignored
Layout 2: Submodules are defined in sub-directories named after their module name:
- ~/masm/core/lib.masm -> Parsed as “miden::core”
- ~/masm/core/sys/mod.masm -> Parsed as “miden::core::sys”
- ~/masm/core/math/mod.masm -> Parsed as “miden::core::math”
- ~/masm/core/math/README.md -> Ignored
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.
Source§impl Assembler
Compilation/Assembly
impl Assembler
Compilation/Assembly
Sourcepub fn assemble_library(
self,
name: impl Into<PackageId>,
root: impl Parse,
support: impl IntoIterator<Item = impl Parse>,
) -> Result<Box<Package>, Report>
pub fn assemble_library( self, name: impl Into<PackageId>, root: impl Parse, support: impl IntoIterator<Item = impl Parse>, ) -> Result<Box<Package>, Report>
Sourcepub fn assemble_library_from_root(
self,
root: impl AsRef<Path>,
namespace: Option<&Path>,
) -> Result<Box<Package>, Report>
pub fn assemble_library_from_root( self, root: impl AsRef<Path>, namespace: Option<&Path>, ) -> Result<Box<Package>, Report>
Assemble a library Package from the set of modules reachable from root.
See Assembler::compile_and_statically_link_from_root for details on how modules are
discovered and linked from root.
Sourcepub fn assemble_kernel(
self,
name: impl Into<PackageId>,
root: Box<Module>,
support: impl IntoIterator<Item = Box<Module>>,
) -> Result<Box<Package>, Report>
pub fn assemble_kernel( self, name: impl Into<PackageId>, root: Box<Module>, support: impl IntoIterator<Item = Box<Module>>, ) -> Result<Box<Package>, Report>
Assembles the provided module into a kernel package.
§Errors
Returns an error if parsing or compilation of the specified modules fails.
Sourcepub fn assemble_kernel_from_root(
self,
name: impl Into<PackageId>,
sys_module_path: impl AsRef<Path>,
) -> Result<Box<Package>, Report>
pub fn assemble_kernel_from_root( self, name: impl Into<PackageId>, sys_module_path: impl AsRef<Path>, ) -> Result<Box<Package>, Report>
Assemble a kernel Package from a standard Miden Assembly kernel project layout.
The kernel library will export procedures defined by the module at sys_module_path.
If the optional lib_dir is provided, all modules under this directory will be available
from the kernel module under the $kernel namespace. For example, if lib_dir is set to
“~/masm/lib”, the files will be accessible in the kernel module as follows:
- ~/masm/lib/foo.masm -> Can be imported as “$kernel::foo”
- ~/masm/lib/bar/baz.masm -> Can be imported as “$kernel::bar::baz”
Note: this is a temporary structure which will likely change once https://github.com/0xMiden/miden-vm/issues/1436 is implemented.
Sourcepub fn assemble_program(
self,
name: impl Into<PackageId>,
source: impl Parse,
) -> Result<Box<Package>, Report>
pub fn assemble_program( self, name: impl Into<PackageId>, source: impl Parse, ) -> Result<Box<Package>, Report>
Compiles the provided module into an executable package.
The resulting program can be executed on Miden VM.
§Errors
Returns an error if parsing or compilation of the specified program fails, or if the source doesn’t have an entrypoint.
Source§impl Assembler
impl Assembler
Sourcepub fn for_project_at_path<'a, S>(
self,
manifest_path: impl AsRef<FsPath>,
store: &'a mut S,
) -> Result<ProjectAssembler<'a, S>, Report>where
S: PackageCache + ?Sized,
pub fn for_project_at_path<'a, S>(
self,
manifest_path: impl AsRef<FsPath>,
store: &'a mut S,
) -> Result<ProjectAssembler<'a, S>, Report>where
S: PackageCache + ?Sized,
Get a ProjectAssembler configured for the project whose manifest is at manifest_path.
Sourcepub fn for_project_at_path_with_providers<'a, S>(
self,
manifest_path: impl AsRef<FsPath>,
store: &'a mut S,
providers: impl IntoIterator<Item = Box<dyn ProjectSourceProvider>>,
) -> Result<ProjectAssembler<'a, S>, Report>where
S: PackageCache + ?Sized,
pub fn for_project_at_path_with_providers<'a, S>(
self,
manifest_path: impl AsRef<FsPath>,
store: &'a mut S,
providers: impl IntoIterator<Item = Box<dyn ProjectSourceProvider>>,
) -> Result<ProjectAssembler<'a, S>, Report>where
S: PackageCache + ?Sized,
Get a ProjectAssembler configured for the project whose manifest is at manifest_path.
Sourcepub fn for_project<'a, S>(
self,
project: Arc<ProjectPackage>,
store: &'a mut S,
) -> Result<ProjectAssembler<'a, S>, Report>where
S: PackageCache + ?Sized,
pub fn for_project<'a, S>(
self,
project: Arc<ProjectPackage>,
store: &'a mut S,
) -> Result<ProjectAssembler<'a, S>, Report>where
S: PackageCache + ?Sized,
Get a ProjectAssembler configured for project
Sourcepub fn for_project_with_providers<'a, S>(
self,
project: Arc<ProjectPackage>,
store: &'a mut S,
providers: impl IntoIterator<Item = Box<dyn ProjectSourceProvider>>,
) -> Result<ProjectAssembler<'a, S>, Report>where
S: PackageCache + ?Sized,
pub fn for_project_with_providers<'a, S>(
self,
project: Arc<ProjectPackage>,
store: &'a mut S,
providers: impl IntoIterator<Item = Box<dyn ProjectSourceProvider>>,
) -> Result<ProjectAssembler<'a, S>, Report>where
S: PackageCache + ?Sized,
Get a ProjectAssembler configured for project
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Assembler
impl !Send for Assembler
impl !Sync for Assembler
impl !UnwindSafe for Assembler
impl Freeze for Assembler
impl Unpin for Assembler
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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