Struct leo_passes::code_generation::generator::CodeGenerator

source ·
pub struct CodeGenerator<'a> {
Show 15 fields pub(crate) symbol_table: &'a SymbolTable, pub(crate) type_table: &'a TypeTable, pub(crate) struct_graph: &'a StructGraph, pub(crate) _call_graph: &'a CallGraph, pub(crate) next_register: u64, pub(crate) current_function: Option<&'a Function>, pub(crate) variable_mapping: IndexMap<&'a Symbol, String>, pub(crate) composite_mapping: IndexMap<&'a Symbol, (bool, String)>, pub(crate) global_mapping: IndexMap<&'a Symbol, String>, pub(crate) variant: Option<Variant>, pub(crate) program: &'a Program, pub(crate) program_id: Option<ProgramId>, pub(crate) finalize_caller: Option<Symbol>, pub(crate) next_label: u64, pub(crate) conditional_depth: u64,
}

Fields§

§symbol_table: &'a SymbolTable

The symbol table for the program.

§type_table: &'a TypeTable

A mapping between expressions and their types.

§struct_graph: &'a StructGraph

The struct dependency graph for the program.

§_call_graph: &'a CallGraph

The call graph for the program.

§next_register: u64

A counter to track the next available register.

§current_function: Option<&'a Function>

Reference to the current function.

§variable_mapping: IndexMap<&'a Symbol, String>

Mapping of variables to registers.

§composite_mapping: IndexMap<&'a Symbol, (bool, String)>

Mapping of composite names to a tuple containing metadata associated with the name. The first element of the tuple indicate whether the composite is a record or not. The second element of the tuple is a string modifier used for code generation.

§global_mapping: IndexMap<&'a Symbol, String>

Mapping of global identifiers to their associated names.

§variant: Option<Variant>

The variant of the function we are currently traversing.

§program: &'a Program

A reference to program. This is needed to look up external programs.

§program_id: Option<ProgramId>

The program ID of the current program.

§finalize_caller: Option<Symbol>

A reference to the finalize caller.

§next_label: u64

A counter to track the next available label.

§conditional_depth: u64

The depth of the current conditional block.

Implementations§

source§

impl<'a> CodeGenerator<'a>

source

pub fn new( symbol_table: &'a SymbolTable, type_table: &'a TypeTable, struct_graph: &'a StructGraph, _call_graph: &'a CallGraph, program: &'a Program, ) -> Self

Initializes a new CodeGenerator.

source§

impl<'a> CodeGenerator<'a>

Implement the necessary methods to visit nodes in the AST.

source

pub(crate) fn visit_expression( &mut self, input: &'a Expression, ) -> (String, String)

source

fn visit_identifier(&mut self, input: &'a Identifier) -> (String, String)

source

fn visit_err(&mut self, _input: &'a ErrExpression) -> (String, String)

source

fn visit_value(&mut self, input: &'a Literal) -> (String, String)

source

fn visit_locator(&mut self, input: &'a LocatorExpression) -> (String, String)

source

fn visit_binary(&mut self, input: &'a BinaryExpression) -> (String, String)

source

fn visit_cast(&mut self, input: &'a CastExpression) -> (String, String)

source

fn visit_array(&mut self, input: &'a ArrayExpression) -> (String, String)

source

fn visit_unary(&mut self, input: &'a UnaryExpression) -> (String, String)

source

fn visit_ternary(&mut self, input: &'a TernaryExpression) -> (String, String)

source

fn visit_struct_init(&mut self, input: &'a StructExpression) -> (String, String)

source

fn visit_array_access(&mut self, input: &'a ArrayAccess) -> (String, String)

source

fn visit_member_access(&mut self, input: &'a MemberAccess) -> (String, String)

source

fn visit_associated_constant( &mut self, input: &'a AssociatedConstant, ) -> (String, String)

source

fn visit_associated_function( &mut self, input: &'a AssociatedFunction, ) -> (String, String)

source

fn visit_access(&mut self, input: &'a AccessExpression) -> (String, String)

source

fn visit_call(&mut self, input: &'a CallExpression) -> (String, String)

source

fn visit_tuple(&mut self, input: &'a TupleExpression) -> (String, String)

source

fn visit_unit(&mut self, _input: &'a UnitExpression) -> (String, String)

source§

impl<'a> CodeGenerator<'a>

source

pub(crate) fn visit_program(&mut self, input: &'a Program) -> String

source

fn visit_struct_or_record(&mut self, struct_: &'a Composite) -> String

source

fn visit_struct(&mut self, struct_: &'a Composite) -> String

source

fn visit_record(&mut self, record: &'a Composite) -> String

source

fn visit_function(&mut self, function: &'a Function) -> String

source

fn visit_mapping(&mut self, mapping: &'a Mapping) -> String

source§

impl<'a> CodeGenerator<'a>

source

fn visit_statement(&mut self, input: &'a Statement) -> String

source

fn visit_assert(&mut self, input: &'a AssertStatement) -> String

source

fn visit_return(&mut self, input: &'a ReturnStatement) -> String

source

fn visit_definition(&mut self, _input: &'a DefinitionStatement) -> String

source

fn visit_expression_statement( &mut self, input: &'a ExpressionStatement, ) -> String

source

fn visit_assign(&mut self, input: &'a AssignStatement) -> String

source

fn visit_conditional(&mut self, _input: &'a ConditionalStatement) -> String

source

fn visit_iteration(&mut self, _input: &'a IterationStatement) -> String

source

fn visit_console(&mut self, _: &'a ConsoleStatement) -> String

source

pub(crate) fn visit_block(&mut self, input: &'a Block) -> String

source§

impl<'a> CodeGenerator<'a>

source

pub(crate) fn visit_type(input: &Type) -> String

source

pub(crate) fn visit_type_with_visibility( &self, type_: &'a Type, visibility: Mode, ) -> String

Trait Implementations§

source§

impl<'a> Pass for CodeGenerator<'a>

§

type Input = (&'a Ast, &'a SymbolTable, &'a TypeTable, &'a DiGraph<Symbol>, &'a DiGraph<Symbol>, &'a Program)

§

type Output = Result<String, LeoError>

source§

fn do_pass( (ast, symbol_table, type_table, struct_graph, call_graph, program): Self::Input, ) -> Self::Output

Runs the compiler pass.

Auto Trait Implementations§

§

impl<'a> Freeze for CodeGenerator<'a>

§

impl<'a> !RefUnwindSafe for CodeGenerator<'a>

§

impl<'a> !Send for CodeGenerator<'a>

§

impl<'a> !Sync for CodeGenerator<'a>

§

impl<'a> Unpin for CodeGenerator<'a>

§

impl<'a> !UnwindSafe for CodeGenerator<'a>

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