From b280158e263cbc672b99fb3926118c1ba6555616 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 19 Sep 2007 10:34:49 +0000 Subject: [PATCH] Added code in the C and C++ backends for handling the new Time type and GetTime statements in the AST --- backends/GenerateC.hs | 11 +++++++++++ backends/GenerateCPPCSP.hs | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index b1e6aa9..d46c88e 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -109,6 +109,7 @@ data GenOps = GenOps { genForwardDeclaration :: GenOps -> A.Specification -> CGen(), genFuncDyadic :: GenOps -> Meta -> String -> A.Expression -> A.Expression -> CGen (), genFuncMonadic :: GenOps -> Meta -> String -> A.Expression -> CGen (), + genGetTime :: GenOps -> Meta -> A.Variable -> CGen (), genIf :: GenOps -> Meta -> A.Structured -> CGen (), genInput :: GenOps -> A.Variable -> A.InputMode -> CGen (), genInputCase :: GenOps -> Meta -> A.Variable -> A.Structured -> CGen (), @@ -197,6 +198,7 @@ cgenOps = GenOps { genForwardDeclaration = cgenForwardDeclaration, genFuncDyadic = cgenFuncDyadic, genFuncMonadic = cgenFuncMonadic, + genGetTime = cgenGetTime, genIf = cgenIf, genInput = cgenInput, genInputCase = cgenInputCase, @@ -364,6 +366,7 @@ cgetScalarType _ A.Int64 = Just "int64_t" cgetScalarType _ A.Real32 = Just "float" cgetScalarType _ A.Real64 = Just "double" cgetScalarType _ A.Timer = Just "Time" +cgetScalarType _ A.Time = Just "Time" cgetScalarType _ _ = Nothing cgenType :: GenOps -> A.Type -> CGen () @@ -1475,6 +1478,7 @@ cgenProcess ops p = case p of A.Input m c im -> call genInput ops c im 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.Skip m -> tell ["/* skip */\n"] A.Stop m -> call genStop ops m "STOP process" A.Main m -> tell ["/* main */\n"] @@ -1568,6 +1572,13 @@ cgenTimerWait ops e = do tell ["ProcTimeAfter ("] call genExpression ops e tell [");\n"] + +cgenGetTime :: GenOps -> Meta -> A.Variable -> CGen () +cgenGetTime ops m v + = do tell ["ProcTime(&"] + call genVariable ops v + tell [");\n"] + --}}} --{{{ output cgenOutput :: GenOps -> A.Variable -> [A.OutputItem] -> CGen () diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index d719e0e..39709db 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -110,6 +110,7 @@ cppgenOps = cgenOps { genDeclaration = cppgenDeclaration, genFlatArraySize = cppgenFlatArraySize, genForwardDeclaration = cppgenForwardDeclaration, + genGetTime = cppgenGetTime, genIf = cppgenIf, genInput = cppgenInput, genInputCase = cppgenInputCase, @@ -349,6 +350,12 @@ cppgenTimerRead ops c v call genVariable ops c tell ["),4294967296.0);\n"] +cppgenGetTime :: GenOps -> Meta -> A.Variable -> CGen () +cppgenGetTime ops m v + = do tell ["csp::CurrentTime (&"] + call genVariable ops v + tell [");"] + {-| Gets a csp::Time to wait with, given a 32-bit microsecond value (returns the temp variable we have put it in) @@ -1041,6 +1048,7 @@ cppgetScalarType _ A.Int64 = Just "int64_t" cppgetScalarType _ A.Real32 = Just "float" cppgetScalarType _ A.Real64 = Just "double" cppgetScalarType _ A.Timer = Just "csp::Time" +cppgetScalarType _ A.Time = Just "csp::Time" cppgetScalarType _ _ = Nothing -- | Generates an array type, giving the Blitz++ array the correct dimensions