diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-12-18 22:40:27 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-12-18 22:40:27 +0000 |
commit | 3bca2f2bf524a858b83210a9b71c5b1e7e0020aa (patch) | |
tree | 1868c6f62b24e045ca2f4bbf6c6e769747d78800 /tools | |
parent | e9b93ea00be0f166c3e59d4f50f983bfc1d285ff (diff) |
Use a lambda to reduce code duplication.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256050 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-extract/llvm-extract.cpp | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/tools/llvm-extract/llvm-extract.cpp b/tools/llvm-extract/llvm-extract.cpp index 936496cd7fe..ca228da74d8 100644 --- a/tools/llvm-extract/llvm-extract.cpp +++ b/tools/llvm-extract/llvm-extract.cpp @@ -222,35 +222,27 @@ int main(int argc, char **argv) { } } - // Materialize requisite global values. - if (!DeleteFn) - for (size_t i = 0, e = GVs.size(); i != e; ++i) { - GlobalValue *GV = GVs[i]; - if (std::error_code EC = GV->materialize()) { - errs() << argv[0] << ": error reading input: " << EC.message() << "\n"; - return 1; - } + auto Materialize = [&](GlobalValue &GV) { + if (std::error_code EC = GV.materialize()) { + errs() << argv[0] << ": error reading input: " << EC.message() << "\n"; + exit(1); } - else { + }; + + // Materialize requisite global values. + if (!DeleteFn) { + for (size_t i = 0, e = GVs.size(); i != e; ++i) + Materialize(*GVs[i]); + } else { // Deleting. Materialize every GV that's *not* in GVs. SmallPtrSet<GlobalValue *, 8> GVSet(GVs.begin(), GVs.end()); for (auto &G : M->globals()) { - if (!GVSet.count(&G)) { - if (std::error_code EC = G.materialize()) { - errs() << argv[0] << ": error reading input: " << EC.message() - << "\n"; - return 1; - } - } + if (!GVSet.count(&G)) + Materialize(G); } for (auto &F : *M) { - if (!GVSet.count(&F)) { - if (std::error_code EC = F.materialize()) { - errs() << argv[0] << ": error reading input: " << EC.message() - << "\n"; - return 1; - } - } + if (!GVSet.count(&F)) + Materialize(F); } } |