Home | History | Annotate | Download | only in MC
      1 //===- CommandAction.cpp --------------------------------------------------===//
      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 #include <mcld/MC/CommandAction.h>
     10 #include <mcld/MC/InputBuilder.h>
     11 #include <mcld/MC/SearchDirs.h>
     12 #include <mcld/MC/Attribute.h>
     13 #include <mcld/Support/MsgHandling.h>
     14 
     15 using namespace mcld;
     16 
     17 //===----------------------------------------------------------------------===//
     18 // Derived Positional Option
     19 //===----------------------------------------------------------------------===//
     20 // InputFileAction
     21 //===----------------------------------------------------------------------===//
     22 InputFileAction::InputFileAction(unsigned int pPosition,
     23                                  const sys::fs::Path &pPath)
     24   : InputAction(pPosition), m_Path(pPath) {
     25 }
     26 
     27 bool InputFileAction::activate(InputBuilder& pBuilder) const
     28 {
     29   pBuilder.createNode<InputTree::Positional>(path().stem().native(), path());
     30   return true;
     31 }
     32 
     33 //===----------------------------------------------------------------------===//
     34 // NamespecAction
     35 //===----------------------------------------------------------------------===//
     36 NamespecAction::NamespecAction(unsigned int pPosition,
     37                                const std::string &pNamespec,
     38                                SearchDirs& pSearchDirs)
     39   : InputAction(pPosition), m_Namespec(pNamespec), m_SearchDirs(pSearchDirs) {
     40 }
     41 
     42 bool NamespecAction::activate(InputBuilder& pBuilder) const
     43 {
     44   sys::fs::Path* path = NULL;
     45   // find out the real path of the namespec.
     46   if (pBuilder.getConstraint().isSharedSystem()) {
     47     // In the system with shared object support, we can find both archive
     48     // and shared object.
     49 
     50     if (pBuilder.getAttributes().isStatic()) {
     51       // with --static, we must search an archive.
     52       path = m_SearchDirs.find(namespec(), Input::Archive);
     53     }
     54     else {
     55       // otherwise, with --Bdynamic, we can find either an archive or a
     56       // shared object.
     57       path = m_SearchDirs.find(namespec(), Input::DynObj);
     58     }
     59   }
     60   else {
     61     // In the system without shared object support, we only look for an archive
     62     path = m_SearchDirs.find(namespec(), Input::Archive);
     63   }
     64 
     65   if (NULL == path) {
     66     fatal(diag::err_cannot_find_namespec) << namespec();
     67     return false;
     68   }
     69 
     70   pBuilder.createNode<InputTree::Positional>(namespec(), *path);
     71   return true;
     72 }
     73 
     74 //===----------------------------------------------------------------------===//
     75 // BitcodeAction
     76 //===----------------------------------------------------------------------===//
     77 BitcodeAction::BitcodeAction(unsigned int pPosition, const sys::fs::Path &pPath)
     78   : InputAction(pPosition), m_Path(pPath) {
     79 }
     80 
     81 bool BitcodeAction::activate(InputBuilder& pBuilder) const
     82 {
     83   pBuilder.createNode<InputTree::Positional>("bitcode", path(), Input::External);
     84   return true;
     85 }
     86 
     87 //===----------------------------------------------------------------------===//
     88 // StartGroupAction
     89 //===----------------------------------------------------------------------===//
     90 StartGroupAction::StartGroupAction(unsigned int pPosition)
     91   : InputAction(pPosition) {
     92 }
     93 
     94 bool StartGroupAction::activate(InputBuilder& pBuilder) const
     95 {
     96   if (pBuilder.isInGroup()) {
     97     fatal(diag::fatal_forbid_nest_group);
     98     return false;
     99   }
    100   pBuilder.enterGroup();
    101   return true;
    102 }
    103 
    104 //===----------------------------------------------------------------------===//
    105 // EndGroupAction
    106 //===----------------------------------------------------------------------===//
    107 EndGroupAction::EndGroupAction(unsigned int pPosition)
    108   : InputAction(pPosition) {
    109 }
    110 
    111 bool EndGroupAction::activate(InputBuilder& pBuilder) const
    112 {
    113   pBuilder.exitGroup();
    114   return true;
    115 }
    116 
    117 //===----------------------------------------------------------------------===//
    118 // WholeArchiveAction
    119 //===----------------------------------------------------------------------===//
    120 WholeArchiveAction::WholeArchiveAction(unsigned int pPosition)
    121   : InputAction(pPosition) {
    122 }
    123 
    124 bool WholeArchiveAction::activate(InputBuilder& pBuilder) const
    125 {
    126   pBuilder.getAttributes().setWholeArchive();
    127   return true;
    128 }
    129 
    130 //===----------------------------------------------------------------------===//
    131 // NoWholeArchiveAction
    132 //===----------------------------------------------------------------------===//
    133 NoWholeArchiveAction::NoWholeArchiveAction(unsigned int pPosition)
    134   : InputAction(pPosition) {
    135 }
    136 
    137 bool NoWholeArchiveAction::activate(InputBuilder& pBuilder) const
    138 {
    139   pBuilder.getAttributes().unsetWholeArchive();
    140   return true;
    141 }
    142 
    143 //===----------------------------------------------------------------------===//
    144 // AsNeededAction
    145 //===----------------------------------------------------------------------===//
    146 AsNeededAction::AsNeededAction(unsigned int pPosition)
    147   : InputAction(pPosition) {
    148 }
    149 
    150 bool AsNeededAction::activate(InputBuilder& pBuilder) const
    151 {
    152   pBuilder.getAttributes().setAsNeeded();
    153   return true;
    154 }
    155 
    156 //===----------------------------------------------------------------------===//
    157 // NoAsNeededAction
    158 //===----------------------------------------------------------------------===//
    159 NoAsNeededAction::NoAsNeededAction(unsigned int pPosition)
    160   : InputAction(pPosition) {
    161 }
    162 
    163 bool NoAsNeededAction::activate(InputBuilder& pBuilder) const
    164 {
    165   pBuilder.getAttributes().unsetAsNeeded();
    166   return true;
    167 }
    168 
    169 //===----------------------------------------------------------------------===//
    170 // AddNeededAction
    171 //===----------------------------------------------------------------------===//
    172 AddNeededAction::AddNeededAction(unsigned int pPosition)
    173   : InputAction(pPosition) {
    174 }
    175 
    176 bool AddNeededAction::activate(InputBuilder& pBuilder) const
    177 {
    178   pBuilder.getAttributes().setAddNeeded();
    179   return true;
    180 }
    181 
    182 //===----------------------------------------------------------------------===//
    183 // NoAddNeededAction
    184 //===----------------------------------------------------------------------===//
    185 NoAddNeededAction::NoAddNeededAction(unsigned int pPosition)
    186   : InputAction(pPosition) {
    187 }
    188 
    189 bool NoAddNeededAction::activate(InputBuilder& pBuilder) const
    190 {
    191   pBuilder.getAttributes().unsetAddNeeded();
    192   return true;
    193 }
    194 
    195 //===----------------------------------------------------------------------===//
    196 // BDynamicAction
    197 //===----------------------------------------------------------------------===//
    198 BDynamicAction::BDynamicAction(unsigned int pPosition)
    199   : InputAction(pPosition) {
    200 }
    201 
    202 bool BDynamicAction::activate(InputBuilder& pBuilder) const
    203 {
    204   pBuilder.getAttributes().setDynamic();
    205   return true;
    206 }
    207 
    208 //===----------------------------------------------------------------------===//
    209 // BStaticAction
    210 //===----------------------------------------------------------------------===//
    211 BStaticAction::BStaticAction(unsigned int pPosition)
    212   : InputAction(pPosition) {
    213 }
    214 
    215 bool BStaticAction::activate(InputBuilder& pBuilder) const
    216 {
    217   pBuilder.getAttributes().setStatic();
    218   return true;
    219 }
    220 
    221