LLVM API Documentation

SystemUtils.cpp

Go to the documentation of this file.
00001 //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains functions used to do a variety of low-level, often
00011 // system-specific, tasks.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "llvm/Support/Streams.h"
00016 #include "llvm/Support/SystemUtils.h"
00017 #include "llvm/System/Process.h"
00018 #include "llvm/System/Program.h"
00019 #include <ostream>
00020 using namespace llvm;
00021 
00022 bool llvm::CheckBitcodeOutputToConsole(raw_ostream* stream_to_check,
00023                                        bool print_warning) {
00024   if (stream_to_check == &outs() &&
00025       sys::Process::StandardOutIsDisplayed()) {
00026     if (print_warning) {
00027       cerr << "WARNING: You're attempting to print out a bitcode file.\n"
00028            << "This is inadvisable as it may cause display problems. If\n"
00029            << "you REALLY want to taste LLVM bitcode first-hand, you\n"
00030            << "can force output with the `-f' option.\n\n";
00031     }
00032     return true;
00033   }
00034   return false;
00035 }
00036 
00037 bool llvm::CheckBitcodeOutputToConsole(std::ostream* stream_to_check,
00038                                        bool print_warning) {
00039   if (stream_to_check == cout.stream() &&
00040       sys::Process::StandardOutIsDisplayed()) {
00041     if (print_warning) {
00042       cerr << "WARNING: You're attempting to print out a bitcode file.\n"
00043            << "This is inadvisable as it may cause display problems. If\n"
00044            << "you REALLY want to taste LLVM bitcode first-hand, you\n"
00045            << "can force output with the `-f' option.\n\n";
00046     }
00047     return true;
00048   }
00049   return false;
00050 }
00051 
00052 /// FindExecutable - Find a named executable, giving the argv[0] of program
00053 /// being executed. This allows us to find another LLVM tool if it is built in
00054 /// the same directory.  If the executable cannot be found, return an
00055 /// empty string.
00056 /// @brief Find a named executable.
00057 #undef FindExecutable   // needed on windows :(
00058 sys::Path llvm::FindExecutable(const std::string &ExeName,
00059                                const char *Argv0, void *MainAddr) {
00060   // Check the directory that the calling program is in.  We can do
00061   // this if ProgramPath contains at least one / character, indicating that it
00062   // is a relative path to the executable itself.
00063   sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
00064   Result.eraseComponent();
00065   if (!Result.isEmpty()) {
00066     Result.appendComponent(ExeName);
00067     if (Result.canExecute())
00068       return Result;
00069   }
00070 
00071   return sys::Path();
00072 }