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 parse( &mut self, source: &str, filename: FileName, modules: &[(&str, FileName)], ) -> Result<()>
Sourcepub fn parse_and_return_ast(
&mut self,
source: &str,
filename: FileName,
modules: &[(&str, FileName)],
) -> Result<Program>
pub fn parse_and_return_ast( &mut self, source: &str, filename: FileName, modules: &[(&str, FileName)], ) -> Result<Program>
Simple wrapper around parse that also returns the 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.
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 parse_from_directory(
&mut self,
entry_file_path: impl AsRef<Path>,
source_directory: impl AsRef<Path>,
) -> Result<Program>
pub fn parse_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 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