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: usizeCurrent variable index
Implementations§
Source§impl CodeGenerator
impl CodeGenerator
Sourcepub fn with_config(config: &CompilerConfig) -> Self
pub fn with_config(config: &CompilerConfig) -> Self
Create a new code generator with config
Sourcepub fn push_loop(&mut self, ctx: LoopContext)
pub fn push_loop(&mut self, ctx: LoopContext)
Push a loop context onto the stack
Sourcepub fn pop_loop(&mut self) -> Option<LoopContext>
pub fn pop_loop(&mut self) -> Option<LoopContext>
Pop a loop context from the stack
Sourcepub fn current_loop(&self) -> Option<&LoopContext>
pub fn current_loop(&self) -> Option<&LoopContext>
Get the current loop context (for break/continue)
Sourcepub fn register_variable(&mut self, name: &str) -> usize
pub fn register_variable(&mut self, name: &str) -> usize
Register a new variable and return its index
Sourcepub fn get_variable_index(&self, name: &str) -> Option<usize>
pub fn get_variable_index(&self, name: &str) -> Option<usize>
Get variable index by name
Sourcepub fn reset_variables(&mut self)
pub fn reset_variables(&mut self)
Reset variable table for new function
§impl CodeGenerator
impl CodeGenerator
pub fn generate( &mut self, ast: &AstNode, ) -> Result<CompilationResult, CompilerError>
Source§impl CodeGenerator
impl CodeGenerator
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
impl CodeGenerator
fn generate_assembly_representation(&self, bytecode: &[u8]) -> String
§impl CodeGenerator
impl CodeGenerator
fn generate_source_map(&self, ast: &AstNode) -> String
fn estimate_node_bytecode_size(&self, node: &AstNode) -> usize
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§
Auto Trait Implementations§
impl Freeze for CodeGenerator
impl RefUnwindSafe for CodeGenerator
impl Send for CodeGenerator
impl Sync for CodeGenerator
impl Unpin for CodeGenerator
impl UnwindSafe for CodeGenerator
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
Mutably borrows from an owned value. Read more
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>
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 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>
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