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: IdentThe 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
impl Module
Sourcepub fn new_with_span<S: AsRef<str>>(name: S, span: SourceSpan) -> Self
pub fn new_with_span<S: AsRef<str>>(name: S, span: SourceSpan) -> Self
Create a new, empty Module with the given source location
Sourcepub fn new_kernel<S: Into<Ident>>(name: S) -> Self
pub fn new_kernel<S: Into<Ident>>(name: S) -> Self
Create a new, empty kernel Module
Sourcepub fn new_kernel_with_span<S: AsRef<str>>(name: S, span: SourceSpan) -> Self
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
Sourcepub const fn reserved_memory_pages(&self) -> u32
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.
Sourcepub const fn reserved_memory_bytes(&self) -> u32
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.
Sourcepub fn set_reserved_memory_size(&mut self, size: u32)
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.
Sourcepub fn is_detached(&self) -> bool
pub fn is_detached(&self) -> bool
Returns true if this module has yet to be attached to a Program
Sourcepub fn segments(&self) -> &DataSegmentTable
pub fn segments(&self) -> &DataSegmentTable
Return the table of data segments for this module
Sourcepub fn declare_data_segment(
&mut self,
offset: Offset,
size: u32,
init: ConstantData,
readonly: bool,
) -> Result<(), DataSegmentError>
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.
Sourcepub fn globals(&self) -> &GlobalVariableTable
pub fn globals(&self) -> &GlobalVariableTable
Return the table of global variables for this module
Sourcepub fn declare_global_variable(
&mut self,
name: Ident,
ty: Type,
linkage: Linkage,
init: Option<ConstantData>,
) -> Result<GlobalVariable, GlobalVariableError>
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.
Sourcepub fn set_global_initializer(
&mut self,
gv: GlobalVariable,
init: ConstantData,
) -> Result<(), GlobalVariableError>
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.
Sourcepub fn global(&self, id: GlobalVariable) -> &GlobalVariableData
pub fn global(&self, id: GlobalVariable) -> &GlobalVariableData
Get the data associated with the given GlobalVariable
Sourcepub fn find_global(&self, name: Ident) -> Option<&GlobalVariableData>
pub fn find_global(&self, name: Ident) -> Option<&GlobalVariableData>
Look up a global by name.
Sourcepub fn entrypoint(&self) -> Option<FunctionIdent>
pub fn entrypoint(&self) -> Option<FunctionIdent>
Find the first function in this module marked with the entrypoint attribute
Sourcepub fn functions<'a, 'b: 'a>(&'b self) -> Iter<'a, FunctionListAdapter>
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
Sourcepub fn function<'a, 'b: 'a>(&'b self, id: Ident) -> Option<&'a Function>
pub fn function<'a, 'b: 'a>(&'b self, id: Ident) -> Option<&'a Function>
Get a Function in this module by name, if available
Sourcepub fn imports(&self) -> ModuleImportInfo
pub fn imports(&self) -> ModuleImportInfo
Compute the set of imports for this module, automatically aliasing modules when there are namespace conflicts
Sourcepub fn contains(&self, name: Ident) -> bool
pub fn contains(&self, name: Ident) -> bool
Returns true if this module contains the function name
Sourcepub fn unlink(&mut self, id: Ident) -> Box<Function>
pub fn unlink(&mut self, id: Ident) -> Box<Function>
Unlinks the given function from this module
Sourcepub fn push(
&mut self,
function: Box<Function>,
) -> Result<(), SymbolConflictError>
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
Sourcepub fn insert_before(
&mut self,
function: Box<Function>,
before: Ident,
) -> Result<(), SymbolConflictError>
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.
Sourcepub fn insert_after(
&mut self,
function: Box<Function>,
after: Ident,
) -> Result<(), SymbolConflictError>
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.
Sourcepub fn pop_front(&mut self) -> Option<Box<Function>>
pub fn pop_front(&mut self) -> Option<Box<Function>>
Remove the first function in the module, and return it, if present
Sourcepub fn cursor_mut<'a, 'b: 'a>(&'b mut self) -> ModuleCursor<'a>
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
Sourcepub fn cursor_at<'a, 'b: 'a>(
&'b self,
id: Ident,
) -> Cursor<'a, FunctionListAdapter>
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.
Sourcepub fn cursor_mut_at<'a, 'b: 'a>(&'b mut self, id: Ident) -> ModuleCursor<'a>
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
impl AnalysisKey for Module
Source§impl Emit for Module
impl Emit for Module
Source§fn output_type(&self, _mode: OutputMode) -> OutputType
fn output_type(&self, _mode: OutputMode) -> OutputType
modeSource§fn write_to<W: Write>(
&self,
writer: W,
mode: OutputMode,
_session: &Session,
) -> Result<()>
fn write_to<W: Write>( &self, writer: W, mode: OutputMode, _session: &Session, ) -> Result<()>
mode to determine the output
typeSource§fn write_to_stdout(&self, session: &Session) -> Result<(), Error>
fn write_to_stdout(&self, session: &Session) -> Result<(), Error>
Source§fn write_to_file(
&self,
path: &Path,
mode: OutputMode,
session: &Session,
) -> Result<(), Error>
fn write_to_file( &self, path: &Path, mode: OutputMode, session: &Session, ) -> Result<(), Error>
mode to determine the output typeSource§impl Parse for Module
impl Parse for Module
type Grammar = ModuleParser
fn parse_tokens( parser: &Parser<'_>, source: Arc<SourceFile>, tokens: impl IntoIterator<Item = Result<(ByteIndex, Token, ByteIndex), ParseError>>, ) -> ParseResult<Self>
fn parse(parser: &Parser<'_>, source: Arc<SourceFile>) -> ParseResult<Self>
Source§impl PrettyPrint for Module
impl PrettyPrint for Module
Source§fn to_pretty_string(&self) -> String
fn to_pretty_string(&self) -> String
Source§fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn pretty_print(&self, f: &mut Formatter<'_>) -> Result<(), Error>
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> 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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