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