0 | module ControlFlow.CBlock
2 | import Data.Singleton
4 | import ControlFlow.CFG
21 | MbPhis : (phi : List lbl -> Type) -> (ins : Neighbors lbl) -> Type
22 | MbPhis phi Nothing = ()
23 | MbPhis phi (Just ins) = List (phi ins)
40 | MbTerm : (term : List lbl -> Type) -> (outs : Neighbors lbl) -> Type
41 | MbTerm term Nothing = ()
42 | MbTerm term (Just outs) = term outs
58 | (phi : List l -> Type)
60 | (terminator : List l -> Type)
63 | (outs : Neighbors l)
73 | theLabel : Singleton lbl
76 | phis : MbPhis phi ins
82 | term : MbTerm terminator outs
88 | emptyCBlock : {lbl : l} -> CBlock phi instr trm lbl Nothing Nothing
89 | emptyCBlock {lbl} = MkBB { theLabel = Val lbl, phis = (), body = [], term = () }
94 | export infixr 7 <++
, <+
95 | export infixr 6 <+|
, |+>
, |++>
96 | export infixr 5 +|
, ++|
104 | : (pre : CBlock phi instr terminator lbl ins Nothing)
105 | -> (post : CBlock phi instr terminator lbl Nothing outs)
106 | -> CBlock phi instr terminator lbl ins outs
116 | { theLabel = theLabel'
125 | , body = (body ++ body')
135 | : (pre : CBlock phi instr trm lbl ins Nothing)
136 | -> (post : List instr)
137 | -> CBlock phi instr trm lbl ins Nothing
138 | (MkBB { theLabel, phis , body , term = () }) <++ instrs
139 | = MkBB { theLabel, phis, body = (body ++ instrs), term = () }
147 | : (pre : CBlock phi instr trm lbl ins Nothing)
149 | -> CBlock phi instr trm lbl ins Nothing
150 | blk <+ instr = blk <++ [instr]
158 | : (pre : CBlock phi instr trm lbl ins Nothing)
159 | -> (post : trm outs)
160 | -> CBlock phi instr trm lbl ins (Just outs)
161 | MkBB { theLabel, phis, body, term = () } <+| term = MkBB { theLabel, phis, body, term }
168 | : (pre : List (phi inputs))
169 | -> (post : CBlock phi instr trm lbl Nothing outs)
170 | -> CBlock phi instr trm lbl (Just inputs) outs
171 | phis |++> MkBB { theLabel, phis = (), body, term }
172 | = MkBB { theLabel, phis, body, term }
179 | : (pre : phi inputs)
180 | -> (post : CBlock phi instr trm lbl Nothing outs)
181 | -> CBlock phi instr trm lbl (Just inputs) outs
182 | instr |+> blk = [instr] |++> blk
189 | : (pre : phi inputs)
190 | -> (post : CBlock phi instr trm lbl (Just inputs) outs)
191 | -> CBlock phi instr trm lbl (Just inputs) outs
192 | instr +| MkBB { theLabel, phis, body, term }
193 | = MkBB { theLabel, phis = instr :: phis, body, term }
200 | : (pre : List (phi inputs))
201 | -> (post : CBlock phi instr trm lbl (Just inputs) outs)
202 | -> CBlock phi instr trm lbl (Just inputs) outs
203 | phis ++| blk = foldl (flip (+|)) blk phis
206 | implementation Connectable (CBlock phi instr terminator) where
213 | emptyCFG : {lbl : l} -> CFG (CBlock phi instr terminatorrt) (Undefined lbl) (Undefined lbl)
214 | emptyCFG = initGraph emptyCBlock