pub struct Compiler<'a, N: Network> {
handler: &'a Handler,
main_file_path: PathBuf,
output_directory: PathBuf,
pub program_name: String,
pub network: String,
pub ast: Ast,
compiler_options: CompilerOptions,
node_builder: NodeBuilder,
assigner: Assigner,
type_table: TypeTable,
import_stubs: IndexMap<Symbol, Stub>,
phantom: PhantomData<N>,
}
Expand description
The primary entry point of the Leo compiler.
Fields§
§handler: &'a Handler
The handler is used for error and warning emissions.
main_file_path: PathBuf
The path to the main leo file.
output_directory: PathBuf
The path to where the compiler outputs all generated files.
program_name: String
The program name,
network: String
The network name,
ast: Ast
The AST for the program.
compiler_options: CompilerOptions
Options configuring compilation.
node_builder: NodeBuilder
The NodeCounter
used to generate sequentially increasing NodeID
s.
assigner: Assigner
The Assigner
is used to construct (unique) assignment statements.
type_table: TypeTable
The type table.
import_stubs: IndexMap<Symbol, Stub>
The stubs for imported programs. Produced by Retriever
module.
phantom: PhantomData<N>
Implementations§
Source§impl<'a, N: Network> Compiler<'a, N>
impl<'a, N: Network> Compiler<'a, N>
Sourcepub fn new(
program_name: String,
network: String,
handler: &'a Handler,
main_file_path: PathBuf,
output_directory: PathBuf,
compiler_options: Option<CompilerOptions>,
import_stubs: IndexMap<Symbol, Stub>,
) -> Self
pub fn new( program_name: String, network: String, handler: &'a Handler, main_file_path: PathBuf, output_directory: PathBuf, compiler_options: Option<CompilerOptions>, import_stubs: IndexMap<Symbol, Stub>, ) -> Self
Returns a new Leo compiler.
Sourcepub fn parse_program_from_string(
&mut self,
program_string: &str,
name: FileName,
) -> Result<()>
pub fn parse_program_from_string( &mut self, program_string: &str, name: FileName, ) -> Result<()>
Parses and stores a program file content from a string, constructs a syntax tree, and generates a program.
Sourcepub fn parse_program(&mut self) -> Result<()>
pub fn parse_program(&mut self) -> Result<()>
Parses and stores the main program file, constructs a syntax tree, and generates a program.
Sourcepub fn symbol_table_pass(&self) -> Result<SymbolTable>
pub fn symbol_table_pass(&self) -> Result<SymbolTable>
Runs the symbol table pass.
Sourcepub fn type_checker_pass(
&'a self,
symbol_table: &mut SymbolTable,
) -> Result<(StructGraph, CallGraph)>
pub fn type_checker_pass( &'a self, symbol_table: &mut SymbolTable, ) -> Result<(StructGraph, CallGraph)>
Runs the type checker pass.
Sourcepub fn static_analysis_pass(&mut self, symbol_table: &SymbolTable) -> Result<()>
pub fn static_analysis_pass(&mut self, symbol_table: &SymbolTable) -> Result<()>
Runs the static analysis pass.
Sourcepub fn const_propagation_and_unroll_loop(
&mut self,
symbol_table: &mut SymbolTable,
) -> Result<()>
pub fn const_propagation_and_unroll_loop( &mut self, symbol_table: &mut SymbolTable, ) -> Result<()>
Run const propagation and loop unrolling until we hit a fixed point or find an error.
Sourcepub fn const_propagation_pass(
&mut self,
symbol_table: &mut SymbolTable,
) -> Result<ConstPropagatorOutput>
pub fn const_propagation_pass( &mut self, symbol_table: &mut SymbolTable, ) -> Result<ConstPropagatorOutput>
Runs the const propagation pass.
Sourcepub fn loop_unrolling_pass(
&mut self,
symbol_table: &mut SymbolTable,
) -> Result<UnrollerOutput>
pub fn loop_unrolling_pass( &mut self, symbol_table: &mut SymbolTable, ) -> Result<UnrollerOutput>
Runs the loop unrolling pass.
Sourcepub fn static_single_assignment_pass(
&mut self,
symbol_table: &SymbolTable,
) -> Result<()>
pub fn static_single_assignment_pass( &mut self, symbol_table: &SymbolTable, ) -> Result<()>
Runs the static single assignment pass.
Sourcepub fn flattening_pass(&mut self, symbol_table: &SymbolTable) -> Result<()>
pub fn flattening_pass(&mut self, symbol_table: &SymbolTable) -> Result<()>
Runs the flattening pass.
Sourcepub fn destructuring_pass(&mut self) -> Result<()>
pub fn destructuring_pass(&mut self) -> Result<()>
Runs the destructuring pass.
Sourcepub fn function_inlining_pass(&mut self, call_graph: &CallGraph) -> Result<()>
pub fn function_inlining_pass(&mut self, call_graph: &CallGraph) -> Result<()>
Runs the function inlining pass.
Sourcepub fn dead_code_elimination_pass(&mut self) -> Result<()>
pub fn dead_code_elimination_pass(&mut self) -> Result<()>
Runs the dead code elimination pass.
Sourcepub fn code_generation_pass(
&mut self,
symbol_table: &SymbolTable,
struct_graph: &StructGraph,
call_graph: &CallGraph,
) -> Result<String>
pub fn code_generation_pass( &mut self, symbol_table: &SymbolTable, struct_graph: &StructGraph, call_graph: &CallGraph, ) -> Result<String>
Runs the code generation pass.
Sourcepub fn compiler_stages(
&mut self,
) -> Result<(SymbolTable, StructGraph, CallGraph)>
pub fn compiler_stages( &mut self, ) -> Result<(SymbolTable, StructGraph, CallGraph)>
Runs the compiler stages.
Sourcefn write_ast_to_json(&self, file_suffix: &str) -> Result<()>
fn write_ast_to_json(&self, file_suffix: &str) -> Result<()>
Writes the AST to a JSON file.
Sourcepub fn add_import_stubs(&mut self) -> Result<()>
pub fn add_import_stubs(&mut self) -> Result<()>
Merges the dependencies defined in program.json
with the dependencies imported in .leo
file
Trait Implementations§
Auto Trait Implementations§
impl<'a, N> !Freeze for Compiler<'a, N>
impl<'a, N> !RefUnwindSafe for Compiler<'a, N>
impl<'a, N> !Send for Compiler<'a, N>
impl<'a, N> !Sync for Compiler<'a, N>
impl<'a, N> Unpin for Compiler<'a, N>where
N: Unpin,
impl<'a, N> !UnwindSafe for Compiler<'a, N>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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