Fixed a few small things related to generating intrinsic calls in the C and C++ backends

This commit is contained in:
Neil Brown 2009-01-25 20:43:39 +00:00
parent c30db7b11e
commit 0b2708b2ed
3 changed files with 16 additions and 3 deletions

View File

@ -128,6 +128,7 @@ cgenOps = GenOps {
genReplicatorStart = cgenReplicatorStart,
genReplicatorEnd = cgenReplicatorEnd,
genReplicatorLoop = cgenReplicatorLoop,
genReschedule = cgenReschedule,
genRetypeSizes = cgenRetypeSizes,
genSeq = cgenSeq,
genSimpleDyadic = cgenSimpleDyadic,
@ -939,7 +940,7 @@ cgenTypeSymbol s t
cgenIntrinsicFunction :: Meta -> String -> [A.Expression] -> CGen ()
cgenIntrinsicFunction m s es
= do tell ["occam_", s, " ("]
= do tell ["occam_", [if c == '.' then '_' else c | c <- s], "("]
sequence [call genExpression e >> genComma | e <- es]
genMeta m
tell [")"]
@ -1541,7 +1542,7 @@ cgenAssign m [v] (A.ExpressionList _ [e])
tell [";"]
cgenAssign m (v:vs) (A.IntrinsicFunctionCallList _ n es)
= do call genVariable v
tell ["=occam_",n,"("]
tell ["=occam_",[if c == '.' then '_' else c | c <- n],"("]
seqComma $ map (call genExpression) es
mapM (\v -> tell [","] >> call genActual (A.Formal A.Abbrev A.Int (A.Name
emptyMeta "dummy_intrinsic_param")) (A.ActualVariable v)) vs
@ -1829,9 +1830,12 @@ cgenProcCall n as
--{{{ intrinsic procs
cgenIntrinsicProc :: Meta -> String -> [A.Actual] -> CGen ()
cgenIntrinsicProc m "ASSERT" [A.ActualExpression e] = call genAssert m e
cgenIntrinsicProc _ "RESCHEDULE" [] = tell ["Reschedule (wptr);\n"]
cgenIntrinsicProc _ "RESCHEDULE" [] = call genReschedule
cgenIntrinsicProc _ s _ = call genMissing $ "intrinsic PROC " ++ s
cgenReschedule :: CGen ()
cgenReschedule = tell ["Reschedule (wptr);"]
cgenAssert :: Meta -> A.Expression -> CGen ()
cgenAssert m e
= do tell ["if (!"]

View File

@ -160,6 +160,7 @@ data GenOps = GenOps {
genReplicatorEnd :: A.Replicator -> CGen (),
-- | Generates the three bits of a for loop (e.g. @int i = 0; i < 10; i++@ for the given replicator)
genReplicatorLoop :: A.Name -> A.Replicator -> CGen (),
genReschedule :: CGen(),
genRetypeSizes :: Meta -> A.Type -> A.Name -> A.Type -> A.Variable -> CGen (),
genSeq :: A.Structured A.Process -> CGen (),
genSimpleDyadic :: String -> A.Expression -> A.Expression -> CGen (),
@ -194,6 +195,10 @@ data GenOps = GenOps {
class CGenCall a where
call :: (GenOps -> a) -> a
instance CGenCall (CGen z) where
call f = do ops <- ask
f ops
instance CGenCall (a -> CGen z) where
-- call :: (a -> CGen b) -> a -> CGen b
call f x0 = do ops <- ask

View File

@ -79,6 +79,7 @@ cppgenOps = cgenOps {
genPoison = cppgenPoison,
genProcCall = cppgenProcCall,
genReplicatorLoop = cppgenReplicatorLoop,
genReschedule = cppgenReschedule,
genStop = cppgenStop,
genTimerRead = cppgenTimerRead,
genTimerWait = cppgenTimerWait,
@ -844,3 +845,6 @@ cppgenClearMobile _ v
tell ["=NULL;}"]
where
genVar = call genVariable v
cppgenReschedule :: CGen ()
cppgenReschedule = tell ["csp::CPPCSP_Yield();"]