LLVM API Documentation
00001 //===- llvm/System/Program.h ------------------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the llvm::sys::Program class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_SYSTEM_PROGRAM_H 00015 #define LLVM_SYSTEM_PROGRAM_H 00016 00017 #include "llvm/System/Path.h" 00018 00019 namespace llvm { 00020 namespace sys { 00021 00022 /// This class provides an abstraction for programs that are executable by the 00023 /// operating system. It provides a platform generic way to find executable 00024 /// programs from the path and to execute them in various ways. The sys::Path 00025 /// class is used to specify the location of the Program. 00026 /// @since 1.4 00027 /// @brief An abstraction for finding and executing programs. 00028 class Program { 00029 /// @name Methods 00030 /// @{ 00031 public: 00032 /// This static constructor (factory) will attempt to locate a program in 00033 /// the operating system's file system using some pre-determined set of 00034 /// locations to search (e.g. the PATH on Unix). 00035 /// @returns A Path object initialized to the path of the program or a 00036 /// Path object that is empty (invalid) if the program could not be found. 00037 /// @throws nothing 00038 /// @brief Construct a Program by finding it by name. 00039 static Path FindProgramByName(const std::string& name); 00040 00041 /// This function executes the program using the \p arguments provided and 00042 /// waits for the program to exit. This function will block the current 00043 /// program until the invoked program exits. The invoked program will 00044 /// inherit the stdin, stdout, and stderr file descriptors, the 00045 /// environment and other configuration settings of the invoking program. 00046 /// If Path::executable() does not return true when this function is 00047 /// called then a std::string is thrown. 00048 /// @returns an integer result code indicating the status of the program. 00049 /// A zero or positive value indicates the result code of the program. A 00050 /// negative value is the signal number on which it terminated. 00051 /// @see FindProgrambyName 00052 /// @brief Executes the program with the given set of \p args. 00053 static int ExecuteAndWait( 00054 const Path& path, ///< sys::Path object providing the path of the 00055 ///< program to be executed. It is presumed this is the result of 00056 ///< the FindProgramByName method. 00057 const char** args, ///< A vector of strings that are passed to the 00058 ///< program. The first element should be the name of the program. 00059 ///< The list *must* be terminated by a null char* entry. 00060 const char ** env = 0, ///< An optional vector of strings to use for 00061 ///< the program's environment. If not provided, the current program's 00062 ///< environment will be used. 00063 const sys::Path** redirects = 0, ///< An optional array of pointers to 00064 ///< Paths. If the array is null, no redirection is done. The array 00065 ///< should have a size of at least three. If the pointer in the array 00066 ///< are not null, then the inferior process's stdin(0), stdout(1), 00067 ///< and stderr(2) will be redirected to the corresponding Paths. 00068 ///< When an empty Path is passed in, the corresponding file 00069 ///< descriptor will be disconnected (ie, /dev/null'd) in a portable 00070 ///< way. 00071 unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount 00072 ///< of time to wait for the child process to exit. If the time 00073 ///< expires, the child is killed and this call returns. If zero, 00074 ///< this function will wait until the child finishes or forever if 00075 ///< it doesn't. 00076 unsigned memoryLimit = 0, ///< If non-zero, this specifies max. amount 00077 ///< of memory can be allocated by process. If memory usage will be 00078 ///< higher limit, the child is killed and this call returns. If zero - 00079 ///< no memory limit. 00080 std::string* ErrMsg = 0 ///< If non-zero, provides a pointer to a string 00081 ///< instance in which error messages will be returned. If the string 00082 ///< is non-empty upon return an error occurred while invoking the 00083 ///< program. 00084 ); 00085 // These methods change the specified standard stream (stdin or stdout) to 00086 // binary mode. They return true if an error occurred 00087 static bool ChangeStdinToBinary(); 00088 static bool ChangeStdoutToBinary(); 00089 /// @} 00090 }; 00091 } 00092 } 00093 00094 #endif
This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.