Added separate alias instructions for SSE logical ops that operate on non-packed...
[oota-llvm.git] / lib / System / Path.cpp
index a0c76dbd20626cdbe2796067e1133a87262fc48e..9ee0a3e852785261a93bd63b40f86ac2f6e2a90d 100644 (file)
-//===- Path.cpp - Path Operating System Concept -----------------*- C++ -*-===//
+//===-- Path.cpp - Implement OS Path Concept --------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
-// Copyright (C) 2004 eXtensible Systems, Inc. All Rights Reserved.
-//
-// This program is open source software; you can redistribute it and/or modify
-// it under the terms of the University of Illinois Open Source License. See
-// LICENSE.TXT (distributed with this software) for details.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-// or FITNESS FOR A PARTICULAR PURPOSE.
+// This file was developed by Reid Spencer and is distributed under the
+// University of Illinois Open Source License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-// 
-// This file implements the common Path concept for a variety of platforms.
-// A path is simply the name of some file system storage place. Paths can be
-// either directories or files.
 //
-//===----------------------------------------------------------------------===//
-/// @file lib/System/Path.cpp
-/// @author Reid Spencer <raspencer@x10sys.com> (original author)
-/// @version \verbatim $Id$ \endverbatim
-/// @date 2004/08/14
-/// @since 1.4
-/// @brief Defines the llvm::sys::Path class.
+//  This header file implements the operating system Path concept.
+//
 //===----------------------------------------------------------------------===//
 
 #include "llvm/System/Path.h"
+#include "llvm/Config/config.h"
+#include <cassert>
 
 namespace llvm {
-namespace sys {
+using namespace sys;
 
-ErrorCode
-Path::append_directory( const std::string& dirname ) throw() {
-  this->append( dirname );
-  make_directory();
-  return NOT_AN_ERROR;
-}
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only TRULY operating system
+//===          independent code.
+//===----------------------------------------------------------------------===//
 
-ErrorCode
-Path::append_file( const std::string& filename ) throw() {
-  this->append( filename );
-  return NOT_AN_ERROR;
+Path
+Path::GetLLVMConfigDir() {
+  Path result;
+#ifdef LLVM_ETCDIR
+  if (result.set(LLVM_ETCDIR))
+    return result;
+#endif
+  return GetLLVMDefaultConfigDir();
 }
 
-ErrorCode
-Path::create( bool create_parents)throw() {
-  ErrorCode result ( NOT_AN_ERROR );
-  if ( is_directory() ) {
-    if ( create_parents ) {
-      result = this->create_directories( );
-    } else {
-      result = this->create_directory( );
-    }
-  } else if ( is_file() ) {
-    if ( create_parents ) {
-      result = this->create_directories( );
-    }
-    if ( result ) {
-      result = this->create_file( );
-    }
-  } else {
-    result = ErrorCode(ERR_SYS_INVALID_ARG);
+LLVMFileType
+sys::IdentifyFileType(const char*magic, unsigned length) {
+  assert(magic && "Invalid magic number string");
+  assert(length >=4 && "Invalid magic number length");
+  switch (magic[0]) {
+    case 'l':
+      if (magic[1] == 'l' && magic[2] == 'v') {
+        if (magic[3] == 'c')
+          return CompressedBytecodeFileType;
+        else if (magic[3] == 'm')
+          return BytecodeFileType;
+      }
+      break;
+
+    case '!':
+      if (length >= 8) {
+        if (memcmp(magic,"!<arch>\n",8) == 0)
+          return ArchiveFileType;
+      }
+      break;
+
+    default:
+      break;
   }
-  return result;
+  return UnknownFileType;
+}
+
+bool
+Path::isArchive() const {
+  if (canRead())
+    return hasMagicNumber("!<arch>\012");
+  return false;
 }
 
-ErrorCode
-Path::remove() throw() {
-  ErrorCode result( NOT_AN_ERROR );
-  if ( is_directory() ) {
-    if ( exists() ) 
-      this->remove_directory( );
-  } else if ( is_file() ) {
-    if ( exists() ) this->remove_file( );
-  } else {
-    result = ErrorCode(ERR_SYS_INVALID_ARG);
+bool
+Path::isDynamicLibrary() const {
+  if (canRead())
+    return hasMagicNumber("\177ELF");
+  return false;
+}
+
+Path
+Path::FindLibrary(std::string& name) {
+  std::vector<sys::Path> LibPaths;
+  GetSystemLibraryPaths(LibPaths);
+  for (unsigned i = 0; i < LibPaths.size(); ++i) {
+    sys::Path FullPath(LibPaths[i]);
+    FullPath.appendComponent("lib" + name + LTDL_SHLIB_EXT);
+    if (FullPath.isDynamicLibrary())
+      return FullPath;
+    FullPath.eraseSuffix();
+    FullPath.appendSuffix("a");
+    if (FullPath.isArchive())
+      return FullPath;
   }
-  return result;
+  return sys::Path();
 }
 
+std::string
+Path::GetDLLSuffix() {
+  return LTDL_SHLIB_EXT;
 }
+
 }
 
-// Include the platform specific portions of this class
-#include "linux/Path.cpp" 
+// Include the truly platform-specific parts of this class.
+
+#if defined(LLVM_ON_UNIX)
+#include "Unix/Path.inc"
+#endif
+#if defined(LLVM_ON_WIN32)
+#include "Win32/Path.inc"
+#endif
 
-// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab