diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index e2eac48..1b0e128 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -136,15 +136,17 @@ cppgenTopLevel s call genStructured s (\m _ -> tell ["\n#error Invalid top-level item: ",show m]) (name, chans) <- tlpInterface tell ["int main (int argc, char** argv) { csp::Start_CPPCSP();"] - (chanType, writer, reader) <- + (chanTypeRead, chanTypeWrite, writer, reader) <- do st <- getCompState case csFrontend st of FrontendOccam -> return ("tockSendableArrayOfBytes", + "tockSendableArrayOfBytes", "StreamWriterByteArray", "StreamReaderByteArray") - _ -> return ("uint8_t", "StreamWriter", "StreamReader") + _ -> return ("uint8_t", "tockList/**/","StreamWriterList", "StreamReader") - tell ["csp::One2OneChannel<",chanType,"> in,out,err;"] + tell ["csp::One2OneChannel<",chanTypeRead,"> in;"] + tell ["csp::One2OneChannel<",chanTypeWrite,"> out,err;"] tell [" csp::Run( csp::InParallel ", "(new ",writer,"(std::cout,out.reader())) ", "(new ",writer,"(std::cerr,err.reader())) ", diff --git a/support/tock_support_cppcsp.h b/support/tock_support_cppcsp.h index b805089..f63363b 100644 --- a/support/tock_support_cppcsp.h +++ b/support/tock_support_cppcsp.h @@ -398,6 +398,41 @@ public: } }; +class StreamWriterList : public csp::CSProcess +{ +private: + std::ostream& out; + csp::Chanin< tockList > in; +protected: + virtual void run() + { + try + { + tockList cs; + while (true) + { + in >> cs; + for (tockList::iterator it = cs.beginSeqEach();it != cs.limitIterator();it++) + { + out << *it; + } + out.flush(); + } + } + catch (csp::PoisonException& e) + { + in.poison(); + } + out.flush(); + } +public: + inline StreamWriterList(std::ostream& _out,const csp::Chanin< tockList >& _in) + : out(_out),in(_in) + { + } +}; + + // Time addition and subtraction: inline csp::Time occam_plus_time (const csp::Time& a, const csp::Time& b, const char *)