Describes the intraprocedural control flow graph (CFG) that corresponds to a function or method within the project.

Constructors

  • Creates an instance of CFG.

    Parameters

    • name: string

      The name of the function or method this CFG represents.

    • id: number

      AST ID.

    • kind: FunctionKind

      Indicates whether this CFG represents a standalone function or a method or a receive method belonging to a contract.

    • origin: EntryOrigin

      Indicates whether the function was defined in users code or in standard library.

    • nodes: BasicBlock[]

      Map of node indices to nodes in the CFG that come in the reverse order.

    • edges: Edge[]

      Map of edge indices to edges in the CFG that come in the reverse order.

    • ref: SrcInfo

      AST reference that corresponds to the function definition.

    • idx: undefined | number = undefined

      An optional unique index. If not set, a new one will be chosen automatically.

    Returns CFG

Properties

edges: Edge[]

Map of edge indices to edges in the CFG that come in the reverse order.

id: number

AST ID.

idx: number

The unique identifier of this CFG among the compilation unit it belongs to.

Indicates whether this CFG represents a standalone function or a method or a receive method belonging to a contract.

name: string

The name of the function or method this CFG represents.

nodes: BasicBlock[]

Map of node indices to nodes in the CFG that come in the reverse order.

origin: EntryOrigin

Indicates whether the function was defined in users code or in standard library.

ref: SrcInfo

AST reference that corresponds to the function definition.

Methods

  • Iterates over all basic blocks in a CFG, applying a callback to each node. The callback can perform any operation, such as analyzing or transforming the node.

    Parameters

    • astStore: TactASTStore

      The store containing the AST nodes.

    • callback: ((stmt: AstStatement, cfgBB: BasicBlock) => void)

      The function to apply to each node.

        • (stmt, cfgBB): void
        • Parameters

          Returns void

    Returns void

  • Iterates over all edges in a CFG, applying a callback to each edge.

    Parameters

    • callback: ((cfgEdge: Edge) => void)

      The function to apply to each edge.

        • (cfgEdge): void
        • Parameters

          Returns void

    Returns void

  • Retrieves a basic block from the CFG based on its unique index.

    Parameters

    • idx: number

      The index of the node to retrieve.

    Returns undefined | BasicBlock

    The basic block if found, otherwise undefined.

  • Retrieves an Edge from the CFG based on its unique index.

    Parameters

    • idx: number

      The index of the edge to retrieve.

    Returns undefined | Edge

    The Edge if found, otherwise undefined.

  • Returns predecessors for the given node.

    Parameters

    • nodeIdx: number

    Returns undefined | BasicBlock[]

    A list of predecessor nodes or undefined if any of the node indexes cannot be found in this CFG.

  • Returns successors for the given node.

    Parameters

    • nodeIdx: number

    Returns undefined | BasicBlock[]

    A list of predecessor nodes or undefined if any of the node indexes cannot be found in this CFG.