Use early returns to reduce nesting.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204171 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rui Ueyama 2014-03-18 18:58:51 +00:00
parent 50e4d56b9f
commit 172c31844b

View File

@ -699,79 +699,79 @@ static void PrintCOFFSymbolTable(const COFFObjectFile *coff) {
static void PrintSymbolTable(const ObjectFile *o) { static void PrintSymbolTable(const ObjectFile *o) {
outs() << "SYMBOL TABLE:\n"; outs() << "SYMBOL TABLE:\n";
if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o)) if (const COFFObjectFile *coff = dyn_cast<const COFFObjectFile>(o)) {
PrintCOFFSymbolTable(coff); PrintCOFFSymbolTable(coff);
else { return;
for (const SymbolRef &Symbol : o->symbols()) { }
StringRef Name; for (const SymbolRef &Symbol : o->symbols()) {
uint64_t Address; StringRef Name;
SymbolRef::Type Type; uint64_t Address;
uint64_t Size; SymbolRef::Type Type;
uint32_t Flags = Symbol.getFlags(); uint64_t Size;
section_iterator Section = o->section_end(); uint32_t Flags = Symbol.getFlags();
if (error(Symbol.getName(Name))) section_iterator Section = o->section_end();
continue; if (error(Symbol.getName(Name)))
if (error(Symbol.getAddress(Address))) continue;
continue; if (error(Symbol.getAddress(Address)))
if (error(Symbol.getType(Type))) continue;
continue; if (error(Symbol.getType(Type)))
if (error(Symbol.getSize(Size))) continue;
continue; if (error(Symbol.getSize(Size)))
if (error(Symbol.getSection(Section))) continue;
continue; if (error(Symbol.getSection(Section)))
continue;
bool Global = Flags & SymbolRef::SF_Global; bool Global = Flags & SymbolRef::SF_Global;
bool Weak = Flags & SymbolRef::SF_Weak; bool Weak = Flags & SymbolRef::SF_Weak;
bool Absolute = Flags & SymbolRef::SF_Absolute; bool Absolute = Flags & SymbolRef::SF_Absolute;
if (Address == UnknownAddressOrSize) if (Address == UnknownAddressOrSize)
Address = 0; Address = 0;
if (Size == UnknownAddressOrSize) if (Size == UnknownAddressOrSize)
Size = 0; Size = 0;
char GlobLoc = ' '; char GlobLoc = ' ';
if (Type != SymbolRef::ST_Unknown) if (Type != SymbolRef::ST_Unknown)
GlobLoc = Global ? 'g' : 'l'; GlobLoc = Global ? 'g' : 'l';
char Debug = (Type == SymbolRef::ST_Debug || Type == SymbolRef::ST_File) char Debug = (Type == SymbolRef::ST_Debug || Type == SymbolRef::ST_File)
? 'd' : ' '; ? 'd' : ' ';
char FileFunc = ' '; char FileFunc = ' ';
if (Type == SymbolRef::ST_File) if (Type == SymbolRef::ST_File)
FileFunc = 'f'; FileFunc = 'f';
else if (Type == SymbolRef::ST_Function) else if (Type == SymbolRef::ST_Function)
FileFunc = 'F'; FileFunc = 'F';
const char *Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 : const char *Fmt = o->getBytesInAddress() > 4 ? "%016" PRIx64 :
"%08" PRIx64; "%08" PRIx64;
outs() << format(Fmt, Address) << " " outs() << format(Fmt, Address) << " "
<< GlobLoc // Local -> 'l', Global -> 'g', Neither -> ' ' << GlobLoc // Local -> 'l', Global -> 'g', Neither -> ' '
<< (Weak ? 'w' : ' ') // Weak? << (Weak ? 'w' : ' ') // Weak?
<< ' ' // Constructor. Not supported yet. << ' ' // Constructor. Not supported yet.
<< ' ' // Warning. Not supported yet. << ' ' // Warning. Not supported yet.
<< ' ' // Indirect reference to another symbol. << ' ' // Indirect reference to another symbol.
<< Debug // Debugging (d) or dynamic (D) symbol. << Debug // Debugging (d) or dynamic (D) symbol.
<< FileFunc // Name of function (F), file (f) or object (O). << FileFunc // Name of function (F), file (f) or object (O).
<< ' '; << ' ';
if (Absolute) if (Absolute) {
outs() << "*ABS*"; outs() << "*ABS*";
else if (Section == o->section_end()) } else if (Section == o->section_end()) {
outs() << "*UND*"; outs() << "*UND*";
else { } else {
if (const MachOObjectFile *MachO = if (const MachOObjectFile *MachO =
dyn_cast<const MachOObjectFile>(o)) { dyn_cast<const MachOObjectFile>(o)) {
DataRefImpl DR = Section->getRawDataRefImpl(); DataRefImpl DR = Section->getRawDataRefImpl();
StringRef SegmentName = MachO->getSectionFinalSegmentName(DR); StringRef SegmentName = MachO->getSectionFinalSegmentName(DR);
outs() << SegmentName << ","; outs() << SegmentName << ",";
}
StringRef SectionName;
if (error(Section->getName(SectionName)))
SectionName = "";
outs() << SectionName;
} }
outs() << '\t' StringRef SectionName;
<< format("%08" PRIx64 " ", Size) if (error(Section->getName(SectionName)))
<< Name SectionName = "";
<< '\n'; outs() << SectionName;
} }
outs() << '\t'
<< format("%08" PRIx64 " ", Size)
<< Name
<< '\n';
} }
} }