Skip to main content
The IRTermKind type identifies the specific IR operation that an IRTerm represents. Every IRTerm has a kind field of this type, which you can compare against the constants below or test with the corresponding is_* methods. The constants are organized into several categories:
  • Structural: BLOCK, INSN, PHI
  • Statements: ASSIGN, STORE, BRANCH, CBRANCH, CALL, RETURN, SKIP, INTRINSIC
  • Operand expressions: OFFSET, LOCATION, VAR, VAL, LOAD, CAST, EXTRACT, CONCAT, IFELSE, CHOICE, INTRINSIC, NAN
  • Unary operations: NOT, NEG, ABS, SQRT, CEILING, FLOOR, ROUND, POPCOUNT
  • Binary arithmetic: ADD, SUB, MUL, DIV, SDIV, REM, SREM
  • Bitwise and shift: AND, OR, XOR, SHL, SHR, SAR
  • Comparison: EQ, NEQ, LT, LE, SLT, SLE
  • Carry/borrow: CARRY, SCARRY, SBORROW
  • Type-related: TYPE, STRUCT_FIELD, FUNC_ARG, ENUM_VARIANT, UNION_VARIANT

Fields

FieldDescriptionType
BLOCKBlock operation typeIRTermKind
INSNInstruction operation typeIRTermKind
PHIPHI operation typeIRTermKind
ASSIGNAssignment operation typeIRTermKind
STOREStore operation typeIRTermKind
BRANCHBranch operation typeIRTermKind
CBRANCHConditional branch operation typeIRTermKind
CALLCall operation typeIRTermKind
RETURNReturn operation typeIRTermKind
SKIPSkip operation typeIRTermKind
INTRINSICIntrinsic operation typeIRTermKind
OFFSETOffset operation typeIRTermKind
LOCATIONLocation operation typeIRTermKind
VARVariable operation typeIRTermKind
VALValue operation typeIRTermKind
LOADLoad operation typeIRTermKind
CASTCast operation typeIRTermKind
IFELSEIf-else operation typeIRTermKind
EXTRACTExtract operation typeIRTermKind
CONCATConcatenation operation typeIRTermKind
CHOICEChoice operation typeIRTermKind
NANNaN operation typeIRTermKind
NOTNOT operation typeIRTermKind
NEGNegation operation typeIRTermKind
ABSAbsolute value operation typeIRTermKind
SQRTSquare root operation typeIRTermKind
CEILINGCeiling operation typeIRTermKind
FLOORFloor operation typeIRTermKind
ROUNDRound operation typeIRTermKind
POPCOUNTPopulation count operation typeIRTermKind
ANDAND operation typeIRTermKind
OROR operation typeIRTermKind
XORXOR operation typeIRTermKind
ADDAddition operation typeIRTermKind
SUBSubtraction operation typeIRTermKind
DIVDivision operation typeIRTermKind
SDIVSigned division operation typeIRTermKind
MULMultiplication operation typeIRTermKind
REMRemainder operation typeIRTermKind
SREMSigned remainder operation typeIRTermKind
SHLShift left operation typeIRTermKind
SARArithmetic right shift operation typeIRTermKind
SHRLogical right shift operation typeIRTermKind
EQEquality operation typeIRTermKind
NEQInequality operation typeIRTermKind
LTLess than operation typeIRTermKind
LELess than or equal operation typeIRTermKind
SLTSigned less than operation typeIRTermKind
SLESigned less than or equal operation typeIRTermKind
SBORROWSigned borrow operation typeIRTermKind
CARRYCarry operation typeIRTermKind
SCARRYSigned carry operation typeIRTermKind
TYPEType operation typeIRTermKind
STRUCT_FIELDStruct field operation typeIRTermKind
FUNC_ARGFunction argument operation typeIRTermKind
ENUM_VARIANTEnum variant operation typeIRTermKind
UNION_VARIANTUnion variant operation typeIRTermKind

Methods

Each constant has a corresponding is_* method that returns true when the kind matches. For example, kind:is_call() is equivalent to kind == IRTermKind.CALL.
MethodDescriptionParametersReturn Type
is_blockReturns true if kind is BLOCKboolean
is_insnReturns true if kind is INSNboolean
is_phiReturns true if kind is PHIboolean
is_assignReturns true if kind is ASSIGNboolean
is_storeReturns true if kind is STOREboolean
is_branchReturns true if kind is BRANCHboolean
is_cbranchReturns true if kind is CBRANCHboolean
is_callReturns true if kind is CALLboolean
is_returnReturns true if kind is RETURNboolean
is_skipReturns true if kind is SKIPboolean
is_intrinsicReturns true if kind is INTRINSICboolean
is_offsetReturns true if kind is OFFSETboolean
is_locationReturns true if kind is LOCATIONboolean
is_varReturns true if kind is VARboolean
is_valReturns true if kind is VALboolean
is_loadReturns true if kind is LOADboolean
is_castReturns true if kind is CASTboolean
is_ifelseReturns true if kind is IFELSEboolean
is_extractReturns true if kind is EXTRACTboolean
is_concatReturns true if kind is CONCATboolean
is_choiceReturns true if kind is CHOICEboolean
is_nanReturns true if kind is NANboolean
is_notReturns true if kind is NOTboolean
is_negReturns true if kind is NEGboolean
is_absReturns true if kind is ABSboolean
is_sqrtReturns true if kind is SQRTboolean
is_ceilingReturns true if kind is CEILINGboolean
is_floorReturns true if kind is FLOORboolean
is_roundReturns true if kind is ROUNDboolean
is_popcountReturns true if kind is POPCOUNTboolean
is_andReturns true if kind is ANDboolean
is_orReturns true if kind is ORboolean
is_xorReturns true if kind is XORboolean
is_addReturns true if kind is ADDboolean
is_subReturns true if kind is SUBboolean
is_divReturns true if kind is DIVboolean
is_signed_divReturns true if kind is SDIVboolean
is_mulReturns true if kind is MULboolean
is_remReturns true if kind is REMboolean
is_signed_remReturns true if kind is SREMboolean
is_shlReturns true if kind is SHLboolean
is_signed_shrReturns true if kind is SARboolean
is_shrReturns true if kind is SHRboolean
is_eqReturns true if kind is EQboolean
is_neqReturns true if kind is NEQboolean
is_ltReturns true if kind is LTboolean
is_leReturns true if kind is LEboolean
is_signed_ltReturns true if kind is SLTboolean
is_signed_leReturns true if kind is SLEboolean
is_signed_borrowReturns true if kind is SBORROWboolean
is_carryReturns true if kind is CARRYboolean
is_signed_carryReturns true if kind is SCARRYboolean
is_typeReturns true if kind is TYPEboolean
is_struct_fieldReturns true if kind is STRUCT_FIELDboolean
is_function_argumentReturns true if kind is FUNC_ARGboolean
is_enum_variantReturns true if kind is ENUM_VARIANTboolean
is_union_variantReturns true if kind is UNION_VARIANTboolean

Reference

Structural kinds

  • BLOCK: a basic block containing a sequence of instructions.
  • INSN: a single instruction containing one or more statements.
  • PHI: an SSA phi node merging values from different control flow paths.

Statement kinds

  • ASSIGN: an assignment of a value to a variable.
  • STORE: a memory store operation.
  • BRANCH: an unconditional branch (jump) to a target address.
  • CBRANCH: a conditional branch that jumps based on a boolean condition.
  • CALL: a function call.
  • RETURN: a return from the current function.
  • SKIP: a no-op placeholder instruction.
  • INTRINSIC: a built-in operation with no direct IR equivalent. INTRINSIC can also appear as an expression when it produces a value.

Expression kinds

  • VAR: a variable reference. Access the underlying variable via the variable field.
  • VAL: a constant value. Access it via the value field or to_bitvec().
  • LOAD: a memory load operation.
  • OFFSET: an address offset computation.
  • LOCATION: a reference to a specific memory location.
  • CAST: a type cast operation.
  • EXTRACT: extracts a range of bits from a value (see lsb, msb).
  • CONCAT: concatenates two values.
  • IFELSE: a conditional (ternary) expression.
  • CHOICE: a choice between multiple alternative values.
  • INTRINSIC: a built-in operation with no direct IR equivalent. Can also appear as a statement (see above).
  • NAN: a Not-a-Number value.

Unary operations

NOT, NEG, ABS, SQRT, CEILING, FLOOR, ROUND, POPCOUNT are standard unary operations on a single operand.

Binary arithmetic

ADD, SUB, MUL, DIV, SDIV, REM, SREM are arithmetic operations. The S-prefixed variants operate on signed values.

Bitwise, shift, and comparison

  • AND, OR, XOR are bitwise operations.
  • SHL is shift left, SHR is logical (unsigned) shift right, SAR is arithmetic (signed) shift right.
  • EQ, NEQ test equality/inequality. LT, LE are unsigned comparisons. SLT, SLE are signed comparisons.
  • CARRY, SCARRY, SBORROW detect carry and borrow for arithmetic operations.
  • TYPE: a type descriptor term. Use sub_kind to determine the specific type category.
  • STRUCT_FIELD: a field within a struct type.
  • FUNC_ARG: an argument of a function type.
  • ENUM_VARIANT: a variant of an enum type.
  • UNION_VARIANT: a variant of a union type.

Example

-- Check the kind of an IR term
if stmt.kind == IRTermKind.CALL then
  print("Found a call at", stmt.address)
end

-- Using the is_* convenience methods
if stmt.kind:is_assign() then
  print("Found an assignment")
end

-- Filter for all STORE operations in a block
for _, insn in ipairs(block.insns) do
  for _, stmt in ipairs(insn.stmts) do
    if stmt.kind:is_store() then
      print("Store at", stmt.address)
    end
  end
end