Make EmitIntValue() work properly on big-endian targets.

llvm-svn: 132715
This commit is contained in:
Roman Divacky 2011-06-07 17:31:02 +00:00
parent 7ae360f2e1
commit 384ffa9a0e
1 changed files with 6 additions and 3 deletions

View File

@ -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 <cstdlib>
@ -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);
}