Skip to main content

Assembler

Struct Assembler 

Source
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:

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_program with 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_library with 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_kernel with 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.

Programs compiled with an empty kernel cannot use the `syscall` instruction.

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, see Self::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::Dynamic for 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::Static for more.

Implementations§

Source§

impl Assembler

Constructors

Source

pub fn new(source_manager: Arc<dyn SourceManager>) -> Assembler

Start building an Assembler

Source

pub fn with_kernel( source_manager: Arc<dyn SourceManager>, kernel: Arc<Package>, ) -> Result<Assembler, Report>

Start building an Assembler with a kernel defined by the provided kernel package.

Source

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.

Source§

impl Assembler

Dependency Management

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.

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.

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

pub fn with_package( self, package: Arc<Package>, linkage: Linkage, ) -> Result<Assembler, Report>

Link against package with the specified linkage mode during assembly.

Link against package with the specified linkage mode during assembly.

Source§

impl Assembler

Public Accessors

Source

pub fn warnings_as_errors(&self) -> bool

Returns true if this assembler promotes warning diagnostics as errors by default.

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§

impl Assembler

Compilation/Assembly

Source

pub fn assemble_library( self, name: impl Into<PackageId>, root: impl Parse, support: impl IntoIterator<Item = impl Parse>, ) -> Result<Box<Package>, Report>

Assembles a root module, and its supporting submodules into a library Package.

§Errors

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

Source

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.

Source

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.

Source

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.

Source

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

This impl block contains no public items.

Procedure Invocation

Source§

impl Assembler

This impl block contains no public items.

Instruction Compilation

Source§

impl Assembler

Source

pub fn for_project_at_path<'a, S>( self, manifest_path: impl AsRef<Path>, 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.

Source

pub fn for_project_at_path_with_providers<'a, S>( self, manifest_path: impl AsRef<Path>, 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.

Source

pub fn for_project<'a, S>( self, project: Arc<Package>, store: &'a mut S, ) -> Result<ProjectAssembler<'a, S>, Report>
where S: PackageCache + ?Sized,

Get a ProjectAssembler configured for project

Source

pub fn for_project_with_providers<'a, S>( self, project: Arc<Package>, 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§

Source§

impl Clone for Assembler

Source§

fn clone(&self) -> Assembler

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<D> OwoColorize for D

Source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
Source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
Source§

fn black(&self) -> FgColorDisplay<'_, Black, Self>

Change the foreground color to black
Source§

fn on_black(&self) -> BgColorDisplay<'_, Black, Self>

Change the background color to black
Source§

fn red(&self) -> FgColorDisplay<'_, Red, Self>

Change the foreground color to red
Source§

fn on_red(&self) -> BgColorDisplay<'_, Red, Self>

Change the background color to red
Source§

fn green(&self) -> FgColorDisplay<'_, Green, Self>

Change the foreground color to green
Source§

fn on_green(&self) -> BgColorDisplay<'_, Green, Self>

Change the background color to green
Source§

fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>

Change the foreground color to yellow
Source§

fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>

Change the background color to yellow
Source§

fn blue(&self) -> FgColorDisplay<'_, Blue, Self>

Change the foreground color to blue
Source§

fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>

Change the background color to blue
Source§

fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to magenta
Source§

fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to magenta
Source§

fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>

Change the foreground color to purple
Source§

fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>

Change the background color to purple
Source§

fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>

Change the foreground color to cyan
Source§

fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>

Change the background color to cyan
Source§

fn white(&self) -> FgColorDisplay<'_, White, Self>

Change the foreground color to white
Source§

fn on_white(&self) -> BgColorDisplay<'_, White, Self>

Change the background color to white
Source§

fn default_color(&self) -> FgColorDisplay<'_, Default, Self>

Change the foreground color to the terminal default
Source§

fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>

Change the background color to the terminal default
Source§

fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>

Change the foreground color to bright black
Source§

fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>

Change the background color to bright black
Source§

fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>

Change the foreground color to bright red
Source§

fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>

Change the background color to bright red
Source§

fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>

Change the foreground color to bright green
Source§

fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>

Change the background color to bright green
Source§

fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>

Change the foreground color to bright yellow
Source§

fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>

Change the background color to bright yellow
Source§

fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>

Change the foreground color to bright blue
Source§

fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>

Change the background color to bright blue
Source§

fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright magenta
Source§

fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright magenta
Source§

fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>

Change the foreground color to bright purple
Source§

fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>

Change the background color to bright purple
Source§

fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>

Change the foreground color to bright cyan
Source§

fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>

Change the background color to bright cyan
Source§

fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>

Change the foreground color to bright white
Source§

fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>

Change the background color to bright white
Source§

fn bold(&self) -> BoldDisplay<'_, Self>

Make the text bold
Source§

fn dimmed(&self) -> DimDisplay<'_, Self>

Make the text dim
Source§

fn italic(&self) -> ItalicDisplay<'_, Self>

Make the text italicized
Source§

fn underline(&self) -> UnderlineDisplay<'_, Self>

Make the text underlined
Make the text blink
Make the text blink (but fast!)
Source§

fn reversed(&self) -> ReversedDisplay<'_, Self>

Swap the foreground and background colors
Source§

fn hidden(&self) -> HiddenDisplay<'_, Self>

Hide the text
Source§

fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>

Cross out the text
Source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
Source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
Source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
Source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self, ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
Source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
Source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
Source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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