Class IRContext

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

final class IRContext 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

    • IRContext

      IRContext(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 "_param_1", "_return_1", "_scope_1", 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_1", "_loop_1", 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 "_end_1", "_loop_exit_1", "_var_unset_1", etc.
    • getCounterFor

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