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
|
|
|
|
//
|
2007-12-29 21:36:04 +01:00
|
|
|
// This file 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"
|
2010-11-29 19:16:10 +01:00
|
|
|
#include "llvm/Support/Process.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
2009-08-24 00:45:37 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2003-12-14 22:35:53 +01:00
|
|
|
using namespace llvm;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2009-08-23 23:36:09 +02:00
|
|
|
bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
|
2009-07-15 19:04:50 +02:00
|
|
|
bool print_warning) {
|
2009-09-11 22:46:33 +02:00
|
|
|
if (stream_to_check.is_displayed()) {
|
2009-07-15 19:04:50 +02:00
|
|
|
if (print_warning) {
|
2009-08-23 23:36:09 +02:00
|
|
|
errs() << "WARNING: You're attempting to print out a bitcode file.\n"
|
2010-11-03 01:24:33 +01:00
|
|
|
"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";
|
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
|
|
|
}
|
|
|
|
|
2010-11-03 17:14:16 +01:00
|
|
|
/// PrependMainExecutablePath - Prepend the path to the program being executed
|
|
|
|
/// to \p ExeName, given the value of argv[0] and the address of main()
|
|
|
|
/// itself. This allows us to find another LLVM tool if it is built in the same
|
|
|
|
/// directory. An empty string is returned on error; note that this function
|
|
|
|
/// just mainpulates the path and doesn't check for executability.
|
|
|
|
/// @brief Find a named executable.
|
|
|
|
sys::Path llvm::PrependMainExecutablePath(const std::string &ExeName,
|
|
|
|
const char *Argv0, void *MainAddr) {
|
2009-08-05 22:21:17 +02:00
|
|
|
// Check the directory that the calling program is in. We can do
|
2009-07-01 17:26:13 +02:00
|
|
|
// this if ProgramPath contains at least one / character, indicating that it
|
2009-07-12 22:23:56 +02:00
|
|
|
// is a relative path to the executable itself.
|
2009-08-05 22:21:17 +02:00
|
|
|
sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
|
2005-07-08 01:21:43 +02:00
|
|
|
Result.eraseComponent();
|
2010-11-02 21:32:46 +01:00
|
|
|
|
2004-12-14 00:41:37 +01:00
|
|
|
if (!Result.isEmpty()) {
|
2005-07-08 01:21:43 +02:00
|
|
|
Result.appendComponent(ExeName);
|
2010-11-02 23:18:28 +01:00
|
|
|
Result.appendSuffix(sys::Path::GetEXESuffix());
|
2002-12-24 00:50:16 +01:00
|
|
|
}
|
|
|
|
|
2010-10-28 21:33:04 +02:00
|
|
|
return Result;
|
2002-12-24 00:50:16 +01:00
|
|
|
}
|