aboutsummaryrefslogtreecommitdiff
path: root/Intermediate.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Intermediate.hs')
-rw-r--r--Intermediate.hs34
1 files changed, 31 insertions, 3 deletions
diff --git a/Intermediate.hs b/Intermediate.hs
index 5f3a9f2..f97d407 100644
--- a/Intermediate.hs
+++ b/Intermediate.hs
@@ -24,7 +24,7 @@ data IRIns
= IMov Ref Ref
| IStore Ref Ref
| ILoad Ref Ref
- | IAri ArithType Ref Ref
+ | IAri ArithType Ref Ref Ref -- destination, operand 1, operand 2
| ICall Name [Ref]
| ICallr Ref Name [Ref]
| IResize Ref Ref
@@ -56,6 +56,10 @@ refSize (Argument sz _) = sz
refSize (Global sz _) = sz
refSize (Constant sz _) = sz
+isConstant :: Ref -> Bool
+isConstant (Constant _ _) = True
+isConstant _ = False
+
instance Pretty BB where
prettyI i (BB bid inss term) =
@@ -105,8 +109,8 @@ instance Pretty IRIns where
prettyI _ (IMov d s) = "mov " ++ pretty d ++ " <- " ++ pretty s
prettyI _ (IStore d s) = "store *" ++ pretty d ++ " <- " ++ pretty s
prettyI _ (ILoad d s) = "load " ++ pretty d ++ " <- *" ++ pretty s
- prettyI _ (IAri at d s) =
- pretty at ++ " " ++ pretty d ++ ", " ++ pretty s
+ prettyI _ (IAri at d s1 s2) =
+ pretty at ++ " " ++ pretty d ++ " <- " ++ pretty s1 ++ ", " ++ pretty s2
prettyI _ (ICall n al) =
"call " ++ n ++ " (" ++ intercalate ", " (map pretty al) ++ ")"
prettyI _ (ICallr d n al) =
@@ -172,3 +176,27 @@ evaluateCmp ct a b = case ct of
CLt -> a < b
CGeq -> a >= b
CLeq -> a <= b
+
+isCommutative :: ArithType -> Bool
+isCommutative AAdd = True
+isCommutative AMul = True
+isCommutative AAnd = True
+isCommutative AOr = True
+isCommutative AXor = True
+isCommutative AEq = True
+isCommutative ANeq = True
+isCommutative ASub = False
+isCommutative ADiv = False
+isCommutative AMod = False
+isCommutative AGt = False
+isCommutative ALt = False
+isCommutative AGeq = False
+isCommutative ALeq = False
+
+isIMov :: IRIns -> Bool
+isIMov (IMov _ _) = True
+isIMov _ = False
+
+isIAri :: IRIns -> Bool
+isIAri (IAri _ _ _ _) = True
+isIAri _ = False