1 //===- bitreader.go - Bindings for bitreader ------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines bindings for the bitreader component.
11 //===----------------------------------------------------------------------===//
16 #include "llvm-c/BitReader.h"
17 #include "llvm-c/Core.h"
27 // ParseBitcodeFile parses the LLVM IR (bitcode) in the file with the
28 // specified name, and returns a new LLVM module.
29 func ParseBitcodeFile(name
string) (Module
, error
) {
30 var buf C
.LLVMMemoryBufferRef
32 var cfilename
*C
.char
= C
.CString(name
)
33 defer C
.free(unsafe
.Pointer(cfilename
))
34 result
:= C
.LLVMCreateMemoryBufferWithContentsOfFile(cfilename
, &buf
, &errmsg
)
36 err
:= errors
.New(C
.GoString(errmsg
))
37 C
.free(unsafe
.Pointer(errmsg
))
40 defer C
.LLVMDisposeMemoryBuffer(buf
)
43 if C
.LLVMParseBitcode2(buf
, &m
.C
) == 0 {
47 err
:= errors
.New(C
.GoString(errmsg
))
48 C
.free(unsafe
.Pointer(errmsg
))