1 {-# LANGUAGE GADTs, RankNTypes, ScopedTypeVariables, TypeFamilies #-}

3 {-# LANGUAGE Trustworthy #-}

4 #endif

6 -- | Utilities for clients of Hoopl, not used internally.

9 (

10 -- * Utilities for clients

11 distributeFact, distributeFactBwd

12 , successorFacts

13 , joinFacts

15 , joinMaps

16 )

17 where

28 -----------------------------------------------------------------------------

30 -- | Forward dataflow analysis and rewriting for the special case of a Body.

31 -- A set of entry points must be supplied; blocks not reachable from

32 -- the set are thrown away.

33 analyzeAndRewriteFwdBody

35 => FwdPass m n f

39 -- | Backward dataflow analysis and rewriting for the special case of a Body.

40 -- A set of entry points must be supplied; blocks not reachable from

41 -- the set are thrown away.

42 analyzeAndRewriteBwdBody

44 => BwdPass m n f

54 -- ^ Internal utility; should not escape

57 -- if it were not, we would use do-notation here.

61 {-

62 Can't write:

64 do (GMany NothingO body NothingO, fb, NothingO) <- anal (....) f

65 return (body, fb)

67 because we need an explicit type signature in order to do the GADT

68 pattern matches on NothingO

69 -}

73 -- | Forward dataflow analysis and rewriting for the special case of a

74 -- graph open at the entry. This special case relieves the client

75 -- from having to specify a type signature for 'NothingO', which beginners

76 -- might find confusing and experts might find annoying.

77 analyzeAndRewriteFwdOx

81 -- | Backward dataflow analysis and rewriting for the special case of a

82 -- graph open at the entry. This special case relieves the client

83 -- from having to specify a type signature for 'NothingO', which beginners

84 -- might find confusing and experts might find annoying.

85 analyzeAndRewriteBwdOx

89 -- | A value that can be used for the entry point of a graph open at the entry.

90 noEntries :: MaybeC O Label

91 noEntries = NothingC

93 analyzeAndRewriteFwdOx pass g f = analyzeAndRewriteFwd pass noEntries g f

102 -- | A utility function so that a transfer function for a first

103 -- node can be given just a fact; we handle the lookup. This

104 -- function is planned to be made obsolete by changes in the dataflow

105 -- interface.

110 -- | This utility function handles a common case in which a transfer function

111 -- produces a single fact out of a last node, which is then distributed

112 -- over the outgoing edges.

113 distributeXfer :: NonLocal n

115 distributeXfer lattice xfer n f =

119 -- | This utility function handles a common case in which a transfer function

120 -- for a last node takes the incoming fact unchanged and simply distributes

121 -- that fact over the outgoing edges.

124 -- because the same fact goes out on every edge,

125 -- there's no need for 'mkFactBase' here.

127 -- | This utility function handles a common case in which a backward transfer

128 -- function takes the incoming fact unchanged and tags it with the node's label.

132 -- | List of (unlabelled) facts from the successors of a last node

136 -- | Join a list of facts.

141 {-# DEPRECATED joinOutFacts

142 "should be replaced by 'joinFacts lat l (successorFacts n f)'; as is, it uses the wrong Label" #-}

150 -- | It's common to represent dataflow facts as a map from variables

151 -- to some fact about the locations. For these maps, the join

152 -- operation on the map can be expressed in terms of the join on each

153 -- element of the codomain:

156 where