45fb9500cdf172725f09ec0152e75d614cde9f87
[oota-llvm.git] / include / llvm / System / Program.h
1 //===- llvm/System/Program.h ------------------------------------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the 
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the llvm::sys::Program class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_SYSTEM_PROGRAM_H
15 #define LLVM_SYSTEM_PROGRAM_H
16
17 #include "llvm/System/Path.h"
18 #include <vector>
19
20 namespace llvm {
21 namespace sys {
22
23   /// This class provides an abstraction for programs that are executable by the
24   /// operating system. It provides a platform generic way to find executable
25   /// programs from the path and to execute them in various ways. The sys::Path
26   /// class is used to specify the location of the Program.
27   /// @since 1.4
28   /// @brief An abstraction for finding and executing programs.
29   class Program {
30     /// @name Methods
31     /// @{
32     public:
33       /// This static constructor (factory) will attempt to locate a program in
34       /// the operating system's file system using some pre-determined set of 
35       /// locations to search (e.g. the PATH on Unix). 
36       /// @returns A Path object initialized to the path of the program or a
37       /// Path object that is empty (invalid) if the program could not be found.
38       /// @throws nothing
39       /// @brief Construct a Program by finding it by name.
40       static Path FindProgramByName(const std::string& name);
41
42       /// This function executes the program using the \p arguments provided and
43       /// waits for the program to exit. This function will block the current
44       /// program until the invoked program exits. The invoked program will 
45       /// inherit the stdin, stdout, and stderr file descriptors, the
46       /// environment and other configuration settings of the invoking program.
47       /// If Path::executable() does not return true when this function is
48       /// called then a std::string is thrown. 
49       /// @param path A sys::Path object providing the path of the program to be
50       /// executed. It is presumed this is the result of the FindProgramByName
51       /// method.
52       /// @returns an integer result code indicating the status of the program.
53       /// @throws std::string on a variety of error conditions or if the invoked
54       /// program aborted abnormally.
55       /// @see FindProgrambyName
56       /// @brief Executes the program with the given set of \p args.
57       static int ExecuteAndWait(
58         const Path& path,  ///< The path to the program to execute
59         const std::vector<std::string>& args,
60           ///< A vector of strings that are passed to the program.
61           ///< The first element should *not* be the name of the program.
62         const char ** env = 0
63           ///< An optional vector of strings to use for the program's 
64           ///< environment. If not provided, the current program's environment
65           ///< will be used.
66       );
67     /// @}
68   };
69 }
70 }
71
72 // vim: sw=2
73
74 #endif