7162ae6b0aec743e7368f9db7fdac2c18f16e57e
[mate.git] / Mate / RegisterAllocation.hs
1 #include "debug.h"
2 module Mate.RegisterAllocation where
3
4 import Data.List
5 import Data.Maybe
6
7
8 type Label a = a
9 type IEdge a = (Label a, Label a)
10 data IGraph a = IGraph [IEdge a] deriving (Show)
11
12 -- TODO: make IEdge eq
13
14 --data IArchitecture = Arch { regs :: Integer  }
15 type IArchitecture = Int --number of regs
16
17
18 type Assignment a = (a, Int)
19
20
21 edgeEq (from,to) (from',to') = from == from' && to == to' 
22
23
24 -- TODO: find combinator do match try semantics here
25 -- Solution: use list because list is MonadPlus instance
26 -- other solution add maybe monadplus implementation
27 conflicts (IGraph xs) (label,anotherLabel) = 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