Mikhail Glushenkov | b90cd83 | 2008-05-06 16:34:12 +0000 | [diff] [blame] | 1 | //===--- CompilationGraph.cpp - The LLVM Compiler Driver --------*- C++ -*-===// |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open |
| 6 | // Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Mikhail Glushenkov | b90cd83 | 2008-05-06 16:34:12 +0000 | [diff] [blame] | 10 | // Compilation graph - implementation. |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Mikhail Glushenkov | b90cd83 | 2008-05-06 16:34:12 +0000 | [diff] [blame] | 14 | #include "CompilationGraph.h" |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 15 | |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 16 | #include "llvm/Support/CommandLine.h" |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 17 | #include "llvm/Support/DOTGraphTraits.h" |
| 18 | #include "llvm/Support/GraphWriter.h" |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 19 | |
Mikhail Glushenkov | 0260658 | 2008-05-06 18:07:14 +0000 | [diff] [blame] | 20 | #include <algorithm> |
| 21 | #include <iostream> |
| 22 | #include <iterator> |
| 23 | #include <queue> |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 24 | #include <stdexcept> |
| 25 | |
| 26 | using namespace llvm; |
Mikhail Glushenkov | be9d9a1 | 2008-05-06 18:08:59 +0000 | [diff] [blame] | 27 | using namespace llvmc; |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 28 | |
| 29 | extern cl::list<std::string> InputFilenames; |
| 30 | extern cl::opt<std::string> OutputFilename; |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 31 | |
Mikhail Glushenkov | 4f6e3a4 | 2008-05-06 17:28:03 +0000 | [diff] [blame] | 32 | namespace { |
| 33 | |
| 34 | // Choose edge that returns |
| 35 | template <class C> |
| 36 | const Edge* ChooseEdge(const C& EdgesContainer, |
| 37 | const std::string& NodeName = "root") { |
| 38 | const Edge* DefaultEdge = 0; |
| 39 | |
| 40 | for (typename C::const_iterator B = EdgesContainer.begin(), |
| 41 | E = EdgesContainer.end(); B != E; ++B) { |
| 42 | const Edge* E = B->getPtr(); |
| 43 | |
| 44 | if (E->isDefault()) |
| 45 | if (!DefaultEdge) |
| 46 | DefaultEdge = E; |
| 47 | else |
| 48 | throw std::runtime_error("Node " + NodeName |
| 49 | + ": multiple default outward edges found!" |
| 50 | "Most probably a specification error."); |
| 51 | if (E->isEnabled()) |
| 52 | return E; |
| 53 | } |
| 54 | |
| 55 | if (DefaultEdge) |
| 56 | return DefaultEdge; |
| 57 | else |
| 58 | throw std::runtime_error("Node " + NodeName |
| 59 | + ": no default outward edge found!" |
| 60 | "Most probably a specification error."); |
Mikhail Glushenkov | 6591c89 | 2008-05-06 17:23:50 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Mikhail Glushenkov | 6591c89 | 2008-05-06 17:23:50 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 65 | CompilationGraph::CompilationGraph() { |
| 66 | NodesMap["root"] = Node(this); |
| 67 | } |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 68 | |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 69 | Node& CompilationGraph::getNode(const std::string& ToolName) { |
| 70 | nodes_map_type::iterator I = NodesMap.find(ToolName); |
| 71 | if (I == NodesMap.end()) |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 72 | throw std::runtime_error("Node " + ToolName + " is not in the graph"); |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 73 | return I->second; |
| 74 | } |
| 75 | |
| 76 | const Node& CompilationGraph::getNode(const std::string& ToolName) const { |
| 77 | nodes_map_type::const_iterator I = NodesMap.find(ToolName); |
| 78 | if (I == NodesMap.end()) |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 79 | throw std::runtime_error("Node " + ToolName + " is not in the graph!"); |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 80 | return I->second; |
| 81 | } |
| 82 | |
| 83 | const std::string& CompilationGraph::getLanguage(const sys::Path& File) const { |
| 84 | LanguageMap::const_iterator Lang = ExtsToLangs.find(File.getSuffix()); |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 85 | if (Lang == ExtsToLangs.end()) |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 86 | throw std::runtime_error("Unknown suffix: " + File.getSuffix() + '!'); |
| 87 | return Lang->second; |
| 88 | } |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 89 | |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 90 | const CompilationGraph::tools_vector_type& |
| 91 | CompilationGraph::getToolsVector(const std::string& LangName) const |
| 92 | { |
| 93 | tools_map_type::const_iterator I = ToolsMap.find(LangName); |
| 94 | if (I == ToolsMap.end()) |
| 95 | throw std::runtime_error("No tools corresponding to " + LangName |
| 96 | + " found!"); |
| 97 | return I->second; |
| 98 | } |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 99 | |
Mikhail Glushenkov | 0a17493 | 2008-05-06 16:36:06 +0000 | [diff] [blame] | 100 | void CompilationGraph::insertNode(Tool* V) { |
Mikhail Glushenkov | c74bfc9 | 2008-05-06 17:26:53 +0000 | [diff] [blame] | 101 | if (NodesMap.count(V->Name()) == 0) { |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 102 | Node N; |
| 103 | N.OwningGraph = this; |
| 104 | N.ToolPtr = V; |
| 105 | NodesMap[V->Name()] = N; |
| 106 | } |
| 107 | } |
| 108 | |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 109 | void CompilationGraph::insertEdge(const std::string& A, Edge* E) { |
Mikhail Glushenkov | c74bfc9 | 2008-05-06 17:26:53 +0000 | [diff] [blame] | 110 | Node& B = getNode(E->ToolName()); |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 111 | if (A == "root") { |
Mikhail Glushenkov | c74bfc9 | 2008-05-06 17:26:53 +0000 | [diff] [blame] | 112 | const std::string& InputLanguage = B.ToolPtr->InputLanguage(); |
Mikhail Glushenkov | 4f6e3a4 | 2008-05-06 17:28:03 +0000 | [diff] [blame] | 113 | ToolsMap[InputLanguage].push_back(IntrusiveRefCntPtr<Edge>(E)); |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 114 | NodesMap["root"].AddEdge(E); |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 115 | } |
| 116 | else { |
Mikhail Glushenkov | 0a17493 | 2008-05-06 16:36:06 +0000 | [diff] [blame] | 117 | Node& N = getNode(A); |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 118 | N.AddEdge(E); |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 119 | } |
Mikhail Glushenkov | c74bfc9 | 2008-05-06 17:26:53 +0000 | [diff] [blame] | 120 | // Increase the inward edge counter. |
| 121 | B.IncrInEdges(); |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 124 | // Make a temporary file named like BaseName-RandomDigits.Suffix |
| 125 | sys::Path MakeTempFile(const sys::Path& TempDir, const std::string& BaseName, |
| 126 | const std::string& Suffix) { |
| 127 | sys::Path Out = TempDir; |
| 128 | Out.appendComponent(BaseName); |
| 129 | Out.appendSuffix(Suffix); |
| 130 | Out.makeUnique(true, NULL); |
| 131 | Out.eraseFromDisk(); |
| 132 | return Out; |
| 133 | } |
| 134 | |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 135 | // Pass input file through the chain until we bump into a Join node or |
| 136 | // a node that says that it is the last. |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 137 | void CompilationGraph::PassThroughGraph (const sys::Path& InFile, |
| 138 | const Node* StartNode, |
| 139 | const sys::Path& TempDir) const { |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 140 | bool Last = false; |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 141 | sys::Path In = InFile; |
Mikhail Glushenkov | 4f6e3a4 | 2008-05-06 17:28:03 +0000 | [diff] [blame] | 142 | const Node* CurNode = StartNode; |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 143 | |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 144 | while(!Last) { |
Mikhail Glushenkov | bbbc9d4 | 2008-05-06 17:27:37 +0000 | [diff] [blame] | 145 | sys::Path Out; |
Mikhail Glushenkov | 4f6e3a4 | 2008-05-06 17:28:03 +0000 | [diff] [blame] | 146 | Tool* CurTool = CurNode->ToolPtr.getPtr(); |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 147 | |
| 148 | if (CurTool->IsJoin()) { |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 149 | JoinTool& JT = dynamic_cast<JoinTool&>(*CurTool); |
| 150 | JT.AddToJoinList(In); |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 151 | break; |
| 152 | } |
| 153 | |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 154 | // Since toolchains do not have to end with a Join node, we should |
| 155 | // check if this Node is the last. |
Mikhail Glushenkov | 4f6e3a4 | 2008-05-06 17:28:03 +0000 | [diff] [blame] | 156 | if (!CurNode->HasChildren() || CurTool->IsLast()) { |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 157 | if (!OutputFilename.empty()) { |
| 158 | Out.set(OutputFilename); |
| 159 | } |
| 160 | else { |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 161 | Out.set(In.getBasename()); |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 162 | Out.appendSuffix(CurTool->OutputSuffix()); |
| 163 | } |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 164 | Last = true; |
| 165 | } |
| 166 | else { |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 167 | Out = MakeTempFile(TempDir, In.getBasename(), CurTool->OutputSuffix()); |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | if (CurTool->GenerateAction(In, Out).Execute() != 0) |
| 171 | throw std::runtime_error("Tool returned error code!"); |
| 172 | |
Mikhail Glushenkov | 4f6e3a4 | 2008-05-06 17:28:03 +0000 | [diff] [blame] | 173 | CurNode = &getNode(ChooseEdge(CurNode->OutEdges, |
| 174 | CurNode->Name())->ToolName()); |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 175 | In = Out; Out.clear(); |
| 176 | } |
Mikhail Glushenkov | 2ba4c5a | 2008-05-06 17:25:51 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Mikhail Glushenkov | 0260658 | 2008-05-06 18:07:14 +0000 | [diff] [blame] | 179 | // Sort the nodes in topological order. |
| 180 | void CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) { |
| 181 | std::queue<const Node*> Q; |
| 182 | Q.push(&getNode("root")); |
| 183 | |
| 184 | while (!Q.empty()) { |
| 185 | const Node* A = Q.front(); |
| 186 | Q.pop(); |
| 187 | Out.push_back(A); |
| 188 | for (Node::const_iterator EB = A->EdgesBegin(), EE = A->EdgesEnd(); |
| 189 | EB != EE; ++EB) { |
| 190 | Node* B = &getNode((*EB)->ToolName()); |
| 191 | B->DecrInEdges(); |
| 192 | if (B->HasNoInEdges()) |
| 193 | Q.push(B); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | namespace { |
| 199 | bool NotJoinNode(const Node* N) { |
| 200 | return N->ToolPtr ? !N->ToolPtr->IsJoin() : true; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | // Call TopologicalSort and filter the resulting list to include |
| 205 | // only Join nodes. |
| 206 | void CompilationGraph:: |
| 207 | TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out) { |
| 208 | std::vector<const Node*> TopSorted; |
| 209 | TopologicalSort(TopSorted); |
| 210 | std::remove_copy_if(TopSorted.begin(), TopSorted.end(), |
| 211 | std::back_inserter(Out), NotJoinNode); |
| 212 | } |
| 213 | |
| 214 | // Find head of the toolchain corresponding to the given file. |
| 215 | const Node* CompilationGraph::FindToolChain(const sys::Path& In) const { |
| 216 | const std::string& InLanguage = getLanguage(In); |
| 217 | const tools_vector_type& TV = getToolsVector(InLanguage); |
| 218 | if (TV.empty()) |
| 219 | throw std::runtime_error("No toolchain corresponding to language" |
| 220 | + InLanguage + " found!"); |
| 221 | return &getNode(ChooseEdge(TV)->ToolName()); |
| 222 | } |
| 223 | |
Mikhail Glushenkov | be9d9a1 | 2008-05-06 18:08:59 +0000 | [diff] [blame] | 224 | // Build the targets. Command-line options are passed through |
| 225 | // temporary variables. |
Mikhail Glushenkov | 0260658 | 2008-05-06 18:07:14 +0000 | [diff] [blame] | 226 | int CompilationGraph::Build (const sys::Path& TempDir) { |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 227 | |
Mikhail Glushenkov | 4f6e3a4 | 2008-05-06 17:28:03 +0000 | [diff] [blame] | 228 | // For each input file: |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 229 | for (cl::list<std::string>::const_iterator B = InputFilenames.begin(), |
| 230 | E = InputFilenames.end(); B != E; ++B) { |
Mikhail Glushenkov | bbbc9d4 | 2008-05-06 17:27:37 +0000 | [diff] [blame] | 231 | sys::Path In = sys::Path(*B); |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 232 | |
Mikhail Glushenkov | 0260658 | 2008-05-06 18:07:14 +0000 | [diff] [blame] | 233 | // Find the toolchain corresponding to this file. |
| 234 | const Node* N = FindToolChain(In); |
| 235 | // Pass file through the chain starting at head. |
| 236 | PassThroughGraph(In, N, TempDir); |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Mikhail Glushenkov | 0260658 | 2008-05-06 18:07:14 +0000 | [diff] [blame] | 239 | std::vector<const Node*> JTV; |
| 240 | TopologicalSortFilterJoinNodes(JTV); |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 241 | |
Mikhail Glushenkov | 0260658 | 2008-05-06 18:07:14 +0000 | [diff] [blame] | 242 | // For all join nodes in topological order: |
| 243 | for (std::vector<const Node*>::iterator B = JTV.begin(), E = JTV.end(); |
| 244 | B != E; ++B) { |
Mikhail Glushenkov | be9d9a1 | 2008-05-06 18:08:59 +0000 | [diff] [blame] | 245 | |
Mikhail Glushenkov | 3d68822 | 2008-05-06 18:07:48 +0000 | [diff] [blame] | 246 | sys::Path Out; |
| 247 | const Node* CurNode = *B; |
| 248 | JoinTool* JT = &dynamic_cast<JoinTool&>(*CurNode->ToolPtr.getPtr()); |
| 249 | bool IsLast = false; |
| 250 | |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 251 | // Are there any files to be joined? |
Mikhail Glushenkov | 3d68822 | 2008-05-06 18:07:48 +0000 | [diff] [blame] | 252 | if (JT->JoinListEmpty()) |
| 253 | continue; |
| 254 | |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 255 | // Is this the last tool in the chain? |
| 256 | // NOTE: we can process several chains in parallel. |
Mikhail Glushenkov | 3d68822 | 2008-05-06 18:07:48 +0000 | [diff] [blame] | 257 | if (!CurNode->HasChildren() || JT->IsLast()) { |
| 258 | if (OutputFilename.empty()) { |
| 259 | Out.set("a"); |
| 260 | Out.appendSuffix(JT->OutputSuffix()); |
| 261 | } |
| 262 | else |
| 263 | Out.set(OutputFilename); |
| 264 | IsLast = true; |
| 265 | } |
| 266 | else { |
Mikhail Glushenkov | 35a85e8 | 2008-05-06 18:10:20 +0000 | [diff] [blame^] | 267 | Out = MakeTempFile(TempDir, "tmp", JT->OutputSuffix()); |
Mikhail Glushenkov | 3d68822 | 2008-05-06 18:07:48 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | if (JT->GenerateAction(Out).Execute() != 0) |
| 271 | throw std::runtime_error("Tool returned error code!"); |
| 272 | |
| 273 | if (!IsLast) { |
| 274 | const Node* NextNode = &getNode(ChooseEdge(CurNode->OutEdges, |
| 275 | CurNode->Name())->ToolName()); |
| 276 | PassThroughGraph(Out, NextNode, TempDir); |
| 277 | } |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 278 | } |
Anton Korobeynikov | ac67b7e | 2008-03-23 08:57:20 +0000 | [diff] [blame] | 279 | |
| 280 | return 0; |
| 281 | } |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 282 | |
Mikhail Glushenkov | bbbc9d4 | 2008-05-06 17:27:37 +0000 | [diff] [blame] | 283 | // Code related to graph visualization. |
| 284 | |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 285 | namespace llvm { |
| 286 | template <> |
Mikhail Glushenkov | be9d9a1 | 2008-05-06 18:08:59 +0000 | [diff] [blame] | 287 | struct DOTGraphTraits<llvmc::CompilationGraph*> |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 288 | : public DefaultDOTGraphTraits |
| 289 | { |
| 290 | |
Mikhail Glushenkov | 97fda6d | 2008-05-06 17:26:14 +0000 | [diff] [blame] | 291 | template<typename GraphType> |
| 292 | static std::string getNodeLabel(const Node* N, const GraphType&) |
| 293 | { |
| 294 | if (N->ToolPtr) |
| 295 | if (N->ToolPtr->IsJoin()) |
| 296 | return N->Name() + "\n (join" + |
| 297 | (N->HasChildren() ? ")" |
| 298 | : std::string(": ") + N->ToolPtr->OutputLanguage() + ')'); |
| 299 | else |
| 300 | return N->Name(); |
| 301 | else |
| 302 | return "root"; |
| 303 | } |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 304 | |
Mikhail Glushenkov | 97fda6d | 2008-05-06 17:26:14 +0000 | [diff] [blame] | 305 | template<typename EdgeIter> |
| 306 | static std::string getEdgeSourceLabel(const Node* N, EdgeIter I) { |
| 307 | if (N->ToolPtr) |
| 308 | return N->ToolPtr->OutputLanguage(); |
| 309 | else |
| 310 | return I->ToolPtr->InputLanguage(); |
| 311 | } |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 312 | }; |
Mikhail Glushenkov | 97fda6d | 2008-05-06 17:26:14 +0000 | [diff] [blame] | 313 | |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | void CompilationGraph::writeGraph() { |
| 317 | std::ofstream O("CompilationGraph.dot"); |
| 318 | |
Mikhail Glushenkov | a4db8c0 | 2008-05-06 16:37:33 +0000 | [diff] [blame] | 319 | if (O.good()) { |
Mikhail Glushenkov | 3d68822 | 2008-05-06 18:07:48 +0000 | [diff] [blame] | 320 | llvm::WriteGraph(this, "compilation-graph"); |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 321 | O.close(); |
| 322 | } |
| 323 | else { |
| 324 | throw std::runtime_error(""); |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | void CompilationGraph::viewGraph() { |
Mikhail Glushenkov | d752c3f | 2008-05-06 16:36:50 +0000 | [diff] [blame] | 329 | llvm::ViewGraph(this, "compilation-graph"); |
Mikhail Glushenkov | 0d08db0 | 2008-05-06 16:35:25 +0000 | [diff] [blame] | 330 | } |