blob: 3d3649eaebabfe4403c2bd148d2f596d58a96f2b [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"
Chris Lattnerb1aa85b2009-08-23 22:45:37 +000018#include "llvm/Support/raw_ostream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000019using namespace llvm;
20
Chris Lattner3a71a1a2009-08-23 21:36:09 +000021bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
Dan Gohman81fd8102009-07-15 17:04:50 +000022 bool print_warning) {
Chris Lattner3a71a1a2009-08-23 21:36:09 +000023 if (&stream_to_check == &outs() &&
Dan Gohman81fd8102009-07-15 17:04:50 +000024 sys::Process::StandardOutIsDisplayed()) {
25 if (print_warning) {
Chris Lattner3a71a1a2009-08-23 21:36:09 +000026 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";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030 }
31 return true;
32 }
33 return false;
34}
35
36/// FindExecutable - Find a named executable, giving the argv[0] of program
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000037/// being executed. This allows us to find another LLVM tool if it is built in
38/// the same directory. If the executable cannot be found, return an
39/// empty string.
40/// @brief Find a named executable.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041#undef FindExecutable // needed on windows :(
42sys::Path llvm::FindExecutable(const std::string &ExeName,
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000043 const char *Argv0, void *MainAddr) {
44 // Check the directory that the calling program is in. We can do
Daniel Dunbarb51088c2009-07-01 15:26:13 +000045 // this if ProgramPath contains at least one / character, indicating that it
Daniel Dunbarbf8e8712009-07-12 20:23:56 +000046 // is a relative path to the executable itself.
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000047 sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048 Result.eraseComponent();
49 if (!Result.isEmpty()) {
50 Result.appendComponent(ExeName);
51 if (Result.canExecute())
52 return Result;
53 }
54
Dan Gohman8e0b7b9d2009-08-05 20:21:17 +000055 return sys::Path();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}