llvm.org GIT mirror llvm / 97ca964
[Support] Rename tool_output_file to ToolOutputFile, NFC This class isn't similar to anything from the STL, so it shouldn't use the STL naming conventions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314050 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 1 year, 11 months ago
28 changed file(s) with 75 addition(s) and 77 deletion(s). Raw diff Collapse all Expand all
7070 const std::string &NewPrefix);
7171
7272 /// Setup optimization remarks.
73 Expectedtool_output_file>>
73 ExpectedToolOutputFile>>
7474 setupOptimizationRemarks(LLVMContext &Context, StringRef LTORemarksFilename,
7575 bool LTOPassRemarksWithHotness, int Count = -1);
7676
236236 bool ShouldEmbedUselists = false;
237237 bool ShouldRestoreGlobalsLinkage = false;
238238 TargetMachine::CodeGenFileType FileType = TargetMachine::CGFT_ObjectFile;
239 std::unique_ptr<tool_output_file> DiagnosticOutputFile;
239 std::unique_ptr<ToolOutputFile> DiagnosticOutputFile;
240240 bool Freestanding = false;
241241 };
242242 }
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This file defines the tool_output_file class.
9 // This file defines the ToolOutputFile class.
1010 //
1111 //===----------------------------------------------------------------------===//
1212
2020 /// This class contains a raw_fd_ostream and adds a few extra features commonly
2121 /// needed for compiler-like tool output files:
2222 /// - The file is automatically deleted if the process is killed.
23 /// - The file is automatically deleted when the tool_output_file
23 /// - The file is automatically deleted when the ToolOutputFile
2424 /// object is destroyed unless the client calls keep().
25 class tool_output_file {
25 class ToolOutputFile {
2626 /// This class is declared before the raw_fd_ostream so that it is constructed
2727 /// before the raw_fd_ostream is constructed and destructed after the
2828 /// raw_fd_ostream is destructed. It installs cleanups in its constructor and
4444 public:
4545 /// This constructor's arguments are passed to to raw_fd_ostream's
4646 /// constructor.
47 tool_output_file(StringRef Filename, std::error_code &EC,
48 sys::fs::OpenFlags Flags);
47 ToolOutputFile(StringRef Filename, std::error_code &EC,
48 sys::fs::OpenFlags Flags);
4949
50 tool_output_file(StringRef Filename, int FD);
50 ToolOutputFile(StringRef Filename, int FD);
5151
5252 /// Return the contained raw_fd_ostream.
5353 raw_fd_ostream &os() { return OS; }
11651165 return BackendProc->wait();
11661166 }
11671167
1168 Expectedtool_output_file>>
1168 ExpectedToolOutputFile>>
11691169 lto::setupOptimizationRemarks(LLVMContext &Context,
11701170 StringRef LTORemarksFilename,
11711171 bool LTOPassRemarksWithHotness, int Count) {
11781178
11791179 std::error_code EC;
11801180 auto DiagnosticFile =
1181 llvm::make_unique<tool_output_file>(Filename, EC, sys::fs::F_None);
1181 llvm::make_unique<ToolOutputFile>(Filename, EC, sys::fs::F_None);
11821182 if (EC)
11831183 return errorCodeToError(EC);
11841184 Context.setDiagnosticsOutputFile(
348348 }
349349
350350 static void
351 finalizeOptimizationRemarks(std::unique_ptr<tool_output_file> DiagOutputFile) {
351 finalizeOptimizationRemarks(std::unique_ptr<ToolOutputFile> DiagOutputFile) {
352352 // Make sure we flush the diagnostic remarks file in case the linker doesn't
353353 // call the global destructors before exiting.
354354 if (!DiagOutputFile)
224224
225225 // create output file
226226 std::error_code EC;
227 tool_output_file Out(Path, EC, sys::fs::F_None);
227 ToolOutputFile Out(Path, EC, sys::fs::F_None);
228228 if (EC) {
229229 std::string ErrMsg = "could not open bitcode file for writing: ";
230230 ErrMsg += Path;
264264 }
265265
266266 // generate object file
267 tool_output_file objFile(Filename, FD);
267 ToolOutputFile objFile(Filename, FD);
268268
269269 bool genResult = compileOptimized(&objFile.os());
270270 objFile.os().close();
393393 TmpArchiveFD, TmpArchive))
394394 return errorCodeToError(EC);
395395
396 tool_output_file Output(TmpArchive, TmpArchiveFD);
396 ToolOutputFile Output(TmpArchive, TmpArchiveFD);
397397 raw_fd_ostream &Out = Output.os();
398398 if (Thin)
399399 Out << "!\n";
None //===--- ToolOutputFile.cpp - Implement the tool_output_file class --------===//
0 //===--- ToolOutputFile.cpp - Implement the ToolOutputFile class --------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This implements the tool_output_file class.
9 // This implements the ToolOutputFile class.
1010 //
1111 //===----------------------------------------------------------------------===//
1212
1515 #include "llvm/Support/Signals.h"
1616 using namespace llvm;
1717
18 tool_output_file::CleanupInstaller::CleanupInstaller(StringRef Filename)
18 ToolOutputFile::CleanupInstaller::CleanupInstaller(StringRef Filename)
1919 : Filename(Filename), Keep(false) {
2020 // Arrange for the file to be deleted if the process is killed.
2121 if (Filename != "-")
2222 sys::RemoveFileOnSignal(Filename);
2323 }
2424
25 tool_output_file::CleanupInstaller::~CleanupInstaller() {
25 ToolOutputFile::CleanupInstaller::~CleanupInstaller() {
2626 // Delete the file if the client hasn't told us not to.
2727 if (!Keep && Filename != "-")
2828 sys::fs::remove(Filename);
3333 sys::DontRemoveFileOnSignal(Filename);
3434 }
3535
36 tool_output_file::tool_output_file(StringRef Filename, std::error_code &EC,
37 sys::fs::OpenFlags Flags)
36 ToolOutputFile::ToolOutputFile(StringRef Filename, std::error_code &EC,
37 sys::fs::OpenFlags Flags)
3838 : Installer(Filename), OS(Filename, EC, Flags) {
3939 // If open fails, no cleanup is needed.
4040 if (EC)
4141 Installer.Keep = true;
4242 }
4343
44 tool_output_file::tool_output_file(StringRef Filename, int FD)
44 ToolOutputFile::ToolOutputFile(StringRef Filename, int FD)
4545 : Installer(Filename), OS(FD, true) {}
6060 return reportError(argv0, "the option -d must be used together with -o\n");
6161
6262 std::error_code EC;
63 tool_output_file DepOut(DependFilename, EC, sys::fs::F_Text);
63 ToolOutputFile DepOut(DependFilename, EC, sys::fs::F_Text);
6464 if (EC)
6565 return reportError(argv0, "error opening " + DependFilename + ":" +
6666 EC.message() + "\n");
9696 return 1;
9797
9898 std::error_code EC;
99 tool_output_file Out(OutputFilename, EC, sys::fs::F_Text);
99 ToolOutputFile Out(OutputFilename, EC, sys::fs::F_Text);
100100 if (EC)
101101 return reportError(argv0, "error opening " + OutputFilename + ":" +
102102 EC.message() + "\n");
384384 }
385385 sys::RemoveFileOnSignal(Filename);
386386
387 tool_output_file BlocksToNotExtractFile(Filename.c_str(), FD);
387 ToolOutputFile BlocksToNotExtractFile(Filename.c_str(), FD);
388388 for (std::vector::const_iterator I = BBs.begin(), E = BBs.end();
389389 I != E; ++I) {
390390 BasicBlock *BB = *I;
5757 /// writeProgramToFile - This writes the current "Program" to the named bitcode
5858 /// file. If an error occurs, true is returned.
5959 ///
60 static bool writeProgramToFileAux(tool_output_file &Out, const Module *M) {
60 static bool writeProgramToFileAux(ToolOutputFile &Out, const Module *M) {
6161 WriteBitcodeToFile(M, Out.os(), PreserveBitcodeUseListOrder);
6262 Out.os().close();
6363 if (!Out.os().has_error()) {
6969
7070 bool BugDriver::writeProgramToFile(const std::string &Filename, int FD,
7171 const Module *M) const {
72 tool_output_file Out(Filename, FD);
72 ToolOutputFile Out(Filename, FD);
7373 return writeProgramToFileAux(Out, M);
7474 }
7575
7676 bool BugDriver::writeProgramToFile(const std::string &Filename,
7777 const Module *M) const {
7878 std::error_code EC;
79 tool_output_file Out(Filename, EC, sys::fs::F_None);
79 ToolOutputFile Out(Filename, EC, sys::fs::F_None);
8080 if (!EC)
8181 return writeProgramToFileAux(Out, M);
8282 return true;
153153 return 1;
154154 }
155155
156 tool_output_file InFile(InputFilename, InputFD);
156 ToolOutputFile InFile(InputFilename, InputFD);
157157
158158 WriteBitcodeToFile(Program, InFile.os(), PreserveBitcodeUseListOrder);
159159 InFile.os().close();
166166
167167 static int compileModule(char **, LLVMContext &);
168168
169 static std::unique_ptr
170 GetOutputStream(const char *TargetName, Triple::OSType OS,
171 const char *ProgName) {
169 static std::unique_ptr GetOutputStream(const char *TargetName,
170 Triple::OSType OS,
171 const char *ProgName) {
172172 // If we don't yet have an output filename, make one.
173173 if (OutputFilename.empty()) {
174174 if (InputFilename == "-")
224224 sys::fs::OpenFlags OpenFlags = sys::fs::F_None;
225225 if (!Binary)
226226 OpenFlags |= sys::fs::F_Text;
227 auto FDOut = llvm::make_unique(OutputFilename, EC,
228 OpenFlags);
227 auto FDOut = llvm::make_unique(OutputFilename, EC, OpenFlags);
229228 if (EC) {
230229 errs() << EC.message() << '\n';
231230 return nullptr;
321320 if (PassRemarksHotnessThreshold)
322321 Context.setDiagnosticsHotnessThreshold(PassRemarksHotnessThreshold);
323322
324 std::unique_ptr<tool_output_file> YamlFile;
323 std::unique_ptr<ToolOutputFile> YamlFile;
325324 if (RemarksFilename != "") {
326325 std::error_code EC;
327 YamlFile = llvm::make_unique(RemarksFilename, EC,
328 sys::fs::F_None);
326 YamlFile =
327 llvm::make_unique(RemarksFilename, EC, sys::fs::F_None);
329328 if (EC) {
330329 errs() << EC.message() << '\n';
331330 return 1;
469468 Options.FloatABIType = FloatABIForCalls;
470469
471470 // Figure out where we are going to send the output.
472 std::unique_ptr<tool_output_file> Out =
471 std::unique_ptr<ToolOutputFile> Out =
473472 GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]);
474473 if (!Out) return 1;
475474
7171 }
7272
7373 std::error_code EC;
74 std::unique_ptr Out(
75 new tool_output_file(OutputFilename, EC, sys::fs::F_None));
74 std::unique_ptr Out(
75 new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
7676 if (EC) {
7777 errs() << EC.message() << '\n';
7878 exit(1);
445445 error(InputPath, EC.message());
446446 return;
447447 }
448 tool_output_file InputTOF{InputPath, InputFD};
448 ToolOutputFile InputTOF{InputPath, InputFD};
449449
450450 unsigned NumSymbols = 0;
451451 for (const auto &Function : Coverage.getCoveredFunctions()) {
463463 error(OutputPath, EC.message());
464464 return;
465465 }
466 tool_output_file OutputTOF{OutputPath, OutputFD};
466 ToolOutputFile OutputTOF{OutputPath, OutputFD};
467467 OutputTOF.os().close();
468468
469469 // Invoke the demangler.
190190 }
191191
192192 std::error_code EC;
193 std::unique_ptr Out(
194 new tool_output_file(OutputFilename, EC, sys::fs::F_None));
193 std::unique_ptr Out(
194 new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
195195 if (EC) {
196196 errs() << EC.message() << '\n';
197197 return 1;
295295 Passes.add(createStripDeadPrototypesPass()); // Remove dead func decls
296296
297297 std::error_code EC;
298 tool_output_file Out(OutputFilename, EC, sys::fs::F_None);
298 ToolOutputFile Out(OutputFilename, EC, sys::fs::F_None);
299299 if (EC) {
300300 errs() << EC.message() << '\n';
301301 return 1;
382382 if (DumpAsm) errs() << "Here's the assembly:\n" << *Composite;
383383
384384 std::error_code EC;
385 tool_output_file Out(OutputFilename, EC, sys::fs::F_None);
385 ToolOutputFile Out(OutputFilename, EC, sys::fs::F_None);
386386 if (EC) {
387387 errs() << EC.message() << '\n';
388388 return 1;
935935 error("writing merged module failed.");
936936 }
937937
938 std::list<tool_output_file> OSs;
938 std::list<ToolOutputFile> OSs;
939939 std::vector OSPtrs;
940940 for (unsigned I = 0; I != Parallelism; ++I) {
941941 std::string PartFilename = OutputFilename;
952952 // Diagnostic messages should have been printed by the handler.
953953 error("error compiling the code");
954954
955 for (tool_output_file &OS : OSs)
955 for (ToolOutputFile &OS : OSs)
956956 OS.keep();
957957 } else {
958958 if (Parallelism != 1)
196196 return TheTarget;
197197 }
198198
199 static std::unique_ptr<tool_output_file> GetOutputStream() {
199 static std::unique_ptr<ToolOutputFile> GetOutputStream() {
200200 if (OutputFilename == "")
201201 OutputFilename = "-";
202202
203203 std::error_code EC;
204 auto Out = llvm::make_unique(OutputFilename, EC,
205 sys::fs::F_None);
204 auto Out =
205 llvm::make_unique(OutputFilename, EC, sys::fs::F_None);
206206 if (EC) {
207207 errs() << EC.message() << '\n';
208208 return nullptr;
533533 FeaturesStr = Features.getString();
534534 }
535535
536 std::unique_ptr<tool_output_file> Out = GetOutputStream();
536 std::unique_ptr<ToolOutputFile> Out = GetOutputStream();
537537 if (!Out)
538538 return 1;
539539
208208
209209 std::error_code EC;
210210 const std::string OutputFilename = "-";
211 auto Out = llvm::make_unique(OutputFilename, EC,
212 sys::fs::F_None);
211 auto Out =
212 llvm::make_unique(OutputFilename, EC, sys::fs::F_None);
213213 if (EC) {
214214 errs() << EC.message() << '\n';
215215 abort();
5353 }
5454
5555 std::error_code EC;
56 std::unique_ptr Out(
57 new tool_output_file(OutputFilename, EC, sys::fs::F_None));
56 std::unique_ptr Out(
57 new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
5858 ExitOnErr(errorCodeToError(EC));
5959
6060 if (BinaryExtract) {
59495949 errs() << XarEC.message() << "\n";
59505950 return;
59515951 }
5952 tool_output_file XarFile(XarFilename, FD);
5952 ToolOutputFile XarFile(XarFilename, FD);
59535953 raw_fd_ostream &XarOut = XarFile.os();
59545954 StringRef XarContents(sect, size);
59555955 XarOut << XarContents;
5454 unsigned I = 0;
5555 SplitModule(std::move(M), NumOutputs, [&](std::unique_ptr MPart) {
5656 std::error_code EC;
57 std::unique_ptr Out(new tool_output_file(
58 OutputFilename + utostr(I++), EC, sys::fs::F_None));
57 std::unique_ptr Out(
58 new ToolOutputFile(OutputFilename + utostr(I++), EC, sys::fs::F_None));
5959 if (EC) {
6060 errs() << EC.message() << '\n';
6161 exit(1);
746746 IntroduceControlFlow(F, R);
747747
748748 // Figure out what stream we are supposed to write to...
749 std::unique_ptr<tool_output_file> Out;
749 std::unique_ptr<ToolOutputFile> Out;
750750 // Default to standard output.
751751 if (OutputFilename.empty())
752752 OutputFilename = "-";
753753
754754 std::error_code EC;
755 Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None));
755 Out.reset(new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
756756 if (EC) {
757757 errs() << EC.message() << '\n';
758758 return 1;
167167 #endif
168168
169169 bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
170 tool_output_file *Out,
171 tool_output_file *ThinLTOLinkOut,
172 tool_output_file *OptRemarkFile,
170 ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut,
171 ToolOutputFile *OptRemarkFile,
173172 StringRef PassPipeline, OutputKind OK,
174173 VerifierKind VK,
175174 bool ShouldPreserveAssemblyUseListOrder,
2525 class LLVMContext;
2626 class Module;
2727 class TargetMachine;
28 class tool_output_file;
28 class ToolOutputFile;
2929
3030 namespace opt_tool {
3131 enum OutputKind {
5151 /// ThinLTOLinkOut is only used when OK is OK_OutputThinLTOBitcode, and can be
5252 /// nullptr.
5353 bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
54 tool_output_file *Out, tool_output_file *ThinLinkOut,
55 tool_output_file *OptRemarkFile, StringRef PassPipeline,
54 ToolOutputFile *Out, ToolOutputFile *ThinLinkOut,
55 ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
5656 opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
5757 bool ShouldPreserveAssemblyUseListOrder,
5858 bool ShouldPreserveBitcodeUseListOrder,
429429 if (PassRemarksHotnessThreshold)
430430 Context.setDiagnosticsHotnessThreshold(PassRemarksHotnessThreshold);
431431
432 std::unique_ptr<tool_output_file> OptRemarkFile;
432 std::unique_ptr<ToolOutputFile> OptRemarkFile;
433433 if (RemarksFilename != "") {
434434 std::error_code EC;
435 OptRemarkFile = llvm::make_unique(RemarksFilename, EC,
436 sys::fs::F_None);
435 OptRemarkFile =
436 llvm::make_unique(RemarksFilename, EC, sys::fs::F_None);
437437 if (EC) {
438438 errs() << EC.message() << '\n';
439439 return 1;
470470 M->setDataLayout(ClDataLayout);
471471
472472 // Figure out what stream we are supposed to write to...
473 std::unique_ptr Out;
474 std::unique_ptr<tool_output_file> ThinLinkOut;
473 std::unique_ptr<ToolOutputFile> Out;
474 std::unique_ptr ThinLinkOut;
475475 if (NoOutput) {
476476 if (!OutputFilename.empty())
477477 errs() << "WARNING: The -o (output filename) option is ignored when\n"
482482 OutputFilename = "-";
483483
484484 std::error_code EC;
485 Out.reset(new tool_output_file(OutputFilename, EC, sys::fs::F_None));
485 Out.reset(new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
486486 if (EC) {
487487 errs() << EC.message() << '\n';
488488 return 1;
490490
491491 if (!ThinLinkBitcodeFile.empty()) {
492492 ThinLinkOut.reset(
493 new tool_output_file(ThinLinkBitcodeFile, EC, sys::fs::F_None));
493 new ToolOutputFile(ThinLinkBitcodeFile, EC, sys::fs::F_None));
494494 if (EC) {
495495 errs() << EC.message() << '\n';
496496 return 1;
579579 OutputFilename = "-";
580580
581581 std::error_code EC;
582 Out = llvm::make_unique(OutputFilename, EC,
583 sys::fs::F_None);
582 Out = llvm::make_unique(OutputFilename, EC,
583 sys::fs::F_None);
584584 if (EC) {
585585 errs() << EC.message() << '\n';
586586 return 1;
7878 OutputFilename = "-";
7979
8080 std::error_code EC;
81 std::unique_ptr Out(
82 new tool_output_file(OutputFilename, EC, sys::fs::F_None));
81 std::unique_ptr Out(
82 new ToolOutputFile(OutputFilename, EC, sys::fs::F_None));
8383 if (EC)
8484 error("yaml2obj: Error opening '" + OutputFilename + "': " + EC.message());
8585