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