LCOV - code coverage report
Current view: top level - lib/Support - Program.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 17 17 100.0 %
Date: 2017-09-14 15:23:50 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 file implements the operating system Program concept.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "llvm/Support/Program.h"
      15             : #include "llvm/ADT/StringRef.h"
      16             : #include "llvm/Config/config.h"
      17             : #include <system_error>
      18             : using namespace llvm;
      19             : using namespace sys;
      20             : 
      21             : //===----------------------------------------------------------------------===//
      22             : //=== WARNING: Implementation here must contain only TRULY operating system
      23             : //===          independent code.
      24             : //===----------------------------------------------------------------------===//
      25             : 
      26             : static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args,
      27             :                     const char **Env, ArrayRef<Optional<StringRef>> Redirects,
      28             :                     unsigned MemoryLimit, std::string *ErrMsg);
      29             : 
      30        5251 : int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp,
      31             :                         ArrayRef<Optional<StringRef>> Redirects,
      32             :                         unsigned SecondsToWait, unsigned MemoryLimit,
      33             :                         std::string *ErrMsg, bool *ExecutionFailed) {
      34             :   assert(Redirects.empty() || Redirects.size() == 3);
      35        5251 :   ProcessInfo PI;
      36        5251 :   if (Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg)) {
      37        5248 :     if (ExecutionFailed)
      38        1109 :       *ExecutionFailed = false;
      39             :     ProcessInfo Result = Wait(
      40        5248 :         PI, SecondsToWait, /*WaitUntilTerminates=*/SecondsToWait == 0, ErrMsg);
      41        5248 :     return Result.ReturnCode;
      42             :   }
      43             : 
      44           3 :   if (ExecutionFailed)
      45           2 :     *ExecutionFailed = true;
      46             : 
      47             :   return -1;
      48             : }
      49             : 
      50           3 : ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **Args,
      51             :                                const char **Envp,
      52             :                                ArrayRef<Optional<StringRef>> Redirects,
      53             :                                unsigned MemoryLimit, std::string *ErrMsg,
      54             :                                bool *ExecutionFailed) {
      55             :   assert(Redirects.empty() || Redirects.size() == 3);
      56           3 :   ProcessInfo PI;
      57           3 :   if (ExecutionFailed)
      58           3 :     *ExecutionFailed = false;
      59           3 :   if (!Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg))
      60           1 :     if (ExecutionFailed)
      61           1 :       *ExecutionFailed = true;
      62             : 
      63           3 :   return PI;
      64             : }
      65             : 
      66             : // Include the platform-specific parts of this class.
      67             : #ifdef LLVM_ON_UNIX
      68             : #include "Unix/Program.inc"
      69             : #endif
      70             : #ifdef LLVM_ON_WIN32
      71             : #include "Windows/Program.inc"
      72             : #endif

Generated by: LCOV version 1.13