rtcompiler.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #define rt_weak __attribute__((weak))
  18. #define rt_typeof typeof
  19. #define rt_noreturn
  20. #define rt_inline static __inline
  21. #define rt_always_inline rt_inline
  22. #elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
  23. #define rt_section(x) @ x
  24. #define rt_used __root
  25. #define PRAGMA(x) _Pragma(#x)
  26. #define rt_align(n) PRAGMA(data_alignment=n)
  27. #define rt_weak __weak
  28. #define rt_typeof __typeof
  29. #define rt_noreturn
  30. #define rt_inline static inline
  31. #define rt_always_inline rt_inline
  32. #elif defined (__GNUC__) /* GNU GCC Compiler */
  33. #define __RT_STRINGIFY(x...) #x
  34. #define RT_STRINGIFY(x...) __RT_STRINGIFY(x)
  35. #define rt_section(x) __attribute__((section(x)))
  36. #define rt_used __attribute__((used))
  37. #define rt_align(n) __attribute__((aligned(n)))
  38. #define rt_weak __attribute__((weak))
  39. #define rt_typeof __typeof__
  40. #define rt_noreturn __attribute__ ((noreturn))
  41. #define rt_inline static __inline
  42. #define rt_always_inline static inline __attribute__((always_inline))
  43. #elif defined (__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
  44. #define rt_section(x) __attribute__((section(x)))
  45. #define rt_used __attribute__((used))
  46. #define rt_align(n) __attribute__((aligned(n)))
  47. #define rt_weak __attribute__((weak))
  48. #define rt_typeof typeof
  49. #define rt_noreturn
  50. #define rt_inline static inline
  51. #define rt_always_inline rt_inline
  52. #elif defined (_MSC_VER) /* for Visual Studio Compiler */
  53. #define rt_section(x)
  54. #define rt_used
  55. #define rt_align(n) __declspec(align(n))
  56. #define rt_weak
  57. #define rt_typeof typeof
  58. #define rt_noreturn
  59. #define rt_inline static __inline
  60. #define rt_always_inline rt_inline
  61. #elif defined (__TI_COMPILER_VERSION__) /* for TI CCS Compiler */
  62. /**
  63. * The way that TI compiler set section is different from other(at least
  64. * GCC and MDK) compilers. See ARM Optimizing C/C++ Compiler 5.9.3 for more
  65. * details.
  66. */
  67. #define rt_section(x) __attribute__((section(x)))
  68. #ifdef __TI_EABI__
  69. #define rt_used __attribute__((retain)) __attribute__((used))
  70. #else
  71. #define rt_used __attribute__((used))
  72. #endif
  73. #define PRAGMA(x) _Pragma(#x)
  74. #define rt_align(n) __attribute__((aligned(n)))
  75. #ifdef __TI_EABI__
  76. #define rt_weak __attribute__((weak))
  77. #else
  78. #define rt_weak
  79. #endif
  80. #define rt_typeof typeof
  81. #define rt_noreturn
  82. #define rt_inline static inline
  83. #define rt_always_inline rt_inline
  84. #elif defined (__TASKING__) /* for TASKING Compiler */
  85. #define rt_section(x) __attribute__((section(x)))
  86. #define rt_used __attribute__((used, protect))
  87. #define PRAGMA(x) _Pragma(#x)
  88. #define rt_align(n) __attribute__((__align(n)))
  89. #define rt_weak __attribute__((weak))
  90. #define rt_typeof typeof
  91. #define rt_noreturn
  92. #define rt_inline static inline
  93. #define rt_always_inline rt_inline
  94. #else /* Unkown Compiler */
  95. #error not supported tool chain
  96. #endif /* __ARMCC_VERSION */
  97. #endif /* __RT_COMPILER_H__ */