-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMonotoneFramework.hs
More file actions
57 lines (53 loc) · 1.85 KB
/
MonotoneFramework.hs
File metadata and controls
57 lines (53 loc) · 1.85 KB
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
{-# LANGUAGE GADTs #-}
module MonotoneFramework where
import Ast
import Data.Set (Set, intersection, difference)
import qualified Data.Set as Set
import Data.Map (Map, findWithDefault, (!))
import qualified Data.Map as Map
import AnalysisTools
import Lattice
data MonotoneFramework a where
MonotoneInstance :: AbstractSet a => {
bottom :: a,
order :: a -> a -> Bool,
leastUpperBound :: a -> a -> a,
transferFunction :: Statement -> a -> a,
flowF :: Set FlowElement,
extreLabE :: Set Label,
iota :: a,
bg :: BlockGraph
} -> MonotoneFramework a
data MFP a where
MFP :: {
circle :: Map Label a,
dot :: Map Label a
} -> MFP a
solveMFP :: (AbstractSet a, Eq a) => MonotoneFramework a -> MFP a
solveMFP monotone =
let iterateSolver [] analy = analy
iterateSolver ((Intra l l') : ws) analy =
if not $ new `lessThan` old
then let newWorkList = allFlowStart l' flw ++ ws
newAnalysis = Map.insert l' (new `join` old) analy
in iterateSolver newWorkList newAnalysis
else iterateSolver ws analy
where lStmt = g ! l
new = func lStmt $ findWithDefault bottm l analy
old = findWithDefault bottm l' analy
resultAnalysis = iterateSolver workList initAnalysis
in MFP {
circle = resultAnalysis,
dot = transMany resultAnalysis
}
where flw = flowF monotone
workList = Set.toList flw
--workList = [x | l <- extremalLables ,x <- allFlowStart l flw]
extremalLables = Set.toList $ extreLabE monotone
initAnalysis = Map.fromList $ zip extremalLables $ repeat (iota monotone)
func = transferFunction monotone
g = bg monotone
lessThan = order monotone
bottm = bottom monotone
join = leastUpperBound monotone
transMany = Map.mapWithKey (\k a -> func (g ! k) a)