Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 1 | //===- InitLLVM.h -----------------------------------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 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 |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 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<const char **&>(Argv)) {} |
| 35 | |
| 36 | ~InitLLVM(); |
| 37 | |
| 38 | private: |
| 39 | BumpPtrAllocator Alloc; |
| 40 | SmallVector<const char *, 0> Args; |
| 41 | PrettyStackTraceProgram StackPrinter; |
| 42 | }; |
| 43 | } // namespace llvm |
| 44 | |
| 45 | #endif |