-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflowgraph.sml
43 lines (39 loc) · 1.48 KB
/
flowgraph.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(* flowgraph.sml
*
* Representing flow graphs.
* This code is taken from Andrew Appel's book "Modern Compiler
* Implementation in ML".
*)
structure Flow = struct
structure Graph = Graph
datatype flowgraph =
FGRAPH of
{
(* control: directed graph representing control flow
* from instruction to instruction. (Each graph
* node represents one instruction. *)
control: Graph.graph,
(* def: mapping from graph nodes to sets of variables
* defined at these nodes *)
def: LVar.Set.set Graph.Map.map,
(* use: mapping from graph nodes to sets of variables
* used at these nodes *)
use: LVar.Set.set Graph.Map.map,
(* ismove: mapping from graph nodes to a boolean telling
* whether the corresponding instruction was a
* MOVE *)
ismove: bool Graph.Map.map
}
(* Note: any "use" within the block is assumed to be BEFORE a "def"
of the same variable. If there is a def(x) followed by use(x)
in the same block, do not mention the use in this data structure,
mention only the def.
More generally:
If there are any nonzero number of defs, mention def(x).
If there are any nonzero number of uses BEFORE THE FIRST DEF,
mention use(x).
For any node in the graph,
Graph.Table.look(def,node) = SOME(def-list)
Graph.Table.look(use,node) = SOME(use-list)
*)
end