b8c130cc9748dc6a5374637518e2d059c6822730
[oota-llvm.git] / include / Support / SystemUtils.h
1 //===- SystemUtils.h - Utilities to do low-level system stuff ---*- C++ -*-===//
2 // 
3 //                     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.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains functions used to do a variety of low-level, often
11 // system-specific, tasks.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef SYSTEMUTILS_H
16 #define SYSTEMUTILS_H
17
18 #include <string>
19
20 namespace llvm {
21
22 /// isExecutableFile - This function returns true if the filename specified
23 /// exists and is executable.
24 ///
25 bool isExecutableFile(const std::string &ExeFileName);
26
27 /// isStandardOutAConsole - Return true if we can tell that the standard output
28 /// stream goes to a terminal window or console.
29 bool isStandardOutAConsole();
30
31 /// FindExecutable - Find a named executable, giving the argv[0] of program
32 /// being executed. This allows us to find another LLVM tool if it is built into
33 /// the same directory, but that directory is neither the current directory, nor
34 /// in the PATH.  If the executable cannot be found, return an empty string.
35 /// 
36 std::string FindExecutable(const std::string &ExeName,
37                            const std::string &ProgramPath);
38
39 /// RunProgramWithTimeout - This function executes the specified program, with
40 /// the specified null-terminated argument array, with the stdin/out/err fd's
41 /// redirected, with a timeout specified by the last argument.  This terminates
42 /// the calling program if there is an error executing the specified program.
43 /// It returns the return value of the program, or -1 if a timeout is detected.
44 ///
45 int RunProgramWithTimeout(const std::string &ProgramPath, const char **Args,
46                           const std::string &StdInFile = "",
47                           const std::string &StdOutFile = "",
48                           const std::string &StdErrFile = "",
49                           unsigned NumSeconds = 0);
50
51 /// ExecWait - Execute a program with the given arguments and environment and 
52 /// wait for it to terminate.
53 ///
54 int ExecWait (const char * const argv[], const char * const envp[]);
55
56 /// AllocateRWXMemory - Allocate a slab of memory with read/write/execute
57 /// permissions.  This is typically used for JIT applications where we want
58 /// to emit code to the memory then jump to it.  Getting this type of memory
59 /// is very OS specific.
60 ///
61 void *AllocateRWXMemory(unsigned NumBytes);
62
63 } // End llvm namespace
64
65 #endif