2009-06-02 17:52:33 +00:00
|
|
|
//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains functions used to do a variety of low-level, often
|
|
|
|
// system-specific, tasks.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Support/SystemUtils.h"
|
|
|
|
#include "llvm/System/Process.h"
|
|
|
|
#include "llvm/System/Program.h"
|
2009-10-14 17:57:32 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-06-02 17:52:33 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-10-14 17:57:32 +00:00
|
|
|
bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
|
2009-06-02 17:52:33 +00:00
|
|
|
bool print_warning) {
|
2009-10-14 17:57:32 +00:00
|
|
|
if (stream_to_check.is_displayed()) {
|
2009-06-02 17:52:33 +00:00
|
|
|
if (print_warning) {
|
2009-10-14 17:57:32 +00:00
|
|
|
errs() << "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";
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// FindExecutable - Find a named executable, giving the argv[0] of program
|
2009-10-14 17:57:32 +00:00
|
|
|
/// being executed. This allows us to find another LLVM tool if it is built in
|
|
|
|
/// the same directory. If the executable cannot be found, return an
|
|
|
|
/// empty string.
|
|
|
|
/// @brief Find a named executable.
|
2009-06-02 17:52:33 +00:00
|
|
|
#undef FindExecutable // needed on windows :(
|
|
|
|
sys::Path llvm::FindExecutable(const std::string &ExeName,
|
2009-10-14 17:57:32 +00:00
|
|
|
const char *Argv0, void *MainAddr) {
|
|
|
|
// Check the directory that the calling program is in. We can do
|
2009-07-04 13:58:26 +00:00
|
|
|
// this if ProgramPath contains at least one / character, indicating that it
|
2009-10-14 17:57:32 +00:00
|
|
|
// is a relative path to the executable itself.
|
|
|
|
sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
|
2009-06-02 17:52:33 +00:00
|
|
|
Result.eraseComponent();
|
|
|
|
if (!Result.isEmpty()) {
|
|
|
|
Result.appendComponent(ExeName);
|
|
|
|
if (Result.canExecute())
|
|
|
|
return Result;
|
2010-09-17 15:48:55 +00:00
|
|
|
// If the path is absolute (and it usually is), call FindProgramByName to
|
|
|
|
// allow it to try platform-specific logic, such as appending a .exe suffix
|
|
|
|
// on Windows. Don't do this if we somehow have a relative path, because
|
|
|
|
// we don't want to go searching the PATH and accidentally find an unrelated
|
|
|
|
// version of the program.
|
|
|
|
if (Result.isAbsolute()) {
|
|
|
|
Result = sys::Program::FindProgramByName(Result.str());
|
|
|
|
if (!Result.empty())
|
|
|
|
return Result;
|
|
|
|
}
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|
|
|
|
|
2009-10-14 17:57:32 +00:00
|
|
|
return sys::Path();
|
2009-06-02 17:52:33 +00:00
|
|
|
}
|