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.
    • callWithTarget

      public void callWithTarget(String targetVariable, CallDetails callDetails)
      Create a call instruction with target variable using current context. Handles void vs non-void returns automatically.
    • callStatic

      public void callStatic(String targetVariable, CallDetails callDetails)
      Create a static call instruction using current context.
    • createFunctionCall

      public CallInstr createFunctionCall(String targetVariable, CallDetailsBuilder.CallDetailsResult callDetailsResult)
      Create a function call with automatic void/non-void handling. Adds promotion instructions and creates the call instruction.
    • callSuperMethod

      public void callSuperMethod(ISymbol superType, String methodName)
      Create a method call to super class constructor or method.
    • callSuperStaticMethod

      public void callSuperStaticMethod(ISymbol superType, String methodName)
      Create a static call to super class initialization method.
    • callThisMethod

      public void callThisMethod(String targetTypeName, String methodName, String targetVariable)
      Create a method call on 'this' object.
    • callThisMethod

      public void callThisMethod(String targetTypeName, String methodName, String targetVariable, DebugInfo debugInfo)
      Create a method call on 'this' object with specific debug info.
    • createBasicBlock

      public BasicBlockInstr createBasicBlock(String labelPrefix)
      Create a BasicBlock with given label and current instructions.
    • 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)
    • returnValue

      public void returnValue(String variableName)
      Return a value using current context debug info.
    • 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.