Skip to content

Commit

Permalink
Adapt finding by UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Apr 19, 2024
1 parent a2a7445 commit 5d9c761
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 115 deletions.
16 changes: 8 additions & 8 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { sdfg_property_to_string } from '../utils/sdfg/display';
import { memletTreeComplete } from '../utils/sdfg/memlet_trees';
import {
check_and_redirect_edge, deletePositioningInfo, deleteSDFGNodes,
deleteCFGBlocks, find_exit_for_entry, find_graph_element_by_uuid,
deleteCFGBlocks, findExitForEntry, findGraphElementByUUID,
getPositioningInfo, get_uuid_graph_element, findRootCFG
} from '../utils/sdfg/sdfg_utils';
import {
Expand Down Expand Up @@ -1033,7 +1033,7 @@ export class SDFGRenderer extends EventEmitter {
const uuid = get_uuid_graph_element(this.selected_elements[0]);
if (this.graph)
this.sdfv_instance.fill_info(
find_graph_element_by_uuid(this.graph, uuid).element
findGraphElementByUUID(this.cfgList, uuid)
);
}

Expand Down Expand Up @@ -1892,12 +1892,12 @@ export class SDFGRenderer extends EventEmitter {
el_id = error.edge_id;
}
const sdfg_id = error.sdfg_id ?? 0;
const offending_element = find_graph_element_by_uuid(
this.graph, sdfg_id + '/' + state_id + '/' + el_id + '/-1'
const problemElem = findGraphElementByUUID(
this.cfgList, sdfg_id + '/' + state_id + '/' + el_id + '/-1'
);
if (offending_element) {
if (offending_element.element)
this.zoom_to_view([offending_element.element]);
if (problemElem) {
if (problemElem && problemElem instanceof SDFGElement)
this.zoom_to_view([problemElem]);
else
this.zoom_to_view([]);

Expand Down Expand Up @@ -4101,7 +4101,7 @@ function relayoutSDFGState(
if ('is_collapsed' in node.attributes && node.attributes.is_collapsed &&
node.type !== SDFGElementType.NestedSDFG &&
node.type !== SDFGElementType.ExternalNestedSDFG)
node.attributes.layout.out_connectors = find_exit_for_entry(
node.attributes.layout.out_connectors = findExitForEntry(
state.nodes, node
)?.attributes.out_connectors ?? [];
else
Expand Down
4 changes: 2 additions & 2 deletions src/sdfv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ export class SDFV {
this.sidebar_show();
}

public fill_info(elem: SDFGElement): void {
public fill_info(elem: SDFGElement | DagreGraph | null): void {
const contentsRaw = this.sidebar_get_contents();
if (!contentsRaw)
if (!contentsRaw || !elem || !(elem instanceof SDFGElement))
return;
const contents = $(contentsRaw);
contents.html('');
Expand Down
139 changes: 34 additions & 105 deletions src/utils/sdfg/sdfg_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,24 @@ import {
} from '../../index';
import {
Edge,
NestedSDFG,
SDFGElement,
SDFGElementType,
SDFGNode,
State
} from '../../renderer/renderer_elements';

export function recursively_find_graph(
graph: DagreGraph,
graph_id: number,
ns_node: SDFGNode | undefined = undefined
): { graph: DagreGraph | undefined, node: SDFGNode | undefined } {
if (graph.node('0').sdfg.cfg_list_id === graph_id) {
return {
graph: graph,
node: ns_node,
};
} else {
const result = {
graph: undefined,
node: undefined,
};
for (const state_id of graph.nodes()) {
const state = graph.node(state_id);
if (state.data.graph !== undefined && state.data.graph !== null)
for (const node_id of state.data.graph.nodes()) {
const node = state.data.graph.node(node_id);
if (node instanceof NestedSDFG) {
const search_graph = recursively_find_graph(
node.data.graph, graph_id, node
);
if (search_graph.graph !== undefined) {
return search_graph;
}
}
}
}
return result;
}
}


export function find_exit_for_entry(
nodes: JsonSDFGNode[], entry_node: JsonSDFGNode
export function findExitForEntry(
nodes: JsonSDFGNode[], entryNode: JsonSDFGNode
): JsonSDFGNode | null {
for (const n of nodes) {
if (n.type.endsWith('Exit') && n.scope_entry &&
parseInt(n.scope_entry) == entry_node.id)
parseInt(n.scope_entry) == entryNode.id)
return n;
}
console.warn('Did not find corresponding exit');
return null;
}


/**
* Return the string UUID for an SDFG graph element.
*
Expand Down Expand Up @@ -137,74 +100,40 @@ export function check_and_redirect_edge(
return new_edge;
}

export function find_graph_element_by_uuid(
p_graph: DagreGraph | undefined | null, uuid: string
): { parent: DagreGraph | undefined, element: any } {
const uuid_split = uuid.split('/');
console.log('Trying to find:', uuid);

const graph_id = Number(uuid_split[0]);
const state_id = Number(uuid_split[1]);
const node_id = Number(uuid_split[2]);
const edge_id: any = Number(uuid_split[3]);

let result: {
parent: DagreGraph | undefined,
element: any,
} = {
parent: undefined,
element: undefined,
};

if (!p_graph)
return result;
export function findGraphElementByUUID(
cfgList: CFGListType, uuid: string
): SDFGElement | DagreGraph | null {
const uuidParts = uuid.split('/');

let graph = p_graph;
if (graph_id > 0) {
const found_graph = recursively_find_graph(graph, graph_id);
if (found_graph.graph === undefined)
throw new Error();
const cfgId = uuidParts[0];
const stateId = uuidParts[1];
const nodeId = uuidParts[2];
const edgeId = uuidParts[3];

graph = found_graph.graph;
result = {
parent: graph,
element: found_graph.node,
};
}

let state = undefined;
if (state_id !== -1 && graph !== undefined) {
state = graph.node(state_id.toString());
result = {
parent: graph,
element: state,
};
}

if (node_id !== -1 && state !== undefined && state.data.graph !== null) {
// Look for a node in a state.
result = {
parent: state.data.graph,
element: state.data.graph.node(node_id),
};
} else if (
edge_id !== -1 && state !== undefined &&
state.data.graph !== null
) {
// Look for an edge in a state.
result = {
parent: state.data.graph,
element: state.data.graph.edge(edge_id),
};
} else if (edge_id !== -1 && state === undefined) {
// Look for an inter-state edge.
result = {
parent: graph,
element: graph.edge(edge_id),
};
}
if (!(cfgId in cfgList))
return null;

return result;
const graph = cfgList[cfgId].graph;

let state = null;
if (stateId !== '-1' && graph !== undefined)
state = graph.node(stateId);

let element = null;
if (nodeId !== '-1' && state !== null && state.data.graph !== null)
element = state.data.graph.node(nodeId); // SDFG Dataflow graph node
else if (edgeId !== '-1' && state !== null && state.data.graph !== null)
element = state.data.graph.edge(edgeId); // Memlet
else if (edgeId !== '-1' && state === null)
element = graph.edge(edgeId as any); // Interstate edge

if (element)
return element;
if (state)
return state;
if (graph)
return graph;
return null;
}

/**
Expand Down

0 comments on commit 5d9c761

Please sign in to comment.