Generate AFTER using > and MINUS

This commit is contained in:
Adam Sampson 2007-04-25 21:24:20 +00:00
parent 092e82d80a
commit d20b113a00
3 changed files with 18 additions and 14 deletions

View File

@ -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

View File

@ -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

View File

@ -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