Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 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 | //===----------------------------------------------------------------------===// |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 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" |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 16 | |
| 17 | #include <llvm/ADT/Triple.h> |
| 18 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 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 |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 26 | * bitcode() - the bitcode being linked |
| 27 | * attribute() - the attribute options |
| 28 | */ |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 29 | class LinkerConfig { |
| 30 | public: |
| 31 | enum CodeGenType { Unknown, Object, DynObj, Exec, External, Binary }; |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 32 | |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 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 { |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 50 | Independent, ///< Position Independent |
| 51 | DynamicDependent, ///< Can call outside libraries |
| 52 | StaticDependent, ///< Can not call outside libraries |
| 53 | Unset ///< Undetermine code position mode |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 54 | }; |
| 55 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 56 | public: |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 57 | LinkerConfig(); |
| 58 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 59 | explicit LinkerConfig(const std::string& pTripleString); |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 60 | |
| 61 | ~LinkerConfig(); |
| 62 | |
| 63 | const GeneralOptions& options() const { return m_Options; } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 64 | GeneralOptions& options() { return m_Options; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 65 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 66 | const TargetOptions& targets() const { return m_Targets; } |
| 67 | TargetOptions& targets() { return m_Targets; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 68 | |
| 69 | const AttributeOption& attribute() const { return m_Attribute; } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 70 | AttributeOption& attribute() { return m_Attribute; } |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 71 | |
| 72 | CodeGenType codeGenType() const { return m_CodeGenType; } |
| 73 | |
| 74 | void setCodeGenType(CodeGenType pType) { m_CodeGenType = pType; } |
| 75 | |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 76 | CodePosition codePosition() const { return m_CodePosition; } |
| 77 | void setCodePosition(CodePosition pPosition) { m_CodePosition = pPosition; } |
| 78 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 79 | bool isCodeIndep() const { return (Independent == m_CodePosition); } |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 80 | bool isCodeDynamic() const { return (DynamicDependent == m_CodePosition); } |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 81 | bool isCodeStatic() const { return (StaticDependent == m_CodePosition); } |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 82 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 83 | static const char* version(); |
| 84 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 85 | private: |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 86 | // ----- General Options ----- // |
| 87 | GeneralOptions m_Options; |
Shih-wei Liao | d0fbbb2 | 2013-01-03 06:23:31 -0800 | [diff] [blame] | 88 | TargetOptions m_Targets; |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 89 | AttributeOption m_Attribute; |
| 90 | |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 91 | CodeGenType m_CodeGenType; |
Stephen Hines | 6f75755 | 2013-03-04 19:51:03 -0800 | [diff] [blame] | 92 | CodePosition m_CodePosition; |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 93 | }; |
| 94 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 95 | } // namespace mcld |
Shih-wei Liao | 22add6f | 2012-12-15 17:21:00 -0800 | [diff] [blame] | 96 | |
Stephen Hines | 37b74a3 | 2014-11-26 18:48:20 -0800 | [diff] [blame] | 97 | #endif // MCLD_LINKERCONFIG_H_ |