blob: 88c3515920ffd8095fc64c0431a58f23a4e4da62 [file] [log] [blame]
Misha Brukman4b585812004-06-18 15:38:49 +00001//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
Misha Brukman10468d82005-04-21 22:55:34 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman10468d82005-04-21 22:55:34 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerde4aa4c2002-12-23 23:50:16 +00009//
10// This file contains functions used to do a variety of low-level, often
11// system-specific, tasks.
12//
13//===----------------------------------------------------------------------===//
14
Reid Spencer7c16caa2004-09-01 22:55:40 +000015#include "llvm/Support/SystemUtils.h"
Reid Spencer1263cfd2005-01-01 23:56:20 +000016#include "llvm/System/Process.h"
Misha Brukman7937b072005-04-22 19:13:22 +000017#include "llvm/System/Program.h"
Reid Spencer1263cfd2005-01-01 23:56:20 +000018#include <iostream>
Chris Lattnerc9499b62003-12-14 21:35:53 +000019using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000020
Reid Spencer4e8dd442005-01-02 00:10:03 +000021bool llvm::CheckBytecodeOutputToConsole(std::ostream* stream_to_check,
22 bool print_warning) {
Reid Spencer1263cfd2005-01-01 23:56:20 +000023 if (stream_to_check == &std::cout && sys::Process::StandardOutIsDisplayed()) {
Reid Spencer4e8dd442005-01-02 00:10:03 +000024 if (print_warning) {
Misha Brukman7937b072005-04-22 19:13:22 +000025 std::cerr << "WARNING: You're attempting to print out a bytecode file.\n"
Misha Brukman308a7152005-05-10 22:03:50 +000026 "This is inadvisable as it may cause display problems. If\n"
27 "you REALLY want to taste LLVM bytecode first-hand, you\n"
28 "can force output with the `-f' option.\n\n";
Reid Spencer4e8dd442005-01-02 00:10:03 +000029 }
Reid Spencer1263cfd2005-01-01 23:56:20 +000030 return true;
31 }
Brian Gaeke5ade5012004-04-02 21:26:04 +000032 return false;
Chris Lattner454e1832004-04-02 05:04:03 +000033}
34
Misha Brukmane4d58ec2003-08-07 21:34:25 +000035/// FindExecutable - Find a named executable, giving the argv[0] of program
Misha Brukman34c96102003-09-29 22:40:07 +000036/// being executed. This allows us to find another LLVM tool if it is built
37/// into the same directory, but that directory is neither the current
38/// directory, nor in the PATH. If the executable cannot be found, return an
39/// empty string.
Reid Spencerd44f8452004-12-19 18:00:09 +000040///
Chris Lattnerb6d6b932004-05-28 01:20:58 +000041#undef FindExecutable // needed on windows :(
Reid Spencerdc49d862004-12-13 23:41:37 +000042sys::Path llvm::FindExecutable(const std::string &ExeName,
Reid Spencerd44f8452004-12-19 18:00:09 +000043 const std::string &ProgramPath) {
Misha Brukman10468d82005-04-21 22:55:34 +000044 // First check the directory that the calling program is in. We can do this
Reid Spencerdc49d862004-12-13 23:41:37 +000045 // if ProgramPath contains at least one / character, indicating that it is a
Chris Lattnerde4aa4c2002-12-23 23:50:16 +000046 // relative path to bugpoint itself.
Reid Spencerdc49d862004-12-13 23:41:37 +000047 sys::Path Result ( ProgramPath );
Reid Spencerc9c04732005-07-07 23:21:43 +000048 Result.eraseComponent();
Reid Spencerdc49d862004-12-13 23:41:37 +000049 if (!Result.isEmpty()) {
Reid Spencerc9c04732005-07-07 23:21:43 +000050 Result.appendComponent(ExeName);
Reid Spencer5b891e92005-07-07 18:21:42 +000051 if (Result.canExecute())
Reid Spencerd44f8452004-12-19 18:00:09 +000052 return Result;
Chris Lattnerde4aa4c2002-12-23 23:50:16 +000053 }
54
Reid Spencerdc49d862004-12-13 23:41:37 +000055 return sys::Program::FindProgramByName(ExeName);
Chris Lattnerde4aa4c2002-12-23 23:50:16 +000056}