Skip to content

Add %MX (bool memory) support for OpenPLC v4#23

Merged
thiagoralves merged 1 commit into
developmentfrom
devin/1767677247-mx-gluevars-support
Jan 6, 2026
Merged

Add %MX (bool memory) support for OpenPLC v4#23
thiagoralves merged 1 commit into
developmentfrom
devin/1767677247-mx-gluevars-support

Conversation

@devin-ai-integration
Copy link
Copy Markdown

Summary

This PR adds support for %MX (boolean memory) located variables in the generated glueVars.c code, enabling OpenPLC v4 runtime to connect %MX variables to the new bool_memory buffer.

Changes:

  • Added bool_memory_ptr pointer declaration under #ifdef OPENPLC_V4 in glueVars.c.j2
  • Added setBufferPointers_v4 function that includes the memory_bool parameter for %MX support
  • Added %MX case to GlueGenerator.__glue_logic that generates glue code wrapped in #ifdef OPENPLC_V4

This is a companion PR to openplc-runtime PR #63 which adds the runtime infrastructure for %MX support.

Review & Testing Checklist for Human

  • Verify function signature match: The setBufferPointers_v4 signature in glueVars.c.j2 must exactly match the ext_setBufferPointers_v4 declaration in openplc-runtime's image_tables.h. Parameter order matters - memory_bool should be the last parameter.

  • Verify pointer type: Confirm IEC_BOOL *(*bool_memory_ptr)[8] matches the runtime's bool_memory[BUFFER_SIZE][8] array type.

  • Test end-to-end: Create a PLC program with %MX variables (e.g., %MX0.0, %MX1.5), compile it with openplc-runtime (which passes -DOPENPLC_V4), and verify the generated glueVars.c contains the bool_memory_ptr assignments.

  • Test v3 compatibility: Compile the same program without -DOPENPLC_V4 and verify the %MX glue code is excluded and compilation succeeds.

Notes

This PR requires openplc-runtime PR beremiz#63 to be merged first, as that PR adds the -DOPENPLC_V4 flag to compile.sh and the setBufferPointers_v4 symbol lookup in the runtime.

Link to Devin run: https://app.devin.ai/sessions/a39db7c299fb417481ba9800b03995c3
Requested by: Thiago Alves (thiago.alves@autonomylogic.com) / @thiagoralves

- Add bool_memory_ptr declaration under #ifdef OPENPLC_V4 in glueVars.c.j2
- Add setBufferPointers_v4 function with bool_memory parameter under #ifdef OPENPLC_V4
- Add %MX case to GlueGenerator.__glue_logic wrapped in #ifdef OPENPLC_V4

When compiled with -DOPENPLC_V4 flag (set in openplc-runtime compile.sh),
the generated glueVars.c will include:
- bool_memory_ptr pointer for %MX variables
- setBufferPointers_v4 function that the runtime calls to pass bool_memory

This enables %MX located variables to be glued to the runtime's bool_memory
buffer, completing the %MX support added in openplc-runtime PR beremiz#63.

For v3 compatibility, the %MX glue code is excluded when OPENPLC_V4 is not
defined, so the same template works for both v3 and v4 runtimes.

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 6, 2026

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@thiagoralves thiagoralves requested a review from Copilot January 6, 2026 20:12
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for %MX (boolean memory) located variables in OpenPLC v4, enabling the compiler to generate glue code that connects %MX variables to the runtime's bool_memory buffer. This is a companion change to openplc-runtime PR beremiz#63.

  • Added bool_memory_ptr pointer declaration and setBufferPointers_v4 function in glueVars.c template
  • Added %MX case handling in GlueGenerator to generate v4-specific glue code
  • All new code is wrapped in #ifdef OPENPLC_V4 preprocessor directives for backward compatibility

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
templates/glueVars.c.j2 Adds bool_memory_ptr declaration and setBufferPointers_v4 function for v4 runtime integration
GlueGenerator.py Adds %MX case to __glue_logic to generate bool_memory_ptr assignments wrapped in OPENPLC_V4 guards

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread GlueGenerator.py
# %MX (bool memory) is only supported in OpenPLC v4
return (
f"#ifdef OPENPLC_V4\n"
f" bool_memory_ptr[{pos1}][{pos2}] = (IEC_BOOL *){varName};\n"
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation in the generated code uses 4 spaces, but other cases in this function (lines 69-73) generate code without leading spaces. This inconsistency could lead to improperly formatted output. Consider removing the leading spaces from line 65 to match the pattern used by other memory types.

Suggested change
f" bool_memory_ptr[{pos1}][{pos2}] = (IEC_BOOL *){varName};\n"
f"bool_memory_ptr[{pos1}][{pos2}] = (IEC_BOOL *){varName};\n"

Copilot uses AI. Check for mistakes.
@thiagoralves thiagoralves merged commit 9131cae into development Jan 6, 2026
6 of 7 checks passed
@thiagoralves thiagoralves deleted the devin/1767677247-mx-gluevars-support branch January 6, 2026 20:15
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