InitLLVM.h revision 360784
1//===- InitLLVM.h -----------------------------------------------*- C++ -*-===// 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#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. A signal handler that exits when a failed write to 21// a pipe occurs may optionally be installed: this is on-by-default. 22// 23// 2. Set up the global new-handler which is called when a memory allocation 24// attempt fails. 25// 26// 3. If running on Windows, obtain command line arguments using a 27// multibyte character-aware API and convert arguments into UTF-8 28// encoding, so that you can assume that command line arguments are 29// always encoded in UTF-8 on any platform. 30// 31// InitLLVM calls llvm_shutdown() on destruction, which cleans up 32// ManagedStatic objects. 33namespace llvm { 34class InitLLVM { 35public: 36 InitLLVM(int &Argc, const char **&Argv, 37 bool InstallPipeSignalExitHandler = true); 38 InitLLVM(int &Argc, char **&Argv, bool InstallPipeSignalExitHandler = true) 39 : InitLLVM(Argc, const_cast<const char **&>(Argv), 40 InstallPipeSignalExitHandler) {} 41 42 ~InitLLVM(); 43 44private: 45 BumpPtrAllocator Alloc; 46 SmallVector<const char *, 0> Args; 47 PrettyStackTraceProgram StackPrinter; 48}; 49} // namespace llvm 50 51#endif 52