[llvm-commits] CVS: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp

Reid Spencer reid at x10sys.com
Mon Dec 13 10:25:37 PST 2004



Changes in directory llvm/lib/Bytecode/Reader:

ReaderWrappers.cpp updated: 1.38 -> 1.39
---
Log message:

For PR351: http://llvm.cs.uiuc.edu/PR351 :
Use sys::MappedFile instead of ReadFileIntoAddressSpace and 
UnmapFileFromAddressSpace. sys::MappedFile has the nice property that it
cleans up after itself so exception handling can be removed.


---
Diffs of the changes:  (+6 -20)

Index: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
diff -u llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.38 llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.39
--- llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.38	Fri Dec 10 18:14:15 2004
+++ llvm/lib/Bytecode/Reader/ReaderWrappers.cpp	Mon Dec 13 12:25:27 2004
@@ -17,9 +17,9 @@
 #include "Reader.h"
 #include "llvm/Module.h"
 #include "llvm/Instructions.h"
-#include "llvm/Support/FileUtilities.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Config/unistd.h"
+#include "llvm/System/MappedFile.h"
 #include <cerrno>
 using namespace llvm;
 
@@ -32,15 +32,13 @@
   ///
   class BytecodeFileReader : public BytecodeReader {
   private:
-    unsigned char *Buffer;
-    unsigned Length;
+    sys::MappedFile mapFile;
 
     BytecodeFileReader(const BytecodeFileReader&); // Do not implement
     void operator=(const BytecodeFileReader &BFR); // Do not implement
 
   public:
     BytecodeFileReader(const std::string &Filename, llvm::BytecodeHandler* H=0);
-    ~BytecodeFileReader();
   };
 }
 
@@ -51,23 +49,11 @@
 BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
                                        llvm::BytecodeHandler* H ) 
   : BytecodeReader(H)
+  , mapFile( sys::Path(Filename))
 {
-  Buffer = (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
-  if (Buffer == 0)
-    throw "Error reading file '" + Filename + "'.";
-
-  try {
-    // Parse the bytecode we mmapped in
-    ParseBytecode(Buffer, Length, Filename);
-  } catch (...) {
-    UnmapFileFromAddressSpace(Buffer, Length);
-    throw;
-  }
-}
-
-BytecodeFileReader::~BytecodeFileReader() {
-  // Unmmap the bytecode...
-  UnmapFileFromAddressSpace(Buffer, Length);
+  mapFile.map();
+  unsigned char* buffer = reinterpret_cast<unsigned char*>(mapFile.base());
+  ParseBytecode(buffer, mapFile.size(), Filename);
 }
 
 //===----------------------------------------------------------------------===//






More information about the llvm-commits mailing list