codegen: handle exceptions of a method
[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) =
27   let comparison  = edgeEq (label,anotherLabel)
28       comparison' = edgeEq (anotherLabel,label)
29   in isJust (find comparison xs) || isJust (find comparison' xs)
30
31
32 isParticipiant label (from,to) = from == label || to == label
33
34 count p = length . filter p
35
36 degree g@(IGraph xs) label = count (isParticipiant label) xs
37
38
39 doChaitin81 :: (Eq a) => IArchitecture -> IGraph a -> [Assignment a]
40 doChaitin81 numberOfRegisters graph = []
41
42 type IState a = ([a],IGraph a)
43
44 --chait81Simplification :: (Eq a) => IArchitecture -> SimplState
45 --chait81Simplification regs = do (
46                               
47 testGraph = IGraph [("a", "b"), ("a","c"), ("c", "b"), ("b","d"), ("d","c"),("b","e"),("d","e")]
48
49