2010-10-07 20:32:40 +00:00
|
|
|
//===- ToolOutputFile.h - Output files for compiler-like tools -----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the tool_output_file class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 00:45:19 +00:00
|
|
|
#ifndef LLVM_SUPPORT_TOOLOUTPUTFILE_H
|
|
|
|
#define LLVM_SUPPORT_TOOLOUTPUTFILE_H
|
2010-10-07 20:32:40 +00:00
|
|
|
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-04-08 13:52:09 +00:00
|
|
|
/// This class contains a raw_fd_ostream and adds a few extra features commonly
|
|
|
|
/// needed for compiler-like tool output files:
|
2010-10-07 20:32:40 +00:00
|
|
|
/// - The file is automatically deleted if the process is killed.
|
|
|
|
/// - The file is automatically deleted when the tool_output_file
|
|
|
|
/// object is destroyed unless the client calls keep().
|
|
|
|
class tool_output_file {
|
2015-04-08 13:52:09 +00:00
|
|
|
/// This class is declared before the raw_fd_ostream so that it is constructed
|
|
|
|
/// before the raw_fd_ostream is constructed and destructed after the
|
|
|
|
/// raw_fd_ostream is destructed. It installs cleanups in its constructor and
|
|
|
|
/// uninstalls them in its destructor.
|
2010-10-07 20:32:40 +00:00
|
|
|
class CleanupInstaller {
|
2014-08-25 18:16:47 +00:00
|
|
|
/// The name of the file.
|
2010-10-07 20:32:40 +00:00
|
|
|
std::string Filename;
|
|
|
|
public:
|
2014-08-25 18:16:47 +00:00
|
|
|
/// The flag which indicates whether we should not delete the file.
|
2010-10-07 20:32:40 +00:00
|
|
|
bool Keep;
|
|
|
|
|
2014-08-25 18:16:47 +00:00
|
|
|
explicit CleanupInstaller(StringRef ilename);
|
2010-10-07 20:32:40 +00:00
|
|
|
~CleanupInstaller();
|
|
|
|
} Installer;
|
|
|
|
|
2015-04-08 13:52:09 +00:00
|
|
|
/// The contained stream. This is intentionally declared after Installer.
|
2010-10-07 20:32:40 +00:00
|
|
|
raw_fd_ostream OS;
|
|
|
|
|
|
|
|
public:
|
2014-08-25 18:16:47 +00:00
|
|
|
/// This constructor's arguments are passed to to raw_fd_ostream's
|
|
|
|
/// constructor.
|
|
|
|
tool_output_file(StringRef Filename, std::error_code &EC,
|
2014-02-24 15:07:20 +00:00
|
|
|
sys::fs::OpenFlags Flags);
|
2010-10-07 20:32:40 +00:00
|
|
|
|
2014-08-25 18:16:47 +00:00
|
|
|
tool_output_file(StringRef Filename, int FD);
|
2013-06-17 18:05:35 +00:00
|
|
|
|
2015-04-08 13:52:09 +00:00
|
|
|
/// Return the contained raw_fd_ostream.
|
2010-10-07 20:32:40 +00:00
|
|
|
raw_fd_ostream &os() { return OS; }
|
|
|
|
|
2015-04-08 13:52:09 +00:00
|
|
|
/// Indicate that the tool's job wrt this output file has been successful and
|
|
|
|
/// the file should not be deleted.
|
2010-10-07 20:32:40 +00:00
|
|
|
void keep() { Installer.Keep = true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end llvm namespace
|
|
|
|
|
|
|
|
#endif
|