1 //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains functions used to do a variety of low-level, often
11 // system-specific, tasks.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/Support/SystemUtils.h"
16 #include "llvm/Support/PathV1.h"
17 #include "llvm/Support/Process.h"
18 #include "llvm/Support/Program.h"
19 #include "llvm/Support/raw_ostream.h"
20 using namespace llvm;
21 
22 bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
23                                        bool print_warning) {
24   if (stream_to_check.is_displayed()) {
25     if (print_warning) {
26       errs() << "WARNING: You're attempting to print out a bitcode file.\n"
27                 "This is inadvisable as it may cause display problems. If\n"
28                 "you REALLY want to taste LLVM bitcode first-hand, you\n"
29                 "can force output with the `-f' option.\n\n";
30     }
31     return true;
32   }
33   return false;
34 }
35 
36 /// PrependMainExecutablePath - Prepend the path to the program being executed
37 /// to \p ExeName, given the value of argv[0] and the address of main()
38 /// itself. This allows us to find another LLVM tool if it is built in the same
39 /// directory. An empty string is returned on error; note that this function
40 /// just mainpulates the path and doesn't check for executability.
41 /// @brief Find a named executable.
42 sys::Path llvm::PrependMainExecutablePath(const std::string &ExeName,
43                                           const char *Argv0, void *MainAddr) {
44   // Check the directory that the calling program is in.  We can do
45   // this if ProgramPath contains at least one / character, indicating that it
46   // is a relative path to the executable itself.
47   sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
48   Result.eraseComponent();
49 
50   if (!Result.isEmpty()) {
51     Result.appendComponent(ExeName);
52     Result.appendSuffix(sys::Path::GetEXESuffix());
53   }
54 
55   return Result;
56 }
57