From 64a9292b75d17bccca07137d3981013eadc5c655 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 25 Jan 2008 16:34:18 +0000 Subject: [PATCH] Moved customVarCompare from ArrayUsageCheck to UsageCheck and used it to derive Ord for the Var type --- transformations/ArrayUsageCheck.hs | 6 ++---- transformations/UsageCheck.hs | 10 ++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/transformations/ArrayUsageCheck.hs b/transformations/ArrayUsageCheck.hs index 6225ad4..2be7e89 100644 --- a/transformations/ArrayUsageCheck.hs +++ b/transformations/ArrayUsageCheck.hs @@ -142,6 +142,8 @@ data FlattenedExp | Modulo (Set.Set FlattenedExp) (Set.Set FlattenedExp) | Divide (Set.Set FlattenedExp) (Set.Set FlattenedExp) +--TODO change the A.Variable to Var, and automatically derive Eq and Ord + instance Eq FlattenedExp where a == b = EQ == compare a b @@ -159,10 +161,6 @@ instance Ord FlattenedExp where compare (Divide ltop lbottom) (Divide rtop rbottom) = combineCompare [compare ltop rtop, compare lbottom rbottom] -customVarCompare :: A.Variable -> A.Variable -> Ordering -customVarCompare (A.Variable _ (A.Name _ _ lname)) (A.Variable _ (A.Name _ _ rname)) = compare lname rname --- TODO the rest - onlyConst :: [FlattenedExp] -> Maybe Integer onlyConst [] = Just 0 onlyConst ((Const n):es) = liftM2 (+) (return n) $ onlyConst es diff --git a/transformations/UsageCheck.hs b/transformations/UsageCheck.hs index c60098c..aca5a3d 100644 --- a/transformations/UsageCheck.hs +++ b/transformations/UsageCheck.hs @@ -29,6 +29,16 @@ import Metadata newtype Var = Var A.Variable +customVarCompare :: A.Variable -> A.Variable -> Ordering +customVarCompare (A.Variable _ (A.Name _ _ lname)) (A.Variable _ (A.Name _ _ rname)) = compare lname rname +-- TODO the rest + +instance Eq Var where + a == b = EQ == compare a b + +instance Ord Var where + compare (Var a) (Var b) = customVarCompare a b + data Vars = Vars { readVars :: Set.Set Var ,writtenVars :: Set.Set Var