Class IRGenerationContext

java.lang.Object
org.ek9lang.compiler.phase7.IRGenerationContext

public final class IRGenerationContext extends Object
Centralized context for IR generation within a single executable scope.

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 Details

    • IRGenerationContext

      public IRGenerationContext(ParsedModule parsedModule, CompilerFlags compilerFlags)
      Create new IR generation context for an executable scope.
      Parameters:
      parsedModule - The parsed module containing resolved symbols
      compilerFlags - The compiler flags for controlling debug instrumentation
  • Method Details

    • getParsedModule

      public ParsedModule getParsedModule()
      Get the parsed module for symbol resolution.
    • getCompilerFlags

      public CompilerFlags getCompilerFlags()
      Get the compiler flags for debug instrumentation control.
    • generateTempName

      public String 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

      public String generateScopeId(String prefix)
      Generate unique scope identifier within this context. Uses underscore prefix to avoid conflicts with EK9 user identifiers.
      Parameters:
      prefix - Descriptive prefix for the scope
      Returns:
      Unique scope ID like "_main_scope_1", "_if_scope_2", etc.
    • generateBlockLabel

      public String generateBlockLabel(String prefix)
      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_2", etc.
    • generateLabelName

      public String generateLabelName(String prefix)
      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).