llvm.org GIT mirror llvm / 0b9d56a
Define InitLLVM to do common initialization all at once. We have a few functions that virtually all command wants to run on process startup/shutdown. This patch adds InitLLVM class to do that all at once, so that we don't need to copy-n-paste boilerplate code to each llvm command's main() function. Differential Revision: https://reviews.llvm.org/D45602 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330046 91177308-0d34-0410-b5e6-96231b3b80d8 Rui Ueyama 1 year, 4 months ago
40 changed file(s) with 185 addition(s) and 268 deletion(s). Raw diff Collapse all Expand all
0 //===- InitLLVM.h -----------------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_SUPPORT_LLVM_H
10 #define LLVM_SUPPORT_LLVM_H
11
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/Support/Allocator.h"
14 #include "llvm/Support/PrettyStackTrace.h"
15
16 // The main() functions in typical LLVM tools start with InitLLVM which does
17 // the following one-time initializations:
18 //
19 // 1. Setting up a signal handler so that pretty stack trace is printed out
20 // if a process crashes.
21 //
22 // 2. If running on Windows, obtain command line arguments using a
23 // multibyte character-aware API and convert arguments into UTF-8
24 // encoding, so that you can assume that command line arguments are
25 // always encoded in UTF-8 on any platform.
26 //
27 // InitLLVM calls llvm_shutdown() on destruction, which cleans up
28 // ManagedStatic objects.
29 namespace llvm {
30 class InitLLVM {
31 public:
32 InitLLVM(int &Argc, const char **&Argv);
33 InitLLVM(int &Argc, char **&Argv)
34 : InitLLVM(Argc, const_cast(Argv)) {}
35
36 ~InitLLVM();
37
38 private:
39 SpecificBumpPtrAllocator Alloc;
40 SmallVector Args;
41 PrettyStackTraceProgram StackPrinter;
42 };
43 } // namespace llvm
44
45 #endif
7575 GlobPattern.cpp
7676 GraphWriter.cpp
7777 Hashing.cpp
78 InitLLVM.cpp
7879 IntEqClasses.cpp
7980 IntervalMap.cpp
8081 JamCRC.cpp
0 //===-- InitLLVM.cpp -----------------------------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Support/InitLLVM.h"
10 #include "llvm/Support/Error.h"
11 #include "llvm/Support/ManagedStatic.h"
12 #include "llvm/Support/PrettyStackTrace.h"
13 #include "llvm/Support/Process.h"
14 #include "llvm/Support/Signals.h"
15 #include
16
17 using namespace llvm;
18
19 InitLLVM::InitLLVM(int &Argc, const char **&Argv) : StackPrinter(Argc, Argv) {
20 sys::PrintStackTraceOnErrorSignal(Argv[0]);
21
22 #ifdef _WIN32
23 // We use UTF-8 as the internal character encoding. On Windows,
24 // arguments passed to main() may not be encoded in UTF-8. In order
25 // to reliably detect encoding of command line arguments, we use an
26 // Windows API to obtain arguments, convert them to UTF-8, and then
27 // write them back to the Argv vector.
28 //
29 // There's probably other way to do the same thing (e.g. using
30 // wmain() instead of main()), but this way seems less intrusive
31 // than that.
32 std::string Banner = std::string(Argv[0]) + ": ";
33 ExitOnError ExitOnErr(Banner);
34
35 ExitOnErr(errorCodeToError(
36 sys::Process::GetArgumentVector(Args, makeArrayRef(Argv, Argc), Alloc)));
37
38 // GetArgumentVector doesn't terminate the vector with a nullptr.
39 // Do it to make it compatible with the real argv.
40 Args.push_back(nullptr);
41
42 Argc = Args.size() - 1;
43 Argv = Args.data();
44 #endif
45 }
46
47 InitLLVM::~InitLLVM() { llvm_shutdown(); }
2020 #include "llvm/LinkAllIR.h"
2121 #include "llvm/LinkAllPasses.h"
2222 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/InitLLVM.h"
2324 #include "llvm/Support/ManagedStatic.h"
2425 #include "llvm/Support/PluginLoader.h"
2526 #include "llvm/Support/PrettyStackTrace.h"
2627 #include "llvm/Support/Process.h"
27 #include "llvm/Support/Signals.h"
2828 #include "llvm/Support/TargetSelect.h"
2929 #include "llvm/Support/Valgrind.h"
3030 #include "llvm/Transforms/IPO/AlwaysInliner.h"
116116
117117 int main(int argc, char **argv) {
118118 #ifndef DEBUG_BUGPOINT
119 llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
120 llvm::PrettyStackTraceProgram X(argc, argv);
121 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
119 InitLLVM X(argc, argv);
122120 #endif
123121
124122 // Initialize passes
2727 #include "llvm/Object/MachO.h"
2828 #include "llvm/Support/CommandLine.h"
2929 #include "llvm/Support/FileSystem.h"
30 #include "llvm/Support/InitLLVM.h"
3031 #include "llvm/Support/ManagedStatic.h"
3132 #include "llvm/Support/Path.h"
32 #include "llvm/Support/PrettyStackTrace.h"
33 #include "llvm/Support/Signals.h"
3433 #include "llvm/Support/TargetSelect.h"
3534 #include "llvm/Support/ThreadPool.h"
3635 #include "llvm/Support/raw_ostream.h"
387386 } // namespace
388387
389388 int main(int argc, char **argv) {
390 llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
391 llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
392 llvm::llvm_shutdown_obj Shutdown;
389 InitLLVM X(argc, argv);
390
393391 void *P = (void *)(intptr_t)getOutputFileName;
394392 std::string SDKPath = llvm::sys::fs::getMainExecutable(argv[0], P);
395393 SDKPath = llvm::sys::path::parent_path(SDKPath);
4040 #include "llvm/Support/FileSystem.h"
4141 #include "llvm/Support/FormattedStream.h"
4242 #include "llvm/Support/Host.h"
43 #include "llvm/Support/InitLLVM.h"
4344 #include "llvm/Support/ManagedStatic.h"
4445 #include "llvm/Support/PluginLoader.h"
45 #include "llvm/Support/PrettyStackTrace.h"
46 #include "llvm/Support/Signals.h"
4746 #include "llvm/Support/SourceMgr.h"
4847 #include "llvm/Support/TargetRegistry.h"
4948 #include "llvm/Support/TargetSelect.h"
268267 // main - Entry point for the llc compiler.
269268 //
270269 int main(int argc, char **argv) {
271 sys::PrintStackTraceOnErrorSignal(argv[0]);
272 PrettyStackTraceProgram X(argc, argv);
270 InitLLVM X(argc, argv);
273271
274272 // Enable debug stream buffering.
275273 EnableDebugBuffering = true;
3939 #include "llvm/Support/Debug.h"
4040 #include "llvm/Support/DynamicLibrary.h"
4141 #include "llvm/Support/Format.h"
42 #include "llvm/Support/InitLLVM.h"
4243 #include "llvm/Support/ManagedStatic.h"
4344 #include "llvm/Support/MathExtras.h"
4445 #include "llvm/Support/Memory.h"
4546 #include "llvm/Support/MemoryBuffer.h"
4647 #include "llvm/Support/Path.h"
4748 #include "llvm/Support/PluginLoader.h"
48 #include "llvm/Support/PrettyStackTrace.h"
4949 #include "llvm/Support/Process.h"
5050 #include "llvm/Support/Program.h"
51 #include "llvm/Support/Signals.h"
5251 #include "llvm/Support/SourceMgr.h"
5352 #include "llvm/Support/TargetSelect.h"
5453 #include "llvm/Support/raw_ostream.h"
315314 // main Driver function
316315 //
317316 int main(int argc, char **argv, char * const *envp) {
318 sys::PrintStackTraceOnErrorSignal(argv[0]);
319 PrettyStackTraceProgram X(argc, argv);
320
321 atexit(llvm_shutdown); // Call llvm_shutdown() on exit.
317 InitLLVM X(argc, argv);
322318
323319 if (argc > 1)
324320 ExitOnErr.setBanner(std::string(argv[0]) + ": ");
1414 #include "llvm/ADT/StringSwitch.h"
1515 #include "llvm/ADT/Triple.h"
1616 #include "llvm/IR/LLVMContext.h"
17 #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h"
18 #include "llvm/ToolDrivers/llvm-lib/LibDriver.h"
1917 #include "llvm/Object/Archive.h"
2018 #include "llvm/Object/ArchiveWriter.h"
2119 #include "llvm/Object/MachO.h"
2523 #include "llvm/Support/Errc.h"
2624 #include "llvm/Support/FileSystem.h"
2725 #include "llvm/Support/Format.h"
26 #include "llvm/Support/InitLLVM.h"
2827 #include "llvm/Support/LineIterator.h"
29 #include "llvm/Support/ManagedStatic.h"
3028 #include "llvm/Support/MemoryBuffer.h"
3129 #include "llvm/Support/Path.h"
32 #include "llvm/Support/PrettyStackTrace.h"
3330 #include "llvm/Support/Process.h"
34 #include "llvm/Support/Signals.h"
3531 #include "llvm/Support/StringSaver.h"
3632 #include "llvm/Support/TargetSelect.h"
3733 #include "llvm/Support/ToolOutputFile.h"
3834 #include "llvm/Support/raw_ostream.h"
35 #include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h"
36 #include "llvm/ToolDrivers/llvm-lib/LibDriver.h"
3937
4038 #if !defined(_MSC_VER) && !defined(__MINGW32__)
4139 #include
948946 }
949947
950948 int main(int argc, char **argv) {
949 InitLLVM X(argc, argv);
951950 ToolName = argv[0];
952 // Print a stack trace if we signal out.
953 sys::PrintStackTraceOnErrorSignal(argv[0]);
954 PrettyStackTraceProgram X(argc, argv);
955 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
956951
957952 llvm::InitializeAllTargetInfos();
958953 llvm::InitializeAllTargetMCs();
2121 #include "llvm/IR/Verifier.h"
2222 #include "llvm/Support/CommandLine.h"
2323 #include "llvm/Support/FileSystem.h"
24 #include "llvm/Support/InitLLVM.h"
2425 #include "llvm/Support/ManagedStatic.h"
25 #include "llvm/Support/PrettyStackTrace.h"
26 #include "llvm/Support/Signals.h"
2726 #include "llvm/Support/SourceMgr.h"
2827 #include "llvm/Support/SystemUtils.h"
2928 #include "llvm/Support/ToolOutputFile.h"
9291 }
9392
9493 int main(int argc, char **argv) {
95 // Print a stack trace if we signal out.
96 sys::PrintStackTraceOnErrorSignal(argv[0]);
97 PrettyStackTraceProgram X(argc, argv);
94 InitLLVM X(argc, argv);
9895 LLVMContext Context;
99 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
10096 cl::ParseCommandLineOptions(argc, argv, "llvm .ll -> .bc assembler\n");
10197
10298 // Parse the file now...
3232 #include "llvm/Bitcode/LLVMBitCodes.h"
3333 #include "llvm/Support/CommandLine.h"
3434 #include "llvm/Support/Format.h"
35 #include "llvm/Support/InitLLVM.h"
3536 #include "llvm/Support/ManagedStatic.h"
3637 #include "llvm/Support/MemoryBuffer.h"
37 #include "llvm/Support/PrettyStackTrace.h"
3838 #include "llvm/Support/SHA1.h"
39 #include "llvm/Support/Signals.h"
4039 #include "llvm/Support/raw_ostream.h"
4140 using namespace llvm;
4241
963962
964963
965964 int main(int argc, char **argv) {
966 // Print a stack trace if we signal out.
967 sys::PrintStackTraceOnErrorSignal(argv[0]);
968 PrettyStackTraceProgram X(argc, argv);
969 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
965 InitLLVM X(argc, argv);
970966 cl::ParseCommandLineOptions(argc, argv, "llvm-bcanalyzer file analyzer\n");
971
972967 return AnalyzeBitcode();
973968 }
1313 #include "llvm/ADT/StringRef.h"
1414 #include "llvm/ADT/StringSwitch.h"
1515 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/InitLLVM.h"
1617 #include "llvm/Support/ManagedStatic.h"
1718 #include "llvm/Support/Path.h"
18 #include "llvm/Support/PrettyStackTrace.h"
1919 #include "llvm/Support/Process.h"
20 #include "llvm/Support/Signals.h"
2120 #include "llvm/Support/raw_ostream.h"
2221 #include
2322
5857 }
5958
6059 int main(int argc, const char **argv) {
61 // Print a stack trace if we signal out.
62 sys::PrintStackTraceOnErrorSignal(argv[0]);
63 PrettyStackTraceProgram X(argc, argv);
64 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
60 InitLLVM X(argc, argv);
6561
6662 // If argv[0] is or ends with 'gcov', always be gcov compatible
6763 if (sys::path::stem(argv[0]).endswith_lower("gcov"))
1919 #include "llvm/Option/Option.h"
2020 #include "llvm/Support/BinaryStreamError.h"
2121 #include "llvm/Support/Error.h"
22 #include "llvm/Support/InitLLVM.h"
2223 #include "llvm/Support/ManagedStatic.h"
2324 #include "llvm/Support/Path.h"
2425 #include "llvm/Support/PrettyStackTrace.h"
6263 public:
6364 CvtResOptTable() : OptTable(InfoTable, true) {}
6465 };
65
66 static ExitOnError ExitOnErr;
6766 }
6867
6968 LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
9493 return std::move(EC.get());
9594 }
9695
97 int main(int argc_, const char *argv_[]) {
98 sys::PrintStackTraceOnErrorSignal(argv_[0]);
99 PrettyStackTraceProgram X(argc_, argv_);
100
101 ExitOnErr.setBanner("llvm-cvtres: ");
102
103 SmallVector argv;
104 SpecificBumpPtrAllocator ArgAllocator;
105 ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
106 argv, makeArrayRef(argv_, argc_), ArgAllocator)));
107
108 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
96 int main(int Argc, const char **Argv) {
97 InitLLVM X(Argc, Argv);
10998
11099 CvtResOptTable T;
111100 unsigned MAI, MAC;
112 ArrayRef ArgsArr = makeArrayRef(argv_ + 1, argc_);
101 ArrayRef ArgsArr = makeArrayRef(Argv + 1, Argc - 1);
113102 opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
114103
115104 if (InputArgs.hasArg(OPT_HELP)) {
1919 #include "llvm/Support/Debug.h"
2020 #include "llvm/Support/Endian.h"
2121 #include "llvm/Support/FileSystem.h"
22 #include "llvm/Support/ManagedStatic.h"
23 #include "llvm/Support/PrettyStackTrace.h"
24 #include "llvm/Support/Signals.h"
22 #include "llvm/Support/InitLLVM.h"
2523 #include "llvm/Support/TargetRegistry.h"
2624 #include "llvm/Support/TargetSelect.h"
2725 #include "llvm/Support/raw_ostream.h"
532530 }
533531
534532 int main(int argc, const char *argv[]) {
535 sys::PrintStackTraceOnErrorSignal(argv[0]);
536 PrettyStackTraceProgram X(argc, argv);
537 llvm_shutdown_obj Y;
533 InitLLVM X(argc, argv);
538534
539535 // Initialize targets.
540536 llvm::InitializeAllTargetInfos();
88
99 #include "llvm/Demangle/Demangle.h"
1010 #include "llvm/Support/CommandLine.h"
11 #include "llvm/Support/PrettyStackTrace.h"
12 #include "llvm/Support/Signals.h"
11 #include "llvm/Support/InitLLVM.h"
1312 #include "llvm/Support/raw_ostream.h"
1413 #include
1514 #include
8079 }
8180
8281 int main(int argc, char **argv) {
83 sys::PrintStackTraceOnErrorSignal(argv[0]);
84 PrettyStackTraceProgram X(argc, argv);
82 InitLLVM X(argc, argv);
8583
8684 cl::ParseCommandLineOptions(argc, argv, "llvm symbol undecoration tool\n");
8785
1515 //
1616 //===----------------------------------------------------------------------===//
1717
18 #include "llvm/IR/LLVMContext.h"
1918 #include "llvm/Bitcode/BitcodeReader.h"
2019 #include "llvm/IR/AssemblyAnnotationWriter.h"
2120 #include "llvm/IR/DebugInfo.h"
2221 #include "llvm/IR/DiagnosticInfo.h"
2322 #include "llvm/IR/DiagnosticPrinter.h"
2423 #include "llvm/IR/IntrinsicInst.h"
24 #include "llvm/IR/LLVMContext.h"
2525 #include "llvm/IR/Module.h"
2626 #include "llvm/IR/Type.h"
2727 #include "llvm/Support/CommandLine.h"
2828 #include "llvm/Support/Error.h"
2929 #include "llvm/Support/FileSystem.h"
3030 #include "llvm/Support/FormattedStream.h"
31 #include "llvm/Support/ManagedStatic.h"
31 #include "llvm/Support/InitLLVM.h"
3232 #include "llvm/Support/MemoryBuffer.h"
33 #include "llvm/Support/PrettyStackTrace.h"
34 #include "llvm/Support/Signals.h"
3533 #include "llvm/Support/ToolOutputFile.h"
3634 #include
3735 using namespace llvm;
161159 }
162160
163161 int main(int argc, char **argv) {
164 // Print a stack trace if we signal out.
165 sys::PrintStackTraceOnErrorSignal(argv[0]);
166 PrettyStackTraceProgram X(argc, argv);
162 InitLLVM X(argc, argv);
167163
168164 ExitOnErr.setBanner(std::string(argv[0]) + ": error: ");
169165
170166 LLVMContext Context;
171 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
172167 Context.setDiagnosticHandler(
173168 llvm::make_unique(argv[0]));
174169 cl::ParseCommandLineOptions(argc, argv, "llvm .bc -> .ll disassembler\n");
2121 #include "llvm/Support/CommandLine.h"
2222 #include "llvm/Support/Debug.h"
2323 #include "llvm/Support/Format.h"
24 #include "llvm/Support/ManagedStatic.h"
24 #include "llvm/Support/InitLLVM.h"
2525 #include "llvm/Support/MemoryBuffer.h"
2626 #include "llvm/Support/Path.h"
27 #include "llvm/Support/PrettyStackTrace.h"
2827 #include "llvm/Support/Regex.h"
29 #include "llvm/Support/Signals.h"
3028 #include "llvm/Support/TargetSelect.h"
3129 #include "llvm/Support/ToolOutputFile.h"
3230 #include "llvm/Support/raw_ostream.h"
509507 }
510508
511509 int main(int argc, char **argv) {
512 // Print a stack trace if we signal out.
513 sys::PrintStackTraceOnErrorSignal(argv[0]);
514 PrettyStackTraceProgram X(argc, argv);
515 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
510 InitLLVM X(argc, argv);
516511
517512 llvm::InitializeAllTargetInfos();
518513 llvm::InitializeAllTargetMCs();
2424 #include "llvm/Support/CommandLine.h"
2525 #include "llvm/Support/Error.h"
2626 #include "llvm/Support/FileSystem.h"
27 #include "llvm/Support/ManagedStatic.h"
28 #include "llvm/Support/PrettyStackTrace.h"
27 #include "llvm/Support/InitLLVM.h"
2928 #include "llvm/Support/Regex.h"
30 #include "llvm/Support/Signals.h"
3129 #include "llvm/Support/SourceMgr.h"
3230 #include "llvm/Support/SystemUtils.h"
3331 #include "llvm/Support/ToolOutputFile.h"
112110 cl::init(false), cl::Hidden);
113111
114112 int main(int argc, char **argv) {
115 // Print a stack trace if we signal out.
116 sys::PrintStackTraceOnErrorSignal(argv[0]);
117 PrettyStackTraceProgram X(argc, argv);
113 InitLLVM X(argc, argv);
118114
119115 LLVMContext Context;
120 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
121116 cl::ParseCommandLineOptions(argc, argv, "llvm extractor\n");
122117
123118 // Use lazy loading, since we only care about selected global values.
2323 #include "llvm/Support/CommandLine.h"
2424 #include "llvm/Support/Debug.h"
2525 #include "llvm/Support/Host.h"
26 #include "llvm/Support/ManagedStatic.h"
26 #include "llvm/Support/InitLLVM.h"
2727 #include "llvm/Support/MemoryBuffer.h"
28 #include "llvm/Support/PrettyStackTrace.h"
29 #include "llvm/Support/Signals.h"
3028 #include "llvm/Support/SourceMgr.h"
3129 #include "llvm/Support/TargetSelect.h"
3230 #include "llvm/Support/raw_ostream.h"
177175 cl::Required);
178176
179177 int main(int argc, char **argv) {
180 // Print a stack trace if we signal out.
181 sys::PrintStackTraceOnErrorSignal(argv[0]);
182 PrettyStackTraceProgram X(argc, argv);
183 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
184
178 InitLLVM X(argc, argv);
185179 cl::ParseCommandLineOptions(argc, argv, "llvm jit event listener test utility\n");
186180
187181 JitEventListenerTest Test;
188
189182 Test.ProcessInput(InputFilename);
190
191183 return 0;
192184 }
2525 #include "llvm/Linker/Linker.h"
2626 #include "llvm/Support/CommandLine.h"
2727 #include "llvm/Support/FileSystem.h"
28 #include "llvm/Support/ManagedStatic.h"
28 #include "llvm/Support/InitLLVM.h"
2929 #include "llvm/Support/Path.h"
30 #include "llvm/Support/PrettyStackTrace.h"
31 #include "llvm/Support/Signals.h"
3230 #include "llvm/Support/SourceMgr.h"
3331 #include "llvm/Support/SystemUtils.h"
3432 #include "llvm/Support/ToolOutputFile.h"
344342 }
345343
346344 int main(int argc, char **argv) {
347 // Print a stack trace if we signal out.
348 sys::PrintStackTraceOnErrorSignal(argv[0]);
349 PrettyStackTraceProgram X(argc, argv);
350
345 InitLLVM X(argc, argv);
351346 ExitOnErr.setBanner(std::string(argv[0]) + ": ");
352347
353348 LLVMContext Context;
354349 Context.setDiagnosticHandler(
355350 llvm::make_unique(), true);
356 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
357351 cl::ParseCommandLineOptions(argc, argv, "llvm linker\n");
358352
359353 if (!DisableDITypeMap)
3939 #include "llvm/Support/ErrorHandling.h"
4040 #include "llvm/Support/ErrorOr.h"
4141 #include "llvm/Support/FileSystem.h"
42 #include "llvm/Support/ManagedStatic.h"
42 #include "llvm/Support/InitLLVM.h"
4343 #include "llvm/Support/MemoryBuffer.h"
4444 #include "llvm/Support/Path.h"
45 #include "llvm/Support/PrettyStackTrace.h"
46 #include "llvm/Support/Signals.h"
4745 #include "llvm/Support/SourceMgr.h"
4846 #include "llvm/Support/TargetSelect.h"
4947 #include "llvm/Support/ToolOutputFile.h"
798796 } // end namespace thinlto
799797
800798 int main(int argc, char **argv) {
801 // Print a stack trace if we signal out.
802 sys::PrintStackTraceOnErrorSignal(argv[0]);
803 PrettyStackTraceProgram X(argc, argv);
804
805 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
799 InitLLVM X(argc, argv);
806800 cl::ParseCommandLineOptions(argc, argv, "llvm LTO linker\n");
807801
808802 if (OptLevel < '0' || OptLevel > '3')
3030 #include "llvm/Support/FileUtilities.h"
3131 #include "llvm/Support/FormattedStream.h"
3232 #include "llvm/Support/Host.h"
33 #include "llvm/Support/ManagedStatic.h"
33 #include "llvm/Support/InitLLVM.h"
3434 #include "llvm/Support/MemoryBuffer.h"
35 #include "llvm/Support/PrettyStackTrace.h"
36 #include "llvm/Support/Signals.h"
3735 #include "llvm/Support/SourceMgr.h"
3836 #include "llvm/Support/TargetRegistry.h"
3937 #include "llvm/Support/TargetSelect.h"
293291 }
294292
295293 int main(int argc, char **argv) {
296 // Print a stack trace if we signal out.
297 sys::PrintStackTraceOnErrorSignal(argv[0]);
298 PrettyStackTraceProgram X(argc, argv);
299 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
294 InitLLVM X(argc, argv);
300295
301296 // Initialize targets and assembly printers/parsers.
302297 llvm::InitializeAllTargetInfos();
4040 #include "llvm/Support/CommandLine.h"
4141 #include "llvm/Support/ErrorOr.h"
4242 #include "llvm/Support/FileSystem.h"
43 #include "llvm/Support/InitLLVM.h"
4344 #include "llvm/Support/MemoryBuffer.h"
44 #include "llvm/Support/PrettyStackTrace.h"
45 #include "llvm/Support/Signals.h"
4645 #include "llvm/Support/SourceMgr.h"
4746 #include "llvm/Support/TargetRegistry.h"
4847 #include "llvm/Support/TargetSelect.h"
275274 } // end of anonymous namespace
276275
277276 int main(int argc, char **argv) {
278 sys::PrintStackTraceOnErrorSignal(argv[0]);
279 PrettyStackTraceProgram X(argc, argv);
280 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
277 InitLLVM X(argc, argv);
281278
282279 // Initialize targets and assembly parsers.
283280 llvm::InitializeAllTargetInfos();
1616 #include "llvm/Option/Option.h"
1717 #include "llvm/Support/Error.h"
1818 #include "llvm/Support/FileOutputBuffer.h"
19 #include "llvm/Support/InitLLVM.h"
1920 #include "llvm/Support/ManagedStatic.h"
2021 #include "llvm/Support/MemoryBuffer.h"
2122 #include "llvm/Support/Path.h"
6061 public:
6162 CvtResOptTable() : OptTable(InfoTable, true) {}
6263 };
63
64 static ExitOnError ExitOnErr;
6564 } // namespace
6665
6766 LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg) {
8584 });
8685 }
8786
88 int main(int argc, const char **argv) {
89 sys::PrintStackTraceOnErrorSignal(argv[0]);
90 PrettyStackTraceProgram X(argc, argv);
91
92 ExitOnErr.setBanner("llvm-mt: ");
93
94 SmallVector argv_buf;
95 SpecificBumpPtrAllocator ArgAllocator;
96 ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
97 argv_buf, makeArrayRef(argv, argc), ArgAllocator)));
98 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
87 int main(int Argc, const char **Argv) {
88 InitLLVM X(Argc, Argv);
9989
10090 CvtResOptTable T;
10191 unsigned MAI, MAC;
102 ArrayRef ArgsArr = makeArrayRef(argv + 1, argc);
92 ArrayRef ArgsArr = makeArrayRef(Argv + 1, Argc - 1);
10393 opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
10494
10595 for (auto *Arg : InputArgs.filtered(OPT_INPUT)) {
3232 #include "llvm/Support/CommandLine.h"
3333 #include "llvm/Support/FileSystem.h"
3434 #include "llvm/Support/Format.h"
35 #include "llvm/Support/ManagedStatic.h"
35 #include "llvm/Support/InitLLVM.h"
3636 #include "llvm/Support/MemoryBuffer.h"
37 #include "llvm/Support/PrettyStackTrace.h"
3837 #include "llvm/Support/Program.h"
3938 #include "llvm/Support/Signals.h"
4039 #include "llvm/Support/TargetSelect.h"
20152014 }
20162015
20172016 int main(int argc, char **argv) {
2018 // Print a stack trace if we signal out.
2019 sys::PrintStackTraceOnErrorSignal(argv[0]);
2020 PrettyStackTraceProgram X(argc, argv);
2021
2022 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
2017 InitLLVM X(argc, argv);
20232018 cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n");
20242019
20252020 // llvm-nm only reads binary files.
2323 #include "llvm/Support/ErrorHandling.h"
2424 #include "llvm/Support/ErrorOr.h"
2525 #include "llvm/Support/FileOutputBuffer.h"
26 #include "llvm/Support/ManagedStatic.h"
27 #include "llvm/Support/PrettyStackTrace.h"
28 #include "llvm/Support/Signals.h"
26 #include "llvm/Support/InitLLVM.h"
2927 #include "llvm/Support/raw_ostream.h"
3028 #include
3129 #include
326324 }
327325
328326 int main(int argc, char **argv) {
329 // Print a stack trace if we signal out.
330 sys::PrintStackTraceOnErrorSignal(argv[0]);
331 PrettyStackTraceProgram X(argc, argv);
332 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
327 InitLLVM X(argc, argv);
333328 cl::ParseCommandLineOptions(argc, argv, "llvm objcopy utility\n");
334329 ToolName = argv[0];
335330 if (InputFilename.empty()) {
5050 #include "llvm/Support/Format.h"
5151 #include "llvm/Support/GraphWriter.h"
5252 #include "llvm/Support/Host.h"
53 #include "llvm/Support/ManagedStatic.h"
53 #include "llvm/Support/InitLLVM.h"
5454 #include "llvm/Support/MemoryBuffer.h"
55 #include "llvm/Support/PrettyStackTrace.h"
56 #include "llvm/Support/Signals.h"
5755 #include "llvm/Support/SourceMgr.h"
5856 #include "llvm/Support/TargetRegistry.h"
5957 #include "llvm/Support/TargetSelect.h"
21782176 }
21792177
21802178 int main(int argc, char **argv) {
2181 // Print a stack trace if we signal out.
2182 sys::PrintStackTraceOnErrorSignal(argv[0]);
2183 PrettyStackTraceProgram X(argc, argv);
2184 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
2179 InitLLVM X(argc, argv);
21852180
21862181 // Initialize targets and assembly printers/parsers.
21872182 llvm::InitializeAllTargetInfos();
1313 ///
1414 //===----------------------------------------------------------------------===//
1515
16 #include "llvm/Demangle/Demangle.h"
1617 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Demangle/Demangle.h"
1818 #include "llvm/Support/Error.h"
1919 #include "llvm/Support/ErrorOr.h"
2020 #include "llvm/Support/FileSystem.h"
2121 #include "llvm/Support/Format.h"
22 #include "llvm/Support/InitLLVM.h"
2223 #include "llvm/Support/LineIterator.h"
23 #include "llvm/Support/FileSystem.h"
2424 #include "llvm/Support/MemoryBuffer.h"
2525 #include "llvm/Support/Path.h"
2626 #include "llvm/Support/Program.h"
27 #include "llvm/Support/YAMLTraits.h"
2728 #include "llvm/Support/raw_ostream.h"
28 #include "llvm/Support/Signals.h"
29 #include "llvm/Support/YAMLTraits.h"
3029 #include
3130 #include
3231 #include
505504 }
506505
507506 int main(int argc, const char **argv) {
508 sys::PrintStackTraceOnErrorSignal(argv[0]);
507 InitLLVM X(argc, argv);
509508
510509 cl::HideUnrelatedOptions(OptReportCategory);
511510 cl::ParseCommandLineOptions(
7272 #include "llvm/Support/FileOutputBuffer.h"
7373 #include "llvm/Support/FileSystem.h"
7474 #include "llvm/Support/Format.h"
75 #include "llvm/Support/InitLLVM.h"
7576 #include "llvm/Support/LineIterator.h"
7677 #include "llvm/Support/ManagedStatic.h"
7778 #include "llvm/Support/MemoryBuffer.h"
8283 #include "llvm/Support/ScopedPrinter.h"
8384 #include "llvm/Support/Signals.h"
8485 #include "llvm/Support/raw_ostream.h"
85
8686
8787 using namespace llvm;
8888 using namespace llvm::codeview;
12041204 Chunks.push_back(opts::ModuleSubsection::All);
12051205 }
12061206
1207 int main(int argc_, const char *argv_[]) {
1208 // Print a stack trace if we signal out.
1209 sys::PrintStackTraceOnErrorSignal(argv_[0]);
1210 PrettyStackTraceProgram X(argc_, argv_);
1211
1207 int main(int Argc, const char **Argv) {
1208 InitLLVM X(Argc, Argv);
12121209 ExitOnErr.setBanner("llvm-pdbutil: ");
12131210
1214 SmallVector argv;
1215 SpecificBumpPtrAllocator ArgAllocator;
1216 ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
1217 argv, makeArrayRef(argv_, argc_), ArgAllocator)));
1218
1219 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
1220
1221 cl::ParseCommandLineOptions(argv.size(), argv.data(), "LLVM PDB Dumper\n");
1211 cl::ParseCommandLineOptions(Argc, Argv, "LLVM PDB Dumper\n");
12221212
12231213 if (opts::BytesSubcommand) {
12241214 if (!parseRange(opts::bytes::DumpBlockRangeOpt,
2323 #include "llvm/Support/Errc.h"
2424 #include "llvm/Support/FileSystem.h"
2525 #include "llvm/Support/Format.h"
26 #include "llvm/Support/ManagedStatic.h"
26 #include "llvm/Support/InitLLVM.h"
2727 #include "llvm/Support/MemoryBuffer.h"
2828 #include "llvm/Support/Path.h"
29 #include "llvm/Support/PrettyStackTrace.h"
30 #include "llvm/Support/Signals.h"
3129 #include "llvm/Support/ThreadPool.h"
3230 #include "llvm/Support/raw_ostream.h"
3331 #include
801799 }
802800
803801 int main(int argc, const char *argv[]) {
804 // Print a stack trace if we signal out.
805 sys::PrintStackTraceOnErrorSignal(argv[0]);
806 PrettyStackTraceProgram X(argc, argv);
807 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
802 InitLLVM X(argc, argv);
808803
809804 StringRef ProgName(sys::path::filename(argv[0]));
810805 if (argc > 1) {
2020 #include "llvm/Option/ArgList.h"
2121 #include "llvm/Support/Error.h"
2222 #include "llvm/Support/FileSystem.h"
23 #include "llvm/Support/InitLLVM.h"
2324 #include "llvm/Support/ManagedStatic.h"
2425 #include "llvm/Support/MemoryBuffer.h"
2526 #include "llvm/Support/PrettyStackTrace.h"
7576
7677 } // anonymous namespace
7778
78 int main(int argc_, const char *argv_[]) {
79 sys::PrintStackTraceOnErrorSignal(argv_[0]);
80 PrettyStackTraceProgram X(argc_, argv_);
81
79 int main(int Argc, const char **Argv) {
80 InitLLVM X(Argc, Argv);
8281 ExitOnErr.setBanner("llvm-rc: ");
83
84 SmallVector argv;
85 SpecificBumpPtrAllocator ArgAllocator;
86 ExitOnErr(errorCodeToError(sys::Process::GetArgumentVector(
87 argv, makeArrayRef(argv_, argc_), ArgAllocator)));
88
89 llvm_shutdown_obj Y;
9082
9183 RcOptTable T;
9284 unsigned MAI, MAC;
93 ArrayRef ArgsArr = makeArrayRef(argv_ + 1, argc_);
85 ArrayRef ArgsArr = makeArrayRef(Argv + 1, Argc - 1);
9486 opt::InputArgList InputArgs = T.ParseArgs(ArgsArr, MAI, MAC);
9587
9688 // The tool prints nothing when invoked with no command-line arguments.
3434 #include "llvm/Support/Debug.h"
3535 #include "llvm/Support/FileSystem.h"
3636 #include "llvm/Support/FormatVariadic.h"
37 #include "llvm/Support/ManagedStatic.h"
37 #include "llvm/Support/InitLLVM.h"
3838 #include "llvm/Support/Path.h"
39 #include "llvm/Support/PrettyStackTrace.h"
4039 #include "llvm/Support/ScopedPrinter.h"
41 #include "llvm/Support/Signals.h"
4240 #include "llvm/Support/TargetRegistry.h"
4341
4442 using namespace llvm;
555553 }
556554
557555 int main(int argc, const char *argv[]) {
558 StringRef ToolName = argv[0];
559 sys::PrintStackTraceOnErrorSignal(ToolName);
560 PrettyStackTraceProgram X(argc, argv);
561 llvm_shutdown_obj Y;
556 InitLLVM X(argc, argv);
562557
563558 // Register the target printer for --version.
564559 cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion);
565560
566561 opts::WideOutput.setHiddenFlag(cl::Hidden);
567562
568 if (sys::path::stem(ToolName).find("readelf") != StringRef::npos)
563 if (sys::path::stem(argv[0]).find("readelf") != StringRef::npos)
569564 opts::Output = opts::GNU;
570565
571566 cl::ParseCommandLineOptions(argc, argv, "LLVM Object Reader\n");
2626 #include "llvm/Object/SymbolSize.h"
2727 #include "llvm/Support/CommandLine.h"
2828 #include "llvm/Support/DynamicLibrary.h"
29 #include "llvm/Support/ManagedStatic.h"
29 #include "llvm/Support/InitLLVM.h"
3030 #include "llvm/Support/Memory.h"
3131 #include "llvm/Support/MemoryBuffer.h"
32 #include "llvm/Support/PrettyStackTrace.h"
33 #include "llvm/Support/Signals.h"
3432 #include "llvm/Support/TargetRegistry.h"
3533 #include "llvm/Support/TargetSelect.h"
3634 #include "llvm/Support/raw_ostream.h"
735733 }
736734
737735 int main(int argc, char **argv) {
738 sys::PrintStackTraceOnErrorSignal(argv[0]);
739 PrettyStackTraceProgram X(argc, argv);
740
736 InitLLVM X(argc, argv);
741737 ProgramName = argv[0];
742 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
743738
744739 llvm::InitializeAllTargetInfos();
745740 llvm::InitializeAllTargetMCs();
2222 #include "llvm/Support/CommandLine.h"
2323 #include "llvm/Support/FileSystem.h"
2424 #include "llvm/Support/Format.h"
25 #include "llvm/Support/ManagedStatic.h"
25 #include "llvm/Support/InitLLVM.h"
2626 #include "llvm/Support/MemoryBuffer.h"
27 #include "llvm/Support/PrettyStackTrace.h"
28 #include "llvm/Support/Signals.h"
2927 #include "llvm/Support/raw_ostream.h"
3028 #include
3129 #include
853851 }
854852
855853 int main(int argc, char **argv) {
856 // Print a stack trace if we signal out.
857 sys::PrintStackTraceOnErrorSignal(argv[0]);
858 PrettyStackTraceProgram X(argc, argv);
859
860 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
854 InitLLVM X(argc, argv);
861855 cl::ParseCommandLineOptions(argc, argv, "llvm object size dumper\n");
862856
863857 ToolName = argv[0];
1515 #include "llvm/Support/CommandLine.h"
1616 #include "llvm/Support/Error.h"
1717 #include "llvm/Support/Format.h"
18 #include "llvm/Support/InitLLVM.h"
1819 #include "llvm/Support/MemoryBuffer.h"
19 #include "llvm/Support/PrettyStackTrace.h"
2020 #include "llvm/Support/Program.h"
21 #include "llvm/Support/Signals.h"
2221 #include
2322 #include
2423
9392 }
9493
9594 int main(int argc, char **argv) {
96 sys::PrintStackTraceOnErrorSignal(argv[0]);
97 PrettyStackTraceProgram X(argc, argv);
95 InitLLVM X(argc, argv);
9896
9997 cl::ParseCommandLineOptions(argc, argv, "llvm string dumper\n");
10098 if (MinLength == 0) {
2121 #include "llvm/Support/CommandLine.h"
2222 #include "llvm/Support/Debug.h"
2323 #include "llvm/Support/FileSystem.h"
24 #include "llvm/Support/ManagedStatic.h"
24 #include "llvm/Support/InitLLVM.h"
2525 #include "llvm/Support/Path.h"
26 #include "llvm/Support/PrettyStackTrace.h"
27 #include "llvm/Support/Signals.h"
2826 #include "llvm/Support/raw_ostream.h"
2927 #include
3028 #include
144142 }
145143
146144 int main(int argc, char **argv) {
147 // Print stack trace if we signal out.
148 sys::PrintStackTraceOnErrorSignal(argv[0]);
149 PrettyStackTraceProgram X(argc, argv);
150 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
145 InitLLVM X(argc, argv);
151146
152147 llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
153148
66 //
77 //===----------------------------------------------------------------------===//
88
9 #include "obj2yaml.h"
910 #include "Error.h"
10 #include "obj2yaml.h"
1111 #include "llvm/Object/Archive.h"
1212 #include "llvm/Object/COFF.h"
1313 #include "llvm/Support/CommandLine.h"
14 #include "llvm/Support/ManagedStatic.h"
15 #include "llvm/Support/PrettyStackTrace.h"
16 #include "llvm/Support/Signals.h"
14 #include "llvm/Support/InitLLVM.h"
1715
1816 using namespace llvm;
1917 using namespace llvm::object;
6159 cl::init("-"));
6260
6361 int main(int argc, char *argv[]) {
62 InitLLVM X(argc, argv);
6463 cl::ParseCommandLineOptions(argc, argv);
65 sys::PrintStackTraceOnErrorSignal(argv[0]);
66 PrettyStackTraceProgram X(argc, argv);
67 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
6864
6965 if (Error Err = dumpInput(InputFilename)) {
7066 reportError(InputFilename, std::move(Err));
4040 #include "llvm/Support/Debug.h"
4141 #include "llvm/Support/FileSystem.h"
4242 #include "llvm/Support/Host.h"
43 #include "llvm/Support/ManagedStatic.h"
43 #include "llvm/Support/InitLLVM.h"
4444 #include "llvm/Support/PluginLoader.h"
45 #include "llvm/Support/PrettyStackTrace.h"
46 #include "llvm/Support/Signals.h"
4745 #include "llvm/Support/SourceMgr.h"
4846 #include "llvm/Support/SystemUtils.h"
4947 #include "llvm/Support/TargetRegistry.h"
366364 // main for opt
367365 //
368366 int main(int argc, char **argv) {
369 sys::PrintStackTraceOnErrorSignal(argv[0]);
370 llvm::PrettyStackTraceProgram X(argc, argv);
367 InitLLVM X(argc, argv);
371368
372369 // Enable debug stream buffering.
373370 EnableDebugBuffering = true;
374371
375 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
376372 LLVMContext Context;
377373
378374 InitializeAllTargets();
4141 #include "llvm/Support/ErrorHandling.h"
4242 #include "llvm/Support/FileSystem.h"
4343 #include "llvm/Support/FileUtilities.h"
44 #include "llvm/Support/ManagedStatic.h"
44 #include "llvm/Support/InitLLVM.h"
4545 #include "llvm/Support/MemoryBuffer.h"
46 #include "llvm/Support/PrettyStackTrace.h"
47 #include "llvm/Support/Signals.h"
4846 #include "llvm/Support/SourceMgr.h"
4947 #include "llvm/Support/SystemUtils.h"
5048 #include "llvm/Support/raw_ostream.h"
526524 }
527525
528526 int main(int argc, char **argv) {
529 sys::PrintStackTraceOnErrorSignal(argv[0]);
530 llvm::PrettyStackTraceProgram X(argc, argv);
527 InitLLVM X(argc, argv);
531528
532529 // Enable debug stream buffering.
533530 EnableDebugBuffering = true;
534531
535 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
536532 LLVMContext Context;
537533
538534 cl::ParseCommandLineOptions(argc, argv,
1818 #include "llvm/ObjectYAML/ObjectYAML.h"
1919 #include "llvm/Support/CommandLine.h"
2020 #include "llvm/Support/FileSystem.h"
21 #include "llvm/Support/ManagedStatic.h"
21 #include "llvm/Support/InitLLVM.h"
2222 #include "llvm/Support/MemoryBuffer.h"
23 #include "llvm/Support/PrettyStackTrace.h"
24 #include "llvm/Support/Signals.h"
2523 #include "llvm/Support/ToolOutputFile.h"
2624 #include "llvm/Support/YAMLTraits.h"
2725 #include "llvm/Support/raw_ostream.h"
6967 }
7068
7169 int main(int argc, char **argv) {
70 InitLLVM X(argc, argv);
7271 cl::ParseCommandLineOptions(argc, argv);
73 sys::PrintStackTraceOnErrorSignal(argv[0]);
74 PrettyStackTraceProgram X(argc, argv);
75 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
7672
7773 if (OutputFilename.empty())
7874 OutputFilename = "-";
2020 #include "llvm/ADT/StringMap.h"
2121 #include "llvm/ADT/StringSet.h"
2222 #include "llvm/Support/CommandLine.h"
23 #include "llvm/Support/InitLLVM.h"
2324 #include "llvm/Support/MemoryBuffer.h"
24 #include "llvm/Support/PrettyStackTrace.h"
2525 #include "llvm/Support/Regex.h"
26 #include "llvm/Support/Signals.h"
2726 #include "llvm/Support/SourceMgr.h"
2827 #include "llvm/Support/raw_ostream.h"
2928 #include
13591358 }
13601359
13611360 int main(int argc, char **argv) {
1362 sys::PrintStackTraceOnErrorSignal(argv[0]);
1363 PrettyStackTraceProgram X(argc, argv);
1361 InitLLVM X(argc, argv);
13641362 cl::ParseCommandLineOptions(argc, argv);
13651363
13661364 if (!ValidateCheckPrefixes()) {