1 //===- InputSectDesc.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/Script/InputSectDesc.h> 10 #include <mcld/Script/WildcardPattern.h> 11 #include <mcld/Support/raw_ostream.h> 12 #include <mcld/LinkerScript.h> 13 #include <mcld/Module.h> 14 #include <llvm/Support/Casting.h> 15 16 using namespace mcld; 17 18 //===----------------------------------------------------------------------===// 19 // InputSectDesc 20 //===----------------------------------------------------------------------===// 21 InputSectDesc::InputSectDesc(KeepPolicy pPolicy, 22 const Spec& pSpec, 23 const OutputSectDesc& pOutputDesc) 24 : ScriptCommand(ScriptCommand::INPUT_SECT_DESC), 25 m_KeepPolicy(pPolicy), 26 m_Spec(pSpec), 27 m_OutputSectDesc(pOutputDesc) 28 { 29 } 30 31 InputSectDesc::~InputSectDesc() 32 { 33 } 34 35 void InputSectDesc::dump() const 36 { 37 if (m_KeepPolicy == Keep) 38 mcld::outs() << "KEEP ("; 39 40 assert (m_Spec.hasFile()); 41 if (m_Spec.file().sortPolicy() == WildcardPattern::SORT_BY_NAME) 42 mcld::outs() << "SORT ("; 43 44 mcld::outs() << m_Spec.file().name(); 45 46 if (m_Spec.hasSections()) { 47 mcld::outs() << "("; 48 49 if (m_Spec.hasExcludeFiles()) { 50 mcld::outs() << "EXCLUDE_FILE ("; 51 for (StringList::const_iterator it = m_Spec.excludeFiles().begin(), 52 ie = m_Spec.excludeFiles().end(); it != ie; ++it) { 53 mcld::outs() << (*it)->name() << " "; 54 } 55 mcld::outs() << ")"; 56 } 57 58 if (m_Spec.hasSections()) { 59 for (StringList::const_iterator it = m_Spec.sections().begin(), 60 ie = m_Spec.sections().end(); it != ie; ++it) { 61 assert((*it)->kind() == StrToken::Wildcard); 62 WildcardPattern* wildcard = llvm::cast<WildcardPattern>(*it); 63 64 switch (wildcard->sortPolicy()) { 65 case WildcardPattern::SORT_BY_NAME: 66 mcld::outs() << "SORT ("; 67 break; 68 case WildcardPattern::SORT_BY_ALIGNMENT: 69 mcld::outs() << "SORT_BY_ALIGNMENT ("; 70 break; 71 case WildcardPattern::SORT_BY_NAME_ALIGNMENT: 72 mcld::outs() << "SORT_BY_NAME_ALIGNMENT ("; 73 break; 74 case WildcardPattern::SORT_BY_ALIGNMENT_NAME: 75 mcld::outs() << "SORT_BY_ALIGNMENT_NAME ("; 76 break; 77 default: 78 break; 79 } 80 81 mcld::outs() << wildcard->name() << " "; 82 83 if (wildcard->sortPolicy() != WildcardPattern::SORT_NONE) 84 mcld::outs() << ")"; 85 } 86 } 87 mcld::outs() << ")"; 88 } 89 90 if (m_Spec.file().sortPolicy() == WildcardPattern::SORT_BY_NAME) 91 mcld::outs() << ")"; 92 93 if (m_KeepPolicy == Keep) 94 mcld::outs() << ")"; 95 96 mcld::outs() << "\n"; 97 } 98 99 void InputSectDesc::activate(Module& pModule) 100 { 101 pModule.getScript().sectionMap().insert(*this, m_OutputSectDesc); 102 } 103