Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:31

0001 //===- InitLLVM.h -----------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_SUPPORT_INITLLVM_H
0010 #define LLVM_SUPPORT_INITLLVM_H
0011 
0012 #include "llvm/ADT/SmallVector.h"
0013 #include "llvm/Support/Allocator.h"
0014 #include "llvm/Support/PrettyStackTrace.h"
0015 #include <optional>
0016 
0017 // The main() functions in typical LLVM tools start with InitLLVM which does
0018 // the following one-time initializations:
0019 //
0020 //  1. Setting up a signal handler so that pretty stack trace is printed out
0021 //     if a process crashes. A signal handler that exits when a failed write to
0022 //     a pipe occurs may optionally be installed: this is on-by-default.
0023 //
0024 //  2. Set up the global new-handler which is called when a memory allocation
0025 //     attempt fails.
0026 //
0027 //  3. If running on Windows, obtain command line arguments using a
0028 //     multibyte character-aware API and convert arguments into UTF-8
0029 //     encoding, so that you can assume that command line arguments are
0030 //     always encoded in UTF-8 on any platform.
0031 //
0032 // InitLLVM calls llvm_shutdown() on destruction, which cleans up
0033 // ManagedStatic objects.
0034 namespace llvm {
0035 class InitLLVM {
0036 public:
0037   InitLLVM(int &Argc, const char **&Argv,
0038            bool InstallPipeSignalExitHandler = true);
0039   InitLLVM(int &Argc, char **&Argv, bool InstallPipeSignalExitHandler = true)
0040       : InitLLVM(Argc, const_cast<const char **&>(Argv),
0041                  InstallPipeSignalExitHandler) {}
0042 
0043   ~InitLLVM();
0044 
0045 private:
0046   BumpPtrAllocator Alloc;
0047   SmallVector<const char *, 0> Args;
0048   std::optional<PrettyStackTraceProgram> StackPrinter;
0049 };
0050 } // namespace llvm
0051 
0052 #endif