MCPcopy Create free account
hub / github.com/chigraph/chigraph / retrieveFromCache

Method retrieveFromCache

libchigraph/src/ModuleCache.cpp:75–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75std::unique_ptr<llvm::Module> ModuleCache::retrieveFromCache(
76 const boost::filesystem::path& moduleName, std::time_t atLeastThisNew) {
77 assert(!moduleName.empty() && "Cannot pass empty path to ModuleCache::retrieveFromCache");
78
79 auto cachePath = cachePathForModule(moduleName);
80
81 // if there is no cache, then there is nothing to retrieve
82 if (!boost::filesystem::is_regular_file(cachePath)) { return nullptr; }
83
84 // see if the cache is new enough
85 auto cacheEditTime = cacheUpdateTime(moduleName);
86 if (cacheEditTime < atLeastThisNew) { return nullptr; }
87
88 // if all of this is true, then we can read the cache
89 auto bcFileBufferOrError = llvm::MemoryBuffer::getFile(cachePath.string());
90 if (!bcFileBufferOrError) { return nullptr; }
91
92 auto errorOrMod = llvm::parseBitcodeFile(llvm::MemoryBufferRef(*bcFileBufferOrError.get()),
93 context().llvmContext());
94
95 if (!errorOrMod) {
96#if LLVM_VERSION_AT_LEAST(4, 0)
97 auto E = errorOrMod.takeError();
98
99 llvm::handleAllErrors(std::move(E), [](llvm::ErrorInfoBase& err) {});
100#endif
101
102 return nullptr;
103 }
104
105 return std::unique_ptr<llvm::Module>{std::move(errorOrMod.get())};
106}
107
108} // namespace chi

Callers 1

compileModuleMethod · 0.80

Calls 1

getMethod · 0.80

Tested by

no test coverage detected