Class OutputVisitor

java.lang.Object
org.ek9lang.compiler.backend.jvm.OutputVisitor
All Implemented Interfaces:
INodeVisitor

public final class OutputVisitor extends Object implements INodeVisitor
Enhanced visitor that uses specialized ASM generators to produce JVM bytecode for IR constructs. Implements visitor pattern with typed visit methods for each IR instruction type. Uses single responsibility principle with separate generators for each instruction type.
  • Constructor Summary

    Constructors
    Constructor
    Description
    OutputVisitor(ConstructTargetTuple constructTargetTuple)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Generate LocalVariableTable for the current method.
    void
    setMethodContext(MethodContext methodContext, org.objectweb.asm.MethodVisitor mv, boolean isConstructor)
    Set method context for all generators before processing a method's instructions.
    void
    Entry point for visitors.
    void
    visit(AssertThrowsInstr assertThrowsInstr)
    Typed visit method for AssertThrowsInstr - delegates to specialized generator.
    void
    visit(BranchInstr branchInstr)
    Typed visit method for BranchInstr - delegates to specialized generator.
    void
    visit(CallInstr callInstr)
    Typed visit method for CallInstr - delegates to specialized generator.
    void
    visit(CastInstr castInstr)
    Typed visit method for CastInstr - delegates to specialized generator.
    void
    Typed visit method for ControlFlowChainInstr - delegates to specialized generator.
    void
    visit(CoverageFinalizeInstr coverageFinalizeInstr)
    Typed visit method for CoverageFinalizeInstr - delegates to specialized generator.
    void
    visit(CoverageProbeInstr coverageProbeInstr)
    Typed visit method for CoverageProbeInstr - delegates to specialized generator.
    void
    visit(EnumIteratorImplInstr enumIteratorImplInstr)
    Typed visit method for EnumIteratorImplInstr - delegates to specialized generator.
    void
    Typed visit method for ForRangePolymorphicInstr - delegates to specialized generator.
    void
    visit(IRConstruct construct)
     
    void
    visit(IRInstr irInstr)
    Dispatch IRInstr to typed visit methods.
    void
    visit(LabelInstr labelInstr)
    Typed visit method for LabelInstr - delegates to specialized generator.
    void
    visit(LiteralInstr literalInstr)
    Typed visit method for LiteralInstr - delegates to specialized generator.
    void
    Typed visit method for LogicalOperationInstr - delegates to specialized generator.
    void
    visit(MemoryInstr memoryInstr)
    Typed visit method for MemoryInstr - delegates to specialized generator.
    void
    visit(PrimitiveLiteralInstr primitiveLiteralInstr)
    Typed visit method for PrimitiveLiteralInstr - delegates to specialized generator.
    void
    visit(SanitizeInstr sanitizeInstr)
    Typed visit method for SanitizeInstr - delegates to specialized generator.
    void
    visit(ScopeInstr scopeInstr)
    Typed visit method for ScopeInstr - delegates to specialized generator.
    void
    visit(StringInterpolationInstr stringInterpolationInstr)
    Typed visit method for StringInterpolationInstr - delegates to specialized generator.
    void
    visit(ThrowInstr throwInstr)
    Typed visit method for ThrowInstr - delegates to specialized generator.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface INodeVisitor

    visit, visit, visit, visit
  • Constructor Details

  • Method Details

    • setMethodContext

      public void setMethodContext(MethodContext methodContext, org.objectweb.asm.MethodVisitor mv, boolean isConstructor)
      Set method context for all generators before processing a method's instructions. Must be called before processing each method to ensure proper variable/label management.
      Parameters:
      methodContext - Shared context for variable and label maps
      mv - Method visitor for this specific method
      isConstructor - Whether we're processing a constructor
    • visit

      public void visit()
      Description copied from interface: INodeVisitor
      Entry point for visitors.
      Specified by:
      visit in interface INodeVisitor
    • visit

      public void visit(IRConstruct construct)
      Specified by:
      visit in interface INodeVisitor
    • visit

      public void visit(IRInstr irInstr)
      Dispatch IRInstr to typed visit methods. This is called by IRInstr.accept(visitor) polymorphically.
      Specified by:
      visit in interface INodeVisitor
    • visit

      public void visit(CallInstr callInstr)
      Typed visit method for CallInstr - delegates to specialized generator.
    • visit

      public void visit(LiteralInstr literalInstr)
      Typed visit method for LiteralInstr - delegates to specialized generator.
    • visit

      public void visit(PrimitiveLiteralInstr primitiveLiteralInstr)
      Typed visit method for PrimitiveLiteralInstr - delegates to specialized generator. Handles loading of primitive values (int, boolean, java.lang.String) directly, without creating EK9 wrapper objects.
    • visit

      public void visit(MemoryInstr memoryInstr)
      Typed visit method for MemoryInstr - delegates to specialized generator.
    • visit

      public void visit(ScopeInstr scopeInstr)
      Typed visit method for ScopeInstr - delegates to specialized generator.
    • visit

      public void visit(BranchInstr branchInstr)
      Typed visit method for BranchInstr - delegates to specialized generator.
    • visit

      public void visit(LabelInstr labelInstr)
      Typed visit method for LabelInstr - delegates to specialized generator.
    • visit

      public void visit(ControlFlowChainInstr instr)
      Typed visit method for ControlFlowChainInstr - delegates to specialized generator. Handles all EK9 control flow constructs: question operator, if/else, switch, loops, try/catch.
    • visit

      public void visit(LogicalOperationInstr instr)
      Typed visit method for LogicalOperationInstr - delegates to specialized generator. Handles logical AND/OR operations with short-circuit evaluation.
    • visit

      public void visit(ForRangePolymorphicInstr instr)
      Typed visit method for ForRangePolymorphicInstr - delegates to specialized generator. Handles polymorphic FOR_RANGE loops with runtime direction detection.
    • visit

      public void visit(ThrowInstr throwInstr)
      Typed visit method for ThrowInstr - delegates to specialized generator. Handles THROW operations - generates ATHROW bytecode to throw exceptions.
    • visit

      public void visit(AssertThrowsInstr assertThrowsInstr)
      Typed visit method for AssertThrowsInstr - delegates to specialized generator.
    • visit

      public void visit(CoverageProbeInstr coverageProbeInstr)
      Typed visit method for CoverageProbeInstr - delegates to specialized generator. Generates bytecode to record coverage probe hits.
      Specified by:
      visit in interface INodeVisitor
    • visit

      public void visit(CoverageFinalizeInstr coverageFinalizeInstr)
      Typed visit method for CoverageFinalizeInstr - delegates to specialized generator. Generates bytecode to finalize coverage data and write to files.
      Specified by:
      visit in interface INodeVisitor
    • visit

      public void visit(SanitizeInstr sanitizeInstr)
      Typed visit method for SanitizeInstr - delegates to specialized generator. Generates bytecode to sanitize a String value using InputSanitizer.
    • visit

      public void visit(EnumIteratorImplInstr enumIteratorImplInstr)
      Typed visit method for EnumIteratorImplInstr - delegates to specialized generator. Generates bytecode for enum iterator implementation.
    • visit

      public void visit(CastInstr castInstr)
      Typed visit method for CastInstr - delegates to specialized generator. Generates CHECKCAST bytecode for type casting or INSTANCEOF for type checking.
    • visit

      public void visit(StringInterpolationInstr stringInterpolationInstr)
      Typed visit method for StringInterpolationInstr - delegates to specialized generator. Generates bytecode using StringConcatFactory.makeConcatWithConstants for optimal string concatenation with no intermediate allocations.
    • generateLocalVariableTable

      public void generateLocalVariableTable()
      Generate LocalVariableTable for the current method. Must be called after processing all instructions but before visitMaxs(). Delegates to any generator (they all share the same AbstractAsmGenerator base).