X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FSupport%2FProcess.cpp;h=ad67e1b10b48b95241a1bcd42f4118f47995e57a;hb=3f0e8837be1414981558186f9688c4ff35dc1815;hp=1360842753d078e118f3a76ea6ef18054bc9b2eb;hpb=8753ba91d28cd0fe7e6767466dec320b1fe2af86;p=oota-llvm.git diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 1360842753d..ad67e1b10b4 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -7,18 +7,16 @@ // //===----------------------------------------------------------------------===// // -// This header file implements the operating system Process concept. +// This file implements the operating system Process concept. // //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringExtras.h" #include "llvm/Config/config.h" -#if LLVM_ON_WIN32 - // This define makes stdlib.h declare the rand_s function. -#define _CRT_RAND_S -#include -#endif #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Process.h" +#include "llvm/Support/Program.h" using namespace llvm; using namespace sys; @@ -28,33 +26,6 @@ using namespace sys; //=== independent code. //===----------------------------------------------------------------------===// -// Empty virtual destructor to anchor the vtable for the process class. -process::~process() {} - -self_process *process::get_self() { - // Use a function local static for thread safe initialization and allocate it - // as a raw pointer to ensure it is never destroyed. - static self_process *SP = new self_process(); - - return SP; -} - -#if defined(_MSC_VER) -// Visual Studio complains that the self_process destructor never exits. This -// doesn't make much sense, as that's the whole point of calling abort... Just -// silence this warning. -#pragma warning(push) -#pragma warning(disable:4722) -#endif - -// The destructor for the self_process subclass must never actually be -// executed. There should be at most one instance of this class, and that -// instance should live until the process terminates to avoid the potential for -// racy accesses during shutdown. -self_process::~self_process() { - llvm_unreachable("This destructor must never be executed!"); -} - /// \brief A helper function to compute the elapsed wall-time since the program /// started. /// @@ -73,16 +44,32 @@ static TimeValue getElapsedWallTime() { /// create race conditions during program startup or shutdown. static volatile TimeValue DummyTimeValue = getElapsedWallTime(); -// Implement this routine by using the static helpers above. They're already -// portable. -TimeValue self_process::get_wall_time() const { - return getElapsedWallTime(); -} - +Optional Process::FindInEnvPath(const std::string& EnvName, + const std::string& FileName) +{ + Optional FoundPath; + Optional OptPath = Process::GetEnv(EnvName); + if (!OptPath.hasValue()) + return FoundPath; + + const char EnvPathSeparatorStr[] = {EnvPathSeparator, '\0'}; + SmallVector Dirs; + SplitString(OptPath.getValue(), Dirs, EnvPathSeparatorStr); + + for (const auto &Dir : Dirs) { + if (Dir.empty()) + continue; + + SmallString<128> FilePath(Dir); + path::append(FilePath, FileName); + if (fs::exists(Twine(FilePath))) { + FoundPath = FilePath.str(); + break; + } + } -#if defined(_MSC_VER) -#pragma warning(pop) -#endif + return FoundPath; +} #define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m"