Deleted Added
full compact
SystemUtils.cpp (212904) SystemUtils.cpp (218893)
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"
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/System/Process.h"
17#include "llvm/System/Program.h"
16#include "llvm/Support/Process.h"
17#include "llvm/Support/Program.h"
18#include "llvm/Support/raw_ostream.h"
19using namespace llvm;
20
21bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
22 bool print_warning) {
23 if (stream_to_check.is_displayed()) {
24 if (print_warning) {
25 errs() << "WARNING: You're attempting to print out a bitcode file.\n"
18#include "llvm/Support/raw_ostream.h"
19using namespace llvm;
20
21bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
22 bool print_warning) {
23 if (stream_to_check.is_displayed()) {
24 if (print_warning) {
25 errs() << "WARNING: You're attempting to print out a bitcode file.\n"
26 << "This is inadvisable as it may cause display problems. If\n"
27 << "you REALLY want to taste LLVM bitcode first-hand, you\n"
28 << "can force output with the `-f' option.\n\n";
26 "This is inadvisable as it may cause display problems. If\n"
27 "you REALLY want to taste LLVM bitcode first-hand, you\n"
28 "can force output with the `-f' option.\n\n";
29 }
30 return true;
31 }
32 return false;
33}
34
29 }
30 return true;
31 }
32 return false;
33}
34
35/// FindExecutable - Find a named executable, giving the argv[0] of program
36/// being executed. This allows us to find another LLVM tool if it is built in
37/// the same directory. If the executable cannot be found, return an
38/// empty string.
35/// PrependMainExecutablePath - Prepend the path to the program being executed
36/// to \p ExeName, given the value of argv[0] and the address of main()
37/// itself. This allows us to find another LLVM tool if it is built in the same
38/// directory. An empty string is returned on error; note that this function
39/// just mainpulates the path and doesn't check for executability.
39/// @brief Find a named executable.
40/// @brief Find a named executable.
40#undef FindExecutable // needed on windows :(
41sys::Path llvm::FindExecutable(const std::string &ExeName,
42 const char *Argv0, void *MainAddr) {
41sys::Path llvm::PrependMainExecutablePath(const std::string &ExeName,
42 const char *Argv0, void *MainAddr) {
43 // Check the directory that the calling program is in. We can do
44 // this if ProgramPath contains at least one / character, indicating that it
45 // is a relative path to the executable itself.
46 sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
47 Result.eraseComponent();
43 // Check the directory that the calling program is in. We can do
44 // this if ProgramPath contains at least one / character, indicating that it
45 // is a relative path to the executable itself.
46 sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
47 Result.eraseComponent();
48
48 if (!Result.isEmpty()) {
49 Result.appendComponent(ExeName);
49 if (!Result.isEmpty()) {
50 Result.appendComponent(ExeName);
50 if (Result.canExecute())
51 return Result;
52 // If the path is absolute (and it usually is), call FindProgramByName to
53 // allow it to try platform-specific logic, such as appending a .exe suffix
54 // on Windows. Don't do this if we somehow have a relative path, because
55 // we don't want to go searching the PATH and accidentally find an unrelated
56 // version of the program.
57 if (Result.isAbsolute()) {
58 Result = sys::Program::FindProgramByName(Result.str());
59 if (!Result.empty())
60 return Result;
61 }
51 Result.appendSuffix(sys::Path::GetEXESuffix());
62 }
63
52 }
53
64 return sys::Path();
54 return Result;
65}
55}