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