Class IRGenerationContext
Each method, operator, function, or program gets its own IRGenerationContext to ensure unique temporary variable names and scope identifiers within that scope.
This prevents conflicts like multiple "_temp1" variables within the same method while allowing parallel processing of different methods/functions.
In general when decomposing EK9 statements/expressions within a processing block we have to use many uniquely named elements. This is so that we can start to use SSA in the IR we generate. So we're taking a big leap from one or a handful of EK9 statements or expressions and expanding them into a larger number of IR statements. This brings opportunities to optimise the IR in a much more significant way - before we get to code generation.
-
Constructor Summary
ConstructorsConstructorDescriptionIRGenerationContext
(ParsedModule parsedModule, CompilerFlags compilerFlags) Create new IR generation context for an executable scope. -
Method Summary
Modifier and TypeMethodDescriptiongenerateBlockLabel
(String prefix) Generate unique basic block label within this context.generateLabelName
(String prefix) Generate unique label name within this context for control flow.generateScopeId
(String prefix) Generate unique scope identifier within this context.Generate unique temporary variable name within this context.int
Get current block counter value (for debugging/testing).Get the compiler flags for debug instrumentation control.Get the parsed module for symbol resolution.int
Get current scope counter value (for debugging/testing).int
Get current temp counter value (for debugging/testing).
-
Constructor Details
-
IRGenerationContext
Create new IR generation context for an executable scope.- Parameters:
parsedModule
- The parsed module containing resolved symbolscompilerFlags
- The compiler flags for controlling debug instrumentation
-
-
Method Details
-
getParsedModule
Get the parsed module for symbol resolution. -
getCompilerFlags
Get the compiler flags for debug instrumentation control. -
generateTempName
Generate unique temporary variable name within this context. Uses underscore prefix to avoid conflicts with EK9 user variables.- Returns:
- Unique temp variable name like "_temp1", "_temp2", etc.
-
generateScopeId
-
generateBlockLabel
-
generateLabelName
Generate unique label name within this context for control flow. Uses underscore prefix to avoid conflicts with EK9 user identifiers.- Parameters:
prefix
- Descriptive prefix for the label.- Returns:
- Unique label like "_var1_unset_1", "_end_label_2", etc.
-
getTempCounter
public int getTempCounter()Get current temp counter value (for debugging/testing). -
getScopeCounter
public int getScopeCounter()Get current scope counter value (for debugging/testing). -
getBlockCounter
public int getBlockCounter()Get current block counter value (for debugging/testing).
-