Changed the C and C++ backends to pass the input tests

This commit is contained in:
Neil Brown 2007-10-10 20:46:23 +00:00
parent 3f6fe50438
commit cc2040679b
3 changed files with 78 additions and 43 deletions

View File

@ -939,34 +939,34 @@ cgenInputItem :: GenOps -> A.Variable -> A.InputItem -> CGen ()
cgenInputItem ops c (A.InCounted m cv av) cgenInputItem ops c (A.InCounted m cv av)
= do call genInputItem ops c (A.InVariable m cv) = do call genInputItem ops c (A.InVariable m cv)
t <- typeOfVariable av t <- typeOfVariable av
tell ["ChanIn ("] tell ["ChanIn("]
call genVariable ops c call genVariable ops c
tell [", "] tell [","]
fst $ abbrevVariable ops A.Abbrev t av fst $ abbrevVariable ops A.Abbrev t av
tell [", "] tell [","]
subT <- trivialSubscriptType t subT <- trivialSubscriptType t
call genVariable ops cv call genVariable ops cv
tell [" * "] tell ["*"]
call genBytesIn ops subT (Just av) call genBytesIn ops subT (Just av)
tell [");\n"] tell [");"]
cgenInputItem ops c (A.InVariable m v) cgenInputItem ops c (A.InVariable m v)
= do t <- typeOfVariable v = do t <- typeOfVariable v
let rhs = fst $ abbrevVariable ops A.Abbrev t v let rhs = fst $ abbrevVariable ops A.Abbrev t v
case t of case t of
A.Int -> A.Int ->
do tell ["ChanInInt ("] do tell ["ChanInInt("]
call genVariable ops c call genVariable ops c
tell [", "] tell [","]
rhs rhs
tell [");\n"] tell [");"]
_ -> _ ->
do tell ["ChanIn ("] do tell ["ChanIn("]
call genVariable ops c call genVariable ops c
tell [", "] tell [","]
rhs rhs
tell [", "] tell [","]
call genBytesIn ops t (Just v) call genBytesIn ops t (Just v)
tell [");\n"] tell [");"]
cgenOutputItem :: GenOps -> A.Variable -> A.OutputItem -> CGen () cgenOutputItem :: GenOps -> A.Variable -> A.OutputItem -> CGen ()
cgenOutputItem ops c (A.OutCounted m ce ae) cgenOutputItem ops c (A.OutCounted m ce ae)

View File

@ -107,7 +107,6 @@ cppgenOps = cgenOps {
genForwardDeclaration = cppgenForwardDeclaration, genForwardDeclaration = cppgenForwardDeclaration,
genGetTime = cppgenGetTime, genGetTime = cppgenGetTime,
genIf = cppgenIf, genIf = cppgenIf,
genInput = cppgenInput,
genInputCase = cppgenInputCase, genInputCase = cppgenInputCase,
genInputItem = cppgenInputItem, genInputItem = cppgenInputItem,
genOutputCase = cppgenOutputCase, genOutputCase = cppgenOutputCase,
@ -410,18 +409,40 @@ cppgenTimerWait ops e
tell ["csp::SleepUntil(",time,");"] tell ["csp::SleepUntil(",time,");"]
cppgenInputItem :: GenOps -> A.Variable -> A.InputItem -> CGen () cppgenInputItem :: GenOps -> A.Variable -> A.InputItem -> CGen ()
cppgenInputItem ops c (A.InCounted m cv av) cppgenInputItem ops c dest
= do call genInputItem ops c (A.InVariable m av) = case dest of
--The size is held by the array; we just assign it to the right variable afterwards: (A.InCounted m cv av) ->
call genVariable ops cv do call genInputItem ops c (A.InVariable m cv)
tell [" = "] recvBytes av (
call genVariable ops av do call genVariable ops cv
tell [" .extent(0); "] tell ["*"]
cppgenInputItem ops c (A.InVariable m v) t <- typeOfVariable av
= do genCPPCSPChannelInput ops c subT <- trivialSubscriptType t
tell [" >> "] call genBytesIn ops t (Just av)
call genVariable ops v )
tell [";\n"] (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 :: GenOps -> A.Variable -> A.OutputItem -> CGen ()
cppgenOutputItem ops chan item cppgenOutputItem ops chan item
@ -439,34 +460,34 @@ cppgenOutputItem ops chan item
tell [");"] tell [");"]
(False,_) -> do chan' (False,_) -> do chan'
tell ["<<"] tell ["<<"]
genNonPoint sv genNonPoint ops sv
tell [";"] tell [";"]
where where
chan' = genCPPCSPChannelOutput ops chan chan' = genCPPCSPChannelOutput ops chan
sendBytes v = do chan' sendBytes v = do chan'
tell ["<<tockSendableArrayOfBytes("] tell ["<<tockSendableArrayOfBytes("]
genPoint v genPoint ops v
tell [");"] tell [");"]
byteArrayChan :: A.Type -> Bool byteArrayChan :: A.Type -> Bool
byteArrayChan (A.Chan _ _ (A.UserProtocol _)) = True byteArrayChan (A.Chan _ _ (A.UserProtocol _)) = True
byteArrayChan (A.Chan _ _ A.Any) = True byteArrayChan (A.Chan _ _ A.Any) = True
byteArrayChan (A.Chan _ _ (A.Counted _ _)) = True byteArrayChan (A.Chan _ _ (A.Counted _ _)) = True
byteArrayChan _ = False byteArrayChan _ = False
genPoint :: A.Variable -> CGen() genPoint :: GenOps -> A.Variable -> CGen()
genPoint v = do t <- typeOfVariable v genPoint ops v = do t <- typeOfVariable v
when (not $ isPoint t) $ tell ["&"] when (not $ isPoint t) $ tell ["&"]
call genVariable ops v call genVariable ops v
genNonPoint :: A.Variable -> CGen() genNonPoint :: GenOps -> A.Variable -> CGen()
genNonPoint v = do t <- typeOfVariable v genNonPoint ops v = do t <- typeOfVariable v
when (isPoint t) $ tell ["*"] when (isPoint t) $ tell ["*"]
call genVariable ops v call genVariable ops v
isPoint :: A.Type -> Bool isPoint :: A.Type -> Bool
isPoint (A.Record _) = True isPoint (A.Record _) = True
isPoint (A.Array _ _) = True isPoint (A.Array _ _) = True
isPoint _ = False isPoint _ = False
-- FIXME Should be a generic helper somewhere (along with the others from GenerateC) -- 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 -- | Helper function to place a comma between items, but not before or after

View File

@ -353,12 +353,26 @@ public:
{ {
} }
///Also for the sender:
template <typename T, typename N>
inline explicit tockSendableArrayOfBytes(const tockArrayView<T,N>& arr)
: n(0),sp(arr.data())
{
}
///For the receiver: ///For the receiver:
inline tockSendableArrayOfBytes(unsigned _n,void* p) inline tockSendableArrayOfBytes(unsigned _n,void* p)
: n(_n),sp(p) : n(_n),sp(p)
{ {
} }
//Also for the receiver:
template <typename T, typename N>
inline explicit tockSendableArrayOfBytes(unsigned _n, const tockArrayView<T,N>& arr)
: n(_n),p(arr.data())
{
}
inline void operator=(const tockSendableArrayOfBytes& _src) inline void operator=(const tockSendableArrayOfBytes& _src)
{ {
//We use the receiver's byte count: //We use the receiver's byte count: