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