blob: 36033e723017213f8d0613ad8d5ae24dfea330e5 [file] [log] [blame]
Shih-wei Liao22add6f2012-12-15 17:21:00 -08001//===- 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 Hines37b74a32014-11-26 18:48:20 -08009#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 Liao22add6f2012-12-15 17:21:00 -080016
17#include <llvm/ADT/Triple.h>
18
Shih-wei Liao22add6f2012-12-15 17:21:00 -080019#include <string>
20
21namespace mcld {
22
23/** \class LinkerConfig
24 * \brief LinkerConfig is composed of argumments of MCLinker.
25 * options() - the general options
Shih-wei Liao22add6f2012-12-15 17:21:00 -080026 * bitcode() - the bitcode being linked
27 * attribute() - the attribute options
28 */
Stephen Hines37b74a32014-11-26 18:48:20 -080029class LinkerConfig {
30 public:
31 enum CodeGenType { Unknown, Object, DynObj, Exec, External, Binary };
Shih-wei Liao22add6f2012-12-15 17:21:00 -080032
Stephen Hines6f757552013-03-04 19:51:03 -080033 /** \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 Hines37b74a32014-11-26 18:48:20 -080050 Independent, ///< Position Independent
51 DynamicDependent, ///< Can call outside libraries
52 StaticDependent, ///< Can not call outside libraries
53 Unset ///< Undetermine code position mode
Stephen Hines6f757552013-03-04 19:51:03 -080054 };
55
Stephen Hines37b74a32014-11-26 18:48:20 -080056 public:
Shih-wei Liao22add6f2012-12-15 17:21:00 -080057 LinkerConfig();
58
Stephen Hines37b74a32014-11-26 18:48:20 -080059 explicit LinkerConfig(const std::string& pTripleString);
Shih-wei Liao22add6f2012-12-15 17:21:00 -080060
61 ~LinkerConfig();
62
63 const GeneralOptions& options() const { return m_Options; }
Stephen Hines37b74a32014-11-26 18:48:20 -080064 GeneralOptions& options() { return m_Options; }
Shih-wei Liao22add6f2012-12-15 17:21:00 -080065
Stephen Hines37b74a32014-11-26 18:48:20 -080066 const TargetOptions& targets() const { return m_Targets; }
67 TargetOptions& targets() { return m_Targets; }
Shih-wei Liao22add6f2012-12-15 17:21:00 -080068
69 const AttributeOption& attribute() const { return m_Attribute; }
Stephen Hines37b74a32014-11-26 18:48:20 -080070 AttributeOption& attribute() { return m_Attribute; }
Shih-wei Liao22add6f2012-12-15 17:21:00 -080071
72 CodeGenType codeGenType() const { return m_CodeGenType; }
73
74 void setCodeGenType(CodeGenType pType) { m_CodeGenType = pType; }
75
Stephen Hines6f757552013-03-04 19:51:03 -080076 CodePosition codePosition() const { return m_CodePosition; }
77 void setCodePosition(CodePosition pPosition) { m_CodePosition = pPosition; }
78
Stephen Hines37b74a32014-11-26 18:48:20 -080079 bool isCodeIndep() const { return (Independent == m_CodePosition); }
Stephen Hines6f757552013-03-04 19:51:03 -080080 bool isCodeDynamic() const { return (DynamicDependent == m_CodePosition); }
Stephen Hines37b74a32014-11-26 18:48:20 -080081 bool isCodeStatic() const { return (StaticDependent == m_CodePosition); }
Stephen Hines6f757552013-03-04 19:51:03 -080082
Shih-wei Liao22add6f2012-12-15 17:21:00 -080083 static const char* version();
84
Stephen Hines37b74a32014-11-26 18:48:20 -080085 private:
Shih-wei Liao22add6f2012-12-15 17:21:00 -080086 // ----- General Options ----- //
87 GeneralOptions m_Options;
Shih-wei Liaod0fbbb22013-01-03 06:23:31 -080088 TargetOptions m_Targets;
Shih-wei Liao22add6f2012-12-15 17:21:00 -080089 AttributeOption m_Attribute;
90
Shih-wei Liao22add6f2012-12-15 17:21:00 -080091 CodeGenType m_CodeGenType;
Stephen Hines6f757552013-03-04 19:51:03 -080092 CodePosition m_CodePosition;
Shih-wei Liao22add6f2012-12-15 17:21:00 -080093};
94
Stephen Hines37b74a32014-11-26 18:48:20 -080095} // namespace mcld
Shih-wei Liao22add6f2012-12-15 17:21:00 -080096
Stephen Hines37b74a32014-11-26 18:48:20 -080097#endif // MCLD_LINKERCONFIG_H_