blob: c3152c0b021655f5f7343dd474d2ea808c46c012 [file] [log] [blame]
Douglas Gregord44252e2011-08-25 20:47:51 +00001//===--- ModuleManager.cpp - Module Manager ---------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the ModuleManager class, which manages a set of loaded
11// modules for the ASTReader.
12//
13//===----------------------------------------------------------------------===//
Ben Langmuirbeee15e2014-04-14 18:00:01 +000014#include "clang/Lex/HeaderSearch.h"
Douglas Gregor7029ce12013-03-19 00:28:20 +000015#include "clang/Lex/ModuleMap.h"
Douglas Gregor7211ac12013-01-25 23:32:03 +000016#include "clang/Serialization/GlobalModuleIndex.h"
Benjamin Krameraf04f982013-08-24 13:16:22 +000017#include "clang/Serialization/ModuleManager.h"
Douglas Gregord44252e2011-08-25 20:47:51 +000018#include "llvm/Support/MemoryBuffer.h"
Rafael Espindola552c1692013-06-11 22:15:02 +000019#include "llvm/Support/Path.h"
Douglas Gregord44252e2011-08-25 20:47:51 +000020#include "llvm/Support/raw_ostream.h"
21#include "llvm/Support/system_error.h"
22
Douglas Gregor9d7c1a22011-10-11 19:27:55 +000023#ifndef NDEBUG
24#include "llvm/Support/GraphWriter.h"
25#endif
26
Douglas Gregord44252e2011-08-25 20:47:51 +000027using namespace clang;
28using namespace serialization;
29
Douglas Gregorde3ef502011-11-30 23:21:26 +000030ModuleFile *ModuleManager::lookup(StringRef Name) {
Douglas Gregordadd85d2013-02-08 21:27:45 +000031 const FileEntry *Entry = FileMgr.getFile(Name, /*openFile=*/false,
32 /*cacheFailure=*/false);
Douglas Gregorbf7fc9c2013-03-27 16:47:18 +000033 if (Entry)
34 return lookup(Entry);
35
36 return 0;
37}
38
39ModuleFile *ModuleManager::lookup(const FileEntry *File) {
40 llvm::DenseMap<const FileEntry *, ModuleFile *>::iterator Known
41 = Modules.find(File);
42 if (Known == Modules.end())
43 return 0;
44
45 return Known->second;
Douglas Gregord44252e2011-08-25 20:47:51 +000046}
47
48llvm::MemoryBuffer *ModuleManager::lookupBuffer(StringRef Name) {
Douglas Gregordadd85d2013-02-08 21:27:45 +000049 const FileEntry *Entry = FileMgr.getFile(Name, /*openFile=*/false,
50 /*cacheFailure=*/false);
Douglas Gregord44252e2011-08-25 20:47:51 +000051 return InMemoryBuffers[Entry];
52}
53
Douglas Gregor7029ce12013-03-19 00:28:20 +000054ModuleManager::AddModuleResult
Douglas Gregor6fb03ae2012-11-30 19:28:05 +000055ModuleManager::addModule(StringRef FileName, ModuleKind Type,
56 SourceLocation ImportLoc, ModuleFile *ImportedBy,
Douglas Gregor7029ce12013-03-19 00:28:20 +000057 unsigned Generation,
58 off_t ExpectedSize, time_t ExpectedModTime,
59 ModuleFile *&Module,
60 std::string &ErrorStr) {
61 Module = 0;
62
63 // Look for the file entry. This only fails if the expected size or
64 // modification time differ.
65 const FileEntry *Entry;
Eli Friedmanc27d0d52013-09-05 23:50:58 +000066 if (lookupModuleFile(FileName, ExpectedSize, ExpectedModTime, Entry)) {
67 ErrorStr = "module file out of date";
Douglas Gregor7029ce12013-03-19 00:28:20 +000068 return OutOfDate;
Eli Friedmanc27d0d52013-09-05 23:50:58 +000069 }
Douglas Gregor7029ce12013-03-19 00:28:20 +000070
Douglas Gregord44252e2011-08-25 20:47:51 +000071 if (!Entry && FileName != "-") {
Eli Friedmanc27d0d52013-09-05 23:50:58 +000072 ErrorStr = "module file not found";
Douglas Gregor7029ce12013-03-19 00:28:20 +000073 return Missing;
Douglas Gregord44252e2011-08-25 20:47:51 +000074 }
Douglas Gregor7029ce12013-03-19 00:28:20 +000075
76 // Check whether we already loaded this module, before
Douglas Gregorde3ef502011-11-30 23:21:26 +000077 ModuleFile *&ModuleEntry = Modules[Entry];
Douglas Gregord44252e2011-08-25 20:47:51 +000078 bool NewModule = false;
79 if (!ModuleEntry) {
80 // Allocate a new module.
Douglas Gregor4fc9f3e2012-01-18 20:56:22 +000081 ModuleFile *New = new ModuleFile(Type, Generation);
Douglas Gregorbdb259d2013-01-21 20:07:12 +000082 New->Index = Chain.size();
Douglas Gregord44252e2011-08-25 20:47:51 +000083 New->FileName = FileName.str();
Argyrios Kyrtzidisaedf7142012-10-03 01:58:42 +000084 New->File = Entry;
Douglas Gregor6fb03ae2012-11-30 19:28:05 +000085 New->ImportLoc = ImportLoc;
Douglas Gregord44252e2011-08-25 20:47:51 +000086 Chain.push_back(New);
87 NewModule = true;
88 ModuleEntry = New;
Douglas Gregor6fb03ae2012-11-30 19:28:05 +000089
Dmitri Gribenkof430da42014-02-12 10:33:14 +000090 New->InputFilesValidationTimestamp = 0;
91 if (New->Kind == MK_Module) {
92 std::string TimestampFilename = New->getTimestampFilename();
Ben Langmuirc8130a72014-02-20 21:59:23 +000093 vfs::Status Status;
Dmitri Gribenkof430da42014-02-12 10:33:14 +000094 // A cached stat value would be fine as well.
95 if (!FileMgr.getNoncachedStatValue(TimestampFilename, Status))
96 New->InputFilesValidationTimestamp =
97 Status.getLastModificationTime().toEpochTime();
98 }
99
Douglas Gregord44252e2011-08-25 20:47:51 +0000100 // Load the contents of the module
101 if (llvm::MemoryBuffer *Buffer = lookupBuffer(FileName)) {
102 // The buffer was already provided for us.
103 assert(Buffer && "Passed null buffer");
104 New->Buffer.reset(Buffer);
105 } else {
106 // Open the AST file.
107 llvm::error_code ec;
108 if (FileName == "-") {
109 ec = llvm::MemoryBuffer::getSTDIN(New->Buffer);
110 if (ec)
111 ErrorStr = ec.message();
112 } else
113 New->Buffer.reset(FileMgr.getBufferForFile(FileName, &ErrorStr));
114
115 if (!New->Buffer)
Douglas Gregor7029ce12013-03-19 00:28:20 +0000116 return Missing;
Douglas Gregord44252e2011-08-25 20:47:51 +0000117 }
118
119 // Initialize the stream
120 New->StreamFile.init((const unsigned char *)New->Buffer->getBufferStart(),
Douglas Gregor7029ce12013-03-19 00:28:20 +0000121 (const unsigned char *)New->Buffer->getBufferEnd());
Douglas Gregor7029ce12013-03-19 00:28:20 +0000122 }
Douglas Gregord44252e2011-08-25 20:47:51 +0000123
124 if (ImportedBy) {
125 ModuleEntry->ImportedBy.insert(ImportedBy);
126 ImportedBy->Imports.insert(ModuleEntry);
127 } else {
Douglas Gregor6fb03ae2012-11-30 19:28:05 +0000128 if (!ModuleEntry->DirectlyImported)
129 ModuleEntry->ImportLoc = ImportLoc;
130
Douglas Gregord44252e2011-08-25 20:47:51 +0000131 ModuleEntry->DirectlyImported = true;
132 }
Douglas Gregor7029ce12013-03-19 00:28:20 +0000133
134 Module = ModuleEntry;
135 return NewModule? NewlyLoaded : AlreadyLoaded;
Douglas Gregord44252e2011-08-25 20:47:51 +0000136}
137
Douglas Gregor7029ce12013-03-19 00:28:20 +0000138void ModuleManager::removeModules(ModuleIterator first, ModuleIterator last,
139 ModuleMap *modMap) {
Douglas Gregor188dbef2012-11-07 17:46:15 +0000140 if (first == last)
141 return;
142
143 // Collect the set of module file pointers that we'll be removing.
144 llvm::SmallPtrSet<ModuleFile *, 4> victimSet(first, last);
145
146 // Remove any references to the now-destroyed modules.
Douglas Gregor188dbef2012-11-07 17:46:15 +0000147 for (unsigned i = 0, n = Chain.size(); i != n; ++i) {
Chandler Carruthb55d0222014-03-03 19:36:27 +0000148 Chain[i]->ImportedBy.remove_if([&](ModuleFile *MF) {
149 return victimSet.count(MF);
150 });
Douglas Gregor188dbef2012-11-07 17:46:15 +0000151 }
152
153 // Delete the modules and erase them from the various structures.
154 for (ModuleIterator victim = first; victim != last; ++victim) {
Ben Langmuirca392142014-05-19 16:13:45 +0000155 const FileEntry *F = (*victim)->File;
156 Modules.erase(F);
Douglas Gregor7029ce12013-03-19 00:28:20 +0000157
Ben Langmuirca392142014-05-19 16:13:45 +0000158 // Refresh the stat() information for the module file so stale information
159 // doesn't get stored accidentally.
160 vfs::Status UpdatedStat;
161 if (FileMgr.getNoncachedStatValue(F->getName(), UpdatedStat)) {
162 llvm::report_fatal_error(Twine("module file '") + F->getName() +
163 "' removed after it has been used");
164 } else {
165 FileMgr.modifyFileEntry(const_cast<FileEntry *>(F), UpdatedStat.getSize(),
166 UpdatedStat.getLastModificationTime().toEpochTime());
167 }
168
Douglas Gregor7029ce12013-03-19 00:28:20 +0000169 if (modMap) {
Ben Langmuirbeee15e2014-04-14 18:00:01 +0000170 StringRef ModuleName = (*victim)->ModuleName;
Douglas Gregor7029ce12013-03-19 00:28:20 +0000171 if (Module *mod = modMap->findModule(ModuleName)) {
172 mod->setASTFile(0);
173 }
174 }
Douglas Gregor188dbef2012-11-07 17:46:15 +0000175 delete *victim;
176 }
177
178 // Remove the modules from the chain.
179 Chain.erase(first, last);
180}
181
Douglas Gregord44252e2011-08-25 20:47:51 +0000182void ModuleManager::addInMemoryBuffer(StringRef FileName,
183 llvm::MemoryBuffer *Buffer) {
184
185 const FileEntry *Entry = FileMgr.getVirtualFile(FileName,
186 Buffer->getBufferSize(), 0);
187 InMemoryBuffers[Entry] = Buffer;
188}
189
Douglas Gregore97cd902013-01-28 16:46:33 +0000190ModuleManager::VisitState *ModuleManager::allocateVisitState() {
191 // Fast path: if we have a cached state, use it.
192 if (FirstVisitState) {
193 VisitState *Result = FirstVisitState;
194 FirstVisitState = FirstVisitState->NextState;
195 Result->NextState = 0;
196 return Result;
197 }
198
199 // Allocate and return a new state.
200 return new VisitState(size());
201}
202
203void ModuleManager::returnVisitState(VisitState *State) {
204 assert(State->NextState == 0 && "Visited state is in list?");
205 State->NextState = FirstVisitState;
206 FirstVisitState = State;
207}
208
Douglas Gregor7211ac12013-01-25 23:32:03 +0000209void ModuleManager::setGlobalIndex(GlobalModuleIndex *Index) {
210 GlobalIndex = Index;
Douglas Gregor603cd862013-03-22 18:50:14 +0000211 if (!GlobalIndex) {
212 ModulesInCommonWithGlobalIndex.clear();
213 return;
Douglas Gregor7029ce12013-03-19 00:28:20 +0000214 }
Douglas Gregor603cd862013-03-22 18:50:14 +0000215
216 // Notify the global module index about all of the modules we've already
217 // loaded.
218 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
219 if (!GlobalIndex->loadedModuleFile(Chain[I])) {
220 ModulesInCommonWithGlobalIndex.push_back(Chain[I]);
221 }
222 }
223}
224
225void ModuleManager::moduleFileAccepted(ModuleFile *MF) {
226 if (!GlobalIndex || GlobalIndex->loadedModuleFile(MF))
227 return;
228
229 ModulesInCommonWithGlobalIndex.push_back(MF);
Douglas Gregor7211ac12013-01-25 23:32:03 +0000230}
231
232ModuleManager::ModuleManager(FileManager &FileMgr)
Douglas Gregore97cd902013-01-28 16:46:33 +0000233 : FileMgr(FileMgr), GlobalIndex(), FirstVisitState(0) { }
Douglas Gregord44252e2011-08-25 20:47:51 +0000234
235ModuleManager::~ModuleManager() {
236 for (unsigned i = 0, e = Chain.size(); i != e; ++i)
237 delete Chain[e - i - 1];
Douglas Gregore97cd902013-01-28 16:46:33 +0000238 delete FirstVisitState;
Douglas Gregord44252e2011-08-25 20:47:51 +0000239}
240
Douglas Gregor7211ac12013-01-25 23:32:03 +0000241void
242ModuleManager::visit(bool (*Visitor)(ModuleFile &M, void *UserData),
243 void *UserData,
Douglas Gregor7029ce12013-03-19 00:28:20 +0000244 llvm::SmallPtrSet<ModuleFile *, 4> *ModuleFilesHit) {
Douglas Gregor7211ac12013-01-25 23:32:03 +0000245 // If the visitation order vector is the wrong size, recompute the order.
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000246 if (VisitOrder.size() != Chain.size()) {
247 unsigned N = size();
248 VisitOrder.clear();
249 VisitOrder.reserve(N);
250
251 // Record the number of incoming edges for each module. When we
252 // encounter a module with no incoming edges, push it into the queue
253 // to seed the queue.
254 SmallVector<ModuleFile *, 4> Queue;
255 Queue.reserve(N);
256 llvm::SmallVector<unsigned, 4> UnusedIncomingEdges;
257 UnusedIncomingEdges.reserve(size());
258 for (ModuleIterator M = begin(), MEnd = end(); M != MEnd; ++M) {
259 if (unsigned Size = (*M)->ImportedBy.size())
260 UnusedIncomingEdges.push_back(Size);
261 else {
262 UnusedIncomingEdges.push_back(0);
263 Queue.push_back(*M);
264 }
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000265 }
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000266
267 // Traverse the graph, making sure to visit a module before visiting any
268 // of its dependencies.
269 unsigned QueueStart = 0;
270 while (QueueStart < Queue.size()) {
271 ModuleFile *CurrentModule = Queue[QueueStart++];
272 VisitOrder.push_back(CurrentModule);
273
274 // For any module that this module depends on, push it on the
275 // stack (if it hasn't already been marked as visited).
276 for (llvm::SetVector<ModuleFile *>::iterator
277 M = CurrentModule->Imports.begin(),
278 MEnd = CurrentModule->Imports.end();
279 M != MEnd; ++M) {
280 // Remove our current module as an impediment to visiting the
281 // module we depend on. If we were the last unvisited module
282 // that depends on this particular module, push it into the
283 // queue to be visited.
284 unsigned &NumUnusedEdges = UnusedIncomingEdges[(*M)->Index];
285 if (NumUnusedEdges && (--NumUnusedEdges == 0))
286 Queue.push_back(*M);
287 }
288 }
289
290 assert(VisitOrder.size() == N && "Visitation order is wrong?");
Douglas Gregor7211ac12013-01-25 23:32:03 +0000291
Douglas Gregore97cd902013-01-28 16:46:33 +0000292 delete FirstVisitState;
293 FirstVisitState = 0;
Douglas Gregord44252e2011-08-25 20:47:51 +0000294 }
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000295
Douglas Gregore97cd902013-01-28 16:46:33 +0000296 VisitState *State = allocateVisitState();
297 unsigned VisitNumber = State->NextVisitNumber++;
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000298
Douglas Gregor7211ac12013-01-25 23:32:03 +0000299 // If the caller has provided us with a hit-set that came from the global
300 // module index, mark every module file in common with the global module
301 // index that is *not* in that set as 'visited'.
302 if (ModuleFilesHit && !ModulesInCommonWithGlobalIndex.empty()) {
303 for (unsigned I = 0, N = ModulesInCommonWithGlobalIndex.size(); I != N; ++I)
304 {
305 ModuleFile *M = ModulesInCommonWithGlobalIndex[I];
Douglas Gregor7029ce12013-03-19 00:28:20 +0000306 if (!ModuleFilesHit->count(M))
Douglas Gregore97cd902013-01-28 16:46:33 +0000307 State->VisitNumber[M->Index] = VisitNumber;
Douglas Gregor7211ac12013-01-25 23:32:03 +0000308 }
309 }
310
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000311 for (unsigned I = 0, N = VisitOrder.size(); I != N; ++I) {
312 ModuleFile *CurrentModule = VisitOrder[I];
313 // Should we skip this module file?
Douglas Gregore97cd902013-01-28 16:46:33 +0000314 if (State->VisitNumber[CurrentModule->Index] == VisitNumber)
Douglas Gregord44252e2011-08-25 20:47:51 +0000315 continue;
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000316
317 // Visit the module.
Douglas Gregore97cd902013-01-28 16:46:33 +0000318 assert(State->VisitNumber[CurrentModule->Index] == VisitNumber - 1);
319 State->VisitNumber[CurrentModule->Index] = VisitNumber;
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000320 if (!Visitor(*CurrentModule, UserData))
321 continue;
322
323 // The visitor has requested that cut off visitation of any
324 // module that the current module depends on. To indicate this
325 // behavior, we mark all of the reachable modules as having been visited.
326 ModuleFile *NextModule = CurrentModule;
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000327 do {
328 // For any module that this module depends on, push it on the
329 // stack (if it hasn't already been marked as visited).
330 for (llvm::SetVector<ModuleFile *>::iterator
331 M = NextModule->Imports.begin(),
332 MEnd = NextModule->Imports.end();
333 M != MEnd; ++M) {
Douglas Gregore97cd902013-01-28 16:46:33 +0000334 if (State->VisitNumber[(*M)->Index] != VisitNumber) {
335 State->Stack.push_back(*M);
336 State->VisitNumber[(*M)->Index] = VisitNumber;
Douglas Gregord44252e2011-08-25 20:47:51 +0000337 }
338 }
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000339
Douglas Gregore97cd902013-01-28 16:46:33 +0000340 if (State->Stack.empty())
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000341 break;
342
343 // Pop the next module off the stack.
Robert Wilhelm25284cc2013-08-23 16:11:15 +0000344 NextModule = State->Stack.pop_back_val();
Douglas Gregore41d7fe2013-01-25 22:25:23 +0000345 } while (true);
Douglas Gregord44252e2011-08-25 20:47:51 +0000346 }
Douglas Gregore97cd902013-01-28 16:46:33 +0000347
348 returnVisitState(State);
Douglas Gregord44252e2011-08-25 20:47:51 +0000349}
350
351/// \brief Perform a depth-first visit of the current module.
Douglas Gregorde3ef502011-11-30 23:21:26 +0000352static bool visitDepthFirst(ModuleFile &M,
353 bool (*Visitor)(ModuleFile &M, bool Preorder,
Douglas Gregord44252e2011-08-25 20:47:51 +0000354 void *UserData),
355 void *UserData,
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000356 SmallVectorImpl<bool> &Visited) {
Douglas Gregord44252e2011-08-25 20:47:51 +0000357 // Preorder visitation
358 if (Visitor(M, /*Preorder=*/true, UserData))
359 return true;
360
361 // Visit children
Douglas Gregorde3ef502011-11-30 23:21:26 +0000362 for (llvm::SetVector<ModuleFile *>::iterator IM = M.Imports.begin(),
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000363 IMEnd = M.Imports.end();
Douglas Gregord44252e2011-08-25 20:47:51 +0000364 IM != IMEnd; ++IM) {
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000365 if (Visited[(*IM)->Index])
Douglas Gregord44252e2011-08-25 20:47:51 +0000366 continue;
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000367 Visited[(*IM)->Index] = true;
368
Douglas Gregord44252e2011-08-25 20:47:51 +0000369 if (visitDepthFirst(**IM, Visitor, UserData, Visited))
370 return true;
371 }
372
373 // Postorder visitation
374 return Visitor(M, /*Preorder=*/false, UserData);
375}
376
Douglas Gregorde3ef502011-11-30 23:21:26 +0000377void ModuleManager::visitDepthFirst(bool (*Visitor)(ModuleFile &M, bool Preorder,
Douglas Gregord44252e2011-08-25 20:47:51 +0000378 void *UserData),
379 void *UserData) {
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000380 SmallVector<bool, 16> Visited(size(), false);
Douglas Gregord44252e2011-08-25 20:47:51 +0000381 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000382 if (Visited[Chain[I]->Index])
Douglas Gregord44252e2011-08-25 20:47:51 +0000383 continue;
Douglas Gregorbdb259d2013-01-21 20:07:12 +0000384 Visited[Chain[I]->Index] = true;
385
Douglas Gregord44252e2011-08-25 20:47:51 +0000386 if (::visitDepthFirst(*Chain[I], Visitor, UserData, Visited))
387 return;
388 }
389}
Douglas Gregor9d7c1a22011-10-11 19:27:55 +0000390
Douglas Gregor7029ce12013-03-19 00:28:20 +0000391bool ModuleManager::lookupModuleFile(StringRef FileName,
392 off_t ExpectedSize,
393 time_t ExpectedModTime,
394 const FileEntry *&File) {
Ben Langmuir05f82ba2014-05-01 03:33:36 +0000395 // Open the file immediately to ensure there is no race between stat'ing and
396 // opening the file.
397 File = FileMgr.getFile(FileName, /*openFile=*/true, /*cacheFailure=*/false);
Douglas Gregor7029ce12013-03-19 00:28:20 +0000398
399 if (!File && FileName != "-") {
400 return false;
401 }
402
403 if ((ExpectedSize && ExpectedSize != File->getSize()) ||
Ben Langmuir027731d2014-05-04 05:20:54 +0000404 (ExpectedModTime && ExpectedModTime != File->getModificationTime()))
405 // Do not destroy File, as it may be referenced. If we need to rebuild it,
406 // it will be destroyed by removeModules.
Douglas Gregor7029ce12013-03-19 00:28:20 +0000407 return true;
Douglas Gregor7029ce12013-03-19 00:28:20 +0000408
409 return false;
410}
411
Douglas Gregor9d7c1a22011-10-11 19:27:55 +0000412#ifndef NDEBUG
413namespace llvm {
414 template<>
415 struct GraphTraits<ModuleManager> {
Douglas Gregorde3ef502011-11-30 23:21:26 +0000416 typedef ModuleFile NodeType;
417 typedef llvm::SetVector<ModuleFile *>::const_iterator ChildIteratorType;
Douglas Gregor9d7c1a22011-10-11 19:27:55 +0000418 typedef ModuleManager::ModuleConstIterator nodes_iterator;
419
420 static ChildIteratorType child_begin(NodeType *Node) {
421 return Node->Imports.begin();
422 }
423
424 static ChildIteratorType child_end(NodeType *Node) {
425 return Node->Imports.end();
426 }
427
428 static nodes_iterator nodes_begin(const ModuleManager &Manager) {
429 return Manager.begin();
430 }
431
432 static nodes_iterator nodes_end(const ModuleManager &Manager) {
433 return Manager.end();
434 }
435 };
436
437 template<>
438 struct DOTGraphTraits<ModuleManager> : public DefaultDOTGraphTraits {
439 explicit DOTGraphTraits(bool IsSimple = false)
440 : DefaultDOTGraphTraits(IsSimple) { }
441
442 static bool renderGraphFromBottomUp() {
443 return true;
444 }
445
Douglas Gregorde3ef502011-11-30 23:21:26 +0000446 std::string getNodeLabel(ModuleFile *M, const ModuleManager&) {
Ben Langmuirbeee15e2014-04-14 18:00:01 +0000447 return M->ModuleName;
Douglas Gregor9d7c1a22011-10-11 19:27:55 +0000448 }
449 };
450}
451
452void ModuleManager::viewGraph() {
453 llvm::ViewGraph(*this, "Modules");
454}
455#endif