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;
475 Output() <<
mPrefix <<
"state_lookup_f" <<
" := 'out_of_range';";
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]" <<
";";
484 Output() << ToStringInteger(gid) <<
": "
485 <<
mPrefix <<
"state_lookup_f" <<
" := CONCAT('s'," <<
mIntegerType <<
"_TO_STRING(IDX))" <<
";";
492 Output() <<
"</ST>" << std::endl;
493 Output() <<
"</body>" << std::endl;
494 Output() <<
"</pou>" << std::endl;
512 void PlcoxmlCodeGenerator::XmlBeginPlainText() {
514 Output() <<
"<xhtml xmlns=\"http://www.w3.org/1999/xhtml\">";
525 void PlcoxmlCodeGenerator::XmlEndPlainText() {
539 void PlcoxmlCodeGenerator::XmlDocumentation(
const std::string& text) {
540 Output() <<
"<documentation>";
544 Output() <<
"</documentation>";
549 Output() <<
"<variable name=\"" << laddr <<
"\">";
553 Output() <<
"<type> <" << ltype <<
" /> </type>";
554 }
else if((ltype ==
"TON") || (ltype ==
"STRING")) {
555 Output() <<
"<type> <derived name=\"" << ltype <<
"\" /> </type>";
557 FCG_ERR(
"PlcoxmlCodeGenerator::VariableDeclare(): unsupported type [" << ltype <<
"]");
563 Output() <<
"</variable>";
569 Output() <<
"<variable name=\"" << laddr <<
"\">";
573 Output() <<
"<type> <" << ltype <<
" /> </type>";
575 FCG_ERR(
"PlcoxmlCodeGenerator::VariableDeclare(): unsupported type [" << ltype <<
"]");
578 Output() <<
"<initialValue> <simpleValue value=\"" << lval <<
"\" /> </initialValue>";
583 Output() <<
"</variable>";
592 FCG_ERR(
"PlcoxmlCodeGenerator::Cintarray(): ignoring empty const vector");
596 FCG_ERR(
"PlcoxmlCodeGenerator::Cintarray(): const vector exceeds addres range");
606 Output() <<
" <dimension lower=\"0\" upper=\"" << val.size()-1 <<
"\" />";
614 Output() <<
"<initialValue> ";
616 Output() <<
" <arrayValue> ";
618 for(
size_t i=0; i<val.size(); ++i) {
622 Output() <<
" </arrayValue> ";
624 Output() <<
"</initialValue> ";
629 Output() <<
"</variable>";
636 FCG_ERR(
"PlcoxmlCodeGenerator::Cwordarray(): ignoring empty const vector");
640 FCG_ERR(
"PlcoxmlCodeGenerator::Cwordarray(): const vector exceeds addres range");
650 Output() <<
" <dimension lower=\"0\" upper=\"" << val.size()-1 <<
"\" />";
658 Output() <<
"<initialValue> ";
660 Output() <<
" <arrayValue> ";
662 for(
size_t i=0; i<val.size(); ++i) {
663 Output() <<
" <value> <simpleValue value=\"" <<
WordConstant(val[i]) <<
"\" /> </value>";
666 Output() <<
" </arrayValue> ";
668 Output() <<
"</initialValue> ";
673 Output() <<
"</variable>";
681 FCG_ERR(
"PlcoxmlCodeGenerator::Cstrarray(): ignoring empty const vector");
685 FCG_ERR(
"PlcoxmlCodeGenerator::Cstrarray(): const vector exceeds address range");
690 for(
size_t i=0; i<val.size(); ++i)
691 if(val[i].size()>len) len=val[i].size();
700 Output() <<
" <dimension lower=\"0\" upper=\"" << val.size()-1 <<
"\" />";
702 Output() <<
" <baseType> <string length=\"" << ToStringInteger(len) <<
"\" /> </baseType>";
708 Output() <<
"<initialValue> ";
710 Output() <<
" <arrayValue> ";
712 for(
size_t i=0; i<val.size(); ++i) {
713 Output() <<
" <value> <simpleValue value=\"";
719 Output()<<
"\" /> </value>";
722 Output() <<
" </arrayValue> ";
724 Output() <<
"</initialValue> ";
729 Output() <<
"</variable>";
741 FCG_ERR(
"PlcoxmlCodeGenerator::Intarray(): ignoring empty const vector");
745 FCG_ERR(
"PlcoxmlCodeGenerator::Intarray(): const vector exceeds addres range");
755 Output() <<
" <dimension lower=\"0\" upper=\"" << len-1 <<
"\" />";
766 Output() <<
"</variable>";
779 FCG_ERR(
"PlcoxmlCodeGenerator::Wordarray(): ignoring empty const vector");
783 FCG_ERR(
"PlcoxmlCodeGenerator::Wordarray(): const vector exceeds addres range");
793 Output() <<
" <dimension lower=\"0\" upper=\"" << len-1 <<
"\" />";
804 Output() <<
"</variable>";