blob: ff076637ab5a9346b343296ebd656a930aba4772 [file] [log] [blame]
Misha Brukmanebb0faa2004-06-18 15:38:49 +00001//===- SystemUtils.cpp - Utilities for low-level system tasks -------------===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Brukmanf976c852005-04-21 22:55:34 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner4a106452002-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 Spencer551ccae2004-09-01 22:55:40 +000015#include "llvm/Support/SystemUtils.h"
Reid Spencer436f23e2005-01-01 23:56:20 +000016#include "llvm/System/Process.h"
Misha Brukmandca79782005-04-22 19:13:22 +000017#include "llvm/System/Program.h"
Chris Lattner74382b72009-08-23 22:45:37 +000018#include "llvm/Support/raw_ostream.h"
Chris Lattner2cdd21c2003-12-14 21:35:53 +000019using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000020
Chris Lattnerb683ea42009-08-23 21:36:09 +000021bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
Dan Gohmand890de12009-07-15 17:04:50 +000022 bool print_warning) {
Dan Gohmanec080462009-09-11 20:46:33 +000023 if (stream_to_check.is_displayed()) {
Dan Gohmand890de12009-07-15 17:04:50 +000024 if (print_warning) {
Chris Lattnerb683ea42009-08-23 21:36:09 +000025 errs() << "WARNING: You're attempting to print out a bitcode file.\n"
Dan Gohman303f3502010-11-03 00:24:33 +000026 "This is inadvisable as it may cause display problems. If\n"
27 "you REALLY want to taste LLVM bitcode first-hand, you\n"
28 "can force output with the `-f' option.\n\n";
Reid Spencer52b50a62005-01-02 00:10:03 +000029 }
Reid Spencer436f23e2005-01-01 23:56:20 +000030 return true;
31 }
Brian Gaeke8507ecb2004-04-02 21:26:04 +000032 return false;
Chris Lattnerb234d462004-04-02 05:04:03 +000033}
34
Mikhail Glushenkov345b3442010-11-02 20:32:46 +000035/// FindExecutable - Find a named executable, given the value of argv[0] of the
36/// program being executed and the address of main itself. This allows us to
37/// find another LLVM tool if it is built in the same directory. An empty string
38/// is returned on error.
Chris Lattner49f61c42004-05-28 01:20:58 +000039#undef FindExecutable // needed on windows :(
Reid Spencer9665e8a2004-12-13 23:41:37 +000040sys::Path llvm::FindExecutable(const std::string &ExeName,
Dan Gohman197f7282009-08-05 20:21:17 +000041 const char *Argv0, void *MainAddr) {
42 // Check the directory that the calling program is in. We can do
Daniel Dunbar93696a32009-07-01 15:26:13 +000043 // this if ProgramPath contains at least one / character, indicating that it
Daniel Dunbara00e85c2009-07-12 20:23:56 +000044 // is a relative path to the executable itself.
Dan Gohman197f7282009-08-05 20:21:17 +000045 sys::Path Result = sys::Path::GetMainExecutable(Argv0, MainAddr);
Reid Spencerdd04df02005-07-07 23:21:43 +000046 Result.eraseComponent();
Mikhail Glushenkov345b3442010-11-02 20:32:46 +000047
Reid Spencer9665e8a2004-12-13 23:41:37 +000048 if (!Result.isEmpty()) {
Reid Spencerdd04df02005-07-07 23:21:43 +000049 Result.appendComponent(ExeName);
Mikhail Glushenkoved724fd2010-11-02 22:18:28 +000050 Result.appendSuffix(sys::Path::GetEXESuffix());
Chris Lattner4a106452002-12-23 23:50:16 +000051 }
52
Mikhail Glushenkov8a5ff472010-10-28 19:33:04 +000053 return Result;
Chris Lattner4a106452002-12-23 23:50:16 +000054}