1 //===- LinkerConfig.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 #ifndef MCLD_LINKERCONFIG_H_
10 #define MCLD_LINKERCONFIG_H_
11 
12 #include "mcld/GeneralOptions.h"
13 #include "mcld/TargetOptions.h"
14 #include "mcld/AttributeOption.h"
15 #include "mcld/Support/Path.h"
16 
17 #include <llvm/ADT/Triple.h>
18 
19 #include <string>
20 
21 namespace mcld {
22 
23 /** \class LinkerConfig
24  *  \brief LinkerConfig is composed of argumments of MCLinker.
25  *   options()        - the general options
26  *   bitcode()        - the bitcode being linked
27  *   attribute()      - the attribute options
28  */
29 class LinkerConfig {
30  public:
31   enum CodeGenType { Unknown, Object, DynObj, Exec, External, Binary };
32 
33   /** \enum CodePosition
34    *  CodePosition indicates the ability of the generated output to be
35    *  loaded at different addresses. If the output can be loaded at different
36    *  addresses, we say the output is position independent. Shared libraries
37    *  and position-independent executable programs (PIE) are in this category.
38    *  ::Independent indicates the output is position independent.
39    *  If a executable program can not be loaded at arbitrary addresses, but it
40    *  can call outside functions, we say the program is dynamic dependent on
41    *  the address to be loaded. ::DynamicDependent indicates the output is not
42    *  only a executable program, but also dynamic dependent. In general,
43    *  executable programs are dynamic dependent.
44    *  If a executable program can not be loaded at different addresses, and
45    *  only call inner functions, then we say the program is static dependent on
46    *  its loaded address. ::StaticDependent is used to indicate this kind of
47    *  output.
48    */
49   enum CodePosition {
50     Independent,       ///< Position Independent
51     DynamicDependent,  ///< Can call outside libraries
52     StaticDependent,   ///< Can not call outside libraries
53     Unset              ///< Undetermine code position mode
54   };
55 
56  public:
57   LinkerConfig();
58 
59   explicit LinkerConfig(const std::string& pTripleString);
60 
61   ~LinkerConfig();
62 
options()63   const GeneralOptions& options() const { return m_Options; }
options()64   GeneralOptions& options() { return m_Options; }
65 
targets()66   const TargetOptions& targets() const { return m_Targets; }
targets()67   TargetOptions& targets() { return m_Targets; }
68 
attribute()69   const AttributeOption& attribute() const { return m_Attribute; }
attribute()70   AttributeOption& attribute() { return m_Attribute; }
71 
codeGenType()72   CodeGenType codeGenType() const { return m_CodeGenType; }
73 
setCodeGenType(CodeGenType pType)74   void setCodeGenType(CodeGenType pType) { m_CodeGenType = pType; }
75 
codePosition()76   CodePosition codePosition() const { return m_CodePosition; }
setCodePosition(CodePosition pPosition)77   void setCodePosition(CodePosition pPosition) { m_CodePosition = pPosition; }
78 
isCodeIndep()79   bool isCodeIndep() const { return (Independent == m_CodePosition); }
isCodeDynamic()80   bool isCodeDynamic() const { return (DynamicDependent == m_CodePosition); }
isCodeStatic()81   bool isCodeStatic() const { return (StaticDependent == m_CodePosition); }
82 
83   static const char* version();
84 
85  private:
86   // -----  General Options  ----- //
87   GeneralOptions m_Options;
88   TargetOptions m_Targets;
89   AttributeOption m_Attribute;
90 
91   CodeGenType m_CodeGenType;
92   CodePosition m_CodePosition;
93 };
94 
95 }  // namespace mcld
96 
97 #endif  // MCLD_LINKERCONFIG_H_
98