From 183e68ee59676e6d0030cb61b929a46df4615c20 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 16 Jan 2008 11:34:56 +0000 Subject: [PATCH] Corrected the display of variables relating to REM --- transformations/ArrayUsageCheck.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/transformations/ArrayUsageCheck.hs b/transformations/ArrayUsageCheck.hs index f50a302..235ee17 100644 --- a/transformations/ArrayUsageCheck.hs +++ b/transformations/ArrayUsageCheck.hs @@ -90,7 +90,9 @@ checkArrayUsage tree = (mapM_ checkPar $ listify (const True) tree) >> return tr showFlattenedExp (Modulo top bottom) = do top' <- showFlattenedExpSet top bottom' <- showFlattenedExpSet bottom - return $ "(" ++ top' ++ " REM " ++ bottom' ++ ")" + case onlyConst (Set.toList bottom) of + Just _ -> return $ "(" ++ top' ++ " / " ++ bottom' ++ ")" + Nothing -> return $ "((" ++ top' ++ " REM " ++ bottom' ++ ") - " ++ top' ++ ")" showFlattenedExp (Divide top bottom) = do top' <- showFlattenedExpSet top bottom' <- showFlattenedExpSet bottom @@ -127,6 +129,12 @@ 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 +onlyConst _ = Nothing + + makeExpSet :: [FlattenedExp] -> Either String (Set.Set FlattenedExp) makeExpSet = foldM makeExpSet' Set.empty where @@ -389,11 +397,6 @@ makeEquations es high = makeEquations' >>* (\(s,v,lh) -> [(s,squareEquations eqI makeEquation' m (Divide top bottom) = throwError "TODO Divide" - onlyConst :: [FlattenedExp] -> Maybe Integer - onlyConst [] = Just 0 - onlyConst ((Const n):es) = liftM2 (+) (return n) $ onlyConst es - onlyConst _ = Nothing - empty :: [(Map.Map Int Integer,[Map.Map Int Integer], [Map.Map Int Integer])] empty = [(Map.empty,[],[])]