LLVM  11.0.0git
InitLLVM.cpp
Go to the documentation of this file.
1 //===-- InitLLVM.cpp -----------------------------------------------------===//
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 
10 #include "llvm/Support/Error.h"
13 #include "llvm/Support/Process.h"
14 #include "llvm/Support/Signals.h"
15 #include <string>
16 
17 #ifdef _WIN32
19 #endif
20 
21 using namespace llvm;
22 using namespace llvm::sys;
23 
24 InitLLVM::InitLLVM(int &Argc, const char **&Argv,
25  bool InstallPipeSignalExitHandler)
26  : StackPrinter(Argc, Argv) {
27  if (InstallPipeSignalExitHandler)
31 
32 #ifdef _WIN32
33  // We use UTF-8 as the internal character encoding. On Windows,
34  // arguments passed to main() may not be encoded in UTF-8. In order
35  // to reliably detect encoding of command line arguments, we use an
36  // Windows API to obtain arguments, convert them to UTF-8, and then
37  // write them back to the Argv vector.
38  //
39  // There's probably other way to do the same thing (e.g. using
40  // wmain() instead of main()), but this way seems less intrusive
41  // than that.
42  std::string Banner = std::string(Argv[0]) + ": ";
43  ExitOnError ExitOnErr(Banner);
44 
45  ExitOnErr(errorCodeToError(windows::GetCommandLineArguments(Args, Alloc)));
46 
47  // GetCommandLineArguments doesn't terminate the vector with a
48  // nullptr. Do it to make it compatible with the real argv.
49  Args.push_back(nullptr);
50 
51  Argc = Args.size() - 1;
52  Argv = Args.data();
53 #endif
54 }
55 
std::error_code GetCommandLineArguments(SmallVectorImpl< const char *> &Args, BumpPtrAllocator &Alloc)
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void push_back(const T &Elt)
Definition: SmallVector.h:246
Helper for check-and-exit error handling.
Definition: Error.h:1306
void DefaultOneShotPipeSignalHandler()
On Unix systems, this function exits with an "IO error" exit code.
void llvm_shutdown()
llvm_shutdown - Deallocate and destroy all ManagedStatic variables.
void PrintStackTraceOnErrorSignal(StringRef Argv0, bool DisableCrashReporting=false)
When an error signal (such as SIGABRT or SIGSEGV) is delivered to the process, print a stack trace an...
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:87
InitLLVM(int &Argc, const char **&Argv, bool InstallPipeSignalExitHandler=true)
Definition: InitLLVM.cpp:24
Provides a library for accessing information about this process and other processes on the operating ...
pointer data()
Return a pointer to the vector&#39;s buffer, even if empty().
Definition: SmallVector.h:171
size_t size() const
Definition: SmallVector.h:66
void SetOneShotPipeSignalFunction(void(*Handler)())
Registers a function to be called in a "one-shot" manner when a pipe signal is delivered to the proce...
void install_out_of_memory_new_handler()