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

Method cacheModule

libchigraph/src/ModuleCache.cpp:26–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24ModuleCache::ModuleCache(chi::Context& ctx) : mContext{&ctx} {}
25
26Result ModuleCache::cacheModule(const boost::filesystem::path& moduleName,
27 llvm::Module& compiledModule, std::time_t timeAtFileRead) {
28 assert(!moduleName.empty() && "Cannot pass a empty module name to ModuleCache::cacheModule");
29
30 Result res;
31
32 auto cachePath = cachePathForModule(moduleName);
33
34 // make the directories
35 boost::filesystem::create_directories(cachePath.parent_path());
36
37 // open & write
38 {
39 // open the file
40 std::error_code errCode;
41 llvm::raw_fd_ostream fileStream(cachePath.string(), errCode, llvm::sys::fs::F_RW);
42
43 if (errCode) {
44 res.addEntry("EUKN", "Failed to open file", {{"Path", cachePath.string()}});
45 return res;
46 }
47
48 // write it
49 llvm::WriteBitcodeToFile(&compiledModule, fileStream);
50 }
51
52 // set age to be correct
53 boost::filesystem::last_write_time(cachePath, timeAtFileRead);
54
55 return res;
56}
57
58boost::filesystem::path ModuleCache::cachePathForModule(
59 const boost::filesystem::path& moduleName) const {

Callers 1

compileModuleMethod · 0.80

Calls 1

addEntryMethod · 0.80

Tested by

no test coverage detected