9fc43ae51d5a4deeb6de6e3ba994e70ae8cfa7dc
[mate.git] / Mate / RegisterAllocation.hs
1 module Mate.RegisterAllocation where
2
3 import Data.List
4 import Data.Maybe
5
6
7 type Label a = a
8 type IEdge a = (Label a, Label a)
9 data IGraph a = IGraph [IEdge a] deriving (Show)
10
11 -- TODO: make IEdge eq
12
13 --data IArchitecture = Arch { regs :: Integer  }
14 type IArchitecture = Int --number of regs
15
16
17 type Assignment a = (a, Int)
18
19
20 edgeEq (from,to) (from',to') = from == from' && to == to' 
21
22
23 -- TODO: find combinator do match try semantics here
24 -- Solution: use list because list is MonadPlus instance
25 -- other solution add maybe monadplus implementation
26 conflicts (IGraph xs) (label,anotherLabel) = let comparison  = edgeEq (label,anotherLabel)
27                                                  comparison' = edgeEq (anotherLabel,label) 
28                                              in isJust (find comparison xs) || isJust (find comparison' xs) 
29
30
31 isParticipiant label (from,to) = from == label || to == label
32
33 count p = length . filter p
34
35 degree g@(IGraph xs) label = count (isParticipiant label) xs
36
37
38 doChaitin81 :: (Eq a) => IArchitecture -> (IGraph a) -> [Assignment a]
39 doChaitin81 numberOfRegisters graph = []
40
41 type IState a = ([a],IGraph a)
42
43 --chait81Simplification :: (Eq a) => IArchitecture -> SimplState
44 --chait81Simplification regs = do (
45                               
46 testGraph = IGraph [("a", "b"), ("a","c"), ("c", "b"), ("b","d"), ("d","c"),("b","e"),("d","e")]
47
48