From 5a7f68a44f0c90ee5e7fea53aab5d47a169297da Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 8 Apr 2009 16:07:01 +0000 Subject: [PATCH] Removed some of the old C generation functions, and added a new one (genFunctionCall) to get the C++ backend compiling again --- backends/GenerateC.hs | 69 +++++++++----------------------------- backends/GenerateCBased.hs | 6 ++-- backends/GenerateCPPCSP.hs | 13 +++++++ 3 files changed, 30 insertions(+), 58 deletions(-) diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 7c13c9a..3cb4031 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -104,8 +104,7 @@ cgenOps = GenOps { genExpression = cgenExpression, genFlatArraySize = cgenFlatArraySize, genForwardDeclaration = cgenForwardDeclaration, - genFuncDyadic = cgenFuncDyadic, - genFuncMonadic = cgenFuncMonadic, + genFunctionCall = cgenFunctionCall, genGetTime = cgenGetTime, genIf = cgenIf, genInput = cgenInput, @@ -134,8 +133,6 @@ cgenOps = GenOps { genReschedule = cgenReschedule, genRetypeSizes = cgenRetypeSizes, genSeq = cgenSeq, - genSimpleDyadic = cgenSimpleDyadic, - genSimpleMonadic = cgenSimpleMonadic, genSpec = cgenSpec, genSpecMode = cgenSpecMode, genStop = cgenStop, @@ -947,14 +944,7 @@ cgenExpression (A.Literal _ t lr) = call genLiteral lr t cgenExpression (A.True m) = tell ["true"] cgenExpression (A.False m) = tell ["false"] -- Any function calls remaining must be to the built-in operator functions: -cgenExpression (A.FunctionCall m n es) - = do A.Function _ _ _ fs _ <- specTypeOfName n - genName n - tell ["(wptr,"] - call genActuals fs (map A.ActualExpression es) - tell [","] - genMeta m - tell [")"] +cgenExpression (A.FunctionCall m n es) = call genFunctionCall m n es cgenExpression (A.IntrinsicFunctionCall m s es) = call genIntrinsicFunction m s es --cgenExpression (A.BytesInExpr m e) cgenExpression (A.BytesInExpr m (A.ExprVariable _ v)) @@ -971,6 +961,17 @@ cgenExpression (A.IsDefined m e) = tell ["("] >> call genExpression e >> tell ["!=NULL)"] cgenExpression t = call genMissing $ "genExpression " ++ show t +cgenFunctionCall :: Meta -> A.Name -> [A.Expression] -> CGen () +cgenFunctionCall m n es + = do A.Function _ _ _ fs _ <- specTypeOfName n + genName n + tell ["(wptr,"] + call genActuals fs (map A.ActualExpression es) + tell [","] + genMeta m + tell [")"] + + cgenTypeSymbol :: String -> A.Type -> CGen () cgenTypeSymbol s t = do f <- fget getScalarType @@ -991,41 +992,6 @@ cgenIntrinsicFunction m s es --}}} --{{{ operators -cgenSimpleMonadic :: String -> A.Expression -> CGen () -cgenSimpleMonadic s e - = do tell ["(", s] - call genExpression e - tell [")"] - -cgenFuncMonadic :: Meta -> String -> A.Expression -> CGen () -cgenFuncMonadic m s e - = do t <- astTypeOf e - call genTypeSymbol s t - tell [" ("] - call genExpression e - tell [", "] - genMeta m - tell [")"] - -cgenSimpleDyadic :: String -> A.Expression -> A.Expression -> CGen () -cgenSimpleDyadic s e f - = do tell ["("] - call genExpression e - tell [" ", s, " "] - call genExpression f - tell [")"] - -cgenFuncDyadic :: Meta -> String -> A.Expression -> A.Expression -> CGen () -cgenFuncDyadic m s e f - = do t <- astTypeOf e - call genTypeSymbol s t - tell [" ("] - call genExpression e - tell [", "] - call genExpression f - tell [", "] - genMeta m - tell [")"] --}}} cgenListConcat :: A.Expression -> A.Expression -> CGen () @@ -1723,13 +1689,8 @@ cgenAssign m [v] (A.ExpressionList _ [e]) cgenAssign m [v] (A.FunctionCallList _ n es) = do call genVariable v A.Original tell ["="] - genName n - tell ["(wptr,"] - A.Function _ _ _ fs _ <- specTypeOfName n - call genActuals fs (map A.ActualExpression es) - tell [","] - genMeta m - tell [");"] + call genFunctionCall m n es + tell [";"] cgenAssign m (v:vs) (A.IntrinsicFunctionCallList _ n es) = do call genVariable v A.Original let (funcName, giveMeta) = case lookup n simpleFloatIntrinsics of diff --git a/backends/GenerateCBased.hs b/backends/GenerateCBased.hs index 1412120..1695d44 100644 --- a/backends/GenerateCBased.hs +++ b/backends/GenerateCBased.hs @@ -142,8 +142,8 @@ data GenOps = GenOps { genExpression :: A.Expression -> CGen (), genFlatArraySize :: [A.Dimension] -> CGen (), genForwardDeclaration :: A.Specification -> CGen(), - genFuncDyadic :: Meta -> String -> A.Expression -> A.Expression -> CGen (), - genFuncMonadic :: Meta -> String -> A.Expression -> CGen (), + -- | Only used for built-in operators at the moment: + genFunctionCall :: Meta -> A.Name -> [A.Expression] -> CGen (), -- | Gets the current time into the given variable genGetTime :: A.Variable -> CGen (), -- | Generates an IF statement (which can have replicators, specifications and such things inside it). @@ -180,8 +180,6 @@ data GenOps = GenOps { 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 (), - genSimpleMonadic :: String -> A.Expression -> CGen (), genSpec :: forall b. Level -> A.Specification -> CGen b -> CGen b, genSpecMode :: A.SpecMode -> CGen (), -- | Generates a STOP process that uses the given Meta tag and message as its printed message. diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index ab349c7..85d0dc3 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -65,6 +65,7 @@ cppgenOps = cgenOps { getCType = cppgetCType, genDirectedVariable = cppgenDirectedVariable, genForwardDeclaration = cppgenForwardDeclaration, + genFunctionCall = cppgenFunctionCall, genGetTime = cppgenGetTime, genIf = cppgenIf, genInputItem = cppgenInputItem, @@ -521,6 +522,7 @@ cppgenFormal nameFunc (A.Formal am t n) = call genDecl NotTopLevel am t (nameFun cppgenForwardDeclaration :: A.Specification -> CGen() cppgenForwardDeclaration (A.Specification _ n (A.Proc _ (sm, _) fs _)) = do --Generate the "process" as a C++ function: + genStatic TopLevel n call genSpecMode sm tell ["void "] name @@ -868,3 +870,14 @@ cppgenDirectedVariable m t v dir cppgenReschedule :: CGen () cppgenReschedule = tell ["csp::CPPCSP_Yield();"] + +-- Changed because we don't need to pass the workspace in: +cppgenFunctionCall :: Meta -> A.Name -> [A.Expression] -> CGen () +cppgenFunctionCall m n es + = do A.Function _ _ _ fs _ <- specTypeOfName n + genName n + tell ["("] + call genActuals fs (map A.ActualExpression es) + tell [","] + genMeta m + tell [")"]