Refactor the RelocVisitor::visit method

This change replaces the brittle if/else chain of string comparisons
with a switch statement on the detected target triple, removing the
need for testing arbitrary architecture names returned from
getFileFormatName, whose primary purpose seems to be for display
(user-interface) purposes. The visitor now takes a reference to the
object file, rather than its arbitrary file format name to figure out
whether the file is a 32 or 64-bit object file and what the detected
target triple is.

A set of tests have been added to help show that the refactoring processes
relocations for the same targets as the original code.

Patch by Charlie Turner.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218388 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Renato Golin
2014-09-24 17:00:42 +00:00
parent cfc42962c8
commit faac033f73
4 changed files with 144 additions and 98 deletions

View File

@@ -667,7 +667,7 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile &Obj)
Sym->getAddress(SymAddr);
}
object::RelocVisitor V(Obj.getFileFormatName());
object::RelocVisitor V(Obj);
// The section address is always 0 for debug sections.
object::RelocToApply R(V.visit(Type, Reloc, 0, SymAddr));
if (V.error()) {