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
+27
View File
@@ -1628,7 +1628,16 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
size_t len = (t->ty == tn->ty) ? 1 : utf_codeLength(sz, v);
s = mem.malloc((len + 1) * sz);
if (t->ty == tn->ty)
#if IN_LLVM
#if __LITTLE_ENDIAN__
memcpy((unsigned char *)s, &v, sz);
#else
memcpy((unsigned char *)s,
(unsigned char *)&v + (sizeof(dinteger_t) - sz), sz);
#endif
#else
memcpy((unsigned char *)s, &v, sz);
#endif
else
utf_encode(sz, s, v);
@@ -1752,7 +1761,16 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
s = mem.malloc((len + 1) * sz);
memcpy(s, es1->string, es1->len * sz);
if (homoConcat)
#if IN_LLVM
#if __LITTLE_ENDIAN__
memcpy((unsigned char *)s + (sz * es1->len), &v, sz);
#else
memcpy((unsigned char *)s + (sz * es1->len),
(unsigned char *)&v + (sizeof(dinteger_t) - sz), sz);
#endif
#else
memcpy((unsigned char *)s + (sz * es1->len), &v, sz);
#endif
else
utf_encode(sz, (unsigned char *)s + (sz * es1->len), v);
@@ -1776,7 +1794,16 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
dinteger_t v = e1->toInteger();
s = mem.malloc((len + 1) * sz);
#if IN_LLVM
#if __LITTLE_ENDIAN__
memcpy((unsigned char *)s, &v, sz);
#else
memcpy((unsigned char *)s,
(unsigned char *)&v + (sizeof(dinteger_t) - sz), sz);
#endif
#else
memcpy((unsigned char *)s, &v, sz);
#endif
memcpy((unsigned char *)s + sz, es2->string, es2->len * sz);
// Add terminating 0