blob: 80d6e4cba9fb6a59e8383b2ca1589862d625b077 [file] [log] [blame]
Misha Brukmanebb0faa2004-06-18 15:38:49 +00001//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner4a106452002-12-23 23:50:16 +00009//
10// This file contains functions used to do a variety of low-level, often
11// system-specific, tasks.
12//
13//===----------------------------------------------------------------------===//
14
Bill Wendlingfe6b1462006-11-26 10:52:51 +000015#include "llvm/Support/Streams.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000016#include "llvm/Support/SystemUtils.h"
Reid Spencer436f23e2005-01-01 23:56:20 +000017#include "llvm/System/Process.h"
Misha Brukmandca79782005-04-22 19:13:22 +000018#include "llvm/System/Program.h"
Bill Wendling1a097e32006-12-07 23:41:45 +000019#include <ostream>
Chris Lattner2cdd21c2003-12-14 21:35:53 +000020using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000021
Gabor Greifa99be512007-07-05 17:07:56 +000022bool llvm::CheckBitcodeOutputToConsole(std::ostream* stream_to_check,
23 bool print_warning) {
Bill Wendlingbcd24982006-12-07 20:28:15 +000024 if (stream_to_check == cout.stream() &&
25 sys::Process::StandardOutIsDisplayed()) {
Reid Spencer52b50a62005-01-02 00:10:03 +000026 if (print_warning) {
Gabor Greifa99be512007-07-05 17:07:56 +000027 cerr << "WARNING: You're attempting to print out a bitcode file.\n"
Bill Wendlinge8156192006-12-07 01:30:32 +000028 << "This is inadvisable as it may cause display problems. If\n"
Gabor Greifa99be512007-07-05 17:07:56 +000029 << "you REALLY want to taste LLVM bitcode first-hand, you\n"
Bill Wendlinge8156192006-12-07 01:30:32 +000030 << "can force output with the `-f' option.\n\n";
Reid Spencer52b50a62005-01-02 00:10:03 +000031 }
Reid Spencer436f23e2005-01-01 23:56:20 +000032 return true;
33 }
Brian Gaeke8507ecb2004-04-02 21:26:04 +000034 return false;
Chris Lattnerb234d462004-04-02 05:04:03 +000035}
36
Misha Brukmanf7066c72003-08-07 21:34:25 +000037/// FindExecutable - Find a named executable, giving the argv[0] of program
Misha Brukman44f8a342003-09-29 22:40:07 +000038/// 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.
Reid Spencera4348052004-12-19 18:00:09 +000042///
Chris Lattner49f61c42004-05-28 01:20:58 +000043#undef FindExecutable // needed on windows :(
Reid Spencer9665e8a2004-12-13 23:41:37 +000044sys::Path llvm::FindExecutable(const std::string &ExeName,
Reid Spencera4348052004-12-19 18:00:09 +000045 const std::string &ProgramPath) {
Misha Brukmanf976c852005-04-21 22:55:34 +000046 // First check the directory that the calling program is in. We can do this
Reid Spencer9665e8a2004-12-13 23:41:37 +000047 // if ProgramPath contains at least one / character, indicating that it is a
Chris Lattner4a106452002-12-23 23:50:16 +000048 // relative path to bugpoint itself.
Reid Spencer9665e8a2004-12-13 23:41:37 +000049 sys::Path Result ( ProgramPath );
Reid Spencerdd04df02005-07-07 23:21:43 +000050 Result.eraseComponent();
Reid Spencer9665e8a2004-12-13 23:41:37 +000051 if (!Result.isEmpty()) {
Reid Spencerdd04df02005-07-07 23:21:43 +000052 Result.appendComponent(ExeName);
Reid Spencerc7f08322005-07-07 18:21:42 +000053 if (Result.canExecute())
Reid Spencera4348052004-12-19 18:00:09 +000054 return Result;
Chris Lattner4a106452002-12-23 23:50:16 +000055 }
56
Reid Spencer9665e8a2004-12-13 23:41:37 +000057 return sys::Program::FindProgramByName(ExeName);
Chris Lattner4a106452002-12-23 23:50:16 +000058}