Struct miden_objects::assembly::AssemblyContext
source · pub struct AssemblyContext { /* private fields */ }Expand description
Contains information about compilation of a program or a kernel module.
Assembly context contains a stack of [ModuleContext]’s, each of which, in turn, contains a stack of [ProcedureContext]’s. Thus, at any point in time, we are in a context of compiling a procedure within a module, and we have access to the info about the current module/procedure tuple bing compiled.
Implementations§
source§impl AssemblyContext
impl AssemblyContext
sourcepub fn for_module(is_kernel_module: bool) -> AssemblyContext
pub fn for_module(is_kernel_module: bool) -> AssemblyContext
Returns a new AssemblyContext for non-executable kernel and non-kernel modules.
The is_kernel_module specifies whether provided module is a kernel module.
sourcepub fn for_program(program: Option<&ProgramAst>) -> AssemblyContext
pub fn for_program(program: Option<&ProgramAst>) -> AssemblyContext
Returns a new AssemblyContext for executable module.
If ProgramAst is provided, the context will contain info about the procedures imported by the program, and thus, will be able to determine names of imported procedures for error reporting purposes.
sourcepub fn with_phantom_calls(self, allow_phantom_calls: bool) -> AssemblyContext
pub fn with_phantom_calls(self, allow_phantom_calls: bool) -> AssemblyContext
Sets the flag specifying whether phantom calls are allowed in this context.
§Panics
Panics if the context was instantiated for compiling a kernel module as procedure calls are not allowed in kernel modules in general.
sourcepub fn num_proc_locals(&self) -> u16
pub fn num_proc_locals(&self) -> u16
Returns the number of memory locals allocated for the procedure currently being compiled.
sourcepub fn get_imported_procedure_name(
&self,
id: &ProcedureId
) -> Option<ProcedureName>
pub fn get_imported_procedure_name( &self, id: &ProcedureId ) -> Option<ProcedureName>
Returns the name of the procedure by its ID from the procedure map.
sourcepub fn get_local_procedure(&self, idx: u16) -> Result<&Procedure, AssemblyError>
pub fn get_local_procedure(&self, idx: u16) -> Result<&Procedure, AssemblyError>
Returns the [Procedure] by its index from the vector of local procedures.
sourcepub fn begin_module(
&mut self,
module_path: &LibraryPath,
module_ast: &ModuleAst
) -> Result<(), AssemblyError>
pub fn begin_module( &mut self, module_path: &LibraryPath, module_ast: &ModuleAst ) -> Result<(), AssemblyError>
Initiates compilation of a new module.
This puts a new module onto the module stack and ensures that there are no circular module dependencies.
§Errors
Returns an error if a module with the same path already exists in the module stack.
sourcepub fn complete_module(
&mut self
) -> Result<(Vec<NamedProcedure>, CallSet), AssemblyError>
pub fn complete_module( &mut self ) -> Result<(Vec<NamedProcedure>, CallSet), AssemblyError>
Completes compilation of the current module.
This pops the module off the module stack and return all local procedures of the module (both exported and internal) together with the combined callset of module’s procedures.
sourcepub fn begin_proc(
&mut self,
name: &ProcedureName,
is_export: bool,
num_locals: u16
) -> Result<(), AssemblyError>
pub fn begin_proc( &mut self, name: &ProcedureName, is_export: bool, num_locals: u16 ) -> Result<(), AssemblyError>
Initiates compilation compilation of a new procedure within the current module.
This puts a new procedure context on the procedure stack of the current module, and also ensures that there are no procedures with identical name in the same module.
§Errors
Returns an error if a procedure with the specified name already exists in the current module.
sourcepub fn complete_proc(&mut self, code: CodeBlock)
pub fn complete_proc(&mut self, code: CodeBlock)
Completes compilation of the current procedure and adds the compiled procedure to the list of the current module’s compiled procedures.
sourcepub fn register_local_call(
&mut self,
proc_idx: u16,
inlined: bool
) -> Result<&Procedure, AssemblyError>
pub fn register_local_call( &mut self, proc_idx: u16, inlined: bool ) -> Result<&Procedure, AssemblyError>
Registers a call to a procedure in the current module located at the specified index. This also returns a reference to the invoked procedure.
A procedure can be called in two modes:
- inlined, when the procedure body is inlined into the MAST.
- not inlined: when a new CALL block is created for the procedure call.
§Errors
Returns an error if:
- A procedure at the specified index could not be found.
- We are compiling a kernel and the procedure is not inlined.
sourcepub fn register_external_call(
&mut self,
proc: &Procedure,
inlined: bool
) -> Result<(), AssemblyError>
pub fn register_external_call( &mut self, proc: &Procedure, inlined: bool ) -> Result<(), AssemblyError>
Registers a call to the specified external procedure (i.e., a procedure which is not a part of the current module).
A procedure can be called in two modes:
- inlined, when the procedure body is inlined into the MAST.
- not inlined: when a new CALL or SYSCALL block is created for the procedure call.
§Errors
Returns an error if:
- A procedure at the specified index could not be found.
- We are compiling a kernel and the procedure is not inlined.
sourcepub fn register_phantom_call(
&mut self,
mast_root: RpoDigest
) -> Result<(), AssemblyError>
pub fn register_phantom_call( &mut self, mast_root: RpoDigest ) -> Result<(), AssemblyError>
Registers a “phantom” call to the procedure with the specified MAST root.
A phantom call indicates that code for the procedure is not available. Executing a phantom call will result in a runtime error. However, the VM may be able to execute a program with phantom calls as long as the branches containing them are not taken.
§Errors
Returns an error if phantom calls are not allowed in this assembly context.
sourcepub fn into_kernel(self) -> Kernel
pub fn into_kernel(self) -> Kernel
sourcepub fn into_cb_table(
self,
proc_cache: &ProcedureCache
) -> Result<CodeBlockTable, AssemblyError>
pub fn into_cb_table( self, proc_cache: &ProcedureCache ) -> Result<CodeBlockTable, AssemblyError>
Transforms this context into a CodeBlockTable for the compiled program.
This method is invoked at the end of the compilation of an executable program.
§Panics
Panics if:
- There is not exactly one module left on the module stack.
- If this module is not an executable module.
§Errors
Returns an error if any of the procedures in the module’s callset cannot be found in the specified procedure cache or the local procedure set of the module.