[bindings] Update Go bindings to DIBuilder
[oota-llvm.git] / bindings / go / llvm / bitwriter.go
1 //===- bitwriter.go - Bindings for bitwriter ------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines bindings for the bitwriter component.
11 //
12 //===----------------------------------------------------------------------===//
13
14 package llvm
15
16 /*
17 #include "llvm-c/BitWriter.h"
18 #include <stdlib.h>
19 */
20 import "C"
21 import "os"
22 import "errors"
23
24 var writeBitcodeToFileErr = errors.New("Failed to write bitcode to file")
25
26 func WriteBitcodeToFile(m Module, file *os.File) error {
27         fail := C.LLVMWriteBitcodeToFD(m.C, C.int(file.Fd()), C.int(0), C.int(0))
28         if fail != 0 {
29                 return writeBitcodeToFileErr
30         }
31         return nil
32 }
33
34 func WriteBitcodeToMemoryBuffer(m Module) MemoryBuffer {
35         mb := C.LLVMWriteBitcodeToMemoryBuffer(m.C)
36         return MemoryBuffer{mb}
37 }
38
39 // TODO(nsf): Figure out way how to make it work with io.Writer