[llvm-dev] RFC: Adding llvm::ThinStream

Pavel Labath via llvm-dev llvm-dev at lists.llvm.org
Thu Feb 23 02:25:32 PST 2017


On 22 February 2017 at 19:57, Zachary Turner via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
>> Oh, reinterpret casting... hrm. That kind of file reading/writing scheme
>> usually makes me a bit uncomfortable due to portability concerns (having to
>> align, byte swap, etc, structs to match the on-disk format can make those
>> structures problematic to work with - if you have to byte swap anyway, you'd
>> need to copy the data out of the underlying buffer anyway, right?)
>
> For byte swapping usually this is done by using llvm's endian aware types.
> If you have a struct with a bunch of llvm::support::ulittle16_t's, then it
> doesn't matter what platform you're on, you can reinterpret_cast the pointer
> to that struct, and when you read the values they will be correct.

How would this work if the endiannes and byte size of the struct (e.g.
ELF header) is only decided at runtime. For example, if I need a
single piece of code to handle both x86_64 little endian and arm32 big
endian versions of a struct. Am I supposed to template everything
based byte size and endiannes (with some runtime dispatch at the top
level)? Or is this not a use case that you have in mind here?

pl


More information about the llvm-dev mailing list