diff --git a/include/llvm/MC/MCObjectWriter.h b/include/llvm/MC/MCObjectWriter.h index da55a0c0a0c..22eea7e022e 100644 --- a/include/llvm/MC/MCObjectWriter.h +++ b/include/llvm/MC/MCObjectWriter.h @@ -10,10 +10,8 @@ #ifndef LLVM_MC_MCOBJECTWRITER_H #define LLVM_MC_MCOBJECTWRITER_H -#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include "llvm/System/DataTypes.h" -#include "llvm/System/Host.h" #include namespace llvm { @@ -94,57 +92,54 @@ public: } void WriteLE16(uint16_t Value) { - if (sys::isBigEndianHost()) - Value = ByteSwap_16(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + Write8(uint8_t(Value >> 0)); + Write8(uint8_t(Value >> 8)); } void WriteLE32(uint32_t Value) { - if (sys::isBigEndianHost()) - Value = ByteSwap_32(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + WriteLE16(uint16_t(Value >> 0)); + WriteLE16(uint16_t(Value >> 16)); } void WriteLE64(uint64_t Value) { - if (sys::isBigEndianHost()) - Value = ByteSwap_64(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + WriteLE32(uint32_t(Value >> 0)); + WriteLE32(uint32_t(Value >> 32)); } void WriteBE16(uint16_t Value) { - if (sys::isLittleEndianHost()) - Value = ByteSwap_16(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + Write8(uint8_t(Value >> 8)); + Write8(uint8_t(Value >> 0)); } void WriteBE32(uint32_t Value) { - if (sys::isLittleEndianHost()) - Value = ByteSwap_32(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + WriteBE16(uint16_t(Value >> 16)); + WriteBE16(uint16_t(Value >> 0)); } void WriteBE64(uint64_t Value) { - if (sys::isLittleEndianHost()) - Value = ByteSwap_64(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + WriteBE32(uint32_t(Value >> 32)); + WriteBE32(uint32_t(Value >> 0)); } void Write16(uint16_t Value) { - if (IsLittleEndian != sys::isLittleEndianHost()) - Value = ByteSwap_16(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + if (IsLittleEndian) + WriteLE16(Value); + else + WriteBE16(Value); } void Write32(uint32_t Value) { - if (IsLittleEndian != sys::isLittleEndianHost()) - Value = ByteSwap_32(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + if (IsLittleEndian) + WriteLE32(Value); + else + WriteBE32(Value); } void Write64(uint64_t Value) { - if (IsLittleEndian != sys::isLittleEndianHost()) - Value = ByteSwap_64(Value); - OS << StringRef((const char*)&Value, sizeof(Value)); + if (IsLittleEndian) + WriteLE64(Value); + else + WriteBE64(Value); } void WriteZeros(unsigned N) {