pub struct ProgramAst { /* private fields */ }
Expand description

An abstract syntax tree of an executable Miden program.

A program AST consists of a body of the program, a list of internal procedure ASTs, a list of imported libraries, a map from procedure ids to procedure names for imported procedures used in the module, and the source location of the program.

Implementations§

source§

impl ProgramAst

source

pub fn new( body: Vec<Node>, local_procs: Vec<ProcedureAst> ) -> Result<ProgramAst, ParsingError>

Returns a new ProgramAst.

A program consist of a body and a set of internal (i.e., not exported) procedures.

§Errors

Returns an error if:

  • The number of body nodes is greater than or equal to 2^16.
  • The number of local procedures is greater than or equal to 2^16.
source

pub fn with_import_info(self, import_info: ModuleImports) -> ProgramAst

Adds the provided import information to the program.

§Panics

Panics if import information has already been added.

source

pub fn with_source_locations<L>( self, locations: L, start: SourceLocation ) -> ProgramAst
where L: IntoIterator<Item = SourceLocation>,

Binds the provided locations to the nodes of this program’s body.

The start location points to the begin token which does not have its own node.

§Panics

Panics if source location information has already been associated with this program.

source

pub fn source_locations(&self) -> impl Iterator<Item = &SourceLocation>

Returns the SourceLocation associated with this program, if present.

source

pub fn procedures(&self) -> &[ProcedureAst]

Returns a slice over the internal procedures of this program.

source

pub fn body(&self) -> &CodeBody

Returns a reference to the body of this program.

source

pub fn import_info(&self) -> &ModuleImports

Returns a reference to the import info for this program

source

pub fn parse(source: &str) -> Result<ProgramAst, ParsingError>

Parses the provided source into a ProgramAst.

A program consist of a body and a set of internal (i.e., not exported) procedures.

source

pub fn write_into<W>(&self, target: &mut W, options: AstSerdeOptions)
where W: ByteWriter,

Writes byte representation of this ProgramAst into the specified target according with the specified serde options.

The serde options are serialized as header information for the purposes of deserialization.

source

pub fn to_bytes(&self, options: AstSerdeOptions) -> Vec<u8>

Returns byte representation of this ProgramAst.

The serde options are serialized as header information for the purposes of deserialization.

source

pub fn read_from<R>(source: &mut R) -> Result<ProgramAst, DeserializationError>
where R: ByteReader,

Returns a ProgramAst struct deserialized from the specified reader.

This function assumes that the byte array contains a serialized AstSerdeOptions struct as a header.

source

pub fn from_bytes(bytes: &[u8]) -> Result<ProgramAst, DeserializationError>

Returns a ProgramAst struct deserialized from the provided bytes.

This function assumes that the byte array contains a serialized AstSerdeOptions struct as a header.

source

pub fn load_source_locations<R>( &mut self, source: &mut R ) -> Result<(), DeserializationError>
where R: ByteReader,

Loads the SourceLocation from the source.

It expects the start location at the first position, and will subsequently load the body via CodeBody::load_source_locations. Finally, it will load the local procedures via ProcedureAst::load_source_locations.

source

pub fn write_source_locations<W>(&self, target: &mut W)
where W: ByteWriter,

Writes the SourceLocation into target.

It will write the start location, and then execute the body serialization via [CodeBlock::write_source_locations]. Finally, it will write the local procedures via ProcedureAst::write_source_locations.

source

pub fn into_parts(self) -> (Vec<ProcedureAst>, Vec<Node>)

Returns local procedures and body nodes of this program.

source

pub fn clear_imports(&mut self)

Clear import info from the program

source

pub fn write_to_file<P>(&self, file_path: P) -> Result<(), Error>
where P: AsRef<Path>,

Writes ProgramAst to provided file path

Trait Implementations§

source§

impl Clone for ProgramAst

source§

fn clone(&self) -> ProgramAst

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for ProgramAst

source§

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

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

impl Display for ProgramAst

source§

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

Writes this ProgramAst as formatted MASM code into the formatter.

The formatted code puts each instruction on a separate line and preserves correct indentation for instruction blocks.

§Panics

Panics if import info is not associated with this program.

source§

impl PartialEq for ProgramAst

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for ProgramAst

source§

impl StructuralPartialEq for ProgramAst

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> ToOwned for T
where T: Clone,

§

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> ToString for T
where T: Display + ?Sized,

source§

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

§

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