Package ghidra.pcode.emu.jit.analysis

# Class JitControlFlowModel.JitBlock

java.lang.Object
ghidra.pcode.exec.PcodeProgram
ghidra.pcode.emu.jit.analysis.JitControlFlowModel.JitBlock

Enclosing class:
  `JitControlFlowModel`

public static class JitControlFlowModel.JitBlock extends PcodeProgram
A basic block of p-code

This follows the formal definition of a basic block, but at the p-code level. All flows into the block enter at its first op, and all flows out of the block exit at its last op. The block also contains information about these flows as well as branches out of the passage via this block.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class ghidra.pcode.exec.PcodeProgram

  `PcodeProgram.MyAppender, PcodeProgram.MyFormatter`

- ## Field Summary

  ### Fields inherited from class ghidra.pcode.exec.PcodeProgram

  `code, language, useropNames`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JitBlock(PcodeProgram program, List<PcodeOp> code)`
  Construct a new block

- ## Method Summary

  Modifier and Type
  Method
  Description
  `List<JitPassage.IntBranch>`
  `branchesFrom()`
  Get internal branches leaving this block
  `List<JitPassage.Branch>`
  `branchesOut()`
  Get branches leaving the passage from this block
  `List<JitPassage.IntBranch>`
  `branchesTo()`
  Get internal branches entering this block
  `SequenceNumber`
  `end()`
  Get the sequence number of the last op
  `PcodeOp`
  `first()`
  Get the first p-code op in this block
  `Map<JitPassage.IntBranch,JitControlFlowModel.BlockFlow>`
  `flowsFrom()`
  Get (internal) flows leaving this block
  `Map<JitPassage.IntBranch,JitControlFlowModel.BlockFlow>`
  `flowsTo()`
  Get (internal) flows entering this block
  `JitControlFlowModel.JitBlock`
  `getFallFrom()`
  If this block has fall through, find the block into which it falls
  `protected String`
  `getHead()`
  For display purposes, get the header above the frame, usually the class name
  `JitControlFlowModel.JitBlock`
  `getTargetBlock(JitPassage.IntBranch branch)`
  Get the target block for the given internal branch, assuming it's from this block
  `boolean`
  `hasJumpTo()`
  Check if there is an internal non-fall-through branch to this block
  `int`
  `instructionCount()`
  Get the number of instructions represented in this block
  `SequenceNumber`
  `start()`
  Get the sequence number of the first op
  `String`
  `toString()`
  `int`
  `trailingOpCount()`
  Get the number of trailing ops in this block

  ### Methods inherited from class ghidra.pcode.exec.PcodeProgram

  `execute, format, format, fromInject, fromInstruction, fromInstruction, getCode, getLanguage, getUseropName`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### JitBlock

    public JitBlock(PcodeProgram program, List<PcodeOp> code)
    Construct a new block
    Parameters:
      `program` - the program (i.e., passage) from which this block is derived
      `code` - the subset of ops, in execution order, comprising this block

- ## Method Details

  - ### getHead

    protected String getHead()
    Description copied from class: `PcodeProgram`
    For display purposes, get the header above the frame, usually the class name
    Overrides:
      `getHead` in class `PcodeProgram`
    Returns:
      the frame's display header

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `PcodeProgram`

  - ### first

    public PcodeOp first()
    Get the first p-code op in this block
    Returns:
      the first p-code op

  - ### start

    public SequenceNumber start()
    Get the sequence number of the first op

    This is used for display and testing purposes only.

    Returns:
      the sequence number

  - ### end

    public SequenceNumber end()
    Get the sequence number of the last op

    This is used for display and testing purposes only.

    Returns:
      the sequence number

  - ### flowsFrom

    public Map<JitPassage.IntBranch,JitControlFlowModel.BlockFlow> flowsFrom()
    Get (internal) flows leaving this block
    Returns:
      the flows, keyed by branch

  - ### flowsTo

    public Map<JitPassage.IntBranch,JitControlFlowModel.BlockFlow> flowsTo()
    Get (internal) flows entering this block
    Returns:
      the flows, keyed by branch

  - ### branchesFrom

    public List<JitPassage.IntBranch> branchesFrom()
    Get internal branches leaving this block
    Returns:
      the list of branches

  - ### branchesTo

    public List<JitPassage.IntBranch> branchesTo()
    Get internal branches entering this block
    Returns:
      the list of branches

  - ### branchesOut

    public List<JitPassage.Branch> branchesOut()
    Get branches leaving the passage from this block
    Returns:
      the list of branches

  - ### getFallFrom

    public JitControlFlowModel.JitBlock getFallFrom()
    If this block has fall through, find the block into which it falls
    Returns:
      the block, or `null`

  - ### hasJumpTo

    public boolean hasJumpTo()
    Check if there is an internal non-fall-through branch to this block

    This is used by the `JitCodeGenerator` to determine whether or not a block's bytecode needs to be labeled.

    Returns:
      true if this block is targeted by a branch

  - ### getTargetBlock

    public JitControlFlowModel.JitBlock getTargetBlock(JitPassage.IntBranch branch)
    Get the target block for the given internal branch, assuming it's from this block
    Parameters:
      `branch` - the branch
    Returns:
      the target block or null

  - ### instructionCount

    public int instructionCount()
    Get the number of instructions represented in this block

    This may get dicey as blocks are not necessarily split on instruction boundaries. Nevertheless, we seek to count the number of instructions executed at runtime, so that we can replay an execution, step in reverse, etc. What we actually do here is count the number of ops which are the first op produced by a decoded instruction.

    Returns:
      the instruction count
    See Also:
      - `JitCompiledPassage.count(int, int)`
      - `JitPcodeThread.count(int, int)`

  - ### trailingOpCount

    public int trailingOpCount()
    Get the number of trailing ops in this block

    It is possible a block represents only partial execution of an instruction. Though `instructionCount()` will count this partial instruction, we can tell how far we got into it by examining this value. With this, we should be able to replay an execution to exactly the same p-code op step.

    Returns:
      the trailing op count