Struct leo_compiler::Compiler

source ·
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 NodeIDs.

§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>

source

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.

source

pub fn checksum(&self) -> Result<String>

Returns a SHA256 checksum of the program file.

source

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.

source

pub fn parse_program(&mut self) -> Result<()>

Parses and stores the main program file, constructs a syntax tree, and generates a program.

source

pub fn symbol_table_pass(&self) -> Result<SymbolTable>

Runs the symbol table pass.

source

pub fn type_checker_pass( &'a self, symbol_table: SymbolTable ) -> Result<(SymbolTable, StructGraph, CallGraph)>

Runs the type checker pass.

source

pub fn loop_unrolling_pass( &mut self, symbol_table: SymbolTable ) -> Result<SymbolTable>

Runs the loop unrolling pass.

source

pub fn static_single_assignment_pass( &mut self, symbol_table: &SymbolTable ) -> Result<()>

Runs the static single assignment pass.

source

pub fn flattening_pass(&mut self, symbol_table: &SymbolTable) -> Result<()>

Runs the flattening pass.

source

pub fn destructuring_pass(&mut self) -> Result<()>

Runs the destructuring pass.

source

pub fn function_inlining_pass(&mut self, call_graph: &CallGraph) -> Result<()>

Runs the function inlining pass.

source

pub fn dead_code_elimination_pass(&mut self) -> Result<()>

Runs the dead code elimination pass.

source

pub fn code_generation_pass( &mut self, symbol_table: &SymbolTable, struct_graph: &StructGraph, call_graph: &CallGraph ) -> Result<String>

Runs the code generation pass.

source

pub fn compiler_stages( &mut self ) -> Result<(SymbolTable, StructGraph, CallGraph)>

Runs the compiler stages.

source

pub fn compile(&mut self) -> Result<String>

Returns a compiled Leo program.

source

fn write_ast_to_json(&self, file_suffix: &str) -> Result<()>

Writes the AST to a JSON file.

source

fn write_symbol_table_to_json( &self, file_suffix: &str, symbol_table: &SymbolTable ) -> Result<()>

Writes the Symbol Table to a JSON file.

source

pub fn add_import_stubs(&mut self) -> Result<()>

Merges the dependencies defined in program.json with the dependencies imported in .leo file

Trait Implementations§

source§

impl<'a, N: Clone + Network> Clone for Compiler<'a, N>

source§

fn clone(&self) -> Compiler<'a, N>

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

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> 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more