Class IRInstr

java.lang.Object
org.ek9lang.compiler.ir.instructions.IRInstr
All Implemented Interfaces:
INode
Direct Known Subclasses:
BranchInstr, CallInstr, ControlFlowChainInstr, GuardedAssignmentBlockInstr, LabelInstr, LiteralInstr, LogicalOperationInstr, MemoryInstr, QuestionOperatorInstr, ScopeInstr

public class IRInstr extends Object implements INode
Base class for all IR instructions in the EK9 intermediate representation.

Each instruction represents a single operation in the target-agnostic IR, which can be translated to JVM bytecode, LLVM IR, or other target formats.

The subclasses from this calls will actually hold the appropriate details accessible via method calls. The idea is not to have to parse or process these operands. Its just very useful to see a human-readable form when debugging and also for testing IR output.

  • Constructor Details

    • IRInstr

      public IRInstr(IROpcode opcode)
      Create instruction with no result (e.g., STORE, BRANCH).
    • IRInstr

      public IRInstr(IROpcode opcode, String result)
      Create instruction with result destination (e.g., LOAD, CALL).
    • IRInstr

      public IRInstr(IROpcode opcode, String result, DebugInfo debugInfo)
      Create instruction with result and debug information.
  • Method Details

    • addOperand

      public IRInstr addOperand(String operand)
      Add operand to this instruction.
    • addOperands

      public IRInstr addOperands(String... operands)
      Add multiple operands to this instruction.
    • getOpcode

      public IROpcode getOpcode()
    • getResult

      public String getResult()
    • getOperands

      public List<String> getOperands()
    • getDebugInfo

      public Optional<DebugInfo> getDebugInfo()
      Get debug information for this instruction.
    • getEscapeMetaData

      public Optional<EscapeMetaDataDetails> getEscapeMetaData()
      Get escape analysis metadata for this instruction.
    • setEscapeMetaData

      public void setEscapeMetaData(EscapeMetaDataDetails escapeMetaData)
      Set escape analysis metadata for this instruction. Should only be called during IR_OPTIMISATION phase.
    • hasEscapeMetaData

      public boolean hasEscapeMetaData()
      Check if this instruction has escape analysis metadata.
    • hasResult

      public boolean hasResult()
      Check if this instruction produces a result value.
    • isMethodCall

      public boolean isMethodCall()
      Check if this instruction is a method call type.
    • isControlFlow

      public boolean isControlFlow()
      Check if this instruction is a control flow type.
    • isMemoryManagement

      public boolean isMemoryManagement()
      Check if this instruction is a memory management type.
    • isLabel

      public boolean isLabel()
      Check if this instruction is a label marker for control flow.
    • accept

      public void accept(INodeVisitor visitor)
      Specified by:
      accept in interface INode
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object