Struct miden_objects::assembly::ProgramAst
source · 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
impl ProgramAst
sourcepub fn new(
body: Vec<Node>,
local_procs: Vec<ProcedureAst>
) -> Result<ProgramAst, ParsingError>
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.
sourcepub fn with_import_info(self, import_info: ModuleImports) -> ProgramAst
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.
sourcepub fn with_source_locations<L>(
self,
locations: L,
start: SourceLocation
) -> ProgramAstwhere
L: IntoIterator<Item = SourceLocation>,
pub fn with_source_locations<L>(
self,
locations: L,
start: SourceLocation
) -> ProgramAstwhere
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.
sourcepub fn source_locations(&self) -> impl Iterator<Item = &SourceLocation>
pub fn source_locations(&self) -> impl Iterator<Item = &SourceLocation>
Returns the SourceLocation associated with this program, if present.
sourcepub fn procedures(&self) -> &[ProcedureAst]
pub fn procedures(&self) -> &[ProcedureAst]
Returns a slice over the internal procedures of this program.
sourcepub fn import_info(&self) -> &ModuleImports
pub fn import_info(&self) -> &ModuleImports
Returns a reference to the import info for this program
sourcepub fn parse(source: &str) -> Result<ProgramAst, ParsingError>
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.
sourcepub fn write_into<W>(&self, target: &mut W, options: AstSerdeOptions)where
W: ByteWriter,
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.
sourcepub fn to_bytes(&self, options: AstSerdeOptions) -> Vec<u8> ⓘ
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.
sourcepub fn read_from<R>(source: &mut R) -> Result<ProgramAst, DeserializationError>where
R: ByteReader,
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.
sourcepub fn from_bytes(bytes: &[u8]) -> Result<ProgramAst, DeserializationError>
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.
sourcepub fn load_source_locations<R>(
&mut self,
source: &mut R
) -> Result<(), DeserializationError>where
R: ByteReader,
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.
sourcepub fn write_source_locations<W>(&self, target: &mut W)where
W: ByteWriter,
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.
sourcepub fn into_parts(self) -> (Vec<ProcedureAst>, Vec<Node>)
pub fn into_parts(self) -> (Vec<ProcedureAst>, Vec<Node>)
Returns local procedures and body nodes of this program.
sourcepub fn clear_imports(&mut self)
pub fn clear_imports(&mut self)
Clear import info from the program
Trait Implementations§
source§impl Clone for ProgramAst
impl Clone for ProgramAst
source§fn clone(&self) -> ProgramAst
fn clone(&self) -> ProgramAst
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for ProgramAst
impl Debug for ProgramAst
source§impl Display for ProgramAst
impl Display for ProgramAst
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
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
impl PartialEq for ProgramAst
source§fn eq(&self, other: &ProgramAst) -> bool
fn eq(&self, other: &ProgramAst) -> bool
self and other values to be equal, and is used
by ==.