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

source

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.

source

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.

source

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.

source

pub fn is_kernel(&self) -> bool

Returns true if this context is used for compiling a kernel.

source

pub fn num_proc_locals(&self) -> u16

Returns the number of memory locals allocated for the procedure currently being compiled.

source

pub fn get_imported_procedure_name( &self, id: &ProcedureId ) -> Option<ProcedureName>

Returns the name of the procedure by its ID from the procedure map.

source

pub fn get_local_procedure(&self, idx: u16) -> Result<&Procedure, AssemblyError>

Returns the [Procedure] by its index from the vector of local procedures.

source

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.

source

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.

source

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.

source

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.

source

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.
source

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.
source

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.

source

pub fn into_kernel(self) -> Kernel

Transforms this context into a Kernel.

This method is invoked at the end of the compilation of a kernel module.

§Panics

Panics if this context was not used for kernel compilation (i.e., was not instantiated with is_kernel == true) or if the kernel module has not been completed yet.

source

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.

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<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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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