Added a helper function for receiving an array of bytes, and changed the C++CSP backend and tests to use the function
This commit is contained in:
parent
1694f524fd
commit
8d0b5fbe1a
|
@ -437,12 +437,13 @@ cppgenInputItem ops c dest
|
||||||
where
|
where
|
||||||
chan' = genCPPCSPChannelInput ops c
|
chan' = genCPPCSPChannelInput ops c
|
||||||
recvBytes :: A.Variable -> CGen () -> CGen ()
|
recvBytes :: A.Variable -> CGen () -> CGen ()
|
||||||
recvBytes v b = do chan'
|
recvBytes v b = do tell ["tockRecvArrayOfBytes("]
|
||||||
tell [">>tockSendableArrayOfBytes("]
|
chan'
|
||||||
|
tell [",tockSendableArrayOfBytes("]
|
||||||
b
|
b
|
||||||
tell [","]
|
tell [","]
|
||||||
genPoint ops v
|
genPoint ops v
|
||||||
tell [");"]
|
tell ["));"]
|
||||||
|
|
||||||
cppgenOutputItem :: GenOps -> A.Variable -> A.OutputItem -> CGen ()
|
cppgenOutputItem :: GenOps -> A.Variable -> A.OutputItem -> CGen ()
|
||||||
cppgenOutputItem ops chan item
|
cppgenOutputItem ops chan item
|
||||||
|
|
|
@ -719,21 +719,29 @@ testInput = TestList
|
||||||
,testInputItem 112 "ChanIn(#,(&xs$),^);" "#>>*(&xs$);" (A.InVariable emptyMeta $ sub0 $ variable "xs") (A.Record foo)
|
,testInputItem 112 "ChanIn(#,(&xs$),^);" "#>>*(&xs$);" (A.InVariable emptyMeta $ sub0 $ variable "xs") (A.Record foo)
|
||||||
|
|
||||||
-- A counted array of Int:
|
-- 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.InCounted emptyMeta (variable "x") (variable "xs")) (A.Counted A.Int A.Int)
|
||||||
-- A counted array of Int8:
|
-- 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)
|
(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
|
-- TODO reading in a counted/fixed-size array into an array of arrays
|
||||||
|
|
||||||
-- inputs as part of protocols/any:
|
-- inputs as part of protocols/any:
|
||||||
,testInputItemProt 300 "ChanInInt(#,&x);" "#>>tockSendableArrayOfBytes(^,&x);" (A.InVariable emptyMeta $ variable "x") A.Int
|
,testInputItemProt 300 "ChanInInt(#,&x);" "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,&x));"
|
||||||
,testInputItemProt 301 "ChanIn(#,&x,^);" "#>>tockSendableArrayOfBytes(^,&x);" (A.InVariable emptyMeta $ variable "x") A.Int8
|
(A.InVariable emptyMeta $ variable "x") A.Int
|
||||||
,testInputItemProt 302 "ChanIn(#,(&x),^);" "#>>tockSendableArrayOfBytes(^,(&x));" (A.InVariable emptyMeta $ variable "x") (A.Record foo)
|
,testInputItemProt 301 "ChanIn(#,&x,^);" "tockRecvArrayOfBytes(#,tockSendableArrayOfBytes(^,&x));"
|
||||||
,testInputItemProt 303 "ChanIn(#,x,^);" "#>>tockSendableArrayOfBytes(^,x);" (A.InVariable emptyMeta $ variable "x") $ A.Array [A.Dimension 8] A.Int
|
(A.InVariable emptyMeta $ variable "x") A.Int8
|
||||||
,testInputItemProt 400 "ChanInInt(#,&x);ChanIn(#,xs,x*^);" "#>>tockSendableArrayOfBytes(^,&x);#>>tockSendableArrayOfBytes(x*^,xs);"
|
,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)
|
(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)
|
(A.InCounted emptyMeta (variable "x") (variable "xs")) (A.Counted A.Int8 A.Int8)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -417,6 +417,19 @@ void tockRecvArray(const csp::Chanin< tockSendableArray<T,N> >& in,const tockArr
|
||||||
in >> tsa;
|
in >> tsa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void tockSendArrayOfBytes(const csp::Chanout<tockSendableArrayOfBytes>& c, const tockSendableArrayOfBytes& b)
|
||||||
|
{
|
||||||
|
c << b;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void tockRecvArrayOfBytes(const csp::Chanin<tockSendableArrayOfBytes>& 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 <typename T>
|
template <typename T>
|
||||||
inline void tockInitChanArray(T* pointTo,T** pointFrom,int count)
|
inline void tockInitChanArray(T* pointTo,T** pointFrom,int count)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user