[PATCH] D15495: Macro Support in Dwarf emission

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 4 10:23:19 PST 2016


aprantl added a comment.

Thanks for the changes!


================
Comment at: lib/CodeGen/AsmPrinter/DwarfDebug.cpp:1919
@@ +1918,3 @@
+  Size += getULEB128Size(F.getLine());
+  DIFile *File = F.getFile();
+  unsigned FID =
----------------
aaboud wrote:
> I could not find an elegant and less messy way to do share code between these functions.
> Also, in DIE.cpp you can see that there is a similar implementation for "EmitValue()" and "SizeOf()" where common code is not shared!
> 
> I tried at least to encapsulate the handling of the macro node array, as it is being repeated three times in the code.
> 
> Please, let me know if you have a better idea on how to share the common code above.
I'll leave this up to you, but what I'm thinking is that we could define a wrapper class for the emission functions:


```
class AbstractAsmStreamer {
  /// Returns the byte size of the ULEB value.
  unsigned emitULEB128(unsigned Val);
  unsigned emitInt8(unsigned char Val);
  unsigned emitBytes(StringRef Data);
  ...
};

/// Streams objects using an MCAsmStreamer.
class AsmStreamEmitter : public AbstractAsmStreamer {
  AsmStreamEmitter(MCAsmStreamer ...);
};

/// Only reports the size of the streamed objects. Is there a better name?
class SizeReporter : public AbstractAsmStreamer {
  SizeReporter(MCAsmStreamer ...);
};

```
and have the emit* methods always return the size:


```
unsigned DwarfDebug::emitMacroFile(AbstractAsmStreamer &Streamer,
                                                             DIMacroFile &F, DwarfCompileUnit &U) {
  assert(F.getMacinfoType() == dwarf::DW_MACINFO_start_file);
  unsigned Size = 0;
  Size += Streamer.EmitULEB128(dwarf::DW_MACINFO_start_file);
  Size += Streamer.EmitULEB128(F.getLine());
  DIFile *File = F.getFile();
  unsigned FID =
      U.getOrCreateSourceID(File->getFilename(), File->getDirectory());
  Size += Streamer.EmitULEB128(FID);

  Size += handleMacroNodes(F.getElements(), U);

  Size += Streamer.EmitULEB128(dwarf::DW_MACINFO_end_file);
  return Size;
}
```

Maybe it's possible to make this interface general enough that it also can be used in DIE.cpp. If we're worried about the performance of the virtual function call we could templatize on Streamer, but it probably doesn't matter.


http://reviews.llvm.org/D15495





More information about the llvm-commits mailing list