InitLLVM.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- InitLLVM.h -----------------------------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_SUPPORT_INITLLVM_H
  14. #define LLVM_SUPPORT_INITLLVM_H
  15. #include "llvm/ADT/Optional.h"
  16. #include "llvm/ADT/SmallVector.h"
  17. #include "llvm/Support/Allocator.h"
  18. #include "llvm/Support/PrettyStackTrace.h"
  19. // The main() functions in typical LLVM tools start with InitLLVM which does
  20. // the following one-time initializations:
  21. //
  22. // 1. Setting up a signal handler so that pretty stack trace is printed out
  23. // if a process crashes. A signal handler that exits when a failed write to
  24. // a pipe occurs may optionally be installed: this is on-by-default.
  25. //
  26. // 2. Set up the global new-handler which is called when a memory allocation
  27. // attempt fails.
  28. //
  29. // 3. If running on Windows, obtain command line arguments using a
  30. // multibyte character-aware API and convert arguments into UTF-8
  31. // encoding, so that you can assume that command line arguments are
  32. // always encoded in UTF-8 on any platform.
  33. //
  34. // InitLLVM calls llvm_shutdown() on destruction, which cleans up
  35. // ManagedStatic objects.
  36. namespace llvm {
  37. class InitLLVM {
  38. public:
  39. InitLLVM(int &Argc, const char **&Argv,
  40. bool InstallPipeSignalExitHandler = true);
  41. InitLLVM(int &Argc, char **&Argv, bool InstallPipeSignalExitHandler = true)
  42. : InitLLVM(Argc, const_cast<const char **&>(Argv),
  43. InstallPipeSignalExitHandler) {}
  44. ~InitLLVM();
  45. private:
  46. BumpPtrAllocator Alloc;
  47. SmallVector<const char *, 0> Args;
  48. Optional<PrettyStackTraceProgram> StackPrinter;
  49. };
  50. } // namespace llvm
  51. #endif
  52. #ifdef __GNUC__
  53. #pragma GCC diagnostic pop
  54. #endif