Evan implemented this.
[oota-llvm.git] / lib / Archive / ArchiveWriter.cpp
index f08526ce8246c904cdecfc459cfc17d829a31fa2..04cc981f79608dbaa2dfb29848f0bf149c9875df 100644 (file)
@@ -2,21 +2,20 @@
 //
 //                     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.
 //
 //===----------------------------------------------------------------------===//
 //
-// Builds up an LLVM archive file (.a) containing LLVM bytecode.
+// Builds up an LLVM archive file (.a) containing LLVM bitcode.
 //
 //===----------------------------------------------------------------------===//
 
 #include "ArchiveInternals.h"
-#include "llvm/Bytecode/Reader.h"
 #include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/Support/Compressor.h"
 #include "llvm/System/Signals.h"
 #include "llvm/System/Process.h"
+#include "llvm/ModuleProvider.h"
 #include <fstream>
 #include <ostream>
 #include <iomanip>
@@ -48,11 +47,12 @@ inline unsigned numVbrBytes(unsigned num) {
   // small ones and four for large ones. We expect this to access file offsets
   // in the 2^10 to 2^24 range and symbol lengths in the 2^0 to 2^8 range,
   // so this approach is reasonable.
-  if (num < 1<<14)
+  if (num < 1<<14) {
     if (num < 1<<7)
       return 1;
     else
       return 2;
+  }
   if (num < 1<<21)
     return 3;
 
@@ -180,11 +180,7 @@ Archive::addFileBefore(const sys::Path& filePath, iterator where,
   mbr->path.getMagicNumber(magic,4);
   switch (sys::IdentifyFileType(magic.c_str(),4)) {
     case sys::Bitcode_FileType:
-    case sys::Bytecode_FileType:
-      flags |= ArchiveMember::BytecodeFlag;
-      break;
-    case sys::CompressedBytecode_FileType:
-      flags |= ArchiveMember::CompressedBytecodeFlag;
+      flags |= ArchiveMember::BitcodeFlag;
       break;
     default:
       break;
@@ -223,19 +219,17 @@ Archive::writeMember(
   }
 
   // Now that we have the data in memory, update the
-  // symbol table if its a bytecode file.
-  if (CreateSymbolTable &&
-      (member.isBytecode() || member.isCompressedBytecode())) {
+  // symbol table if its a bitcode file.
+  if (CreateSymbolTable && member.isBitcode()) {
     std::vector<std::string> symbols;
     std::string FullMemberName = archPath.toString() + "(" +
       member.getPath().toString()
       + ")";
     ModuleProvider* MP = 
-      GetBytecodeSymbols((const unsigned char*)data,fSize,
-                         FullMemberName, symbols,
-                         Compressor::decompressToNewBuffer, ErrMsg);
+      GetBitcodeSymbols((const unsigned char*)data,fSize,
+                        FullMemberName, symbols, ErrMsg);
 
-    // If the bytecode parsed successfully
+    // If the bitcode parsed successfully
     if ( MP ) {
       for (std::vector<std::string>::iterator SI = symbols.begin(),
            SE = symbols.end(); SI != SE; ++SI) {
@@ -257,7 +251,7 @@ Archive::writeMember(
         delete mFile;
       }
       if (ErrMsg)
-        *ErrMsg = "Can't parse bytecode member: " + member.getPath().toString()
+        *ErrMsg = "Can't parse bitcode member: " + member.getPath().toString()
           + ": " + *ErrMsg;
       return true;
     }
@@ -354,7 +348,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
 {
   // Make sure they haven't opened up the file, not loaded it,
   // but are now trying to write it which would wipe out the file.
-  if (members.empty() && mapfile->size() > 8) {
+  if (members.empty() && mapfile && mapfile->size() > 8) {
     if (ErrMsg)
       *ErrMsg = "Can't write an archive not opened for writing";
     return true;