pub struct Compiler {
pub program_name: Option<String>,
pub statements_before_dce: u32,
pub statements_after_dce: u32,
/* private fields */
}Expand description
The primary entry point of the Leo compiler.
Fields§
§program_name: Option<String>The program name,
statements_before_dce: u32How many statements were in the AST before DCE?
statements_after_dce: u32How many statements were in the AST after DCE?
Implementations§
Source§impl Compiler
impl Compiler
pub fn network(&self) -> NetworkName
Sourcepub fn parse_program(
&mut self,
source: &str,
filename: FileName,
modules: &[(&str, FileName)],
) -> Result<()>
pub fn parse_program( &mut self, source: &str, filename: FileName, modules: &[(&str, FileName)], ) -> Result<()>
Parses the given source into a program AST and stores it in the compiler state.
The source file and any provided module sources are first registered in the session source map so spans can be resolved correctly. The parser then constructs the program AST from the main source and its modules.
After parsing, this verifies that the program scope name matches the expected
program name (from program.json or the test filename). The resulting AST is
stored in self.state.ast, and optionally written to disk if configured.
Sourcepub fn parse_and_return_program(
&mut self,
source: &str,
filename: FileName,
modules: &[(&str, FileName)],
) -> Result<Program>
pub fn parse_and_return_program( &mut self, source: &str, filename: FileName, modules: &[(&str, FileName)], ) -> Result<Program>
Simple wrapper around parse_program that also returns a program AST.
Sourcepub fn parse_and_return_library(
&mut self,
library_name: &str,
source: &str,
filename: FileName,
modules: &[(&str, FileName)],
) -> Result<Library>
pub fn parse_and_return_library( &mut self, library_name: &str, source: &str, filename: FileName, modules: &[(&str, FileName)], ) -> Result<Library>
Simple wrapper around parse_library that also returns a library AST.
Sourcepub fn parse_library(
&mut self,
library_name: Symbol,
source: &str,
filename: FileName,
modules: &[(&str, FileName)],
) -> Result<()>
pub fn parse_library( &mut self, library_name: Symbol, source: &str, filename: FileName, modules: &[(&str, FileName)], ) -> Result<()>
Parses a library source (and its submodules) into a library AST.
All source strings are registered in the session source map so span information
can be resolved correctly. The resulting AST is stored in self.state.ast.
Sourcepub fn new(
expected_program_name: Option<String>,
is_test: bool,
handler: Handler,
node_builder: Rc<NodeBuilder>,
output_directory: PathBuf,
compiler_options: Option<CompilerOptions>,
import_stubs: IndexMap<Symbol, Stub>,
network: NetworkName,
) -> Self
pub fn new( expected_program_name: Option<String>, is_test: bool, handler: Handler, node_builder: Rc<NodeBuilder>, output_directory: PathBuf, compiler_options: Option<CompilerOptions>, import_stubs: IndexMap<Symbol, Stub>, network: NetworkName, ) -> Self
Returns a new Leo compiler.
pub fn do_pass<P: Pass>(&mut self, input: P::Input) -> Result<P::Output>
Sourcepub fn frontend_passes(&mut self) -> Result<()>
pub fn frontend_passes(&mut self) -> Result<()>
Runs all frontend passes: NameValidation through StaticAnalyzing.
Sourcepub fn intermediate_passes(
&mut self,
) -> Result<(Program, IndexMap<String, Program>)>
pub fn intermediate_passes( &mut self, ) -> Result<(Program, IndexMap<String, Program>)>
Runs the compiler stages.
Returns the generated ABIs (primary and imports), which are captured immediately after monomorphisation to ensure all types are resolved, but not yet lowered.
Sourcepub fn compile(
&mut self,
source: &str,
filename: FileName,
modules: &Vec<(&str, FileName)>,
) -> Result<Compiled>
pub fn compile( &mut self, source: &str, filename: FileName, modules: &Vec<(&str, FileName)>, ) -> Result<Compiled>
Compiles a program from a given source string and a list of module sources.
§Arguments
source- The main source code as a string slice.filename- The name of the main source file.modules- A vector of tuples where each tuple contains:- A module source as a string slice.
- Its associated
FileName.
§Returns
Ok(CompiledPrograms)containing the generated bytecode and ABI if compilation succeeds.Err(CompilerError)if any stage of the pipeline fails.
Sourcepub fn compile_from_directory(
&mut self,
entry_file_path: impl AsRef<Path>,
source_directory: impl AsRef<Path>,
) -> Result<Compiled>
pub fn compile_from_directory( &mut self, entry_file_path: impl AsRef<Path>, source_directory: impl AsRef<Path>, ) -> Result<Compiled>
Compiles a program from a source file and its associated module files in the same directory tree.
Sourcepub fn compile_from_directory_with_file_source(
&mut self,
entry_file_path: impl AsRef<Path>,
source_directory: impl AsRef<Path>,
file_source: &impl FileSource,
) -> Result<Compiled>
pub fn compile_from_directory_with_file_source( &mut self, entry_file_path: impl AsRef<Path>, source_directory: impl AsRef<Path>, file_source: &impl FileSource, ) -> Result<Compiled>
Compiles a program from a source file using the given file source.
Sourcepub fn parse_program_from_directory(
&mut self,
entry_file_path: impl AsRef<Path>,
source_directory: impl AsRef<Path>,
) -> Result<Program>
pub fn parse_program_from_directory( &mut self, entry_file_path: impl AsRef<Path>, source_directory: impl AsRef<Path>, ) -> Result<Program>
Parses a program from a source file and its associated module files in the same directory tree.
Sourcepub fn parse_program_from_directory_with_file_source(
&mut self,
entry_file_path: impl AsRef<Path>,
source_directory: impl AsRef<Path>,
file_source: &impl FileSource,
) -> Result<Program>
pub fn parse_program_from_directory_with_file_source( &mut self, entry_file_path: impl AsRef<Path>, source_directory: impl AsRef<Path>, file_source: &impl FileSource, ) -> Result<Program>
Parses a program from a source file using the given file source.
Sourcepub fn parse_library_from_directory(
&mut self,
library_name: Symbol,
entry_file_path: impl AsRef<Path>,
source_directory: impl AsRef<Path>,
) -> Result<Library>
pub fn parse_library_from_directory( &mut self, library_name: Symbol, entry_file_path: impl AsRef<Path>, source_directory: impl AsRef<Path>, ) -> Result<Library>
Parses a program from a source file and its associated module files in the same directory tree.
Sourcepub fn parse_library_from_directory_with_file_source(
&mut self,
library_name: Symbol,
entry_file_path: impl AsRef<Path>,
source_directory: impl AsRef<Path>,
file_source: &impl FileSource,
) -> Result<Library>
pub fn parse_library_from_directory_with_file_source( &mut self, library_name: Symbol, entry_file_path: impl AsRef<Path>, source_directory: impl AsRef<Path>, file_source: &impl FileSource, ) -> Result<Library>
Parses a library from a source file.
Sourcepub fn add_import_stubs(&mut self) -> Result<()>
pub fn add_import_stubs(&mut self) -> Result<()>
Resolves and registers all import stubs for the current program.
This method performs a graph traversal over the program’s import relationships to:
- Establish parent–child relationships between stubs based on imports.
- Collect all reachable stubs in traversal order.
- Store the explored stubs back into
self.state.ast.ast.stubs.
The traversal starts from the imports of the main program and recursively follows their transitive dependencies. Any missing stub during traversal results in an error.
§Returns
Ok(())if all imports are successfully resolved and stubs are collected.Err(CompilerError)if any imported program cannot be found.
Auto Trait Implementations§
impl !Freeze for Compiler
impl !RefUnwindSafe for Compiler
impl !Send for Compiler
impl !Sync for Compiler
impl Unpin for Compiler
impl UnsafeUnpin for Compiler
impl !UnwindSafe for Compiler
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<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 more