blob: 764f6be4eb2ab4727bdcf1509ca1e7d3f943d733 [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 Spencer52b50a62005-01-02 00:10:03 +000022bool llvm::CheckBytecodeOutputToConsole(std::ostream* stream_to_check,
23 bool print_warning) {
Reid Spencer436f23e2005-01-01 23:56:20 +000024 if (stream_to_check == &std::cout && sys::Process::StandardOutIsDisplayed()) {
Reid Spencer52b50a62005-01-02 00:10:03 +000025 if (print_warning) {
26 std::cerr << "WARNING: You're attempting to print out a bytecode file.\n";
27 std::cerr << "This is inadvisable as it may cause display problems. If\n";
28 std::cerr << "you REALLY want to taste LLVM bytecode first-hand, you\n";
29 std::cerr << "can force output with the `-f' option.\n\n";
30 }
Reid Spencer436f23e2005-01-01 23:56:20 +000031 return true;
32 }
Brian Gaeke8507ecb2004-04-02 21:26:04 +000033 return false;
Chris Lattnerb234d462004-04-02 05:04:03 +000034}
35
Misha Brukmanf7066c72003-08-07 21:34:25 +000036/// FindExecutable - Find a named executable, giving the argv[0] of program
Misha Brukman44f8a342003-09-29 22:40:07 +000037/// being executed. This allows us to find another LLVM tool if it is built
38/// into the same directory, but that directory is neither the current
39/// directory, nor in the PATH. If the executable cannot be found, return an
40/// empty string.
Reid Spencera4348052004-12-19 18:00:09 +000041///
Chris Lattner49f61c42004-05-28 01:20:58 +000042#undef FindExecutable // needed on windows :(
Reid Spencer9665e8a2004-12-13 23:41:37 +000043sys::Path llvm::FindExecutable(const std::string &ExeName,
Reid Spencera4348052004-12-19 18:00:09 +000044 const std::string &ProgramPath) {
45 // First check the directory that the calling program is in. We can do this
Reid Spencer9665e8a2004-12-13 23:41:37 +000046 // if ProgramPath contains at least one / character, indicating that it is a
Chris Lattner4a106452002-12-23 23:50:16 +000047 // relative path to bugpoint itself.
Reid Spencer9665e8a2004-12-13 23:41:37 +000048 sys::Path Result ( ProgramPath );
49 Result.elideFile();
Reid Spencer9665e8a2004-12-13 23:41:37 +000050 if (!Result.isEmpty()) {
51 Result.appendFile(ExeName);
Reid Spencera4348052004-12-19 18:00:09 +000052 if (Result.executable())
53 return Result;
Chris Lattner4a106452002-12-23 23:50:16 +000054 }
55
Reid Spencer9665e8a2004-12-13 23:41:37 +000056 return sys::Program::FindProgramByName(ExeName);
Chris Lattner4a106452002-12-23 23:50:16 +000057}