This is an archive of the discontinued LLVM Phabricator instance.

[YAML] Add new method `yaml::IO::maskedBitSetCase()` to simplify handling of bitset flags with enumeration block
ClosedPublic

Authored by atanasyan on May 16 2014, 11:00 AM.

Details

Reviewers
kledzik
Summary

Some bit-set fields used in ELF file headers in fact contain two parts. The first one is a regular bit-field. The second one is an enumeraion. For example ELF header e_flags for MIPS target might contain the following values:

Bit-set values:

EF_MIPS_NOREORDER = 0x00000001
EF_MIPS_PIC       = 0x00000002
EF_MIPS_CPIC      = 0x00000004
EF_MIPS_ABI2      = 0x00000020

Enumeration:

EF_MIPS_ARCH_32   = 0x50000000
EF_MIPS_ARCH_64   = 0x60000000
EF_MIPS_ARCH_32R2 = 0x70000000
EF_MIPS_ARCH_64R2 = 0x80000000

For printing bit-sets we use the yaml::IO::bitSetCase(). It does not support bit-set/enumeration combinations and prints too many flags from an enumeration part. This patch fixes this problem. New method yaml::IO::maskedBitSetCase() handle "enumeration" part of bitset defined by provided mask.

Diff Detail

Event Timeline

atanasyan updated this revision to Diff 9491.May 16 2014, 11:00 AM
atanasyan retitled this revision from to [YAML] Add an optional argument `EnumMask` to the `yaml::IO::bitSetCase()`.
atanasyan updated this object.
atanasyan edited the test plan for this revision. (Show Details)
atanasyan added a reviewer: kledzik.
atanasyan added a subscriber: Unknown Object (MLST).
atanasyan updated this revision to Diff 9602.May 20 2014, 2:46 AM

Update the patch against the latest trunk state.

kledzik edited edge metadata.May 21 2014, 2:07 PM

Please update the yaml documentation (llvm/docs/YamlIO.rst) with this new functionality too.

BTW, I had this same issue with mach-o in which the uint32_t section "flags" field has a 8-bit enum and 24-bits of flags. What I did was break them into two yaml fields.

include/llvm/Support/YAMLTraits.h
475–480

I think it would be cleaner to add a new method:

void maskedBitSetCase()

or

void bitSetCaseWithMask()

rather that adding that optional parameter, because now you have to check if the mask is zero (not used) and use different bit checking.

atanasyan updated this revision to Diff 9681.May 22 2014, 2:17 AM
atanasyan retitled this revision from [YAML] Add an optional argument `EnumMask` to the `yaml::IO::bitSetCase()` to [YAML] Add new method `yaml::IO::maskedBitSetCase()` to simplify handling of bitset flags with enumeration block.
atanasyan updated this object.
atanasyan edited edge metadata.

The updated patch has the following changes:

  1. Keep the bitSetCase() unchanged and add new method maskedBitSetCase().
  2. Update the yaml documentation.

I considered to break the Flags field into two parts. But I could not invent good names for these fields. The "enumeration" values have different meanings for different targets. Some targets do not use the Flags field at all. Moreover I am not sure that there is no target with more than one "enumeration" blocks in the Flag field.

kledzik accepted this revision.May 22 2014, 3:38 PM
kledzik edited edge metadata.

LGTM

This revision is now accepted and ready to land.May 22 2014, 3:38 PM
silvas added a subscriber: silvas.May 22 2014, 9:06 PM
silvas added inline comments.
docs/YamlIO.rst
418

typo: maskeBitSet

atanasyan closed this revision.May 23 2014, 1:16 AM

Thanks for review.

Closed by commit rL209504.