Copy ExpandInlineAsm to TargetLowering from TargetAsmInfo.
[oota-llvm.git] / include / llvm / System / Path.h
index 3ab9e087b0ce53b1737b9adf39f290ff2e0dff53..8b603f5ad42c5d5f5d6c5f38f4ec1704daf46482 100644 (file)
@@ -15,6 +15,7 @@
 #define LLVM_SYSTEM_PATH_H
 
 #include "llvm/System/TimeValue.h"
+#include "llvm/Support/raw_ostream.h"
 #include <set>
 #include <string>
 #include <vector>
@@ -28,8 +29,8 @@ namespace sys {
   /// platform independent and eliminates many of the unix-specific fields.
   /// However, to support llvm-ar, the mode, user, and group fields are
   /// retained. These pertain to unix security and may not have a meaningful
-  /// value on non-Unix platforms. However, the other fields fields should 
-  /// always be applicable on all platforms.  The structure is filled in by 
+  /// value on non-Unix platforms. However, the other fields fields should
+  /// always be applicable on all platforms.  The structure is filled in by
   /// the PathWithStatus class.
   /// @brief File status structure
   class FileStatus {
@@ -45,7 +46,7 @@ namespace sys {
 
     FileStatus() : fileSize(0), modTime(0,0), mode(0777), user(999),
                    group(999), uniqueID(0), isDir(false), isFile(false) { }
-    
+
     TimeValue getTimestamp() const { return modTime; }
     uint64_t getSize() const { return fileSize; }
     uint32_t getMode() const { return mode; }
@@ -148,7 +149,7 @@ namespace sys {
       /// constructor must provide the same result as GetRootDirectory.
       /// @brief Construct a path to the current user's "home" directory
       static Path GetUserHomeDirectory();
-      
+
       /// Construct a path to the current directory for the current process.
       /// @returns The current working directory.
       /// @brief Returns the current working directory.
@@ -162,6 +163,10 @@ namespace sys {
       /// @brief Return the dynamic link library suffix.
       static std::string GetDLLSuffix();
 
+      /// GetMainExecutable - Return the path to the main executable, given the
+      /// value of argv[0] from program startup and the address of main itself.
+      static Path GetMainExecutable(const char *argv0, void *MainAddr);
+
       /// This is one of the very few ways in which a path can be constructed
       /// with a syntactically invalid name. The only *legal* invalid name is an
       /// empty one. Other invalid names are not permitted. Empty paths are
@@ -173,20 +178,19 @@ namespace sys {
 
       /// This constructor will accept a std::string as a path. No checking is
       /// done on this path to determine if it is valid. To determine validity
-      /// of the path, use the isValid method. 
+      /// of the path, use the isValid method.
       /// @param p The path to assign.
       /// @brief Construct a Path from a string.
-      explicit Path(const std::string& p) : path(p) {}
+      explicit Path(const std::string& p);
 
       /// This constructor will accept a character range as a path.  No checking
       /// is done on this path to determine if it is valid.  To determine
-      /// validity of the path, use the isValid method. 
+      /// validity of the path, use the isValid method.
       /// @param StrStart A pointer to the first character of the path name
       /// @param StrLen The length of the path name at StrStart
       /// @brief Construct a Path from a string.
-      explicit Path(const char *StrStart, unsigned StrLen)
-        : path(StrStart, StrStart+StrLen) {}
-      
+      Path(const char *StrStart, unsigned StrLen);
+
     /// @}
     /// @name Operators
     /// @{
@@ -199,19 +203,21 @@ namespace sys {
         return *this;
       }
 
+      /// Makes a copy of \p that to \p this.
+      /// @param \p that A std::string denoting the path
+      /// @returns \p this
+      /// @brief Assignment Operator
+      Path &operator=(const std::string &that);
+
       /// Compares \p this Path with \p that Path for equality.
       /// @returns true if \p this and \p that refer to the same thing.
       /// @brief Equality Operator
-      bool operator==(const Path &that) const {
-        return 0 == path.compare(that.path);
-      }
+      bool operator==(const Path &that) const;
 
       /// Compares \p this Path with \p that Path for inequality.
       /// @returns true if \p this and \p that refer to different things.
       /// @brief Inequality Operator
-      bool operator!=(const Path &that) const {
-        return 0 != path.compare(that.path);
-      }
+      bool operator!=(const Path &that) const;
 
       /// Determines if \p this Path is less than \p that Path. This is required
       /// so that Path objects can be placed into ordered collections (e.g.
@@ -219,9 +225,7 @@ namespace sys {
       /// the std::string::compare method.
       /// @returns true if \p this path is lexicographically less than \p that.
       /// @brief Less Than Operator
-      bool operator<(const Path& that) const {
-        return 0 > path.compare(that.path);
-      }
+      bool operator<(const Path& that) const;
 
     /// @}
     /// @name Path Accessors
@@ -236,10 +240,10 @@ namespace sys {
       /// @brief Determine if a path is syntactically valid or not.
       bool isValid() const;
 
-      /// This function determines if the contents of the path name are empty. 
+      /// This function determines if the contents of the path name are empty.
       /// That is, the path name has a zero length. This does NOT determine if
-      /// if the file is empty. To get the length of the file itself, Use the 
-      /// PathWithStatus::getFileStatus() method and then the getSize() method 
+      /// if the file is empty. To get the length of the file itself, Use the
+      /// PathWithStatus::getFileStatus() method and then the getSize() method
       /// on the returned FileStatus object.
       /// @returns true iff the path is empty.
       /// @brief Determines if the path name is empty (invalid).
@@ -266,11 +270,29 @@ namespace sys {
       /// @brief Get the base name of the path
       std::string getBasename() const;
 
+      /// This function strips off the suffix of the path beginning with the
+      /// path separator ('/' on Unix, '\' on Windows) and returns the result.
+      std::string getDirname() const;
+
+      /// This function strips off the path and basename(up to and
+      /// including the last dot) of the file or directory name and
+      /// returns just the suffix. For example /a/foo.bar would cause
+      /// this function to return "bar".
+      /// @returns std::string containing the suffix of the path
+      /// @brief Get the suffix of the path
+      std::string getSuffix() const;
+
       /// Obtain a 'C' string for the path name.
       /// @returns a 'C' string containing the path name.
       /// @brief Returns the path as a C string.
       const char *c_str() const { return path.c_str(); }
 
+      /// size - Return the length in bytes of this path name.
+      size_t size() const { return path.size(); }
+
+      /// empty - Returns true if the path is empty.
+      unsigned empty() const { return path.empty(); }
+
     /// @}
     /// @name Disk Accessors
     /// @{
@@ -284,10 +306,15 @@ namespace sys {
       bool isRootDirectory() const;
 
       /// This function determines if the path name is absolute, as opposed to
-      /// relative. 
+      /// relative.
       /// @brief Determine if the path is absolute.
       bool isAbsolute() const;
 
+      /// This function determines if the path name is absolute, as opposed to
+      /// relative.
+      /// @brief Determine if the path is absolute.
+      static bool isAbsolute(const char *NameStart, unsigned NameLen);
+
       /// This function opens the file associated with the path name provided by
       /// the Path object and reads its magic number. If the magic number at the
       /// start of the file matches \p magic, true is returned. In all other
@@ -317,7 +344,7 @@ namespace sys {
       /// bitcode files.
       /// @brief Determine if the path references a bitcode file.
       bool isBitcodeFile() const;
-      
+
       /// This function determines if the path name in the object references a
       /// native Dynamic Library (shared library, shared object) by looking at
       /// the file's magic number. The Path object must reference a file, not a
@@ -326,7 +353,7 @@ namespace sys {
       /// shared library.
       /// @brief Determine if the path reference a dynamic library.
       bool isDynamicLibrary() 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
@@ -335,12 +362,12 @@ namespace sys {
       /// the file system.
       bool exists() const;
 
-      /// This function determines if the path name refences an 
+      /// This function determines if the path name refences an
       /// existing directory.
       /// @returns true if the pathname references an existing directory.
       /// @brief Determins if the path is a directory in the file system.
       bool isDirectory() const;
-    
+
       /// This function determines if the path name references a readable file
       /// or directory in the file system. This function checks for
       /// the existence and readability (by the current program) of the file
@@ -438,6 +465,10 @@ namespace sys {
       /// @brief Make the current path name unique in the file system.
       bool makeUnique( bool reuse_current /*= true*/, std::string* ErrMsg );
 
+      /// The current Path name is made absolute by prepending the
+      /// current working directory if necessary.
+      void makeAbsolute();
+
     /// @}
     /// @name Disk Mutators
     /// @{
@@ -475,9 +506,9 @@ namespace sys {
       /// created. The created directory will have no entries.
       /// @returns true if the directory could not be created, false otherwise
       /// @brief Create the directory this Path refers to.
-      bool createDirectoryOnDisk( 
-        bool create_parents = false, ///<  Determines whether non-existent 
-           ///< directory components other than the last one (the "parents") 
+      bool createDirectoryOnDisk(
+        bool create_parents = false, ///<  Determines whether non-existent
+           ///< directory components other than the last one (the "parents")
            ///< are created or not.
         std::string* ErrMsg = 0 ///< Optional place to put error messages.
       );
@@ -499,11 +530,11 @@ namespace sys {
       /// file is created.  Note that this will both change the Path object
       /// *and* create the corresponding file. This function will ensure that
       /// the newly generated temporary file name is unique in the file system.
-      /// @returns true if the file couldn't be created, false otherwise. 
+      /// @returns true if the file couldn't be created, false otherwise.
       /// @brief Create a unique temporary file
       bool createTemporaryFileOnDisk(
-        bool reuse_current = false, ///< When set to true, this parameter 
-          ///< indicates that if the current file name does not exist then 
+        bool reuse_current = false, ///< When set to true, this parameter
+          ///< indicates that if the current file name does not exist then
           ///< it will be used without modification.
         std::string* ErrMsg = 0 ///< Optional place to put error messages
       );
@@ -529,12 +560,36 @@ namespace sys {
       /// @brief Removes the file or directory from the filesystem.
       bool eraseFromDisk(bool destroy_contents = false,
                          std::string *Err = 0) const;
+
+
+      /// MapInFilePages - This is a low level system API to map in the file
+      /// that is currently opened as FD into the current processes' address
+      /// space for read only access.  This function may return null on failure
+      /// or if the system cannot provide the following constraints:
+      ///  1) The pages must be valid after the FD is closed, until
+      ///     UnMapFilePages is called.
+      ///  2) Any padding after the end of the file must be zero filled, if
+      ///     present.
+      ///  3) The pages must be contiguous.
+      ///
+      /// This API is not intended for general use, clients should use
+      /// MemoryBuffer::getFile instead.
+      static const char *MapInFilePages(int FD, uint64_t FileSize);
+
+      /// UnMapFilePages - Free pages mapped into the current process by
+      /// MapInFilePages.
+      ///
+      /// This API is not intended for general use, clients should use
+      /// MemoryBuffer::getFile instead.
+      static void UnMapFilePages(const char *Base, uint64_t FileSize);
+
     /// @}
     /// @name Data
     /// @{
     protected:
       mutable std::string path;   ///< Storage for the path name.
 
+
     /// @}
   };
 
@@ -549,23 +604,23 @@ namespace sys {
   class PathWithStatus : public Path {
     /// @name Constructors
     /// @{
-    public: 
+    public:
       /// @brief Default constructor
       PathWithStatus() : Path(), status(), fsIsValid(false) {}
 
       /// @brief Copy constructor
-      PathWithStatus(const PathWithStatus &that) 
-        : Path(static_cast<const Path&>(that)), status(that.status), 
+      PathWithStatus(const PathWithStatus &that)
+        : Path(static_cast<const Path&>(that)), status(that.status),
            fsIsValid(that.fsIsValid) {}
 
       /// This constructor allows construction from a Path object
       /// @brief Path constructor
-      PathWithStatus(const Path &other) 
+      PathWithStatus(const Path &other)
         : Path(other), status(), fsIsValid(false) {}
 
       /// This constructor will accept a std::string as a path. No checking is
       /// done on this path to determine if it is valid. To determine validity
-      /// of the path, use the isValid method. 
+      /// of the path, use the isValid method.
       /// @brief Construct a Path from a string.
       explicit PathWithStatus(
         const std::string& p ///< The path to assign.
@@ -573,7 +628,7 @@ namespace sys {
 
       /// This constructor will accept a character range as a path.  No checking
       /// is done on this path to determine if it is valid.  To determine
-      /// validity of the path, use the isValid method. 
+      /// validity of the path, use the isValid method.
       /// @brief Construct a Path from a string.
       explicit PathWithStatus(
         const char *StrStart,  ///< Pointer to the first character of the path
@@ -654,10 +709,25 @@ namespace sys {
   /// @returns true if an error occurs, false otherwise
   /// @brief Copy one file to another.
   bool CopyFile(const Path& Dest, const Path& Src, std::string* ErrMsg);
+
+  /// This is the OS-specific path separator: a colon on Unix or a semicolon
+  /// on Windows.
+  extern const char PathSeparator;
+}
+
+inline raw_ostream& operator<<(raw_ostream& strm, const sys::Path& aPath) {
+  strm << aPath.toString();
+  return strm;
+}
+
+inline raw_ostream& operator<<(raw_ostream& strm,
+                               const sys::PathWithStatus& aPath) {
+  strm << static_cast<const sys::Path&>(aPath);
+  return strm;
 }
 
 std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath);
-inline std::ostream& operator<<(std::ostream& strm, 
+inline std::ostream& operator<<(std::ostream& strm,
                                 const sys::PathWithStatus& aPath) {
   strm << static_cast<const sys::Path&>(aPath);
   return strm;