Introduced BEPolicy and LEPolicy.

This commit is contained in:
Markus F.X.J. Oberhumer 2006-06-14 14:45:49 +02:00
parent 7daf63fd3f
commit 75120676ad
2 changed files with 226 additions and 44 deletions

View File

@ -239,7 +239,7 @@ inline int get_le32_signed(const void *p)
return sign_extend(v, 32);
}
inline int get_le64_signed(const void *p)
inline acc_int64l_t get_le64_signed(const void *p)
{
acc_int64l_t v = get_le64(p);
return sign_extend(v, 64);
@ -476,6 +476,168 @@ int __acc_cdecl_qsort le64_compare_signed(const void *, const void *);
#endif
/*************************************************************************
//
**************************************************************************/
namespace NBELE {
struct BEPolicy
{
enum { isBE = 1, isLE = 0 };
typedef BE16 U16;
typedef BE32 U32;
typedef BE64 U64;
static inline unsigned get16(const void *p)
{ return get_be16(p); }
static inline unsigned get24(const void *p)
{ return get_be24(p); }
static inline unsigned get32(const void *p)
{ return get_be32(p); }
static inline acc_uint64l_t get64(const void *p)
{ return get_be64(p); }
static inline void set16(void *p, unsigned v)
{ set_be16(p, v); }
static inline void set24(void *p, unsigned v)
{ set_be24(p, v); }
static inline void set32(void *p, unsigned v)
{ set_be32(p, v); }
static inline void set64(void *p, acc_uint64l_t v)
{ set_be64(p, v); }
static inline unsigned get16_signed(const void *p)
{ return get_be16_signed(p); }
static inline unsigned get24_signed(const void *p)
{ return get_be24_signed(p); }
static inline unsigned get32_signed(const void *p)
{ return get_be32_signed(p); }
static inline acc_uint64l_t get64_signed(const void *p)
{ return get_be64_signed(p); }
static int __acc_cdecl_qsort u16_compare(const void *a, const void *b)
{ return be16_compare(a, b); }
static int __acc_cdecl_qsort u24_compare(const void *a, const void *b)
{ return be24_compare(a, b); }
static int __acc_cdecl_qsort u32_compare(const void *a, const void *b)
{ return be32_compare(a, b); }
static int __acc_cdecl_qsort u64_compare(const void *a, const void *b)
{ return be64_compare(a, b); }
static int __acc_cdecl_qsort u16_compare_signed(const void *a, const void *b)
{ return be16_compare_signed(a, b); }
static int __acc_cdecl_qsort u24_compare_signed(const void *a, const void *b)
{ return be24_compare_signed(a, b); }
static int __acc_cdecl_qsort u32_compare_signed(const void *a, const void *b)
{ return be32_compare_signed(a, b); }
static int __acc_cdecl_qsort u64_compare_signed(const void *a, const void *b)
{ return be64_compare_signed(a, b); }
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
COMPILE_TIME_ASSERT_ALIGNOF(U16, char)
COMPILE_TIME_ASSERT_ALIGNOF(U32, char)
COMPILE_TIME_ASSERT_ALIGNOF(U64, char)
}
};
struct LEPolicy
{
enum { isBE = 0, isLE = 1 };
typedef LE16 U16;
typedef LE32 U32;
typedef LE64 U64;
static inline unsigned get16(const void *p)
{ return get_le16(p); }
static inline unsigned get24(const void *p)
{ return get_le24(p); }
static inline unsigned get32(const void *p)
{ return get_le32(p); }
static inline acc_uint64l_t get64(const void *p)
{ return get_le64(p); }
static inline void set16(void *p, unsigned v)
{ set_le16(p, v); }
static inline void set24(void *p, unsigned v)
{ set_le24(p, v); }
static inline void set32(void *p, unsigned v)
{ set_le32(p, v); }
static inline void set64(void *p, acc_uint64l_t v)
{ set_le64(p, v); }
static inline unsigned get16_signed(const void *p)
{ return get_le16_signed(p); }
static inline unsigned get24_signed(const void *p)
{ return get_le24_signed(p); }
static inline unsigned get32_signed(const void *p)
{ return get_le32_signed(p); }
static inline acc_uint64l_t get64_signed(const void *p)
{ return get_le64_signed(p); }
static int __acc_cdecl_qsort u16_compare(const void *a, const void *b)
{ return le16_compare(a, b); }
static int __acc_cdecl_qsort u24_compare(const void *a, const void *b)
{ return le24_compare(a, b); }
static int __acc_cdecl_qsort u32_compare(const void *a, const void *b)
{ return le32_compare(a, b); }
static int __acc_cdecl_qsort u64_compare(const void *a, const void *b)
{ return le64_compare(a, b); }
static int __acc_cdecl_qsort u16_compare_signed(const void *a, const void *b)
{ return le16_compare_signed(a, b); }
static int __acc_cdecl_qsort u24_compare_signed(const void *a, const void *b)
{ return le24_compare_signed(a, b); }
static int __acc_cdecl_qsort u32_compare_signed(const void *a, const void *b)
{ return le32_compare_signed(a, b); }
static int __acc_cdecl_qsort u64_compare_signed(const void *a, const void *b)
{ return le64_compare_signed(a, b); }
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
COMPILE_TIME_ASSERT_ALIGNOF(U16, char)
COMPILE_TIME_ASSERT_ALIGNOF(U32, char)
COMPILE_TIME_ASSERT_ALIGNOF(U64, char)
}
};
#if (ACC_ABI_BIG_ENDIAN)
typedef BEPolicy HostPolicy;
#elif (ACC_ABI_LITTLE_ENDIAN)
typedef LEPolicy HostPolicy;
#else
# error "ACC_ABI_ENDIAN"
#endif
struct HostAlignedPolicy
{
enum { isBE = HostPolicy::isBE, isLE = HostPolicy::isLE };
typedef acc_uint16e_t U16;
typedef acc_uint32e_t U32;
typedef acc_uint64l_t U64;
static void compileTimeAssertions() {
COMPILE_TIME_ASSERT(sizeof(U16) == 2)
COMPILE_TIME_ASSERT(sizeof(U32) == 4)
COMPILE_TIME_ASSERT(sizeof(U64) == 8)
}
};
} // namespace NBELE
#endif /* already included */

View File

@ -192,7 +192,7 @@ struct Shdr
}
__attribute_packed;
template <class TT16, class TT32, class TT64>
template <class TT16, class TT32>
struct Sym
{
TT32 st_name; /* symbol name (index into string table) */
@ -239,6 +239,7 @@ __attribute_packed;
} // namespace TT_Elf32
namespace TT_Elf64 {
// Program segment header.
@ -309,39 +310,62 @@ __attribute_packed;
} // namespace TT_Elf64
/*************************************************************************
// now for the actual types
**************************************************************************/
typedef TT_Elf ::Ehdr<unsigned int,unsigned int,unsigned int,unsigned short> Elf32_Ehdr;
typedef TT_Elf32::Phdr<unsigned int,unsigned int,unsigned int> Elf32_Phdr;
typedef TT_Elf32::Shdr<unsigned int,unsigned int,unsigned int> Elf32_Shdr;
typedef TT_Elf ::Dyn <unsigned int,unsigned int> Elf32_Dyn;
typedef TT_Elf32::Sym <unsigned short,unsigned int,void> Elf32_Sym;
#define P NBELE::HostPolicy
typedef TT_Elf ::Ehdr<P::U32,P::U32,P::U32,P::U16> Elf32_Ehdr;
typedef TT_Elf32::Phdr<P::U32,P::U32,P::U32> Elf32_Phdr;
typedef TT_Elf32::Shdr<P::U32,P::U32,P::U32> Elf32_Shdr;
typedef TT_Elf ::Dyn <P::U32,P::U32> Elf32_Dyn;
typedef TT_Elf32::Sym <P::U16,P::U32> Elf32_Sym;
#undef P
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Ehdr) == 52)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Phdr) == 32)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Shdr) == 40)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Dyn) == 8)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Sym) == 16)
#define P NBELE::BEPolicy
typedef TT_Elf ::Ehdr<P::U32,P::U32,P::U32,P::U16> Elf_BE32_Ehdr;
typedef TT_Elf32::Phdr<P::U32,P::U32,P::U32> Elf_BE32_Phdr;
typedef TT_Elf32::Shdr<P::U32,P::U32,P::U32> Elf_BE32_Shdr;
typedef TT_Elf ::Dyn <P::U32,P::U32> Elf_BE32_Dyn;
typedef TT_Elf32::Sym <P::U16,P::U32> Elf_BE32_Sym;
#undef P
typedef TT_Elf ::Ehdr<LE32,LE32,LE32,LE16> Elf_LE32_Ehdr;
typedef TT_Elf32::Phdr<LE32,LE32,LE32> Elf_LE32_Phdr;
typedef TT_Elf32::Shdr<LE32,LE32,LE32> Elf_LE32_Shdr;
typedef TT_Elf ::Dyn <LE32,LE32> Elf_LE32_Dyn;
typedef TT_Elf32::Sym <LE16,LE32,void> Elf_LE32_Sym;
#define P NBELE::LEPolicy
typedef TT_Elf ::Ehdr<P::U32,P::U32,P::U32,P::U16> Elf_LE32_Ehdr;
typedef TT_Elf32::Phdr<P::U32,P::U32,P::U32> Elf_LE32_Phdr;
typedef TT_Elf32::Shdr<P::U32,P::U32,P::U32> Elf_LE32_Shdr;
typedef TT_Elf ::Dyn <P::U32,P::U32> Elf_LE32_Dyn;
typedef TT_Elf32::Sym <P::U16,P::U32> Elf_LE32_Sym;
#undef P
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Ehdr) == 52)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Phdr) == 32)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Shdr) == 40)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Dyn) == 8)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Sym) == 16)
#define P NBELE::HostPolicy
typedef TT_Elf ::Ehdr<P::U32,P::U64,P::U64,P::U16> Elf64_Ehdr;
typedef TT_Elf64::Phdr<P::U32,P::U64,P::U64,P::U64> Elf64_Phdr;
typedef TT_Elf64::Shdr<P::U32,P::U64,P::U64,P::U64> Elf64_Shdr;
typedef TT_Elf ::Dyn <P::U64,P::U64> Elf64_Dyn;
#undef P
typedef TT_Elf ::Ehdr<BE32,BE32,BE32,BE16> Elf_BE32_Ehdr;
typedef TT_Elf32::Phdr<BE32,BE32,BE32> Elf_BE32_Phdr;
typedef TT_Elf32::Shdr<BE32,BE32,BE32> Elf_BE32_Shdr;
typedef TT_Elf ::Dyn <BE32,BE32> Elf_BE32_Dyn;
typedef TT_Elf32::Sym <BE16,BE32,void> Elf_BE32_Sym;
#define P NBELE::BEPolicy
typedef TT_Elf ::Ehdr<P::U32,P::U64,P::U64,P::U16> Elf_BE64_Ehdr;
typedef TT_Elf64::Phdr<P::U32,P::U64,P::U64,P::U64> Elf_BE64_Phdr;
typedef TT_Elf64::Shdr<P::U32,P::U64,P::U64,P::U64> Elf_BE64_Shdr;
typedef TT_Elf ::Dyn <P::U64,P::U64> Elf_BE64_Dyn;
#undef P
#define P NBELE::LEPolicy
typedef TT_Elf ::Ehdr<P::U32,P::U64,P::U64,P::U16> Elf_LE64_Ehdr;
typedef TT_Elf64::Phdr<P::U32,P::U64,P::U64,P::U64> Elf_LE64_Phdr;
typedef TT_Elf64::Shdr<P::U32,P::U64,P::U64,P::U64> Elf_LE64_Shdr;
typedef TT_Elf ::Dyn <P::U64,P::U64> Elf_LE64_Dyn;
#undef P
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Ehdr) == 52)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Phdr) == 32)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Shdr) == 40)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Dyn) == 8)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf32_Sym) == 16)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Ehdr) == 52)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Phdr) == 32)
@ -349,31 +373,27 @@ ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Shdr) == 40)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Dyn) == 8)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE32_Sym) == 16)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Ehdr) == 52)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Phdr) == 32)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Shdr) == 40)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Dyn) == 8)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE32_Sym) == 16)
typedef TT_Elf ::Ehdr<LE32,LE64,LE64,LE16> Elf_LE64_Ehdr;
typedef TT_Elf64::Phdr<LE32,LE64,LE64,LE64> Elf_LE64_Phdr;
typedef TT_Elf64::Shdr<LE32,LE64,LE64,LE64> Elf_LE64_Shdr;
typedef TT_Elf ::Dyn <LE64,LE64> Elf_LE64_Dyn;
typedef TT_Elf ::Ehdr<unsigned int,unsigned long long,
unsigned long long,unsigned short> Elf64_Ehdr;
typedef TT_Elf64::Phdr<unsigned int,unsigned long long,
unsigned long long,unsigned long long> Elf64_Phdr;
typedef TT_Elf64::Shdr<unsigned int,unsigned long long,
unsigned long long,unsigned long long> Elf64_Shdr;
typedef TT_Elf ::Dyn <unsigned long long,unsigned long long> Elf64_Dyn;
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Ehdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Phdr) == 56)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Shdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Dyn) == 16)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE64_Ehdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE64_Phdr) == 56)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE64_Shdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_BE64_Dyn) == 16)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Ehdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Phdr) == 56)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Shdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf_LE64_Dyn) == 16)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Ehdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Phdr) == 56)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Shdr) == 64)
ACC_COMPILE_TIME_ASSERT_HEADER(sizeof(Elf64_Dyn) == 16)
#endif /* already included */