Split the Build function into two parts.

llvm-svn: 50736
This commit is contained in:
Mikhail Glushenkov 2008-05-06 17:25:51 +00:00
parent af15882a5a
commit be23113e93
2 changed files with 65 additions and 43 deletions

View File

@ -109,17 +109,14 @@ void CompilationGraph::insertEdge(const std::string& A, Edge* E) {
} }
} }
// TOFIX: support more interesting graph topologies. We will need to // Pass input file through the chain until we bump into a Join node or
// do topological sorting to process multiple Join nodes correctly. // a node that says that it is the last.
int CompilationGraph::Build (const sys::Path& tempDir) const { const Tool* CompilationGraph::PassThroughGraph (sys::Path& In,
PathVector JoinList; sys::Path Out,
const Tool* JoinTool = 0; const sys::Path& TempDir,
sys::Path In, Out; PathVector& JoinList) const {
bool Last = false;
// For each input file const Tool* ret = 0;
for (cl::list<std::string>::const_iterator B = InputFilenames.begin(),
E = InputFilenames.end(); B != E; ++B) {
In = sys::Path(*B);
// Get to the head of the toolchain. // Get to the head of the toolchain.
const tools_vector_type& TV = getToolsVector(getLanguage(In)); const tools_vector_type& TV = getToolsVector(getLanguage(In));
@ -127,15 +124,12 @@ int CompilationGraph::Build (const sys::Path& tempDir) const {
throw std::runtime_error("Tool names vector is empty!"); throw std::runtime_error("Tool names vector is empty!");
const Node* N = &getNode(*TV.begin()); const Node* N = &getNode(*TV.begin());
// Pass file through the chain until we bump into a Join node or a
// node that says that it is the last.
bool Last = false;
while(!Last) { while(!Last) {
const Tool* CurTool = N->ToolPtr.getPtr(); const Tool* CurTool = N->ToolPtr.getPtr();
if (CurTool->IsJoin()) { if (CurTool->IsJoin()) {
JoinList.push_back(In); JoinList.push_back(In);
JoinTool = CurTool; ret = CurTool;
break; break;
} }
@ -150,7 +144,7 @@ int CompilationGraph::Build (const sys::Path& tempDir) const {
Last = true; Last = true;
} }
else { else {
Out = tempDir; Out = TempDir;
Out.appendComponent(In.getBasename()); Out.appendComponent(In.getBasename());
Out.appendSuffix(CurTool->OutputSuffix()); Out.appendSuffix(CurTool->OutputSuffix());
Out.makeUnique(true, NULL); Out.makeUnique(true, NULL);
@ -163,6 +157,28 @@ int CompilationGraph::Build (const sys::Path& tempDir) const {
N = &getNode(N->ChooseEdge()->ToolName()); N = &getNode(N->ChooseEdge()->ToolName());
In = Out; Out.clear(); In = Out; Out.clear();
} }
return ret;
}
// TOFIX: support more interesting graph topologies. We will need to
// do topological sorting to process multiple Join nodes correctly.
int CompilationGraph::Build (const sys::Path& TempDir) const {
PathVector JoinList;
const Tool* JoinTool = 0;
sys::Path In, Out;
// For each input file
for (cl::list<std::string>::const_iterator B = InputFilenames.begin(),
E = InputFilenames.end(); B != E; ++B) {
In = sys::Path(*B);
const Tool* NewJoin = PassThroughGraph(In, Out, TempDir, JoinList);
if (JoinTool && NewJoin && JoinTool != NewJoin)
throw std::runtime_error("Graphs with multiple Join nodes"
"are not yet supported!");
else if (NewJoin)
JoinTool = NewJoin;
} }
if (JoinTool) { if (JoinTool) {

View File

@ -141,6 +141,12 @@ namespace llvmcc {
// Return a reference to the list of tool names corresponding to // Return a reference to the list of tool names corresponding to
// the given language name. Throws std::runtime_error. // the given language name. Throws std::runtime_error.
const tools_vector_type& getToolsVector(const std::string& LangName) const; const tools_vector_type& getToolsVector(const std::string& LangName) const;
// Pass the input file through the toolchain.
const Tool* PassThroughGraph (llvm::sys::Path& In, llvm::sys::Path Out,
const llvm::sys::Path& TempDir,
PathVector& JoinList) const;
}; };
/// GraphTraits support code. /// GraphTraits support code.