pull some win32 code into common code, add bitcode identification support.
authorChris Lattner <sabre@nondot.org>
Sun, 6 May 2007 05:32:21 +0000 (05:32 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 6 May 2007 05:32:21 +0000 (05:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36846 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Path.cpp
lib/System/Unix/Path.inc
lib/System/Win32/Path.inc

index 634ce5dabb0a938dac6105e47ee2fd868bb48579..fcdc5ff22cf3cec57474a8c97d6cf41ea064345b 100644 (file)
@@ -43,6 +43,10 @@ sys::IdentifyFileType(const char*magic, unsigned length) {
   assert(magic && "Invalid magic number string");
   assert(length >=4 && "Invalid magic number length");
   switch (magic[0]) {
+    case 'B':
+      if (magic[1] == 'C' && magic[2] == (char)0xC0 && magic[3] == (char)0xDE)
+        return Bitcode_FileType;
+      break;
     case 'l':
       if (magic[1] == 'l' && magic[2] == 'v') {
         if (magic[3] == 'c')
@@ -160,6 +164,31 @@ std::string Path::GetDLLSuffix() {
   return LTDL_SHLIB_EXT;
 }
 
+bool
+Path::isBytecodeFile() const {
+  std::string actualMagic;
+  if (!getMagicNumber(actualMagic, 4))
+    return false;
+  return actualMagic == "llvc" || actualMagic == "llvm";
+}
+
+bool
+Path::isBitcodeFile() const {
+  std::string actualMagic;
+  if (!getMagicNumber(actualMagic, 4))
+    return false;
+  return actualMagic == "BC\xC0\xDE";
+}
+
+bool Path::hasMagicNumber(const std::string &Magic) const {
+  std::string actualMagic;
+  if (getMagicNumber(actualMagic, Magic.size()))
+    return Magic == actualMagic;
+  return false;
+}
+
+
+
 // Include the truly platform-specific parts of this class.
 #if defined(LLVM_ON_UNIX)
 #include "Unix/Path.inc"
index 53906d99cec3186b157f6946797e0f66643b788e..db95e3c216c83ea7f13d7cdcb580631b4a001098 100644 (file)
@@ -267,21 +267,6 @@ Path::getBasename() const {
     return path.substr(slash, dot - slash);
 }
 
-bool Path::hasMagicNumber(const std::string &Magic) const {
-  size_t len = Magic.size();
-  assert(len < 1024 && "Request for magic string too long");
-  char* buf = (char*) alloca(1 + len);
-  int fd = ::open(path.c_str(), O_RDONLY);
-  if (fd < 0)
-    return false;
-  size_t read_len = ::read(fd, buf, len);
-  close(fd);
-  if (len != read_len)
-    return false;
-  buf[len] = '\0';
-  return Magic == buf;
-}
-
 bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
   assert(len < 1024 && "Request for magic string too long");
   char* buf = (char*) alloca(1 + len);
@@ -298,22 +283,6 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
   return true;
 }
 
-bool 
-Path::isBytecodeFile() const {
-  char buffer[4];
-  buffer[0] = 0;
-  int fd = ::open(path.c_str(), O_RDONLY);
-  if (fd < 0)
-    return false;
-  ssize_t bytes_read = ::read(fd, buffer, 4);
-  ::close(fd);
-  if (4 != bytes_read) 
-    return false;
-
-  return (buffer[0] == 'l' && buffer[1] == 'l' && buffer[2] == 'v' &&
-         (buffer[3] == 'c' || buffer[3] == 'm'));
-}
-
 bool
 Path::exists() const {
   return 0 == access(path.c_str(), F_OK );
index f28fe86b59b444b023e6926107000d3addec8c3d..67f16a75b60eb91ff88cd0e498ac62b1b24cdc25 100644 (file)
@@ -247,21 +247,6 @@ Path::getBasename() const {
     return path.substr(slash, dot - slash);
 }
 
-bool Path::hasMagicNumber(const std::string &Magic) const {
-  std::string actualMagic;
-  if (getMagicNumber(actualMagic, Magic.size()))
-    return Magic == actualMagic;
-  return false;
-}
-
-bool
-Path::isBytecodeFile() const {
-  std::string actualMagic;
-  if (!getMagicNumber(actualMagic, 4))
-    return false;
-  return actualMagic == "llvc" || actualMagic == "llvm";
-}
-
 bool
 Path::exists() const {
   DWORD attr = GetFileAttributes(path.c_str());