@specs-feup/clava
Version:
A C/C++ source-to-source compiler written in Typescript
191 lines • 6.37 kB
TypeScript
import cytoscape from "cytoscape";
import { Statement } from "../../../Joinpoints.js";
import CfgNodeType from "./CfgNodeType.js";
export default class CfgBuilder {
/**
* AST node to process
*/
private jp;
/**
* Graph being built
*/
private graph;
/**
* Maps stmts to graph nodes
*/
private nodes;
/**
* The start node of the graph
*/
private startNode;
/**
* The end node of the graph
*/
private endNode;
/**
* Maps the astId to the corresponding temporary statement
*/
private temporaryStmts;
/**
* If true, uses deterministic ids for the graph ids (e.g. id_0, id_1...). Otherwise, uses $jp.astId whenever possible.
*/
private deterministicIds;
/**
* Current id, in case deterministic ids are used
*/
private currentId;
/**
* An instance of DataFactory, for creating graph node data
*/
private dataFactory;
/**
* Calculates what node is unconditionally executed after a given statement
*/
private nextNodes;
/**
* If true, each instruction list should be split
*/
private splitInstList;
/**
* If true, the goto nodes should be excluded from the graph
*/
private removeGotoNodes;
/**
* If true, the label nodes should be excluded from the graph
*/
private removeLabelNodes;
/**
* If true, the temporary scope statements should not be removed from the graph
*/
private keepTemporaryScopeStmts;
/**
* Creates a new instance of the CfgBuilder class
* @param $jp -
* @param deterministicIds - If true, uses deterministic ids for the graph ids (e.g. id_0, id_1...). Otherwise, uses $jp.astId whenever possible
* @param options - An object containing configuration options for the cfg
*/
constructor($jp: Statement, deterministicIds?: boolean, options?: {
/**
* If true, statements of each instruction list must be split
*/
splitInstList: boolean;
/**
* If true, the nodes that correspond to goto statements will be excluded from the resulting graph
*/
removeGotoNodes: boolean;
/**
* If true, the nodes that correspond to label statements will be excluded from the resulting graph
*/
removeLabelNodes: boolean;
/**
* If true, the temporary scope statements will be kept in the resulting graph
*/
keepTemporaryScopeStmts: boolean;
});
/**
* Returns the next id that will be used to identify a graph node
*/
private nextId;
/**
* Connects two nodes using a directed edge
* @param source - Starting point from which the edge originates
* @param target - Destination point to which the edge points
* @param edgeType - The edge label that connects
*/
private addEdge;
/**
* Builds the control flow graph
* @returns An array that includes the built graph, the nodes, the start and end nodes
*/
build(): [
cytoscape.Core,
Map<string, cytoscape.NodeSingular>,
cytoscape.NodeSingular,
cytoscape.NodeSingular
];
/**
* Inserts comments that specify the beginning and end of a scope
*/
protected addAuxComments(): void;
/**
* Creates all nodes (except start and end), with only the leader statement
*/
protected createNodes(): void;
/**
* Connects a node associated with a statement that is an instance of a "if" statement.
* @param node - Node whose type is "IF"
*/
private connectIfNode;
/**
* Connects a node associated with a statement that is an instance of a "loop" statement.
* @param node - Node whose type is "LOOP"
*/
private connectLoopNode;
/**
* Connects a node associated with a statement that is part of a loop header and corresponds to the loop condition
* @param node - Node whose type is "COND"
*/
private connectCondNode;
/**
* Connects a node associated with a statement that is an instance of a "break" statement.
* @param node - Node whose type is "BREAK"
*/
private connectBreakNode;
/**
* Connects a node associated with a statement that is an instance of a "continue" statement.
* @param node - Node whose type is "CONTINUE"
*/
private connectContinueNode;
/**
* Connects a node associated with a statement that is an instance of a "switch" statement.
* @param node - Node whose type is "SWITCH"
*/
private connectSwitchNode;
/**
* Connects a node associated with a statement that is an instance of a "case" statement.
* @param node - Node whose type is "CASE"
*/
private connectCaseNode;
/**
* Connects a node associated with a statement that is part of a loop header and corresponds to the loop initialization
* @param node - Node whose type is "INIT"
*/
private connectInitNode;
/**
* Connects a node associated with a statement that is part of a loop header and corresponds to the loop step
* @param node - Node whose type is "STEP"
*/
private connectStepNode;
/**
* @param node - Node whose type is "INST_LIST"
*/
private connectInstListNode;
/**
* @param node - Node whose type is "GOTO"
*/
private connectGotoNode;
/**
* @param node - Node whose type is "LABEL"
*/
private connectLabelNode;
/**
* Connects a node associated with a statement that is an instance of a "return" statement.
* @param node - Node whose type is "RETURN"
*/
private connectReturnNode;
/**
* Connects a node associated with a statement that is an instance of a "scope" statement.
* @param node - Node whose type is "SCOPE", "THEN" or "ELSE"
*/
private connectScopeNode;
/**
* Connects the leader statement nodes according to their type
*/
protected connectNodes(): void;
protected cleanCfg(): void;
/**
* Returns the node corresponding to this statement, or creates a new one if one does not exist yet.
*/
protected getOrAddNode($stmt: Statement, create?: boolean, forceNodeType?: CfgNodeType): cytoscape.NodeSingular;
}
//# sourceMappingURL=CfgBuilder.d.ts.map