Class IRContext
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
ConstructorsConstructorDescriptionIRContext
(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.Get the compiler flags for debug instrumentation control.int
getCounterFor
(String prefix) Get current counter value for a specific prefix (for debugging/testing).Get the parsed module for symbol resolution.int
Get current temp counter value (for debugging/testing).int
Get total number of unique prefixes used (for debugging/testing).
-
Constructor Details
-
IRContext
IRContext(ParsedModule parsedModule, CompilerFlags compilerFlags) 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
Generate unique basic block label within this context. Uses underscore prefix to avoid conflicts with EK9 user identifiers.- Parameters:
prefix
- Descriptive prefix for the block- Returns:
- Unique block label like "_entry_1", "_if_then_1", "_loop_1", etc.
-
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 "_end_1", "_loop_exit_1", "_var_unset_1", etc.
-
getCounterFor
Get current counter value for a specific prefix (for debugging/testing).- Parameters:
prefix
- The prefix to check- Returns:
- Current counter value, or 0 if prefix hasn't been used
-
getTempCounter
public int getTempCounter()Get current temp counter value (for debugging/testing). -
getUniquePrefixCount
public int getUniquePrefixCount()Get total number of unique prefixes used (for debugging/testing).
-