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