Some cosmetic changes (change some comments, move code around a bit).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50762 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mikhail Glushenkov 2008-05-06 18:16:52 +00:00
parent 2e9e0c2951
commit be86712de8
2 changed files with 44 additions and 43 deletions

View File

@ -20,7 +20,6 @@
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#include <iostream>
#include <limits> #include <limits>
#include <queue> #include <queue>
#include <stdexcept> #include <stdexcept>
@ -88,6 +87,7 @@ const Node& CompilationGraph::getNode(const std::string& ToolName) const {
return I->second; return I->second;
} }
// Find the language name corresponding to the given file.
const std::string& CompilationGraph::getLanguage(const sys::Path& File) const { const std::string& CompilationGraph::getLanguage(const sys::Path& File) const {
LanguageMap::const_iterator Lang = ExtsToLangs.find(File.getSuffix()); LanguageMap::const_iterator Lang = ExtsToLangs.find(File.getSuffix());
if (Lang == ExtsToLangs.end()) if (Lang == ExtsToLangs.end())
@ -95,6 +95,7 @@ const std::string& CompilationGraph::getLanguage(const sys::Path& File) const {
return Lang->second; return Lang->second;
} }
// Find the tools list corresponding to the given language name.
const CompilationGraph::tools_vector_type& const CompilationGraph::tools_vector_type&
CompilationGraph::getToolsVector(const std::string& LangName) const CompilationGraph::getToolsVector(const std::string& LangName) const
{ {
@ -189,42 +190,7 @@ void CompilationGraph::PassThroughGraph (const sys::Path& InFile,
} }
} }
// Sort the nodes in topological order. // Find the head of the toolchain corresponding to the given file.
void CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) {
std::queue<const Node*> Q;
Q.push(&getNode("root"));
while (!Q.empty()) {
const Node* A = Q.front();
Q.pop();
Out.push_back(A);
for (Node::const_iterator EB = A->EdgesBegin(), EE = A->EdgesEnd();
EB != EE; ++EB) {
Node* B = &getNode((*EB)->ToolName());
B->DecrInEdges();
if (B->HasNoInEdges())
Q.push(B);
}
}
}
namespace {
bool NotJoinNode(const Node* N) {
return N->ToolPtr ? !N->ToolPtr->IsJoin() : true;
}
}
// Call TopologicalSort and filter the resulting list to include
// only Join nodes.
void CompilationGraph::
TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out) {
std::vector<const Node*> TopSorted;
TopologicalSort(TopSorted);
std::remove_copy_if(TopSorted.begin(), TopSorted.end(),
std::back_inserter(Out), NotJoinNode);
}
// Find head of the toolchain corresponding to the given file.
// Also, insert an input language into InLangs. // Also, insert an input language into InLangs.
const Node* CompilationGraph:: const Node* CompilationGraph::
FindToolChain(const sys::Path& In, const std::string* forceLanguage, FindToolChain(const sys::Path& In, const std::string* forceLanguage,
@ -304,8 +270,43 @@ void CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
} }
} }
// Build the targets. Command-line options are passed through // Sort the nodes in topological order.
// temporary variables. void CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) {
std::queue<const Node*> Q;
Q.push(&getNode("root"));
while (!Q.empty()) {
const Node* A = Q.front();
Q.pop();
Out.push_back(A);
for (Node::const_iterator EB = A->EdgesBegin(), EE = A->EdgesEnd();
EB != EE; ++EB) {
Node* B = &getNode((*EB)->ToolName());
B->DecrInEdges();
if (B->HasNoInEdges())
Q.push(B);
}
}
}
namespace {
bool NotJoinNode(const Node* N) {
return N->ToolPtr ? !N->ToolPtr->IsJoin() : true;
}
}
// Call TopologicalSort and filter the resulting list to include
// only Join nodes.
void CompilationGraph::
TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out) {
std::vector<const Node*> TopSorted;
TopologicalSort(TopSorted);
std::remove_copy_if(TopSorted.begin(), TopSorted.end(),
std::back_inserter(Out), NotJoinNode);
}
// Build the targets. Command-line options are accessed through global
// variables.
int CompilationGraph::Build (const sys::Path& TempDir) { int CompilationGraph::Build (const sys::Path& TempDir) {
InputLanguagesSet InLangs; InputLanguagesSet InLangs;
@ -325,12 +326,12 @@ int CompilationGraph::Build (const sys::Path& TempDir) {
JoinTool* JT = &dynamic_cast<JoinTool&>(*CurNode->ToolPtr.getPtr()); JoinTool* JT = &dynamic_cast<JoinTool&>(*CurNode->ToolPtr.getPtr());
bool IsLast = false; bool IsLast = false;
// Are there any files to be joined? // Are there any files in the join list?
if (JT->JoinListEmpty()) if (JT->JoinListEmpty())
continue; continue;
// Is this the last tool in the chain? // Is this the last tool in the toolchain?
// NOTE: we can process several chains in parallel. // NOTE: we can process several toolchains in parallel.
if (!CurNode->HasChildren() || JT->IsLast()) { if (!CurNode->HasChildren() || JT->IsLast()) {
if (OutputFilename.empty()) { if (OutputFilename.empty()) {
Out.set("a"); Out.set("a");

View File

@ -2,7 +2,7 @@ Introduction
============ ============
Disclaimer: this document is currently somewhat out-of-date and is Disclaimer: this document is currently somewhat out-of-date and is
retained for reference; for documentation, refer to retained for reference; for more recent documentation please refer to
LLVMC-Tutorial.rst. LLVMC-Tutorial.rst.
A complete rewrite of the LLVMC compiler driver is proposed, aimed at A complete rewrite of the LLVMC compiler driver is proposed, aimed at