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: FunctionName

      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: ItemOrigin

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

    • nodes: BasicBlock[]

      Map of block indices to basic blocks 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 | CFGIdx = 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: CFGIdx

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.

The name of the function or method this CFG represents.

nodes: BasicBlock[]

Map of block indices to basic blocks in the CFG that come in the reverse order.

origin: ItemOrigin

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 basic block.

    Parameters

    • astStore: TactASTStore

      The store containing the AST nodes.

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

      The function to apply to each block.

        • (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 an Edge from the CFG based on its unique index.

    Parameters

    • idx: EdgeIdx

      The index of the edge to retrieve.

    Returns undefined | Edge

    The Edge if found, otherwise undefined.