X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FEndian.h;h=8d5649dc1f91ec3ab130d168b1a1422d81daef02;hb=f5091b476c46333ecfcf095cd2e422e9748e9546;hp=1058beff7b9cf9053e602d69c691d1378d64dae5;hpb=fd7c230c85dbc9b1c5145319a0d5eaeb99f61176;p=oota-llvm.git diff --git a/include/llvm/Support/Endian.h b/include/llvm/Support/Endian.h index 1058beff7b9..8d5649dc1f9 100644 --- a/include/llvm/Support/Endian.h +++ b/include/llvm/Support/Endian.h @@ -14,9 +14,8 @@ #ifndef LLVM_SUPPORT_ENDIAN_H #define LLVM_SUPPORT_ENDIAN_H -#include "llvm/Config/config.h" -#include "llvm/System/Host.h" -#include "llvm/System/SwapByteOrder.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/SwapByteOrder.h" #include "llvm/Support/type_traits.h" namespace llvm { @@ -48,43 +47,43 @@ struct alignment_access_helper } // end namespace detail -namespace endian { - template - static value_type read_le(const void *memory) { - value_type t = - reinterpret_cast *>(memory)->val; - if (sys::isBigEndianHost()) - return sys::SwapByteOrder(t); - return t; - } - - template - static void write_le(void *memory, value_type value) { - if (sys::isBigEndianHost()) - value = sys::SwapByteOrder(value); - reinterpret_cast *> - (memory)->val = value; - } - - template - static value_type read_be(const void *memory) { - value_type t = - reinterpret_cast *>(memory)->val; - if (sys::isLittleEndianHost()) - return sys::SwapByteOrder(t); - return t; - } - - template - static void write_be(void *memory, value_type value) { - if (sys::isLittleEndianHost()) - value = sys::SwapByteOrder(value); - reinterpret_cast *> - (memory)->val = value; +namespace endian { + template + inline value_type read_le(const void *memory) { + value_type t = + reinterpret_cast *>(memory)->val; + if (sys::isBigEndianHost()) + return sys::SwapByteOrder(t); + return t; + } + + template + inline void write_le(void *memory, value_type value) { + if (sys::isBigEndianHost()) + value = sys::SwapByteOrder(value); + reinterpret_cast *> + (memory)->val = value; } -}; + + template + inline value_type read_be(const void *memory) { + value_type t = + reinterpret_cast *>(memory)->val; + if (sys::isLittleEndianHost()) + return sys::SwapByteOrder(t); + return t; + } + + template + inline void write_be(void *memory, value_type value) { + if (sys::isLittleEndianHost()) + value = sys::SwapByteOrder(value); + reinterpret_cast *> + (memory)->val = value; + } +} namespace detail { @@ -99,6 +98,9 @@ public: operator value_type() const { return endian::read_le(Value); } + void operator=(value_type newValue) { + endian::write_le((void *)&Value, newValue); + } private: uint8_t Value[sizeof(value_type)]; }; @@ -109,6 +111,9 @@ public: operator value_type() const { return endian::read_be(Value); } + void operator=(value_type newValue) { + endian::write_be((void *)&Value, newValue); + } private: uint8_t Value[sizeof(value_type)]; }; @@ -119,6 +124,9 @@ public: operator value_type() const { return endian::read_le(&Value); } + void operator=(value_type newValue) { + endian::write_le((void *)&Value, newValue); + } private: value_type Value; }; @@ -129,6 +137,9 @@ public: operator value_type() const { return endian::read_be(&Value); } + void operator=(value_type newValue) { + endian::write_be((void *)&Value, newValue); + } private: value_type Value; };