1 //===- bitreader.go - Bindings for bitreader ------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines bindings for the bitreader component.
12 //===----------------------------------------------------------------------===//
17 #include "llvm-c/BitReader.h"
18 #include "llvm-c/Core.h"
28 // ParseBitcodeFile parses the LLVM IR (bitcode) in the file with the
29 // specified name, and returns a new LLVM module.
30 func ParseBitcodeFile(name
string) (Module
, error
) {
31 var buf C
.LLVMMemoryBufferRef
33 var cfilename
*C
.char
= C
.CString(name
)
34 defer C
.free(unsafe
.Pointer(cfilename
))
35 result
:= C
.LLVMCreateMemoryBufferWithContentsOfFile(cfilename
, &buf
, &errmsg
)
37 err
:= errors
.New(C
.GoString(errmsg
))
38 C
.free(unsafe
.Pointer(errmsg
))
41 defer C
.LLVMDisposeMemoryBuffer(buf
)
44 if C
.LLVMParseBitcode2(buf
, &m
.C
) == 0 {
48 err
:= errors
.New(C
.GoString(errmsg
))
49 C
.free(unsafe
.Pointer(errmsg
))