From d20b113a00bfd5269ec2d05a8abe33fdd59bfc95 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Wed, 25 Apr 2007 21:24:20 +0000 Subject: [PATCH] Generate AFTER using > and MINUS --- fco2/GenerateC.hs | 1 - fco2/SimplifyExprs.hs | 18 ++++++++++++++++++ fco2/fco_support.h | 13 ------------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fco2/GenerateC.hs b/fco2/GenerateC.hs index e9b7476..965b9fc 100644 --- a/fco2/GenerateC.hs +++ b/fco2/GenerateC.hs @@ -440,7 +440,6 @@ genDyadic _ A.Less e f = genSimpleDyadic "<" e f genDyadic _ A.More e f = genSimpleDyadic ">" e f genDyadic _ A.LessEq e f = genSimpleDyadic "<=" e f genDyadic _ A.MoreEq e f = genSimpleDyadic ">=" e f -genDyadic m A.After e f = genFuncDyadic m "after" e f --}}} --{{{ input/output items diff --git a/fco2/SimplifyExprs.hs b/fco2/SimplifyExprs.hs index 4f1f346..2078275 100644 --- a/fco2/SimplifyExprs.hs +++ b/fco2/SimplifyExprs.hs @@ -16,6 +16,7 @@ simplifyExprs = runPasses passes where passes = [ ("Convert FUNCTIONs to PROCs", functionsToProcs) + , ("Convert AFTER to MINUS", removeAfter) , ("Pull up definitions", pullUp) ] @@ -54,6 +55,23 @@ functionsToProcs = doGeneric `extM` doSpecification vpToProc (A.ValOfSpec m s vp) vs = A.ProcSpec m s (vpToProc vp vs) vpToProc (A.ValOf m p el) vs = A.Seq m [p, A.Assign m vs el] +-- | Convert AFTER expressions to the equivalent using MINUS (which is how the +-- occam 3 manual defines AFTER). +removeAfter :: Data t => t -> PassM t +removeAfter = doGeneric `extM` doExpression + where + doGeneric :: Data t => t -> PassM t + doGeneric = gmapM removeAfter + + doExpression :: A.Expression -> PassM A.Expression + doExpression (A.Dyadic m A.After a b) + = do a' <- removeAfter a + b' <- removeAfter b + t <- typeOfExpression a' + let zero = A.ExprLiteral m $ A.Literal m t $ A.IntLiteral m "0" + return $ A.Dyadic m A.More (A.Dyadic m A.Minus a' b') zero + doExpression e = doGeneric e + -- | Find things that need to be moved up to their enclosing process, and do -- so. pullUp :: Data t => t -> PassM t diff --git a/fco2/fco_support.h b/fco2/fco_support.h index bc77dcd..e994e08 100644 --- a/fco2/fco_support.h +++ b/fco2/fco_support.h @@ -100,11 +100,6 @@ static int occam_check_index (int i, int limit, const char *pos) { } \ return a % b; \ } -#define MAKE_AFTER(type) \ - static bool occam_after_##type (type, type) occam_unused; \ - static bool occam_after_##type (type a, type b) { \ - return (a - b) > 0; \ - } //{{{ char MAKE_RANGE_CHECK(char, "%d") @@ -113,7 +108,6 @@ MAKE_SUBTR(char) MAKE_MUL(char) MAKE_DIV(char) MAKE_REM(char) -MAKE_AFTER(char) //}}} //{{{ int16_t MAKE_RANGE_CHECK(int16_t, "%d") @@ -122,7 +116,6 @@ MAKE_SUBTR(int16_t) MAKE_MUL(int16_t) MAKE_DIV(int16_t) MAKE_REM(int16_t) -MAKE_AFTER(int16_t) //}}} //{{{ int MAKE_RANGE_CHECK(int, "%d") @@ -131,7 +124,6 @@ MAKE_SUBTR(int) MAKE_MUL(int) MAKE_DIV(int) MAKE_REM(int) -MAKE_AFTER(int) //}}} //{{{ int32_t MAKE_RANGE_CHECK(int32_t, "%d") @@ -140,7 +132,6 @@ MAKE_SUBTR(int32_t) MAKE_MUL(int32_t) MAKE_DIV(int32_t) MAKE_REM(int32_t) -MAKE_AFTER(int32_t) //}}} //{{{ int64_t MAKE_RANGE_CHECK(int64_t, "%lld") @@ -149,7 +140,6 @@ MAKE_SUBTR(int64_t) MAKE_MUL(int64_t) MAKE_DIV(int64_t) MAKE_REM(int64_t) -MAKE_AFTER(int64_t) //}}} // FIXME range checks for float and double shouldn't work this way //{{{ float @@ -158,7 +148,6 @@ MAKE_ADD(float) MAKE_SUBTR(float) MAKE_MUL(float) MAKE_DIV(float) -MAKE_AFTER(float) //}}} //{{{ double MAKE_RANGE_CHECK(double, "%d") @@ -166,7 +155,6 @@ MAKE_ADD(double) MAKE_SUBTR(double) MAKE_MUL(double) MAKE_DIV(double) -MAKE_AFTER(double) //}}} #undef MAKE_RANGE_CHECK @@ -175,6 +163,5 @@ MAKE_AFTER(double) #undef MAKE_MUL #undef MAKE_DIV #undef MAKE_REM -#undef MAKE_AFTER #endif