Class IRInstructionBuilder

java.lang.Object
org.ek9lang.compiler.phase7.generation.IRInstructionBuilder

public class IRInstructionBuilder extends Object
Stateful instruction builder that uses the IR generation context automatically.

This builder eliminates the need for manual BasicDetails construction and scope/debug info management by using the current stack context from IRGenerationContext automatically.

All instruction creation methods use the current scope and debug information from the stack, ensuring consistency and eliminating parameter threading.

  • Constructor Details

    • IRInstructionBuilder

      public IRInstructionBuilder(IRGenerationContext context)
      Create a new instruction builder with stack-based context access. This enables generators to access the current IRContext without parameter threading.
  • Method Details

    • createDebugInfo

      public DebugInfo createDebugInfo(org.antlr.v4.runtime.tree.ParseTree ctx)
    • createDebugInfo

      public DebugInfo createDebugInfo(Ek9Token token)
      Create debug info from a token.
    • createDebugInfo

      public DebugInfo createDebugInfo(org.antlr.v4.runtime.Token token)
      Create debug info from an ANTLR token.
    • createDebugInfo

      public DebugInfo createDebugInfo(IToken token)
      Create debug info from an EK9 IToken.
    • createTempVariable

      public String createTempVariable()
      Create a temporary variable name.
    • createLabel

      public LabelInstr createLabel(String labelPrefix)
      Create a label instruction using current context.
    • loadLiteral

      public void loadLiteral(String variableName, String literalValue, String literalType)
      Load literal instruction using current context.
    • createCall

      public CallInstr createCall(CallContext callContext)
      Create a call instruction using current context.
    • manageVariable

      public void manageVariable(String variableName)
      Create a memory retain and register for memory management current context.
    • getContext

      public IRGenerationContext getContext()
      Get the IRGenerationContext for scope and debug management. This allows helpers to access the stack-based context when needed.
    • getIRContext

      public IRContext getIRContext()
      Get the original IRContext for legacy generator compatibility. This provides access to parsed module, compiler flags, and other context without parameter threading through the call stack.
    • returnVoid

      public void returnVoid()
    • returnValue

      public void returnValue(String variableName, DebugInfo debugInfo)
    • addInstruction

      public void addInstruction(IRInstr instruction)
      Add a raw instruction to the current context.
    • addInstructions

      public void addInstructions(List<IRInstr> instructions)
      Add multiple raw instructions to the current context.
    • extractInstructions

      public List<IRInstr> extractInstructions()
      Extract all built instructions and clear the builder.