Struct Module

Source
pub struct Module {
    pub name: Ident,
    pub docs: Option<String>,
    /* private fields */
}
Expand description

Represents a SSA IR module

These correspond to MASM modules.

This module is largely a container for functions, but it also provides as the owner for pooled resources available to functions:

  • Mapping from Signature to FuncRef
  • Mapping from FunctionName to FuncRef

Fields§

§name: Ident

The name of this module

§docs: Option<String>

Documentation attached to this module, to be passed through to Miden Assembly during code generation.

Implementations§

Source§

impl Module

Source

pub fn new<S: Into<Ident>>(name: S) -> Self

Create a new, empty Module

Source

pub fn new_with_span<S: AsRef<str>>(name: S, span: SourceSpan) -> Self

Create a new, empty Module with the given source location

Source

pub fn new_kernel<S: Into<Ident>>(name: S) -> Self

Create a new, empty kernel Module

Source

pub fn new_kernel_with_span<S: AsRef<str>>(name: S, span: SourceSpan) -> Self

Create a new, empty kernel Module with the given source location

Source

pub const fn page_size(&self) -> u32

Get the page size to use by default for this module.

Source

pub const fn reserved_memory_pages(&self) -> u32

Get the size (in pages) of the linear memory address space (starting from offset 0), which is reserved for use by the caller.

Source

pub const fn reserved_memory_bytes(&self) -> u32

Get the size (in bytes) of the linear memory address space (starting from offset 0), which is reserved for use by the caller.

Source

pub fn set_reserved_memory_size(&mut self, size: u32)

Set the size of the reserved linear memory region.

NOTE: Declared data segments can be placed in the reserved area, but global variables will never be allocated in the reserved area.

Source

pub const fn is_kernel(&self) -> bool

Returns true if this module is a kernel module

Source

pub fn is_detached(&self) -> bool

Returns true if this module has yet to be attached to a Program

Source

pub fn segments(&self) -> &DataSegmentTable

Return the table of data segments for this module

Source

pub fn declare_data_segment( &mut self, offset: Offset, size: u32, init: ConstantData, readonly: bool, ) -> Result<(), DataSegmentError>

Declare a new DataSegment in this module, with the given offset, size, and data.

Returns Err if the segment declaration is invalid, or conflicts with an existing segment

Data segments are ordered by the address at which they are allocated, at link-time, all segments from all modules are linked together, and they must either be disjoint, or exactly identical in order to overlap - it is not permitted to have partially overlapping segments with different views of the memory represented by that segment.

Source

pub fn globals(&self) -> &GlobalVariableTable

Return the table of global variables for this module

Source

pub fn declare_global_variable( &mut self, name: Ident, ty: Type, linkage: Linkage, init: Option<ConstantData>, ) -> Result<GlobalVariable, GlobalVariableError>

Declare a new GlobalVariable in this module, with the given name, type, linkage, and optional initializer.

Returns Err if a symbol with the same name but conflicting declaration already exists, or if the specification of the global variable is invalid in any way.

NOTE: The GlobalVariable returned here is scoped to this module only, it cannot be used to index into the global variable table of a Program, which is constructed at link-time.

Source

pub fn set_global_initializer( &mut self, gv: GlobalVariable, init: ConstantData, ) -> Result<(), GlobalVariableError>

Set the initializer for a GlobalVariable to init.

Returns Err if the initializer conflicts with the current definition of the global in any way.

Source

pub fn global(&self, id: GlobalVariable) -> &GlobalVariableData

Get the data associated with the given GlobalVariable

Source

pub fn find_global(&self, name: Ident) -> Option<&GlobalVariableData>

Look up a global by name.

Source

pub fn entrypoint(&self) -> Option<FunctionIdent>

Find the first function in this module marked with the entrypoint attribute

Source

pub fn functions<'a, 'b: 'a>(&'b self) -> Iter<'a, FunctionListAdapter>

Return an iterator over the functions in this module

The iterator is double-ended, so can be used to traverse the module body in either direction

Source

pub fn function<'a, 'b: 'a>(&'b self, id: Ident) -> Option<&'a Function>

Get a Function in this module by name, if available

Source

pub fn imports(&self) -> ModuleImportInfo

Compute the set of imports for this module, automatically aliasing modules when there are namespace conflicts

Source

pub fn contains(&self, name: Ident) -> bool

Returns true if this module contains the function name

Unlinks the given function from this module

Source

pub fn push( &mut self, function: Box<Function>, ) -> Result<(), SymbolConflictError>

Append function to the end of this module’s body, returning the [FuncId] assigned to it within this module.

NOTE: This function will panic if either of the following rules are violated:

  • If this module is a kernel module, public functions must use the kernel calling convention, however private functions can use any convention.
  • If this module is not a kernel module, functions may not use the kernel calling convention
Source

pub fn insert_before( &mut self, function: Box<Function>, before: Ident, ) -> Result<(), SymbolConflictError>

Insert function in the module body before the function with id before

If before is no longer attached to this module, function is added to the end of the module body.

Source

pub fn insert_after( &mut self, function: Box<Function>, after: Ident, ) -> Result<(), SymbolConflictError>

Insert function in the module body after the function with id after

If after is no longer attached to this module, function is added to the end of the module body.

Source

pub fn pop_front(&mut self) -> Option<Box<Function>>

Remove the first function in the module, and return it, if present

Source

pub fn cursor_mut<'a, 'b: 'a>(&'b mut self) -> ModuleCursor<'a>

Returns a mutable cursor to the module body, starting at the first function.

If the module body is empty, the returned cursor will point to the null object.

NOTE: If one uses this cursor to insert a function that is invalid

Source

pub fn cursor_at<'a, 'b: 'a>( &'b self, id: Ident, ) -> Cursor<'a, FunctionListAdapter>

Returns a cursor to the module body, located at the function indicated by id.

If no function with id is in the list, the returned cursor will point to the null object.

Source

pub fn cursor_mut_at<'a, 'b: 'a>(&'b mut self, id: Ident) -> ModuleCursor<'a>

Returns a mutable cursor to the module body, located at the function indicated by id.

If no function with id is in the list, the returned cursor will point to the null object.

Trait Implementations§

Source§

impl AnalysisKey for Module

Source§

type Key = Ident

The type of the unique identifier associated with Self
Source§

fn key(&self) -> Self::Key

Get the key to associate with the current entity
Source§

impl Debug for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Module

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Emit for Module

Source§

fn name(&self) -> Option<Symbol>

The name of this item, if applicable
Source§

fn output_type(&self, _mode: OutputMode) -> OutputType

The output type associated with this item and the given mode
Source§

fn write_to<W: Write>( &self, writer: W, mode: OutputMode, _session: &Session, ) -> Result<()>

Write this item to the given std::io::Write handle, using mode to determine the output type
Source§

fn write_to_stdout(&self, session: &Session) -> Result<(), Error>

Write this item to standard output, inferring the best OutputMode based on whether or not stdout is a tty or not
Source§

fn write_to_file( &self, path: &Path, mode: OutputMode, session: &Session, ) -> Result<(), Error>

Write this item to the given file path, using mode to determine the output type
Source§

impl Parse for Module

Source§

type Grammar = ModuleParser

Source§

fn parse_tokens( parser: &Parser<'_>, source: Arc<SourceFile>, tokens: impl IntoIterator<Item = Result<(ByteIndex, Token, ByteIndex), ParseError>>, ) -> ParseResult<Self>

Source§

fn parse(parser: &Parser<'_>, source: Arc<SourceFile>) -> ParseResult<Self>

Source§

impl PartialEq for Module

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PrettyPrint for Module

Source§

fn render(&self) -> Document

The core of the PrettyPrint functionality. Read more
Source§

fn to_pretty_string(&self) -> String

Produce a String containing the results of pretty-printing this object. Read more
Source§

fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Pretty-print this object to the given core::fmt::Formatter. Read more
Source§

impl Spanned for Module

Source§

impl Eq for Module

Auto Trait Implementations§

§

impl !Freeze for Module

§

impl !RefUnwindSafe for Module

§

impl !Send for Module

§

impl !Sync for Module

§

impl Unpin for Module

§

impl !UnwindSafe for Module

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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