From 71d1c3b68d5ec3661f53ec43650c93f044ee2dc6 Mon Sep 17 00:00:00 2001 From: Tiago Lascasas Santos Date: Tue, 2 Apr 2024 03:39:31 +0100 Subject: [PATCH] [ClavaLaraApi] Adds rankdir option tp Call Graph DOT generation --- .../clava/clava/graphs/StaticCallGraph.js | 101 +++++++++--------- 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/ClavaLaraApi/src-lara-clava/clava/clava/graphs/StaticCallGraph.js b/ClavaLaraApi/src-lara-clava/clava/clava/graphs/StaticCallGraph.js index bc0835dbf..fa82ea777 100644 --- a/ClavaLaraApi/src-lara-clava/clava/clava/graphs/StaticCallGraph.js +++ b/ClavaLaraApi/src-lara-clava/clava/clava/graphs/StaticCallGraph.js @@ -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); + } }