Refactoring: split the function CompilationGraph::Build() into two parts.

llvm-svn: 50760
This commit is contained in:
Mikhail Glushenkov 2008-05-06 18:15:35 +00:00
parent a02084cff7
commit de7fad129d
2 changed files with 22 additions and 10 deletions

View File

@ -245,12 +245,11 @@ FindToolChain(const sys::Path& In, const std::string* forceLanguage,
return &getNode(ChooseEdge(TV, InLangs)->ToolName()); return &getNode(ChooseEdge(TV, InLangs)->ToolName());
} }
// Build the targets. Command-line options are passed through // Helper function used by Build().
// temporary variables. // Traverses initial portions of the toolchains (up to the first Join node).
int CompilationGraph::Build (const sys::Path& TempDir) { // This function is also responsible for handling the -x option.
void CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
InputLanguagesSet InLangs; const sys::Path& TempDir) {
// This is related to -x option handling. // This is related to -x option handling.
cl::list<std::string>::const_iterator xIter = Languages.begin(), cl::list<std::string>::const_iterator xIter = Languages.begin(),
xBegin = xIter, xEnd = Languages.end(); xBegin = xIter, xEnd = Languages.end();
@ -303,6 +302,16 @@ int CompilationGraph::Build (const sys::Path& TempDir) {
// Pass file through the chain starting at head. // Pass file through the chain starting at head.
PassThroughGraph(In, N, InLangs, TempDir); PassThroughGraph(In, N, InLangs, TempDir);
} }
}
// Build the targets. Command-line options are passed through
// temporary variables.
int CompilationGraph::Build (const sys::Path& TempDir) {
InputLanguagesSet InLangs;
// Traverse initial parts of the toolchains and fill in InLangs.
BuildInitial(InLangs, TempDir);
std::vector<const Node*> JTV; std::vector<const Node*> JTV;
TopologicalSortFilterJoinNodes(JTV); TopologicalSortFilterJoinNodes(JTV);

View File

@ -20,17 +20,16 @@
#include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/GraphTraits.h"
#include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/ADT/IntrusiveRefCntPtr.h"
#include "llvm/ADT/iterator" #include "llvm/ADT/iterator"
//#include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringMap.h"
#include "llvm/System/Path.h" #include "llvm/System/Path.h"
#include <set>
#include <string> #include <string>
namespace llvmc { namespace llvmc {
typedef std::set<std::string> InputLanguagesSet; typedef llvm::SmallSet<std::string, 5> InputLanguagesSet;
// An edge of the compilation graph. // An edge of the compilation graph.
class Edge : public llvm::RefCountedBaseVPTR<Edge> { class Edge : public llvm::RefCountedBaseVPTR<Edge> {
@ -162,7 +161,7 @@ namespace llvmc {
// 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. // Pass the input file through the toolchain starting at StartNode.
void PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode, void PassThroughGraph (const llvm::sys::Path& In, const Node* StartNode,
const InputLanguagesSet& InLangs, const InputLanguagesSet& InLangs,
const llvm::sys::Path& TempDir) const; const llvm::sys::Path& TempDir) const;
@ -172,6 +171,10 @@ namespace llvmc {
const std::string* forceLanguage, const std::string* forceLanguage,
InputLanguagesSet& InLangs) const; InputLanguagesSet& InLangs) const;
// Traverse the initial parts of the toolchains.
void BuildInitial(InputLanguagesSet& InLangs,
const llvm::sys::Path& TempDir);
// Sort the nodes in topological order. // Sort the nodes in topological order.
void TopologicalSort(std::vector<const Node*>& Out); void TopologicalSort(std::vector<const Node*>& Out);
// Call TopologicalSort and filter the resulting list to include // Call TopologicalSort and filter the resulting list to include