blob: 7756e033ad8f62a32cc2825839dec8ec8cbe4e7f [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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000015#include "llvm/Support/SystemUtils.h"
16#include "llvm/System/Process.h"
17#include "llvm/System/Program.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000018using namespace llvm;
19
Chris Lattner3a71a1a2009-08-23 21:36:09 +000020bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
Dan Gohman81fd8102009-07-15 17:04:50 +000021 bool print_warning) {
Chris Lattner3a71a1a2009-08-23 21:36:09 +000022 if (&stream_to_check == &outs() &&
Dan Gohman81fd8102009-07-15 17:04:50 +000023 sys::Process::StandardOutIsDisplayed()) {
24 if (print_warning) {
Chris Lattner3a71a1a2009-08-23 21:36:09 +000025 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";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000029 }
30 return true;
31 }
32 return false;
33}
34
35/// FindExecutable - Find a named executable, giving the argv[0] of program
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000036/// 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.
39/// @brief Find a named executable.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040#undef FindExecutable // needed on windows :(
41sys::Path llvm::FindExecutable(const std::string &ExeName,
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000042 const char *Argv0, void *MainAddr) {
43 // Check the directory that the calling program is in. We can do
Daniel Dunbarb51088c2009-07-01 15:26:13 +000044 // this if ProgramPath contains at least one / character, indicating that it
Daniel Dunbarbf8e8712009-07-12 20:23:56 +000045 // is a relative path to the executable itself.
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000046 sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 Result.eraseComponent();
48 if (!Result.isEmpty()) {
49 Result.appendComponent(ExeName);
50 if (Result.canExecute())
51 return Result;
52 }
53
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000054 return sys::Path();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055}