1336809Sdim//===- InitLLVM.h -----------------------------------------------*- C++ -*-===//
2336809Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6336809Sdim//
7336809Sdim//===----------------------------------------------------------------------===//
8336809Sdim
9336809Sdim#ifndef LLVM_SUPPORT_LLVM_H
10336809Sdim#define LLVM_SUPPORT_LLVM_H
11336809Sdim
12336809Sdim#include "llvm/ADT/SmallVector.h"
13336809Sdim#include "llvm/Support/Allocator.h"
14336809Sdim#include "llvm/Support/PrettyStackTrace.h"
15336809Sdim
16336809Sdim// The main() functions in typical LLVM tools start with InitLLVM which does
17336809Sdim// the following one-time initializations:
18336809Sdim//
19336809Sdim//  1. Setting up a signal handler so that pretty stack trace is printed out
20360784Sdim//     if a process crashes. A signal handler that exits when a failed write to
21360784Sdim//     a pipe occurs may optionally be installed: this is on-by-default.
22336809Sdim//
23353358Sdim//  2. Set up the global new-handler which is called when a memory allocation
24353358Sdim//     attempt fails.
25353358Sdim//
26353358Sdim//  3. If running on Windows, obtain command line arguments using a
27336809Sdim//     multibyte character-aware API and convert arguments into UTF-8
28336809Sdim//     encoding, so that you can assume that command line arguments are
29336809Sdim//     always encoded in UTF-8 on any platform.
30336809Sdim//
31336809Sdim// InitLLVM calls llvm_shutdown() on destruction, which cleans up
32336809Sdim// ManagedStatic objects.
33336809Sdimnamespace llvm {
34336809Sdimclass InitLLVM {
35336809Sdimpublic:
36360784Sdim  InitLLVM(int &Argc, const char **&Argv,
37360784Sdim           bool InstallPipeSignalExitHandler = true);
38360784Sdim  InitLLVM(int &Argc, char **&Argv, bool InstallPipeSignalExitHandler = true)
39360784Sdim      : InitLLVM(Argc, const_cast<const char **&>(Argv),
40360784Sdim                 InstallPipeSignalExitHandler) {}
41336809Sdim
42336809Sdim  ~InitLLVM();
43336809Sdim
44336809Sdimprivate:
45336809Sdim  BumpPtrAllocator Alloc;
46336809Sdim  SmallVector<const char *, 0> Args;
47336809Sdim  PrettyStackTraceProgram StackPrinter;
48336809Sdim};
49336809Sdim} // namespace llvm
50336809Sdim
51336809Sdim#endif
52