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

Class ModuleCache

libchigraph/include/chi/ModuleCache.hpp:16–65  ·  view source on GitHub ↗

This class caches modules into the lib/ direcotry of the workspace

Source from the content-addressed store, hash-verified

14
15/// This class caches modules into the lib/ direcotry of the workspace
16struct ModuleCache {
17 /// Create a module cache with a bound context
18 explicit ModuleCache(Context& ctx);
19
20 // No copy or move
21 ModuleCache(const ModuleCache&) = delete;
22 ModuleCache(ModuleCache&&) = delete;
23 ModuleCache& operator=(const ModuleCache&) = delete;
24 ModuleCache& operator=(ModuleCache&&) = delete;
25
26 /// Cache a module
27 /// \param moduleName The name of the module to cache
28 /// \pre `!moduleName.empty()`
29 /// \param compiledModule The IR that's been compiled from this module
30 /// \param timeAtFileRead The time to store as the cache time. Should be the time the module was
31 /// read from disk
32 /// \return The Result
33 Result cacheModule(const boost::filesystem::path& moduleName, llvm::Module& compiledModule,
34 std::time_t timeAtFileRead);
35
36 /// Get the cache name for a module. Basically `context().workspacePath() / moduleName + ".bc"`
37 /// \param moduleName The name of the module to get a cache path for
38 /// \return The path
39 boost::filesystem::path cachePathForModule(const boost::filesystem::path& moduleName) const;
40
41 /// Inavlidate the cache, as it delete the cache file
42 /// \param moduleName The name of the module to invalidate
43 /// \pre `!moduleName.empty()`
44 void invalidateCache(const boost::filesystem::path& moduleName);
45
46 /// Get the time that a cache was updated
47 /// \param moduleName The module to get the last update time for
48 /// \return The time it was updated, or 0 if there is no cache
49 std::time_t cacheUpdateTime(const boost::filesystem::path& moduleName) const;
50
51 /// Retrieve a module from the cache
52 /// \param moduleName The name of the module to retrieve
53 /// \pre `!moduleName.empty()`
54 /// \param atLeastThisNew Make sure the cache is at least as new as this
55 /// \return A llvm::Module, or nullptr if no suitable cache was found
56 std::unique_ptr<llvm::Module> retrieveFromCache(const boost::filesystem::path& moduleName,
57 std::time_t atLeastThisNew);
58
59 /// Get the context this cache is bound to
60 /// \return the `Context`
61 Context& context() const { return *mContext; }
62
63private:
64 Context* mContext;
65};
66
67} // namespace chi
68

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected