Make frontend endian-aware.

In many parts the DMD frontend assumes a little endian CPU. In some
parts there are checks for endianess but they are incomplete and the
used definition is wrong. (Test for endianess will be removed in dmd
2.062.)
In this commit I add the required #if's and also add a CMake test for
endianess because there is no single compiler definition to check for.
This commit is contained in:
kai
2013-01-21 08:41:21 +01:00
parent 9e9acb9c4b
commit 55560bf382
5 changed files with 121 additions and 0 deletions

View File

@@ -544,20 +544,46 @@ bool Module::read(Loc loc)
inline unsigned readwordLE(unsigned short *p)
{
#if IN_LLVM
#if __LITTLE_ENDIAN__
return *p;
#else
return (((unsigned char *)p)[1] << 8) | ((unsigned char *)p)[0];
#endif
#else
#if LITTLE_ENDIAN
return *p;
#else
return (((unsigned char *)p)[1] << 8) | ((unsigned char *)p)[0];
#endif
#endif
}
inline unsigned readwordBE(unsigned short *p)
{
#if IN_LLVM
#if __BIG_ENDIAN__
return *p;
#else
return (((unsigned char *)p)[0] << 8) | ((unsigned char *)p)[1];
#endif
#else
return (((unsigned char *)p)[0] << 8) | ((unsigned char *)p)[1];
#endif
}
inline unsigned readlongLE(unsigned *p)
{
#if IN_LLVM
#if __LITTLE_ENDIAN__
return *p;
#else
return ((unsigned char *)p)[0] |
(((unsigned char *)p)[1] << 8) |
(((unsigned char *)p)[2] << 16) |
(((unsigned char *)p)[3] << 24);
#endif
#else
#if LITTLE_ENDIAN
return *p;
#else
@@ -566,14 +592,26 @@ inline unsigned readlongLE(unsigned *p)
(((unsigned char *)p)[2] << 16) |
(((unsigned char *)p)[3] << 24);
#endif
#endif
}
inline unsigned readlongBE(unsigned *p)
{
#if IN_LLVM
#if __BIG_ENDIAN__
return *p;
#else
return ((unsigned char *)p)[3] |
(((unsigned char *)p)[2] << 8) |
(((unsigned char *)p)[1] << 16) |
(((unsigned char *)p)[0] << 24);
#endif
#else
return ((unsigned char *)p)[3] |
(((unsigned char *)p)[2] << 8) |
(((unsigned char *)p)[1] << 16) |
(((unsigned char *)p)[0] << 24);
#endif
}
#if IN_LLVM