Skip to content

Compile to IEC 61131-10 XML - Omron - #1896

Open
DoubleCouponDay wants to merge 35 commits into
PLC-lang:masterfrom
DoubleCouponDay:omron-xml-target
Open

Compile to IEC 61131-10 XML - Omron#1896
DoubleCouponDay wants to merge 35 commits into
PLC-lang:masterfrom
DoubleCouponDay:omron-xml-target

Conversation

@DoubleCouponDay

@DoubleCouponDay DoubleCouponDay commented Aug 28, 2026

Copy link
Copy Markdown

Based on my discussion post here, I've implemented XML generation as a first class compilation target. For now, the implementation focuses on a subset of Structured Text that is compatible with Sysmac Studio. All that is required is to add the --xml-omron argument. the new plc_xmlgen module is portable enough to handle other specific subsets in the future (eg: CODESYS).

Here is an example of usage:

plc ./source/clampandsaw.st ./source/testallbuiltins.st --xml-omron --generate-external-constructors -i ./externals/stdlib_externals.st -i ./externals/omron_externals.st -L ./compiled -l iec61131std -l libNX1P2 -l ws2_32 -l ntdll -l userenv -o ./compiled/lib_structured_text.xml

For this to work, the builtins of a specific PLC device are compiled into a separate library which can be linked to. As a result, VAR_EXTERNAL and VAR_EXTERNAL CONSTANT had to fixed. Without external references to a stub library, none of the references to built in constants, types, and global functions could compile.

To be clear, Sysmac does not support the following ST syntax:

  • no POINTER TO
  • no REFERENCE TO
  • no WSTRING
  • no CLASS
  • no INTERFACE
  • no ALIAS TO

Unit tests have been added to confirm the feature.

Here is a concise list of changes made in this PR:

New XML export target

  • Added compiler/plc_xmlgen crate: xml_gen.rs generator plus a serializer.rs typed node builder for IEC 61131-10 Ed1 XML.
  • Added --xml-omron CLI flag and a GenerationParameters struct threaded into codegen.
  • Added FormatOption::XML with .xml output naming in plc_project and the codegen participant.
  • Added GeneratedModule::persist_to_xml that sits alongside the object/IR/bitcode arms.
  • PipelineParticipant::generate now receives &AnnotatedProject and &CompileOptions so the generator can see the AST.

Type rendering for Sysmac

  • Emits only StructTypeSpec and EnumTypeWithNamedValueSpec declarations; The two Sysmac actually accepts.
  • Resolves aliases, arrays and strings into inline TypeName text instead of declaring them.
  • Renders arrays as ARRAY[0..3] OF X, multi-dimensional as ARRAY[0..1,1..3] OF X with no space after the separator.
  • Renders strings as String[n], defaulting to a length of 80 characters.
  • Recursively resolves nested element types through alias chains, with a hop limit guarding self-referential aliases. The max amount of recursion depth is 16.

VAR_EXTERNAL behaviour

  • The initializer lowering now skips VAR_EXTERNAL blocks, so variables from a linked library are no longer initialised a second time.
  • Removed the E106 "VAR_EXTERNAL blocks have no effect" warning and its diagnostic entry, doc file and tests.

New diagnostic

  • Added E152 (error) for constructs the chosen XML target cannot represent, with a markdown doc page.
  • plc_xmlgen scans user types, globals, POU variable blocks and struct members, skipping external linkage and compiler-generated declarations.

Supporting changes

  • Added Display impls for AstLiteral, Array, Date, Time, TimeOfDay and DateAndTime so literals can be serialised as text.
  • Lowercased VariableBlockType's Display output to match the XML attribute vocabulary.
  • Fixed Windows MSVC linking in the stdlib integration test harness (/MD, explicit exports and system libs).
  • Documented the new target in book/src/using_rusty.md.

@DoubleCouponDay
DoubleCouponDay marked this pull request as draft August 28, 2026 04:37
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.03573% with 447 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.90%. Comparing base (1e70538) to head (c0461a8).
⚠️ Report is 223 commits behind head on master.

Files with missing lines Patch % Lines
compiler/plc_xmlgen/src/serializer.rs 24.30% 218 Missing ⚠️
compiler/plc_xmlgen/src/xml_gen.rs 83.28% 120 Missing ⚠️
compiler/plc_ast/src/literals.rs 9.75% 37 Missing ⚠️
src/codegen.rs 6.45% 29 Missing ⚠️
libs/stdlib/tests/common/mod.rs 0.00% 13 Missing ⚠️
compiler/plc_driver/src/pipelines.rs 65.38% 9 Missing ⚠️
compiler/plc_driver/src/pipelines/participant.rs 58.82% 7 Missing ⚠️
xtask/src/reporter/sysout.rs 0.00% 4 Missing ⚠️
src/linker.rs 50.00% 2 Missing ⚠️
compiler/plc_ast/src/ast.rs 93.33% 1 Missing ⚠️
... and 7 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1896      +/-   ##
==========================================
- Coverage   94.68%   92.90%   -1.78%     
==========================================
  Files         188      197       +9     
  Lines       58726    78883   +20157     
==========================================
+ Hits        55603    73285   +17682     
- Misses       3123     5598    +2475     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DoubleCouponDay

Copy link
Copy Markdown
Author

Hey @volsa @ghaith. My Pull Request is finally ready for review. I'm excited to share this with everyone so let me know if you have any feedback. 😄

@DoubleCouponDay
DoubleCouponDay marked this pull request as ready for review September 4, 2026 08:38
@DoubleCouponDay

Copy link
Copy Markdown
Author

The 'PR Artifacts' stage of the pipeline is failing with "HttpError: Resource not accessible by integration". How can that be fixed?

Also, the oscat tool in the 'Metrics' stage is failing due to missing support for the INT_TO_STRING built-in function.

@volsa

volsa commented Sep 7, 2026

Copy link
Copy Markdown
Member

Hi, thanks for the contribution!

Just as a heads-up, we have quite a lot going on at the moment so it may take us a little while to find the time to review this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants