Class IRInstructionBuilder
java.lang.Object
org.ek9lang.compiler.phase7.generation.IRInstructionBuilder
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 Summary
ConstructorsConstructorDescriptionIRInstructionBuilder(IRGenerationContext context) Create a new instruction builder with stack-based context access. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddInstruction(IRInstr instruction) Add a raw instruction to the current context.voidaddInstructions(List<IRInstr> instructions) Add multiple raw instructions to the current context.voidcallInstanceInit(ISymbol constructType, DebugInfo debugInfo) voidcallStatic(String targetVariable, CallDetails callDetails) Create a static call instruction using current context.voidcallSuperClassInit(ISymbol superType) THE call of a super type's_c_init(class initialisation) from a construct's own, into the fixedIRConstants.TEMP_C_INIT, with the current frame's debug info.voidcallSuperConstructor(ISymbol superType) AddsuperConstructorCall(ISymbol, DebugInfo)with the current frame's debug info.voidcallWithTarget(String targetVariable, CallDetails callDetails) Create a call instruction with target variable using current context.createBasicBlock(String labelPrefix) Create a BasicBlock with given label and current instructions.createDebugInfo(org.antlr.v4.runtime.Token token) Create debug info from an ANTLR token.createDebugInfo(org.antlr.v4.runtime.tree.ParseTree ctx) createDebugInfo(Ek9Token token) Create debug info from a token.createDebugInfo(IToken token) Create debug info from an EK9 IToken.Create a temporary variable name.Extract all built instructions and clear the builder.Get the IRGenerationContext for scope and debug management.voidinitializeEnumConstant(ISymbol enumType, String constantName, int ordinal) Initialize an enum constant static field.voidinNewScope(DebugInfo debugInfo, Consumer<String> body) THE scoped body for code built through this builder (INFRA-1): a fresh scope id, pushed on the stack, SCOPE_ENTER, whateverbodyadds (it is handed the scope id), SCOPE_EXIT, popped.instanceInitCall(ISymbol constructType, DebugInfo debugInfo) THE call of a construct's own_i_init- its field initialisers - from a constructor, synthetic or written (IR tidy W3.4, OPS-2/MONO-14); use this, never a hand-builtCallDetails.voidloadLiteral(String variableName, String literalValue, String literalType) Load literal instruction using current context.voidCreate a memory retain only (no scope register).voidretainAndRegister(String variableName) Create a memory retain and scope register for memory management using current context.voidreturnValue(String variableName) Return a value using current context debug info.voidreturnValue(String variableName, DebugInfo debugInfo) voidvoidscopeRegister(String variableName) Create a scope register only (NO retain) for a +1 producer temp.superConstructorCall(ISymbol superType, DebugInfo debugInfo) THE implicit super-constructor call (super.<init>()) of a constructor, synthetic or written (IR tidy W3.4, OPS-2/MONO-14) - use this, never a hand-builtCallDetails.
-
Constructor Details
-
IRInstructionBuilder
Create a new instruction builder with stack-based context access. This enables generators to access the current IRContext without parameter threading.
-
-
Method Details
-
createDebugInfo
-
createDebugInfo
-
createDebugInfo
Create debug info from an ANTLR token. -
createDebugInfo
-
createTempVariable
Create a temporary variable name. -
loadLiteral
-
callWithTarget
Create a call instruction with target variable using current context. Handles void vs non-void returns automatically. -
callStatic
Create a static call instruction using current context. -
superConstructorCall
THE implicit super-constructor call (super.<init>()) of a constructor, synthetic or written (IR tidy W3.4, OPS-2/MONO-14) - use this, never a hand-builtCallDetails. Named throughIRGenerationContext.resolveTypeName(ISymbol)(the identity outside a monomorphisation), metadata of the super's no-argument constructor fromSynthesisedCallMetaData, the result into the fixedIRConstants.TEMP_SUPER_INIT.debugInfonull means the current frame's. -
callSuperConstructor
AddsuperConstructorCall(ISymbol, DebugInfo)with the current frame's debug info. -
instanceInitCall
THE call of a construct's own_i_init- its field initialisers - from a constructor, synthetic or written (IR tidy W3.4, OPS-2/MONO-14); use this, never a hand-builtCallDetails._i_initreturns nothing, so nothing receives the result.debugInfonull means the current frame's. -
callInstanceInit
-
callSuperClassInit
THE call of a super type's_c_init(class initialisation) from a construct's own, into the fixedIRConstants.TEMP_C_INIT, with the current frame's debug info. -
createBasicBlock
Create a BasicBlock with given label and current instructions. -
retainAndRegister
Create a memory retain and scope register for memory management using current context. Standard ARC pattern: RETAIN (increment refcount) + SCOPE_REGISTER (register for cleanup at scope exit). -
scopeRegister
Create a scope register only (NO retain) for a +1 producer temp. A producer result (CALL / constructor / factory / LOAD_LITERAL) is already handed back at +1, so it only needs SCOPE_REGISTER — the scope-exit release balances that +1 and frees it. Use this, NOTretainAndRegister(String), for producer temps: an extra RETAIN leaves the object at +1 after the release, which is the B1-class generated-body ARC leak (no-op on the JVM). ReserveretainAndRegisterfor BORROWED values (e.g. LOAD_FIELD) the scope must keep alive. -
retain
Create a memory retain only (no scope register). Used for ownership transfer: the variable's refcount is incremented but not registered for scope-based cleanup because ownership transfers to an external entity (e.g., static field on _Application, return value to caller). -
getContext
Get the IRGenerationContext for scope and debug management. This allows helpers to access the stack-based context when needed. -
returnVoid
public void returnVoid() -
returnValue
-
returnValue
Return a value using current context debug info. -
initializeEnumConstant
Initialize an enum constant static field.Creates a new enum instance, sets its _ordinal, _name, and _isEnumSet fields, then stores it to the static field on the enum class.
- Parameters:
enumType- The enum type SYMBOL - names the target and supplies the constructor metadataconstantName- The constant field name (e.g., "Red")ordinal- The ordinal value (0-based position)
-
addInstruction
Add a raw instruction to the current context. -
inNewScope
THE scoped body for code built through this builder (INFRA-1): a fresh scope id, pushed on the stack, SCOPE_ENTER, whateverbodyadds (it is handed the scope id), SCOPE_EXIT, popped. Exactly the hand-rolled sequence, so anything the body generates (scope ids, temps, labels) is numbered after the scope's own id as it always was. The list-returning twin isScopedInstructionExecutor.executeWithScopeId. -
addInstructions
-
extractInstructions
-