InitLLVM.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #ifndef LLVM_SUPPORT_INITLLVM_H
  9. #define LLVM_SUPPORT_INITLLVM_H
  10. #include "llvm/ADT/Optional.h"
  11. #include "llvm/ADT/SmallVector.h"
  12. #include "llvm/Support/Allocator.h"
  13. #include "llvm/Support/PrettyStackTrace.h"
  14. // The main() functions in typical LLVM tools start with InitLLVM which does
  15. // the following one-time initializations:
  16. //
  17. // 1. Setting up a signal handler so that pretty stack trace is printed out
  18. // if a process crashes. A signal handler that exits when a failed write to
  19. // a pipe occurs may optionally be installed: this is on-by-default.
  20. //
  21. // 2. Set up the global new-handler which is called when a memory allocation
  22. // attempt fails.
  23. //
  24. // 3. If running on Windows, obtain command line arguments using a
  25. // multibyte character-aware API and convert arguments into UTF-8
  26. // encoding, so that you can assume that command line arguments are
  27. // always encoded in UTF-8 on any platform.
  28. //
  29. // InitLLVM calls llvm_shutdown() on destruction, which cleans up
  30. // ManagedStatic objects.
  31. namespace llvm {
  32. class InitLLVM {
  33. public:
  34. InitLLVM(int &Argc, const char **&Argv,
  35. bool InstallPipeSignalExitHandler = true);
  36. InitLLVM(int &Argc, char **&Argv, bool InstallPipeSignalExitHandler = true)
  37. : InitLLVM(Argc, const_cast<const char **&>(Argv),
  38. InstallPipeSignalExitHandler) {}
  39. ~InitLLVM();
  40. private:
  41. BumpPtrAllocator Alloc;
  42. SmallVector<const char *, 0> Args;
  43. Optional<PrettyStackTraceProgram> StackPrinter;
  44. };
  45. } // namespace llvm
  46. #endif