diff include/llvm/Support/Endian.h @ 77:54457678186b LLVM3.6

LLVM 3.6
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 08 Sep 2014 22:06:00 +0900
parents 95c75e76d11b
children 60c9769439b8
line wrap: on
line diff
--- a/include/llvm/Support/Endian.h	Thu Dec 12 15:22:36 2013 +0900
+++ b/include/llvm/Support/Endian.h	Mon Sep 08 22:06:00 2014 +0900
@@ -17,7 +17,6 @@
 #include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Host.h"
 #include "llvm/Support/SwapByteOrder.h"
-#include "llvm/Support/type_traits.h"
 
 namespace llvm {
 namespace support {
@@ -35,13 +34,15 @@
 } // end namespace detail
 
 namespace endian {
+/// Swap the bytes of value to match the given endianness.
 template<typename value_type, endianness endian>
 inline value_type byte_swap(value_type value) {
   if (endian != native && sys::IsBigEndianHost != (endian == big))
-    return sys::SwapByteOrder(value);
+    sys::swapByteOrder(value);
   return value;
 }
 
+/// Read a value of a particular endianness from memory.
 template<typename value_type,
          endianness endian,
          std::size_t alignment>
@@ -55,6 +56,16 @@
   return byte_swap<value_type, endian>(ret);
 }
 
+/// Read a value of a particular endianness from a buffer, and increment the
+/// buffer past that value.
+template<typename value_type, endianness endian, std::size_t alignment>
+inline value_type readNext(const unsigned char *&memory) {
+  value_type ret = read<value_type, endian, alignment>(memory);
+  memory += sizeof(value_type);
+  return ret;
+}
+
+/// Write a value to memory with a particular endianness.
 template<typename value_type,
          endianness endian,
          std::size_t alignment>
@@ -85,7 +96,24 @@
 private:
   AlignedCharArray<PickAlignment<value_type, alignment>::value,
                    sizeof(value_type)> Value;
+
+public:
+  struct ref {
+    explicit ref(void *Ptr) : Ptr(Ptr) {}
+
+    operator value_type() const {
+      return endian::read<value_type, endian, alignment>(Ptr);
+    }
+
+    void operator=(value_type NewValue) {
+      endian::write<value_type, endian, alignment>(Ptr, NewValue);
+    }
+
+  private:
+    void *Ptr;
+  };
 };
+
 } // end namespace detail
 
 typedef detail::packed_endian_specific_integral