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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
(*
* This module builds a CFG from a stream of instructions.
* We use the FLOWGRPAH_GEN interface here, which is the
* default interface used by the core MLRISC.
*
* -- Allen
*)
functor CFGGen
(structure CFG : CONTROL_FLOW_GRAPH
structure InsnProps : INSN_PROPERTIES
structure MLTree : MLTREE
sharing CFG.I = InsnProps.I
sharing MLTree.Constant = InsnProps.I.Constant
sharing MLTree.PseudoOp = CFG.P
) : FLOWGRAPH_GEN =
struct
structure I = CFG.I
structure C = I.C
structure S = MLTree.Stream
structure T = MLTree
structure P = CFG.P
structure Builder = ControlFlowGraphGen
(structure CFG = CFG
structure Stream = S
structure InsnProps = InsnProps
)
type flowgraph = CFG.cfg
fun newStream{compile,flowgraph} =
let val cfg = ref(case flowgraph of
NONE => CFG.new()
| SOME cfg => cfg
)
val {stream,next} = Builder.builder(!cfg)
val S.STREAM{beginCluster,endCluster,pseudoOp,emit,exitBlock,
getAnnotations,comment,annotation,
defineLabel,entryLabel,...}
= stream
fun endCFG a =
let val _ = endCluster a
val oldCFG = !cfg
val newCFG = CFG.new()
in cfg := newCFG;
next newCFG;
compile oldCFG
end
in S.STREAM{beginCluster = beginCluster,
endCluster = endCFG,
pseudoOp = pseudoOp,
emit = emit,
exitBlock = exitBlock,
comment = comment,
annotation = annotation,
getAnnotations = getAnnotations,
defineLabel = defineLabel,
entryLabel = entryLabel
}
end
end
|