Class ThrowInstr
- All Implemented Interfaces:
INode
Handles both forms of throw statement: - throw Exception("message") - constructor call expression - throw exceptionVariable - variable reference
Key Design: - Terminating instruction (like RETURN) - no code follows in same basic block - Exception object MUST be on stack/in variable before throw - Interacts with CONTROL_FLOW_CHAIN exception handlers for try/catch - Backend generates ATHROW (JVM) or resume (LLVM) instruction - Stack unwinding handled by backend exception mechanism
ARC Semantics: - Exception object should be RETAINED and SCOPE_REGISTERED before throw - THROW transfers ownership to exception mechanism (refcount maintained during unwinding) - CATCH receives ownership without additional RETAIN (clean ownership transfer) - SCOPE_EXIT after THROW is unreachable (backend handles cleanup during unwinding)
-
Method Summary
Modifier and TypeMethodDescriptionaddOperand(String operand) Add operand to this instruction.addOperands(String... operands) Add multiple operands to this instruction.Get the exception object variable to throw.static ThrowInstrthrowException(String exceptionVariable, DebugInfo debugInfo) Create throw instruction with exception object variable and debug info.Methods inherited from class IRInstr
accept, equals, getDebugInfo, getEscapeMetaData, getOpcode, getOperands, getResult, hasEscapeMetaData, hashCode, hasResult, isControlFlow, isLabel, isMemoryManagement, isMethodCall, setEscapeMetaData, toString
-
Method Details
-
throwException
Create throw instruction with exception object variable and debug info. The exception variable must contain a valid Exception or subtype object.- Parameters:
exceptionVariable- The variable containing the exception object to throwdebugInfo- Debug information for source location (used in stack traces)- Returns:
- ThrowInstr instance
-
getExceptionVariable
Get the exception object variable to throw.- Returns:
- Exception variable name, or null if not set
-
addOperand
Description copied from class:IRInstrAdd operand to this instruction.- Overrides:
addOperandin classIRInstr
-
addOperands
Description copied from class:IRInstrAdd multiple operands to this instruction.- Overrides:
addOperandsin classIRInstr
-