[PowerPC] Add some Book II instructions to AsmParser
[oota-llvm.git] / lib / Archive / ArchiveInternals.h
index dde83583c9a4d480616d427047303926afe9faf0..f6c87e899f25b498c8850d4b62be5023d55ef207 100644 (file)
@@ -1,36 +1,58 @@
-//===-- lib/Bytecode/ArchiveInternals.h -------------------------*- C++ -*-===//
-// 
+//===-- lib/Archive/ArchiveInternals.h -------------------------*- C++ -*-===//
+//
 //                     The LLVM Compiler Infrastructure
 //
-// 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 is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
 //===----------------------------------------------------------------------===//
 //
 // Internal implementation header for LLVM Archive files.
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef LIB_BYTECODE_ARCHIVEINTERNALS_H
-#define LIB_BYTECODE_ARCHIVEINTERNALS_H
+#ifndef LIB_ARCHIVE_ARCHIVEINTERNALS_H
+#define LIB_ARCHIVE_ARCHIVEINTERNALS_H
 
-#include "llvm/Bytecode/Archive.h"
-#include "llvm/System/TimeValue.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/Bitcode/Archive.h"
+#include "llvm/Support/TimeValue.h"
+#include <cstring>
 
-#define ARFILE_MAGIC "!<arch>\n"                   ///< magic string 
-#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1)  ///< length of magic string 
-#define ARFILE_SYMTAB_NAME "/"                     ///< name of symtab entry
-#define ARFILE_STRTAB_NAME "//"                    ///< name of strtab entry
-#define ARFILE_PAD '\n'                            ///< inter-file align padding
+#define ARFILE_MAGIC "!<arch>\n"                   ///< magic string
+#define ARFILE_MAGIC_LEN (sizeof(ARFILE_MAGIC)-1)  ///< length of magic string
+#define ARFILE_SVR4_SYMTAB_NAME "/               " ///< SVR4 symtab entry name
+#define ARFILE_LLVM_SYMTAB_NAME "#_LLVM_SYM_TAB_#" ///< LLVM symtab entry name
+#define ARFILE_BSD4_SYMTAB_NAME "__.SYMDEF SORTED" ///< BSD4 symtab entry name
+#define ARFILE_STRTAB_NAME      "//              " ///< Name of string table
+#define ARFILE_PAD "\n"                            ///< inter-file align padding
+#define ARFILE_MEMBER_MAGIC "`\n"                  ///< fmag field magic #
 
 namespace llvm {
 
-  /// The ArchiveMemberHeader structure is used internally for bytecode archives. 
-  /// The header precedes each file member in the archive. This structure is 
+  class LLVMContext;
+
+  /// The ArchiveMemberHeader structure is used internally for bitcode
+  /// archives.
+  /// The header precedes each file member in the archive. This structure is
   /// defined using character arrays for direct and correct interpretation
   /// regardless of the endianess of the machine that produced it.
   /// @brief Archive File Member Header
   class ArchiveMemberHeader {
+    /// @name Data
+    /// @{
+    public:
+      char name[16];  ///< Name of the file member.
+      char date[12];  ///< File date, decimal seconds since Epoch
+      char uid[6];    ///< user id in ASCII decimal
+      char gid[6];    ///< group id in ASCII decimal
+      char mode[8];   ///< file mode in ASCII octal
+      char size[10];  ///< file size in ASCII decimal
+      char fmag[2];   ///< Always contains ARFILE_MAGIC_TERMINATOR
+
+    /// @}
+    /// @name Methods
+    /// @{
     public:
     void init() {
       memset(name,' ',16);
@@ -42,115 +64,23 @@ namespace llvm {
       fmag[0] = '`';
       fmag[1] = '\n';
     }
-    void setDate( int secondsSinceEpoch = 0 ) {
-      if (secondsSinceEpoch == 0) {
-        sys::TimeValue tv = sys::TimeValue::now();
-        uint64_t secs; uint32_t nanos;
-        tv.GetTimespecTime(secs,nanos);
-        secondsSinceEpoch = (int) secs;
-      }
-      char buffer[20];
-      sprintf(buffer,"%d", secondsSinceEpoch);
-      memcpy(date,buffer,strlen(buffer));
-    }
-
-    void setSize(size_t sz) {
-      char buffer[20];
-      sprintf(buffer, "%u", (unsigned)sz);
-      memcpy(size,buffer,strlen(buffer));
-    }
-
-    void setMode(int m) {
-      char buffer[20];
-      sprintf(buffer, "%o", m);
-      memcpy(mode,buffer,strlen(buffer));
-    }
-
-    void setUid(unsigned u) {
-      char buffer[20];
-      sprintf(buffer, "%u", u);
-      memcpy(uid,buffer,strlen(buffer));
-    }
-
-    void setGid(unsigned g) {
-      char buffer[20];
-      sprintf(buffer, "%u", g);
-      memcpy(gid,buffer,strlen(buffer));
-    }
 
-    bool setName(const std::string& nm) {
-      if (nm.length() > 0 && nm.length() <= 16) {
-        memcpy(name,nm.c_str(),nm.length());
-        for (int i = nm.length()+1; i < 16; i++ ) name[i] = ' ';
-        return true;
-      }
-      return false;
+    bool checkSignature() const {
+      return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
     }
-
-    private:
-    char name[16];  ///< Name of the file member. The filename is terminated with '/'
-                    ///< and blanks. The empty name (/ and 15 blanks) is for the 
-                    ///< symbol table. The special name "//" and 15 blanks is for
-                    ///< the string table, used for long file names. It must be
-                    ///< first in the archive.
-    char date[12];  ///< File date, decimal seconds since Epoch
-    char uid[6];    ///< user id in ASCII decimal
-    char gid[6];    ///< group id in ASCII decimal
-    char mode[8];   ///< file mode in ASCII octal
-    char size[10];  ///< file size in ASCII decimal
-    char fmag[2];   ///< Always contains ARFILE_MAGIC_TERMINATOR
-
-  };
-
-  /// The ArchiveInternals class is used to hold the content of the archive
-  /// while it is in memory. It also provides the bulk of the implementation for
-  /// the llvm:Archive class's interface.
-  class Archive::ArchiveInternals {
-    /// @name Types
-    /// @{
-    public:
-      typedef std::vector<std::string> StrTab;
-
-      /// This structure holds information for one member in the archive. It is
-      /// used temporarily while the contents of the archive are being
-      /// determined.
-      struct MemberInfo {
-        MemberInfo() {}
-        sys::Path path;
-        std::string name;
-        sys::Path::StatusInfo status;
-        StrTab symbols;
-        unsigned offset;
-      };
-
-    /// @}
-    /// @name Methods
-    /// @{
-    public:
-      /// @brief Add a file member to the archive.
-      void addFileMember(
-        const sys::Path& path,         ///< The path to the file to be added
-        const std::string& name,       ///< The name for the member
-        const StrTab* syms = 0         ///< The symbol table of the member
-      );
-
-      /// @brief Write the accumulated archive information to an archive file
-      void writeArchive();
-      void writeMember(const MemberInfo& member,std::ofstream& ARFile);
-      void writeSymbolTable(std::ofstream& ARFile);
-      void writeInteger(int num, std::ofstream& ARFile);
-
-    /// @}
-    /// @name  Data
-    /// @{
-    private:
-      friend class Archive;            ///< Parent class is a friend
-      sys::Path       fname;           ///< Path to the archive file
-      std::vector<MemberInfo> members; ///< Info about member files
-      Archive::SymTab* symtab;         ///< User's symbol table
-
-    /// @}
   };
+  
+  // Get just the externally visible defined symbols from the bitcode
+  bool GetBitcodeSymbols(const sys::Path& fName,
+                          LLVMContext& Context,
+                          std::vector<std::string>& symbols,
+                          std::string* ErrMsg);
+  
+  Module* GetBitcodeSymbols(const char *Buffer, unsigned Length,
+                            const std::string& ModuleID,
+                            LLVMContext& Context,
+                            std::vector<std::string>& symbols,
+                            std::string* ErrMsg);
 }
 
 #endif