LLVM 20.0.0git
ToolOutputFile.cpp
Go to the documentation of this file.
1//===--- ToolOutputFile.cpp - Implement the ToolOutputFile class --------===//
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// This implements the ToolOutputFile class.
10//
11//===----------------------------------------------------------------------===//
12
16using namespace llvm;
17
18static bool isStdout(StringRef Filename) { return Filename == "-"; }
19
21 : Filename(std::string(Filename)), Keep(false) {
22 // Arrange for the file to be deleted if the process is killed.
23 if (!isStdout(Filename))
25}
26
28 if (isStdout(Filename))
29 return;
30
31 // Delete the file if the client hasn't told us not to.
32 if (!Keep)
34
35 // Ok, the file is successfully written and closed, or deleted. There's no
36 // further need to clean it up on signals.
38}
39
40ToolOutputFile::ToolOutputFile(StringRef Filename, std::error_code &EC,
42 : Installer(Filename) {
43 if (isStdout(Filename)) {
44 OS = &outs();
45 EC = std::error_code();
46 return;
47 }
48 OSHolder.emplace(Filename, EC, Flags);
49 OS = &*OSHolder;
50 // If open fails, no cleanup is needed.
51 if (EC)
52 Installer.Keep = true;
53}
54
56 : Installer(Filename) {
57 OSHolder.emplace(FD, true);
58 OS = &*OSHolder;
59}
static bool isStdout(StringRef Filename)
CleanupInstaller(StringRef Filename)
std::string Filename
The name of the file.
bool Keep
The flag which indicates whether we should not delete the file.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
ToolOutputFile(StringRef Filename, std::error_code &EC, sys::fs::OpenFlags Flags)
This constructor's arguments are passed to raw_fd_ostream's constructor.
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
void DontRemoveFileOnSignal(StringRef Filename)
This function removes a file from the list of files to be removed on signal delivery.
bool RemoveFileOnSignal(StringRef Filename, std::string *ErrMsg=nullptr)
This function registers signal handlers to ensure that if a signal gets delivered that the named file...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
@ Keep
No function return thunk.
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858