Gordon Henriksen | bbc6597 | 2007-12-11 00:20:48 +0000 | [diff] [blame^] | 1 | //===-- BitReader.cpp -----------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by Gordon Henriksen and is distributed under the |
| 6 | // University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm-c/BitReader.h" |
| 11 | #include "llvm/Bitcode/ReaderWriter.h" |
| 12 | #include "llvm/Support/MemoryBuffer.h" |
| 13 | #include <string> |
| 14 | |
| 15 | using namespace llvm; |
| 16 | |
| 17 | |
| 18 | int LLVMReadBitcodeFromFile(const char *Path, LLVMModuleRef *OutModule, |
| 19 | char **OutMessage) { |
| 20 | std::string Message; |
| 21 | |
| 22 | MemoryBuffer *buf = MemoryBuffer::getFile(Path, strlen(Path), &Message); |
| 23 | if (!buf) { |
| 24 | if (!OutMessage) |
| 25 | *OutMessage = strdup(Message.c_str()); |
| 26 | return 1; |
| 27 | } |
| 28 | |
| 29 | *OutModule = wrap(ParseBitcodeFile(buf, &Message)); |
| 30 | if (!*OutModule) { |
| 31 | if (OutMessage) |
| 32 | *OutMessage = strdup(Message.c_str()); |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | void LLVMDisposeBitcodeReaderMessage(char *Message) { |
| 40 | if (Message) |
| 41 | free(Message); |
| 42 | } |