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 implements \c vfs::OutputBackend class methods.
11///
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Support/VirtualOutputBackend.h"
15#include "llvm/ADT/SmallString.h"
16#include "llvm/Support/VirtualOutputError.h"
17
18using namespace llvm;
19using namespace llvm::vfs;
20
21void OutputBackend::anchor() {}
22
23Expected<OutputFile>
24OutputBackend::createFile(const Twine &Path,
25 std::optional<OutputConfig> Config) {
26 SmallString<128> PathStorage;
27 Path.toVector(Out&: PathStorage);
28
29 if (Config) {
30 // Check for invalid configs.
31 if (!Config->getText() && Config->getCRLF())
32 return make_error<OutputConfigError>(Args&: *Config, Args&: PathStorage);
33 }
34
35 std::unique_ptr<OutputFileImpl> Impl;
36 if (Error E = createFileImpl(Path: PathStorage, Config).moveInto(Value&: Impl))
37 return std::move(E);
38 assert(Impl && "Expected valid Impl or Error");
39 return OutputFile(PathStorage, std::move(Impl));
40}
41