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