LLVM API Documentation
00001 //===- SystemUtils.cpp - Utilities for low-level system tasks -------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source 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/SystemUtils.h" 00016 #include "llvm/System/Process.h" 00017 #include "llvm/System/Program.h" 00018 #include <iostream> 00019 using namespace llvm; 00020 00021 bool llvm::CheckBytecodeOutputToConsole(std::ostream* stream_to_check, 00022 bool print_warning) { 00023 if (stream_to_check == &std::cout && sys::Process::StandardOutIsDisplayed()) { 00024 if (print_warning) { 00025 std::cerr << "WARNING: You're attempting to print out a bytecode file.\n" 00026 "This is inadvisable as it may cause display problems. If\n" 00027 "you REALLY want to taste LLVM bytecode first-hand, you\n" 00028 "can force output with the `-f' option.\n\n"; 00029 } 00030 return true; 00031 } 00032 return false; 00033 } 00034 00035 /// FindExecutable - Find a named executable, giving the argv[0] of program 00036 /// being executed. This allows us to find another LLVM tool if it is built 00037 /// into the same directory, but that directory is neither the current 00038 /// directory, nor in the PATH. If the executable cannot be found, return an 00039 /// empty string. 00040 /// 00041 #undef FindExecutable // needed on windows :( 00042 sys::Path llvm::FindExecutable(const std::string &ExeName, 00043 const std::string &ProgramPath) { 00044 // First check the directory that the calling program is in. We can do this 00045 // if ProgramPath contains at least one / character, indicating that it is a 00046 // relative path to bugpoint itself. 00047 sys::Path Result ( ProgramPath ); 00048 Result.eraseComponent(); 00049 if (!Result.isEmpty()) { 00050 Result.appendComponent(ExeName); 00051 if (Result.canExecute()) 00052 return Result; 00053 } 00054 00055 return sys::Program::FindProgramByName(ExeName); 00056 }