Class AbstractAsmGenerator

java.lang.Object
org.ek9lang.compiler.backend.jvm.AbstractAsmGenerator
Direct Known Subclasses:
AbstractControlFlowAsmGenerator, AssertThrowsAsmGenerator, BranchInstrAsmGenerator, CallInstrAsmGenerator, CastInstrAsmGenerator, ControlFlowChainAsmGenerator, CoverageFinalizeAsmGenerator, CoverageProbeAsmGenerator, EnumIteratorImplAsmGenerator, LabelInstrAsmGenerator, LiteralInstrAsmGenerator, MemoryInstrAsmGenerator, PrimitiveLiteralAsmGenerator, SanitizeInstrAsmGenerator, ScopeInstrAsmGenerator, StringInterpolationAsmGenerator, ThrowInstrAsmGenerator

abstract class AbstractAsmGenerator extends Object
Common abstract base class for all specialized ASM generators.

Provides shared functionality for JVM bytecode generation including:

  • Access to ClassWriter and current MethodVisitor
  • EK9 to JVM name conversion using existing utilities
  • Debug information handling
  • Common JVM instruction patterns

This class delegates to focused utility classes in the support package:

  • Field Details

    • constructTargetTuple

      protected final ConstructTargetTuple constructTargetTuple
    • outputVisitor

      protected final OutputVisitor outputVisitor
    • classWriter

      protected final org.objectweb.asm.ClassWriter classWriter
  • Constructor Details

    • AbstractAsmGenerator

      protected AbstractAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter)
  • Method Details

    • setSharedMethodContext

      protected void setSharedMethodContext(MethodContext context)
      Set shared method context for coordinated variable slot allocation across generators.
    • getMethodContext

      protected MethodContext getMethodContext()
      Get the shared method context.
    • setCurrentMethodVisitor

      protected void setCurrentMethodVisitor(org.objectweb.asm.MethodVisitor methodVisitor)
      Set the current method visitor for instruction generation.
    • getCurrentMethodVisitor

      protected org.objectweb.asm.MethodVisitor getCurrentMethodVisitor()
      Get the current method visitor.
    • convertToJvmName

      protected String convertToJvmName(String ek9FullyQualifiedName)
      Convert EK9 fully qualified name to JVM internal name format.
    • convertToJvmDescriptor

      protected String convertToJvmDescriptor(String ek9TypeName)
      Convert EK9 type name to JVM descriptor format.
    • generateDebugInfo

      protected void generateDebugInfo(DebugInfo debugInfo)
      Generate debug line number from EK9 debug info if available.
    • generateLocalVariableTable

      protected void generateLocalVariableTable()
      Generate LocalVariableTable entries for all variables tracked during method processing.
    • generateLoadVariable

      protected void generateLoadVariable(String variableName)
      Generate common JVM instructions for loading a variable.
    • generateStoreVariable

      protected void generateStoreVariable(String variableName)
      Generate common JVM instructions for storing to a variable.
    • generateStoreVariableAsInt

      protected void generateStoreVariableAsInt(String variableName)
      Generate JVM instructions for storing a primitive int to a variable.

      Used for INSTANCEOF results and other primitive operations.

    • isFieldAccess

      protected boolean isFieldAccess(String variableName)
      Check if variable name represents field access on 'this'.
    • isVariableFieldAccess

      protected boolean isVariableFieldAccess(String variableName)
      Check if variable name represents field access on another variable.
    • extractFieldName

      protected String extractFieldName(String variableName)
      Extract field name from variable name.
    • getFieldDescriptor

      protected String getFieldDescriptor(String variableName)
      Get field type descriptor for putfield/getfield instructions.
    • getOwnerClassName

      protected String getOwnerClassName()
      Get owner class name for field access.
    • getVariableIndex

      protected int getVariableIndex(String variableName)
      Get or assign local variable slot for a variable name.
    • isVariableAllocated

      protected boolean isVariableAllocated(String variableName)
      Check if a variable has already been allocated a local variable slot.
    • getOrCreateLabel

      protected org.objectweb.asm.Label getOrCreateLabel(String labelName)
      Get or create JVM Label for IR label name.
    • trackTempVariableFromLoad

      protected void trackTempVariableFromLoad(String tempVar, String sourceVar)
      Track that a temp variable was created from loading another variable.
    • trackTempVariableFromLiteral

      protected void trackTempVariableFromLiteral(String tempVar, String literalValue, String literalType)
      Track that a temp variable was created from a literal value.
    • generateStackOperation

      protected void generateStackOperation(String variableName)
      Generate stack operation for a variable.
    • generateStringLiteral

      protected void generateStringLiteral(String literalValue)
      Generate EK9 String literal from string value.
    • generateIntegerLiteral

      protected void generateIntegerLiteral(String literalValue)
      Generate EK9 Integer literal from string value.
    • generateBooleanLiteral

      protected void generateBooleanLiteral(String literalValue)
      Generate EK9 Boolean literal from string value.
    • generateFloatLiteral

      protected void generateFloatLiteral(String literalValue)
      Generate EK9 Float literal from string value.
    • generateCharacterLiteral

      protected void generateCharacterLiteral(String literalValue)
      Generate EK9 Character literal from string value.
    • generateObjectLiteral

      protected void generateObjectLiteral(String literalValue, String literalType)
      Generate EK9 type literal for generic/object types.
    • generateMethodDescriptor

      protected String generateMethodDescriptor(List<String> parameterTypes, String returnType)
      Generate method descriptor from EK9 parameter and return types.