diff options
author | Mikhail Glushenkov <foldr@codedgers.com> | 2010-02-23 09:04:57 +0000 |
---|---|---|
committer | Mikhail Glushenkov <foldr@codedgers.com> | 2010-02-23 09:04:57 +0000 |
commit | 1afba8e474c54939bc6ab92ed57776fd059529a0 (patch) | |
tree | c2871a835c4b83f2c5c844a8301be19c682f4468 /lib/CompilerDriver/Tool.cpp | |
parent | 7cebe55bade5c784fb9e2c574cc797fcd6cf1082 (diff) |
Implement order-preserving option forwarding.
Needed to correctly handle things like 'llvmc -framework Foo foo.o -framework
Bar bar.o' - before this commit all '-framework' options would've been grouped
together in the beginning.
Due to our dependence on CommandLine this turned out to be a giant hack; we will
migrate away from CommandLine eventually.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96922 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CompilerDriver/Tool.cpp')
-rw-r--r-- | lib/CompilerDriver/Tool.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/CompilerDriver/Tool.cpp b/lib/CompilerDriver/Tool.cpp index 7be24147ce..5e558ca43c 100644 --- a/lib/CompilerDriver/Tool.cpp +++ b/lib/CompilerDriver/Tool.cpp @@ -17,6 +17,8 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/System/Path.h" +#include <algorithm> + using namespace llvm; using namespace llvmc; @@ -72,11 +74,21 @@ sys::Path Tool::OutFilename(const sys::Path& In, return Out; } +namespace { + template <class A, class B> + bool CompareFirst (std::pair<A,B> p1, std::pair<A,B> p2) { + return std::less<A>()(p1.first, p2.first); + } +} + StrVector Tool::SortArgs(ArgsVector& Args) const { StrVector Out; - for (ArgsVector::iterator B = Args.begin(), E = Args.end(); B != E; ++B) + // HACK: this won't be needed when we'll migrate away from CommandLine. + std::stable_sort(Args.begin(), Args.end(), &CompareFirst<unsigned, std::string>); + for (ArgsVector::iterator B = Args.begin(), E = Args.end(); B != E; ++B) { Out.push_back(B->second); + } return Out; } |