blob: 758268f79b9ce1132412a56df52b30f74a1ed534 [file] [log] [blame]
Mikhail Glushenkovb90cd832008-05-06 16:34:12 +00001//===--- CompilationGraph.cpp - The LLVM Compiler Driver --------*- C++ -*-===//
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +00002//
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 Glushenkovb90cd832008-05-06 16:34:12 +000010// Compilation graph - implementation.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000011//
12//===----------------------------------------------------------------------===//
13
Mikhail Glushenkova6730372008-05-12 16:31:42 +000014#include "Error.h"
Mikhail Glushenkov4a1a77c2008-09-22 20:50:40 +000015#include "llvm/CompilerDriver/CompilationGraph.h"
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000016
Mikhail Glushenkov87416b42008-05-06 18:10:53 +000017#include "llvm/ADT/STLExtras.h"
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000018#include "llvm/Support/CommandLine.h"
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +000019#include "llvm/Support/DOTGraphTraits.h"
20#include "llvm/Support/GraphWriter.h"
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000021
Mikhail Glushenkov02606582008-05-06 18:07:14 +000022#include <algorithm>
Mikhail Glushenkov02606582008-05-06 18:07:14 +000023#include <iterator>
Mikhail Glushenkov87416b42008-05-06 18:10:53 +000024#include <limits>
Mikhail Glushenkov02606582008-05-06 18:07:14 +000025#include <queue>
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000026#include <stdexcept>
27
28using namespace llvm;
Mikhail Glushenkovbe9d9a12008-05-06 18:08:59 +000029using namespace llvmc;
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000030
31extern cl::list<std::string> InputFilenames;
Mikhail Glushenkov87416b42008-05-06 18:10:53 +000032extern cl::list<std::string> Languages;
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000033
Mikhail Glushenkov2e73e852008-05-30 06:19:52 +000034namespace llvmc {
Mikhail Glushenkov2e73e852008-05-30 06:19:52 +000035
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +000036 const std::string& LanguageMap::GetLanguage(const sys::Path& File) const {
37 LanguageMap::const_iterator Lang = this->find(File.getSuffix());
38 if (Lang == this->end())
Mikhail Glushenkov2e73e852008-05-30 06:19:52 +000039 throw std::runtime_error("Unknown suffix: " + File.getSuffix());
40 return Lang->second;
41 }
42}
43
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +000044namespace {
45
Mikhail Glushenkov4561ab52008-05-07 21:50:19 +000046 /// ChooseEdge - Return the edge with the maximum weight.
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +000047 template <class C>
48 const Edge* ChooseEdge(const C& EdgesContainer,
Mikhail Glushenkov76b1b242008-05-06 18:15:12 +000049 const InputLanguagesSet& InLangs,
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +000050 const std::string& NodeName = "root") {
Mikhail Glushenkovbb8b58d2008-05-06 18:14:24 +000051 const Edge* MaxEdge = 0;
52 unsigned MaxWeight = 0;
53 bool SingleMax = true;
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +000054
55 for (typename C::const_iterator B = EdgesContainer.begin(),
56 E = EdgesContainer.end(); B != E; ++B) {
Bill Wendling46f7a5e2008-10-02 18:39:11 +000057 const Edge* e = B->getPtr();
58 unsigned EW = e->Weight(InLangs);
Mikhail Glushenkovbb8b58d2008-05-06 18:14:24 +000059 if (EW > MaxWeight) {
Bill Wendling46f7a5e2008-10-02 18:39:11 +000060 MaxEdge = e;
Mikhail Glushenkovbb8b58d2008-05-06 18:14:24 +000061 MaxWeight = EW;
62 SingleMax = true;
Mikhail Glushenkove0ff9ae2008-05-06 18:18:58 +000063 } else if (EW == MaxWeight) {
Mikhail Glushenkovbb8b58d2008-05-06 18:14:24 +000064 SingleMax = false;
65 }
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +000066 }
67
Mikhail Glushenkovbb8b58d2008-05-06 18:14:24 +000068 if (!SingleMax)
69 throw std::runtime_error("Node " + NodeName +
70 ": multiple maximal outward edges found!"
Mikhail Glushenkov87416b42008-05-06 18:10:53 +000071 " Most probably a specification error.");
Mikhail Glushenkovbb8b58d2008-05-06 18:14:24 +000072 if (!MaxEdge)
73 throw std::runtime_error("Node " + NodeName +
74 ": no maximal outward edge found!"
75 " Most probably a specification error.");
76 return MaxEdge;
Mikhail Glushenkov6591c892008-05-06 17:23:50 +000077 }
78
Mikhail Glushenkov6591c892008-05-06 17:23:50 +000079}
80
Mikhail Glushenkov7e6d70a2008-11-26 22:59:45 +000081void Node::AddEdge(Edge* Edg) {
82 // If there already was an edge between two nodes, modify it instead
83 // of adding a new edge.
84 const std::string& ToolName = Edg->ToolName();
85 for (container_type::iterator B = OutEdges.begin(), E = OutEdges.end();
86 B != E; ++B) {
87 if ((*B)->ToolName() == ToolName) {
88 llvm::IntrusiveRefCntPtr<Edge>(Edg).swap(*B);
89 return;
90 }
91 }
92 OutEdges.push_back(llvm::IntrusiveRefCntPtr<Edge>(Edg));
93}
94
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +000095CompilationGraph::CompilationGraph() {
96 NodesMap["root"] = Node(this);
97}
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000098
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +000099Node& CompilationGraph::getNode(const std::string& ToolName) {
100 nodes_map_type::iterator I = NodesMap.find(ToolName);
101 if (I == NodesMap.end())
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000102 throw std::runtime_error("Node " + ToolName + " is not in the graph");
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000103 return I->second;
104}
105
106const Node& CompilationGraph::getNode(const std::string& ToolName) const {
107 nodes_map_type::const_iterator I = NodesMap.find(ToolName);
108 if (I == NodesMap.end())
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000109 throw std::runtime_error("Node " + ToolName + " is not in the graph!");
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000110 return I->second;
111}
112
Mikhail Glushenkovbe867122008-05-06 18:16:52 +0000113// Find the tools list corresponding to the given language name.
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000114const CompilationGraph::tools_vector_type&
115CompilationGraph::getToolsVector(const std::string& LangName) const
116{
117 tools_map_type::const_iterator I = ToolsMap.find(LangName);
118 if (I == ToolsMap.end())
Mikhail Glushenkov87416b42008-05-06 18:10:53 +0000119 throw std::runtime_error("No tool corresponding to the language "
Mikhail Glushenkov35bca412008-05-30 06:16:59 +0000120 + LangName + " found");
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000121 return I->second;
122}
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000123
Mikhail Glushenkov0a174932008-05-06 16:36:06 +0000124void CompilationGraph::insertNode(Tool* V) {
Mikhail Glushenkovaa4774c2008-11-12 00:04:46 +0000125 if (NodesMap.count(V->Name()) == 0)
126 NodesMap[V->Name()] = Node(this, V);
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000127}
128
Mikhail Glushenkovffcf3a12008-05-30 06:18:16 +0000129void CompilationGraph::insertEdge(const std::string& A, Edge* Edg) {
130 Node& B = getNode(Edg->ToolName());
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000131 if (A == "root") {
Mikhail Glushenkov5fe84752008-05-30 06:24:49 +0000132 const char** InLangs = B.ToolPtr->InputLanguages();
133 for (;*InLangs; ++InLangs)
134 ToolsMap[*InLangs].push_back(IntrusiveRefCntPtr<Edge>(Edg));
Mikhail Glushenkovffcf3a12008-05-30 06:18:16 +0000135 NodesMap["root"].AddEdge(Edg);
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000136 }
137 else {
Mikhail Glushenkov0a174932008-05-06 16:36:06 +0000138 Node& N = getNode(A);
Mikhail Glushenkovffcf3a12008-05-30 06:18:16 +0000139 N.AddEdge(Edg);
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000140 }
Mikhail Glushenkovc74bfc92008-05-06 17:26:53 +0000141 // Increase the inward edge counter.
142 B.IncrInEdges();
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000143}
144
Mikhail Glushenkov2ba4c5a2008-05-06 17:25:51 +0000145// Pass input file through the chain until we bump into a Join node or
146// a node that says that it is the last.
Mikhail Glushenkov35a85e82008-05-06 18:10:20 +0000147void CompilationGraph::PassThroughGraph (const sys::Path& InFile,
148 const Node* StartNode,
Mikhail Glushenkov76b1b242008-05-06 18:15:12 +0000149 const InputLanguagesSet& InLangs,
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +0000150 const sys::Path& TempDir,
151 const LanguageMap& LangMap) const {
Mikhail Glushenkov35a85e82008-05-06 18:10:20 +0000152 sys::Path In = InFile;
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +0000153 const Node* CurNode = StartNode;
Mikhail Glushenkov2ba4c5a2008-05-06 17:25:51 +0000154
Mikhail Glushenkovf9152532008-12-07 16:41:11 +0000155 while(true) {
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +0000156 Tool* CurTool = CurNode->ToolPtr.getPtr();
Mikhail Glushenkov2ba4c5a2008-05-06 17:25:51 +0000157
158 if (CurTool->IsJoin()) {
Mikhail Glushenkov35a85e82008-05-06 18:10:20 +0000159 JoinTool& JT = dynamic_cast<JoinTool&>(*CurTool);
160 JT.AddToJoinList(In);
Mikhail Glushenkov2ba4c5a2008-05-06 17:25:51 +0000161 break;
162 }
163
Mikhail Glushenkovf9152532008-12-07 16:41:11 +0000164 Action CurAction = CurTool->GenerateAction(In, CurNode->HasChildren(),
165 TempDir, InLangs, LangMap);
Mikhail Glushenkov2ba4c5a2008-05-06 17:25:51 +0000166
Mikhail Glushenkovf9152532008-12-07 16:41:11 +0000167 if (int ret = CurAction.Execute())
Mikhail Glushenkova6730372008-05-12 16:31:42 +0000168 throw error_code(ret);
Mikhail Glushenkov2ba4c5a2008-05-06 17:25:51 +0000169
Mikhail Glushenkovf9152532008-12-07 16:41:11 +0000170 if (CurAction.StopCompilation())
Mikhail Glushenkov87416b42008-05-06 18:10:53 +0000171 return;
172
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +0000173 CurNode = &getNode(ChooseEdge(CurNode->OutEdges,
Mikhail Glushenkov76b1b242008-05-06 18:15:12 +0000174 InLangs,
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +0000175 CurNode->Name())->ToolName());
Mikhail Glushenkovf9152532008-12-07 16:41:11 +0000176 In = CurAction.OutFile();
Mikhail Glushenkov2ba4c5a2008-05-06 17:25:51 +0000177 }
Mikhail Glushenkov2ba4c5a2008-05-06 17:25:51 +0000178}
179
Mikhail Glushenkovbe867122008-05-06 18:16:52 +0000180// Find the head of the toolchain corresponding to the given file.
Mikhail Glushenkov76b1b242008-05-06 18:15:12 +0000181// Also, insert an input language into InLangs.
Mikhail Glushenkov87416b42008-05-06 18:10:53 +0000182const Node* CompilationGraph::
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +0000183FindToolChain(const sys::Path& In, const std::string* ForceLanguage,
184 InputLanguagesSet& InLangs, const LanguageMap& LangMap) const {
Mikhail Glushenkov76b1b242008-05-06 18:15:12 +0000185
186 // Determine the input language.
Mikhail Glushenkov87416b42008-05-06 18:10:53 +0000187 const std::string& InLanguage =
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +0000188 ForceLanguage ? *ForceLanguage : LangMap.GetLanguage(In);
Mikhail Glushenkov76b1b242008-05-06 18:15:12 +0000189
190 // Add the current input language to the input language set.
191 InLangs.insert(InLanguage);
192
193 // Find the toolchain for the input language.
Mikhail Glushenkov02606582008-05-06 18:07:14 +0000194 const tools_vector_type& TV = getToolsVector(InLanguage);
195 if (TV.empty())
Mikhail Glushenkova6730372008-05-12 16:31:42 +0000196 throw std::runtime_error("No toolchain corresponding to language "
197 + InLanguage + " found");
Mikhail Glushenkov76b1b242008-05-06 18:15:12 +0000198 return &getNode(ChooseEdge(TV, InLangs)->ToolName());
Mikhail Glushenkov02606582008-05-06 18:07:14 +0000199}
200
Mikhail Glushenkov4c11a622008-05-06 18:15:35 +0000201// Helper function used by Build().
202// Traverses initial portions of the toolchains (up to the first Join node).
203// This function is also responsible for handling the -x option.
204void CompilationGraph::BuildInitial (InputLanguagesSet& InLangs,
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +0000205 const sys::Path& TempDir,
206 const LanguageMap& LangMap) {
Mikhail Glushenkov87416b42008-05-06 18:10:53 +0000207 // This is related to -x option handling.
208 cl::list<std::string>::const_iterator xIter = Languages.begin(),
209 xBegin = xIter, xEnd = Languages.end();
210 bool xEmpty = true;
211 const std::string* xLanguage = 0;
212 unsigned xPos = 0, xPosNext = 0, filePos = 0;
213
214 if (xIter != xEnd) {
215 xEmpty = false;
216 xPos = Languages.getPosition(xIter - xBegin);
217 cl::list<std::string>::const_iterator xNext = llvm::next(xIter);
218 xPosNext = (xNext == xEnd) ? std::numeric_limits<unsigned>::max()
219 : Languages.getPosition(xNext - xBegin);
220 xLanguage = (*xIter == "none") ? 0 : &(*xIter);
221 }
222
Mikhail Glushenkov4f6e3a42008-05-06 17:28:03 +0000223 // For each input file:
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000224 for (cl::list<std::string>::const_iterator B = InputFilenames.begin(),
Mikhail Glushenkov87416b42008-05-06 18:10:53 +0000225 CB = B, E = InputFilenames.end(); B != E; ++B) {
Mikhail Glushenkovbbbc9d42008-05-06 17:27:37 +0000226 sys::Path In = sys::Path(*B);
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000227
Mikhail Glushenkov87416b42008-05-06 18:10:53 +0000228 // Code for handling the -x option.
229 // Output: std::string* xLanguage (can be NULL).
230 if (!xEmpty) {
231 filePos = InputFilenames.getPosition(B - CB);
232
233 if (xPos < filePos) {
234 if (filePos < xPosNext) {
235 xLanguage = (*xIter == "none") ? 0 : &(*xIter);
236 }
237 else { // filePos >= xPosNext
238 // Skip xIters while filePos > xPosNext
239 while (filePos > xPosNext) {
240 ++xIter;
241 xPos = xPosNext;
242
243 cl::list<std::string>::const_iterator xNext = llvm::next(xIter);
244 if (xNext == xEnd)
245 xPosNext = std::numeric_limits<unsigned>::max();
246 else
247 xPosNext = Languages.getPosition(xNext - xBegin);
248 xLanguage = (*xIter == "none") ? 0 : &(*xIter);
249 }
250 }
251 }
252 }
253
Mikhail Glushenkov02606582008-05-06 18:07:14 +0000254 // Find the toolchain corresponding to this file.
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +0000255 const Node* N = FindToolChain(In, xLanguage, InLangs, LangMap);
Mikhail Glushenkov02606582008-05-06 18:07:14 +0000256 // Pass file through the chain starting at head.
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +0000257 PassThroughGraph(In, N, InLangs, TempDir, LangMap);
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000258 }
Mikhail Glushenkov4c11a622008-05-06 18:15:35 +0000259}
260
Mikhail Glushenkovbe867122008-05-06 18:16:52 +0000261// Sort the nodes in topological order.
262void CompilationGraph::TopologicalSort(std::vector<const Node*>& Out) {
263 std::queue<const Node*> Q;
264 Q.push(&getNode("root"));
265
266 while (!Q.empty()) {
267 const Node* A = Q.front();
268 Q.pop();
269 Out.push_back(A);
270 for (Node::const_iterator EB = A->EdgesBegin(), EE = A->EdgesEnd();
271 EB != EE; ++EB) {
272 Node* B = &getNode((*EB)->ToolName());
273 B->DecrInEdges();
274 if (B->HasNoInEdges())
275 Q.push(B);
276 }
277 }
278}
279
280namespace {
281 bool NotJoinNode(const Node* N) {
282 return N->ToolPtr ? !N->ToolPtr->IsJoin() : true;
283 }
284}
285
286// Call TopologicalSort and filter the resulting list to include
287// only Join nodes.
288void CompilationGraph::
289TopologicalSortFilterJoinNodes(std::vector<const Node*>& Out) {
290 std::vector<const Node*> TopSorted;
291 TopologicalSort(TopSorted);
292 std::remove_copy_if(TopSorted.begin(), TopSorted.end(),
293 std::back_inserter(Out), NotJoinNode);
294}
295
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +0000296int CompilationGraph::Build (const sys::Path& TempDir,
297 const LanguageMap& LangMap) {
Mikhail Glushenkov4c11a622008-05-06 18:15:35 +0000298
299 InputLanguagesSet InLangs;
300
301 // Traverse initial parts of the toolchains and fill in InLangs.
Mikhail Glushenkov11a353a2008-09-22 20:47:46 +0000302 BuildInitial(InLangs, TempDir, LangMap);
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000303
Mikhail Glushenkov02606582008-05-06 18:07:14 +0000304 std::vector<const Node*> JTV;
305 TopologicalSortFilterJoinNodes(JTV);
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000306
Mikhail Glushenkov02606582008-05-06 18:07:14 +0000307 // For all join nodes in topological order:
308 for (std::vector<const Node*>::iterator B = JTV.begin(), E = JTV.end();
309 B != E; ++B) {
Mikhail Glushenkovbe9d9a12008-05-06 18:08:59 +0000310
Mikhail Glushenkov3d688222008-05-06 18:07:48 +0000311 const Node* CurNode = *B;
312 JoinTool* JT = &dynamic_cast<JoinTool&>(*CurNode->ToolPtr.getPtr());
Mikhail Glushenkov3d688222008-05-06 18:07:48 +0000313
Mikhail Glushenkovbe867122008-05-06 18:16:52 +0000314 // Are there any files in the join list?
Mikhail Glushenkov3d688222008-05-06 18:07:48 +0000315 if (JT->JoinListEmpty())
316 continue;
317
Mikhail Glushenkovf9152532008-12-07 16:41:11 +0000318 Action CurAction = JT->GenerateAction(CurNode->HasChildren(),
319 TempDir, InLangs, LangMap);
Mikhail Glushenkov3d688222008-05-06 18:07:48 +0000320
Mikhail Glushenkovf9152532008-12-07 16:41:11 +0000321 if (int ret = CurAction.Execute())
Mikhail Glushenkova6730372008-05-12 16:31:42 +0000322 throw error_code(ret);
Mikhail Glushenkov3d688222008-05-06 18:07:48 +0000323
Mikhail Glushenkovf9152532008-12-07 16:41:11 +0000324 if (CurAction.StopCompilation())
325 return 0;
326
Mikhail Glushenkovb677df82008-12-07 16:45:37 +0000327 const Node* NextNode = &getNode(ChooseEdge(CurNode->OutEdges, InLangs,
328 CurNode->Name())->ToolName());
329 PassThroughGraph(sys::Path(CurAction.OutFile()), NextNode,
330 InLangs, TempDir, LangMap);
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000331 }
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +0000332
333 return 0;
334}
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000335
Mikhail Glushenkovbbbc9d42008-05-06 17:27:37 +0000336// Code related to graph visualization.
337
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000338namespace llvm {
339 template <>
Mikhail Glushenkovbe9d9a12008-05-06 18:08:59 +0000340 struct DOTGraphTraits<llvmc::CompilationGraph*>
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000341 : public DefaultDOTGraphTraits
342 {
343
Mikhail Glushenkov97fda6d2008-05-06 17:26:14 +0000344 template<typename GraphType>
345 static std::string getNodeLabel(const Node* N, const GraphType&)
346 {
347 if (N->ToolPtr)
348 if (N->ToolPtr->IsJoin())
349 return N->Name() + "\n (join" +
350 (N->HasChildren() ? ")"
351 : std::string(": ") + N->ToolPtr->OutputLanguage() + ')');
352 else
353 return N->Name();
354 else
355 return "root";
356 }
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000357
Mikhail Glushenkov97fda6d2008-05-06 17:26:14 +0000358 template<typename EdgeIter>
359 static std::string getEdgeSourceLabel(const Node* N, EdgeIter I) {
Mikhail Glushenkovffcf3a12008-05-30 06:18:16 +0000360 if (N->ToolPtr) {
Mikhail Glushenkov97fda6d2008-05-06 17:26:14 +0000361 return N->ToolPtr->OutputLanguage();
Mikhail Glushenkovffcf3a12008-05-30 06:18:16 +0000362 }
363 else {
Mikhail Glushenkov5fe84752008-05-30 06:24:49 +0000364 const char** InLangs = I->ToolPtr->InputLanguages();
Mikhail Glushenkovffcf3a12008-05-30 06:18:16 +0000365 std::string ret;
366
Mikhail Glushenkov5fe84752008-05-30 06:24:49 +0000367 for (; *InLangs; ++InLangs) {
368 if (*(InLangs + 1)) {
369 ret += *InLangs;
370 ret += ", ";
371 }
372 else {
373 ret += *InLangs;
374 }
Mikhail Glushenkovffcf3a12008-05-30 06:18:16 +0000375 }
376
377 return ret;
378 }
Mikhail Glushenkov97fda6d2008-05-06 17:26:14 +0000379 }
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000380 };
Mikhail Glushenkov97fda6d2008-05-06 17:26:14 +0000381
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000382}
383
384void CompilationGraph::writeGraph() {
Mikhail Glushenkov35bca412008-05-30 06:16:59 +0000385 std::ofstream O("compilation-graph.dot");
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000386
Mikhail Glushenkova4db8c02008-05-06 16:37:33 +0000387 if (O.good()) {
Mikhail Glushenkov3d688222008-05-06 18:07:48 +0000388 llvm::WriteGraph(this, "compilation-graph");
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000389 O.close();
390 }
391 else {
Mikhail Glushenkov35bca412008-05-30 06:16:59 +0000392 throw std::runtime_error("Error opening file 'compilation-graph.dot'"
393 " for writing!");
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000394 }
395}
396
397void CompilationGraph::viewGraph() {
Mikhail Glushenkovd752c3f2008-05-06 16:36:50 +0000398 llvm::ViewGraph(this, "compilation-graph");
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +0000399}