123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- #ifndef LLVM_SUPPORT_ALIGNOF_H
- #define LLVM_SUPPORT_ALIGNOF_H
- #include <cstddef>
- namespace objc {
- template <typename T>
- struct AlignmentCalcImpl {
- char x;
- T t;
- private:
- AlignmentCalcImpl() {}
- };
- template <typename T>
- struct AlignOf {
- enum { Alignment =
- static_cast<unsigned int>(sizeof(AlignmentCalcImpl<T>) - sizeof(T)) };
- enum { Alignment_GreaterEqual_2Bytes = Alignment >= 2 ? 1 : 0 };
- enum { Alignment_GreaterEqual_4Bytes = Alignment >= 4 ? 1 : 0 };
- enum { Alignment_GreaterEqual_8Bytes = Alignment >= 8 ? 1 : 0 };
- enum { Alignment_GreaterEqual_16Bytes = Alignment >= 16 ? 1 : 0 };
- enum { Alignment_LessEqual_2Bytes = Alignment <= 2 ? 1 : 0 };
- enum { Alignment_LessEqual_4Bytes = Alignment <= 4 ? 1 : 0 };
- enum { Alignment_LessEqual_8Bytes = Alignment <= 8 ? 1 : 0 };
- enum { Alignment_LessEqual_16Bytes = Alignment <= 16 ? 1 : 0 };
- };
- template <typename T>
- inline unsigned alignOf() { return AlignOf<T>::Alignment; }
- template <size_t Alignment> struct AlignedCharArrayImpl;
- #ifndef _MSC_VER
- #if __has_feature(cxx_alignas)
- #define LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
- template <> struct AlignedCharArrayImpl<x> { \
- char aligned alignas(x); \
- }
- #elif defined(__GNUC__)
- #define LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
- template <> struct AlignedCharArrayImpl<x> { \
- char aligned __attribute__((aligned(x))); \
- }
- #else
- # error No supported align as directive.
- #endif
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(1);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(2);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(4);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(8);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(16);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(32);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(64);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(128);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(512);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(1024);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(2048);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(4096);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(8192);
- #undef LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
- #else
- template <> struct AlignedCharArrayImpl<1> { char aligned; };
- template <> struct AlignedCharArrayImpl<2> { short aligned; };
- template <> struct AlignedCharArrayImpl<4> { int aligned; };
- template <> struct AlignedCharArrayImpl<8> { double aligned; };
- #define LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(x) \
- template <> struct AlignedCharArrayImpl<x> { \
- __declspec(align(x)) char aligned; \
- }
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(16);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(32);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(64);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(128);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(512);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(1024);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(2048);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(4096);
- LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT(8192);
- #undef LLVM_ALIGNEDCHARARRAY_TEMPLATE_ALIGNMENT
- #endif
- template <typename T1,
- typename T2 = char, typename T3 = char, typename T4 = char>
- union AlignedCharArrayUnion {
- private:
- class AlignerImpl {
- T1 t1; T2 t2; T3 t3; T4 t4;
- AlignerImpl();
- };
- union SizerImpl {
- char arr1[sizeof(T1)], arr2[sizeof(T2)], arr3[sizeof(T3)], arr4[sizeof(T4)];
- };
- public:
-
-
-
-
- char buffer[sizeof(SizerImpl)];
- private:
-
-
-
- AlignedCharArrayImpl<AlignOf<AlignerImpl>::Alignment> nonce_member;
- };
- }
- #endif
|