Class AbstractAsmGenerator
- Direct Known Subclasses:
AbstractControlFlowAsmGenerator, BranchInstrAsmGenerator, CallInstrAsmGenerator, ControlFlowChainAsmGenerator, LabelInstrAsmGenerator, LiteralInstrAsmGenerator, MemoryInstrAsmGenerator, ScopeInstrAsmGenerator
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classMetadata for a local variable needed for LocalVariableTable generation.static classShared context for a method that must be coordinated across all generators.(package private) static classScope boundary information for tracking variable lifetimes.(package private) static classRepresents the source of a temp variable for stack-oriented code generation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.objectweb.asm.ClassWriterprotected final ConstructTargetTupleprotected final OutputVisitor -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractAsmGenerator(ConstructTargetTuple constructTargetTuple, OutputVisitor outputVisitor, org.objectweb.asm.ClassWriter classWriter) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidConvert Java primitive boolean on stack to int (0 or 1) via Boolean wrapper.protected StringconvertToJvmDescriptor(String ek9TypeName) Convert EK9 type name to JVM descriptor format.protected StringconvertToJvmName(String ek9FullyQualifiedName) Convert EK9 fully qualified name to JVM internal name format.protected voidgenerateBooleanLiteral(String literalValue) Generate EK9 Boolean literal from string value.protected voidgenerateCharacterLiteral(String literalValue) Generate EK9 Character literal from string value.protected voidgenerateDebugInfo(DebugInfo debugInfo) Generate debug line number from EK9 debug info if available.protected voidgenerateFloatLiteral(String literalValue) Generate EK9 Float literal from string value.protected voidgenerateIntegerLiteral(String literalValue) Generate EK9 Integer literal from string value.protected voidgenerateLoadVariable(String variableName) Generate common JVM instructions for loading a variable.protected voidGenerate LocalVariableTable entries for all variables tracked during method processing.protected StringgenerateMethodDescriptor(List<String> parameterTypes, String returnType) Generate method descriptor from EK9 parameter and return types.protected voidgenerateObjectLiteral(String literalValue, String literalType) Generate EK9 type literal from string value for generic/object types.protected voidgenerateStackOperation(String variableName) Generate stack operation for a variable - either load from slot or re-generate the operation.protected voidgenerateStoreVariable(String variableName) Generate common JVM instructions for storing to a variable.protected voidgenerateStringLiteral(String literalValue) Generate EK9 String literal from string value.protected org.objectweb.asm.MethodVisitorGet the current method visitor.protected AbstractAsmGenerator.MethodContextGet the shared method context.protected org.objectweb.asm.LabelgetOrCreateLabel(String labelName) Get or create JVM Label for IR label name.protected intgetVariableIndex(String variableName) Get or assign local variable slot for a variable name.protected booleanisVariableAllocated(String variableName) Check if a variable has already been allocated a local variable slot.protected voidsetCurrentMethodVisitor(org.objectweb.asm.MethodVisitor methodVisitor) Set the current method visitor for instruction generation.protected voidSet shared method context for coordinated variable slot allocation across generators.protected voidtrackTempVariableFromLiteral(String tempVar, String literalValue, String literalType) Track that a temp variable was created from a literal value.protected voidtrackTempVariableFromLoad(String tempVar, String sourceVar) Track that a temp variable was created from loading another variable.
-
Field Details
-
constructTargetTuple
-
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
-
getMethodContext
Get the shared method context. Provides access to variable maps, label maps, and local variable metadata. -
setCurrentMethodVisitor
protected void setCurrentMethodVisitor(org.objectweb.asm.MethodVisitor methodVisitor) Set the current method visitor for instruction generation. Note: Does NOT reset variable maps - that should be done by the caller if needed. -
getCurrentMethodVisitor
protected org.objectweb.asm.MethodVisitor getCurrentMethodVisitor()Get the current method visitor. -
convertToJvmName
-
convertToJvmDescriptor
-
generateDebugInfo
Generate debug line number from EK9 debug info if available. Creates a JVM Label to mark the bytecode position and associates it with the source line number. -
generateLocalVariableTable
protected void generateLocalVariableTable()Generate LocalVariableTable entries for all variables tracked during method processing. Must be called after method body processing but before visitMaxs().LocalVariableTable enables jdb debugger to show variable names and values via 'locals' command. Each entry maps: variable name + type descriptor + scope (start/end labels) + JVM slot.
Handles two cases: 1. Method parameters: Have REFERENCE but no SCOPE_REGISTER (caller-owned memory) 2. Local variables: Have REFERENCE + SCOPE_REGISTER (callee-owned memory)
-
generateLoadVariable
Generate common JVM instructions for loading a variable. -
generateStoreVariable
Generate common JVM instructions for storing to a variable. In stack-oriented approach, temp variables that will be consumed immediately should not be stored to local variables at all. -
getVariableIndex
Get or assign local variable slot for a variable name. Uses opaque identifier mapping - treats variable names as unique identifiers and assigns sequential slots per method (1, 2, 3, 4, etc.) regardless of the actual name.Example: _temp1 -> slot 1, _temp10 -> slot 2, _temp3 -> slot 3 (in order encountered)
-
isVariableAllocated
Check if a variable has already been allocated a local variable slot. Returns true for method parameters (pre-registered) and already-declared local variables. This is used to distinguish parameters from new local variable declarations. -
getOrCreateLabel
Get or create JVM Label for IR label name. Reuses the same Label object for both label definition (LABEL instruction) and branch targets (BRANCH, BRANCH_TRUE, BRANCH_FALSE instructions). -
trackTempVariableFromLoad
-
trackTempVariableFromLiteral
-
generateStackOperation
Generate stack operation for a variable - either load from slot or re-generate the operation. This is the key method for stack-oriented code generation. -
generateStringLiteral
Generate EK9 String literal from string value. -
generateIntegerLiteral
Generate EK9 Integer literal from string value. -
generateBooleanLiteral
Generate EK9 Boolean literal from string value. -
generateFloatLiteral
Generate EK9 Float literal from string value. -
generateCharacterLiteral
Generate EK9 Character literal from string value. -
generateObjectLiteral
-
generateMethodDescriptor
-
convertBooleanToInt
protected void convertBooleanToInt()Convert Java primitive boolean on stack to int (0 or 1) via Boolean wrapper.Java primitive boolean and int are distinct types in JVM verification. Methods like Boolean._true(), _false(), _set() return primitive boolean, but conditional branch instructions require proper type conversion for verification.
Solution: Use Boolean.valueOf() boxing to convert boolean→Boolean object, then call intValue() from Boolean's Number superclass to get int. This satisfies JVM verifier's type system requirements.
Stack transformation: Pre-condition: [boolean] (primitive boolean type) Post-condition: [int] (primitive int type, value 0 or 1)
Bytecode pattern:
// Stack: [boolean] INVOKESTATIC Boolean.valueOf(Z)LBoolean; // Box to Boolean object INVOKEVIRTUAL Boolean.intValue()I // Unbox to int via Number.intValue() // Stack: [int]