|
47 | 47 | #include "llvm/Support/VirtualOutputBackend.h" |
48 | 48 | #include "llvm/Support/VirtualOutputBackends.h" |
49 | 49 | #include "llvm/Support/raw_ostream.h" |
| 50 | +#include <optional> |
50 | 51 | #include <variant> |
51 | 52 |
|
52 | 53 | namespace { |
@@ -197,6 +198,53 @@ swiftscan_string_ref_t swiftscan_cas_store(swiftscan_cas_t cas, uint8_t *data, |
197 | 198 | CAS.getID(*Result).toString().c_str()); |
198 | 199 | } |
199 | 200 |
|
| 201 | +int64_t swiftscan_cas_get_ondisk_size(swiftscan_cas_t cas, |
| 202 | + swiftscan_string_ref_t *error) { |
| 203 | + auto &CAS = unwrap(cas)->getCAS(); |
| 204 | + std::optional<uint64_t> Size; |
| 205 | + if (auto E = CAS.getStorageSize().moveInto(Size)) { |
| 206 | + *error = |
| 207 | + swift::c_string_utils::create_clone(toString(std::move(E)).c_str()); |
| 208 | + return -2; |
| 209 | + } |
| 210 | + |
| 211 | + *error = swift::c_string_utils::create_null(); |
| 212 | + return Size ? *Size : -1; |
| 213 | +} |
| 214 | + |
| 215 | +bool |
| 216 | +swiftscan_cas_set_ondisk_size_limit(swiftscan_cas_t cas, int64_t size_limit, |
| 217 | + swiftscan_string_ref_t *error) { |
| 218 | + if (size_limit < 0) { |
| 219 | + *error = swift::c_string_utils::create_clone( |
| 220 | + "invalid size limit passing to swiftscan_cas_set_ondisk_size_limit"); |
| 221 | + return true; |
| 222 | + } |
| 223 | + auto &CAS = unwrap(cas)->getCAS(); |
| 224 | + std::optional<uint64_t> SizeLimit; |
| 225 | + if (size_limit > 0) |
| 226 | + SizeLimit = size_limit; |
| 227 | + if (auto E = CAS.setSizeLimit(SizeLimit)) { |
| 228 | + *error = |
| 229 | + swift::c_string_utils::create_clone(toString(std::move(E)).c_str()); |
| 230 | + return true; |
| 231 | + } |
| 232 | + *error = swift::c_string_utils::create_null(); |
| 233 | + return false; |
| 234 | +} |
| 235 | + |
| 236 | +bool swiftscan_cas_prune_ondisk_data(swiftscan_cas_t cas, |
| 237 | + swiftscan_string_ref_t *error) { |
| 238 | + auto &CAS = unwrap(cas)->getCAS(); |
| 239 | + if (auto E = CAS.pruneStorageData()) { |
| 240 | + *error = |
| 241 | + swift::c_string_utils::create_clone(toString(std::move(E)).c_str()); |
| 242 | + return true; |
| 243 | + } |
| 244 | + *error = swift::c_string_utils::create_null(); |
| 245 | + return false; |
| 246 | +} |
| 247 | + |
200 | 248 | /// Expand the invocation if there is repsonseFile into Args that are passed in |
201 | 249 | /// the parameter. Return swift-frontend arguments in an ArrayRef, which has the |
202 | 250 | /// first "-frontend" option dropped if needed. |
|
0 commit comments