[llvm-commits] [llvm] r96922 - in /llvm/trunk: lib/CompilerDriver/Tool.cpp utils/TableGen/LLVMCConfigurationEmitter.cpp
Mikhail Glushenkov
foldr at codedgers.com
Tue Feb 23 01:04:57 PST 2010
Author: foldr
Date: Tue Feb 23 03:04:57 2010
New Revision: 96922
URL: http://llvm.org/viewvc/llvm-project?rev=96922&view=rev
Log:
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.
Modified:
llvm/trunk/lib/CompilerDriver/Tool.cpp
llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
Modified: llvm/trunk/lib/CompilerDriver/Tool.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CompilerDriver/Tool.cpp?rev=96922&r1=96921&r2=96922&view=diff
==============================================================================
--- llvm/trunk/lib/CompilerDriver/Tool.cpp (original)
+++ llvm/trunk/lib/CompilerDriver/Tool.cpp Tue Feb 23 03:04:57 2010
@@ -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 @@
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;
}
Modified: llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp?rev=96922&r1=96921&r2=96922&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/LLVMCConfigurationEmitter.cpp Tue Feb 23 03:04:57 2010
@@ -1795,14 +1795,18 @@
switch (D.Type) {
case OptionType::Switch:
O.indent(IndentLevel)
- << "vec.push_back(std::make_pair(0, \"" << Name << "\"));\n";
+ << "vec.push_back(std::make_pair(" << D.GenVariableName()
+ << ".getPosition(), \"" << Name << "\"));\n";
break;
case OptionType::Parameter:
- O.indent(IndentLevel) << "vec.push_back(std::make_pair(0, \"" << Name;
+ O.indent(IndentLevel) << "vec.push_back(std::make_pair("
+ << D.GenVariableName()
+ <<".getPosition(), \"" << Name;
if (!D.isForwardNotSplit()) {
O << "\"));\n";
- O.indent(IndentLevel) << "vec.push_back(std::make_pair(0, "
+ O.indent(IndentLevel) << "vec.push_back(std::make_pair("
+ << D.GenVariableName() << ".getPosition(), "
<< D.GenVariableName() << "));\n";
}
else {
@@ -1810,7 +1814,8 @@
}
break;
case OptionType::Prefix:
- O.indent(IndentLevel) << "vec.push_back(std::make_pair(0, \""
+ O.indent(IndentLevel) << "vec.push_back(std::make_pair("
+ << D.GenVariableName() << ".getPosition(), \""
<< Name << "\" + "
<< D.GenVariableName() << "));\n";
break;
@@ -1820,12 +1825,15 @@
<< "::iterator B = " << D.GenVariableName() << ".begin(),\n";
O.indent(IndentLevel)
<< "E = " << D.GenVariableName() << ".end(); B != E;) {\n";
- O.indent(IndentLevel1) << "vec.push_back(std::make_pair(0, \""
+ O.indent(IndentLevel1) << "unsigned pos = " << D.GenVariableName()
+ << ".getPosition(B - " << D.GenVariableName()
+ << ".begin());\n";
+ O.indent(IndentLevel1) << "vec.push_back(std::make_pair(pos, \""
<< Name << "\" + " << "*B));\n";
O.indent(IndentLevel1) << "++B;\n";
for (int i = 1, j = D.MultiVal; i < j; ++i) {
- O.indent(IndentLevel1) << "vec.push_back(std::make_pair(0, *B));\n";
+ O.indent(IndentLevel1) << "vec.push_back(std::make_pair(pos, *B));\n";
O.indent(IndentLevel1) << "++B;\n";
}
@@ -1837,11 +1845,14 @@
<< D.GenVariableName() << ".begin(),\n";
O.indent(IndentLevel) << "E = " << D.GenVariableName()
<< ".end() ; B != E;) {\n";
- O.indent(IndentLevel1) << "vec.push_back(std::make_pair(0, \""
+ O.indent(IndentLevel1) << "unsigned pos = " << D.GenVariableName()
+ << ".getPosition(B - " << D.GenVariableName()
+ << ".begin());\n";
+ O.indent(IndentLevel1) << "vec.push_back(std::make_pair(pos, \""
<< Name << "\"));\n";
for (int i = 0, j = D.MultiVal; i < j; ++i) {
- O.indent(IndentLevel1) << "vec.push_back(std::make_pair(0, *B));\n";
+ O.indent(IndentLevel1) << "vec.push_back(std::make_pair(pos, *B));\n";
O.indent(IndentLevel1) << "++B;\n";
}
@@ -1923,7 +1934,7 @@
{
CheckNumberOfArguments(Dag, 1);
this->EmitHookInvocation(InitPtrToString(Dag.getArg(0)),
- "vec.push_back(std::make_pair(0, ", "));\n",
+ "vec.push_back(std::make_pair(65536, ", "));\n",
IndentLevel, O);
}
@@ -1954,7 +1965,8 @@
const OptionDescription& D = OptDescs.FindListOrParameter(Name);
if (D.isParameter()) {
- O.indent(IndentLevel) << "vec.push_back(std::make_pair(0, "
+ O.indent(IndentLevel) << "vec.push_back(std::make_pair("
+ << D.GenVariableName() << ".getPosition(), "
<< D.GenVariableName() << "));\n";
}
else {
@@ -1964,7 +1976,11 @@
<< ".end(); B != E; ++B)\n";
O.indent(IndentLevel) << "{\n";
O.indent(IndentLevel + Indent1)
- << "vec.push_back(std::make_pair(0, *B));\n";
+ << "unsigned pos = " << D.GenVariableName()
+ << ".getPosition(B - " << D.GenVariableName()
+ << ".begin());\n";
+ O.indent(IndentLevel + Indent1)
+ << "vec.push_back(std::make_pair(pos, *B));\n";
O.indent(IndentLevel) << "}\n";
}
}
@@ -1977,8 +1993,10 @@
const std::string& Hook = InitPtrToString(Dag.getArg(1));
const OptionDescription& D = OptDescs.FindListOrParameter(Name);
- O.indent(IndentLevel) << "vec.push_back(std::make_pair(0, " << "hooks::"
- << Hook << "(" << D.GenVariableName()
+ O.indent(IndentLevel) << "vec.push_back(std::make_pair("
+ << D.GenVariableName() << ".getPosition("
+ << (D.isList() ? "0" : "") << "), "
+ << "hooks::" << Hook << "(" << D.GenVariableName()
<< (D.isParameter() ? ".c_str()" : "") << ")));\n";
}
@@ -2092,8 +2110,9 @@
// Input file (s)
if (!D.InFileOption.empty()) {
- O.indent(Indent2) << "vec.push_back(std::make_pair(0, \""
- << D.InFileOption << "\");\n";
+ O.indent(Indent2)
+ << "vec.push_back(std::make_pair(InputFilenames.getPosition(0), \""
+ << D.InFileOption << "\");\n";
}
if (IsJoin) {
@@ -2101,23 +2120,26 @@
<< "for (PathVector::const_iterator B = inFiles.begin(),\n";
O.indent(Indent3) << "E = inFiles.end(); B != E; ++B)\n";
O.indent(Indent2) << "{\n";
- O.indent(Indent3) << "vec.push_back(std::make_pair(0, B->str()));\n";
+ O.indent(Indent3) << "vec.push_back(std::make_pair("
+ << "InputFilenames.getPosition(B - inFiles.begin()), "
+ << "B->str()));\n";
O.indent(Indent2) << "}\n";
}
else {
- O.indent(Indent2) << "vec.push_back(std::make_pair(0, inFile.str()));\n";
+ O.indent(Indent2) << "vec.push_back(std::make_pair("
+ << "InputFilenames.getPosition(0), inFile.str()));\n";
}
// Output file
O.indent(Indent2) << "if (!no_out_file) {\n";
if (!D.OutFileOption.empty())
- O.indent(Indent3) << "vec.push_back(std::make_pair(0, \""
+ O.indent(Indent3) << "vec.push_back(std::make_pair(65536, \""
<< D.OutFileOption << "\"));\n";
O.indent(Indent3) << "out_file = this->OutFilename("
<< (IsJoin ? "sys::Path(),\n" : "inFile,\n");
O.indent(Indent4) << "TempDir, stop_compilation, output_suffix).str();\n\n";
- O.indent(Indent3) << "vec.push_back(std::make_pair(0, out_file));\n";
+ O.indent(Indent3) << "vec.push_back(std::make_pair(65536, out_file));\n";
O.indent(Indent2) << "}\n\n";
@@ -2127,7 +2149,9 @@
O.indent(Indent3) << "for (cl::list<std::string>::iterator B = "
<< SinkOptionName << ".begin(), E = " << SinkOptionName
<< ".end(); B != E; ++B)\n";
- O.indent(Indent4) << "vec.push_back(std::make_pair(0, *B));\n";
+ O.indent(Indent4) << "vec.push_back(std::make_pair(" << SinkOptionName
+ << ".getPosition(B - " << SinkOptionName
+ << ".begin()), *B));\n";
O.indent(Indent2) << "}\n";
}
More information about the llvm-commits
mailing list