# Lib.Terminator module

MIF08, CAP, CFG library - Terminators.

Each `block` of a `CFG` ends with a branching instruction called a terminator. There are three kinds of terminators:

- `Lib.Statement.AbsoluteJump` is a non-conditional jump to another block of the CFG

- `BranchingTerminator` is a conditional branching instruction with two successor blocks. Unlike the class `ConditionalJump` that was used in `LinearCode`, both successor labels have to be specified.

- `Return` marks the end of the function

During the construction of the CFG, `jump2terminator()` builds a terminator for each extracted chunk of instructions.

class Lib.Terminator.Return

  Bases: `Statement`

  A terminator that marks the end of the function.

  printIns(stream)

    Print the statement on the given output. Should never be called on the base class.

  targets() → List[ Label ]

    Return the labels targetted by the Return terminator.

  args() → List[ Operand ]
  rename(renamer: Renamer )
  substitute(subst: Dict[ Operand , Operand ])
  is_read_only()

class Lib.Terminator.BranchingTerminator(cond: Condition, op1: Operand, op2: Operand, label_then: Label, label_else: Label )

  Bases: `Instruction`

  A terminating statement with a condition.

  cond: Condition

    The condition of the branch

  label_then: Label

    The destination label if the condition is true

  label_else: Label

    The destination label if the condition is false

  op1: Operand

    The first operand of the condition

  op2: Operand

    The second operand of the condition

  args() → List[ Operand ]

    List of operands the instruction takes

  targets() → List[ Label ]

    Return the labels targetted by the Branching terminator.

  rename(renamer: Renamer )
  substitute(subst: Dict[ Operand , Operand ])

Lib.Terminator.jump2terminator(j: Lib.Statement.ConditionalJump | Lib.Statement.AbsoluteJump | None, next_label: Lib.Statement.Label | None) → Lib.Terminator.Return | Lib.Statement.AbsoluteJump | Lib.Terminator.BranchingTerminator

  Construct the Terminator associated to the potential jump j to the potential label next_label.