LLVM API Documentation
00001 //===- llvm/System/Program.h ------------------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by Reid Spencer and is distributed under the 00006 // University of Illinois Open Source 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 #include <vector> 00019 00020 namespace llvm { 00021 namespace sys { 00022 00023 /// This class provides an abstraction for programs that are executable by the 00024 /// operating system. It provides a platform generic way to find executable 00025 /// programs from the path and to execute them. The sys::Path class is used to 00026 /// locate the Program. 00027 /// @since 1.4 00028 /// @brief An abstraction for finding and executing programs. 00029 class Program { 00030 /// @name Methods 00031 /// @{ 00032 public: 00033 /// This static constructor (factory) will attempt to locate a program in 00034 /// the operating system's file system using some pre-determined set of 00035 /// locations to search (e.g. the PATH on Unix). 00036 /// @returns A Path object initialized to the path of the program or a 00037 /// Path object that is empty (invalid) if the program could not be found. 00038 /// @throws nothing 00039 /// @brief Construct a Program by finding it by name. 00040 static Path FindProgramByName(const std::string& name); 00041 00042 /// This function executes the program using the \p arguments provided and 00043 /// waits for the program to exit. This function will block the current 00044 /// program until the invoked program exits. The invoked program will 00045 /// inherit the stdin, stdout, and stderr file descriptors, the 00046 /// environment and other configuration settings of the inoking program. 00047 /// If Path::executable() does not return true when this function is 00048 /// called then a std::string is thrown. 00049 /// Path::executable() returns true. 00050 /// @param path A sys::Path object providing the path of the program to be 00051 /// executed. It is presumed this is the result of the FindProgramByName 00052 /// method. 00053 /// @param args A vector of strings that are passed to the program. 00054 /// The first element should *not* be the name of the program. 00055 /// @returns an integer result code indicating the status of the program. 00056 /// @throws std::string on a variety of error conditions or if the invoked 00057 /// program aborted abnormally. 00058 /// @see FindProgrambyName 00059 /// @brief Executes the program with the given set of \p arguments. 00060 static int ExecuteAndWait(const Path& path, 00061 const std::vector<std::string>& args); 00062 /// @} 00063 }; 00064 } 00065 } 00066 00067 // vim: sw=2 00068 00069 #endif