blob: afa0d7e961b8c396d3fdbb06bb2257cc17fdf82f [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source 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/Streams.h"
16#include "llvm/Support/SystemUtils.h"
17#include "llvm/System/Process.h"
18#include "llvm/System/Program.h"
19#include <ostream>
20using namespace llvm;
21
22bool llvm::CheckBitcodeOutputToConsole(std::ostream* stream_to_check,
23 bool print_warning) {
24 if (stream_to_check == cout.stream() &&
25 sys::Process::StandardOutIsDisplayed()) {
26 if (print_warning) {
27 cerr << "WARNING: You're attempting to print out a bitcode file.\n"
28 << "This is inadvisable as it may cause display problems. If\n"
29 << "you REALLY want to taste LLVM bitcode first-hand, you\n"
30 << "can force output with the `-f' option.\n\n";
31 }
32 return true;
33 }
34 return false;
35}
36
37/// FindExecutable - Find a named executable, giving the argv[0] of program
38/// being executed. This allows us to find another LLVM tool if it is built
39/// into the same directory, but that directory is neither the current
40/// directory, nor in the PATH. If the executable cannot be found, return an
41/// empty string.
42///
43#undef FindExecutable // needed on windows :(
44sys::Path llvm::FindExecutable(const std::string &ExeName,
45 const std::string &ProgramPath) {
46 // First check the directory that the calling program is in. We can do this
47 // if ProgramPath contains at least one / character, indicating that it is a
48 // relative path to bugpoint itself.
49 sys::Path Result ( ProgramPath );
50 Result.eraseComponent();
51 if (!Result.isEmpty()) {
52 Result.appendComponent(ExeName);
53 if (Result.canExecute())
54 return Result;
55 }
56
57 return sys::Program::FindProgramByName(ExeName);
58}