[llvm-commits] [llvm] r114032 - in /llvm/trunk: include/llvm/System/Path.h lib/System/Path.cpp

Michael J. Spencer bigcheesegs at gmail.com
Wed Sep 15 15:45:46 PDT 2010


Author: mspencer
Date: Wed Sep 15 17:45:45 2010
New Revision: 114032

URL: http://llvm.org/viewvc/llvm-project?rev=114032&view=rev
Log:
System/Path: Add isObjectFile().

Modified:
    llvm/trunk/include/llvm/System/Path.h
    llvm/trunk/lib/System/Path.cpp

Modified: llvm/trunk/include/llvm/System/Path.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Path.h?rev=114032&r1=114031&r2=114032&view=diff
==============================================================================
--- llvm/trunk/include/llvm/System/Path.h (original)
+++ llvm/trunk/include/llvm/System/Path.h Wed Sep 15 17:45:45 2010
@@ -342,6 +342,17 @@
       /// @brief Determine if the path references a dynamic library.
       bool isDynamicLibrary() const;
 
+      /// This function determines if the path name in the object references a
+      /// native object file by looking at it's magic number. The term object
+      /// file is defined as "an organized collection of separate, named
+      /// sequences of binary data." This covers the obvious file formats such as
+      /// COFF and ELF, but it also includes llvm ir bitcode, archives,
+      /// libraries, etc...
+      /// @returns true if the file starts with the magic number for an object
+      /// file.
+      /// @brief Determine if the path references an object file.
+      bool isObjectFile() const;
+
       /// This function determines if the path name references an existing file
       /// or directory in the file system.
       /// @returns true if the pathname references an existing file or

Modified: llvm/trunk/lib/System/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Path.cpp?rev=114032&r1=114031&r2=114032&view=diff
==============================================================================
--- llvm/trunk/lib/System/Path.cpp (original)
+++ llvm/trunk/lib/System/Path.cpp Wed Sep 15 17:45:45 2010
@@ -156,6 +156,20 @@
   return false;
 }
 
+bool
+Path::isObjectFile() const {
+  std::string Magic;
+  if (getMagicNumber(Magic, 64))
+    if (IdentifyFileType(Magic.c_str(),
+                         static_cast<unsigned>(Magic.length()))
+        != Unknown_FileType) {
+      // Everything in LLVMFileType is currently an object file.
+      return true;
+    }
+
+  return false;
+}
+
 Path
 Path::FindLibrary(std::string& name) {
   std::vector<sys::Path> LibPaths;





More information about the llvm-commits mailing list