mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
148 lines
2.8 KiB
C++
148 lines
2.8 KiB
C++
/**
|
|
* @file
|
|
* @brief Helper for useful compiler features.
|
|
*/
|
|
#ifndef STA_CORE_LANG_HPP
|
|
#define STA_CORE_LANG_HPP
|
|
|
|
#include <sta/config.hpp>
|
|
|
|
|
|
/**
|
|
* @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
|
|
|
|
|
|
/**
|
|
* @brief A macro for concatenating preprocessor tokens A and B without expanding them.
|
|
* @param A first preprocessor token.
|
|
* @param B second preprocessor token.
|
|
*/
|
|
#ifndef STA_CONCAT_NX
|
|
# define STA_CONCAT_NX(A, B) A ## B
|
|
#endif // !STA_CONCAT_NX
|
|
|
|
|
|
/**
|
|
* @brief Macro-expands A and B first and concatenates them afterwards.
|
|
* @param A first preprocessor token.
|
|
* @param B second preprocessor token.
|
|
*/
|
|
#ifndef STA_CONCAT
|
|
# define STA_CONCAT(A, B) STA_CONCAT_NX(A, B)
|
|
#endif // !STA_CONCAT
|
|
|
|
|
|
/** @} */
|
|
|
|
#endif // STA_CORE_LANG_HPP
|