Relocator.h revision d0fbbb227051be16931a1aa9b4a7722ac039c698
1//===- Relocator.h --------------------------------------------------------===// 2// 3// The MCLinker Project 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9#ifndef MCLD_RELOCATOR_H 10#define MCLD_RELOCATOR_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14 15#include <mcld/Fragment/Relocation.h> 16 17namespace mcld 18{ 19 20class FragmentLinker; 21class TargetLDBackend; 22 23/** \class Relocator 24 * \brief Relocator provides the interface of performing relocations 25 */ 26class Relocator 27{ 28public: 29 typedef Relocation::Type Type; 30 typedef Relocation::Address Address; 31 typedef Relocation::DWord DWord; 32 typedef Relocation::SWord SWord; 33 34public: 35 enum Result { 36 OK, 37 BadReloc, 38 Overflow, 39 Unsupport, 40 Unknown 41 }; 42 43public: 44 virtual ~Relocator() {} 45 46 /// apply - general apply function 47 virtual Result applyRelocation(Relocation& pRelocation) = 0; 48 49 void setFragmentLinker(const FragmentLinker& pLinker) 50 { m_pLinker = &pLinker; } 51 52 // ------ observers -----// 53 const FragmentLinker& getFragmentLinker() const 54 { 55 assert(NULL != m_pLinker); 56 return *m_pLinker; 57 } 58 59 bool hasFragmentLinker() const 60 { return (NULL != m_pLinker); } 61 62 virtual TargetLDBackend& getTarget() = 0; 63 64 virtual const TargetLDBackend& getTarget() const = 0; 65 66 virtual const char* getName(Type pType) const = 0; 67 68private: 69 const FragmentLinker* m_pLinker; 70 71}; 72 73} // namespace of mcld 74 75#endif 76 77