-{-# LANGUAGE ScopedTypeVariables #-}
module ZipCfg
( -- These data types and names are carefully thought out
- BlockId(..) -- ToDo: BlockId should be abstract, but it isn't yet
+ BlockId(..), mkBlockId -- ToDo: BlockId should be abstract, but it isn't yet
, BlockEnv, emptyBlockEnv, lookupBlockEnv, extendBlockEnv, insertBlock, mkBlockEnv
, BlockSet, emptyBlockSet, elemBlockSet, extendBlockSet, mkBlockSet
, Graph(..), LGraph(..), FGraph(..)
, blockId, zip, unzip, last, goto_end, zipht, tailOfLast
, splice_tail, splice_head, splice_head_only', splice_head'
, of_block_list, to_block_list
- , map_nodes
+ , map_blocks, map_nodes, mapM_blocks
, postorder_dfs, postorder_dfs_from, postorder_dfs_from_except
, fold_layout
, fold_blocks
, pprLgraph, pprGraph
- , entry -- exported for the convenience of ZipDataflow, at least for now
+ , entry -- exported for the convenience of ZipDataflow0, at least for now
{-
-- the following functions might one day be useful and can be found
'LastExit' node, and a graph representing a full procedure should not
contain any 'LastExit' nodes. 'LastExit' nodes are used only to splice
graphs together, either during graph construction (see module 'MkZipCfg')
-or during optimization (see module 'ZipDataflow').
+or during optimization (see module 'ZipDataflow0').
A graph is parameterized over the types of middle and last nodes. Each of
these types will typically be instantiated with a subset of C-- statements
map_nodes :: (BlockId -> BlockId) -> (m -> m') -> (l -> l') -> LGraph m l -> LGraph m' l'
-- mapping includes the entry id!
-map_blocks :: (Block m l -> Block m' l') -> LGraph m' l' -> LGraph m' l'
+map_blocks :: (Block m l -> Block m' l') -> LGraph m l -> LGraph m' l'
+mapM_blocks :: Monad mm
+ => (Block m l -> mm (Block m' l')) -> LGraph m l -> mm (LGraph m' l')
-- | These translation functions are speculative. I hope eventually
-- they will be used in the native-code back ends ---NR
tail (ZLast LastExit) = ZLast LastExit
tail (ZLast (LastOther l)) = ZLast (LastOther (last l))
+
+mapM_blocks f (LGraph eid blocks) = blocks' >>= return . LGraph eid
+ where blocks' =
+ foldUFM (\b mblocks -> do { blocks <- mblocks
+ ; b <- f b
+ ; return $ insertBlock b blocks })
+ (return emptyBlockEnv) blocks
+
fold_blocks f z (LGraph _ blocks) = foldUFM f z blocks
of_block_list e blocks = LGraph e $ foldr insertBlock emptyBlockEnv blocks
instance Uniquable BlockId where
getUnique (BlockId u) = u
+mkBlockId :: Unique -> BlockId
+mkBlockId uniq = BlockId uniq
+
instance Show BlockId where
show (BlockId u) = show u