rtcompiler.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (c) 2006-2024, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2024-01-18 Shell Separate the compiler porting from rtdef.h
  9. */
  10. #ifndef __RT_COMPILER_H__
  11. #define __RT_COMPILER_H__
  12. #include <rtconfig.h>
  13. #if defined(__ARMCC_VERSION) /* ARM Compiler */
  14. #define rt_section(x) __attribute__((section(x)))
  15. #define rt_used __attribute__((used))
  16. #define rt_align(n) __attribute__((aligned(n)))
  17. #if __ARMCC_VERSION >= 6010050
  18. #define rt_packed(declare) declare __attribute__((packed))
  19. #else
  20. #define rt_packed(declare) declare
  21. #endif
  22. #define rt_weak __attribute__((weak))
  23. #define rt_typeof __typeof
  24. #define rt_noreturn
  25. #define rt_inline static __inline
  26. #define rt_always_inline rt_inline
  27. #elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
  28. #define rt_section(x) @ x
  29. #define rt_used __root
  30. #define PRAGMA(x) _Pragma(#x)
  31. #define rt_align(n) PRAGMA(data_alignment=n)
  32. #define rt_packed(declare) declare
  33. #define rt_weak __weak
  34. #define rt_typeof __typeof
  35. #define rt_noreturn
  36. #define rt_inline static inline
  37. #define rt_always_inline rt_inline
  38. #elif defined (__GNUC__) /* GNU GCC Compiler */
  39. #define __RT_STRINGIFY(x...) #x
  40. #define RT_STRINGIFY(x...) __RT_STRINGIFY(x)
  41. #define rt_section(x) __attribute__((section(x)))
  42. #define rt_used __attribute__((used))
  43. #define rt_align(n) __attribute__((aligned(n)))
  44. #define rt_packed(declare) declare __attribute__((packed))
  45. #define rt_weak __attribute__((weak))
  46. #define rt_typeof __typeof__
  47. #define rt_noreturn __attribute__ ((noreturn))
  48. #define rt_inline static __inline
  49. #define rt_always_inline static inline __attribute__((always_inline))
  50. #elif defined (__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
  51. #define rt_section(x) __attribute__((section(x)))
  52. #define rt_used __attribute__((used))
  53. #define rt_align(n) __attribute__((aligned(n)))
  54. #define rt_packed(declare) declare
  55. #define rt_weak __attribute__((weak))
  56. #define rt_typeof typeof
  57. #define rt_noreturn
  58. #define rt_inline static inline
  59. #define rt_always_inline rt_inline
  60. #elif defined (_MSC_VER) /* for Visual Studio Compiler */
  61. #define rt_section(x)
  62. #define rt_used
  63. #define rt_align(n) __declspec(align(n))
  64. #define rt_packed(declare) __pragma(pack(push, 1)) declare __pragma(pack(pop))
  65. #define rt_weak
  66. #define rt_typeof typeof
  67. #define rt_noreturn
  68. #define rt_inline static __inline
  69. #define rt_always_inline rt_inline
  70. #elif defined (__TI_COMPILER_VERSION__) /* for TI CCS Compiler */
  71. /**
  72. * The way that TI compiler set section is different from other(at least
  73. * GCC and MDK) compilers. See ARM Optimizing C/C++ Compiler 5.9.3 for more
  74. * details.
  75. */
  76. #define rt_section(x) __attribute__((section(x)))
  77. #ifdef __TI_EABI__
  78. #define rt_used __attribute__((retain)) __attribute__((used))
  79. #else
  80. #define rt_used __attribute__((used))
  81. #endif
  82. #define PRAGMA(x) _Pragma(#x)
  83. #define rt_align(n) __attribute__((aligned(n)))
  84. #define rt_packed(declare) declare __attribute__((packed))
  85. #ifdef __TI_EABI__
  86. #define rt_weak __attribute__((weak))
  87. #else
  88. #define rt_weak
  89. #endif
  90. #define rt_typeof typeof
  91. #define rt_noreturn
  92. #define rt_inline static inline
  93. #define rt_always_inline rt_inline
  94. #elif defined (__TASKING__) /* for TASKING Compiler */
  95. #define rt_section(x) __attribute__((section(x)))
  96. #define rt_used __attribute__((used, protect))
  97. #define PRAGMA(x) _Pragma(#x)
  98. #define rt_align(n) __attribute__((__align(n)))
  99. #define rt_packed(declare) declare __packed__
  100. #define rt_weak __attribute__((weak))
  101. #define rt_typeof typeof
  102. #define rt_noreturn
  103. #define rt_inline static inline
  104. #define rt_always_inline rt_inline
  105. #else /* Unkown Compiler */
  106. #error not supported tool chain
  107. #endif /* __ARMCC_VERSION */
  108. #endif /* __RT_COMPILER_H__ */