2004-06-18 23:38:49 +08:00
|
|
|
//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-12-24 07:50:16 +08:00
|
|
|
//
|
|
|
|
// This file contains functions used to do a variety of low-level, often
|
|
|
|
// system-specific, tasks.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-11-26 18:52:51 +08:00
|
|
|
#include "llvm/Support/Streams.h"
|
2004-09-02 06:55:40 +08:00
|
|
|
#include "llvm/Support/SystemUtils.h"
|
2005-01-02 07:56:20 +08:00
|
|
|
#include "llvm/System/Process.h"
|
2005-04-23 03:13:22 +08:00
|
|
|
#include "llvm/System/Program.h"
|
2006-12-08 07:41:45 +08:00
|
|
|
#include <ostream>
|
2003-12-15 05:35:53 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2007-07-06 01:07:56 +08:00
|
|
|
bool llvm::CheckBitcodeOutputToConsole(std::ostream* stream_to_check,
|
|
|
|
bool print_warning) {
|
2006-12-08 04:28:15 +08:00
|
|
|
if (stream_to_check == cout.stream() &&
|
|
|
|
sys::Process::StandardOutIsDisplayed()) {
|
2005-01-02 08:10:03 +08:00
|
|
|
if (print_warning) {
|
2007-07-06 01:07:56 +08:00
|
|
|
cerr << "WARNING: You're attempting to print out a bitcode file.\n"
|
2006-12-07 09:30:32 +08:00
|
|
|
<< "This is inadvisable as it may cause display problems. If\n"
|
2007-07-06 01:07:56 +08:00
|
|
|
<< "you REALLY want to taste LLVM bitcode first-hand, you\n"
|
2006-12-07 09:30:32 +08:00
|
|
|
<< "can force output with the `-f' option.\n\n";
|
2005-01-02 08:10:03 +08:00
|
|
|
}
|
2005-01-02 07:56:20 +08:00
|
|
|
return true;
|
|
|
|
}
|
2004-04-03 05:26:04 +08:00
|
|
|
return false;
|
2004-04-02 13:04:03 +08:00
|
|
|
}
|
|
|
|
|
2003-08-08 05:34:25 +08:00
|
|
|
/// FindExecutable - Find a named executable, giving the argv[0] of program
|
2003-09-30 06:40:07 +08:00
|
|
|
/// being executed. This allows us to find another LLVM tool if it is built
|
|
|
|
/// into the same directory, but that directory is neither the current
|
|
|
|
/// directory, nor in the PATH. If the executable cannot be found, return an
|
|
|
|
/// empty string.
|
2004-12-20 02:00:09 +08:00
|
|
|
///
|
2004-05-28 09:20:58 +08:00
|
|
|
#undef FindExecutable // needed on windows :(
|
2004-12-14 07:41:37 +08:00
|
|
|
sys::Path llvm::FindExecutable(const std::string &ExeName,
|
2004-12-20 02:00:09 +08:00
|
|
|
const std::string &ProgramPath) {
|
2005-04-22 06:55:34 +08:00
|
|
|
// First check the directory that the calling program is in. We can do this
|
2004-12-14 07:41:37 +08:00
|
|
|
// if ProgramPath contains at least one / character, indicating that it is a
|
2002-12-24 07:50:16 +08:00
|
|
|
// relative path to bugpoint itself.
|
2004-12-14 07:41:37 +08:00
|
|
|
sys::Path Result ( ProgramPath );
|
2005-07-08 07:21:43 +08:00
|
|
|
Result.eraseComponent();
|
2004-12-14 07:41:37 +08:00
|
|
|
if (!Result.isEmpty()) {
|
2005-07-08 07:21:43 +08:00
|
|
|
Result.appendComponent(ExeName);
|
2005-07-08 02:21:42 +08:00
|
|
|
if (Result.canExecute())
|
2004-12-20 02:00:09 +08:00
|
|
|
return Result;
|
2002-12-24 07:50:16 +08:00
|
|
|
}
|
|
|
|
|
2004-12-14 07:41:37 +08:00
|
|
|
return sys::Program::FindProgramByName(ExeName);
|
2002-12-24 07:50:16 +08:00
|
|
|
}
|