-#include "Support/SystemUtils.h"
-#include <algorithm>
-#include <fstream>
-#include <iostream>
-#include <cstdlib>
-#include "Config/sys/types.h"
-#include "Config/sys/stat.h"
-#include "Config/fcntl.h"
-#include "Config/sys/wait.h"
-#include "Config/unistd.h"
-#include "Config/errno.h"
-
-/// isExecutableFile - This function returns true if the filename specified
-/// exists and is executable.
-///
-bool isExecutableFile(const std::string &ExeFileName) {
- struct stat Buf;
- if (stat(ExeFileName.c_str(), &Buf))
- return false; // Must not be executable!
-
- if (!(Buf.st_mode & S_IFREG))
- return false; // Not a regular file?
-
- if (Buf.st_uid == getuid()) // Owner of file?
- return Buf.st_mode & S_IXUSR;
- else if (Buf.st_gid == getgid()) // In group of file?
- return Buf.st_mode & S_IXGRP;
- else // Unrelated to file?
- return Buf.st_mode & S_IXOTH;
-}
-
-
-// FindExecutable - Find a named executable, giving the argv[0] of program 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.
-//
-std::string FindExecutable(const std::string &ExeName,
- const std::string &ProgramPath) {
- // First check the directory that bugpoint is in. We can do this if
- // BugPointPath contains at least one / character, indicating that it is a
- // relative path to bugpoint itself.
- //
- std::string Result = ProgramPath;
- while (!Result.empty() && Result[Result.size()-1] != '/')
- Result.erase(Result.size()-1, 1);
-
- if (!Result.empty()) {
- Result += ExeName;
- if (isExecutableFile(Result)) return Result; // Found it?
- }
-
- // Okay, if the path to the program didn't tell us anything, try using the
- // PATH environment variable.
- const char *PathStr = getenv("PATH");
- if (PathStr == 0) return "";
-
- // Now we have a colon separated list of directories to search... try them...
- unsigned PathLen = strlen(PathStr);
- while (PathLen) {
- // Find the first colon...
- const char *Colon = std::find(PathStr, PathStr+PathLen, ':');
-
- // Check to see if this first directory contains the executable...
- std::string FilePath = std::string(PathStr, Colon) + '/' + ExeName;
- if (isExecutableFile(FilePath))
- return FilePath; // Found the executable!
-
- // Nope it wasn't in this directory, check the next range!
- PathLen -= Colon-PathStr;
- PathStr = Colon;
- while (*PathStr == ':') { // Advance past colons
- PathStr++;
- PathLen--;
+#include "llvm/Support/SystemUtils.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/raw_ostream.h"
+using namespace llvm;
+
+bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
+ bool print_warning) {
+ if (stream_to_check.is_displayed()) {
+ if (print_warning) {
+ 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";