This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][DWARF][NFC] Move DWARFTypePrinter class to its own file.
ClosedPublic

Authored by avl on Jan 12 2022, 11:08 AM.

Details

Summary

This patch moves DWARFTypePrinter class to its own file, so that it
might be reused. It will help D96035, which uses DWARFTypePrinter.

Diff Detail

Event Timeline

avl created this revision.Jan 12 2022, 11:08 AM
avl requested review of this revision.Jan 12 2022, 11:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2022, 11:08 AM

I don't especially object to moving this to a separate file - but maybe it'd be more suitable to have this exposed as a function on DWARFDie, rather than exposing the whole DWARFTypePrinter API?

avl added a comment.Jan 12 2022, 11:31 PM

I don't especially object to moving this to a separate file - but maybe it'd be more suitable to have this exposed as a function on DWARFDie, rather than exposing the whole DWARFTypePrinter API?

i.e. something similar to this:

void DWARFDie::dumpTypeQualifiedName(raw_ostream& OS);
void DWARFDie::dumpTypeUnqualifiedName(raw_ostream& OS, std::string *OriginalFullName = nullptr);

If that is a preferred variant - I will change the patch accordingly.

Though, The variant with a separate class has an advantage in that it separates dumping functionality from the DWARFDie class.
That is similar to the "Model-View" pattern. If we would add more dumps(for different programming languages, or for different DWARFDie kinds) then we would be necessary to add more dumping functions into the DWARFDie interface, which is probably not a good thing:

void DWARFDie::dumpSubprogram(raw_ostream& OS);
void DWARFDie::dumpRanges(raw_ostream& OS);

From that point of view, using a separate class for dumping probably looks preferable. It allows keeping the DWARFDie interface simpler.
But if adding specific dumping methods to the DWARFDie looks better for us - I am OK to do this.

I don't especially object to moving this to a separate file - but maybe it'd be more suitable to have this exposed as a function on DWARFDie, rather than exposing the whole DWARFTypePrinter API?

i.e. something similar to this:

void DWARFDie::dumpTypeQualifiedName(raw_ostream& OS);
void DWARFDie::dumpTypeUnqualifiedName(raw_ostream& OS, std::string *OriginalFullName = nullptr);

If that is a preferred variant - I will change the patch accordingly.

Though, The variant with a separate class has an advantage in that it separates dumping functionality from the DWARFDie class.

Oh, fair point - how about free functions, then? void dumpTypeQualifiedName(DWARFDie D, raw_ostream &OS) - that sort of thing?

avl updated this revision to Diff 399758.Jan 13 2022, 1:05 PM

addressed comments(left DWARFTypePrinter inside DWARFDie.cpp, created two functions for type printing)

dblaikie accepted this revision.Jan 13 2022, 1:08 PM

Looks good, thanks!

This revision is now accepted and ready to land.Jan 13 2022, 1:08 PM
avl added a comment.Jan 13 2022, 1:18 PM

Thank you for the review!