mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2025-01-19 19:33:32 +08:00
d8db49c17a
__ARMCC_VERSION: https://smtp.keil.com/support/man/docs/armcc/armcc_chr1359124980173.htm __IAR_SYSTEMS_ICC__: <Not Found> __GNUC__: https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#index-packed-type-attribute __ADSPBLACKFIN__: <Not Found> _MSC_VER: https://learn.microsoft.com/en-us/cpp/preprocessor/pack?view=msvc-170 __TI_COMPILER_VERSION__: https://software-dl.ti.com/codegen/docs/tiarmclang/rel1_3_0_LTS/migration_guide/migrating_c_and_cpp_source/pragmas_and_attributes.html __TASKING__: https://resources.tasking.com/sites/default/files/2021-02/TASKING_Alignment%20Requirements%20Restrictions_WEB.pdf Usage: ```c rt_packed(struct object1 { int dword; char byte; }); typedef struct object1 object1; rt_packed(struct object2 { int dword; char byte; }); ``` Signed-off-by: GuEe-GUI <2991707448@qq.com>
112 lines
4.6 KiB
C
112 lines
4.6 KiB
C
/*
|
|
* Copyright (c) 2006-2024, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2024-01-18 Shell Separate the compiler porting from rtdef.h
|
|
*/
|
|
#ifndef __RT_COMPILER_H__
|
|
#define __RT_COMPILER_H__
|
|
|
|
#include <rtconfig.h>
|
|
|
|
#if defined(__ARMCC_VERSION) /* ARM Compiler */
|
|
#define rt_section(x) __attribute__((section(x)))
|
|
#define rt_used __attribute__((used))
|
|
#define rt_align(n) __attribute__((aligned(n)))
|
|
#if __ARMCC_VERSION >= 6010050
|
|
#define rt_packed(declare) declare __attribute__((packed))
|
|
#else
|
|
#define rt_packed(declare) declare
|
|
#endif
|
|
#define rt_weak __attribute__((weak))
|
|
#define rt_typeof typeof
|
|
#define rt_noreturn
|
|
#define rt_inline static __inline
|
|
#define rt_always_inline rt_inline
|
|
#elif defined (__IAR_SYSTEMS_ICC__) /* for IAR Compiler */
|
|
#define rt_section(x) @ x
|
|
#define rt_used __root
|
|
#define PRAGMA(x) _Pragma(#x)
|
|
#define rt_align(n) PRAGMA(data_alignment=n)
|
|
#define rt_packed(declare) declare
|
|
#define rt_weak __weak
|
|
#define rt_typeof __typeof
|
|
#define rt_noreturn
|
|
#define rt_inline static inline
|
|
#define rt_always_inline rt_inline
|
|
#elif defined (__GNUC__) /* GNU GCC Compiler */
|
|
#define __RT_STRINGIFY(x...) #x
|
|
#define RT_STRINGIFY(x...) __RT_STRINGIFY(x)
|
|
#define rt_section(x) __attribute__((section(x)))
|
|
#define rt_used __attribute__((used))
|
|
#define rt_align(n) __attribute__((aligned(n)))
|
|
#define rt_packed(declare) declare __attribute__((packed))
|
|
#define rt_weak __attribute__((weak))
|
|
#define rt_typeof __typeof__
|
|
#define rt_noreturn __attribute__ ((noreturn))
|
|
#define rt_inline static __inline
|
|
#define rt_always_inline static inline __attribute__((always_inline))
|
|
#elif defined (__ADSPBLACKFIN__) /* for VisualDSP++ Compiler */
|
|
#define rt_section(x) __attribute__((section(x)))
|
|
#define rt_used __attribute__((used))
|
|
#define rt_align(n) __attribute__((aligned(n)))
|
|
#define rt_packed(declare) declare
|
|
#define rt_weak __attribute__((weak))
|
|
#define rt_typeof typeof
|
|
#define rt_noreturn
|
|
#define rt_inline static inline
|
|
#define rt_always_inline rt_inline
|
|
#elif defined (_MSC_VER) /* for Visual Studio Compiler */
|
|
#define rt_section(x)
|
|
#define rt_used
|
|
#define rt_align(n) __declspec(align(n))
|
|
#define rt_packed(declare) __pragma(pack(push, 1)) declare __pragma(pack(pop))
|
|
#define rt_weak
|
|
#define rt_typeof typeof
|
|
#define rt_noreturn
|
|
#define rt_inline static __inline
|
|
#define rt_always_inline rt_inline
|
|
#elif defined (__TI_COMPILER_VERSION__) /* for TI CCS Compiler */
|
|
/**
|
|
* The way that TI compiler set section is different from other(at least
|
|
* GCC and MDK) compilers. See ARM Optimizing C/C++ Compiler 5.9.3 for more
|
|
* details.
|
|
*/
|
|
#define rt_section(x) __attribute__((section(x)))
|
|
#ifdef __TI_EABI__
|
|
#define rt_used __attribute__((retain)) __attribute__((used))
|
|
#else
|
|
#define rt_used __attribute__((used))
|
|
#endif
|
|
#define PRAGMA(x) _Pragma(#x)
|
|
#define rt_align(n) __attribute__((aligned(n)))
|
|
#define rt_packed(declare) declare __attribute__((packed))
|
|
#ifdef __TI_EABI__
|
|
#define rt_weak __attribute__((weak))
|
|
#else
|
|
#define rt_weak
|
|
#endif
|
|
#define rt_typeof typeof
|
|
#define rt_noreturn
|
|
#define rt_inline static inline
|
|
#define rt_always_inline rt_inline
|
|
#elif defined (__TASKING__) /* for TASKING Compiler */
|
|
#define rt_section(x) __attribute__((section(x)))
|
|
#define rt_used __attribute__((used, protect))
|
|
#define PRAGMA(x) _Pragma(#x)
|
|
#define rt_align(n) __attribute__((__align(n)))
|
|
#define rt_packed(declare) declare __packed__
|
|
#define rt_weak __attribute__((weak))
|
|
#define rt_typeof typeof
|
|
#define rt_noreturn
|
|
#define rt_inline static inline
|
|
#define rt_always_inline rt_inline
|
|
#else /* Unkown Compiler */
|
|
#error not supported tool chain
|
|
#endif /* __ARMCC_VERSION */
|
|
|
|
#endif /* __RT_COMPILER_H__ */
|