From: Reid Spencer Date: Mon, 13 Dec 2004 17:01:53 +0000 (+0000) Subject: For PR351: \ X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=9d88d1aaab145e18c8e0fe93544f8a1ff0474866;p=oota-llvm.git For PR351: \ The getFileTimestamp and getFileSize functions have been removed from \ FileUtilities.{h,cpp}. They are replaced by Path::getTimestamp and \ Path::getSize,respectively. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18892 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Debugger/ProgramInfo.h b/include/llvm/Debugger/ProgramInfo.h index 4420e724189..f7ee77dc314 100644 --- a/include/llvm/Debugger/ProgramInfo.h +++ b/include/llvm/Debugger/ProgramInfo.h @@ -21,6 +21,7 @@ #ifndef LLVM_DEBUGGER_PROGRAMINFO_H #define LLVM_DEBUGGER_PROGRAMINFO_H +#include "llvm/System/TimeValue.h" #include #include #include @@ -133,7 +134,7 @@ namespace llvm { /// ProgramTimeStamp - This is the timestamp of the executable file that we /// currently have loaded into the debugger. - unsigned long long ProgramTimeStamp; + sys::TimeValue ProgramTimeStamp; /// SourceFiles - This map is used to transform source file descriptors into /// their corresponding SourceFileInfo objects. This mapping owns the @@ -170,7 +171,7 @@ namespace llvm { /// getProgramTimeStamp - Return the time-stamp of the program when it was /// loaded. - unsigned long long getProgramTimeStamp() const { return ProgramTimeStamp; } + sys::TimeValue getProgramTimeStamp() const { return ProgramTimeStamp; } //===------------------------------------------------------------------===// // Interfaces to the source code files that make up the program. diff --git a/include/llvm/Support/FileUtilities.h b/include/llvm/Support/FileUtilities.h index f61ee7c6405..885ee86c0d3 100644 --- a/include/llvm/Support/FileUtilities.h +++ b/include/llvm/Support/FileUtilities.h @@ -61,17 +61,6 @@ bool MakeFileExecutable(const std::string &Filename); /// bool MakeFileReadable(const std::string &Filename); -/// getFileSize - Return the size of the specified file in bytes, or -1 if the -/// file cannot be read or does not exist. -long long getFileSize(const std::string &Filename); - - -/// getFileTimestamp - Get the last modified time for the specified file in an -/// unspecified format. This is useful to allow checking to see if a file was -/// updated since that last time the timestampt was aquired. If the file does -/// not exist or there is an error getting the time-stamp, zero is returned. -unsigned long long getFileTimestamp(const std::string &Filename); - /// ReadFileIntoAddressSpace - Attempt to map the specific file into the /// address space of the current process for reading. If this succeeds, /// return the address of the buffer and the length of the file mapped. On diff --git a/include/llvm/System/Path.h b/include/llvm/System/Path.h index 10c8bccef88..57cbc6c64d9 100644 --- a/include/llvm/System/Path.h +++ b/include/llvm/System/Path.h @@ -376,6 +376,21 @@ namespace sys { /// @brief Get file status. void getStatusInfo(StatusInfo& info) const; + /// This function returns the last modified time stamp for the file + /// referenced by this path. The Path may reference a file or a directory. + /// If the file does not exist, a ZeroTime timestamp is returned. + /// @returns last modified timestamp of the file/directory or ZeroTime + /// @brief Get file timestamp. + inline TimeValue getTimestamp() const { + StatusInfo info; getStatusInfo(info); return info.modTime; + } + + /// This function returns the size of the file referenced by this path. + /// @brief Get file size. + inline size_t getSize() const { + StatusInfo info; getStatusInfo(info); return info.fileSize; + } + /// This method attempts to set the Path object to \p unverified_path /// and interpret the name as a directory name. The \p unverified_path /// is verified. If verification succeeds then \p unverified_path diff --git a/lib/Debugger/ProgramInfo.cpp b/lib/Debugger/ProgramInfo.cpp index c6e5d32b666..c0d85f97e45 100644 --- a/lib/Debugger/ProgramInfo.cpp +++ b/lib/Debugger/ProgramInfo.cpp @@ -236,9 +236,10 @@ void SourceFunctionInfo::getSourceLocation(unsigned &RetLineNo, // ProgramInfo implementation // -ProgramInfo::ProgramInfo(Module *m) : M(m) { +ProgramInfo::ProgramInfo(Module *m) : M(m), ProgramTimeStamp(0,0) { assert(M && "Cannot create program information with a null module!"); - ProgramTimeStamp = getFileTimestamp(M->getModuleIdentifier()); + sys::Path modulePath(M->getModuleIdentifier()); + ProgramTimeStamp = modulePath.getTimestamp(); SourceFilesIsComplete = false; SourceFunctionsIsComplete = false; diff --git a/lib/Support/FileUtilities.cpp b/lib/Support/FileUtilities.cpp index 5b7c56e950e..305f455937a 100644 --- a/lib/Support/FileUtilities.cpp +++ b/lib/Support/FileUtilities.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/FileUtilities.h" #include "llvm/Support/DataTypes.h" +#include "llvm/System/Path.h" #include "llvm/Config/unistd.h" #include "llvm/Config/fcntl.h" #include "llvm/Config/sys/types.h" @@ -195,26 +196,6 @@ bool llvm::MakeFileReadable(const std::string &Filename) { return AddPermissionsBits(Filename, 0444); } -/// getFileSize - Return the size of the specified file in bytes, or -1 if the -/// file cannot be read or does not exist. -long long llvm::getFileSize(const std::string &Filename) { - struct stat StatBuf; - if (stat(Filename.c_str(), &StatBuf) == -1) - return -1; - return StatBuf.st_size; -} - -/// getFileTimestamp - Get the last modified time for the specified file in an -/// unspecified format. This is useful to allow checking to see if a file was -/// updated since that last time the timestampt was aquired. If the file does -/// not exist or there is an error getting the time-stamp, zero is returned. -unsigned long long llvm::getFileTimestamp(const std::string &Filename) { - struct stat StatBuf; - if (stat(Filename.c_str(), &StatBuf) == -1) - return 0; - return StatBuf.st_mtime; -} - /// ReadFileIntoAddressSpace - Attempt to map the specific file into the /// address space of the current process for reading. If this succeeds, /// return the address of the buffer and the length of the file mapped. On @@ -222,7 +203,8 @@ unsigned long long llvm::getFileTimestamp(const std::string &Filename) { void *llvm::ReadFileIntoAddressSpace(const std::string &Filename, unsigned &Length) { #if defined(HAVE_MMAP_FILE) && !defined(_MSC_VER) - Length = (unsigned)getFileSize(Filename); + sys::Path File(Filename); + Length = (unsigned)File.getSize(); if ((int)Length == -1) return 0; FDHandle FD(open(Filename.c_str(), O_RDONLY)); diff --git a/tools/llvm-db/Commands.cpp b/tools/llvm-db/Commands.cpp index de7fdf604b7..37f8a782095 100644 --- a/tools/llvm-db/Commands.cpp +++ b/tools/llvm-db/Commands.cpp @@ -49,8 +49,8 @@ void CLIDebugger::startProgramRunning() { eliminateRunInfo(); // If the program has been modified, reload it! - std::string Program = Dbg.getProgramPath(); - if (TheProgramInfo->getProgramTimeStamp() != getFileTimestamp(Program)) { + sys::Path Program (Dbg.getProgramPath()); + if (TheProgramInfo->getProgramTimeStamp() != Program.getTimestamp()) { std::cout << "'" << Program << "' has changed; re-reading program.\n"; // Unload an existing program. This kills the program if necessary. @@ -59,7 +59,7 @@ void CLIDebugger::startProgramRunning() { TheProgramInfo = 0; CurrentFile = 0; - Dbg.loadProgram(Program); + Dbg.loadProgram(Program.toString()); TheProgramInfo = new ProgramInfo(Dbg.getProgram()); }