From 5347cb83e730a84fabe162dfc722132cc3ed0f75 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 29 Nov 2019 12:01:43 +0100 Subject: WIP push temporaries before calls Requires liveness analysis --- Util.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Util.hs (limited to 'Util.hs') diff --git a/Util.hs b/Util.hs new file mode 100644 index 0000000..11b5658 --- /dev/null +++ b/Util.hs @@ -0,0 +1,21 @@ +module Util where + +import qualified Data.Map.Strict as Map + + +uniq :: Eq a => [a] -> [a] +uniq (x:y:zs) | x == y = uniq (y:zs) + | otherwise = x : uniq (y:zs) +uniq l = l + +sortUniq :: Ord a => [a] -> [a] +sortUniq = uniq . sort + +oppositeGraph :: (Show a, Ord a) => Map.Map a [a] -> Map.Map a [a] +oppositeGraph graph = + let nodes = concat [k : vs | (k, vs) <- Map.assocs graph] + edges = map ((,) <$> fst . head <*> map snd) + . groupBy ((==) `on` fst) + . sortOn fst + $ [(to, from) | (from, tos) <- Map.assocs graph, to <- tos] + in Map.fromList (map (,[]) nodes ++ edges) -- cgit v1.2.3-70-g09d2