Debian Codegraph @

lib/mlrisc-lib/MLRISC/graphs/trace-graph.sml

raw
1 (*
2 * Trace subgraph adaptor. This takes a linear list of node ids.
3 * The view returned is the part of the graph that lies on this linear list.
4 *)
5
6 signature TRACE_SUBGRAPH_VIEW =
7 sig
8
9 val trace_view : Graph.node_id list ->
10 ('n,'e,'g) Graph.graph ->
11 ('n,'e,'g) Graph.graph
12 end
13
14 structure TraceView : TRACE_SUBGRAPH_VIEW =
15 struct
16
17 structure G = Graph
18 structure A = HashArray
19 structure S = Subgraph_P_View
20
21 fun trace_view nodes (G as G.GRAPH g) =
22 let val ord = A.array(#capacity g (),~100)
23 fun order(i,[]) = ()
24 | order(i,n::ns) = (A.update(ord,n,i); order(i+1,ns))
25 val _ = order(0,nodes)
26 fun node_p i = A.sub(ord,i) >= 0
27 fun edge_p (i,j) = A.sub(ord,i) + 1 = A.sub(ord,j)
28 in S.subgraph_p_view nodes node_p edge_p G
29 end
30
31 end
32