mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 06:32:24 +00:00
For 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18902 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
20d793aad1
commit
9153f8f476
@ -17,9 +17,9 @@
|
|||||||
#include "Reader.h"
|
#include "Reader.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Support/FileUtilities.h"
|
|
||||||
#include "llvm/ADT/StringExtras.h"
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/Config/unistd.h"
|
#include "llvm/Config/unistd.h"
|
||||||
|
#include "llvm/System/MappedFile.h"
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -32,15 +32,13 @@ namespace {
|
|||||||
///
|
///
|
||||||
class BytecodeFileReader : public BytecodeReader {
|
class BytecodeFileReader : public BytecodeReader {
|
||||||
private:
|
private:
|
||||||
unsigned char *Buffer;
|
sys::MappedFile mapFile;
|
||||||
unsigned Length;
|
|
||||||
|
|
||||||
BytecodeFileReader(const BytecodeFileReader&); // Do not implement
|
BytecodeFileReader(const BytecodeFileReader&); // Do not implement
|
||||||
void operator=(const BytecodeFileReader &BFR); // Do not implement
|
void operator=(const BytecodeFileReader &BFR); // Do not implement
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BytecodeFileReader(const std::string &Filename, llvm::BytecodeHandler* H=0);
|
BytecodeFileReader(const std::string &Filename, llvm::BytecodeHandler* H=0);
|
||||||
~BytecodeFileReader();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,23 +49,11 @@ static std::string ErrnoMessage (int savedErrNum, std::string descr) {
|
|||||||
BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
|
BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
|
||||||
llvm::BytecodeHandler* H )
|
llvm::BytecodeHandler* H )
|
||||||
: BytecodeReader(H)
|
: BytecodeReader(H)
|
||||||
|
, mapFile( sys::Path(Filename))
|
||||||
{
|
{
|
||||||
Buffer = (unsigned char*)ReadFileIntoAddressSpace(Filename, Length);
|
mapFile.map();
|
||||||
if (Buffer == 0)
|
unsigned char* buffer = reinterpret_cast<unsigned char*>(mapFile.base());
|
||||||
throw "Error reading file '" + Filename + "'.";
|
ParseBytecode(buffer, mapFile.size(), 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user