diff options
author | Ash Wolf <ninji@wuffs.org> | 2022-12-29 12:32:55 +0000 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2022-12-29 12:32:55 +0000 |
commit | fcfbafff31869ed808bff0639532db1828660e92 (patch) | |
tree | 7425b346b031c4cb47a06250b3f6f950374d44ae /compiler_and_linker/FrontEnd/C | |
parent | bc1321735c15104ffad195e1509cab5f3a044260 (diff) | |
download | MWCC-fcfbafff31869ed808bff0639532db1828660e92.tar.gz MWCC-fcfbafff31869ed808bff0639532db1828660e92.zip |
dump lots more code
Diffstat (limited to '')
-rw-r--r-- | compiler_and_linker/FrontEnd/Common/CompilerTools.c | 53 |
1 files changed, 43 insertions, 10 deletions
diff --git a/compiler_and_linker/FrontEnd/Common/CompilerTools.c b/compiler_and_linker/FrontEnd/Common/CompilerTools.c index 3eae51d..131aa8e 100644 --- a/compiler_and_linker/FrontEnd/Common/CompilerTools.c +++ b/compiler_and_linker/FrontEnd/Common/CompilerTools.c @@ -1,4 +1,5 @@ #include "compiler/CompilerTools.h" +#include "compiler/CInt64.h" #include "cos.h" extern Boolean systemHandles; @@ -140,6 +141,7 @@ void AppendGListTargetEndianWord(GList *gl, SInt16 theword) { ptr = *gl->data + gl->size; gl->size += 2; + theword = CTool_EndianConvertWord16(theword); *(ptr++) = ((unsigned char *) &theword)[0]; *(ptr++) = ((unsigned char *) &theword)[1]; } @@ -170,6 +172,7 @@ void AppendGListTargetEndianLong(GList *gl, SInt32 theword) { ptr = *gl->data + gl->size; gl->size += 4; + theword = CTool_EndianConvertWord32(theword); *(ptr++) = ((unsigned char *) &theword)[0]; *(ptr++) = ((unsigned char *) &theword)[1]; *(ptr++) = ((unsigned char *) &theword)[2]; @@ -1157,26 +1160,56 @@ short getbit(SInt32 l) { } } +#ifdef ENDIAN_CONVERSION +UInt16 CTool_EndianConvertWord16(UInt16 theword) { + UInt16 conv; + ((UInt8 *) &conv)[0] = ((UInt8 *) &theword)[1]; + ((UInt8 *) &conv)[1] = ((UInt8 *) &theword)[0]; + return conv; +} + +UInt32 CTool_EndianConvertWord32(UInt32 theword) { + UInt32 conv; + ((UInt8 *) &conv)[0] = ((UInt8 *) &theword)[3]; + ((UInt8 *) &conv)[1] = ((UInt8 *) &theword)[2]; + ((UInt8 *) &conv)[2] = ((UInt8 *) &theword)[1]; + ((UInt8 *) &conv)[3] = ((UInt8 *) &theword)[0]; + return conv; +} + +void CTool_EndianConvertMem(UInt8 *data, short len) { + UInt8 *a = data; + UInt8 *b = data + len; + while (--b > a) { + UInt8 val = *b; + *b = *a; + *a++ = val; + } +} +#endif + void CTool_EndianConvertWord64(CInt64 ci, char *result) { UInt32 buf[2]; - buf[0] = ci.hi; - buf[1] = ci.lo; + buf[0] = CTool_EndianConvertWord32(CTool_EndianReadWord32(&ci.hi)); + buf[1] = CTool_EndianConvertWord32(CInt64_GetULong(&ci)); memcpy(result, buf, 8); } +#ifdef ENDIAN_CONVERSION +UInt32 CTool_EndianReadWord32(void *ptr) { + return *((UInt32 *) ptr); +} +#endif + UInt16 CTool_EndianConvertInPlaceWord16Ptr(UInt16 *x) { - unsigned short v; - v = *x; - // this probably has a conversion on non-ppc - *x = v; + UInt16 v; + *x = v = CTool_EndianConvertWord16(*x); return v; } UInt32 CTool_EndianConvertInPlaceWord32Ptr(UInt32 *x) { - unsigned long v; - v = *x; - // this probably has a conversion on non-ppc - *x = v; + UInt32 v; + *x = v = CTool_EndianConvertWord32(*x); return v; } |