Movatterモバイル変換


[0]ホーム

URL:


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

Generated on Fri Jul 18 2025 12:55:23 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp