mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Small obj2yaml cleanups.
* using namespace llvm. * whitespace. * early return. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179920 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "obj2yaml.h"
|
||||
#include "llvm/Object/COFF.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
template <typename One, typename Two>
|
||||
struct pod_pair { // I'd much rather use std::pair, but it's not a POD
|
||||
@@ -17,8 +18,8 @@ struct pod_pair { // I'd much rather use std::pair, but it's not a POD
|
||||
Two second;
|
||||
};
|
||||
|
||||
#define STRING_PAIR(x) {llvm::COFF::x, #x}
|
||||
static const pod_pair<llvm::COFF::MachineTypes, const char *>
|
||||
#define STRING_PAIR(x) {COFF::x, #x}
|
||||
static const pod_pair<COFF::MachineTypes, const char *>
|
||||
MachineTypePairs [] = {
|
||||
STRING_PAIR(IMAGE_FILE_MACHINE_UNKNOWN),
|
||||
STRING_PAIR(IMAGE_FILE_MACHINE_AM33),
|
||||
@@ -43,7 +44,7 @@ MachineTypePairs [] = {
|
||||
STRING_PAIR(IMAGE_FILE_MACHINE_WCEMIPSV2)
|
||||
};
|
||||
|
||||
static const pod_pair<llvm::COFF::SectionCharacteristics, const char *>
|
||||
static const pod_pair<COFF::SectionCharacteristics, const char *>
|
||||
SectionCharacteristicsPairs1 [] = {
|
||||
STRING_PAIR(IMAGE_SCN_TYPE_NO_PAD),
|
||||
STRING_PAIR(IMAGE_SCN_CNT_CODE),
|
||||
@@ -60,7 +61,7 @@ SectionCharacteristicsPairs1 [] = {
|
||||
STRING_PAIR(IMAGE_SCN_MEM_PRELOAD)
|
||||
};
|
||||
|
||||
static const pod_pair<llvm::COFF::SectionCharacteristics, const char *>
|
||||
static const pod_pair<COFF::SectionCharacteristics, const char *>
|
||||
SectionCharacteristicsPairsAlignment [] = {
|
||||
STRING_PAIR(IMAGE_SCN_ALIGN_1BYTES),
|
||||
STRING_PAIR(IMAGE_SCN_ALIGN_2BYTES),
|
||||
@@ -78,7 +79,7 @@ SectionCharacteristicsPairsAlignment [] = {
|
||||
STRING_PAIR(IMAGE_SCN_ALIGN_8192BYTES)
|
||||
};
|
||||
|
||||
static const pod_pair<llvm::COFF::SectionCharacteristics, const char *>
|
||||
static const pod_pair<COFF::SectionCharacteristics, const char *>
|
||||
SectionCharacteristicsPairs2 [] = {
|
||||
STRING_PAIR(IMAGE_SCN_LNK_NRELOC_OVFL),
|
||||
STRING_PAIR(IMAGE_SCN_MEM_DISCARDABLE),
|
||||
@@ -90,7 +91,7 @@ SectionCharacteristicsPairs2 [] = {
|
||||
STRING_PAIR(IMAGE_SCN_MEM_WRITE)
|
||||
};
|
||||
|
||||
static const pod_pair<llvm::COFF::SymbolBaseType, const char *>
|
||||
static const pod_pair<COFF::SymbolBaseType, const char *>
|
||||
SymbolBaseTypePairs [] = {
|
||||
STRING_PAIR(IMAGE_SYM_TYPE_NULL),
|
||||
STRING_PAIR(IMAGE_SYM_TYPE_VOID),
|
||||
@@ -110,7 +111,7 @@ SymbolBaseTypePairs [] = {
|
||||
STRING_PAIR(IMAGE_SYM_TYPE_DWORD)
|
||||
};
|
||||
|
||||
static const pod_pair<llvm::COFF::SymbolComplexType, const char *>
|
||||
static const pod_pair<COFF::SymbolComplexType, const char *>
|
||||
SymbolComplexTypePairs [] = {
|
||||
STRING_PAIR(IMAGE_SYM_DTYPE_NULL),
|
||||
STRING_PAIR(IMAGE_SYM_DTYPE_POINTER),
|
||||
@@ -118,7 +119,7 @@ SymbolComplexTypePairs [] = {
|
||||
STRING_PAIR(IMAGE_SYM_DTYPE_ARRAY),
|
||||
};
|
||||
|
||||
static const pod_pair<llvm::COFF::SymbolStorageClass, const char *>
|
||||
static const pod_pair<COFF::SymbolStorageClass, const char *>
|
||||
SymbolStorageClassPairs [] = {
|
||||
STRING_PAIR(IMAGE_SYM_CLASS_END_OF_FUNCTION),
|
||||
STRING_PAIR(IMAGE_SYM_CLASS_NULL),
|
||||
@@ -149,7 +150,7 @@ SymbolStorageClassPairs [] = {
|
||||
STRING_PAIR(IMAGE_SYM_CLASS_CLR_TOKEN),
|
||||
};
|
||||
|
||||
static const pod_pair<llvm::COFF::RelocationTypeX86, const char *>
|
||||
static const pod_pair<COFF::RelocationTypeX86, const char *>
|
||||
RelocationTypeX86Pairs [] = {
|
||||
STRING_PAIR(IMAGE_REL_I386_ABSOLUTE),
|
||||
STRING_PAIR(IMAGE_REL_I386_DIR16),
|
||||
@@ -181,7 +182,7 @@ RelocationTypeX86Pairs [] = {
|
||||
STRING_PAIR(IMAGE_REL_AMD64_SSPAN32)
|
||||
};
|
||||
|
||||
static const pod_pair<llvm::COFF::RelocationTypesARM, const char *>
|
||||
static const pod_pair<COFF::RelocationTypesARM, const char *>
|
||||
RelocationTypesARMPairs [] = {
|
||||
STRING_PAIR(IMAGE_REL_ARM_ABSOLUTE),
|
||||
STRING_PAIR(IMAGE_REL_ARM_ADDR32),
|
||||
@@ -203,7 +204,7 @@ RelocationTypesARMPairs [] = {
|
||||
|
||||
namespace yaml { // COFF-specific yaml-writing specific routines
|
||||
|
||||
static llvm::raw_ostream &writeName(llvm::raw_ostream &Out,
|
||||
static raw_ostream &writeName(raw_ostream &Out,
|
||||
const char *Name, std::size_t NameSize) {
|
||||
for (std::size_t i = 0; i < NameSize; ++i) {
|
||||
if (!Name[i]) break;
|
||||
@@ -214,8 +215,9 @@ static llvm::raw_ostream &writeName(llvm::raw_ostream &Out,
|
||||
|
||||
// Given an array of pod_pair<enum, const char *>, write all enums that match
|
||||
template <typename T, std::size_t N>
|
||||
static llvm::raw_ostream &writeBitMask(llvm::raw_ostream &Out,
|
||||
const pod_pair<T, const char *> (&Arr)[N], unsigned long Val) {
|
||||
static raw_ostream &writeBitMask(raw_ostream &Out,
|
||||
const pod_pair<T, const char *> (&Arr)[N],
|
||||
unsigned long Val) {
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
if (Val & Arr[i].first)
|
||||
Out << Arr[i].second << ", ";
|
||||
@@ -236,8 +238,8 @@ const char *nameLookup(const pod_pair<T, const char *> (&Arr)[N],
|
||||
}
|
||||
|
||||
|
||||
static llvm::raw_ostream &yamlCOFFHeader(
|
||||
const llvm::object::coff_file_header *Header,llvm::raw_ostream &Out) {
|
||||
static raw_ostream &yamlCOFFHeader(const object::coff_file_header *Header,
|
||||
raw_ostream &Out) {
|
||||
|
||||
Out << "header: !Header\n";
|
||||
Out << " Machine: ";
|
||||
@@ -247,13 +249,14 @@ static llvm::raw_ostream &yamlCOFFHeader(
|
||||
}
|
||||
|
||||
|
||||
static llvm::raw_ostream &yamlCOFFSections(llvm::object::COFFObjectFile &Obj,
|
||||
std::size_t NumSections, llvm::raw_ostream &Out) {
|
||||
llvm::error_code ec;
|
||||
static raw_ostream &yamlCOFFSections(object::COFFObjectFile &Obj,
|
||||
std::size_t NumSections,
|
||||
raw_ostream &Out) {
|
||||
error_code ec;
|
||||
Out << "sections:\n";
|
||||
for (llvm::object::section_iterator iter = Obj.begin_sections();
|
||||
for (object::section_iterator iter = Obj.begin_sections();
|
||||
iter != Obj.end_sections(); iter.increment(ec)) {
|
||||
const llvm::object::coff_section *sect = Obj.getCOFFSection(iter);
|
||||
const object::coff_section *sect = Obj.getCOFFSection(iter);
|
||||
|
||||
Out << " - !Section\n";
|
||||
Out << " Name: ";
|
||||
@@ -268,15 +271,15 @@ static llvm::raw_ostream &yamlCOFFSections(llvm::object::COFFObjectFile &Obj,
|
||||
Out << "] # ";
|
||||
yaml::writeHexNumber(Out, sect->Characteristics) << '\n';
|
||||
|
||||
llvm::ArrayRef<uint8_t> sectionData;
|
||||
ArrayRef<uint8_t> sectionData;
|
||||
Obj.getSectionContents(sect, sectionData);
|
||||
Out << " SectionData: ";
|
||||
yaml::writeHexStream(Out, sectionData) << '\n';
|
||||
if (iter->begin_relocations() != iter->end_relocations())
|
||||
Out << " Relocations:\n";
|
||||
for (llvm::object::relocation_iterator rIter = iter->begin_relocations();
|
||||
for (object::relocation_iterator rIter = iter->begin_relocations();
|
||||
rIter != iter->end_relocations(); rIter.increment(ec)) {
|
||||
const llvm::object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
|
||||
const object::coff_relocation *reloc = Obj.getCOFFRelocation(rIter);
|
||||
|
||||
Out << " - !Relocation\n";
|
||||
Out << " VirtualAddress: " ;
|
||||
@@ -292,15 +295,16 @@ static llvm::raw_ostream &yamlCOFFSections(llvm::object::COFFObjectFile &Obj,
|
||||
return Out;
|
||||
}
|
||||
|
||||
static llvm::raw_ostream& yamlCOFFSymbols(llvm::object::COFFObjectFile &Obj,
|
||||
std::size_t NumSymbols, llvm::raw_ostream &Out) {
|
||||
llvm::error_code ec;
|
||||
static raw_ostream& yamlCOFFSymbols(object::COFFObjectFile &Obj,
|
||||
std::size_t NumSymbols,
|
||||
raw_ostream &Out) {
|
||||
error_code ec;
|
||||
Out << "symbols:\n";
|
||||
for (llvm::object::symbol_iterator iter = Obj.begin_symbols();
|
||||
for (object::symbol_iterator iter = Obj.begin_symbols();
|
||||
iter != Obj.end_symbols(); iter.increment(ec)) {
|
||||
// Gather all the info that we need
|
||||
llvm::StringRef str;
|
||||
const llvm::object::coff_symbol *symbol = Obj.getCOFFSymbol(iter);
|
||||
StringRef str;
|
||||
const object::coff_symbol *symbol = Obj.getCOFFSymbol(iter);
|
||||
Obj.getSymbolName(symbol, str);
|
||||
std::size_t simpleType = symbol->getBaseType();
|
||||
std::size_t complexType = symbol->getComplexType();
|
||||
@@ -328,7 +332,7 @@ static llvm::raw_ostream& yamlCOFFSymbols(llvm::object::COFFObjectFile &Obj,
|
||||
<< " # (" << (int) storageClass << ")\n";
|
||||
|
||||
if (symbol->NumberOfAuxSymbols > 0) {
|
||||
llvm::ArrayRef<uint8_t> aux = Obj.getSymbolAuxData(symbol);
|
||||
ArrayRef<uint8_t> aux = Obj.getSymbolAuxData(symbol);
|
||||
Out << " NumberOfAuxSymbols: "
|
||||
<< (int) symbol->NumberOfAuxSymbols << '\n';
|
||||
Out << " AuxillaryData: ";
|
||||
@@ -342,17 +346,20 @@ static llvm::raw_ostream& yamlCOFFSymbols(llvm::object::COFFObjectFile &Obj,
|
||||
}
|
||||
|
||||
|
||||
llvm::error_code coff2yaml(llvm::raw_ostream &Out, llvm::MemoryBuffer *TheObj) {
|
||||
llvm::error_code ec;
|
||||
llvm::object::COFFObjectFile obj(TheObj, ec);
|
||||
if (!ec) {
|
||||
const llvm::object::coff_file_header *hd;
|
||||
error_code coff2yaml(raw_ostream &Out, MemoryBuffer *TheObj) {
|
||||
error_code ec;
|
||||
object::COFFObjectFile obj(TheObj, ec);
|
||||
if (ec)
|
||||
return ec;
|
||||
|
||||
const object::coff_file_header *hd;
|
||||
ec = obj.getHeader(hd);
|
||||
if (!ec) {
|
||||
if (ec)
|
||||
return ec;
|
||||
|
||||
yamlCOFFHeader(hd, Out);
|
||||
yamlCOFFSections(obj, hd->NumberOfSections, Out);
|
||||
yamlCOFFSymbols(obj, hd->NumberOfSymbols, Out);
|
||||
}
|
||||
}
|
||||
|
||||
return ec;
|
||||
}
|
||||
|
Reference in New Issue
Block a user