Changeset View
Standalone View
llvm/include/llvm/ObjectYAML/DWARFEmitter.h
Show All 11 Lines | |||||
#ifndef LLVM_OBJECTYAML_DWARFEMITTER_H | #ifndef LLVM_OBJECTYAML_DWARFEMITTER_H | ||||
#define LLVM_OBJECTYAML_DWARFEMITTER_H | #define LLVM_OBJECTYAML_DWARFEMITTER_H | ||||
#include "llvm/ADT/StringMap.h" | #include "llvm/ADT/StringMap.h" | ||||
#include "llvm/ADT/StringRef.h" | #include "llvm/ADT/StringRef.h" | ||||
#include "llvm/Support/Error.h" | #include "llvm/Support/Error.h" | ||||
#include "llvm/Support/Host.h" | #include "llvm/Support/Host.h" | ||||
#include "llvm/Support/MemoryBuffer.h" | #include "llvm/Support/MemoryBuffer.h" | ||||
#include <map> | |||||
#include <memory> | #include <memory> | ||||
namespace llvm { | namespace llvm { | ||||
class raw_ostream; | class raw_ostream; | ||||
namespace DWARFYAML { | namespace DWARFYAML { | ||||
struct Data; | struct Data; | ||||
struct PubSection; | struct PubSection; | ||||
Error emitDebugAbbrev(raw_ostream &OS, const Data &DI); | class DWARFState { | ||||
Error emitDebugStr(raw_ostream &OS, const Data &DI); | private: | ||||
Data &DWARF; | |||||
jhenderson: Would it make any sense to merge the `DWARFYAML::Data` class and `DWARFYAML::DWARFState` class… | |||||
labathUnsubmitted That would definitely be nice. labath: That would definitely be nice. | |||||
HiguoxingAuthorUnsubmitted
I think they can be merged. But is there any particular reason to merge them? Personally, I would like to keep the DWARFYAML::DWARFState class. Here are a few concerns I would like to address:
I can be persuaded :-) Higuoxing: >>! @jhenderson :
> Would it make any sense to merge the `DWARFYAML::Data` class and `DWARFYAML… | |||||
jhendersonUnsubmitted
As things stand, it mostly seems like DWARFState merely gets in the way of accessing the Data class. It seems to me like it would be easier to use if the two were one class, as you wouldn't have to keep going through an extra function call/member access.
If, rather than do all the calculations up front (e.g. mapping tables to IDs), you put the Data members behind getters, you could then add the "linking" code there. For example, with the AbbrevTable ID mapping, you could have the getAbbrevTableIndexByID method, which is the only way of getting an abbrev table from outside the class. The first time this is called (or optionally every time), it works out the mapping between ID(s) and table(s). This avoids the need for an explicit link or finalize method.
I'm not sure I agree they have different functions. The AbbrevID2Index map is just a helper variable that is directly derived from the Data struct's members. We could get rid of it entirely, and just move the getAbbrevTableIndexByID method into Data, rewriting it to just run through the list of tables each time to find the right ID. This is obviously less efficient than instantiating a mapping up front, if done repeatedly, but I think it indicates that this extra layer is not actually doing anything distinct. Similar principles apply probably for other things, although without further concrete examples, it's hard to discuss them! jhenderson: > I think they can be merged. But is there any particular reason to merge them?
As things stand… | |||||
HiguoxingAuthorUnsubmitted Thanks for the explanation! Higuoxing: Thanks for the explanation! | |||||
std::map<uint64_t, uint64_t> AbbrevID2Index; | |||||
jhendersonUnsubmitted Can you use std::unordered_map here? Do we need deterministic ordering? Might also be worth naming it something like AbbrevTableID2Index to avoid confusing with the AbbrevCode values. jhenderson: Can you use `std::unordered_map` here? Do we need deterministic ordering? Might also be worth… | |||||
DWARFState(Data &DI, Error &Err); | |||||
public: | |||||
static Expected<DWARFState> create(Data &DI); | |||||
Data &getDWARFData() const { return DWARF; } | |||||
Optional<uint64_t> getAbbrevTableIndexByID(uint64_t ID) const; | |||||
}; | |||||
Error emitDebugAbbrev(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugStr(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugAranges(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugRanges(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugPubnames(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugPubtypes(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugGNUPubnames(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugGNUPubtypes(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugInfo(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugLine(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugAddr(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugStrOffsets(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugRnglists(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugLoclists(raw_ostream &OS, const DWARFState &DS); | |||||
Error emitDebugAranges(raw_ostream &OS, const Data &DI); | std::function<Error(raw_ostream &, const DWARFState &)> | ||||
Error emitDebugRanges(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugPubnames(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugPubtypes(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugGNUPubnames(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugGNUPubtypes(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugInfo(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugLine(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugAddr(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugStrOffsets(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugRnglists(raw_ostream &OS, const Data &DI); | |||||
Error emitDebugLoclists(raw_ostream &OS, const Data &DI); | |||||
std::function<Error(raw_ostream &, const Data &)> | |||||
getDWARFEmitterByName(StringRef SecName); | getDWARFEmitterByName(StringRef SecName); | ||||
Expected<StringMap<std::unique_ptr<MemoryBuffer>>> | Expected<StringMap<std::unique_ptr<MemoryBuffer>>> | ||||
emitDebugSections(StringRef YAMLString, | emitDebugSections(StringRef YAMLString, | ||||
bool IsLittleEndian = sys::IsLittleEndianHost, | bool IsLittleEndian = sys::IsLittleEndianHost, | ||||
bool Is64BitAddrSize = true); | bool Is64BitAddrSize = true); | ||||
} // end namespace DWARFYAML | } // end namespace DWARFYAML | ||||
} // end namespace llvm | } // end namespace llvm | ||||
#endif // LLVM_OBJECTYAML_DWARFEMITTER_H | #endif // LLVM_OBJECTYAML_DWARFEMITTER_H |
Would it make any sense to merge the DWARFYAML::Data class and DWARFYAML::DWARFState class at all?