mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 21:29:41 +00:00
[dsymutil] Out-line the YAML serialization code. NFC
It will get a bit bigger in an upcoming commit. No need to have all of that in the header. Also move parseYAMLDebugMap() to the same place as the serialization code. This way it will be able to share a private Context object with it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239185 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b539fba9d7
commit
527bb619d1
@ -86,5 +86,114 @@ void DebugMap::print(raw_ostream &OS) const {
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
void DebugMap::dump() const { print(errs()); }
|
void DebugMap::dump() const { print(errs()); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ErrorOr<std::unique_ptr<DebugMap>>
|
||||||
|
DebugMap::parseYAMLDebugMap(StringRef InputFile, StringRef PrependPath,
|
||||||
|
bool Verbose) {
|
||||||
|
auto ErrOrFile = MemoryBuffer::getFileOrSTDIN(InputFile);
|
||||||
|
if (auto Err = ErrOrFile.getError())
|
||||||
|
return Err;
|
||||||
|
|
||||||
|
std::unique_ptr<DebugMap> Res;
|
||||||
|
yaml::Input yin((*ErrOrFile)->getBuffer(), &PrependPath);
|
||||||
|
yin >> Res;
|
||||||
|
|
||||||
|
if (auto EC = yin.error())
|
||||||
|
return EC;
|
||||||
|
|
||||||
|
return std::move(Res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace yaml {
|
||||||
|
|
||||||
|
// Normalize/Denormalize between YAML and a DebugMapObject.
|
||||||
|
struct MappingTraits<dsymutil::DebugMapObject>::YamlDMO {
|
||||||
|
YamlDMO(IO &io) {}
|
||||||
|
YamlDMO(IO &io, dsymutil::DebugMapObject &Obj);
|
||||||
|
dsymutil::DebugMapObject denormalize(IO &IO);
|
||||||
|
|
||||||
|
std::string Filename;
|
||||||
|
std::vector<dsymutil::DebugMapObject::YAMLSymbolMapping> Entries;
|
||||||
|
};
|
||||||
|
|
||||||
|
void MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>>::
|
||||||
|
mapping(IO &io, std::pair<std::string, DebugMapObject::SymbolMapping> &s) {
|
||||||
|
io.mapRequired("sym", s.first);
|
||||||
|
io.mapRequired("objAddr", s.second.ObjectAddress);
|
||||||
|
io.mapRequired("binAddr", s.second.BinaryAddress);
|
||||||
|
io.mapOptional("size", s.second.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MappingTraits<dsymutil::DebugMapObject>::mapping(
|
||||||
|
IO &io, dsymutil::DebugMapObject &DMO) {
|
||||||
|
MappingNormalization<YamlDMO, dsymutil::DebugMapObject> Norm(io, DMO);
|
||||||
|
io.mapRequired("filename", Norm->Filename);
|
||||||
|
io.mapRequired("symbols", Norm->Entries);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScalarTraits<Triple>::output(const Triple &val, void *,
|
||||||
|
llvm::raw_ostream &out) {
|
||||||
|
out << val.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
StringRef ScalarTraits<Triple>::input(StringRef scalar, void *, Triple &value) {
|
||||||
|
value = Triple(scalar);
|
||||||
|
return StringRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
SequenceTraits<std::vector<std::unique_ptr<dsymutil::DebugMapObject>>>::size(
|
||||||
|
IO &io, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq) {
|
||||||
|
return seq.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
dsymutil::DebugMapObject &
|
||||||
|
SequenceTraits<std::vector<std::unique_ptr<dsymutil::DebugMapObject>>>::element(
|
||||||
|
IO &, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq,
|
||||||
|
size_t index) {
|
||||||
|
if (index >= seq.size()) {
|
||||||
|
seq.resize(index + 1);
|
||||||
|
seq[index].reset(new dsymutil::DebugMapObject);
|
||||||
|
}
|
||||||
|
return *seq[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void MappingTraits<dsymutil::DebugMap>::mapping(IO &io,
|
||||||
|
dsymutil::DebugMap &DM) {
|
||||||
|
io.mapRequired("triple", DM.BinaryTriple);
|
||||||
|
io.mapOptional("objects", DM.Objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MappingTraits<std::unique_ptr<dsymutil::DebugMap>>::mapping(
|
||||||
|
IO &io, std::unique_ptr<dsymutil::DebugMap> &DM) {
|
||||||
|
if (!DM)
|
||||||
|
DM.reset(new DebugMap());
|
||||||
|
io.mapRequired("triple", DM->BinaryTriple);
|
||||||
|
io.mapOptional("objects", DM->Objects);
|
||||||
|
}
|
||||||
|
|
||||||
|
MappingTraits<dsymutil::DebugMapObject>::YamlDMO::YamlDMO(
|
||||||
|
IO &io, dsymutil::DebugMapObject &Obj) {
|
||||||
|
Filename = Obj.Filename;
|
||||||
|
Entries.reserve(Obj.Symbols.size());
|
||||||
|
for (auto &Entry : Obj.Symbols)
|
||||||
|
Entries.push_back(std::make_pair(Entry.getKey(), Entry.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
dsymutil::DebugMapObject
|
||||||
|
MappingTraits<dsymutil::DebugMapObject>::YamlDMO::denormalize(IO &IO) {
|
||||||
|
void *Ctxt = IO.getContext();
|
||||||
|
StringRef PrependPath = *reinterpret_cast<StringRef *>(Ctxt);
|
||||||
|
SmallString<80> Path(PrependPath);
|
||||||
|
sys::path::append(Path, Filename);
|
||||||
|
dsymutil::DebugMapObject Res(Path);
|
||||||
|
for (auto &Entry : Entries) {
|
||||||
|
auto &Mapping = Entry.second;
|
||||||
|
Res.addSymbol(Entry.first, Mapping.ObjectAddress, Mapping.BinaryAddress,
|
||||||
|
Mapping.Size);
|
||||||
|
}
|
||||||
|
return Res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,6 +98,10 @@ public:
|
|||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
void dump() const;
|
void dump() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// Read a debug map for \a InputFile.
|
||||||
|
static ErrorOr<std::unique_ptr<DebugMap>>
|
||||||
|
parseYAMLDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief The DebugMapObject represents one object file described by
|
/// \brief The DebugMapObject represents one object file described by
|
||||||
@ -185,102 +189,37 @@ using namespace llvm::dsymutil;
|
|||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>> {
|
struct MappingTraits<std::pair<std::string, DebugMapObject::SymbolMapping>> {
|
||||||
|
static void mapping(IO &io,
|
||||||
static void
|
std::pair<std::string, DebugMapObject::SymbolMapping> &s);
|
||||||
mapping(IO &io, std::pair<std::string, DebugMapObject::SymbolMapping> &s) {
|
|
||||||
io.mapRequired("sym", s.first);
|
|
||||||
io.mapRequired("objAddr", s.second.ObjectAddress);
|
|
||||||
io.mapRequired("binAddr", s.second.BinaryAddress);
|
|
||||||
io.mapOptional("size", s.second.Size);
|
|
||||||
}
|
|
||||||
|
|
||||||
static const bool flow = true;
|
static const bool flow = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct MappingTraits<dsymutil::DebugMapObject> {
|
template <> struct MappingTraits<dsymutil::DebugMapObject> {
|
||||||
// Normalize/Denormalize between YAML and a DebugMapObject.
|
struct YamlDMO;
|
||||||
struct YamlDMO {
|
static void mapping(IO &io, dsymutil::DebugMapObject &DMO);
|
||||||
YamlDMO(IO &io) {}
|
|
||||||
|
|
||||||
YamlDMO(IO &io, dsymutil::DebugMapObject &Obj) {
|
|
||||||
Filename = Obj.Filename;
|
|
||||||
Entries.reserve(Obj.Symbols.size());
|
|
||||||
for (auto &Entry : Obj.Symbols)
|
|
||||||
Entries.push_back(std::make_pair(Entry.getKey(), Entry.getValue()));
|
|
||||||
}
|
|
||||||
|
|
||||||
dsymutil::DebugMapObject denormalize(IO &IO) {
|
|
||||||
void *Ctxt = IO.getContext();
|
|
||||||
StringRef PrependPath = *reinterpret_cast<StringRef*>(Ctxt);
|
|
||||||
SmallString<80> Path(PrependPath);
|
|
||||||
sys::path::append(Path, Filename);
|
|
||||||
dsymutil::DebugMapObject Res(Path);
|
|
||||||
for (auto &Entry : Entries) {
|
|
||||||
auto &Mapping = Entry.second;
|
|
||||||
Res.addSymbol(Entry.first, Mapping.ObjectAddress, Mapping.BinaryAddress,
|
|
||||||
Mapping.Size);
|
|
||||||
}
|
|
||||||
return Res;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string Filename;
|
|
||||||
std::vector<dsymutil::DebugMapObject::YAMLSymbolMapping> Entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void mapping(IO &io, dsymutil::DebugMapObject &DMO) {
|
|
||||||
MappingNormalization<YamlDMO, dsymutil::DebugMapObject> Norm(io, DMO);
|
|
||||||
io.mapRequired("filename", Norm->Filename);
|
|
||||||
io.mapRequired("symbols", Norm->Entries);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct ScalarTraits<Triple> {
|
template <> struct ScalarTraits<Triple> {
|
||||||
|
static void output(const Triple &val, void *, llvm::raw_ostream &out);
|
||||||
static void output(const Triple &val, void *, llvm::raw_ostream &out) {
|
static StringRef input(StringRef scalar, void *, Triple &value);
|
||||||
out << val.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
static StringRef input(StringRef scalar, void *, Triple &value) {
|
|
||||||
value = Triple(scalar);
|
|
||||||
return StringRef();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool mustQuote(StringRef) { return true; }
|
static bool mustQuote(StringRef) { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct SequenceTraits<std::vector<std::unique_ptr<dsymutil::DebugMapObject>>> {
|
struct SequenceTraits<std::vector<std::unique_ptr<dsymutil::DebugMapObject>>> {
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
size(IO &io, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq) {
|
size(IO &io, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq);
|
||||||
return seq.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static dsymutil::DebugMapObject &
|
static dsymutil::DebugMapObject &
|
||||||
element(IO &, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq,
|
element(IO &, std::vector<std::unique_ptr<dsymutil::DebugMapObject>> &seq,
|
||||||
size_t index) {
|
size_t index);
|
||||||
if (index >= seq.size()) {
|
|
||||||
seq.resize(index + 1);
|
|
||||||
seq[index].reset(new dsymutil::DebugMapObject);
|
|
||||||
}
|
|
||||||
return *seq[index];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct MappingTraits<dsymutil::DebugMap> {
|
template <> struct MappingTraits<dsymutil::DebugMap> {
|
||||||
static void mapping(IO &io, dsymutil::DebugMap &DM) {
|
static void mapping(IO &io, dsymutil::DebugMap &DM);
|
||||||
io.mapRequired("triple", DM.BinaryTriple);
|
|
||||||
io.mapOptional("objects", DM.Objects);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <> struct MappingTraits<std::unique_ptr<dsymutil::DebugMap>> {
|
template <> struct MappingTraits<std::unique_ptr<dsymutil::DebugMap>> {
|
||||||
static void mapping(IO &io, std::unique_ptr<dsymutil::DebugMap> &DM) {
|
static void mapping(IO &io, std::unique_ptr<dsymutil::DebugMap> &DM);
|
||||||
if (!DM)
|
|
||||||
DM.reset(new DebugMap());
|
|
||||||
io.mapRequired("triple", DM->BinaryTriple);
|
|
||||||
io.mapOptional("objects", DM->Objects);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,31 +242,18 @@ void MachODebugMapParser::loadMainBinarySymbols() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<std::unique_ptr<DebugMap>>
|
|
||||||
parseYAMLDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose) {
|
|
||||||
auto ErrOrFile = MemoryBuffer::getFileOrSTDIN(InputFile);
|
|
||||||
if (auto Err =ErrOrFile.getError())
|
|
||||||
return Err;
|
|
||||||
|
|
||||||
std::unique_ptr<DebugMap> Res;
|
|
||||||
yaml::Input yin((*ErrOrFile)->getBuffer(), &PrependPath);
|
|
||||||
yin >> Res;
|
|
||||||
|
|
||||||
if (auto EC = yin.error())
|
|
||||||
return EC;
|
|
||||||
|
|
||||||
return std::move(Res);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace dsymutil {
|
namespace dsymutil {
|
||||||
llvm::ErrorOr<std::unique_ptr<DebugMap>>
|
|
||||||
parseDebugMap(StringRef InputFile, StringRef PrependPath, bool Verbose, bool InputIsYAML) {
|
llvm::ErrorOr<std::unique_ptr<DebugMap>> parseDebugMap(StringRef InputFile,
|
||||||
|
StringRef PrependPath,
|
||||||
|
bool Verbose,
|
||||||
|
bool InputIsYAML) {
|
||||||
if (!InputIsYAML) {
|
if (!InputIsYAML) {
|
||||||
MachODebugMapParser Parser(InputFile, PrependPath, Verbose);
|
MachODebugMapParser Parser(InputFile, PrependPath, Verbose);
|
||||||
return Parser.parse();
|
return Parser.parse();
|
||||||
} else {
|
} else {
|
||||||
return parseYAMLDebugMap(InputFile, PrependPath, Verbose);
|
return DebugMap::parseYAMLDebugMap(InputFile, PrependPath, Verbose);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user