diff options
author | Chris Lattner <sabre@nondot.org> | 2007-04-29 07:54:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-04-29 07:54:31 +0000 |
commit | c453f76e2b4d7fd1e042b5b6d4c20556779186df (patch) | |
tree | a24882c0c4c773a77d7e16562335fe8364ffc47d /lib/Bitcode/Reader/ReaderWrappers.cpp | |
parent | 333ffd4abfcc3be32a945dc73c81adeafde1ba6b (diff) |
Switch the bitcode reader interface to take a MemoryBuffer instead of knowing
anything about disk I/O itself. This greatly simplifies its interface -
eliminating the need for the ReaderWrappers.cpp file.
This adds a new option to llvm-dis (-bitcode) which instructs it to read
the input file as bitcode. Until/unless the bytecode reader is taught to
read from MemoryBuffer, there is no way to handle stdin reading without it.
I don't plan to switch the bytecode reader over, I'd rather delete it :),
so the option will stay around temporarily.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Bitcode/Reader/ReaderWrappers.cpp')
-rw-r--r-- | lib/Bitcode/Reader/ReaderWrappers.cpp | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/lib/Bitcode/Reader/ReaderWrappers.cpp b/lib/Bitcode/Reader/ReaderWrappers.cpp deleted file mode 100644 index 8bf81a2f83..0000000000 --- a/lib/Bitcode/Reader/ReaderWrappers.cpp +++ /dev/null @@ -1,98 +0,0 @@ -//===- ReaderWrappers.cpp - Parse bitcode from file or buffer -------------===// -// -// The LLVM Compiler Infrastructure -// -// This file was developed by Chris Lattner and is distributed under -// the University of Illinois Open Source License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements loading and parsing a bitcode file and parsing a -// module from a memory buffer. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Bitcode/ReaderWriter.h" -#include "BitcodeReader.h" -#include "llvm/System/MappedFile.h" -using namespace llvm; - -//===----------------------------------------------------------------------===// -// BitcodeFileReader - Read from an mmap'able file descriptor. - -namespace { - /// BitcodeFileReader - parses bitcode from a file. - /// - class BitcodeFileReader : public BitcodeReader { - private: - std::string Filename; - sys::MappedFile File; - - BitcodeFileReader(const BitcodeFileReader&); // DO NOT IMPLEMENT - void operator=(const BitcodeFileReader&); // DO NOT IMPLEMENT - public: - BitcodeFileReader(const std::string &FN) : Filename(FN) {} - bool Read(std::string *ErrMsg); - - void FreeState() { - BitcodeReader::FreeState(); - File.close(); - } - }; -} - -bool BitcodeFileReader::Read(std::string *ErrMsg) { - if (File.open(sys::Path(Filename), sys::MappedFile::READ_ACCESS, ErrMsg)) - return true; - if (!File.map(ErrMsg)) { - File.close(); - return true; - } - unsigned char *Buffer = reinterpret_cast<unsigned char*>(File.base()); - if (!ParseBitcode(Buffer, File.size(), Filename)) - return false; - assert(getErrorString() && "Didn't set an error string?"); - if (ErrMsg) *ErrMsg = getErrorString(); - return true; -} - - - -//===----------------------------------------------------------------------===// -// External interface -//===----------------------------------------------------------------------===// - -/// getBitcodeModuleProvider - lazy function-at-a-time loading from a file. -/// -ModuleProvider *llvm::getBitcodeModuleProvider(const std::string &Filename, - std::string *ErrMsg) { - if (Filename != std::string("-")) { - BitcodeFileReader *R = new BitcodeFileReader(Filename); - if (R->Read(ErrMsg)) { - delete R; - return 0; - } - return R; - } - - assert(0 && "FIXME: stdin reading unimp!"); -#if 0 - // Read from stdin - BytecodeStdinReader *R = new BytecodeStdinReader(); - if (R->Read(ErrMsg)) { - delete R; - return 0; - } - return R; -#endif -} - -/// ParseBitcodeFile - Read the specified bitcode file, returning the module. -/// If an error occurs, return null and fill in *ErrMsg if non-null. -Module *llvm::ParseBitcodeFile(const std::string &Filename,std::string *ErrMsg){ - ModuleProvider *MP = getBitcodeModuleProvider(Filename, ErrMsg); - if (!MP) return 0; - Module *M = MP->releaseModule(ErrMsg); - delete MP; - return M; -} |