This is an archive of the discontinued LLVM Phabricator instance.

[obj2yaml] - Simplify and reduce `ELFDumper<ELFT>::dumpSections`. NFCI.
ClosedPublic

Authored by grimar on Mar 20 2020, 7:57 AM.

Details

Summary

This method it a bit too large.
It is becoming inconvenient to update it.
This patch suggests a way to reduce and cleanup it.

Diff Detail

Event Timeline

grimar created this revision.Mar 20 2020, 7:57 AM
MaskRay added inline comments.Mar 20 2020, 8:02 AM
llvm/tools/obj2yaml/elf2yaml.cpp
251

std::function<...> is not needed. How about returning a pointer to class member function?

grimar marked an inline comment as done.Mar 20 2020, 2:06 PM
grimar added inline comments.
llvm/tools/obj2yaml/elf2yaml.cpp
251

I wanted, but I do not think we can. The following will not compile:

typedef Expected<ELFYAML::Chunk *> (ELFDumper<ELFT>::*Fn)(const Elf_Shdr *);
auto GetDumper = [this](unsigned Type) -> Fn {
switch (Type) {
  case ELF::SHT_DYNAMIC:
    return &ELFDumper<ELFT>::dumpDynamicSection;
...
  default:
    return nullptr;
  }
};

Because, for example, dumpDynamicSection returns Expected<ELFYAML::DynamicSection*> and not Expected<ELFYAML::Chunk *>. Other dumpers follows.

It seems can be fixed by changing return type of all dumper methods to `Expected<ELFYAML::Chunk *>`,
but I am not sure it worth doing. std::function fits better here I think.

MaskRay accepted this revision.Mar 20 2020, 2:44 PM
MaskRay added inline comments.
llvm/tools/obj2yaml/elf2yaml.cpp
251

I see. C++ can't infer that the return type of a function type is covariant :(

This revision is now accepted and ready to land.Mar 20 2020, 2:44 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 21 2020, 8:33 AM