From e6e0d0b41a0165c9216ef9f51c9dbd9743648887 Mon Sep 17 00:00:00 2001 From: Thiago Alves Date: Wed, 15 Apr 2026 00:33:01 -0400 Subject: [PATCH] fix: AVR compatibility for runtime headers - iec_located.hpp: Relax static_assert for LocatedVar size to only enforce on 64-bit platforms (AVR pointers are 2 bytes, not 8) - iec_traits.hpp: Rename template params B1/B2/B3 to Bnd1/Bnd2/Bnd3 to avoid collision with Arduino's binary.h macros (B0-B7) - iec_array.hpp: Add explicit #include (implicit on full stdlib, required when using minimal AVR C++ headers) - iec_enum.hpp: Guard #include and operator<< with #ifndef __AVR__ (I/O streams unavailable on AVR) Non-AVR platforms are unchanged. All 1505 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/runtime/include/iec_array.hpp | 1 + src/runtime/include/iec_enum.hpp | 4 ++++ src/runtime/include/iec_located.hpp | 8 +++++--- src/runtime/include/iec_traits.hpp | 8 ++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/runtime/include/iec_array.hpp b/src/runtime/include/iec_array.hpp index 261198a..b81f70b 100644 --- a/src/runtime/include/iec_array.hpp +++ b/src/runtime/include/iec_array.hpp @@ -14,6 +14,7 @@ #include #include +#include #ifndef __AVR__ #include #endif diff --git a/src/runtime/include/iec_enum.hpp b/src/runtime/include/iec_enum.hpp index c51354e..4941309 100644 --- a/src/runtime/include/iec_enum.hpp +++ b/src/runtime/include/iec_enum.hpp @@ -13,7 +13,9 @@ #pragma once #include +#ifndef __AVR__ #include +#endif #include #include "iec_var.hpp" @@ -213,12 +215,14 @@ class IEC_ENUM_Var { template using IEC_ENUM = IEC_ENUM_Var; +#ifndef __AVR__ // Stream output for IEC_ENUM_Var — outputs underlying integer value template inline std::ostream& operator<<(std::ostream& os, const IEC_ENUM_Var& v) { return os << static_cast::type>( static_cast(v)); } +#endif /* * Example generated enumeration: diff --git a/src/runtime/include/iec_located.hpp b/src/runtime/include/iec_located.hpp index 177a869..852e6b7 100644 --- a/src/runtime/include/iec_located.hpp +++ b/src/runtime/include/iec_located.hpp @@ -120,9 +120,11 @@ struct LocatedVar { } }; -// Verify expected layout -static_assert(sizeof(LocatedVar) == 16, "LocatedVar should be 16 bytes"); -static_assert(alignof(LocatedVar) == 8, "LocatedVar should be 8-byte aligned"); +// Verify expected layout (size varies by platform: 16 bytes on 64-bit, 8 on 32-bit, 6 on AVR) +#if INTPTR_MAX == INT64_MAX +static_assert(sizeof(LocatedVar) == 16, "LocatedVar should be 16 bytes on 64-bit"); +static_assert(alignof(LocatedVar) == 8, "LocatedVar should be 8-byte aligned on 64-bit"); +#endif // ============================================================================= // Helper Functions for Address Parsing diff --git a/src/runtime/include/iec_traits.hpp b/src/runtime/include/iec_traits.hpp index 588b338..9eae9a7 100644 --- a/src/runtime/include/iec_traits.hpp +++ b/src/runtime/include/iec_traits.hpp @@ -382,11 +382,11 @@ template struct is_iec_array : std::false_type {}; template struct is_iec_array> : std::true_type {}; -template -struct is_iec_array> : std::true_type {}; +template +struct is_iec_array> : std::true_type {}; -template -struct is_iec_array> : std::true_type {}; +template +struct is_iec_array> : std::true_type {}; template inline constexpr bool is_iec_array_v = is_iec_array::value;