diff --git a/backends/GenerateC.hs b/backends/GenerateC.hs index 0cd3906..8a578a9 100644 --- a/backends/GenerateC.hs +++ b/backends/GenerateC.hs @@ -939,34 +939,34 @@ cgenInputItem :: GenOps -> A.Variable -> A.InputItem -> CGen () cgenInputItem ops c (A.InCounted m cv av) = do call genInputItem ops c (A.InVariable m cv) t <- typeOfVariable av - tell ["ChanIn ("] + tell ["ChanIn("] call genVariable ops c - tell [", "] + tell [","] fst $ abbrevVariable ops A.Abbrev t av - tell [", "] + tell [","] subT <- trivialSubscriptType t call genVariable ops cv - tell [" * "] + tell ["*"] call genBytesIn ops subT (Just av) - tell [");\n"] + tell [");"] cgenInputItem ops c (A.InVariable m v) = do t <- typeOfVariable v let rhs = fst $ abbrevVariable ops A.Abbrev t v case t of A.Int -> - do tell ["ChanInInt ("] + do tell ["ChanInInt("] call genVariable ops c - tell [", "] + tell [","] rhs - tell [");\n"] + tell [");"] _ -> - do tell ["ChanIn ("] + do tell ["ChanIn("] call genVariable ops c - tell [", "] + tell [","] rhs - tell [", "] + tell [","] call genBytesIn ops t (Just v) - tell [");\n"] + tell [");"] cgenOutputItem :: GenOps -> A.Variable -> A.OutputItem -> CGen () cgenOutputItem ops c (A.OutCounted m ce ae) diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 68bca7e..0ba9b14 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -107,7 +107,6 @@ cppgenOps = cgenOps { genForwardDeclaration = cppgenForwardDeclaration, genGetTime = cppgenGetTime, genIf = cppgenIf, - genInput = cppgenInput, genInputCase = cppgenInputCase, genInputItem = cppgenInputItem, genOutputCase = cppgenOutputCase, @@ -410,18 +409,40 @@ cppgenTimerWait ops e tell ["csp::SleepUntil(",time,");"] cppgenInputItem :: GenOps -> A.Variable -> A.InputItem -> CGen () -cppgenInputItem ops c (A.InCounted m cv av) - = do call genInputItem ops c (A.InVariable m av) - --The size is held by the array; we just assign it to the right variable afterwards: - call genVariable ops cv - tell [" = "] - call genVariable ops av - tell [" .extent(0); "] -cppgenInputItem ops c (A.InVariable m v) - = do genCPPCSPChannelInput ops c - tell [" >> "] - call genVariable ops v - tell [";\n"] +cppgenInputItem ops c dest + = case dest of + (A.InCounted m cv av) -> + do call genInputItem ops c (A.InVariable m cv) + recvBytes av ( + do call genVariable ops cv + tell ["*"] + t <- typeOfVariable av + subT <- trivialSubscriptType t + call genBytesIn ops t (Just av) + ) + (A.InVariable m v) -> + do ct <- typeOfVariable c + t <- typeOfVariable v + case (byteArrayChan ct,t) of + (True,_)-> recvBytes v (call genBytesIn ops t (Just v)) + (False,A.Array {}) -> do tell ["tockRecvArray("] + chan' + tell [","] + call genVariable ops v + tell [");"] + (False,_) -> do chan' + tell [">>"] + genNonPoint ops v + tell [";"] + where + chan' = genCPPCSPChannelInput ops c + recvBytes :: A.Variable -> CGen () -> CGen () + recvBytes v b = do chan' + tell [">>tockSendableArrayOfBytes("] + b + tell [","] + genPoint ops v + tell [");"] cppgenOutputItem :: GenOps -> A.Variable -> A.OutputItem -> CGen () cppgenOutputItem ops chan item @@ -439,34 +460,34 @@ cppgenOutputItem ops chan item tell [");"] (False,_) -> do chan' tell ["<<"] - genNonPoint sv + genNonPoint ops sv tell [";"] where chan' = genCPPCSPChannelOutput ops chan sendBytes v = do chan' tell ["< Bool - byteArrayChan (A.Chan _ _ (A.UserProtocol _)) = True - byteArrayChan (A.Chan _ _ A.Any) = True - byteArrayChan (A.Chan _ _ (A.Counted _ _)) = True - byteArrayChan _ = False - - genPoint :: A.Variable -> CGen() - genPoint v = do t <- typeOfVariable v + genPoint ops v + tell [");"] + +byteArrayChan :: A.Type -> Bool +byteArrayChan (A.Chan _ _ (A.UserProtocol _)) = True +byteArrayChan (A.Chan _ _ A.Any) = True +byteArrayChan (A.Chan _ _ (A.Counted _ _)) = True +byteArrayChan _ = False + +genPoint :: GenOps -> A.Variable -> CGen() +genPoint ops v = do t <- typeOfVariable v when (not $ isPoint t) $ tell ["&"] call genVariable ops v - genNonPoint :: A.Variable -> CGen() - genNonPoint v = do t <- typeOfVariable v +genNonPoint :: GenOps -> A.Variable -> CGen() +genNonPoint ops v = do t <- typeOfVariable v when (isPoint t) $ tell ["*"] call genVariable ops v - isPoint :: A.Type -> Bool - isPoint (A.Record _) = True - isPoint (A.Array _ _) = True - isPoint _ = False +isPoint :: A.Type -> Bool +isPoint (A.Record _) = True +isPoint (A.Array _ _) = True +isPoint _ = False -- FIXME Should be a generic helper somewhere (along with the others from GenerateC) -- | Helper function to place a comma between items, but not before or after diff --git a/tock_support_cppcsp.h b/tock_support_cppcsp.h index 4a3e460..40f26af 100644 --- a/tock_support_cppcsp.h +++ b/tock_support_cppcsp.h @@ -353,12 +353,26 @@ public: { } + ///Also for the sender: + template + inline explicit tockSendableArrayOfBytes(const tockArrayView& arr) + : n(0),sp(arr.data()) + { + } + ///For the receiver: inline tockSendableArrayOfBytes(unsigned _n,void* p) : n(_n),sp(p) { } + //Also for the receiver: + template + inline explicit tockSendableArrayOfBytes(unsigned _n, const tockArrayView& arr) + : n(_n),p(arr.data()) + { + } + inline void operator=(const tockSendableArrayOfBytes& _src) { //We use the receiver's byte count: