summaryrefslogtreecommitdiff
path: root/tools/llvmc2
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2008-05-06 17:25:51 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2008-05-06 17:25:51 +0000
commit2ba4c5ababa878b05a7de1e97a98df50d8bcf6c4 (patch)
treef8e0a507dcc3fd97b723d530a99cab70bb3edb7e /tools/llvmc2
parentd81887841cef9c1fe40451c3f16cb53525b2ee2e (diff)
downloadllvm-2ba4c5ababa878b05a7de1e97a98df50d8bcf6c4.tar.gz
llvm-2ba4c5ababa878b05a7de1e97a98df50d8bcf6c4.tar.bz2
llvm-2ba4c5ababa878b05a7de1e97a98df50d8bcf6c4.tar.xz
Split the Build function into two parts.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50736 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvmc2')
-rw-r--r--tools/llvmc2/CompilationGraph.cpp102
-rw-r--r--tools/llvmc2/CompilationGraph.h6
2 files changed, 65 insertions, 43 deletions
diff --git a/tools/llvmc2/CompilationGraph.cpp b/tools/llvmc2/CompilationGraph.cpp
index f6cbe08754..53195cbe95 100644
--- a/tools/llvmc2/CompilationGraph.cpp
+++ b/tools/llvmc2/CompilationGraph.cpp
@@ -109,9 +109,61 @@ void CompilationGraph::insertEdge(const std::string& A, Edge* E) {
}
}
+// Pass input file through the chain until we bump into a Join node or
+// a node that says that it is the last.
+const Tool* CompilationGraph::PassThroughGraph (sys::Path& In,
+ sys::Path Out,
+ const sys::Path& TempDir,
+ PathVector& JoinList) const {
+ bool Last = false;
+ const Tool* ret = 0;
+
+ // Get to the head of the toolchain.
+ const tools_vector_type& TV = getToolsVector(getLanguage(In));
+ if (TV.empty())
+ throw std::runtime_error("Tool names vector is empty!");
+ const Node* N = &getNode(*TV.begin());
+
+ while(!Last) {
+ const Tool* CurTool = N->ToolPtr.getPtr();
+
+ if (CurTool->IsJoin()) {
+ JoinList.push_back(In);
+ ret = CurTool;
+ break;
+ }
+
+ // Is this the last tool?
+ if (!N->HasChildren() || CurTool->IsLast()) {
+ // Check if the first tool is also the last
+ if (Out.empty())
+ Out.set(In.getBasename());
+ else
+ Out.appendComponent(In.getBasename());
+ Out.appendSuffix(CurTool->OutputSuffix());
+ Last = true;
+ }
+ else {
+ Out = TempDir;
+ Out.appendComponent(In.getBasename());
+ Out.appendSuffix(CurTool->OutputSuffix());
+ Out.makeUnique(true, NULL);
+ Out.eraseFromDisk();
+ }
+
+ if (CurTool->GenerateAction(In, Out).Execute() != 0)
+ throw std::runtime_error("Tool returned error code!");
+
+ N = &getNode(N->ChooseEdge()->ToolName());
+ 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 {
+int CompilationGraph::Build (const sys::Path& TempDir) const {
PathVector JoinList;
const Tool* JoinTool = 0;
sys::Path In, Out;
@@ -121,48 +173,12 @@ int CompilationGraph::Build (const sys::Path& tempDir) const {
E = InputFilenames.end(); B != E; ++B) {
In = sys::Path(*B);
- // Get to the head of the toolchain.
- const tools_vector_type& TV = getToolsVector(getLanguage(In));
- if (TV.empty())
- throw std::runtime_error("Tool names vector is empty!");
- 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) {
- const Tool* CurTool = N->ToolPtr.getPtr();
-
- if (CurTool->IsJoin()) {
- JoinList.push_back(In);
- JoinTool = CurTool;
- break;
- }
-
- // Is this the last tool?
- if (!N->HasChildren() || CurTool->IsLast()) {
- // Check if the first tool is also the last
- if (Out.empty())
- Out.set(In.getBasename());
- else
- Out.appendComponent(In.getBasename());
- Out.appendSuffix(CurTool->OutputSuffix());
- Last = true;
- }
- else {
- Out = tempDir;
- Out.appendComponent(In.getBasename());
- Out.appendSuffix(CurTool->OutputSuffix());
- Out.makeUnique(true, NULL);
- Out.eraseFromDisk();
- }
-
- if (CurTool->GenerateAction(In, Out).Execute() != 0)
- throw std::runtime_error("Tool returned error code!");
-
- N = &getNode(N->ChooseEdge()->ToolName());
- In = Out; Out.clear();
- }
+ 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) {
diff --git a/tools/llvmc2/CompilationGraph.h b/tools/llvmc2/CompilationGraph.h
index 18c1e6b3b5..bddd8bdf3a 100644
--- a/tools/llvmc2/CompilationGraph.h
+++ b/tools/llvmc2/CompilationGraph.h
@@ -141,6 +141,12 @@ namespace llvmcc {
// Return a reference to the list of tool names corresponding to
// the given language name. Throws std::runtime_error.
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.