11 namespace serialization {
16 write<uint64_t>(fp, s.size());
17 fwrite(s.data(),
sizeof(std::string::value_type), s.size(), fp);
24 read<uint64_t>(fp, len);
27 fread(s.data(),
sizeof(std::string::value_type), len, fp);
32 write(fp, value.abs_path_on_disk);
33 write(fp, value.object_filename);
34 write(fp, value.hash);
35 write(fp, value.last_modification);
36 write(fp, value.depend_by);
40 read(fp, value.abs_path_on_disk);
41 read(fp, value.object_filename);
43 read(fp, value.last_modification);
44 read(fp, value.depend_by);
48 write<uint64_t>(fp, value.cache.size());
49 for (
auto &item : value.cache) {
50 write(fp, item.first);
51 write(fp, item.second);
53 write<uint64_t>(fp, value.free_list.size());
54 for (
auto &item : value.free_list) {
57 write<yoi::indexT>(fp, value.next_hash);
62 read<uint64_t>(fp, len);
63 for (
auto i = 0; i < len; i++) {
68 value.cache.insert({key, entry});
70 read<uint64_t>(fp, len);
71 for (
auto i = 0; i < len; i++) {
74 value.free_list.insert(item);
76 read<yoi::indexT>(fp, value.next_hash);
79 template <>
void write(FILE *fp,
const std::set<yoi::indexT> &value) {
80 write<uint64_t>(fp, value.size());
81 for (
auto &item : value) {
86 template <>
void read(FILE *fp, std::set<yoi::indexT> &value) {
88 read<uint64_t>(fp, len);
89 for (
auto i = 0; i < len; i++) {
126 std::set<yoi::wstr> source_set(source_files.begin(), source_files.end());
127 std::set<yoi::wstr> to_be_removed, to_be_added;
128 for (
auto &item :
cache) {
129 if (source_set.find(item.first) == source_set.end()) {
130 to_be_removed.insert(item.first);
133 for (
auto &item : source_files) {
135 to_be_added.insert(item);
138 for (
auto &item : to_be_removed) {
139 if (std::filesystem::exists(
cache[item].object_filename)) {
140 std::filesystem::remove(
cache[item].object_filename);
145 for (
auto &item : to_be_added) {
152 if (
cache.find(abs_path_on_disk) !=
cache.end()) {
153 return cache[abs_path_on_disk].hash;
162 if (!std::filesystem::exists(
compilerCtx->getBuildConfig()->buildCachePath)) {
163 std::filesystem::create_directories(
compilerCtx->getBuildConfig()->buildCachePath);
165 yoi::wstr object_filename =
compilerCtx->getBuildConfig()->buildCachePath + L
"/" + std::to_wstring(hash) + L
".o";
181 if (
cache.find(abs_path_on_disk) ==
cache.end()) {
184 return cache[abs_path_on_disk].hash;
189 if (
cache.find(abs_path_on_disk) ==
cache.end()) {
192 return cache.at(abs_path_on_disk);
198 cache.erase(abs_path_on_disk);
203 if (
cache.find(abs_path_on_disk) !=
cache.end()) {
204 cache[abs_path_on_disk].last_modification = last_modification;
void purge_and_update(const yoi::vec< yoi::wstr > &source_files)
purge the cache, add the entries that previously not in the cache, remove the entries that are not in...
CodegenObjectCacheEntry get_entry(const yoi::wstr &abs_path_on_disk)
get the entry from the cache
yoi::indexT register_entry(const yoi::wstr &abs_path_on_disk)
register a new entry to the cache
yoi::indexT register_entry_unlocked(const yoi::wstr &abs_path_on_disk)
CodegenObjectCache & setCompilerCtx(const std::shared_ptr< compilerContext > &compilerCtx)
set the build config
void remove_entry(const yoi::wstr &abs_path_on_disk)
remove the entry from the cache
std::set< yoi::indexT > free_list
std::shared_ptr< compilerContext > compilerCtx
yoi::indexT get_entry_index(const yoi::wstr &abs_path_on_disk)
get the entry from the cache
void update_last_modification(const yoi::wstr &abs_path_on_disk, yoi::indexT last_modification)
update the last modification time of an entry
std::map< yoi::wstr, CodegenObjectCacheEntry > cache
void write(FILE *fp, const yoi::wstr &value)
void read(FILE *fp, yoi::wstr &value)
std::string wstring2string(const std::wstring &v)
std::wstring string2wstring(const std::string &v)
CodegenObjectCacheEntry setAbsPathOnDisk(const yoi::wstr &abs_path_on_disk)
const yoi::wstr & getObjectFilename() const
yoi::indexT last_modification
yoi::wstr object_filename
CodegenObjectCacheEntry setHash(yoi::indexT hash)
CodegenObjectCacheEntry setLastModification(yoi::indexT last_modification)
yoi::indexT getHash() const
const yoi::wstr & getAbsPathOnDisk() const
CodegenObjectCacheEntry setObjectFilename(const yoi::wstr &object_filename)
yoi::wstr abs_path_on_disk
yoi::indexT getLastModification() const