summaryrefslogtreecommitdiff
path: root/include/mcld/Fragment/Fragment.h
blob: 3e848117f4a3809bcf31829407b8ff7562c7bb86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//===- Fragment.h ---------------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef MCLD_FRAGMENT_FRAGMENT_H_
#define MCLD_FRAGMENT_FRAGMENT_H_

#include "mcld/Support/Compiler.h"

#include <llvm/ADT/ilist_node.h>
#include <llvm/Support/DataTypes.h>

#include <cassert>
#include <cstddef>

namespace mcld {

class SectionData;

/** \class Fragment
 *  \brief Fragment is the minimun linking unit of MCLinker.
 */
class Fragment : public llvm::ilist_node_with_parent<Fragment, SectionData> {
 public:
  enum Type { Alignment, Fillment, Region, Target, Stub, Null };

 public:
  Fragment();

  explicit Fragment(Type pKind, SectionData* pParent = NULL);

  virtual ~Fragment();

  Type getKind() const { return m_Kind; }

  const SectionData* getParent() const { return m_pParent; }
  SectionData* getParent() { return m_pParent; }

  void setParent(SectionData* pValue) { m_pParent = pValue; }

  uint64_t getOffset() const;

  void setOffset(uint64_t pOffset) { m_Offset = pOffset; }

  bool hasOffset() const;

  static bool classof(const Fragment* O) { return true; }

  virtual size_t size() const {
    assert(false && "Can not call abstract Fragment::size()!");
    return 0;
  }

 private:
  Type m_Kind;

  SectionData* m_pParent;

  uint64_t m_Offset;

 private:
  DISALLOW_COPY_AND_ASSIGN(Fragment);
};

}  // namespace mcld

#endif  // MCLD_FRAGMENT_FRAGMENT_H_