Input.h revision 533eae20118036f425f27bf0536ef0ccbb090b65
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  off_t fileOffset() const
98  { return m_fileOffset; }
99
100  void setFileOffset(off_t pFileOffset)
101  { m_fileOffset = pFileOffset; }
102
103  // -----  memory area  ----- //
104  void setMemArea(MemoryArea* pMemArea)
105  { m_pMemArea = pMemArea; }
106
107  bool hasMemArea() const
108  { return (NULL != m_pMemArea); }
109
110  const MemoryArea* memArea() const { return m_pMemArea; }
111  MemoryArea*       memArea()       { return m_pMemArea; }
112
113  // -----  context  ----- //
114  void setContext(LDContext* pContext)
115  { m_pContext = pContext; }
116
117  bool hasContext() const
118  { return (NULL != m_pContext); }
119
120  const LDContext* context() const { return m_pContext; }
121  LDContext*       context()       { return m_pContext; }
122
123private:
124  unsigned int m_Type;
125  std::string m_Name;
126  sys::fs::Path m_Path;
127  Attribute *m_pAttr;
128  bool m_bNeeded;
129  off_t m_fileOffset;
130  MemoryArea* m_pMemArea;
131  LDContext* m_pContext;
132};
133
134} // namespace of mcld
135
136#endif
137
138