brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 4d2de66 Raw
96 lines · c
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIB_CAS_BUILTINCAS_H10#define LLVM_LIB_CAS_BUILTINCAS_H11 12#include "llvm/ADT/StringRef.h"13#include "llvm/CAS/BuiltinCASContext.h"14#include "llvm/CAS/ObjectStore.h"15 16namespace llvm::cas {17class ActionCache;18namespace ondisk {19class UnifiedOnDiskCache;20} // namespace ondisk21namespace builtin {22 23/// Common base class for builtin CAS implementations using the same CASContext.24class BuiltinCAS : public ObjectStore {25public:26  BuiltinCAS() : ObjectStore(BuiltinCASContext::getDefaultContext()) {}27 28  Expected<CASID> parseID(StringRef Reference) final;29 30  Expected<ObjectRef> store(ArrayRef<ObjectRef> Refs,31                            ArrayRef<char> Data) final;32  virtual Expected<ObjectRef> storeImpl(ArrayRef<uint8_t> ComputedHash,33                                        ArrayRef<ObjectRef> Refs,34                                        ArrayRef<char> Data) = 0;35 36  virtual Expected<ObjectRef>37  storeFromNullTerminatedRegion(ArrayRef<uint8_t> ComputedHash,38                                sys::fs::mapped_file_region Map) {39    return storeImpl(ComputedHash, {}, ArrayRef(Map.data(), Map.size()));40  }41 42  /// Both builtin CAS implementations provide lifetime for free, so this can43  /// be const, and readData() and getDataSize() can be implemented on top of44  /// it.45  virtual ArrayRef<char> getDataConst(ObjectHandle Node) const = 0;46 47  ArrayRef<char> getData(ObjectHandle Node,48                         bool RequiresNullTerminator) const final {49    // BuiltinCAS Objects are always null terminated.50    return getDataConst(Node);51  }52  uint64_t getDataSize(ObjectHandle Node) const final {53    return getDataConst(Node).size();54  }55 56  Error createUnknownObjectError(const CASID &ID) const {57    return createStringError(std::make_error_code(std::errc::invalid_argument),58                             "unknown object '" + ID.toString() + "'");59  }60 61  Error createCorruptObjectError(const CASID &ID) const {62    return createStringError(std::make_error_code(std::errc::invalid_argument),63                             "corrupt object '" + ID.toString() + "'");64  }65 66  Error createCorruptStorageError() const {67    return createStringError(std::make_error_code(std::errc::invalid_argument),68                             "corrupt storage");69  }70 71  Error validateObject(const CASID &ID) final;72};73 74/// Create a \p UnifiedOnDiskCache instance that uses \p BLAKE3 hashing.75Expected<std::unique_ptr<ondisk::UnifiedOnDiskCache>>76createBuiltinUnifiedOnDiskCache(StringRef Path);77 78/// \param UniDB A \p UnifiedOnDiskCache instance from \p79/// createBuiltinUnifiedOnDiskCache.80std::unique_ptr<ObjectStore> createObjectStoreFromUnifiedOnDiskCache(81    std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB);82 83/// \param UniDB A \p UnifiedOnDiskCache instance from \p84/// createBuiltinUnifiedOnDiskCache.85std::unique_ptr<ActionCache> createActionCacheFromUnifiedOnDiskCache(86    std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB);87 88// FIXME: Proxy not portable. Maybe also error-prone?89constexpr StringLiteral DefaultDirProxy = "/^llvm::cas::builtin::default";90constexpr StringLiteral DefaultDir = "llvm.cas.builtin.default";91 92} // end namespace builtin93} // end namespace llvm::cas94 95#endif // LLVM_LIB_CAS_BUILTINCAS_H96