Remove dependency of DWARF generation code on AsmPrinter.
This patch is not for integration. I want to consult whether it is going
in the right direction. It demonstrates the possible variant of refactoring.
Not all cases/problems are resolved in this patch currently.
During work on "Remove obsolete debug info in lld" I need to generate
DWARF without using AsmPrinter(To not to add extra libraries to lld).
The current implementation of DWARF generation is heavily depends on
using AsmPrinter. F.e. CodeGen/DIE.h
class DIEInteger {
void emitValue(const AsmPrinter *Asm, dwarf::Form Form) const; unsigned SizeOf(const AsmPrinter *AP, dwarf::Form Form) const;
}
I think it would be a bad idea to write a new set of DWARF generating
classes, not depending on AsmPrinter. Instead, it would be better
to reduce dependence on AsmPrinter for current structures.
It would allow for reusing existed implementation.
There is already a place which implements such separation :
AsmPrinter/ByteStreamer.h:ByteStreamer
AsmPrinter/DwarfDebug.h:DwarfDebug::emitDebugLocEntry(ByteStreamer &Streamer)
But it is used locally. I think the same idea could be implemented
in a more general way:
There should be a class that allows writing byte data in the dwarf section: DwarfDebugSection.
DwarfDebugSection would have two descendands: DwarfDebugSectionAsm, DwarfDebugSectionBin.
There should be a class that allows writing DWARF constructions(units, line tables,
address ranges) to DwarfDebugSection: DwarfDebugFile.
DIE* classes from CodeGen/DIE.h should be moved into DebugInfoDWARF library.
DwarfDebugSection & DwarfDebugFile should be put into DebugInfoDWARF library.
In a far perspective: DwarfDebugFile could replace AsmPrinter/DwarfFile,
other classes would be moved into DebugInfoDWARF library(DwarfStringPool...).
The above changes would allow generating DWARF without AsmPrinter.
Also, this implementation could probably be reused by debug info tools(dsymutil,
llvm-gsymutil, llvm-dwp...).
This patch presents some changes which show the direction of the refactoring.
What do you think? Would this refactoring be useful?
Is it OK to do things in this manner?
If that idea is OK, then changes could be done incrementally,
moving code(currently located in AsmPrinter) into DebugInfoDWARF library.