aboutsummaryrefslogtreecommitdiff
path: root/ReplaceRefs.hs
diff options
context:
space:
mode:
Diffstat (limited to 'ReplaceRefs.hs')
-rw-r--r--ReplaceRefs.hs40
1 files changed, 39 insertions, 1 deletions
diff --git a/ReplaceRefs.hs b/ReplaceRefs.hs
index 6e10c90..5886937 100644
--- a/ReplaceRefs.hs
+++ b/ReplaceRefs.hs
@@ -1,8 +1,12 @@
module ReplaceRefs
- (replaceRef, replaceRefsIns, replaceRefsTerm, replaceRefsBB, replaceRefsBBList)
+ (replaceRef, replaceRefsIns, replaceRefsTerm, replaceRefsBB, replaceRefsBBList,
+ findAllRefs, findAllRefsInss, findAllRefsIns, findAllRefsTerm, findAllRefsBBList)
where
+import Data.List
+
import Intermediate
+import Utils
replaceRef :: Ref -> Ref -> Ref -> Ref
@@ -13,6 +17,8 @@ replaceRefsIns from to (IMov a b) = IMov (trans from to a) (trans from to b)
replaceRefsIns from to (ILea a n) = ILea (trans from to a) n
replaceRefsIns from to (IStore a b) = IStore (trans from to a) (trans from to b)
replaceRefsIns from to (ILoad a b) = ILoad (trans from to a) (trans from to b)
+replaceRefsIns from to (ISet a n b) = ISet (trans from to a) n (trans from to b)
+replaceRefsIns from to (IGet a b n) = IGet (trans from to a) (trans from to b) n
replaceRefsIns from to (IAri at a b c) = IAri at (trans from to a) (trans from to b) (trans from to c)
replaceRefsIns from to (ICall n al) = ICall n (map (trans from to) al)
replaceRefsIns from to (ICallr a n al) = ICallr (trans from to a) n (map (trans from to) al)
@@ -40,3 +46,35 @@ trans :: Ref -> Ref -> Ref -> Ref
trans from to ref
| ref == from = to
| otherwise = ref
+
+
+findAllRefs :: BB -> [Ref]
+findAllRefs (BB _ inss _) = findAllRefsInss inss
+
+findAllRefsInss :: [IRIns] -> [Ref]
+findAllRefsInss inss = uniq $ sort $ concatMap findAllRefsIns inss
+
+findAllRefsIns :: IRIns -> [Ref]
+findAllRefsIns (IMov a b) = [a, b]
+findAllRefsIns (ILea a _) = [a]
+findAllRefsIns (IStore a b) = [a, b]
+findAllRefsIns (ILoad a b) = [a, b]
+findAllRefsIns (ISet a _ b) = [a, b]
+findAllRefsIns (IGet a b _) = [a, b]
+findAllRefsIns (IAri _ a b c) = [a, b, c]
+findAllRefsIns (ICall _ al) = al
+findAllRefsIns (ICallr a _ al) = a : al
+findAllRefsIns (IResize a b) = [a, b]
+findAllRefsIns IDebugger = []
+findAllRefsIns INop = []
+
+findAllRefsTerm :: IRTerm -> [Ref]
+findAllRefsTerm (IJcc _ a b _ _) = [a, b]
+findAllRefsTerm (IJmp _) = []
+findAllRefsTerm IRet = []
+findAllRefsTerm (IRetr a) = [a]
+findAllRefsTerm IUnreachable = []
+findAllRefsTerm ITermNone = undefined
+
+findAllRefsBBList :: [BB] -> [Ref]
+findAllRefsBBList = uniq . sort . concatMap findAllRefs