comparison lib/Support/Program.cpp @ 0:95c75e76d11b

LLVM 3.4
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Thu, 12 Dec 2013 13:56:28 +0900
parents
children 54457678186b
comparison
equal deleted inserted replaced
-1:000000000000 0:95c75e76d11b
1 //===-- Program.cpp - Implement OS Program Concept --------------*- 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 header file implements the operating system Program concept.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/Support/Program.h"
15 #include "llvm/Config/config.h"
16 #include "llvm/Support/system_error.h"
17 using namespace llvm;
18 using namespace sys;
19
20 //===----------------------------------------------------------------------===//
21 //=== WARNING: Implementation here must contain only TRULY operating system
22 //=== independent code.
23 //===----------------------------------------------------------------------===//
24
25 static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
26 const char **env, const StringRef **Redirects,
27 unsigned memoryLimit, std::string *ErrMsg);
28
29 int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
30 const StringRef **redirects, unsigned secondsToWait,
31 unsigned memoryLimit, std::string *ErrMsg,
32 bool *ExecutionFailed) {
33 ProcessInfo PI;
34 if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
35 if (ExecutionFailed)
36 *ExecutionFailed = false;
37 ProcessInfo Result = Wait(PI, secondsToWait, true, ErrMsg);
38 return Result.ReturnCode;
39 }
40
41 if (ExecutionFailed)
42 *ExecutionFailed = true;
43
44 return -1;
45 }
46
47 ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args,
48 const char **envp, const StringRef **redirects,
49 unsigned memoryLimit, std::string *ErrMsg,
50 bool *ExecutionFailed) {
51 ProcessInfo PI;
52 if (ExecutionFailed)
53 *ExecutionFailed = false;
54 if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
55 if (ExecutionFailed)
56 *ExecutionFailed = true;
57
58 return PI;
59 }
60
61 // Include the platform-specific parts of this class.
62 #ifdef LLVM_ON_UNIX
63 #include "Unix/Program.inc"
64 #endif
65 #ifdef LLVM_ON_WIN32
66 #include "Windows/Program.inc"
67 #endif