blob: 3d3649eaebabfe4403c2bd148d2f596d58a96f2b [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//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// 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"
Chris Lattnerc521f542009-08-23 22:45:37 +000018#include "llvm/Support/raw_ostream.h"
Chris Lattnerc9499b62003-12-14 21:35:53 +000019using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000020
Chris Lattnerb9f25f92009-08-23 21:36:09 +000021bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
Dan Gohman69353322009-07-15 17:04:50 +000022 bool print_warning) {
Chris Lattnerb9f25f92009-08-23 21:36:09 +000023 if (&stream_to_check == &outs() &&
Dan Gohman69353322009-07-15 17:04:50 +000024 sys::Process::StandardOutIsDisplayed()) {
25 if (print_warning) {
Chris Lattnerb9f25f92009-08-23 21:36:09 +000026 errs() << "WARNING: You're attempting to print out a bitcode file.\n"
27 << "This is inadvisable as it may cause display problems. If\n"
28 << "you REALLY want to taste LLVM bitcode first-hand, you\n"
29 << "can force output with the `-f' option.\n\n";
Reid Spencer4e8dd442005-01-02 00:10:03 +000030 }
Reid Spencer1263cfd2005-01-01 23:56:20 +000031 return true;
32 }
Brian Gaeke5ade5012004-04-02 21:26:04 +000033 return false;
Chris Lattner454e1832004-04-02 05:04:03 +000034}
35
Misha Brukmane4d58ec2003-08-07 21:34:25 +000036/// FindExecutable - Find a named executable, giving the argv[0] of program
Dan Gohman46ffffa2009-08-05 20:21:17 +000037/// being executed. This allows us to find another LLVM tool if it is built in
38/// the same directory. If the executable cannot be found, return an
39/// empty string.
40/// @brief Find a named executable.
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,
Dan Gohman46ffffa2009-08-05 20:21:17 +000043 const char *Argv0, void *MainAddr) {
44 // Check the directory that the calling program is in. We can do
Daniel Dunbarb8f779d2009-07-01 15:26:13 +000045 // this if ProgramPath contains at least one / character, indicating that it
Daniel Dunbardf555fd2009-07-12 20:23:56 +000046 // is a relative path to the executable itself.
Dan Gohman46ffffa2009-08-05 20:21:17 +000047 sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
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
Dan Gohman46ffffa2009-08-05 20:21:17 +000055 return sys::Path();
Chris Lattnerde4aa4c2002-12-23 23:50:16 +000056}