LLVM  9.0.0svn
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 
15 #include "llvm/Support/Signals.h"
16 using namespace llvm;
17 
18 ToolOutputFile::CleanupInstaller::CleanupInstaller(StringRef Filename)
19  : Filename(Filename), Keep(false) {
20  // Arrange for the file to be deleted if the process is killed.
21  if (Filename != "-")
22  sys::RemoveFileOnSignal(Filename);
23 }
24 
25 ToolOutputFile::CleanupInstaller::~CleanupInstaller() {
26  // Delete the file if the client hasn't told us not to.
27  if (!Keep && Filename != "-")
28  sys::fs::remove(Filename);
29 
30  // Ok, the file is successfully written and closed, or deleted. There's no
31  // further need to clean it up on signals.
32  if (Filename != "-")
34 }
35 
36 ToolOutputFile::ToolOutputFile(StringRef Filename, std::error_code &EC,
37  sys::fs::OpenFlags Flags)
38  : Installer(Filename), OS(Filename, EC, Flags) {
39  // If open fails, no cleanup is needed.
40  if (EC)
41  Installer.Keep = true;
42 }
43 
45  : Installer(Filename), OS(FD, true) {}
This class represents lattice values for constants.
Definition: AllocatorList.h:23
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
block Block Frequency true
ToolOutputFile(StringRef Filename, std::error_code &EC, sys::fs::OpenFlags Flags)
This constructor's arguments are passed to raw_fd_ostream's constructor.
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...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48