blob: 09c0b19aa9c0bead5b178406227208cfeab1c771 [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//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
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
Dan Gohman81fd8102009-07-15 17:04:50 +000022bool llvm::CheckBitcodeOutputToConsole(raw_ostream* stream_to_check,
23 bool print_warning) {
24 if (stream_to_check == &outs() &&
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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037bool llvm::CheckBitcodeOutputToConsole(std::ostream* stream_to_check,
38 bool print_warning) {
39 if (stream_to_check == cout.stream() &&
40 sys::Process::StandardOutIsDisplayed()) {
41 if (print_warning) {
42 cerr << "WARNING: You're attempting to print out a bitcode file.\n"
43 << "This is inadvisable as it may cause display problems. If\n"
44 << "you REALLY want to taste LLVM bitcode first-hand, you\n"
45 << "can force output with the `-f' option.\n\n";
46 }
47 return true;
48 }
49 return false;
50}
51
52/// FindExecutable - Find a named executable, giving the argv[0] of program
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000053/// being executed. This allows us to find another LLVM tool if it is built in
54/// the same directory. If the executable cannot be found, return an
55/// empty string.
56/// @brief Find a named executable.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057#undef FindExecutable // needed on windows :(
58sys::Path llvm::FindExecutable(const std::string &ExeName,
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000059 const char *Argv0, void *MainAddr) {
60 // Check the directory that the calling program is in. We can do
Daniel Dunbarb51088c2009-07-01 15:26:13 +000061 // this if ProgramPath contains at least one / character, indicating that it
Daniel Dunbarbf8e8712009-07-12 20:23:56 +000062 // is a relative path to the executable itself.
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000063 sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064 Result.eraseComponent();
65 if (!Result.isEmpty()) {
66 Result.appendComponent(ExeName);
67 if (Result.canExecute())
68 return Result;
69 }
70
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000071 return sys::Path();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072}