Add %MX (bool memory) support for OpenPLC v4#23
Conversation
- 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 EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Comment |
There was a problem hiding this comment.
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_ptrpointer declaration andsetBufferPointers_v4function in glueVars.c template - Added %MX case handling in GlueGenerator to generate v4-specific glue code
- All new code is wrapped in
#ifdef OPENPLC_V4preprocessor 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.
| # %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" |
There was a problem hiding this comment.
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.
| f" bool_memory_ptr[{pos1}][{pos2}] = (IEC_BOOL *){varName};\n" | |
| f"bool_memory_ptr[{pos1}][{pos2}] = (IEC_BOOL *){varName};\n" |
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_memorybuffer.Changes:
bool_memory_ptrpointer declaration under#ifdef OPENPLC_V4in glueVars.c.j2setBufferPointers_v4function that includes thememory_boolparameter for %MX supportGlueGenerator.__glue_logicthat generates glue code wrapped in#ifdef OPENPLC_V4This 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_v4signature in glueVars.c.j2 must exactly match theext_setBufferPointers_v4declaration in openplc-runtime'simage_tables.h. Parameter order matters -memory_boolshould be the last parameter.Verify pointer type: Confirm
IEC_BOOL *(*bool_memory_ptr)[8]matches the runtime'sbool_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_V4and 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_V4flag to compile.sh and thesetBufferPointers_v4symbol lookup in the runtime.Link to Devin run: https://app.devin.ai/sessions/a39db7c299fb417481ba9800b03995c3
Requested by: Thiago Alves (thiago.alves@autonomylogic.com) / @thiagoralves