CodeGenerator

Struct CodeGenerator 

Source
pub struct CodeGenerator {
    _config: CompilerConfig,
    loop_stack: Vec<LoopContext>,
    variable_table: Vec<VariableInfo>,
    next_var_index: usize,
}
Expand description

Code generator for Yul AST to NeoVM bytecode

Fields§

§_config: CompilerConfig§loop_stack: Vec<LoopContext>

Stack of loop contexts for break/continue resolution

§variable_table: Vec<VariableInfo>

Variable table for tracking local variables

§next_var_index: usize

Current variable index

Implementations§

Source§

impl CodeGenerator

Source

pub fn new() -> Self

Create a new code generator with default loop stack

Source

pub fn with_config(config: &CompilerConfig) -> Self

Create a new code generator with config

Source

pub fn push_loop(&mut self, ctx: LoopContext)

Push a loop context onto the stack

Source

pub fn pop_loop(&mut self) -> Option<LoopContext>

Pop a loop context from the stack

Source

pub fn current_loop(&self) -> Option<&LoopContext>

Get the current loop context (for break/continue)

Source

pub fn register_variable(&mut self, name: &str) -> usize

Register a new variable and return its index

Source

pub fn get_variable_index(&self, name: &str) -> Option<usize>

Get variable index by name

Source

pub fn reset_variables(&mut self)

Reset variable table for new function

§

impl CodeGenerator

pub fn generate( &mut self, ast: &AstNode, ) -> Result<CompilationResult, CompilerError>

Source§

impl CodeGenerator

Source

fn generate_node( &mut self, node: &AstNode, bytecode: &mut Vec<u8>, functions: &mut Vec<FunctionMeta>, events: &mut Vec<String>, estimated_gas: &mut u64, ) -> Result<(), CompilerError>

§

impl CodeGenerator

fn generate_assembly_representation(&self, bytecode: &[u8]) -> String

§

impl CodeGenerator

fn generate_source_map(&self, ast: &AstNode) -> String

fn estimate_node_bytecode_size(&self, node: &AstNode) -> usize

Estimate the bytecode size a node will produce, mirroring the emission logic in node_gen.rs so source map offsets track real bytecode positions.

fn visit_ast_for_source_map( &self, node: &AstNode, source_map: &mut String, offset: usize, )

fn count_ast_nodes(&self, node: &AstNode) -> usize

Trait Implementations§

Source§

impl Default for CodeGenerator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.