/** * @file * @brief Helper for useful compiler features. */ #ifndef STA_CORE_LANG_HPP #define STA_CORE_LANG_HPP #include /** * @defgroup sta_core_lang Lang * @ingroup sta_core * @brief Compiler instructions. * @{ */ /** * @brief Assembler instruction. */ #ifndef STA_ASM # define STA_ASM __asm #endif // STA_ASM /** * @brief Mark as deprecated. */ #ifndef STA_DEPRECATED # define STA_DEPRECATED __attribute__((deprecated)) #endif // STA_DEPRECATED /** * @brief Mark as weak definition. */ #ifndef STA_WEAK # define STA_WEAK __attribute__((weak)) #endif // STA_WEAK /** * @brief Mark as field w/o added padding. */ #ifndef STA_PACKED # define STA_PACKED __attribute__((packed)) #endif // STA_PACKED /** * @brief Mark as struct w/o added padding. */ #ifndef STA_PACKED_STRUCT # define STA_PACKED_STRUCT struct STA_PACKED #endif // STA_PACKED_STRUCT /** * @brief Mark as union w/o added padding. */ #ifndef STA_PACKED_UNION # define STA_PACKED_UNION union STA_PACKED #endif // STA_PACKED_UNION /** * @brief Add breakpoint. * * @param value Additional uint16_t data for debugger */ #ifndef STA_BKPT # define STA_BKPT(value) STA_ASM volatile ("bkpt "#value) #endif // STA_BKPT // TODO Check for GCC /** * @brief Silencing compiler warnings in unreachable code locations. * * Example: * @code * enum class E { A }; * * E val = A; * * switch (val) * { * case E::A: * break; * * default: * // All enum values already handled * STA_UNREACHABLE(); * } * @endcode */ #ifndef STA_UNREACHABLE # define STA_UNREACHABLE() __builtin_unreachable() #endif // !STA_UNREACHABLE /** * @brief A macro for marking code as not implemented. Causes a program to * crash with the appropriate error message if the code is executed. */ #ifndef STA_NOT_IMPLEMENTED # define STA_NOT_IMPLEMENTED() // throw "myFunction is not implemented yet."; #endif // !STA_NOT_IMPLEMENTED /** * @brief Silencing compiler warnings for intended switch case fallthrough. * * Example: * @code * switch (val) * { * case A: STA_FALLTHROUGH(); * case B: * do(); * break; * } * @endcode */ #ifndef STA_FALLTRHOUGH # define STA_FALLTHROUGH() __attribute__((fallthrough)) #endif // !STA_FALLTRHOUGH /** @} */ #endif // STA_CORE_LANG_HPP