mesh_compiler.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * SPDX-FileCopyrightText: 2010-2014,2017 Wind River Systems, Inc.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _BLE_MESH_COMPILER_H_
  7. #define _BLE_MESH_COMPILER_H_
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define ___in_section(a, b, c)
  12. #define __in_section(a, b, c) ___in_section(a, b, c)
  13. #define __in_section_unique(seg) ___in_section(seg, __FILE__, __COUNTER__)
  14. #ifndef __packed
  15. #define __packed __attribute__((__packed__))
  16. #endif
  17. #ifndef __aligned
  18. #define __aligned(x) __attribute__((__aligned__(x)))
  19. #endif
  20. #ifndef __used
  21. #define __used __attribute__((__used__))
  22. #endif
  23. #ifndef ARG_UNUSED
  24. #define ARG_UNUSED(x) (void)(x)
  25. #endif
  26. #ifndef popcount
  27. #define popcount(x) __builtin_popcount(x)
  28. #endif
  29. #ifndef ALWAYS_INLINE
  30. #define ALWAYS_INLINE inline __attribute__((always_inline))
  31. #endif
  32. /*
  33. * This is meant to be used in conjunction with __in_section() and similar
  34. * where scattered structure instances are concatened together by the linker
  35. * and walked by the code at run time just like a contiguous array of such
  36. * structures.
  37. *
  38. * Assemblers and linkers may insert alignment padding by default whose
  39. * size is larger than the natural alignment for those structures when
  40. * gathering various section segments together, messing up the array walk.
  41. * To prevent this, we need to provide an explicit alignment not to rely
  42. * on the default that might just work by luck.
  43. *
  44. * Alignment statements in linker scripts are not sufficient as
  45. * the assembler may add padding by itself to each segment when switching
  46. * between sections within the same file even if it merges many such segments
  47. * into a single section in the end.
  48. */
  49. #ifndef Z_DECL_ALIGN
  50. #define Z_DECL_ALIGN(type) __aligned(__alignof(type)) type
  51. #endif
  52. /*
  53. * Convenience helper combining __in_section() and Z_DECL_ALIGN().
  54. * The section name is the struct type prepended with an underscore.
  55. * The subsection is "static" and the subsubsection is the variable name.
  56. */
  57. #ifndef Z_STRUCT_SECTION_ITERABLE
  58. #define Z_STRUCT_SECTION_ITERABLE(struct_type, name) \
  59. Z_DECL_ALIGN(struct struct_type) name
  60. #endif
  61. #ifdef __cplusplus
  62. }
  63. #endif
  64. #endif /* _BLE_MESH_COMPILER_H_ */