diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2016-09-13 13:00:06 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2016-09-13 13:00:06 +0000 |
| commit | 28c1597ad968eb8ec9681c387b5d97de656c720e (patch) | |
| tree | eabac29128a5c3f5dc96cf4b8c091e8ce72f03f6 | |
| parent | 09c1109b12945861d3eab1ef4548d61ba57126ed (diff) | |
| download | bcm5719-llvm-28c1597ad968eb8ec9681c387b5d97de656c720e.tar.gz bcm5719-llvm-28c1597ad968eb8ec9681c387b5d97de656c720e.zip | |
Refactor duplicated code. NFC.
llvm-svn: 281329
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index bbe49432104..b7f71944a2a 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -216,6 +216,15 @@ template <class ELFT> void LinkerScript<ELFT>::createAssignments() { template <class ELFT> void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) { + auto AddSec = [&](InputSectionBase<ELFT> *Sec, StringRef Name) { + OutputSectionBase<ELFT> *OutSec; + bool IsNew; + std::tie(OutSec, IsNew) = Factory.create(Sec, Name); + if (IsNew) + OutputSections->push_back(OutSec); + return OutSec; + }; + for (const std::unique_ptr<BaseCommand> &Base1 : Opt.Commands) { if (auto *Cmd = dyn_cast<SymbolAssignment>(Base1.get())) { if (shouldDefine<ELFT>(Cmd)) @@ -235,12 +244,7 @@ void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) { continue; for (InputSectionBase<ELFT> *Sec : V) { - OutputSectionBase<ELFT> *OutSec; - bool IsNew; - std::tie(OutSec, IsNew) = Factory.create(Sec, Cmd->Name); - if (IsNew) - OutputSections->push_back(OutSec); - + OutputSectionBase<ELFT> *OutSec = AddSec(Sec, Cmd->Name); uint32_t Subalign = Cmd->SubalignExpr ? Cmd->SubalignExpr(0) : 0; if (Subalign) @@ -256,11 +260,7 @@ void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) { for (InputSectionBase<ELFT> *S : F->getSections()) { if (isDiscarded(S) || S->OutSec) continue; - OutputSectionBase<ELFT> *OutSec; - bool IsNew; - std::tie(OutSec, IsNew) = Factory.create(S, getOutputSectionName(S)); - if (IsNew) - OutputSections->push_back(OutSec); + OutputSectionBase<ELFT> *OutSec = AddSec(S, getOutputSectionName(S)); OutSec->addSection(S); } } |

