LLVM API Documentation

Program.h

Go to the documentation of this file.
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 "llvm/System/IncludeFile.h"
00019 #include <vector>
00020 
00021 namespace llvm {
00022 namespace sys {
00023 
00024   /// This class provides an abstraction for programs that are executable by the
00025   /// operating system. It provides a platform generic way to find executable
00026   /// programs from the path and to execute them in various ways. The sys::Path
00027   /// class is used to specify the location of the Program.
00028   /// @since 1.4
00029   /// @brief An abstraction for finding and executing programs.
00030   class Program {
00031     /// @name Methods
00032     /// @{
00033     public:
00034       /// This static constructor (factory) will attempt to locate a program in
00035       /// the operating system's file system using some pre-determined set of
00036       /// locations to search (e.g. the PATH on Unix).
00037       /// @returns A Path object initialized to the path of the program or a
00038       /// Path object that is empty (invalid) if the program could not be found.
00039       /// @throws nothing
00040       /// @brief Construct a Program by finding it by name.
00041       static Path FindProgramByName(const std::string& name);
00042 
00043       /// This function executes the program using the \p arguments provided and
00044       /// waits for the program to exit. This function will block the current
00045       /// program until the invoked program exits. The invoked program will
00046       /// inherit the stdin, stdout, and stderr file descriptors, the
00047       /// environment and other configuration settings of the invoking program.
00048       /// If Path::executable() does not return true when this function is
00049       /// called then a std::string is thrown.
00050       /// @returns an integer result code indicating the status of the program.
00051       /// A zero or positive value indicates the result code of the program. A
00052       /// negative value is the signal number on which it terminated.
00053       /// @throws std::string on a variety of error conditions or if the invoked
00054       /// program aborted abnormally.
00055       /// @see FindProgrambyName
00056       /// @brief Executes the program with the given set of \p args.
00057       static int ExecuteAndWait(
00058         const Path& path,  ///< sys::Path object providing the path of the 
00059           ///< program to be executed. It is presumed this is the result of 
00060           ///< the FindProgramByName method.
00061         const char** args, ///< A vector of strings that are passed to the
00062           ///< program.  The first element should be the name of the program.
00063           ///< The list *must* be terminated by a null char* entry.
00064         const char ** env = 0, ///< An optional vector of strings to use for
00065           ///< the program's environment. If not provided, the current program's
00066           ///< environment will be used.
00067         const sys::Path** redirects = 0, ///< An optional array of pointers to
00068           ///< Paths. If the array is null, no redirection is done. The array
00069           ///< should have a size of at least three. If the pointer in the array
00070           ///< are not null, then the inferior process's stdin(0), stdout(1),
00071           ///< and stderr(2) will be redirected to the corresponding Paths.
00072         unsigned secondsToWait = 0 ///< If non-zero, this specifies the amount
00073           ///< of time to wait for the child process to exit. If the time
00074           ///< expires, the child is killed and this call returns. If zero,
00075           ///< this function will wait until the child finishes or forever if
00076           ///< it doesn't.
00077       );
00078       // These methods change the specified standard stream (stdin or stdout) to
00079       // binary mode.
00080       static void ChangeStdinToBinary();
00081       static void ChangeStdoutToBinary();
00082   };
00083 }
00084 }
00085 
00086 FORCE_DEFINING_FILE_TO_BE_LINKED(SystemProgram)
00087 
00088 #endif