diff --git a/package.json b/package.json index 0a158b7..d25944c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@spcl/sdfv", - "version": "1.3.0", + "version": "1.3.1", "description": "A standalone viewer for SDFGs", "homepage": "https://github.com/spcl/dace-webclient", "main": "out/index.js", diff --git a/src/index.ts b/src/index.ts index fbf84cd..7385b67 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,5 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { SDFGElement } from './renderer/renderer_elements'; - export * from './overlays/memory_volume_overlay'; export * from './overlays/runtime_micro_seconds_overlay'; export * from './overlays/memory_location_overlay'; @@ -26,96 +24,4 @@ export * from './utils/utils'; export * from './overlay_manager'; export * from './sdfv'; export * from './sdfv_ui'; - -export type SymbolMap = { - [symbol: string]: number | undefined, -}; - -export type DagreGraph = dagre.graphlib.Graph; - -export type InvalidSDFGError = { - message: string | undefined, - sdfg_id: number | undefined, - state_id: number | undefined, - node_id: number | undefined, - edge_id: number | undefined, - isedge_id: number | undefined, -}; - -export interface JsonSDFGElement { - attributes?: any, - type: string, -} - -export interface JsonSDFGEdge extends JsonSDFGElement { - dst: string, - dst_connector: string | null, - src: string, - src_connector: string | null, - height: number, - width: number, - x?: number, - y?: number, -} - -export interface JsonSDFGNode extends JsonSDFGElement { - id: number, - label: string, - scope_entry: string | null, - scope_exit: string | null, -} - -export interface JsonSDFGBlock extends JsonSDFGElement { - collapsed?: boolean, - edges?: JsonSDFGEdge[], - nodes?: (JsonSDFGBlock | JsonSDFGNode)[], - id: number, - label: string, -} - -type CodeBlock = { - string_data: string, - language: string, -}; - -export interface JsonSDFGConditionalBlock extends JsonSDFGBlock { - branches: ([CodeBlock | null, JsonSDFGControlFlowRegion])[]; -} - -export interface JsonSDFGControlFlowRegion extends JsonSDFGBlock { - nodes: JsonSDFGBlock[], - edges: JsonSDFGEdge[], - start_block: number, - cfg_list_id: number, -} - -export interface JsonSDFGState extends JsonSDFGBlock { - scope_dict: any, - nodes: JsonSDFGNode[], - edges: JsonSDFGEdge[], -} - -export interface JsonSDFG extends JsonSDFGControlFlowRegion { - error: InvalidSDFGError | undefined, -} - -export type ModeButtons = { - pan: HTMLElement | null, - move: HTMLElement | null, - select: HTMLElement | null, - add_btns: HTMLElement[], -}; - -export type SDFVTooltipFunc = (container: HTMLElement) => void; - -export type Point2D = { - x: number, - y: number, -}; - -export type Size2D = { - w: number, - h: number, -}; - -export type SimpleRect = Point2D & Size2D; +export * from './types'; diff --git a/src/layouter/layout.ts b/src/layouter/layout.ts index af61cf2..88c2288 100644 --- a/src/layouter/layout.ts +++ b/src/layouter/layout.ts @@ -2,42 +2,45 @@ import dagre from 'dagre'; +import { SDFVSettings } from '../utils/sdfv_settings'; +import { SMLayouter } from './state_machine/sm_layouter'; import { - AccessNode, - calculateBoundingBox, - calculateEdgeBoundingBox, - CFGListType, - check_and_redirect_edge, - ConditionalBlock, - Connector, - ControlFlowRegion, - DagreGraph, - deepCopy, - findExitForEntry, - intersectRect, - InterstateEdge, JsonSDFG, JsonSDFGBlock, - JsonSDFGConditionalBlock, JsonSDFGControlFlowRegion, JsonSDFGEdge, JsonSDFGNode, + Point2D, + Size2D, +} from '../types'; +import { + AccessNode, + ConditionalBlock, + Connector, + ControlFlowRegion, + InterstateEdge, LoopRegion, Memlet, NestedSDFG, - Point2D, ScopeNode, SDFG, - sdfg_property_to_string, SDFGElements, SDFGElementType, SDFGNode, - SDFV, - Size2D, State, -} from '..'; -import { SDFVSettings } from '../utils/sdfv_settings'; -import { SMLayouter } from './state_machine/sm_layouter'; +} from '../renderer/renderer_elements'; +import { sdfg_property_to_string } from '../utils/sdfg/display'; +import { SDFV } from '../sdfv'; +import type { CFGListType, DagreGraph } from '../renderer/renderer'; +import { + check_and_redirect_edge, + findExitForEntry, +} from '../utils/sdfg/sdfg_utils'; +import { + calculateBoundingBox, + calculateEdgeBoundingBox, +} from '../utils/bounding_box'; +import { deepCopy, intersectRect } from '../utils/utils'; type CFGBlockInfoT = { label?: string, @@ -270,8 +273,9 @@ function layoutDFNode( node.type === SDFGElementType.ExternalNestedSDFG) { if (node.attributes.sdfg && node.attributes.sdfg.type !== 'SDFGShell') { + const nsdfg = new SDFG(node.attributes.sdfg); nestedGraph = layoutControlFlowRegion( - node.attributes.sdfg, state, ctx, cfgList, stateParentList, + node.attributes.sdfg, nsdfg, ctx, cfgList, stateParentList, omitAccessNodes ); const sdfgInfo = calculateBoundingBox(nestedGraph); diff --git a/src/layouter/state_machine/sm_layouter.ts b/src/layouter/state_machine/sm_layouter.ts index 0b16701..97a4a67 100644 --- a/src/layouter/state_machine/sm_layouter.ts +++ b/src/layouter/state_machine/sm_layouter.ts @@ -1,6 +1,5 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { DagreGraph } from '../..'; import * as dagre from 'dagre'; import { allBackedges } from '../graphlib/algorithms/cycles'; import { @@ -8,6 +7,7 @@ import { immediateDominators, } from '../graphlib/algorithms/dominance'; import { DiGraph } from '../graphlib/di_graph'; +import type { DagreGraph } from '../../renderer/renderer'; /* eslint-disable @typescript-eslint/no-var-requires */ const dagreOrder = require('dagre/lib/order'); diff --git a/src/local_view/lview_parser.ts b/src/local_view/lview_parser.ts index 7eb4cf5..75ad6cf 100644 --- a/src/local_view/lview_parser.ts +++ b/src/local_view/lview_parser.ts @@ -1,7 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. import $ from 'jquery'; -import { DagreGraph, JsonSDFG } from '..'; import { AccessNode, Edge, @@ -28,6 +27,8 @@ import { MemoryNode } from './elements/memory_node'; import { Element } from './elements/element'; import { LViewRenderer } from './lview_renderer'; import { evaluate } from 'mathjs'; +import type { DagreGraph } from '../renderer/renderer'; +import { JsonSDFG } from '../types'; export class LViewGraphParseError extends Error {} diff --git a/src/overlay_manager.ts b/src/overlay_manager.ts index a217fd8..902df7d 100644 --- a/src/overlay_manager.ts +++ b/src/overlay_manager.ts @@ -1,15 +1,15 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. import { MathNode, parse, SymbolNode } from 'mathjs'; -import { Point2D, SymbolMap } from './index'; -import { GenericSdfgOverlay } from './overlays/generic_sdfg_overlay'; -import { +import type { GenericSdfgOverlay } from './overlays/generic_sdfg_overlay'; +import type { GraphElementInfo, SDFGElementGroup, SDFGRenderer, } from './renderer/renderer'; -import { SDFGElement } from './renderer/renderer_elements'; +import type { SDFGElement } from './renderer/renderer_elements'; import { createElement } from './utils/utils'; +import { Point2D, SymbolMap } from './types'; export class SymbolResolver { diff --git a/src/overlays/avg_parallelism_overlay.ts b/src/overlays/avg_parallelism_overlay.ts index 1ebd935..b25371a 100644 --- a/src/overlays/avg_parallelism_overlay.ts +++ b/src/overlays/avg_parallelism_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/depth_overlay.ts b/src/overlays/depth_overlay.ts index 7d3ebf1..43b9a0c 100644 --- a/src/overlays/depth_overlay.ts +++ b/src/overlays/depth_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/diff_overlay.ts b/src/overlays/diff_overlay.ts index b9f5071..4fe3b25 100644 --- a/src/overlays/diff_overlay.ts +++ b/src/overlays/diff_overlay.ts @@ -1,7 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { Point2D } from '../index'; -import { +import type { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -13,6 +12,7 @@ import { ControlFlowBlock, } from '../renderer/renderer_elements'; import { DiffMap } from '../sdfg_diff_viewer'; +import { Point2D } from '../types'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; export class DiffOverlay extends GenericSdfgOverlay { diff --git a/src/overlays/generic_sdfg_overlay.ts b/src/overlays/generic_sdfg_overlay.ts index 9b50901..25c7eca 100644 --- a/src/overlays/generic_sdfg_overlay.ts +++ b/src/overlays/generic_sdfg_overlay.ts @@ -1,12 +1,14 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. import { log, mean, median } from 'mathjs'; -import { DagreGraph, OverlayManager, Point2D, SDFVSettings, SimpleRect, SymbolResolver } from '../index'; -import { +import type { + DagreGraph, GraphElementInfo, SDFGElementGroup, SDFGRenderer, } from '../renderer/renderer'; +import { OverlayManager, SymbolResolver } from '../overlay_manager'; +import { SDFVSettings } from '../utils/sdfv_settings'; import { ConditionalBlock, ControlFlowBlock, @@ -17,6 +19,7 @@ import { SDFGNode, State, } from '../renderer/renderer_elements'; +import { Point2D, SimpleRect } from '../types'; declare const vscode: any; diff --git a/src/overlays/logical_group_overlay.ts b/src/overlays/logical_group_overlay.ts index 07e053f..0da209d 100644 --- a/src/overlays/logical_group_overlay.ts +++ b/src/overlays/logical_group_overlay.ts @@ -1,7 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { Point2D } from '../index'; -import { +import type { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -13,6 +12,7 @@ import { ControlFlowBlock, Edge, } from '../renderer/renderer_elements'; +import { Point2D } from '../types'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; export type LogicalGroup = { diff --git a/src/overlays/memory_location_overlay.ts b/src/overlays/memory_location_overlay.ts index fe56442..cdf4825 100644 --- a/src/overlays/memory_location_overlay.ts +++ b/src/overlays/memory_location_overlay.ts @@ -1,7 +1,6 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { Point2D } from '../index'; -import { +import type { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -11,6 +10,7 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D } from '../types'; import { KELLY_COLORS } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/memory_volume_overlay.ts b/src/overlays/memory_volume_overlay.ts index 7bbeb17..8c94a61 100644 --- a/src/overlays/memory_volume_overlay.ts +++ b/src/overlays/memory_volume_overlay.ts @@ -1,7 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { DagreGraph, Point2D, SymbolMap } from '../index'; -import { +import type { + DagreGraph, GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -15,6 +15,7 @@ import { SDFGElement, State, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/operational_intensity_overlay.ts b/src/overlays/operational_intensity_overlay.ts index 3796d2f..daf37fd 100644 --- a/src/overlays/operational_intensity_overlay.ts +++ b/src/overlays/operational_intensity_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/runtime_micro_seconds_overlay.ts b/src/overlays/runtime_micro_seconds_overlay.ts index 5557016..93245e1 100644 --- a/src/overlays/runtime_micro_seconds_overlay.ts +++ b/src/overlays/runtime_micro_seconds_overlay.ts @@ -1,13 +1,13 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { getGraphElementUUID } from '../index'; -import { SDFGRenderer } from '../renderer/renderer'; +import type { SDFGRenderer } from '../renderer/renderer'; import { ControlFlowBlock, SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; import { getTempColorHslString } from '../utils/utils'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { GenericSdfgOverlay, OverlayType, diff --git a/src/overlays/simulated_operational_intensity_overlay.ts b/src/overlays/simulated_operational_intensity_overlay.ts index dc8a854..407d8a2 100644 --- a/src/overlays/simulated_operational_intensity_overlay.ts +++ b/src/overlays/simulated_operational_intensity_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/overlays/static_flops_overlay.ts b/src/overlays/static_flops_overlay.ts index 903d1eb..8adaa2a 100644 --- a/src/overlays/static_flops_overlay.ts +++ b/src/overlays/static_flops_overlay.ts @@ -1,12 +1,7 @@ // Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. -import { +import type { DagreGraph, - Point2D, - SymbolMap, - getGraphElementUUID, -} from '../index'; -import { GraphElementInfo, SDFGElementGroup, SDFGRenderer, @@ -19,6 +14,8 @@ import { SDFGElement, SDFGNode, } from '../renderer/renderer_elements'; +import { Point2D, SymbolMap } from '../types'; +import { getGraphElementUUID } from '../utils/sdfg/sdfg_utils'; import { getTempColorHslString } from '../utils/utils'; import { GenericSdfgOverlay, OverlayType } from './generic_sdfg_overlay'; diff --git a/src/renderer/canvas_manager.ts b/src/renderer/canvas_manager.ts index 7ad1b26..541df46 100644 --- a/src/renderer/canvas_manager.ts +++ b/src/renderer/canvas_manager.ts @@ -14,8 +14,9 @@ import { getPositioningInfo, initialize_positioning_info, } from '../utils/sdfg/sdfg_utils'; -import { SDFGRenderer, CFGListType } from './renderer'; -import { DagreGraph, intersectRect, Point2D } from '../index'; +import type { SDFGRenderer, CFGListType, DagreGraph } from './renderer'; +import { Point2D } from '../types'; +import { intersectRect } from '../utils/utils'; const animation_duration = 1000; diff --git a/src/renderer/renderer.ts b/src/renderer/renderer.ts index 2f8d4b4..f572483 100644 --- a/src/renderer/renderer.ts +++ b/src/renderer/renderer.ts @@ -4,26 +4,6 @@ import $ from 'jquery'; import dagre from 'dagre'; import EventEmitter from 'events'; -import { - DagreGraph, - JsonSDFG, - JsonSDFGBlock, - JsonSDFGConditionalBlock, - JsonSDFGControlFlowRegion, - JsonSDFGEdge, - JsonSDFGElement, - JsonSDFGNode, - JsonSDFGState, - MemoryLocationOverlay, - MemoryVolumeOverlay, - ModeButtons, - Point2D, - SDFVTooltipFunc, - SimpleRect, - checkCompatSave, - parse_sdfg, - stringify_sdfg, -} from '../index'; import { LViewLayouter } from '../local_view/lview_layouter'; import { LViewGraphParseError, LViewParser } from '../local_view/lview_parser'; import { LViewRenderer } from '../local_view/lview_renderer'; @@ -61,6 +41,23 @@ import { import { cfgToDotGraph } from '../utils/sdfg/dotgraph'; import { layoutSDFG } from '../layouter/layout'; import { GenericSdfgOverlay } from '../overlays/generic_sdfg_overlay'; +import { + JsonSDFG, + JsonSDFGBlock, + JsonSDFGConditionalBlock, + JsonSDFGControlFlowRegion, + JsonSDFGEdge, + JsonSDFGElement, + JsonSDFGNode, + JsonSDFGState, + ModeButtons, + Point2D, + SDFVTooltipFunc, + SimpleRect, +} from '../types'; +import { MemoryLocationOverlay } from '../overlays/memory_location_overlay'; +import { MemoryVolumeOverlay } from '../overlays/memory_volume_overlay'; +import { checkCompatSave, parse_sdfg, stringify_sdfg } from '../utils/sdfg/json_serializer'; // External, non-typescript libraries which are presented as previously loaded // scripts and global javascript variables: @@ -70,6 +67,8 @@ declare const canvas2pdf: any; // Some global functions and variables which are only accessible within VSCode: declare const vscode: any | null; +export type DagreGraph = dagre.graphlib.Graph; + export type SDFGElementGroup = ( 'states' | 'nodes' | 'edges' | 'isedges' | 'connectors' | 'controlFlowRegions' | 'controlFlowBlocks' @@ -582,7 +581,7 @@ export class SDFGRenderer extends EventEmitter { // Overlays menu. if ((!this.enableMaskUI || - this.enableMaskUI.includes('overlays_menu')) && + this.enableMaskUI.includes('overlays_menu')) && !this.in_vscode) { const overlayDropdown = $('
', { class: 'dropdown', @@ -652,7 +651,7 @@ export class SDFGRenderer extends EventEmitter { role: 'group', }).appendTo(this.toolbar); if (!this.enableMaskUI || - this.enableMaskUI.includes('zoom_to_fit_all')) { + this.enableMaskUI.includes('zoom_to_fit_all')) { // Zoom to fit. $('