Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ClavaLaraApi] Adds rankdir option tp Call Graph DOT generation #143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 52 additions & 49 deletions ClavaLaraApi/src-lara-clava/clava/clava/graphs/StaticCallGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,59 @@ laraImport("weaver.Query");
laraImport("clava.graphs.scg.StaticCallGraphBuilder");

class StaticCallGraph extends Graph {
static #dotFormatter = undefined;

// Maps functions to graph nodes
#functions;

constructor(graph, functions) {
super(graph);
this.#functions = functions;
}

/**
*
* @param {$jp} $jp
* @param {boolean} [visitCalls = true] - If true, recursively visits the functions of each call, building a call graph of the available code
* @returns
*/
static build($jp, visitCalls = true) {
const builder = new StaticCallGraphBuilder();

const graph = builder.build($jp, visitCalls);

return new StaticCallGraph(graph, builder.nodes);
}

get functions() {
return this.#functions;
}

getNode($function) {
// Normalize function
return this.#functions[$function.canonical.astId];
}

static get dotFormatter() {
if (StaticCallGraph.#dotFormatter === undefined) {
StaticCallGraph.#dotFormatter = new DotFormatter();
StaticCallGraph.#dotFormatter.addNodeAttribute(
"style=dashed",
(node) => Graphs.isLeaf(node) && !node.data().hasImplementation()
);
StaticCallGraph.#dotFormatter.addNodeAttribute(
"style=filled",
(node) => Graphs.isLeaf(node) && node.data().hasCalls()
);
static #dotFormatter = undefined;

// Maps functions to graph nodes
#functions;

constructor(graph, functions) {
super(graph);
this.#functions = functions;
}

/**
*
* @param {$jp} $jp
* @param {boolean} [visitCalls = true] - If true, recursively visits the functions of each call, building a call graph of the available code
* @returns
*/
static build($jp, visitCalls = true) {
const builder = new StaticCallGraphBuilder();

const graph = builder.build($jp, visitCalls);

return new StaticCallGraph(graph, builder.nodes);
}

get functions() {
return this.#functions;
}

getNode($function) {
// Normalize function
return this.#functions[$function.canonical.astId];
}

return StaticCallGraph.#dotFormatter;
}
static get dotFormatter() {
if (StaticCallGraph.#dotFormatter === undefined) {
StaticCallGraph.#dotFormatter = new DotFormatter();
StaticCallGraph.#dotFormatter.addNodeAttribute(
"style=dashed",
(node) => Graphs.isLeaf(node) && !node.data().hasImplementation()
);
StaticCallGraph.#dotFormatter.addNodeAttribute(
"style=filled",
(node) => Graphs.isLeaf(node) && node.data().hasCalls()
);
}

toDot() {
return super.toDot(StaticCallGraph.dotFormatter);
}
return StaticCallGraph.#dotFormatter;
}

toDot(rankdir = "TB") {
const formatter = StaticCallGraph.dotFormatter;
formatter.setLayoutOption("rankdir", rankdir);

return super.toDot(formatter);
}
}
Loading