[llvm-commits] [PATCH][Support] Add Endian.h which contains generic code to deal with endian specific data.

Michael Spencer bigcheesegs at gmail.com
Fri Sep 24 18:09:37 PDT 2010

On Tue, Sep 14, 2010 at 5:53 PM, Michael Spencer <bigcheesegs at gmail.com> wrote:
> The attached patch adds Endian.h to Support. This patch is a
> prerequisite for the object file library I am writing.
> Endian.h contains:
> * SwapByteOrderIfDifferent
> This is a templated function that takes a value_type, and returns the
> value if host and target are the same, or returns the value with its
> endianness swapped if they are different.
> (host and target are int's because MSVC doesn't support enums used
> like this. see:
> http://stackoverflow.com/questions/2763836/sfinae-failing-with-enum-template-parameter)
> * endian
> This is a templated struct for reading endian specific data directly
> from memory. It is typedefed based on the host platform's endianness
> (well, not yet, because there's no LLVM_IS_BIG_ENDIAN or such yet).
> * packed_endian_specific_integral
> This is the most important thing included in this patch. This class
> allows the portable creation of packed structs of any integral integer
> value_type and endianness. Any struct that would be POD if it used
> normal integral data types is still POD if it uses these.
> This is used extensively in the object file library to directly access
> memory mapped object files. In the case when host and target
> endianness match (and the compiler inlines), using these should
> produce identical code to "*reinterpret_cast<value_type*>(memory)".
> - Michael Spencer

New version, now with unittests.

- Michael Spencer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Support-add-endian.patch
Type: application/octet-stream
Size: 12431 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100924/b8e4f9db/attachment.obj>

More information about the llvm-commits mailing list