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