From 41d4923e9c209d36881823d471eecf4ea7919b83 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 26 Sep 2007 23:18:21 +0000 Subject: [PATCH] Added support for the new Wait process to the C and C++ backends --- backends/GenerateC.hs | 10 ++++++++++ backends/GenerateCPPCSP.hs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index d46c88e..fdc5263 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -153,6 +153,7 @@ data GenOps = GenOps { genVariable' :: GenOps -> Bool -> A.Variable -> CGen (), genVariableAM :: GenOps -> A.Variable -> A.AbbrevMode -> CGen (), genVariableUnchecked :: GenOps -> A.Variable -> CGen (), + genWait :: GenOps -> A.WaitMode -> A.Expression -> CGen (), genWhile :: GenOps -> A.Expression -> A.Process -> CGen (), getScalarType :: GenOps -> A.Type -> Maybe String, introduceSpec :: GenOps -> A.Specification -> CGen (), @@ -243,6 +244,7 @@ cgenOps = GenOps { genVariableAM = cgenVariableAM, genVariableUnchecked = cgenVariableUnchecked, genWhile = cgenWhile, + genWait = cgenWait, getScalarType = cgetScalarType, introduceSpec = cintroduceSpec, removeSpec = cremoveSpec @@ -1479,6 +1481,7 @@ cgenProcess ops p = case p of A.Output m c ois -> call genOutput ops c ois A.OutputCase m c t ois -> call genOutputCase ops c t ois A.GetTime m v -> call genGetTime ops m v + A.Wait m wm e -> call genWait ops wm e A.Skip m -> tell ["/* skip */\n"] A.Stop m -> call genStop ops m "STOP process" A.Main m -> tell ["/* main */\n"] @@ -1579,6 +1582,13 @@ cgenGetTime ops m v call genVariable ops v tell [");\n"] +cgenWait :: GenOps -> A.WaitMode -> A.Expression -> CGen () +cgenWait ops A.WaitUntil e = call genTimerWait ops e +cgenWait ops A.WaitFor e + = do tell ["ProcAfter ("] + call genExpression ops e + tell [");\n"] + --}}} --{{{ output cgenOutput :: GenOps -> A.Variable -> [A.OutputItem] -> CGen () diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 39709db..ac2ac05 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -130,6 +130,7 @@ cppgenOps = cgenOps { genUnfoldedExpression = cppgenUnfoldedExpression, genUnfoldedVariable = cppgenUnfoldedVariable, genVariable' = cppgenVariable', + genWait = cppgenWait, getScalarType = cppgetScalarType, introduceSpec = cppintroduceSpec, removeSpec = cppremoveSpec @@ -356,6 +357,12 @@ cppgenGetTime ops m v call genVariable ops v tell [");"] +cppgenWait :: GenOps -> A.WaitMode -> A.Expression -> CGen () +cppgenWait ops wm e + = do tell [if wm == A.WaitFor then "csp::SleepFor" else "csp::SleepUntil", "("] + call genExpression ops e + tell [");"] + {-| Gets a csp::Time to wait with, given a 32-bit microsecond value (returns the temp variable we have put it in)