From: Roman Divacky Date: Tue, 7 Jun 2011 17:31:02 +0000 (+0000) Subject: Make EmitIntValue() work properly on big-endian targets. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=65891533a3b35d7fc8fa807a96b7ee2f09ff22b5;p=oota-llvm.git Make EmitIntValue() work properly on big-endian targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132715 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp index 974e885aacd..ae3ed0f3f61 100644 --- a/lib/MC/MCStreamer.cpp +++ b/lib/MC/MCStreamer.cpp @@ -15,6 +15,7 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetAsmInfo.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/Twine.h" #include @@ -80,9 +81,11 @@ void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size, assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) && "Invalid size"); char buf[8]; - // FIXME: Endianness assumption. - for (unsigned i = 0; i != Size; ++i) - buf[i] = uint8_t(Value >> (i * 8)); + const bool isLittleEndian = Context.getTargetAsmInfo().isLittleEndian(); + for (unsigned i = 0; i != Size; ++i) { + unsigned index = isLittleEndian ? i : (Size - i - 1); + buf[i] = uint8_t(Value >> (index * 8)); + } EmitBytes(StringRef(buf, Size), AddrSpace); }