Intrinsic PROCs (ASSERT for now)

This commit is contained in:
Adam Sampson 2007-04-29 14:46:19 +00:00
parent 5de146234f
commit 2d88249408
7 changed files with 62 additions and 0 deletions

View File

@ -243,5 +243,6 @@ data Process =
| Processor Meta Expression Process
| Alt Meta Bool Structured
| ProcCall Meta Name [Actual]
| IntrinsicProcCall Meta String [Actual]
deriving (Show, Eq, Typeable, Data)

View File

@ -978,6 +978,7 @@ genProcess p = case p of
A.Processor m e p -> genProcess p
A.Alt m b s -> genAlt b s
A.ProcCall m n as -> genProcCall n as
A.IntrinsicProcCall m s as -> genIntrinsicProc m s as
--{{{ assignment
genAssign :: [A.Variable] -> A.ExpressionList -> CGen ()
@ -1322,5 +1323,18 @@ genProcCall n as
genActuals as
tell [");\n"]
--}}}
--{{{ intrinsic procs
genIntrinsicProc :: Meta -> String -> [A.Actual] -> CGen ()
genIntrinsicProc m "ASSERT" [A.ActualExpression A.Bool e] = genAssert m e
genIntrinsicProc _ s _ = missing $ "intrinsic PROC " ++ s
genAssert :: Meta -> A.Expression -> CGen ()
genAssert m e
= do tell ["if (!"]
genExpression e
tell [") {\n"]
genStop m "assertion failed"
tell ["}\n"]
--}}}
--}}}

View File

@ -9,3 +9,7 @@ KRoC's TLP interface.
INLINE PROC, although it's ignored (because it should be up to the C compiler
what gets inlined).
Intrinsics:
- ASSERT

View File

@ -1336,6 +1336,7 @@ process
<|> parallel
<|> altProcess
<|> procInstance
<|> intrinsicProc
<|> mainProcess
<|> handleSpecs (allocation <|> specification) process
(\m s p -> A.Seq m (A.Spec m s (A.OnlyP m p)))
@ -1718,6 +1719,31 @@ actual (A.Formal am t n)
where
an = A.nameName n
--}}}
--{{{ intrinsic PROC call
intrinsicProcs :: [(String, [(A.AbbrevMode, A.Type, String)])]
intrinsicProcs =
[ ("ASSERT", [(A.ValAbbrev, A.Bool, "value")])
]
intrinsicProcName :: OccParser (String, [A.Formal])
intrinsicProcName
= do n <- anyName A.ProcName
let s = A.nameName n
case lookup s intrinsicProcs of
Just atns -> return (s, [A.Formal am t (A.Name emptyMeta A.VariableName n)
| (am, t, n) <- atns])
Nothing -> pzero
intrinsicProc :: OccParser A.Process
intrinsicProc
= do m <- md
(n, fs) <- tryVX intrinsicProcName sLeftR
as <- actuals fs
sRightR
eol
return $ A.IntrinsicProcCall m n as
<?> "intrinsic PROC instance"
--}}}
--{{{ preprocessor directives
preprocessorDirective :: OccParser A.Process
preprocessorDirective

View File

@ -0,0 +1,3 @@
PROC P ()
ASSERT (FALSE)
:

View File

@ -0,0 +1,5 @@
INT FUNCTION id(VAL INT i) IS i :
PROC P ()
INT x:
x := id (4)
:

View File

@ -0,0 +1,9 @@
PROC P ()
SEQ
ASSERT (TRUE)
-- check we can override an intrinsic
PROC ASSERT (VAL BOOL b)
SKIP
:
ASSERT (FALSE)
: