summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2010-09-15 22:45:45 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2010-09-15 22:45:45 +0000
commit33e7e5d89bbcbbed862821fccb98018fe116b99d (patch)
treed42ae6f4e8df10e00406e4ef226cc6bc14e28c73 /llvm
parentd5e111c2c16d0f79264546bb9ca2bae467b2a171 (diff)
downloadbcm5719-llvm-33e7e5d89bbcbbed862821fccb98018fe116b99d.tar.gz
bcm5719-llvm-33e7e5d89bbcbbed862821fccb98018fe116b99d.zip
System/Path: Add isObjectFile().
llvm-svn: 114032
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/System/Path.h11
-rw-r--r--llvm/lib/System/Path.cpp14
2 files changed, 25 insertions, 0 deletions
diff --git a/llvm/include/llvm/System/Path.h b/llvm/include/llvm/System/Path.h
index 23b18d47145..27fa2c3f4fc 100644
--- a/llvm/include/llvm/System/Path.h
+++ b/llvm/include/llvm/System/Path.h
@@ -342,6 +342,17 @@ namespace sys {
/// @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
diff --git a/llvm/lib/System/Path.cpp b/llvm/lib/System/Path.cpp
index 4445c667d86..0026fd29df5 100644
--- a/llvm/lib/System/Path.cpp
+++ b/llvm/lib/System/Path.cpp
@@ -156,6 +156,20 @@ Path::isDynamicLibrary() const {
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;
OpenPOWER on IntegriCloud