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

@@ -35,29 +35,54 @@ hash_t calcHash(const char *str, size_t len)
case 2:
hash *= 37;
#if IN_LLVM
#if __LITTLE_ENDIAN__
hash += *(const uint16_t *)str;
#else
hash += str[0] * 256 + str[1];
#endif
#else
#if LITTLE_ENDIAN
hash += *(const uint16_t *)str;
#else
hash += str[0] * 256 + str[1];
#endif
#endif
return hash;
case 3:
hash *= 37;
#if IN_LLVM
#if __LITTLE_ENDIAN__
hash += (*(const uint16_t *)str << 8) +
((const uint8_t *)str)[2];
#else
hash += (str[0] * 256 + str[1]) * 256 + str[2];
#endif
#else
#if LITTLE_ENDIAN
hash += (*(const uint16_t *)str << 8) +
((const uint8_t *)str)[2];
#else
hash += (str[0] * 256 + str[1]) * 256 + str[2];
#endif
#endif
return hash;
default:
hash *= 37;
#if IN_LLVM
#if __LITTLE_ENDIAN__
hash += *(const uint32_t *)str;
#else
hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];
#endif
#else
#if LITTLE_ENDIAN
hash += *(const uint32_t *)str;
#else
hash += ((str[0] * 256 + str[1]) * 256 + str[2]) * 256 + str[3];
#endif
#endif
str += 4;
len -= 4;