diff --git a/src/renderer/renderer.ts b/src/renderer/renderer.ts index 2f9a50c2..fdc30e82 100644 --- a/src/renderer/renderer.ts +++ b/src/renderer/renderer.ts @@ -3574,6 +3574,10 @@ export class SDFGRenderer extends EventEmitter { return this.sdfg; } + public getCFGList(): CFGListType { + return this.cfgList; + } + public get_graph(): DagreGraph | null { return this.graph; } diff --git a/src/sdfv.ts b/src/sdfv.ts index 3c21fa09..89a0d4b2 100644 --- a/src/sdfv.ts +++ b/src/sdfv.ts @@ -14,11 +14,11 @@ import { Point2D, sdfg_property_to_string, showErrorModal, - traverseSDFGScopes + traverseSDFGScopes, } from './index'; import { LViewRenderer } from './local_view/lview_renderer'; import { - RuntimeMicroSecondsOverlay + RuntimeMicroSecondsOverlay, } from './overlays/runtime_micro_seconds_overlay'; import { OverlayManager } from './overlay_manager'; import { SDFGRenderer } from './renderer/renderer'; @@ -26,10 +26,14 @@ import { AccessNode, Edge, Memlet, NestedSDFG, SDFG, SDFGElement, SDFGNode, - State + State, } from './renderer/renderer_elements'; import { htmlSanitize } from './utils/sanitization'; -import { checkCompatLoad, parse_sdfg, stringify_sdfg } from './utils/sdfg/json_serializer'; +import { + checkCompatLoad, + parse_sdfg, + stringify_sdfg, +} from './utils/sdfg/json_serializer'; import { SDFVSettings } from './utils/sdfv_settings'; declare const vscode: any; @@ -47,7 +51,8 @@ export class SDFV { public static SCOPE_LOD: number = 0.75; // 0.75 // Points-per-pixel threshold for not drawing memlets/interstate edges. public static EDGE_LOD: number = 5.0; // 5.0 - // Points-per-pixel threshold for not drawing Arrowheads of memlets/interstate edges. + // Points-per-pixel threshold for not drawing Arrowheads of + // memlets/interstate edges. public static ARROW_LOD: number = 2.0; // 2.0 // Points-per-pixel threshold for not drawing connectors. public static CONNECTOR_LOD = 2.0; // 2.0 @@ -103,10 +108,11 @@ export class SDFV { else window.getSelection()?.removeAllRanges(); - if (right) + if (right) { right.style.width = Math.max( ((e.view ? e.view.innerWidth - e.pageX : 0)), 20 ) + 'px'; + } }; if (bar) { @@ -169,7 +175,7 @@ export class SDFV { const stack: any[] = [sidebar]; // Add elements to tree view in sidebar - traverseSDFGScopes(sdfg, (node: SDFGNode, parent: DagreGraph) => { + traverseSDFGScopes(sdfg, (node, parent) => { // Skip exit nodes when scopes are known if (node.type().endsWith('Exit') && node.data.node.scope_entry >= 0) { @@ -187,9 +193,8 @@ export class SDFV { // If a scope has children, remove the name "Entry" from the type if (node.type().endsWith('Entry') && node.parent_id && node.id) { const state = node.parentElem?.data.state.nodes[node.parent_id]; - if (state.scope_dict[node.id] !== undefined) { + if (state.scope_dict[node.id] !== undefined) node_type = node_type.slice(0, -5); - } } d.innerHTML = htmlSanitize` @@ -310,7 +315,9 @@ export class SDFV { // If access node, add array information too if (elem instanceof AccessNode) { - const sdfg_array = elem.sdfg.attributes._arrays[elem.attributes().data]; + const sdfg_array = elem.sdfg.attributes._arrays[ + elem.attributes().data + ]; contents.append($('
')); contents.append($('

', { text: sdfg_array.type + ' properties:', @@ -406,30 +413,33 @@ function init_sdfv( }); $('#outline').on('click', () => { const renderer = sdfv.get_renderer(); - if (renderer) + if (renderer) { setTimeout(() => { const graph = renderer.get_graph(); if (graph) sdfv.outline(renderer, graph); }, 1); + } }); $('#search-btn').on('click', () => { const renderer = sdfv.get_renderer(); - if (renderer) + if (renderer) { setTimeout(() => { const graph = renderer.get_graph(); const query = $('#search').val(); - if (graph && query) + if (graph && query) { find_in_graph( sdfv, renderer, graph, query.toString(), $('#search-case').is(':checked') ); + } }, 1); + } }); $('#advsearch-btn').on('click', (e) => { e.preventDefault(); const renderer = sdfv.get_renderer(); - if (renderer) + if (renderer) { setTimeout(() => { const graph = renderer.get_graph(); const code = $('#advsearch').val(); @@ -440,6 +450,7 @@ function init_sdfv( ); } }, 1); + } return false; }); $('#search').on('keydown', (e: any) => { @@ -461,21 +472,23 @@ function init_sdfv( add_btns.push(document.getElementById('elem_access_node')); add_btns.push(document.getElementById('elem_stream')); add_btns.push(document.getElementById('elem_state')); - if (pan_btn) + if (pan_btn) { mode_buttons = { pan: pan_btn, move: move_btn, select: select_btn, add_btns: add_btns, }; + } if (sdfg !== null) { const container = document.getElementById('contents'); - if (container) + if (container) { sdfv.set_renderer(new SDFGRenderer( sdfv, sdfg, container, mouse_event, user_transform, debug_draw, null, mode_buttons )); + } } return sdfv; @@ -483,16 +496,18 @@ function init_sdfv( function start_find_in_graph(sdfv: SDFV): void { const renderer = sdfv.get_renderer(); - if (renderer) + if (renderer) { setTimeout(() => { const graph = renderer.get_graph(); const query = $('#search').val(); - if (graph && query) + if (graph && query) { find_in_graph( sdfv, renderer, graph, query.toString(), $('#search-case').is(':checked') ); + } }, 1); + } } export function reload_file(sdfv: SDFV): void { @@ -511,22 +526,24 @@ function file_read_complete(sdfv: SDFV): void { const info_field = document.getElementById('task-info-field'); if (result_string && container && info_field) { - - // Create the loader element before starting to parse and layout the graph. - // The layouting can take several seconds for large graphs on slow machines. - // The user sees a loading animation in the meantime so that the site doesn't - // appear unresponsive. - // The loader element is removed/cleared again at the end of the layout function in - // the SDFGRenderer. - const loaderDiv = document.createElement("div"); - loaderDiv.classList.add("loader"); + // Create the loader element before starting to parse and layout the + // graph. The layouting can take several seconds for large graphs on + // slow machines. The user sees a loading animation in the meantime so + // that the site doesn't appear unresponsive. The loader element is + // removed/cleared again at the end of the layout function in the + // SDFGRenderer. + const loaderDiv = document.createElement('div'); + loaderDiv.classList.add('loader'); info_field.appendChild(loaderDiv); - // Use setTimeout function to force the browser to reload the dom with the above loader element. + // Use setTimeout function to force the browser to reload the dom with + // the above loader element. setTimeout(() => { const sdfg = checkCompatLoad(parse_sdfg(result_string)); sdfv.get_renderer()?.destroy(); - sdfv.set_renderer(new SDFGRenderer(sdfv, sdfg, container, mouse_event)); + sdfv.set_renderer( + new SDFGRenderer(sdfv, sdfg, container, mouse_event) + ); sdfv.close_menu(); }, 20); } @@ -644,8 +661,10 @@ function getParameterByName(name: string): string | null { name = name.replace(/[\[\]]/g, '\\$&'); const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'), results = regex.exec(url); - if (!results) return null; - if (!results[2]) return ''; + if (!results) + return null; + if (!results[2]) + return ''; return decodeURIComponent(results[2].replace(/\+/g, ' ')); } @@ -683,10 +702,8 @@ function find_recursive( if (predicate(graph, node)) results.push(node); // Enter states or nested SDFGs recursively - if (node.data.graph) { + if (node.data.graph) find_recursive(node.data.graph, predicate, results); - - } } for (const edgeid of graph.edges()) { const edge = graph.edge(edgeid); @@ -696,7 +713,8 @@ function find_recursive( } export function find_in_graph_predicate( - sdfv: SDFV, renderer: SDFGRenderer, sdfg: DagreGraph, predicate: CallableFunction + sdfv: SDFV, renderer: SDFGRenderer, sdfg: DagreGraph, + predicate: CallableFunction ): void { sdfv.sidebar_set_title('Search Results'); @@ -715,7 +733,9 @@ export function find_in_graph_predicate( const d = document.createElement('div'); d.className = 'context_menu_option'; d.innerHTML = htmlSanitize`${result.type()} ${result.label()}`; - d.onclick = () => { renderer.zoom_to_view([result]); }; + d.onclick = () => { + renderer.zoom_to_view([result]); + }; d.onmouseenter = () => { if (!result.highlighted) { result.highlighted = true; @@ -919,7 +939,7 @@ $(() => { vscode; if (vscode) return; - } catch (_) {} + } catch (_) { } // Set the default settings based on the current script's attributes // or URL parameters. @@ -974,7 +994,11 @@ declare global { // Exported functions parse_sdfg: (sdfg_json: string) => JsonSDFG; stringify_sdfg: (sdfg: JsonSDFG) => string; - init_sdfv: (sdfg: JsonSDFG, user_transform?: DOMMatrix | null, debug_draw?: boolean, existing_sdfv?: SDFV | null, toolbar?: boolean, minimap?: boolean | null) => SDFV; + init_sdfv: ( + sdfg: JsonSDFG, user_transform?: DOMMatrix | null, + debug_draw?: boolean, existing_sdfv?: SDFV | null, + toolbar?: boolean, minimap?: boolean | null + ) => SDFV; } } diff --git a/src/utils/sdfg/traversal.ts b/src/utils/sdfg/traversal.ts index 86a5fe93..795b62e7 100644 --- a/src/utils/sdfg/traversal.ts +++ b/src/utils/sdfg/traversal.ts @@ -1,6 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { DagreGraph } from '../../index'; +import { DagreGraph, SDFGNode } from '../../index'; /** * Receives a callback that accepts (node, parent graph) and returns a value. @@ -10,8 +10,8 @@ import { DagreGraph } from '../../index'; * signature as `func`). **/ export function traverseSDFGScopes( - sdfg: DagreGraph, func: CallableFunction, - postSubscopeFunc?: CallableFunction + sdfg: DagreGraph, func: (gNode: SDFGNode, g: DagreGraph) => boolean, + postSubscopeFunc?: (gNode: SDFGNode, g: DagreGraph) => void ): void { function scopesRecursive( graph: DagreGraph, nodes: string[], processedNodes?: Set