summaryrefslogtreecommitdiff
path: root/Util.hs
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-11-29 12:01:43 +0100
committertomsmeding <tom.smeding@gmail.com>2019-11-30 10:19:16 +0100
commit5347cb83e730a84fabe162dfc722132cc3ed0f75 (patch)
tree8fc73547c30f66365eb5d48e73ac11e9e302da66 /Util.hs
parentfbe7dbf3b1efe3615f87f0327871ebfd80f1e050 (diff)
WIP push temporaries before calls
Requires liveness analysis
Diffstat (limited to 'Util.hs')
-rw-r--r--Util.hs21
1 files changed, 21 insertions, 0 deletions
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)