LLVM 22.0.0git
VirtualOutputBackend.h
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file contains the declarations of the VirtualOutputBackend class, which
11/// can be used to virtualized output files from LLVM tools.
12/// VirtualOutputBackend provides an unified interface to write outputs and a
13/// configurable interface for tools to operate on those outputs.
14/// VirtualOutputBackend contains basic implementations like writing to disk
15/// with different configurations, or advanced logics like output filtering
16/// and duplicating.
17///
18//===----------------------------------------------------------------------===//
19
20#ifndef LLVM_SUPPORT_VIRTUALOUTPUTBACKEND_H
21#define LLVM_SUPPORT_VIRTUALOUTPUTBACKEND_H
22
24#include "llvm/Support/Error.h"
27
28namespace llvm::vfs {
29
30/// Interface for virtualized outputs.
31///
32/// If virtual functions are added here, also add them to \a
33/// ProxyOutputBackend.
34class OutputBackend : public RefCountedBase<OutputBackend> {
35 virtual void anchor();
36
37public:
38 /// Get a backend that points to the same destination as this one but that
39 /// has independent settings.
40 ///
41 /// Not thread-safe, but all operations are thread-safe when performed on
42 /// separate clones of the same backend.
44
45 /// Create a file. If \p Config is \c std::nullopt, uses the backend's default
46 /// OutputConfig (may match \a OutputConfig::OutputConfig(), or may
47 /// have been customized).
48 ///
49 /// Thread-safe.
51 createFile(const Twine &Path,
52 std::optional<OutputConfig> Config = std::nullopt);
53
54protected:
55 /// Must be thread-safe. Virtual function has a different name than \a
56 /// clone() so that implementations can override the return value.
58
59 /// Create a file for \p Path. Must be thread-safe.
60 ///
61 /// \pre \p Config is valid or std::nullopt.
63 createFileImpl(StringRef Path, std::optional<OutputConfig> Config) = 0;
64
65 OutputBackend() = default;
66
67public:
68 virtual ~OutputBackend() = default;
69};
70
71} // namespace llvm::vfs
72
73#endif // LLVM_SUPPORT_VIRTUALOUTPUTBACKEND_H
This file defines the RefCountedBase, ThreadSafeRefCountedBase, and IntrusiveRefCntPtr classes.
This file contains the declarations of the OutputConfig class.
This file contains the declarations of the llvm::vfs::OutputFile class, which is a virtualized output...
Tagged union holding either a T or a Error.
Definition Error.h:485
A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
virtual Expected< std::unique_ptr< OutputFileImpl > > createFileImpl(StringRef Path, std::optional< OutputConfig > Config)=0
Create a file for Path.
virtual ~OutputBackend()=default
virtual IntrusiveRefCntPtr< OutputBackend > cloneImpl() const =0
Must be thread-safe.
Expected< OutputFile > createFile(const Twine &Path, std::optional< OutputConfig > Config=std::nullopt)
Create a file.
IntrusiveRefCntPtr< OutputBackend > clone() const
Get a backend that points to the same destination as this one but that has independent settings.