diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 7284690..63bccd3 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -193,87 +193,6 @@ genCPPCSPChannelOutput ops var _ -> call genMissing ops $ "genCPPCSPChannelOutput used on something which does not support output: " ++ show var --}}} -cppgenInput :: GenOps -> A.Variable -> A.InputMode -> CGen () -cppgenInput ops c im - = do case im of - A.InputTimerRead m (A.InVariable m' v) -> call genTimerRead ops c v - A.InputTimerAfter m e -> call genTimerWait ops e - A.InputSimple m is -> mapM_ (call genInputItem ops c) is - _ -> call genMissing ops $ "genInput " ++ show im - --- | This function processes (potentially chained) variants to get the real index of the data item inside the variant -whichExpr :: A.Name -> String -> String -> Int -> CGen() -> CGen() -whichExpr proto which variant offset protoGen - = do cases <- casesOfProtocol proto - case (offset > (length cases)) of - True -> return () - False -> - do tell [which, " = ", variant , " . which() + ",show offset," ; "] - case ((offset + 9) > (length cases)) of - True -> return () - False -> - do tell ["if ( ", which , " == 9 + ",show offset,") { "] - innerVariant <- makeNonce "case_tag" - innerProto - tell [" & ",innerVariant," = boost::get< /**/"] - innerProto - tell [" /**/>( ",variant," ); "] - whichExpr proto which innerVariant (offset + 9) innerProto - tell [" } "] - where innerProto = protoGen >> tell ["_"] - - --- | Generates the long boost::tie expression that will be used to get all the data out of a tuple that we have read -genInputTupleAssign :: GenOps -> Bool -> String -> [A.InputItem] -> CGen() -genInputTupleAssign ops hasTag caseVar items - = do genInputTupleAssign' hasTag caseVar items - sequence_ $ map genInputSizeAssign items - where - genInputTupleAssign' :: Bool -> String -> [A.InputItem] -> CGen() - genInputTupleAssign' hasTag caseVar items - = do if ((length rest) /= 0) then tell ["tie10("] else tell ["boost::tuples::tie("] - when (hasTag) (tell ["boost::tuples::ignore,"]) - infixComma (map genInputAssign firstLoad) - when ((length rest) /= 0) (tell [","] >> genInputTupleAssign' False "" rest) - if ((length caseVar) /= 0) then tell [") = ",caseVar," ; "] else tell [")"] - where - (firstLoad,rest) = splitAt (if hasTag then 8 else 9) items - - --Gets the variable to input into: - genInputAssign :: A.InputItem -> CGen() - genInputAssign (A.InVariable _ arr) - = call genVariable ops arr - genInputAssign (A.InCounted _ count arr) - = call genVariable ops arr - - --Gets the variable that will receieve the size of an inputted array - genInputSizeAssign :: A.InputItem -> CGen() - genInputSizeAssign (A.InVariable _ arr) - = return () - genInputSizeAssign (A.InCounted _ count arr) - = call genVariable ops count >> tell [" = "] >> call genVariable ops arr >> tell [" .extent(0);"] - --- | Generates the code for getting a particular tagged value out of a (potentially chained) variant -genVariantGet :: A.Name -> A.Name -> String -> CGen() -> CGen String -genVariantGet proto tag var variantName - = do cases <- casesOfProtocol proto - let index = indexOfTag cases tag - genVariantGet' index proto tag var variantName - where - --This is coded oddly, but it does the job! - genVariantGet' :: Int -> A.Name -> A.Name -> String -> CGen() -> CGen String - genVariantGet' index proto tag var variantName - = do caseVar <- makeNonce "case_tag" - (target,recur) <- case (index >= 9) of - True -> return (variantName >> tell ["_"],genVariantGet' (index - 9) proto tag caseVar (variantName >> tell ["_"])) - False -> return (genTupleProtocolTagName proto tag,return caseVar) - target - tell [" & ",caseVar," = boost::get< "] - target - tell [" >( ", var, " );"] - recur - - -- | C++CSP2 returns the number of seconds since the epoch as the time --Since this is too large to be contained in an int once it has been multiplied, --the remainder is taken to trim the timer back down to something that will be useful in an int @@ -441,63 +360,6 @@ infixComma :: [CGen ()] -> CGen () infixComma (c0:cs) = c0 >> sequence_ [genComma >> c | c <- cs] infixComma [] = return () ---{{{Helper functions for protocol names and tags: - -genProtocolName :: A.Name -> CGen() -genProtocolName proto - = do tell ["protocol_"] - genName proto - -genProtocolTagName :: A.Name -> A.Name -> CGen() -genProtocolTagName proto tag - = do tell ["protocol_tag_"] - genName proto - tell ["_"] - genName tag - -genTupleProtocolTagName :: A.Name -> A.Name -> CGen() -genTupleProtocolTagName proto tag = tell ["tuple_"] >> genProtocolTagName proto tag - - ---Given a list of cases and a tag, finds the index of that tag: -indexOfTag :: [(A.Name, [A.Type])] -> A.Name -> Int -indexOfTag = indexOfTag' 0 - where - indexOfTag' :: Int -> [(A.Name, [A.Type])] -> A.Name -> Int - indexOfTag' n ((possible,_):rest) target - | possible == target = n - | otherwise = indexOfTag' (n+1) rest target - ---Helper for getting all the cases of a given protocol: -casesOfProtocol :: A.Name -> CGen [(A.Name, [A.Type])] -casesOfProtocol proto - = do protoType <- specTypeOfName proto - case protoType of - A.Protocol _ _ -> return ([]) - A.ProtocolCase _ types -> return (types) - ---}}} - --- | Used when constructing a chained variant -- we must specify the variant types through the chain, so the ---compiler understands that we're giving it one of the inner variants -genSubTypes :: A.Name -> A.Name -> CGen() -> CGen() -genSubTypes proto tag middle - = do protoType <- specTypeOfName proto - case protoType of - --sequential, no need for sub-types: - A.Protocol _ types -> middle - --choice, do need the sub-types: - A.ProtocolCase _ types -> do sequence_ - [ (genProtocolName proto >> - tell [(replicate ind '_')," ( "]) | ind <- [0 .. byNine] - ] - middle - tell [replicate (byNine + 1) ')'] - --We add one because the protocol tag itself counts as an item in our C++ implementation: - where realIndex = 1 + (indexOfTag types tag) - byNine = realIndex `div` 9 - - cppgenOutputCase :: GenOps -> A.Variable -> A.Name -> [A.OutputItem] -> CGen () cppgenOutputCase ops c tag ois = do t <- typeOfVariable c @@ -753,36 +615,6 @@ cppabbrevExpression ops am t@(A.Array _ _) e bad = call genMissing ops "array expression abbreviation" cppabbrevExpression ops am _ e = call genExpression ops e --- | Used to create boost::variant and boost::tuple types. Both these classes can have a maximum of nine items ---so if there are more than nine items, we must have variants containing variants, or tuples containing tuples -createChainedType :: String -> CGen() -> [CGen()] -> CGen () -createChainedType combinator typeName items - = do when ((length rest) /= 0) - (createChainedType combinator subName rest) - tell ["typedef ",combinator," < "] - infixComma firstNine - when ((length rest) /= 0) - (tell [" , "] >> subName) - --To stop the indent program ruining the C++ Code by combining all the ">" into ">>>" we use these odd blank comments: - tell ["/**/> "] - typeName - tell [" ; "] - where - subName = (typeName >> tell ["_"]) - (firstNine,rest) = splitAt 9 items - --- | Used to create (potentially chained) tuple expressions -tupleExpression :: Bool -> CGen() -> [CGen()] -> CGen() -tupleExpression useBrackets tupleType items - = do tupleType - when (useBrackets) (tell [" ( "]) - infixComma firstNine - when ((length rest) /= 0) - (tell [" , "] >> (tupleExpression True (tell ["boost::make_tuple"]) rest)) - when (useBrackets) (tell [" ) "]) - where - (firstNine,rest) = splitAt 9 items - -- | Takes a list of dimensions and outputs a comma-seperated list of the numerical values --Unknown dimensions have value 0 (which is treated specially by the tockArrayView class) genDims:: [A.Dimension] -> CGen()