34 FD_DCG(
"PlcoxmlCodeGenerator(" <<
this <<
")::PlcoxmlCodeGenerator()");
40 FD_DCG(
"PlcoxmlCodeGenerator(" <<
this <<
")::~PlcoxmlCodeGenerator()");
46 FD_DCG(
"PlcoxmlCodeGenerator::Clear()");
62 FD_DCG(
"PlcoxmlCodeGenerator::DoReadTargetConfiguration()");
67 if(rTr.ExistsBegin(
"IecSchemeVersion")) {
68 rTr.ReadBegin(
"IecSchemeVersion",token);
70 rTr.ReadEnd(
"IecSchemeVersion");
72 if(rTr.ExistsBegin(
"IecToolVendor")) {
73 rTr.ReadBegin(
"IecToolVendor",token);
75 rTr.ReadEnd(
"IecToolVendor");
77 if(rTr.ExistsBegin(
"IecContentAuthor")) {
78 rTr.ReadBegin(
"IecContentAuthor",token);
80 rTr.ReadEnd(
"IecContentAuthor");
82 if(rTr.ExistsBegin(
"IecContentOrganization")) {
83 rTr.ReadBegin(
"IecContenetOrganization",token);
85 rTr.ReadEnd(
"IecContentOrganization");
87 if(rTr.ExistsBegin(
"IecContentVersion")) {
88 rTr.ReadBegin(
"IecContentVersion",token);
90 rTr.ReadEnd(
"IecContentVersion");
92 if(rTr.ExistsBegin(
"IecTextElement")) {
93 rTr.ReadBegin(
"IecTextElement",token);
95 rTr.ReadEnd(
"IecTextElement");
101 FD_DCG(
"PlcoxmlCodeGenerator::DoWriteTargetConfiguration()");
106 token.SetEmpty(
"IecSchemeVersion");
109 token.SetEmpty(
"IecToolVendor");
113 token.SetEmpty(
"IecContentAuthor");
118 token.SetEmpty(
"IecContentCompany");
123 token.SetEmpty(
"IecContentVersion");
128 token.SetEmpty(
"IecTextElement");
152 FCG_ERR(
"PlcoxmlCodeGenerator::DoGenerate(): xml scheme \"" <<
mIecSchemeVersion <<
"\" not supported");
154 FCG_ERR(
"PlcoxmlCodeGenerator::DoGenerate(): xml text element \"" <<
mIecTextElement <<
"\" not supported");
157 FCG_ERR(
"PlcoxmlCodeGenerator::DoGenerate(): xml format requires a project name");
160 FCG_ERR(
"PlcoxmlCodeGenerator::DoGenerate(): literal insert to cyclic function not supported by this target");
162 FCG_ERR(
"PlcoxmlCodeGenerator::DoGenerate(): literal prepend not supported by this target");
164 FCG_ERR(
"PlcoxmlCodeGenerator::DoGenerate(): literal append not supported by this target");
171 now_tm = localtime(&now_time);
173 snprintf(now_str,24,
"%4d-%02d-%02dT%02d:%02d:%02d",now_tm->tm_year+1900,now_tm->tm_mon+1,now_tm->tm_mday,now_tm->tm_hour,now_tm->tm_min,now_tm->tm_sec);
174 std::string datestr(now_str);
175 std::string verstr=COMPILEDES_VERSION;
177 Output() <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
180 Output() <<
"<project" << std::endl;
181 Output() <<
" xmlns=\"http://www.plcopen.org/xml/tc6.xsd\"" << std::endl;
182 Output() <<
" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"" << std::endl;
183 Output() <<
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << std::endl;
184 Output() <<
" xsi:schemaLocation=\"http://www.plcopen.org/xml/tc6.xsd http://www.plcopen.org/xml/tc6.xsd\" >" << std::endl;
186 Output() <<
"<project" << std::endl;
187 Output() <<
" xmlns=\"http://www.plcopen.org/xml/tc6_0201\"" << std::endl;
188 Output() <<
" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"" << std::endl;
189 Output() <<
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << std::endl;
190 Output() <<
" xsi:schemaLocation=\"http://www.plcopen.org/xml/tc6_0201 http://www.plcopen.org/xml/tc6.xsd\" >" << std::endl;
192 Output() <<
"<project>" << std::endl;
195 Output() <<
"<fileHeader" << std::endl;
197 Output() <<
" creationDateTime=\"" << datestr <<
"\"" << std::endl;
198 Output() <<
" productName=\"CompileDES\"" << std::endl;
199 Output() <<
" productVersion=\"" << verstr <<
"\" />" << std::endl;
201 Output() <<
"<contentHeader" << std::endl;
206 Output() <<
" >" << std::endl;
208 Output() <<
" <coordinateInfo>" << std::endl;
209 Output() <<
" <fbd><scaling x=\"1\" y=\"1\"/></fbd>" << std::endl;
210 Output() <<
" <ld><scaling x=\"1\" y=\"1\"/></ld>" << std::endl;
211 Output() <<
" <sfc><scaling x=\"1\" y=\"1\"/></sfc>" << std::endl;
212 Output() <<
" </coordinateInfo>" << std::endl;
214 Output() <<
"</contentHeader>" << std::endl;
216 Output() <<
"<types>" << std::endl;
218 Output() <<
"<dataTypes />" << std::endl;
220 Output() <<
"<pous>" << std::endl;
223 Output() <<
"</pous>" << std::endl;
224 Output() <<
"</types>" << std::endl;
226 Output() <<
"<instances>" << std::endl;
227 Output() <<
" <configurations />" << std::endl;
228 Output() <<
"</instances>" << std::endl;
230 Output() <<
"</project>" << std::endl;
235 Output() <<
"<pou name=\"" <<
mPrefix <<
"cyclic_fb" <<
"\" pouType=\"functionBlock\">" << std::endl;
237 Output() <<
"<interface>" << std::endl;
242 Output() <<
"</interface>" << std::endl;
244 Output() <<
"<body>" << std::endl;
245 Output() <<
"<ST>" << std::endl;
252 Output() <<
"</ST>" << std::endl;
253 Output() <<
"</body>" << std::endl;
254 Output() <<
"</pou>" << std::endl;
266 Output() <<
"<inputVars retain=\"false\">" << std::endl;
270 Output() <<
"</inputVars>" << std::endl;
276 Output() <<
"<outputVars retain=\"false\">" << std::endl;
283 Output() <<
"</outputVars>" << std::endl;
289 Output() <<
"<localVars retain=\"false\">" << std::endl;
303 Output() <<
"</localVars>" << std::endl;
311 Output() <<
"<externalVars>" << std::endl;
316 Output() <<
"</externalVars>" << std::endl;
320 Output() <<
"<externalVars>" << std::endl;
324 Output() <<
"</externalVars>" << std::endl;
334 Comment(
"************************************************");
335 Comment(
"CodeGenerator: Target IEC 61131 Structured Text ");
336 Comment(
"************************************************");
346 Comment(
"************************************************");
347 Comment(
"CodeGenerator: Generated Code Ends Here ");
348 Comment(
"************************************************");
355 std::string lineaddr= lit->second.mAddress;
356 if(lineaddr.size()<1)
continue;
357 if(lineaddr.at(0)==
'%') {
358 Output() <<
"<variable name=\"\" address=\"" << lineaddr <<
"\">";
361 Output() <<
"<type> <BOOL /> </type>";
363 XmlDocumentation(
"physical input");
366 Output() <<
"</variable>";
372 if(!ait->second.mSetClr)
continue;
373 std::string actaddr= ait->second.mAddress;
374 if(actaddr.size()<1)
continue;
375 if(actaddr.at(0)==
'%') {
376 Output() <<
"<variable name=\"\" address=\"" << actaddr <<
"\">";
379 Output() <<
"<type> <BOOL /> </type>";
381 XmlDocumentation(
"physical output");
384 Output() <<
"</variable>";
395 Output() <<
"<pou name=\"" <<
mPrefix <<
"event_lookup_f" <<
"\" pouType=\"function\">" << std::endl;
397 Output() <<
"<interface>" << std::endl;
400 Output() <<
"<returnType> <string /> </returnType>" << std::endl;
402 Output() <<
"<inputVars retain=\"false\">" << std::endl;
403 Output() <<
" <variable name=\"IDX\">" << std::endl;
406 XmlDocumentation(
"event index");
408 Output() <<
" </variable>" << std::endl;
409 Output() <<
"</inputVars>" << std::endl;
413 Output() <<
"<localVars retain=\"false\" constant=\"true\">" << std::endl;
417 Output() <<
"</localVars>" << std::endl;
422 Output() <<
"</interface>" << std::endl;
424 Output() <<
"<body>" << std::endl;
425 Output() <<
"<ST>" << std::endl;
431 Output() <<
"</ST>" << std::endl;
432 Output() <<
"</body>" << std::endl;
433 Output() <<
"</pou>" << std::endl;
437 Output() <<
"<pou name=\"" <<
mPrefix <<
"state_lookup_f" <<
"\" pouType=\"function\">" << std::endl;
439 Output() <<
"<interface>" << std::endl;
442 Output() <<
"<returnType> <string /> </returnType>" << std::endl;
444 Output() <<
"<inputVars retain=\"false\">" << std::endl;
445 Output() <<
" <variable name=\"GID\">" << std::endl;
448 XmlDocumentation(
"generator id");
450 Output() <<
" </variable>" << std::endl;
451 Output() <<
" <variable name=\"IDX\">" << std::endl;
454 XmlDocumentation(
"state index");
456 Output() <<
" </variable>" << std::endl;
457 Output() <<
"</inputVars>" << std::endl;
461 Output() <<
"<localVars retain=\"false\" constant=\"true\">" << std::endl;
465 Output() <<
"</localVars>" << std::endl;
470 Output() <<
"</interface>" << std::endl;
472 Output() <<
"<body>" << std::endl;
473 Output() <<
"<ST>" << std::endl;
477 Output() <<
"CASE GID OF";
479 for(
size_t gid=0; gid<
Size(); ++gid) {
481 Output() << ToStringInteger(gid) <<
": " 482 <<
mPrefix <<
"state_lookup_f" <<
" := " <<
mPrefix <<
"state_lookup_" << ToStringInteger(gid) <<
"[IDX]" <<
";";
487 Output() <<
"IF LEN(" <<
mPrefix <<
"state_lookup_f) = 0 THEN";
495 Output() <<
"</ST>" << std::endl;
496 Output() <<
"</body>" << std::endl;
497 Output() <<
"</pou>" << std::endl;
515 void PlcoxmlCodeGenerator::XmlBeginPlainText() {
517 Output() <<
"<xhtml xmlns=\"http://www.w3.org/1999/xhtml\">";
528 void PlcoxmlCodeGenerator::XmlEndPlainText() {
542 void PlcoxmlCodeGenerator::XmlDocumentation(
const std::string& text) {
543 Output() <<
"<documentation>";
547 Output() <<
"</documentation>";
552 Output() <<
"<variable name=\"" << laddr <<
"\">";
556 Output() <<
"<type> <" << ltype <<
" /> </type>";
557 }
else if((ltype ==
"TON") || (ltype ==
"STRING")) {
558 Output() <<
"<type> <derived name=\"" << ltype <<
"\" /> </type>";
560 FCG_ERR(
"PlcoxmlCodeGenerator::VariableDeclare(): unsupported type [" << ltype <<
"]");
566 Output() <<
"</variable>";
572 Output() <<
"<variable name=\"" << laddr <<
"\">";
576 Output() <<
"<type> <" << ltype <<
" /> </type>";
578 FCG_ERR(
"PlcoxmlCodeGenerator::VariableDeclare(): unsupported type [" << ltype <<
"]");
581 Output() <<
"<initialValue> <simpleValue value=\"" << lval <<
"\" /> </initialValue>";
586 Output() <<
"</variable>";
595 FCG_ERR(
"PlcoxmlCodeGenerator::Cintarray(): ignoring empty const vector");
599 FCG_ERR(
"PlcoxmlCodeGenerator::Cintarray(): const vector exceeds addres range");
609 Output() <<
" <dimension lower=\"" << offset <<
"\" upper=\"" << val.size()+offset-1 <<
"\" />";
617 Output() <<
"<initialValue> ";
619 Output() <<
" <arrayValue> ";
621 for(
size_t i=0; i<val.size(); ++i) {
625 Output() <<
" </arrayValue> ";
627 Output() <<
"</initialValue> ";
632 Output() <<
"</variable>";
639 FCG_ERR(
"PlcoxmlCodeGenerator::Cwordarray(): ignoring empty const vector");
643 FCG_ERR(
"PlcoxmlCodeGenerator::Cwordarray(): const vector exceeds addres range");
653 Output() <<
" <dimension lower=\"" << offset <<
"\" upper=\"" << val.size()+offset-1 <<
"\" />";
661 Output() <<
"<initialValue> ";
663 Output() <<
" <arrayValue> ";
665 for(
size_t i=0; i<val.size(); ++i) {
666 Output() <<
" <value> <simpleValue value=\"" <<
WordConstant(val[i]) <<
"\" /> </value>";
669 Output() <<
" </arrayValue> ";
671 Output() <<
"</initialValue> ";
676 Output() <<
"</variable>";
684 FCG_ERR(
"PlcoxmlCodeGenerator::Cstrarray(): ignoring empty const vector");
688 FCG_ERR(
"PlcoxmlCodeGenerator::Cstrarray(): const vector exceeds address range");
693 for(
size_t i=0; i<val.size(); ++i)
694 if(val[i].size()>len) len=val[i].size();
703 Output() <<
" <dimension lower=\"" << offset <<
"\" upper=\"" << val.size()+offset-1 <<
"\" />";
705 Output() <<
" <baseType> <string length=\"" << ToStringInteger(len) <<
"\" /> </baseType>";
711 Output() <<
"<initialValue> ";
713 Output() <<
" <arrayValue> ";
715 for(
size_t i=0; i<val.size(); ++i) {
716 Output() <<
" <value> <simpleValue value=\"";
722 Output()<<
"\" /> </value>";
725 Output() <<
" </arrayValue> ";
727 Output() <<
"</initialValue> ";
732 Output() <<
"</variable>";
744 FCG_ERR(
"PlcoxmlCodeGenerator::Intarray(): ignoring empty const vector");
748 FCG_ERR(
"PlcoxmlCodeGenerator::Intarray(): const vector exceeds addres range");
758 Output() <<
" <dimension lower=\"" << offset <<
"\" upper=\"" << len+offset-1 <<
"\" />";
769 Output() <<
"</variable>";
782 FCG_ERR(
"PlcoxmlCodeGenerator::Wordarray(): ignoring empty const vector");
786 FCG_ERR(
"PlcoxmlCodeGenerator::Wordarray(): const vector exceeds addres range");
796 Output() <<
" <dimension lower=\"" << offset <<
"\" upper=\"" << len+offset-1 <<
"\" />";
807 Output() <<
"</variable>";
#define FAUDES_REGISTERCODEGENERATOR(ftype, ctype)
Class registration macro.
virtual void DoGenerateCyclicCode(void)
cut-and-paste template for code snippet assembly
Idx Size(void) const
Number of generators.
void DoGenerate(void)
code generation hook (overall)
Code-generator PlcOpen XML (IEC 61131-3 ST)
virtual void WordarrayDeclare(const AA &address, int offset, int len)
generate code: conditionals
std::string mIecContentVersion
option: xml entry content header "version"
virtual void DeclareStatus(void)
Declare "status".
LineIterator LinesEnd()
Access to line records by iterator.
virtual void DeclareRecentEvent(void)
Declare "recent_event".
virtual void LiteralCyclic(void)
generate code: conditionals
virtual void XmlCdataEscape(bool on)
XmlCdataEscape (escape "]]>")
void DoGenerateInterface(void)
code generation (cyclic function, interface)
std::string mIecContentOrganization
option: xml entry content header "company"
virtual std::ostream & Output(void)
Output stream.
virtual void DoGenerateResetCode(void)
cut-and-paste template for code snippet assembly
virtual void VariableDeclare(const std::string &ladd, const std::string <ype)
generate code: conditionals
Implementation of primitives by IEC 61131 ST.
virtual void CstrarrayDeclare(const AA &address, int offset, const std::vector< std::string > &val)
generate code: conditionals
virtual void LineFeed(int lines=1)
LineFeed (convenience support for derived classes)
virtual std::string TargetAddress(const AA &address)
abstract address conversion
virtual AX StringConstant(const std::string &val)
generate code: conditionals
std::string mLiteralCyclic
option: extra cyclic code
virtual void MuteComments(bool on)
Mute comments (convenience support for derived classes)
std::string mLiteralAppend
extra code to prepend
std::string mName
faudes object name (aka project name)
virtual AX IntegerConstant(int val)
generate code: conditionals
Target PlcOpen XML (IEC 61131-3 ST)
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
File i/o.
virtual void DeclareSmallCarray(void)
Declare bit-mask loop-ups.
virtual void CwordarrayDeclare(const AA &address, int offset, const std::vector< word_t > &val)
generate code: conditionals
virtual void DoReadTargetConfiguration(TokenReader &rTr)
File i/o.
virtual void DeclareAux(void)
Declare variables local to the provided snippets, e.g. helpers for bit-mask computation.
void DoGenerateLookups(void)
code generation hook (symbolic name lookup functions)
virtual void DeclareLargeCarray(void)
Declare compiled transition relations.
void DoGenerateFunction(void)
code generation hook (cyclic function)
virtual void DeclareImportSymbolicIo(void)
generate code: conditionals
virtual void DeclareReset(void)
Declare "reset".
void DoGenerateBody(void)
code generation (cyclicg function, st body)
virtual void DeclareTimers(void)
generate code: conditionals
virtual void IndentInc()
Indentation (convenience support for derived classes)
virtual void Clear(void)
Clear all data.
virtual void IntarrayDeclare(const AA &address, int offset, int len)
generate code: conditionals
static std::string VersionString(void)
Version (refers to macro COMPILEDES_VERSION, defined in cgp_codegenerator.h)
std::string mIntegerType
target data type for integer
virtual void DeclareStateNameLookup(void)
Declare symbolic name lookup tables.
virtual void DeclareParallelState(void)
Declare "parallel_state".
virtual const std::string & Name(void) const
Get objects's name (reimplementing base faudes::Type)
int mIntegerSize
compressed boolean capacity of target type integer
virtual AX WordConstant(word_t val)
generate code: conditionals
std::map< std::string, ActionAddress >::iterator ActionAddressIterator
Access to action record by iterator.
std::string mWordType
target data type for word
virtual void DeclareLoopState(void)
Declare loop state, i.e. line levels, loop flag.
bool mEventNameLookup
code option: event name lookup
std::string mIecDeclarePhysical
option: formal declaration of io lines
std::string RecentComment(void)
Recent muted comment (convenience support for derived classes)
virtual void DeclarePendingEvents(void)
Declare "pending_events" and "enabled_events".
std::string mIecContentAuthor
option: xml entry content header "author"
std::string mIecSchemeVersion
option: plcopen-xml version "v1.01" or "v2.01"
virtual void XmlTextEscape(bool on)
XmlTextEscape (escape "<", ">", "&", "\"" and "'")
virtual int CountImportSymbolicIo(void)
generate code: conditionals
ActionAddressIterator ActionAddressesBegin()
Access to action addresses by iterator.
virtual void DeclareEventNameLookup(void)
Declare symbolic name lookup tables.
std::string mIecTextElement
option: plain text xml-element "cdata", "xhtml", or "pre"
virtual void Clear(void)
Clear all data.
Abstract address; see also Absstract_Addresses.
virtual int CountImportPhysicalIo(void)
generate code: conditionals
bool mStateNameLookup
code option: state name lookup
virtual void CintarrayDeclare(const AA &address, int offset, const std::vector< int > &val)
generate code: conditionals
ActionAddressIterator ActionAddressesEnd()
Access to action addresses by iterator.
std::string mPrefix
universal prefix (pseudo name space)
virtual ~PlcoxmlCodeGenerator(void)
Explicit destructor.
virtual void IndentDec()
Indentation (convenience support for derived classes)
virtual void DeclareSystime(void)
generate code: conditionals
std::map< std::string, LineAddress >::iterator LineIterator
Access to line records by iterator.
bool mHasIecTimeOperators
option: overloaded operators for time maths
std::string mIecToolVendor
option: xml entry file header "company"
virtual void DoReadTargetConfiguration(TokenReader &rTr)
File i/o.
virtual void DecrementTimers(void)
code snippet
std::map< std::string, bitarray_rec > mBitarrays
Record of all declared bit-arrays.
std::string mLiteralPrepend
extra code to prepend
LineIterator LinesBegin()
Access to line records by iterator.
virtual void Comment(const std::string &text)
generate code: conditionals
virtual void MuteVspace(bool on)
Mute empty lines (convenience support for derived classes)
virtual void DeclareImportPhysicalIo(void)
generate code: conditionals
virtual void DoWriteTargetConfiguration(TokenWriter &rTw) const
File i/o.
PlcoxmlCodeGenerator(void)
Constructor.
std::vector< bool > mHasStateNames
record per generator whether there is a lookup table