blob: dfb87755f7b609a681c46e6a2ebc562969093b02 [file] [log] [blame]
Misha Brukmanebb0faa2004-06-18 15:38:49 +00001//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
John Criswellb576c942003-10-20 19:43:21 +00002//
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//===----------------------------------------------------------------------===//
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
Reid Spencer551ccae2004-09-01 22:55:40 +000015#include "llvm/Support/SystemUtils.h"
Reid Spencer9665e8a2004-12-13 23:41:37 +000016#include "llvm/System/Program.h"
Reid Spencer436f23e2005-01-01 23:56:20 +000017#include "llvm/System/Process.h"
18#include <iostream>
Reid Spencer44f69662004-12-14 04:18:15 +000019
Chris Lattner2cdd21c2003-12-14 21:35:53 +000020using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000021
Reid Spencer436f23e2005-01-01 23:56:20 +000022bool llvm::CheckBytecodeOutputToConsole(std::ostream* stream_to_check) {
23 if (stream_to_check == &std::cout && sys::Process::StandardOutIsDisplayed()) {
24 std::cerr << "WARNING: You're attempting to print out a bytecode file.\n";
25 std::cerr << "This is inadvisable as it may cause display problems. If\n";
26 std::cerr << "you REALLY want to taste LLVM bytecode first-hand, you can\n";
27 std::cerr << "force output with the `-f' option.\n\n";
28 return true;
29 }
Brian Gaeke8507ecb2004-04-02 21:26:04 +000030 return false;
Chris Lattnerb234d462004-04-02 05:04:03 +000031}
32
Misha Brukmanf7066c72003-08-07 21:34:25 +000033/// FindExecutable - Find a named executable, giving the argv[0] of program
Misha Brukman44f8a342003-09-29 22:40:07 +000034/// being executed. This allows us to find another LLVM tool if it is built
35/// into the same directory, but that directory is neither the current
36/// directory, nor in the PATH. If the executable cannot be found, return an
37/// empty string.
Reid Spencera4348052004-12-19 18:00:09 +000038///
Chris Lattner49f61c42004-05-28 01:20:58 +000039#undef FindExecutable // needed on windows :(
Reid Spencer9665e8a2004-12-13 23:41:37 +000040sys::Path llvm::FindExecutable(const std::string &ExeName,
Reid Spencera4348052004-12-19 18:00:09 +000041 const std::string &ProgramPath) {
42 // First check the directory that the calling program is in. We can do this
Reid Spencer9665e8a2004-12-13 23:41:37 +000043 // if ProgramPath contains at least one / character, indicating that it is a
Chris Lattner4a106452002-12-23 23:50:16 +000044 // relative path to bugpoint itself.
Reid Spencer9665e8a2004-12-13 23:41:37 +000045 sys::Path Result ( ProgramPath );
46 Result.elideFile();
Reid Spencer9665e8a2004-12-13 23:41:37 +000047 if (!Result.isEmpty()) {
48 Result.appendFile(ExeName);
Reid Spencera4348052004-12-19 18:00:09 +000049 if (Result.executable())
50 return Result;
Chris Lattner4a106452002-12-23 23:50:16 +000051 }
52
Reid Spencer9665e8a2004-12-13 23:41:37 +000053 return sys::Program::FindProgramByName(ExeName);
Chris Lattner4a106452002-12-23 23:50:16 +000054}