1//===- impl.cpp -----------------------------------------------------------===//
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#include "X86GOT.h"
10
11#include <mcld/LD/LDFileFormat.h>
12#include <mcld/LD/SectionData.h>
13
14#include <llvm/Support/Casting.h>
15
16using namespace mcld;
17
18//===----------------------------------------------------------------------===//
19// X86_32GOT
20//===----------------------------------------------------------------------===//
21X86_32GOT::X86_32GOT(LDSection& pSection)
22  : GOT(pSection), m_pLast(NULL)
23{
24}
25
26X86_32GOT::~X86_32GOT()
27{
28}
29
30void X86_32GOT::reserve(size_t pNum)
31{
32  for (size_t i = 0; i < pNum; i++) {
33    new X86_32GOTEntry(0, m_SectionData);
34  }
35}
36
37X86_32GOTEntry* X86_32GOT::consume()
38{
39  if (NULL == m_pLast) {
40    assert(!empty() && "Consume empty GOT entry!");
41    m_pLast = llvm::cast<X86_32GOTEntry>(&m_SectionData->front());
42    return m_pLast;
43  }
44
45  m_pLast = llvm::cast<X86_32GOTEntry>(m_pLast->getNextNode());
46  return m_pLast;
47}
48
49//===----------------------------------------------------------------------===//
50// X86_64GOT
51//===----------------------------------------------------------------------===//
52X86_64GOT::X86_64GOT(LDSection& pSection)
53  : GOT(pSection), m_pLast(NULL)
54{
55}
56
57X86_64GOT::~X86_64GOT()
58{
59}
60
61void X86_64GOT::reserve(size_t pNum)
62{
63  for (size_t i = 0; i < pNum; i++) {
64    new X86_64GOTEntry(0, m_SectionData);
65  }
66}
67
68X86_64GOTEntry* X86_64GOT::consume()
69{
70  if (NULL == m_pLast) {
71    assert(!empty() && "Consume empty GOT entry!");
72    m_pLast = llvm::cast<X86_64GOTEntry>(&m_SectionData->front());
73    return m_pLast;
74  }
75
76  m_pLast = llvm::cast<X86_64GOTEntry>(m_pLast->getNextNode());
77  return m_pLast;
78}
79
80