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