blob: c6600887bc4e8df577ba669386e1e9f8255f99e5 [file] [log] [blame]
Gordon Henriksenbbc65972007-12-11 00:20:48 +00001//===-- 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
15using namespace llvm;
16
17
18int 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
39void LLVMDisposeBitcodeReaderMessage(char *Message) {
40 if (Message)
41 free(Message);
42}