mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-26 05:32:25 +00:00
129d7d3bde
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43099 91177308-0d34-0410-b5e6-96231b3b80d8
49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
//===--- AlignOf.h - Portable calculation of type alignment -----*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file was developed by Ted Kremenek and is distributed under
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines the AlignOf function that computes alignments for
|
|
// arbitrary types.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_SUPPORT_ALIGNOF_H
|
|
#define LLVM_SUPPORT_ALIGNOF_H
|
|
|
|
namespace llvm {
|
|
|
|
template <typename T>
|
|
struct AlignmentCalcImpl {
|
|
char x;
|
|
T t;
|
|
private:
|
|
AlignmentCalcImpl() {} // Never instantiate.
|
|
};
|
|
|
|
/// AlignOf - A templated class that contains an enum value representing
|
|
/// the alignment of the template argument. For example,
|
|
/// AlignOf<int>::Alignment represents the alignment of type "int". The
|
|
/// alignment calculated is the minimum alignment, and not necessarily
|
|
/// the "desired" alignment returned by GCC's __alignof__ (for example). Note
|
|
/// that because the alignment is an enum value, it can be used as a
|
|
/// compile-time constant (e.g., for template instantiation).
|
|
template <typename T>
|
|
struct AlignOf {
|
|
enum { Alignment = sizeof(AlignmentCalcImpl<T>) - sizeof(T) };
|
|
};
|
|
|
|
/// alignof - A templated function that returns the mininum alignment of
|
|
/// of a type. This provides no extra functionality beyond the AlignOf
|
|
/// class besides some cosmetic cleanliness. Example usage:
|
|
/// alignof<int>() returns the alignment of an int.
|
|
template <typename T>
|
|
static inline unsigned alignof() { return AlignOf<T>::Alignment; }
|
|
|
|
} // end namespace llvm
|
|
#endif
|