Remove an unused method on the Program class.
[oota-llvm.git] / include / llvm / Support / Program.h
1 //===- llvm/Support/Program.h ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // 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/Support/Path.h"
18
19 namespace llvm {
20 class error_code;
21 namespace sys {
22
23   // TODO: Add operations to communicate with the process, redirect its I/O,
24   // etc.
25
26   /// This class provides an abstraction for programs that are executable by the
27   /// operating system. It provides a platform generic way to find executable
28   /// programs from the path and to execute them in various ways. The sys::Path
29   /// class is used to specify the location of the Program.
30   /// @since 1.4
31   /// @brief An abstraction for finding and executing programs.
32   class Program {
33     /// Opaque handle for target specific data.
34     void *Data_;
35
36     // Noncopyable.
37     Program(const Program& other) LLVM_DELETED_FUNCTION;
38     Program& operator=(const Program& other) LLVM_DELETED_FUNCTION;
39
40     /// @name Methods
41     /// @{
42   public:
43
44     Program();
45     ~Program();
46
47     /// This function executes the program using the \p arguments provided.  The
48     /// invoked program will inherit the stdin, stdout, and stderr file
49     /// descriptors, the environment and other configuration settings of the
50     /// invoking program. If Path::executable() does not return true when this
51     /// function is called then a std::string is thrown.
52     /// @returns false in case of error, true otherwise.
53     /// @see FindProgramByName
54     /// @brief Executes the program with the given set of \p args.
55     bool Execute
56     ( const Path& path,  ///< sys::Path object providing the path of the
57       ///< program to be executed. It is presumed this is the result of
58       ///< the FindProgramByName method.
59       const char** args, ///< A vector of strings that are passed to the
60       ///< program.  The first element should be the name of the program.
61       ///< The list *must* be terminated by a null char* entry.
62       const char ** env = 0, ///< An optional vector of strings to use for
63       ///< the program's environment. If not provided, the current program's
64       ///< environment will be used.
65       const sys::Path** redirects = 0, ///< An optional array of pointers to
66       ///< Paths. If the array is null, no redirection is done. The array
67       ///< should have a size of at least three. If the pointer in the array
68       ///< are not null, then the inferior process's stdin(0), stdout(1),
69       ///< and stderr(2) will be redirected to the corresponding Paths.
70       ///< When an empty Path is passed in, the corresponding file
71       ///< descriptor will be disconnected (ie, /dev/null'd) in a portable
72       ///< way.
73       unsigned memoryLimit = 0, ///< If non-zero, this specifies max. amount
74       ///< of memory can be allocated by process. If memory usage will be
75       ///< higher limit, the child is killed and this call returns. If zero
76       ///< - no memory limit.
77       std::string* ErrMsg = 0 ///< If non-zero, provides a pointer to a string
78       ///< instance in which error messages will be returned. If the string
79       ///< is non-empty upon return an error occurred while invoking the
80       ///< program.
81       );
82
83     /// This function waits for the program to exit. This function will block
84     /// the current program until the invoked program exits.
85     /// @returns an integer result code indicating the status of the program.
86     /// A zero or positive value indicates the result code of the program.
87     /// -1 indicates failure to execute
88     /// -2 indicates a crash during execution or timeout
89     /// @see Execute
90     /// @brief Waits for the program to exit.
91     int Wait
92     ( const Path& path, ///< The path to the child process executable.
93       unsigned secondsToWait, ///< If non-zero, this specifies the amount
94       ///< of time to wait for the child process to exit. If the time
95       ///< expires, the child is killed and this call returns. If zero,
96       ///< this function will wait until the child finishes or forever if
97       ///< it doesn't.
98       std::string* ErrMsg ///< If non-zero, provides a pointer to a string
99       ///< instance in which error messages will be returned. If the string
100       ///< is non-empty upon return an error occurred while waiting.
101       );
102
103     /// This function terminates the program.
104     /// @returns true if an error occurred.
105     /// @see Execute
106     /// @brief Terminates the program.
107     bool Kill
108     ( std::string* ErrMsg = 0 ///< If non-zero, provides a pointer to a string
109       ///< instance in which error messages will be returned. If the string
110       ///< is non-empty upon return an error occurred while killing the
111       ///< program.
112       );
113
114     /// This static constructor (factory) will attempt to locate a program in
115     /// the operating system's file system using some pre-determined set of
116     /// locations to search (e.g. the PATH on Unix). Paths with slashes are
117     /// returned unmodified.
118     /// @returns A Path object initialized to the path of the program or a
119     /// Path object that is empty (invalid) if the program could not be found.
120     /// @brief Construct a Program by finding it by name.
121     static Path FindProgramByName(const std::string& name);
122
123     // These methods change the specified standard stream (stdin, stdout, or
124     // stderr) to binary mode. They return errc::success if the specified stream
125     // was changed. Otherwise a platform dependent error is returned.
126     static error_code ChangeStdinToBinary();
127     static error_code ChangeStdoutToBinary();
128     static error_code ChangeStderrToBinary();
129
130     /// A convenience function equivalent to Program prg; prg.Execute(..);
131     /// prg.Wait(..);
132     /// @see Execute, Wait
133     static int ExecuteAndWait(const Path& path,
134                               const char** args,
135                               const char ** env = 0,
136                               const sys::Path** redirects = 0,
137                               unsigned secondsToWait = 0,
138                               unsigned memoryLimit = 0,
139                               std::string* ErrMsg = 0);
140
141     /// A convenience function equivalent to Program prg; prg.Execute(..);
142     /// @see Execute
143     static void ExecuteNoWait(const Path& path,
144                               const char** args,
145                               const char ** env = 0,
146                               const sys::Path** redirects = 0,
147                               unsigned memoryLimit = 0,
148                               std::string* ErrMsg = 0);
149
150     /// @}
151
152   };
153 }
154 }
155
156 #endif