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