This is an archive of the discontinued LLVM Phabricator instance.

[llvm-readelf/obj] - Cleanup the interface of `DumpStyle`. NFCI.
ClosedPublic

Authored by grimar on Sep 2 2020, 9:22 AM.

Details

Summary

We have 2 DumpStyles currently:
class GNUStyle : public DumpStyle<ELFT> and class LLVMStyle : public DumpStyle<ELFT>.

The problem of DumpStyle interface is that almost for each method
we provide const ELFFile<ELFT> * as argument. But in fact each of
dump styles keeps ELFDumper<ELFT> *Dumper which can be used to get an object from.

But since we use the Obj too often, I've decided to introduce a one more reference member
instead of reading it from the Dumper each time:
const ELFFile<ELFT> &Obj; This is kind of similar to FileName member which we have already:
it is also used to store a the file name which can be read from Dumper->getElfObject()->getFileName().

I had to adjust the code which previously worked with a pointer to an object
and now works with a reference.

In a follow-up I am going to try to get rid of const ELFObjectFile<ELFT> arguments
which are still passed to a set of functions.

Diff Detail

Event Timeline

grimar created this revision.Sep 2 2020, 9:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2020, 9:22 AM
Herald added a subscriber: rupprecht. · View Herald Transcript
grimar requested review of this revision.Sep 2 2020, 9:22 AM
jhenderson accepted this revision.Sep 3 2020, 1:22 AM

LGTM.

llvm/tools/llvm-readobj/ELFDumper.cpp
697–698

Another minor improvement you could do is initialise FileName in the initialiser list. Separate patch that one though.

3581

Maybe worth changing getGroups to take a reference too, whilst you're at it.

This revision is now accepted and ready to land.Sep 3 2020, 1:22 AM