[InstCombine] Signed saturation patterns
[llvm-core.git] / bindings / go / llvm / bitreader.go
blob1954916e717da384a00bda8e33972768f86d806e
1 //===- bitreader.go - Bindings for bitreader ------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines bindings for the bitreader component.
11 //===----------------------------------------------------------------------===//
13 package llvm
16 #include "llvm-c/BitReader.h"
17 #include "llvm-c/Core.h"
18 #include <stdlib.h>
20 import "C"
22 import (
23 "errors"
24 "unsafe"
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
31 var errmsg *C.char
32 var cfilename *C.char = C.CString(name)
33 defer C.free(unsafe.Pointer(cfilename))
34 result := C.LLVMCreateMemoryBufferWithContentsOfFile(cfilename, &buf, &errmsg)
35 if result != 0 {
36 err := errors.New(C.GoString(errmsg))
37 C.free(unsafe.Pointer(errmsg))
38 return Module{}, err
40 defer C.LLVMDisposeMemoryBuffer(buf)
42 var m Module
43 if C.LLVMParseBitcode2(buf, &m.C) == 0 {
44 return m, nil
47 err := errors.New(C.GoString(errmsg))
48 C.free(unsafe.Pointer(errmsg))
49 return Module{}, err