1//===- Input.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//
10//  Input class inherits MCLDFile, which is used to represent a input file
11//
12//===----------------------------------------------------------------------===//
13#ifndef MCLD_MC_INPUT_H
14#define MCLD_MC_INPUT_H
15
16#include <mcld/Support/Path.h>
17
18namespace mcld {
19
20class MemoryArea;
21class AttributeProxy;
22class Attribute;
23class InputFactory;
24class LDContext;
25
26/** \class Input
27 *  \brief Input provides the information of a input file.
28 */
29class Input
30{
31friend class InputFactory;
32public:
33  enum Type {
34    Unknown,
35    Binary,
36    Object,
37    Exec,
38    DynObj,
39    CoreFile,
40    Script,
41    Archive,
42    External
43  };
44
45public:
46  explicit Input(llvm::StringRef pName);
47
48  Input(llvm::StringRef pName,
49        const AttributeProxy& pAttr);
50
51  Input(llvm::StringRef pName,
52        const sys::fs::Path& pPath,
53        unsigned int pType = Unknown,
54        off_t pFileOffset = 0);
55
56  Input(llvm::StringRef pName,
57        const sys::fs::Path& pPath,
58        const AttributeProxy& pAttr,
59        unsigned int pType = Unknown,
60        off_t pFileOffset = 0);
61
62  ~Input();
63
64  const std::string& name() const
65  { return m_Name; }
66
67  void setName(const std::string& pName)
68  { m_Name = pName; }
69
70  const sys::fs::Path& path() const
71  { return m_Path; }
72
73  void setPath(const sys::fs::Path& pPath)
74  { m_Path = pPath; }
75
76  void setType(unsigned int pType)
77  { m_Type = pType; }
78
79  unsigned int type() const
80  { return m_Type; }
81
82  bool isRecognized() const
83  { return (m_Type != Unknown); }
84
85  bool hasAttribute() const
86  { return (NULL != m_pAttr); }
87
88  const Attribute* attribute() const
89  { return m_pAttr; }
90
91  bool isNeeded() const
92  { return m_bNeeded; }
93
94  void setNeeded()
95  { m_bNeeded = true; }
96
97  bool noExport() const
98  { return m_bNoExport; }
99
100  void setNoExport()
101  { m_bNoExport = true; }
102
103  off_t fileOffset() const
104  { return m_fileOffset; }
105
106  void setFileOffset(off_t pFileOffset)
107  { m_fileOffset = pFileOffset; }
108
109  // -----  memory area  ----- //
110  void setMemArea(MemoryArea* pMemArea)
111  { m_pMemArea = pMemArea; }
112
113  bool hasMemArea() const
114  { return (NULL != m_pMemArea); }
115
116  const MemoryArea* memArea() const { return m_pMemArea; }
117  MemoryArea*       memArea()       { return m_pMemArea; }
118
119  // -----  context  ----- //
120  void setContext(LDContext* pContext)
121  { m_pContext = pContext; }
122
123  bool hasContext() const
124  { return (NULL != m_pContext); }
125
126  const LDContext* context() const { return m_pContext; }
127  LDContext*       context()       { return m_pContext; }
128
129private:
130  unsigned int m_Type;
131  std::string m_Name;
132  sys::fs::Path m_Path;
133  Attribute *m_pAttr;
134  bool m_bNeeded;
135  bool m_bNoExport;
136  off_t m_fileOffset;
137  MemoryArea* m_pMemArea;
138  LDContext* m_pContext;
139};
140
141} // namespace of mcld
142
143#endif
144
145