LLVM  8.0.1
ToolOutputFile.cpp
Go to the documentation of this file.
1 //===--- ToolOutputFile.cpp - Implement the ToolOutputFile class --------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This implements the ToolOutputFile class.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "llvm/Support/Signals.h"
17 using namespace llvm;
18 
19 ToolOutputFile::CleanupInstaller::CleanupInstaller(StringRef Filename)
20  : Filename(Filename), Keep(false) {
21  // Arrange for the file to be deleted if the process is killed.
22  if (Filename != "-")
23  sys::RemoveFileOnSignal(Filename);
24 }
25 
26 ToolOutputFile::CleanupInstaller::~CleanupInstaller() {
27  // Delete the file if the client hasn't told us not to.
28  if (!Keep && Filename != "-")
29  sys::fs::remove(Filename);
30 
31  // Ok, the file is successfully written and closed, or deleted. There's no
32  // further need to clean it up on signals.
33  if (Filename != "-")
35 }
36 
37 ToolOutputFile::ToolOutputFile(StringRef Filename, std::error_code &EC,
38  sys::fs::OpenFlags Flags)
39  : Installer(Filename), OS(Filename, EC, Flags) {
40  // If open fails, no cleanup is needed.
41  if (EC)
42  Installer.Keep = true;
43 }
44 
46  : Installer(Filename), OS(FD, true) {}
This class represents lattice values for constants.
Definition: AllocatorList.h:24
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:49