MipsGOT.h revision affc150dc44fab1911775a49636d0ce85333b634
1//===- MipsGOT.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_MIPS_GOT_H 10#define MCLD_MIPS_GOT_H 11#ifdef ENABLE_UNITTEST 12#include <gtest.h> 13#endif 14 15#include <mcld/Target/GOT.h> 16 17namespace mcld 18{ 19class LDSection; 20class MemoryRegion; 21 22/** \class MipsGOT 23 * \brief Mips Global Offset Table. 24 */ 25class MipsGOT : public GOT 26{ 27private: 28 typedef llvm::DenseMap<const ResolveInfo*, GOTEntry*> SymbolIndexMapType; 29 typedef llvm::DenseMap<const ResolveInfo*, bool> SymbolTypeMapType; 30 31public: 32 typedef llvm::MCSectionData::iterator iterator; 33 typedef llvm::MCSectionData::const_iterator const_iterator; 34 35public: 36 MipsGOT(LDSection& pSection, llvm::MCSectionData& pSectionData); 37 38 iterator begin(); 39 iterator end(); 40 41 const_iterator begin() const; 42 const_iterator end() const; 43 44 uint64_t emit(MemoryRegion& pRegion); 45 46 void reserveLocalEntry(); 47 void reserveGlobalEntry(); 48 49 GOTEntry* getEntry(const ResolveInfo& pInfo, bool& pExist); 50 51 size_t getTotalNum() const; 52 size_t getLocalNum() const; 53 54 void setLocal(const ResolveInfo* pInfo) { 55 m_GOTTypeMap[pInfo] = false; 56 } 57 58 void setGlobal(const ResolveInfo* pInfo) { 59 m_GOTTypeMap[pInfo] = true; 60 } 61 62 bool isLocal(const ResolveInfo* pInfo) { 63 return m_GOTTypeMap[pInfo] == false; 64 } 65 66 bool isGlobal(const ResolveInfo* pInfo) { 67 return m_GOTTypeMap[pInfo] == true; 68 } 69 70private: 71 SymbolIndexMapType m_GeneralGOTMap; // Map ResolveInfo* to GOTEntry *. 72 SymbolTypeMapType m_GOTTypeMap; 73 74 iterator m_LocalGOTIterator; // last local GOT entries 75 iterator m_GlobalGOTIterator; // last global GOT entries 76 size_t m_pLocalNum; 77 78private: 79 // Use reserveLocalEntry()/reserveGlobalEntry() instead of this routine. 80 void reserveEntry(size_t pNum = 1); 81}; 82 83} // namespace of mcld 84 85#endif 86 87