From: Rui Ueyama Date: Mon, 2 Mar 2015 20:00:15 +0000 (+0000) Subject: Support: Add {read,write}{16,32,64}{le,be} functions. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=955419ebf0cbf99c927068c18d7f46490c3242b1;p=oota-llvm.git Support: Add {read,write}{16,32,64}{le,be} functions. Add convenient functions for endian-aware reads/writes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231002 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/Endian.h b/include/llvm/Support/Endian.h index 47b82fdc497..db85c6541e2 100644 --- a/include/llvm/Support/Endian.h +++ b/include/llvm/Support/Endian.h @@ -195,7 +195,23 @@ typedef detail::packed_endian_specific_integral unaligned_int32_t; typedef detail::packed_endian_specific_integral unaligned_int64_t; -} // end namespace llvm + +namespace endian { +inline uint16_t read16le(const void *p) { return *(ulittle16_t *)p; } +inline uint32_t read32le(const void *p) { return *(ulittle32_t *)p; } +inline uint64_t read64le(const void *p) { return *(ulittle64_t *)p; } +inline uint16_t read16be(const void *p) { return *(ubig16_t *)p; } +inline uint32_t read32be(const void *p) { return *(ubig32_t *)p; } +inline uint64_t read64be(const void *p) { return *(ubig64_t *)p; } + +inline void write16le(void *p, uint16_t v) { *(ulittle16_t *)p = v; } +inline void write32le(void *p, uint32_t v) { *(ulittle32_t *)p = v; } +inline void write64le(void *p, uint64_t v) { *(ulittle64_t *)p = v; } +inline void write16be(void *p, uint16_t v) { *(ubig16_t *)p = v; } +inline void write32be(void *p, uint32_t v) { *(ubig32_t *)p = v; } +inline void write64be(void *p, uint64_t v) { *(ubig64_t *)p = v; } +} // end namespace endian } // end namespace support +} // end namespace llvm #endif