This is an archive of the discontinued LLVM Phabricator instance.

[Support/Endian] Add support for endian-specific enums
ClosedPublic

Authored by labath on Mar 8 2019, 10:01 AM.

Details

Summary

Binary formats often include various enumerations or bitsets, but using
endian-specific types for accessing them is tricky because they
currently only support integral types. This is particularly true for
scoped enums (enum class), as these are not implicitly convertible to
integral types, and so one has to perform two casts just to read the
enum value.

This fixes that support by adding first-class support for enumeration
types to endian-specific types. The support for them was already almost
working -- all I needed to do was overload getSwappedBytes for
enumeration types (which casts the enum to its underlying type and performs the
conversion there). I also add some convenience template aliases to simplify
declaring endian-specific enums.

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Mar 8 2019, 10:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 8 2019, 10:01 AM
Herald added a subscriber: kristina. · View Herald Transcript
Bigcheese requested changes to this revision.Mar 8 2019, 12:09 PM

I agree with Zach, this should be little_t and big_t. You should also add aligned_big_t and aligned_little_t.

This revision now requires changes to proceed.Mar 8 2019, 12:09 PM
labath updated this revision to Diff 189904.Mar 8 2019, 12:09 PM

Rename the new types to big_t/little_t as they're not really enum-specific.

labath updated this revision to Diff 189907.Mar 8 2019, 12:16 PM

Add aligned_{big/little}_t as well.

This revision is now accepted and ready to land.Mar 8 2019, 12:17 PM

Thank you for the quick review.

This revision was automatically updated to reflect the committed changes.