1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[obj2yaml] Include all mach_header fields in yaml

Since we want to be able to use yaml to describe degenerate object files as well as valid ones, we need to be explicit of some fields in your yaml definitions.

llvm-svn: 269313
This commit is contained in:
Chris Bieneman 2016-05-12 17:44:43 +00:00
parent f351ddf6e0
commit 63f045f898
3 changed files with 8 additions and 1 deletions

View File

@ -23,11 +23,14 @@ namespace llvm {
namespace MachOYAML {
struct FileHeader {
llvm::yaml::Hex32 magic;
llvm::yaml::Hex32 cputype;
llvm::yaml::Hex32 cpusubtype;
llvm::yaml::Hex32 filetype;
uint32_t ncmds;
uint32_t sizeofcmds;
llvm::yaml::Hex32 flags;
// TODO: Need to handle the reserved field in mach_header_64
};
struct Object {

View File

@ -20,10 +20,12 @@ namespace yaml {
void MappingTraits<MachOYAML::FileHeader>::mapping(
IO &IO, MachOYAML::FileHeader &FileHdr) {
IO.mapRequired("magic", FileHdr.magic);
IO.mapRequired("cputype", FileHdr.cputype);
IO.mapRequired("cpusubtype", FileHdr.cpusubtype);
IO.mapOptional("filetype", FileHdr.filetype);
IO.mapRequired("ncmds", FileHdr.ncmds);
IO.mapRequired("sizeofcmds", FileHdr.sizeofcmds);
IO.mapRequired("flags", FileHdr.flags);
}
@ -31,7 +33,7 @@ void MappingTraits<MachOYAML::Object>::mapping(IO &IO,
MachOYAML::Object &Object) {
// If the context isn't already set, tag the document as !mach-o.
// For Fat files there will be a different tag so they can be differentiated.
if(!IO.getContext()) {
if (!IO.getContext()) {
IO.setContext(&Object);
IO.mapTag("!mach-o", true);
}

View File

@ -26,10 +26,12 @@ public:
Expected<MachOYAML::Object *> MachODumper::dump() {
auto Y = make_unique<MachOYAML::Object>();
Y->Header.magic = Obj.getHeader().magic;
Y->Header.cputype = Obj.getHeader().cputype;
Y->Header.cpusubtype = Obj.getHeader().cpusubtype;
Y->Header.filetype = Obj.getHeader().filetype;
Y->Header.ncmds = Obj.getHeader().ncmds;
Y->Header.sizeofcmds = Obj.getHeader().sizeofcmds;
Y->Header.flags = Obj.getHeader().flags;
return Y.release();