diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 0ba9b14..cda89cc 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -437,12 +437,13 @@ cppgenInputItem ops c dest where chan' = genCPPCSPChannelInput ops c recvBytes :: A.Variable -> CGen () -> CGen () - recvBytes v b = do chan' - tell [">>tockSendableArrayOfBytes("] + recvBytes v b = do tell ["tockRecvArrayOfBytes("] + chan' + tell [",tockSendableArrayOfBytes("] b tell [","] genPoint ops v - tell [");"] + tell ["));"] cppgenOutputItem :: GenOps -> A.Variable -> A.OutputItem -> CGen () cppgenOutputItem ops chan item diff --git a/backends/GenerateCTest.hs b/backends/GenerateCTest.hs index 75dcc86..819c96e 100644 --- a/backends/GenerateCTest.hs +++ b/backends/GenerateCTest.hs @@ -719,21 +719,29 @@ testInput = TestList ,testInputItem 112 "ChanIn(#,(&xs$),^);" "#>>*(&xs$);" (A.InVariable emptyMeta $ sub0 $ variable "xs") (A.Record foo) -- A counted array of Int: - ,testInputItem 200 "ChanInInt(#,&x);ChanIn(#,xs,x*^);" "#>>tockSendableArrayOfBytes(^,&x);#>>tockSendableArrayOfBytes(x*^,xs);" + ,testInputItem 200 "ChanInInt(#,&x);ChanIn(#,xs,x*^);" + "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,&x));tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(x*^,xs));" (A.InCounted emptyMeta (variable "x") (variable "xs")) (A.Counted A.Int A.Int) -- A counted array of Int8: - ,testInputItem 201 "ChanIn(#,&x,^);ChanIn(#,xs,x*^);" "#>>tockSendableArrayOfBytes(^,&x);#>>tockSendableArrayOfBytes(x*^,xs);" + ,testInputItem 201 "ChanIn(#,&x,^);ChanIn(#,xs,x*^);" + "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,&x));tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(x*^,xs));" (A.InCounted emptyMeta (variable "x") (variable "xs")) (A.Counted A.Int8 A.Int8) -- TODO reading in a counted/fixed-size array into an array of arrays -- inputs as part of protocols/any: - ,testInputItemProt 300 "ChanInInt(#,&x);" "#>>tockSendableArrayOfBytes(^,&x);" (A.InVariable emptyMeta $ variable "x") A.Int - ,testInputItemProt 301 "ChanIn(#,&x,^);" "#>>tockSendableArrayOfBytes(^,&x);" (A.InVariable emptyMeta $ variable "x") A.Int8 - ,testInputItemProt 302 "ChanIn(#,(&x),^);" "#>>tockSendableArrayOfBytes(^,(&x));" (A.InVariable emptyMeta $ variable "x") (A.Record foo) - ,testInputItemProt 303 "ChanIn(#,x,^);" "#>>tockSendableArrayOfBytes(^,x);" (A.InVariable emptyMeta $ variable "x") $ A.Array [A.Dimension 8] A.Int - ,testInputItemProt 400 "ChanInInt(#,&x);ChanIn(#,xs,x*^);" "#>>tockSendableArrayOfBytes(^,&x);#>>tockSendableArrayOfBytes(x*^,xs);" + ,testInputItemProt 300 "ChanInInt(#,&x);" "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,&x));" + (A.InVariable emptyMeta $ variable "x") A.Int + ,testInputItemProt 301 "ChanIn(#,&x,^);" "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,&x));" + (A.InVariable emptyMeta $ variable "x") A.Int8 + ,testInputItemProt 302 "ChanIn(#,(&x),^);" "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,(&x)));" + (A.InVariable emptyMeta $ variable "x") (A.Record foo) + ,testInputItemProt 303 "ChanIn(#,x,^);" "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,x));" + (A.InVariable emptyMeta $ variable "x") $ A.Array [A.Dimension 8] A.Int + ,testInputItemProt 400 "ChanInInt(#,&x);ChanIn(#,xs,x*^);" + "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,&x));tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(x*^,xs));" (A.InCounted emptyMeta (variable "x") (variable "xs")) (A.Counted A.Int A.Int) - ,testInputItemProt 401 "ChanIn(#,&x,^);ChanIn(#,xs,x*^);" "#>>tockSendableArrayOfBytes(^,&x);#>>tockSendableArrayOfBytes(x*^,xs);" + ,testInputItemProt 401 "ChanIn(#,&x,^);ChanIn(#,xs,x*^);" + "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,&x));tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(x*^,xs));" (A.InCounted emptyMeta (variable "x") (variable "xs")) (A.Counted A.Int8 A.Int8) diff --git a/tock_support_cppcsp.h b/tock_support_cppcsp.h index d1eaa9a..11166b6 100644 --- a/tock_support_cppcsp.h +++ b/tock_support_cppcsp.h @@ -417,6 +417,19 @@ void tockRecvArray(const csp::Chanin< tockSendableArray >& in,const tockArr in >> tsa; } +inline void tockSendArrayOfBytes(const csp::Chanout& c, const tockSendableArrayOfBytes& b) +{ + c << b; +} + +inline void tockRecvArrayOfBytes(const csp::Chanin& c, const tockSendableArrayOfBytes& _b) +{ + //We can't read into the const parameter, so we copy it into a non-const version and read into that. + //The copying will preserve the pointer inside, so it doesn't cause any problems: + tockSendableArrayOfBytes b(_b); + c >> b; +} + template inline void tockInitChanArray(T* pointTo,T** pointFrom,int count) {