2
0

Program.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include "llvm/Support/Program.h"
  14. #include "llvm/ADT/StringRef.h"
  15. #include "llvm/Config/config.h"
  16. #include <system_error>
  17. using namespace llvm;
  18. using namespace sys;
  19. //===----------------------------------------------------------------------===//
  20. //=== WARNING: Implementation here must contain only TRULY operating system
  21. //=== independent code.
  22. //===----------------------------------------------------------------------===//
  23. #if defined(MSFT_SUPPORTS_CHILD_PROCESSES) || defined(LLVM_ON_UNIX)
  24. static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
  25. const char **env, const StringRef **Redirects,
  26. unsigned memoryLimit, std::string *ErrMsg);
  27. int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
  28. const StringRef **redirects, unsigned secondsToWait,
  29. unsigned memoryLimit, std::string *ErrMsg,
  30. bool *ExecutionFailed) {
  31. ProcessInfo PI;
  32. if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
  33. if (ExecutionFailed)
  34. *ExecutionFailed = false;
  35. ProcessInfo Result = Wait(
  36. PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg);
  37. return Result.ReturnCode;
  38. }
  39. if (ExecutionFailed)
  40. *ExecutionFailed = true;
  41. return -1;
  42. }
  43. ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args,
  44. const char **envp, const StringRef **redirects,
  45. unsigned memoryLimit, std::string *ErrMsg,
  46. bool *ExecutionFailed) {
  47. ProcessInfo PI;
  48. if (ExecutionFailed)
  49. *ExecutionFailed = false;
  50. if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
  51. if (ExecutionFailed)
  52. *ExecutionFailed = true;
  53. return PI;
  54. }
  55. #endif // MSFT_SUPPORTS_CHILD_PROCESSES
  56. // Include the platform-specific parts of this class.
  57. #ifdef LLVM_ON_UNIX
  58. #include "Unix/Program.inc"
  59. #endif
  60. #ifdef LLVM_ON_WIN32
  61. #include "Windows/Program.inc"
  62. #endif