Initial version of Go bindings.
[oota-llvm.git] / bindings / go / llvm / ir.go
1 //===- ir.go - Bindings for ir --------------------------------------------===//
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 ir component.
11 //
12 //===----------------------------------------------------------------------===//
13
14 package llvm
15
16 /*
17 #include "llvm-c/Core.h"
18 #include "IRBindings.h"
19 #include <stdlib.h>
20 */
21 import "C"
22 import "unsafe"
23 import "errors"
24
25 type (
26         // We use these weird structs here because *Ref types are pointers and
27         // Go's spec says that a pointer cannot be used as a receiver base type.
28         Context struct {
29                 C C.LLVMContextRef
30         }
31         Module struct {
32                 C C.LLVMModuleRef
33         }
34         Type struct {
35                 C C.LLVMTypeRef
36         }
37         Value struct {
38                 C C.LLVMValueRef
39         }
40         BasicBlock struct {
41                 C C.LLVMBasicBlockRef
42         }
43         Builder struct {
44                 C C.LLVMBuilderRef
45         }
46         ModuleProvider struct {
47                 C C.LLVMModuleProviderRef
48         }
49         MemoryBuffer struct {
50                 C C.LLVMMemoryBufferRef
51         }
52         PassManager struct {
53                 C C.LLVMPassManagerRef
54         }
55         Use struct {
56                 C C.LLVMUseRef
57         }
58         Attribute        uint64
59         Opcode           C.LLVMOpcode
60         TypeKind         C.LLVMTypeKind
61         Linkage          C.LLVMLinkage
62         Visibility       C.LLVMVisibility
63         CallConv         C.LLVMCallConv
64         IntPredicate     C.LLVMIntPredicate
65         FloatPredicate   C.LLVMRealPredicate
66         LandingPadClause C.LLVMLandingPadClauseTy
67 )
68
69 func (c Context) IsNil() bool        { return c.C == nil }
70 func (c Module) IsNil() bool         { return c.C == nil }
71 func (c Type) IsNil() bool           { return c.C == nil }
72 func (c Value) IsNil() bool          { return c.C == nil }
73 func (c BasicBlock) IsNil() bool     { return c.C == nil }
74 func (c Builder) IsNil() bool        { return c.C == nil }
75 func (c ModuleProvider) IsNil() bool { return c.C == nil }
76 func (c MemoryBuffer) IsNil() bool   { return c.C == nil }
77 func (c PassManager) IsNil() bool    { return c.C == nil }
78 func (c Use) IsNil() bool            { return c.C == nil }
79
80 // helpers
81 func llvmTypeRefPtr(t *Type) *C.LLVMTypeRef    { return (*C.LLVMTypeRef)(unsafe.Pointer(t)) }
82 func llvmValueRefPtr(t *Value) *C.LLVMValueRef { return (*C.LLVMValueRef)(unsafe.Pointer(t)) }
83 func llvmBasicBlockRefPtr(t *BasicBlock) *C.LLVMBasicBlockRef {
84         return (*C.LLVMBasicBlockRef)(unsafe.Pointer(t))
85 }
86 func boolToLLVMBool(b bool) C.LLVMBool {
87         if b {
88                 return C.LLVMBool(1)
89         }
90         return C.LLVMBool(0)
91 }
92
93 func llvmValueRefs(values []Value) (*C.LLVMValueRef, C.unsigned) {
94         var pt *C.LLVMValueRef
95         ptlen := C.unsigned(len(values))
96         if ptlen > 0 {
97                 pt = llvmValueRefPtr(&values[0])
98         }
99         return pt, ptlen
100 }
101
102 //-------------------------------------------------------------------------
103 // llvm.Attribute
104 //-------------------------------------------------------------------------
105
106 const (
107         NoneAttribute               Attribute = 0
108         ZExtAttribute               Attribute = C.LLVMZExtAttribute
109         SExtAttribute               Attribute = C.LLVMSExtAttribute
110         NoReturnAttribute           Attribute = C.LLVMNoReturnAttribute
111         InRegAttribute              Attribute = C.LLVMInRegAttribute
112         StructRetAttribute          Attribute = C.LLVMStructRetAttribute
113         NoUnwindAttribute           Attribute = C.LLVMNoUnwindAttribute
114         NoAliasAttribute            Attribute = C.LLVMNoAliasAttribute
115         ByValAttribute              Attribute = C.LLVMByValAttribute
116         NestAttribute               Attribute = C.LLVMNestAttribute
117         ReadNoneAttribute           Attribute = C.LLVMReadNoneAttribute
118         ReadOnlyAttribute           Attribute = C.LLVMReadOnlyAttribute
119         NoInlineAttribute           Attribute = C.LLVMNoInlineAttribute
120         AlwaysInlineAttribute       Attribute = C.LLVMAlwaysInlineAttribute
121         OptimizeForSizeAttribute    Attribute = C.LLVMOptimizeForSizeAttribute
122         StackProtectAttribute       Attribute = C.LLVMStackProtectAttribute
123         StackProtectReqAttribute    Attribute = C.LLVMStackProtectReqAttribute
124         Alignment                   Attribute = C.LLVMAlignment
125         NoCaptureAttribute          Attribute = C.LLVMNoCaptureAttribute
126         NoRedZoneAttribute          Attribute = C.LLVMNoRedZoneAttribute
127         NoImplicitFloatAttribute    Attribute = C.LLVMNoImplicitFloatAttribute
128         NakedAttribute              Attribute = C.LLVMNakedAttribute
129         InlineHintAttribute         Attribute = C.LLVMInlineHintAttribute
130         StackAlignment              Attribute = C.LLVMStackAlignment
131         ReturnsTwiceAttribute       Attribute = C.LLVMReturnsTwice
132         UWTableAttribute            Attribute = C.LLVMUWTable
133         NonLazyBindAttribute        Attribute = 1 << 31
134         SanitizeAddressAttribute    Attribute = 1 << 32
135         MinSizeAttribute            Attribute = 1 << 33
136         NoDuplicateAttribute        Attribute = 1 << 34
137         StackProtectStrongAttribute Attribute = 1 << 35
138         SanitizeThreadAttribute     Attribute = 1 << 36
139         SanitizeMemoryAttribute     Attribute = 1 << 37
140         NoBuiltinAttribute          Attribute = 1 << 38
141         ReturnedAttribute           Attribute = 1 << 39
142         ColdAttribute               Attribute = 1 << 40
143         BuiltinAttribute            Attribute = 1 << 41
144         OptimizeNoneAttribute       Attribute = 1 << 42
145         InAllocaAttribute           Attribute = 1 << 43
146         NonNullAttribute            Attribute = 1 << 44
147         JumpTableAttribute          Attribute = 1 << 45
148 )
149
150 //-------------------------------------------------------------------------
151 // llvm.Opcode
152 //-------------------------------------------------------------------------
153
154 const (
155         Ret         Opcode = C.LLVMRet
156         Br          Opcode = C.LLVMBr
157         Switch      Opcode = C.LLVMSwitch
158         IndirectBr  Opcode = C.LLVMIndirectBr
159         Invoke      Opcode = C.LLVMInvoke
160         Unreachable Opcode = C.LLVMUnreachable
161
162         // Standard Binary Operators
163         Add  Opcode = C.LLVMAdd
164         FAdd Opcode = C.LLVMFAdd
165         Sub  Opcode = C.LLVMSub
166         FSub Opcode = C.LLVMFSub
167         Mul  Opcode = C.LLVMMul
168         FMul Opcode = C.LLVMFMul
169         UDiv Opcode = C.LLVMUDiv
170         SDiv Opcode = C.LLVMSDiv
171         FDiv Opcode = C.LLVMFDiv
172         URem Opcode = C.LLVMURem
173         SRem Opcode = C.LLVMSRem
174         FRem Opcode = C.LLVMFRem
175
176         // Logical Operators
177         Shl  Opcode = C.LLVMShl
178         LShr Opcode = C.LLVMLShr
179         AShr Opcode = C.LLVMAShr
180         And  Opcode = C.LLVMAnd
181         Or   Opcode = C.LLVMOr
182         Xor  Opcode = C.LLVMXor
183
184         // Memory Operators
185         Alloca        Opcode = C.LLVMAlloca
186         Load          Opcode = C.LLVMLoad
187         Store         Opcode = C.LLVMStore
188         GetElementPtr Opcode = C.LLVMGetElementPtr
189
190         // Cast Operators
191         Trunc    Opcode = C.LLVMTrunc
192         ZExt     Opcode = C.LLVMZExt
193         SExt     Opcode = C.LLVMSExt
194         FPToUI   Opcode = C.LLVMFPToUI
195         FPToSI   Opcode = C.LLVMFPToSI
196         UIToFP   Opcode = C.LLVMUIToFP
197         SIToFP   Opcode = C.LLVMSIToFP
198         FPTrunc  Opcode = C.LLVMFPTrunc
199         FPExt    Opcode = C.LLVMFPExt
200         PtrToInt Opcode = C.LLVMPtrToInt
201         IntToPtr Opcode = C.LLVMIntToPtr
202         BitCast  Opcode = C.LLVMBitCast
203
204         // Other Operators
205         ICmp   Opcode = C.LLVMICmp
206         FCmp   Opcode = C.LLVMFCmp
207         PHI    Opcode = C.LLVMPHI
208         Call   Opcode = C.LLVMCall
209         Select Opcode = C.LLVMSelect
210         // UserOp1
211         // UserOp2
212         VAArg          Opcode = C.LLVMVAArg
213         ExtractElement Opcode = C.LLVMExtractElement
214         InsertElement  Opcode = C.LLVMInsertElement
215         ShuffleVector  Opcode = C.LLVMShuffleVector
216         ExtractValue   Opcode = C.LLVMExtractValue
217         InsertValue    Opcode = C.LLVMInsertValue
218 )
219
220 //-------------------------------------------------------------------------
221 // llvm.TypeKind
222 //-------------------------------------------------------------------------
223
224 const (
225         VoidTypeKind      TypeKind = C.LLVMVoidTypeKind
226         FloatTypeKind     TypeKind = C.LLVMFloatTypeKind
227         DoubleTypeKind    TypeKind = C.LLVMDoubleTypeKind
228         X86_FP80TypeKind  TypeKind = C.LLVMX86_FP80TypeKind
229         FP128TypeKind     TypeKind = C.LLVMFP128TypeKind
230         PPC_FP128TypeKind TypeKind = C.LLVMPPC_FP128TypeKind
231         LabelTypeKind     TypeKind = C.LLVMLabelTypeKind
232         IntegerTypeKind   TypeKind = C.LLVMIntegerTypeKind
233         FunctionTypeKind  TypeKind = C.LLVMFunctionTypeKind
234         StructTypeKind    TypeKind = C.LLVMStructTypeKind
235         ArrayTypeKind     TypeKind = C.LLVMArrayTypeKind
236         PointerTypeKind   TypeKind = C.LLVMPointerTypeKind
237         VectorTypeKind    TypeKind = C.LLVMVectorTypeKind
238         MetadataTypeKind  TypeKind = C.LLVMMetadataTypeKind
239 )
240
241 //-------------------------------------------------------------------------
242 // llvm.Linkage
243 //-------------------------------------------------------------------------
244
245 const (
246         ExternalLinkage            Linkage = C.LLVMExternalLinkage
247         AvailableExternallyLinkage Linkage = C.LLVMAvailableExternallyLinkage
248         LinkOnceAnyLinkage         Linkage = C.LLVMLinkOnceAnyLinkage
249         LinkOnceODRLinkage         Linkage = C.LLVMLinkOnceODRLinkage
250         WeakAnyLinkage             Linkage = C.LLVMWeakAnyLinkage
251         WeakODRLinkage             Linkage = C.LLVMWeakODRLinkage
252         AppendingLinkage           Linkage = C.LLVMAppendingLinkage
253         InternalLinkage            Linkage = C.LLVMInternalLinkage
254         PrivateLinkage             Linkage = C.LLVMPrivateLinkage
255         ExternalWeakLinkage        Linkage = C.LLVMExternalWeakLinkage
256         CommonLinkage              Linkage = C.LLVMCommonLinkage
257 )
258
259 //-------------------------------------------------------------------------
260 // llvm.Visibility
261 //-------------------------------------------------------------------------
262
263 const (
264         DefaultVisibility   Visibility = C.LLVMDefaultVisibility
265         HiddenVisibility    Visibility = C.LLVMHiddenVisibility
266         ProtectedVisibility Visibility = C.LLVMProtectedVisibility
267 )
268
269 //-------------------------------------------------------------------------
270 // llvm.CallConv
271 //-------------------------------------------------------------------------
272
273 const (
274         CCallConv           CallConv = C.LLVMCCallConv
275         FastCallConv        CallConv = C.LLVMFastCallConv
276         ColdCallConv        CallConv = C.LLVMColdCallConv
277         X86StdcallCallConv  CallConv = C.LLVMX86StdcallCallConv
278         X86FastcallCallConv CallConv = C.LLVMX86FastcallCallConv
279 )
280
281 //-------------------------------------------------------------------------
282 // llvm.IntPredicate
283 //-------------------------------------------------------------------------
284
285 const (
286         IntEQ  IntPredicate = C.LLVMIntEQ
287         IntNE  IntPredicate = C.LLVMIntNE
288         IntUGT IntPredicate = C.LLVMIntUGT
289         IntUGE IntPredicate = C.LLVMIntUGE
290         IntULT IntPredicate = C.LLVMIntULT
291         IntULE IntPredicate = C.LLVMIntULE
292         IntSGT IntPredicate = C.LLVMIntSGT
293         IntSGE IntPredicate = C.LLVMIntSGE
294         IntSLT IntPredicate = C.LLVMIntSLT
295         IntSLE IntPredicate = C.LLVMIntSLE
296 )
297
298 //-------------------------------------------------------------------------
299 // llvm.FloatPredicate
300 //-------------------------------------------------------------------------
301
302 const (
303         FloatPredicateFalse FloatPredicate = C.LLVMRealPredicateFalse
304         FloatOEQ            FloatPredicate = C.LLVMRealOEQ
305         FloatOGT            FloatPredicate = C.LLVMRealOGT
306         FloatOGE            FloatPredicate = C.LLVMRealOGE
307         FloatOLT            FloatPredicate = C.LLVMRealOLT
308         FloatOLE            FloatPredicate = C.LLVMRealOLE
309         FloatONE            FloatPredicate = C.LLVMRealONE
310         FloatORD            FloatPredicate = C.LLVMRealORD
311         FloatUNO            FloatPredicate = C.LLVMRealUNO
312         FloatUEQ            FloatPredicate = C.LLVMRealUEQ
313         FloatUGT            FloatPredicate = C.LLVMRealUGT
314         FloatUGE            FloatPredicate = C.LLVMRealUGE
315         FloatULT            FloatPredicate = C.LLVMRealULT
316         FloatULE            FloatPredicate = C.LLVMRealULE
317         FloatUNE            FloatPredicate = C.LLVMRealUNE
318         FloatPredicateTrue  FloatPredicate = C.LLVMRealPredicateTrue
319 )
320
321 //-------------------------------------------------------------------------
322 // llvm.LandingPadClause
323 //-------------------------------------------------------------------------
324
325 const (
326         LandingPadCatch  LandingPadClause = C.LLVMLandingPadCatch
327         LandingPadFilter LandingPadClause = C.LLVMLandingPadFilter
328 )
329
330 //-------------------------------------------------------------------------
331 // llvm.Context
332 //-------------------------------------------------------------------------
333
334 func NewContext() Context    { return Context{C.LLVMContextCreate()} }
335 func GlobalContext() Context { return Context{C.LLVMGetGlobalContext()} }
336 func (c Context) Dispose()   { C.LLVMContextDispose(c.C) }
337
338 func (c Context) MDKindID(name string) (id int) {
339         cname := C.CString(name)
340         defer C.free(unsafe.Pointer(cname))
341         id = int(C.LLVMGetMDKindIDInContext(c.C, cname, C.unsigned(len(name))))
342         return
343 }
344
345 func MDKindID(name string) (id int) {
346         cname := C.CString(name)
347         defer C.free(unsafe.Pointer(cname))
348         id = int(C.LLVMGetMDKindID(cname, C.unsigned(len(name))))
349         return
350 }
351
352 //-------------------------------------------------------------------------
353 // llvm.Module
354 //-------------------------------------------------------------------------
355
356 // Create and destroy modules.
357 // See llvm::Module::Module.
358 func NewModule(name string) (m Module) {
359         cname := C.CString(name)
360         defer C.free(unsafe.Pointer(cname))
361         m.C = C.LLVMModuleCreateWithName(cname)
362         return
363 }
364
365 func (c Context) NewModule(name string) (m Module) {
366         cname := C.CString(name)
367         defer C.free(unsafe.Pointer(cname))
368         m.C = C.LLVMModuleCreateWithNameInContext(cname, c.C)
369         return
370 }
371
372 // See llvm::Module::~Module
373 func (m Module) Dispose() { C.LLVMDisposeModule(m.C) }
374
375 // Data layout. See Module::getDataLayout.
376 func (m Module) DataLayout() string {
377         clayout := C.LLVMGetDataLayout(m.C)
378         return C.GoString(clayout)
379 }
380
381 func (m Module) SetDataLayout(layout string) {
382         clayout := C.CString(layout)
383         defer C.free(unsafe.Pointer(clayout))
384         C.LLVMSetDataLayout(m.C, clayout)
385 }
386
387 // Target triple. See Module::getTargetTriple.
388 func (m Module) Target() string {
389         ctarget := C.LLVMGetTarget(m.C)
390         return C.GoString(ctarget)
391 }
392 func (m Module) SetTarget(target string) {
393         ctarget := C.CString(target)
394         defer C.free(unsafe.Pointer(ctarget))
395         C.LLVMSetTarget(m.C, ctarget)
396 }
397
398 func (m Module) GetTypeByName(name string) (t Type) {
399         cname := C.CString(name)
400         defer C.free(unsafe.Pointer(cname))
401         t.C = C.LLVMGetTypeByName(m.C, cname)
402         return
403 }
404
405 // See Module::dump.
406 func (m Module) Dump() {
407         C.LLVMDumpModule(m.C)
408 }
409
410 func (m Module) String() string {
411         cir := C.LLVMPrintModuleToString(m.C)
412         defer C.free(unsafe.Pointer(cir))
413         ir := C.GoString(cir)
414         return ir
415 }
416
417 // See Module::setModuleInlineAsm.
418 func (m Module) SetInlineAsm(asm string) {
419         casm := C.CString(asm)
420         defer C.free(unsafe.Pointer(casm))
421         C.LLVMSetModuleInlineAsm(m.C, casm)
422 }
423
424 func (m Module) AddNamedMetadataOperand(name string, operand Value) {
425         cname := C.CString(name)
426         defer C.free(unsafe.Pointer(cname))
427         C.LLVMAddNamedMetadataOperand(m.C, cname, operand.C)
428 }
429
430 func (m Module) Context() (c Context) {
431         c.C = C.LLVMGetModuleContext(m.C)
432         return
433 }
434
435 //-------------------------------------------------------------------------
436 // llvm.Type
437 //-------------------------------------------------------------------------
438
439 // LLVM types conform to the following hierarchy:
440 //
441 //   types:
442 //     integer type
443 //     real type
444 //     function type
445 //     sequence types:
446 //       array type
447 //       pointer type
448 //       vector type
449 //     void type
450 //     label type
451 //     opaque type
452
453 // See llvm::LLVMTypeKind::getTypeID.
454 func (t Type) TypeKind() TypeKind { return TypeKind(C.LLVMGetTypeKind(t.C)) }
455
456 // See llvm::LLVMType::getContext.
457 func (t Type) Context() (c Context) {
458         c.C = C.LLVMGetTypeContext(t.C)
459         return
460 }
461
462 // Operations on integer types
463 func (c Context) Int1Type() (t Type)  { t.C = C.LLVMInt1TypeInContext(c.C); return }
464 func (c Context) Int8Type() (t Type)  { t.C = C.LLVMInt8TypeInContext(c.C); return }
465 func (c Context) Int16Type() (t Type) { t.C = C.LLVMInt16TypeInContext(c.C); return }
466 func (c Context) Int32Type() (t Type) { t.C = C.LLVMInt32TypeInContext(c.C); return }
467 func (c Context) Int64Type() (t Type) { t.C = C.LLVMInt64TypeInContext(c.C); return }
468 func (c Context) IntType(numbits int) (t Type) {
469         t.C = C.LLVMIntTypeInContext(c.C, C.unsigned(numbits))
470         return
471 }
472
473 func Int1Type() (t Type)  { t.C = C.LLVMInt1Type(); return }
474 func Int8Type() (t Type)  { t.C = C.LLVMInt8Type(); return }
475 func Int16Type() (t Type) { t.C = C.LLVMInt16Type(); return }
476 func Int32Type() (t Type) { t.C = C.LLVMInt32Type(); return }
477 func Int64Type() (t Type) { t.C = C.LLVMInt64Type(); return }
478
479 func IntType(numbits int) (t Type) {
480         t.C = C.LLVMIntType(C.unsigned(numbits))
481         return
482 }
483
484 func (t Type) IntTypeWidth() int {
485         return int(C.LLVMGetIntTypeWidth(t.C))
486 }
487
488 // Operations on real types
489 func (c Context) FloatType() (t Type)    { t.C = C.LLVMFloatTypeInContext(c.C); return }
490 func (c Context) DoubleType() (t Type)   { t.C = C.LLVMDoubleTypeInContext(c.C); return }
491 func (c Context) X86FP80Type() (t Type)  { t.C = C.LLVMX86FP80TypeInContext(c.C); return }
492 func (c Context) FP128Type() (t Type)    { t.C = C.LLVMFP128TypeInContext(c.C); return }
493 func (c Context) PPCFP128Type() (t Type) { t.C = C.LLVMPPCFP128TypeInContext(c.C); return }
494
495 func FloatType() (t Type)    { t.C = C.LLVMFloatType(); return }
496 func DoubleType() (t Type)   { t.C = C.LLVMDoubleType(); return }
497 func X86FP80Type() (t Type)  { t.C = C.LLVMX86FP80Type(); return }
498 func FP128Type() (t Type)    { t.C = C.LLVMFP128Type(); return }
499 func PPCFP128Type() (t Type) { t.C = C.LLVMPPCFP128Type(); return }
500
501 // Operations on function types
502 func FunctionType(returnType Type, paramTypes []Type, isVarArg bool) (t Type) {
503         var pt *C.LLVMTypeRef
504         var ptlen C.unsigned
505         if len(paramTypes) > 0 {
506                 pt = llvmTypeRefPtr(&paramTypes[0])
507                 ptlen = C.unsigned(len(paramTypes))
508         }
509         t.C = C.LLVMFunctionType(returnType.C,
510                 pt,
511                 ptlen,
512                 boolToLLVMBool(isVarArg))
513         return
514 }
515
516 func (t Type) IsFunctionVarArg() bool { return C.LLVMIsFunctionVarArg(t.C) != 0 }
517 func (t Type) ReturnType() (rt Type)  { rt.C = C.LLVMGetReturnType(t.C); return }
518 func (t Type) ParamTypesCount() int   { return int(C.LLVMCountParamTypes(t.C)) }
519 func (t Type) ParamTypes() []Type {
520         count := t.ParamTypesCount()
521         if count > 0 {
522                 out := make([]Type, count)
523                 C.LLVMGetParamTypes(t.C, llvmTypeRefPtr(&out[0]))
524                 return out
525         }
526         return nil
527 }
528
529 // Operations on struct types
530 func (c Context) StructType(elementTypes []Type, packed bool) (t Type) {
531         var pt *C.LLVMTypeRef
532         var ptlen C.unsigned
533         if len(elementTypes) > 0 {
534                 pt = llvmTypeRefPtr(&elementTypes[0])
535                 ptlen = C.unsigned(len(elementTypes))
536         }
537         t.C = C.LLVMStructTypeInContext(c.C,
538                 pt,
539                 ptlen,
540                 boolToLLVMBool(packed))
541         return
542 }
543
544 func StructType(elementTypes []Type, packed bool) (t Type) {
545         var pt *C.LLVMTypeRef
546         var ptlen C.unsigned
547         if len(elementTypes) > 0 {
548                 pt = llvmTypeRefPtr(&elementTypes[0])
549                 ptlen = C.unsigned(len(elementTypes))
550         }
551         t.C = C.LLVMStructType(pt, ptlen, boolToLLVMBool(packed))
552         return
553 }
554
555 func (c Context) StructCreateNamed(name string) (t Type) {
556         cname := C.CString(name)
557         defer C.free(unsafe.Pointer(cname))
558         t.C = C.LLVMStructCreateNamed(c.C, cname)
559         return
560 }
561
562 func (t Type) StructName() string {
563         return C.GoString(C.LLVMGetStructName(t.C))
564 }
565
566 func (t Type) StructSetBody(elementTypes []Type, packed bool) {
567         var pt *C.LLVMTypeRef
568         var ptlen C.unsigned
569         if len(elementTypes) > 0 {
570                 pt = llvmTypeRefPtr(&elementTypes[0])
571                 ptlen = C.unsigned(len(elementTypes))
572         }
573         C.LLVMStructSetBody(t.C, pt, ptlen, boolToLLVMBool(packed))
574 }
575
576 func (t Type) IsStructPacked() bool         { return C.LLVMIsPackedStruct(t.C) != 0 }
577 func (t Type) StructElementTypesCount() int { return int(C.LLVMCountStructElementTypes(t.C)) }
578 func (t Type) StructElementTypes() []Type {
579         out := make([]Type, t.StructElementTypesCount())
580         if len(out) > 0 {
581                 C.LLVMGetStructElementTypes(t.C, llvmTypeRefPtr(&out[0]))
582         }
583         return out
584 }
585
586 // Operations on array, pointer, and vector types (sequence types)
587 func ArrayType(elementType Type, elementCount int) (t Type) {
588         t.C = C.LLVMArrayType(elementType.C, C.unsigned(elementCount))
589         return
590 }
591 func PointerType(elementType Type, addressSpace int) (t Type) {
592         t.C = C.LLVMPointerType(elementType.C, C.unsigned(addressSpace))
593         return
594 }
595 func VectorType(elementType Type, elementCount int) (t Type) {
596         t.C = C.LLVMVectorType(elementType.C, C.unsigned(elementCount))
597         return
598 }
599
600 func (t Type) ElementType() (rt Type)   { rt.C = C.LLVMGetElementType(t.C); return }
601 func (t Type) ArrayLength() int         { return int(C.LLVMGetArrayLength(t.C)) }
602 func (t Type) PointerAddressSpace() int { return int(C.LLVMGetPointerAddressSpace(t.C)) }
603 func (t Type) VectorSize() int          { return int(C.LLVMGetVectorSize(t.C)) }
604
605 // Operations on other types
606 func (c Context) VoidType() (t Type)  { t.C = C.LLVMVoidTypeInContext(c.C); return }
607 func (c Context) LabelType() (t Type) { t.C = C.LLVMLabelTypeInContext(c.C); return }
608
609 func VoidType() (t Type)  { t.C = C.LLVMVoidType(); return }
610 func LabelType() (t Type) { t.C = C.LLVMLabelType(); return }
611
612 //-------------------------------------------------------------------------
613 // llvm.Value
614 //-------------------------------------------------------------------------
615
616 // Operations on all values
617 func (v Value) Type() (t Type) { t.C = C.LLVMTypeOf(v.C); return }
618 func (v Value) Name() string   { return C.GoString(C.LLVMGetValueName(v.C)) }
619 func (v Value) SetName(name string) {
620         cname := C.CString(name)
621         defer C.free(unsafe.Pointer(cname))
622         C.LLVMSetValueName(v.C, cname)
623 }
624 func (v Value) Dump()                       { C.LLVMDumpValue(v.C) }
625 func (v Value) ReplaceAllUsesWith(nv Value) { C.LLVMReplaceAllUsesWith(v.C, nv.C) }
626 func (v Value) HasMetadata() bool           { return C.LLVMHasMetadata(v.C) != 0 }
627 func (v Value) Metadata(kind int) (rv Value) {
628         rv.C = C.LLVMGetMetadata(v.C, C.unsigned(kind))
629         return
630 }
631 func (v Value) SetMetadata(kind int, node Value) {
632         C.LLVMSetMetadata(v.C, C.unsigned(kind), node.C)
633 }
634
635 // Conversion functions.
636 // Return the input value if it is an instance of the specified class, otherwise NULL.
637 // See llvm::dyn_cast_or_null<>.
638 func (v Value) IsAArgument() (rv Value)   { rv.C = C.LLVMIsAArgument(v.C); return }
639 func (v Value) IsABasicBlock() (rv Value) { rv.C = C.LLVMIsABasicBlock(v.C); return }
640 func (v Value) IsAInlineAsm() (rv Value)  { rv.C = C.LLVMIsAInlineAsm(v.C); return }
641 func (v Value) IsAUser() (rv Value)       { rv.C = C.LLVMIsAUser(v.C); return }
642 func (v Value) IsAConstant() (rv Value)   { rv.C = C.LLVMIsAConstant(v.C); return }
643 func (v Value) IsAConstantAggregateZero() (rv Value) {
644         rv.C = C.LLVMIsAConstantAggregateZero(v.C)
645         return
646 }
647 func (v Value) IsAConstantArray() (rv Value)       { rv.C = C.LLVMIsAConstantArray(v.C); return }
648 func (v Value) IsAConstantExpr() (rv Value)        { rv.C = C.LLVMIsAConstantExpr(v.C); return }
649 func (v Value) IsAConstantFP() (rv Value)          { rv.C = C.LLVMIsAConstantFP(v.C); return }
650 func (v Value) IsAConstantInt() (rv Value)         { rv.C = C.LLVMIsAConstantInt(v.C); return }
651 func (v Value) IsAConstantPointerNull() (rv Value) { rv.C = C.LLVMIsAConstantPointerNull(v.C); return }
652 func (v Value) IsAConstantStruct() (rv Value)      { rv.C = C.LLVMIsAConstantStruct(v.C); return }
653 func (v Value) IsAConstantVector() (rv Value)      { rv.C = C.LLVMIsAConstantVector(v.C); return }
654 func (v Value) IsAGlobalValue() (rv Value)         { rv.C = C.LLVMIsAGlobalValue(v.C); return }
655 func (v Value) IsAFunction() (rv Value)            { rv.C = C.LLVMIsAFunction(v.C); return }
656 func (v Value) IsAGlobalAlias() (rv Value)         { rv.C = C.LLVMIsAGlobalAlias(v.C); return }
657 func (v Value) IsAGlobalVariable() (rv Value)      { rv.C = C.LLVMIsAGlobalVariable(v.C); return }
658 func (v Value) IsAUndefValue() (rv Value)          { rv.C = C.LLVMIsAUndefValue(v.C); return }
659 func (v Value) IsAInstruction() (rv Value)         { rv.C = C.LLVMIsAInstruction(v.C); return }
660 func (v Value) IsABinaryOperator() (rv Value)      { rv.C = C.LLVMIsABinaryOperator(v.C); return }
661 func (v Value) IsACallInst() (rv Value)            { rv.C = C.LLVMIsACallInst(v.C); return }
662 func (v Value) IsAIntrinsicInst() (rv Value)       { rv.C = C.LLVMIsAIntrinsicInst(v.C); return }
663 func (v Value) IsADbgInfoIntrinsic() (rv Value)    { rv.C = C.LLVMIsADbgInfoIntrinsic(v.C); return }
664 func (v Value) IsADbgDeclareInst() (rv Value)      { rv.C = C.LLVMIsADbgDeclareInst(v.C); return }
665 func (v Value) IsAMemIntrinsic() (rv Value)        { rv.C = C.LLVMIsAMemIntrinsic(v.C); return }
666 func (v Value) IsAMemCpyInst() (rv Value)          { rv.C = C.LLVMIsAMemCpyInst(v.C); return }
667 func (v Value) IsAMemMoveInst() (rv Value)         { rv.C = C.LLVMIsAMemMoveInst(v.C); return }
668 func (v Value) IsAMemSetInst() (rv Value)          { rv.C = C.LLVMIsAMemSetInst(v.C); return }
669 func (v Value) IsACmpInst() (rv Value)             { rv.C = C.LLVMIsACmpInst(v.C); return }
670 func (v Value) IsAFCmpInst() (rv Value)            { rv.C = C.LLVMIsAFCmpInst(v.C); return }
671 func (v Value) IsAICmpInst() (rv Value)            { rv.C = C.LLVMIsAICmpInst(v.C); return }
672 func (v Value) IsAExtractElementInst() (rv Value)  { rv.C = C.LLVMIsAExtractElementInst(v.C); return }
673 func (v Value) IsAGetElementPtrInst() (rv Value)   { rv.C = C.LLVMIsAGetElementPtrInst(v.C); return }
674 func (v Value) IsAInsertElementInst() (rv Value)   { rv.C = C.LLVMIsAInsertElementInst(v.C); return }
675 func (v Value) IsAInsertValueInst() (rv Value)     { rv.C = C.LLVMIsAInsertValueInst(v.C); return }
676 func (v Value) IsAPHINode() (rv Value)             { rv.C = C.LLVMIsAPHINode(v.C); return }
677 func (v Value) IsASelectInst() (rv Value)          { rv.C = C.LLVMIsASelectInst(v.C); return }
678 func (v Value) IsAShuffleVectorInst() (rv Value)   { rv.C = C.LLVMIsAShuffleVectorInst(v.C); return }
679 func (v Value) IsAStoreInst() (rv Value)           { rv.C = C.LLVMIsAStoreInst(v.C); return }
680 func (v Value) IsATerminatorInst() (rv Value)      { rv.C = C.LLVMIsATerminatorInst(v.C); return }
681 func (v Value) IsABranchInst() (rv Value)          { rv.C = C.LLVMIsABranchInst(v.C); return }
682 func (v Value) IsAInvokeInst() (rv Value)          { rv.C = C.LLVMIsAInvokeInst(v.C); return }
683 func (v Value) IsAReturnInst() (rv Value)          { rv.C = C.LLVMIsAReturnInst(v.C); return }
684 func (v Value) IsASwitchInst() (rv Value)          { rv.C = C.LLVMIsASwitchInst(v.C); return }
685 func (v Value) IsAUnreachableInst() (rv Value)     { rv.C = C.LLVMIsAUnreachableInst(v.C); return }
686 func (v Value) IsAUnaryInstruction() (rv Value)    { rv.C = C.LLVMIsAUnaryInstruction(v.C); return }
687 func (v Value) IsAAllocaInst() (rv Value)          { rv.C = C.LLVMIsAAllocaInst(v.C); return }
688 func (v Value) IsACastInst() (rv Value)            { rv.C = C.LLVMIsACastInst(v.C); return }
689 func (v Value) IsABitCastInst() (rv Value)         { rv.C = C.LLVMIsABitCastInst(v.C); return }
690 func (v Value) IsAFPExtInst() (rv Value)           { rv.C = C.LLVMIsAFPExtInst(v.C); return }
691 func (v Value) IsAFPToSIInst() (rv Value)          { rv.C = C.LLVMIsAFPToSIInst(v.C); return }
692 func (v Value) IsAFPToUIInst() (rv Value)          { rv.C = C.LLVMIsAFPToUIInst(v.C); return }
693 func (v Value) IsAFPTruncInst() (rv Value)         { rv.C = C.LLVMIsAFPTruncInst(v.C); return }
694 func (v Value) IsAIntToPtrInst() (rv Value)        { rv.C = C.LLVMIsAIntToPtrInst(v.C); return }
695 func (v Value) IsAPtrToIntInst() (rv Value)        { rv.C = C.LLVMIsAPtrToIntInst(v.C); return }
696 func (v Value) IsASExtInst() (rv Value)            { rv.C = C.LLVMIsASExtInst(v.C); return }
697 func (v Value) IsASIToFPInst() (rv Value)          { rv.C = C.LLVMIsASIToFPInst(v.C); return }
698 func (v Value) IsATruncInst() (rv Value)           { rv.C = C.LLVMIsATruncInst(v.C); return }
699 func (v Value) IsAUIToFPInst() (rv Value)          { rv.C = C.LLVMIsAUIToFPInst(v.C); return }
700 func (v Value) IsAZExtInst() (rv Value)            { rv.C = C.LLVMIsAZExtInst(v.C); return }
701 func (v Value) IsAExtractValueInst() (rv Value)    { rv.C = C.LLVMIsAExtractValueInst(v.C); return }
702 func (v Value) IsALoadInst() (rv Value)            { rv.C = C.LLVMIsALoadInst(v.C); return }
703 func (v Value) IsAVAArgInst() (rv Value)           { rv.C = C.LLVMIsAVAArgInst(v.C); return }
704
705 // Operations on Uses
706 func (v Value) FirstUse() (u Use)  { u.C = C.LLVMGetFirstUse(v.C); return }
707 func (u Use) NextUse() (ru Use)    { ru.C = C.LLVMGetNextUse(u.C); return }
708 func (u Use) User() (v Value)      { v.C = C.LLVMGetUser(u.C); return }
709 func (u Use) UsedValue() (v Value) { v.C = C.LLVMGetUsedValue(u.C); return }
710
711 // Operations on Users
712 func (v Value) Operand(i int) (rv Value)   { rv.C = C.LLVMGetOperand(v.C, C.unsigned(i)); return }
713 func (v Value) SetOperand(i int, op Value) { C.LLVMSetOperand(v.C, C.unsigned(i), op.C) }
714 func (v Value) OperandsCount() int         { return int(C.LLVMGetNumOperands(v.C)) }
715
716 // Operations on constants of any type
717 func ConstNull(t Type) (v Value)        { v.C = C.LLVMConstNull(t.C); return }
718 func ConstAllOnes(t Type) (v Value)     { v.C = C.LLVMConstAllOnes(t.C); return }
719 func Undef(t Type) (v Value)            { v.C = C.LLVMGetUndef(t.C); return }
720 func (v Value) IsConstant() bool        { return C.LLVMIsConstant(v.C) != 0 }
721 func (v Value) IsNull() bool            { return C.LLVMIsNull(v.C) != 0 }
722 func (v Value) IsUndef() bool           { return C.LLVMIsUndef(v.C) != 0 }
723 func ConstPointerNull(t Type) (v Value) { v.C = C.LLVMConstPointerNull(t.C); return }
724
725 // Operations on metadata
726 func (c Context) MDString(str string) (v Value) {
727         cstr := C.CString(str)
728         defer C.free(unsafe.Pointer(cstr))
729         v.C = C.LLVMMDStringInContext(c.C, cstr, C.unsigned(len(str)))
730         return
731 }
732 func MDString(str string) (v Value) {
733         cstr := C.CString(str)
734         defer C.free(unsafe.Pointer(cstr))
735         v.C = C.LLVMMDString(cstr, C.unsigned(len(str)))
736         return
737 }
738 func (c Context) MDNode(vals []Value) (v Value) {
739         ptr, nvals := llvmValueRefs(vals)
740         v.C = C.LLVMMDNodeInContext(c.C, ptr, nvals)
741         return
742 }
743 func MDNode(vals []Value) (v Value) {
744         ptr, nvals := llvmValueRefs(vals)
745         v.C = C.LLVMMDNode(ptr, nvals)
746         return
747 }
748
749 // Operations on scalar constants
750 func ConstInt(t Type, n uint64, signExtend bool) (v Value) {
751         v.C = C.LLVMConstInt(t.C,
752                 C.ulonglong(n),
753                 boolToLLVMBool(signExtend))
754         return
755 }
756 func ConstIntFromString(t Type, str string, radix int) (v Value) {
757         cstr := C.CString(str)
758         defer C.free(unsafe.Pointer(cstr))
759         v.C = C.LLVMConstIntOfString(t.C, cstr, C.uint8_t(radix))
760         return
761 }
762 func ConstFloat(t Type, n float64) (v Value) {
763         v.C = C.LLVMConstReal(t.C, C.double(n))
764         return
765 }
766 func ConstFloatFromString(t Type, str string) (v Value) {
767         cstr := C.CString(str)
768         defer C.free(unsafe.Pointer(cstr))
769         v.C = C.LLVMConstRealOfString(t.C, cstr)
770         return
771 }
772
773 func (v Value) ZExtValue() uint64 { return uint64(C.LLVMConstIntGetZExtValue(v.C)) }
774 func (v Value) SExtValue() int64  { return int64(C.LLVMConstIntGetSExtValue(v.C)) }
775
776 // Operations on composite constants
777 func (c Context) ConstString(str string, addnull bool) (v Value) {
778         cstr := C.CString(str)
779         defer C.free(unsafe.Pointer(cstr))
780         v.C = C.LLVMConstStringInContext(c.C, cstr,
781                 C.unsigned(len(str)), boolToLLVMBool(!addnull))
782         return
783 }
784 func (c Context) ConstStruct(constVals []Value, packed bool) (v Value) {
785         ptr, nvals := llvmValueRefs(constVals)
786         v.C = C.LLVMConstStructInContext(c.C, ptr, nvals,
787                 boolToLLVMBool(packed))
788         return
789 }
790 func ConstNamedStruct(t Type, constVals []Value) (v Value) {
791         ptr, nvals := llvmValueRefs(constVals)
792         v.C = C.LLVMConstNamedStruct(t.C, ptr, nvals)
793         return
794 }
795 func ConstString(str string, addnull bool) (v Value) {
796         cstr := C.CString(str)
797         defer C.free(unsafe.Pointer(cstr))
798         v.C = C.LLVMConstString(cstr,
799                 C.unsigned(len(str)), boolToLLVMBool(!addnull))
800         return
801 }
802 func ConstArray(t Type, constVals []Value) (v Value) {
803         ptr, nvals := llvmValueRefs(constVals)
804         v.C = C.LLVMConstArray(t.C, ptr, nvals)
805         return
806 }
807 func ConstStruct(constVals []Value, packed bool) (v Value) {
808         ptr, nvals := llvmValueRefs(constVals)
809         v.C = C.LLVMConstStruct(ptr, nvals, boolToLLVMBool(packed))
810         return
811 }
812 func ConstVector(scalarConstVals []Value, packed bool) (v Value) {
813         ptr, nvals := llvmValueRefs(scalarConstVals)
814         v.C = C.LLVMConstVector(ptr, nvals)
815         return
816 }
817
818 // Constant expressions
819 func (v Value) Opcode() Opcode                { return Opcode(C.LLVMGetConstOpcode(v.C)) }
820 func (v Value) InstructionOpcode() Opcode     { return Opcode(C.LLVMGetInstructionOpcode(v.C)) }
821 func AlignOf(t Type) (v Value)                { v.C = C.LLVMAlignOf(t.C); return }
822 func SizeOf(t Type) (v Value)                 { v.C = C.LLVMSizeOf(t.C); return }
823 func ConstNeg(v Value) (rv Value)             { rv.C = C.LLVMConstNeg(v.C); return }
824 func ConstNSWNeg(v Value) (rv Value)          { rv.C = C.LLVMConstNSWNeg(v.C); return }
825 func ConstNUWNeg(v Value) (rv Value)          { rv.C = C.LLVMConstNUWNeg(v.C); return }
826 func ConstFNeg(v Value) (rv Value)            { rv.C = C.LLVMConstFNeg(v.C); return }
827 func ConstNot(v Value) (rv Value)             { rv.C = C.LLVMConstNot(v.C); return }
828 func ConstAdd(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstAdd(lhs.C, rhs.C); return }
829 func ConstNSWAdd(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNSWAdd(lhs.C, rhs.C); return }
830 func ConstNUWAdd(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNUWAdd(lhs.C, rhs.C); return }
831 func ConstFAdd(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFAdd(lhs.C, rhs.C); return }
832 func ConstSub(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstSub(lhs.C, rhs.C); return }
833 func ConstNSWSub(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNSWSub(lhs.C, rhs.C); return }
834 func ConstNUWSub(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNUWSub(lhs.C, rhs.C); return }
835 func ConstFSub(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFSub(lhs.C, rhs.C); return }
836 func ConstMul(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstMul(lhs.C, rhs.C); return }
837 func ConstNSWMul(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNSWMul(lhs.C, rhs.C); return }
838 func ConstNUWMul(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNUWMul(lhs.C, rhs.C); return }
839 func ConstFMul(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFMul(lhs.C, rhs.C); return }
840 func ConstUDiv(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstUDiv(lhs.C, rhs.C); return }
841 func ConstSDiv(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstSDiv(lhs.C, rhs.C); return }
842 func ConstExactSDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstExactSDiv(lhs.C, rhs.C); return }
843 func ConstFDiv(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFDiv(lhs.C, rhs.C); return }
844 func ConstURem(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstURem(lhs.C, rhs.C); return }
845 func ConstSRem(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstSRem(lhs.C, rhs.C); return }
846 func ConstFRem(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFRem(lhs.C, rhs.C); return }
847 func ConstAnd(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstAnd(lhs.C, rhs.C); return }
848 func ConstOr(lhs, rhs Value) (v Value)        { v.C = C.LLVMConstOr(lhs.C, rhs.C); return }
849 func ConstXor(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstXor(lhs.C, rhs.C); return }
850
851 func ConstICmp(pred IntPredicate, lhs, rhs Value) (v Value) {
852         v.C = C.LLVMConstICmp(C.LLVMIntPredicate(pred), lhs.C, rhs.C)
853         return
854 }
855 func ConstFCmp(pred FloatPredicate, lhs, rhs Value) (v Value) {
856         v.C = C.LLVMConstFCmp(C.LLVMRealPredicate(pred), lhs.C, rhs.C)
857         return
858 }
859
860 func ConstShl(lhs, rhs Value) (v Value)  { v.C = C.LLVMConstShl(lhs.C, rhs.C); return }
861 func ConstLShr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstLShr(lhs.C, rhs.C); return }
862 func ConstAShr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAShr(lhs.C, rhs.C); return }
863
864 func ConstGEP(v Value, indices []Value) (rv Value) {
865         ptr, nvals := llvmValueRefs(indices)
866         rv.C = C.LLVMConstGEP(v.C, ptr, nvals)
867         return
868 }
869 func ConstInBoundsGEP(v Value, indices []Value) (rv Value) {
870         ptr, nvals := llvmValueRefs(indices)
871         rv.C = C.LLVMConstInBoundsGEP(v.C, ptr, nvals)
872         return
873 }
874 func ConstTrunc(v Value, t Type) (rv Value)         { rv.C = C.LLVMConstTrunc(v.C, t.C); return }
875 func ConstSExt(v Value, t Type) (rv Value)          { rv.C = C.LLVMConstSExt(v.C, t.C); return }
876 func ConstZExt(v Value, t Type) (rv Value)          { rv.C = C.LLVMConstZExt(v.C, t.C); return }
877 func ConstFPTrunc(v Value, t Type) (rv Value)       { rv.C = C.LLVMConstFPTrunc(v.C, t.C); return }
878 func ConstFPExt(v Value, t Type) (rv Value)         { rv.C = C.LLVMConstFPExt(v.C, t.C); return }
879 func ConstUIToFP(v Value, t Type) (rv Value)        { rv.C = C.LLVMConstUIToFP(v.C, t.C); return }
880 func ConstSIToFP(v Value, t Type) (rv Value)        { rv.C = C.LLVMConstSIToFP(v.C, t.C); return }
881 func ConstFPToUI(v Value, t Type) (rv Value)        { rv.C = C.LLVMConstFPToUI(v.C, t.C); return }
882 func ConstFPToSI(v Value, t Type) (rv Value)        { rv.C = C.LLVMConstFPToSI(v.C, t.C); return }
883 func ConstPtrToInt(v Value, t Type) (rv Value)      { rv.C = C.LLVMConstPtrToInt(v.C, t.C); return }
884 func ConstIntToPtr(v Value, t Type) (rv Value)      { rv.C = C.LLVMConstIntToPtr(v.C, t.C); return }
885 func ConstBitCast(v Value, t Type) (rv Value)       { rv.C = C.LLVMConstBitCast(v.C, t.C); return }
886 func ConstZExtOrBitCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstZExtOrBitCast(v.C, t.C); return }
887 func ConstSExtOrBitCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstSExtOrBitCast(v.C, t.C); return }
888 func ConstTruncOrBitCast(v Value, t Type) (rv Value) {
889         rv.C = C.LLVMConstTruncOrBitCast(v.C, t.C)
890         return
891 }
892 func ConstPointerCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstPointerCast(v.C, t.C); return }
893 func ConstIntCast(v Value, t Type, signed bool) (rv Value) {
894         rv.C = C.LLVMConstIntCast(v.C, t.C, boolToLLVMBool(signed))
895         return
896 }
897 func ConstFPCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstFPCast(v.C, t.C); return }
898 func ConstSelect(cond, iftrue, iffalse Value) (rv Value) {
899         rv.C = C.LLVMConstSelect(cond.C, iftrue.C, iffalse.C)
900         return
901 }
902 func ConstExtractElement(vec, i Value) (rv Value) {
903         rv.C = C.LLVMConstExtractElement(vec.C, i.C)
904         return
905 }
906 func ConstInsertElement(vec, elem, i Value) (rv Value) {
907         rv.C = C.LLVMConstInsertElement(vec.C, elem.C, i.C)
908         return
909 }
910 func ConstShuffleVector(veca, vecb, mask Value) (rv Value) {
911         rv.C = C.LLVMConstShuffleVector(veca.C, vecb.C, mask.C)
912         return
913 }
914
915 //TODO
916 //LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
917 //                                   unsigned NumIdx);
918
919 func ConstExtractValue(agg Value, indices []uint32) (rv Value) {
920         n := len(indices)
921         if n == 0 {
922                 panic("one or more indices are required")
923         }
924         ptr := (*C.unsigned)(&indices[0])
925         rv.C = C.LLVMConstExtractValue(agg.C, ptr, C.unsigned(n))
926         return
927 }
928
929 func ConstInsertValue(agg, val Value, indices []uint32) (rv Value) {
930         n := len(indices)
931         if n == 0 {
932                 panic("one or more indices are required")
933         }
934         ptr := (*C.unsigned)(&indices[0])
935         rv.C = C.LLVMConstInsertValue(agg.C, val.C, ptr, C.unsigned(n))
936         return
937 }
938
939 func BlockAddress(f Value, bb BasicBlock) (v Value) {
940         v.C = C.LLVMBlockAddress(f.C, bb.C)
941         return
942 }
943
944 // Operations on global variables, functions, and aliases (globals)
945 func (v Value) GlobalParent() (m Module) { m.C = C.LLVMGetGlobalParent(v.C); return }
946 func (v Value) IsDeclaration() bool      { return C.LLVMIsDeclaration(v.C) != 0 }
947 func (v Value) Linkage() Linkage         { return Linkage(C.LLVMGetLinkage(v.C)) }
948 func (v Value) SetLinkage(l Linkage)     { C.LLVMSetLinkage(v.C, C.LLVMLinkage(l)) }
949 func (v Value) Section() string          { return C.GoString(C.LLVMGetSection(v.C)) }
950 func (v Value) SetSection(str string) {
951         cstr := C.CString(str)
952         defer C.free(unsafe.Pointer(cstr))
953         C.LLVMSetSection(v.C, cstr)
954 }
955 func (v Value) Visibility() Visibility      { return Visibility(C.LLVMGetVisibility(v.C)) }
956 func (v Value) SetVisibility(vi Visibility) { C.LLVMSetVisibility(v.C, C.LLVMVisibility(vi)) }
957 func (v Value) Alignment() int              { return int(C.LLVMGetAlignment(v.C)) }
958 func (v Value) SetAlignment(a int)          { C.LLVMSetAlignment(v.C, C.unsigned(a)) }
959
960 // Operations on global variables
961 func AddGlobal(m Module, t Type, name string) (v Value) {
962         cname := C.CString(name)
963         defer C.free(unsafe.Pointer(cname))
964         v.C = C.LLVMAddGlobal(m.C, t.C, cname)
965         return
966 }
967 func AddGlobalInAddressSpace(m Module, t Type, name string, addressSpace int) (v Value) {
968         cname := C.CString(name)
969         defer C.free(unsafe.Pointer(cname))
970         v.C = C.LLVMAddGlobalInAddressSpace(m.C, t.C, cname, C.unsigned(addressSpace))
971         return
972 }
973 func (m Module) NamedGlobal(name string) (v Value) {
974         cname := C.CString(name)
975         defer C.free(unsafe.Pointer(cname))
976         v.C = C.LLVMGetNamedGlobal(m.C, cname)
977         return
978 }
979
980 func (m Module) FirstGlobal() (v Value)   { v.C = C.LLVMGetFirstGlobal(m.C); return }
981 func (m Module) LastGlobal() (v Value)    { v.C = C.LLVMGetLastGlobal(m.C); return }
982 func NextGlobal(v Value) (rv Value)       { rv.C = C.LLVMGetNextGlobal(v.C); return }
983 func PrevGlobal(v Value) (rv Value)       { rv.C = C.LLVMGetPreviousGlobal(v.C); return }
984 func (v Value) EraseFromParentAsGlobal()  { C.LLVMDeleteGlobal(v.C) }
985 func (v Value) Initializer() (rv Value)   { rv.C = C.LLVMGetInitializer(v.C); return }
986 func (v Value) SetInitializer(cv Value)   { C.LLVMSetInitializer(v.C, cv.C) }
987 func (v Value) IsThreadLocal() bool       { return C.LLVMIsThreadLocal(v.C) != 0 }
988 func (v Value) SetThreadLocal(tl bool)    { C.LLVMSetThreadLocal(v.C, boolToLLVMBool(tl)) }
989 func (v Value) IsGlobalConstant() bool    { return C.LLVMIsGlobalConstant(v.C) != 0 }
990 func (v Value) SetGlobalConstant(gc bool) { C.LLVMSetGlobalConstant(v.C, boolToLLVMBool(gc)) }
991
992 // Operations on aliases
993 func AddAlias(m Module, t Type, aliasee Value, name string) (v Value) {
994         cname := C.CString(name)
995         defer C.free(unsafe.Pointer(cname))
996         v.C = C.LLVMAddAlias(m.C, t.C, aliasee.C, cname)
997         return
998 }
999
1000 // Operations on functions
1001 func AddFunction(m Module, name string, ft Type) (v Value) {
1002         cname := C.CString(name)
1003         defer C.free(unsafe.Pointer(cname))
1004         v.C = C.LLVMAddFunction(m.C, cname, ft.C)
1005         return
1006 }
1007
1008 func (m Module) NamedFunction(name string) (v Value) {
1009         cname := C.CString(name)
1010         defer C.free(unsafe.Pointer(cname))
1011         v.C = C.LLVMGetNamedFunction(m.C, cname)
1012         return
1013 }
1014
1015 func (m Module) FirstFunction() (v Value)  { v.C = C.LLVMGetFirstFunction(m.C); return }
1016 func (m Module) LastFunction() (v Value)   { v.C = C.LLVMGetLastFunction(m.C); return }
1017 func NextFunction(v Value) (rv Value)      { rv.C = C.LLVMGetNextFunction(v.C); return }
1018 func PrevFunction(v Value) (rv Value)      { rv.C = C.LLVMGetPreviousFunction(v.C); return }
1019 func (v Value) EraseFromParentAsFunction() { C.LLVMDeleteFunction(v.C) }
1020 func (v Value) IntrinsicID() int           { return int(C.LLVMGetIntrinsicID(v.C)) }
1021 func (v Value) FunctionCallConv() CallConv {
1022         return CallConv(C.LLVMCallConv(C.LLVMGetFunctionCallConv(v.C)))
1023 }
1024 func (v Value) SetFunctionCallConv(cc CallConv) { C.LLVMSetFunctionCallConv(v.C, C.unsigned(cc)) }
1025 func (v Value) GC() string                      { return C.GoString(C.LLVMGetGC(v.C)) }
1026 func (v Value) SetGC(name string) {
1027         cname := C.CString(name)
1028         defer C.free(unsafe.Pointer(cname))
1029         C.LLVMSetGC(v.C, cname)
1030 }
1031 func (v Value) AddFunctionAttr(a Attribute)    { C.LLVMAddFunctionAttr2(v.C, C.uint64_t(a)) }
1032 func (v Value) FunctionAttr() Attribute        { return Attribute(C.LLVMGetFunctionAttr2(v.C)) }
1033 func (v Value) RemoveFunctionAttr(a Attribute) { C.LLVMRemoveFunctionAttr2(v.C, C.uint64_t(a)) }
1034 func (v Value) AddTargetDependentFunctionAttr(attr, value string) {
1035         cattr := C.CString(attr)
1036         defer C.free(unsafe.Pointer(cattr))
1037         cvalue := C.CString(value)
1038         defer C.free(unsafe.Pointer(cvalue))
1039         C.LLVMAddTargetDependentFunctionAttr(v.C, cattr, cvalue)
1040 }
1041
1042 // Operations on parameters
1043 func (v Value) ParamsCount() int { return int(C.LLVMCountParams(v.C)) }
1044 func (v Value) Params() []Value {
1045         out := make([]Value, v.ParamsCount())
1046         if len(out) > 0 {
1047                 C.LLVMGetParams(v.C, llvmValueRefPtr(&out[0]))
1048         }
1049         return out
1050 }
1051 func (v Value) Param(i int) (rv Value)  { rv.C = C.LLVMGetParam(v.C, C.unsigned(i)); return }
1052 func (v Value) ParamParent() (rv Value) { rv.C = C.LLVMGetParamParent(v.C); return }
1053 func (v Value) FirstParam() (rv Value)  { rv.C = C.LLVMGetFirstParam(v.C); return }
1054 func (v Value) LastParam() (rv Value)   { rv.C = C.LLVMGetLastParam(v.C); return }
1055 func NextParam(v Value) (rv Value)      { rv.C = C.LLVMGetNextParam(v.C); return }
1056 func PrevParam(v Value) (rv Value)      { rv.C = C.LLVMGetPreviousParam(v.C); return }
1057 func (v Value) AddAttribute(a Attribute) {
1058         if a >= 1<<32 {
1059                 panic("attribute value currently unsupported")
1060         }
1061         C.LLVMAddAttribute(v.C, C.LLVMAttribute(a))
1062 }
1063 func (v Value) RemoveAttribute(a Attribute) {
1064         if a >= 1<<32 {
1065                 panic("attribute value currently unsupported")
1066         }
1067         C.LLVMRemoveAttribute(v.C, C.LLVMAttribute(a))
1068 }
1069 func (v Value) Attribute() Attribute        { return Attribute(C.LLVMGetAttribute(v.C)) }
1070 func (v Value) SetParamAlignment(align int) { C.LLVMSetParamAlignment(v.C, C.unsigned(align)) }
1071
1072 // Operations on basic blocks
1073 func (bb BasicBlock) AsValue() (v Value)      { v.C = C.LLVMBasicBlockAsValue(bb.C); return }
1074 func (v Value) IsBasicBlock() bool            { return C.LLVMValueIsBasicBlock(v.C) != 0 }
1075 func (v Value) AsBasicBlock() (bb BasicBlock) { bb.C = C.LLVMValueAsBasicBlock(v.C); return }
1076 func (bb BasicBlock) Parent() (v Value)       { v.C = C.LLVMGetBasicBlockParent(bb.C); return }
1077 func (v Value) BasicBlocksCount() int         { return int(C.LLVMCountBasicBlocks(v.C)) }
1078 func (v Value) BasicBlocks() []BasicBlock {
1079         out := make([]BasicBlock, v.BasicBlocksCount())
1080         C.LLVMGetBasicBlocks(v.C, llvmBasicBlockRefPtr(&out[0]))
1081         return out
1082 }
1083 func (v Value) FirstBasicBlock() (bb BasicBlock)    { bb.C = C.LLVMGetFirstBasicBlock(v.C); return }
1084 func (v Value) LastBasicBlock() (bb BasicBlock)     { bb.C = C.LLVMGetLastBasicBlock(v.C); return }
1085 func NextBasicBlock(bb BasicBlock) (rbb BasicBlock) { rbb.C = C.LLVMGetNextBasicBlock(bb.C); return }
1086 func PrevBasicBlock(bb BasicBlock) (rbb BasicBlock) { rbb.C = C.LLVMGetPreviousBasicBlock(bb.C); return }
1087 func (v Value) EntryBasicBlock() (bb BasicBlock)    { bb.C = C.LLVMGetEntryBasicBlock(v.C); return }
1088 func (c Context) AddBasicBlock(f Value, name string) (bb BasicBlock) {
1089         cname := C.CString(name)
1090         defer C.free(unsafe.Pointer(cname))
1091         bb.C = C.LLVMAppendBasicBlockInContext(c.C, f.C, cname)
1092         return
1093 }
1094 func (c Context) InsertBasicBlock(ref BasicBlock, name string) (bb BasicBlock) {
1095         cname := C.CString(name)
1096         defer C.free(unsafe.Pointer(cname))
1097         bb.C = C.LLVMInsertBasicBlockInContext(c.C, ref.C, cname)
1098         return
1099 }
1100 func AddBasicBlock(f Value, name string) (bb BasicBlock) {
1101         cname := C.CString(name)
1102         defer C.free(unsafe.Pointer(cname))
1103         bb.C = C.LLVMAppendBasicBlock(f.C, cname)
1104         return
1105 }
1106 func InsertBasicBlock(ref BasicBlock, name string) (bb BasicBlock) {
1107         cname := C.CString(name)
1108         defer C.free(unsafe.Pointer(cname))
1109         bb.C = C.LLVMInsertBasicBlock(ref.C, cname)
1110         return
1111 }
1112 func (bb BasicBlock) EraseFromParent()          { C.LLVMDeleteBasicBlock(bb.C) }
1113 func (bb BasicBlock) MoveBefore(pos BasicBlock) { C.LLVMMoveBasicBlockBefore(bb.C, pos.C) }
1114 func (bb BasicBlock) MoveAfter(pos BasicBlock)  { C.LLVMMoveBasicBlockAfter(bb.C, pos.C) }
1115
1116 // Operations on instructions
1117 func (v Value) InstructionParent() (bb BasicBlock) { bb.C = C.LLVMGetInstructionParent(v.C); return }
1118 func (bb BasicBlock) FirstInstruction() (v Value)  { v.C = C.LLVMGetFirstInstruction(bb.C); return }
1119 func (bb BasicBlock) LastInstruction() (v Value)   { v.C = C.LLVMGetLastInstruction(bb.C); return }
1120 func NextInstruction(v Value) (rv Value)           { rv.C = C.LLVMGetNextInstruction(v.C); return }
1121 func PrevInstruction(v Value) (rv Value)           { rv.C = C.LLVMGetPreviousInstruction(v.C); return }
1122
1123 // Operations on call sites
1124 func (v Value) SetInstructionCallConv(cc CallConv) {
1125         C.LLVMSetInstructionCallConv(v.C, C.unsigned(cc))
1126 }
1127 func (v Value) InstructionCallConv() CallConv {
1128         return CallConv(C.LLVMCallConv(C.LLVMGetInstructionCallConv(v.C)))
1129 }
1130 func (v Value) AddInstrAttribute(i int, a Attribute) {
1131         if a >= 1<<32 {
1132                 panic("attribute value currently unsupported")
1133         }
1134         C.LLVMAddInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a))
1135 }
1136 func (v Value) RemoveInstrAttribute(i int, a Attribute) {
1137         if a >= 1<<32 {
1138                 panic("attribute value currently unsupported")
1139         }
1140         C.LLVMRemoveInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a))
1141 }
1142 func (v Value) SetInstrParamAlignment(i int, align int) {
1143         C.LLVMSetInstrParamAlignment(v.C, C.unsigned(i), C.unsigned(align))
1144 }
1145
1146 // Operations on call instructions (only)
1147 func (v Value) IsTailCall() bool    { return C.LLVMIsTailCall(v.C) != 0 }
1148 func (v Value) SetTailCall(is bool) { C.LLVMSetTailCall(v.C, boolToLLVMBool(is)) }
1149
1150 // Operations on phi nodes
1151 func (v Value) AddIncoming(vals []Value, blocks []BasicBlock) {
1152         ptr, nvals := llvmValueRefs(vals)
1153         C.LLVMAddIncoming(v.C, ptr, llvmBasicBlockRefPtr(&blocks[0]), nvals)
1154 }
1155 func (v Value) IncomingCount() int { return int(C.LLVMCountIncoming(v.C)) }
1156 func (v Value) IncomingValue(i int) (rv Value) {
1157         rv.C = C.LLVMGetIncomingValue(v.C, C.unsigned(i))
1158         return
1159 }
1160 func (v Value) IncomingBlock(i int) (bb BasicBlock) {
1161         bb.C = C.LLVMGetIncomingBlock(v.C, C.unsigned(i))
1162         return
1163 }
1164
1165 //-------------------------------------------------------------------------
1166 // llvm.Builder
1167 //-------------------------------------------------------------------------
1168
1169 // An instruction builder represents a point within a basic block, and is the
1170 // exclusive means of building instructions using the C interface.
1171
1172 func (c Context) NewBuilder() (b Builder) { b.C = C.LLVMCreateBuilderInContext(c.C); return }
1173 func NewBuilder() (b Builder)             { b.C = C.LLVMCreateBuilder(); return }
1174 func (b Builder) SetInsertPoint(block BasicBlock, instr Value) {
1175         C.LLVMPositionBuilder(b.C, block.C, instr.C)
1176 }
1177 func (b Builder) SetInsertPointBefore(instr Value)     { C.LLVMPositionBuilderBefore(b.C, instr.C) }
1178 func (b Builder) SetInsertPointAtEnd(block BasicBlock) { C.LLVMPositionBuilderAtEnd(b.C, block.C) }
1179 func (b Builder) GetInsertBlock() (bb BasicBlock)      { bb.C = C.LLVMGetInsertBlock(b.C); return }
1180 func (b Builder) ClearInsertionPoint()                 { C.LLVMClearInsertionPosition(b.C) }
1181 func (b Builder) Insert(instr Value)                   { C.LLVMInsertIntoBuilder(b.C, instr.C) }
1182 func (b Builder) InsertWithName(instr Value, name string) {
1183         cname := C.CString(name)
1184         defer C.free(unsafe.Pointer(cname))
1185         C.LLVMInsertIntoBuilderWithName(b.C, instr.C, cname)
1186 }
1187 func (b Builder) Dispose() { C.LLVMDisposeBuilder(b.C) }
1188
1189 // Metadata
1190 func (b Builder) SetCurrentDebugLocation(v Value) { C.LLVMSetCurrentDebugLocation(b.C, v.C) }
1191 func (b Builder) CurrentDebugLocation() (v Value) { v.C = C.LLVMGetCurrentDebugLocation(b.C); return }
1192 func (b Builder) SetInstDebugLocation(v Value)    { C.LLVMSetInstDebugLocation(b.C, v.C) }
1193 func (b Builder) InsertDeclare(module Module, storage Value, md Value) Value {
1194         f := module.NamedFunction("llvm.dbg.declare")
1195         if f.IsNil() {
1196                 ftyp := FunctionType(VoidType(), []Type{storage.Type(), md.Type()}, false)
1197                 f = AddFunction(module, "llvm.dbg.declare", ftyp)
1198         }
1199         return b.CreateCall(f, []Value{storage, md}, "")
1200 }
1201
1202 // Terminators
1203 func (b Builder) CreateRetVoid() (rv Value)    { rv.C = C.LLVMBuildRetVoid(b.C); return }
1204 func (b Builder) CreateRet(v Value) (rv Value) { rv.C = C.LLVMBuildRet(b.C, v.C); return }
1205 func (b Builder) CreateAggregateRet(vs []Value) (rv Value) {
1206         ptr, nvals := llvmValueRefs(vs)
1207         rv.C = C.LLVMBuildAggregateRet(b.C, ptr, nvals)
1208         return
1209 }
1210 func (b Builder) CreateBr(bb BasicBlock) (rv Value) { rv.C = C.LLVMBuildBr(b.C, bb.C); return }
1211 func (b Builder) CreateCondBr(ifv Value, thenb, elseb BasicBlock) (rv Value) {
1212         rv.C = C.LLVMBuildCondBr(b.C, ifv.C, thenb.C, elseb.C)
1213         return
1214 }
1215 func (b Builder) CreateSwitch(v Value, elseb BasicBlock, numCases int) (rv Value) {
1216         rv.C = C.LLVMBuildSwitch(b.C, v.C, elseb.C, C.unsigned(numCases))
1217         return
1218 }
1219 func (b Builder) CreateIndirectBr(addr Value, numDests int) (rv Value) {
1220         rv.C = C.LLVMBuildIndirectBr(b.C, addr.C, C.unsigned(numDests))
1221         return
1222 }
1223 func (b Builder) CreateInvoke(fn Value, args []Value, then, catch BasicBlock, name string) (rv Value) {
1224         cname := C.CString(name)
1225         defer C.free(unsafe.Pointer(cname))
1226         ptr, nvals := llvmValueRefs(args)
1227         rv.C = C.LLVMBuildInvoke(b.C, fn.C, ptr, nvals, then.C, catch.C, cname)
1228         return
1229 }
1230 func (b Builder) CreateUnreachable() (rv Value) { rv.C = C.LLVMBuildUnreachable(b.C); return }
1231
1232 // Add a case to the switch instruction
1233 func (v Value) AddCase(on Value, dest BasicBlock) { C.LLVMAddCase(v.C, on.C, dest.C) }
1234
1235 // Add a destination to the indirectbr instruction
1236 func (v Value) AddDest(dest BasicBlock) { C.LLVMAddDestination(v.C, dest.C) }
1237
1238 // Arithmetic
1239 func (b Builder) CreateAdd(lhs, rhs Value, name string) (v Value) {
1240         cname := C.CString(name)
1241         defer C.free(unsafe.Pointer(cname))
1242         v.C = C.LLVMBuildAdd(b.C, lhs.C, rhs.C, cname)
1243         return
1244 }
1245 func (b Builder) CreateNSWAdd(lhs, rhs Value, name string) (v Value) {
1246         cname := C.CString(name)
1247         defer C.free(unsafe.Pointer(cname))
1248         v.C = C.LLVMBuildNSWAdd(b.C, lhs.C, rhs.C, cname)
1249         return
1250 }
1251 func (b Builder) CreateNUWAdd(lhs, rhs Value, name string) (v Value) {
1252         cname := C.CString(name)
1253         defer C.free(unsafe.Pointer(cname))
1254         v.C = C.LLVMBuildNUWAdd(b.C, lhs.C, rhs.C, cname)
1255         return
1256 }
1257 func (b Builder) CreateFAdd(lhs, rhs Value, name string) (v Value) {
1258         cname := C.CString(name)
1259         defer C.free(unsafe.Pointer(cname))
1260         v.C = C.LLVMBuildFAdd(b.C, lhs.C, rhs.C, cname)
1261         return
1262 }
1263 func (b Builder) CreateSub(lhs, rhs Value, name string) (v Value) {
1264         cname := C.CString(name)
1265         defer C.free(unsafe.Pointer(cname))
1266         v.C = C.LLVMBuildSub(b.C, lhs.C, rhs.C, cname)
1267         return
1268 }
1269 func (b Builder) CreateNSWSub(lhs, rhs Value, name string) (v Value) {
1270         cname := C.CString(name)
1271         defer C.free(unsafe.Pointer(cname))
1272         v.C = C.LLVMBuildNSWSub(b.C, lhs.C, rhs.C, cname)
1273         return
1274 }
1275 func (b Builder) CreateNUWSub(lhs, rhs Value, name string) (v Value) {
1276         cname := C.CString(name)
1277         defer C.free(unsafe.Pointer(cname))
1278         v.C = C.LLVMBuildNUWSub(b.C, lhs.C, rhs.C, cname)
1279         return
1280 }
1281 func (b Builder) CreateFSub(lhs, rhs Value, name string) (v Value) {
1282         cname := C.CString(name)
1283         v.C = C.LLVMBuildFSub(b.C, lhs.C, rhs.C, cname)
1284         C.free(unsafe.Pointer(cname))
1285         return
1286 }
1287 func (b Builder) CreateMul(lhs, rhs Value, name string) (v Value) {
1288         cname := C.CString(name)
1289         defer C.free(unsafe.Pointer(cname))
1290         v.C = C.LLVMBuildMul(b.C, lhs.C, rhs.C, cname)
1291         return
1292 }
1293 func (b Builder) CreateNSWMul(lhs, rhs Value, name string) (v Value) {
1294         cname := C.CString(name)
1295         defer C.free(unsafe.Pointer(cname))
1296         v.C = C.LLVMBuildNSWMul(b.C, lhs.C, rhs.C, cname)
1297         return
1298 }
1299 func (b Builder) CreateNUWMul(lhs, rhs Value, name string) (v Value) {
1300         cname := C.CString(name)
1301         defer C.free(unsafe.Pointer(cname))
1302         v.C = C.LLVMBuildNUWMul(b.C, lhs.C, rhs.C, cname)
1303         return
1304 }
1305 func (b Builder) CreateFMul(lhs, rhs Value, name string) (v Value) {
1306         cname := C.CString(name)
1307         defer C.free(unsafe.Pointer(cname))
1308         v.C = C.LLVMBuildFMul(b.C, lhs.C, rhs.C, cname)
1309         return
1310 }
1311 func (b Builder) CreateUDiv(lhs, rhs Value, name string) (v Value) {
1312         cname := C.CString(name)
1313         defer C.free(unsafe.Pointer(cname))
1314         v.C = C.LLVMBuildUDiv(b.C, lhs.C, rhs.C, cname)
1315         return
1316 }
1317 func (b Builder) CreateSDiv(lhs, rhs Value, name string) (v Value) {
1318         cname := C.CString(name)
1319         defer C.free(unsafe.Pointer(cname))
1320         v.C = C.LLVMBuildSDiv(b.C, lhs.C, rhs.C, cname)
1321         return
1322 }
1323 func (b Builder) CreateExactSDiv(lhs, rhs Value, name string) (v Value) {
1324         cname := C.CString(name)
1325         defer C.free(unsafe.Pointer(cname))
1326         v.C = C.LLVMBuildExactSDiv(b.C, lhs.C, rhs.C, cname)
1327         return
1328 }
1329 func (b Builder) CreateFDiv(lhs, rhs Value, name string) (v Value) {
1330         cname := C.CString(name)
1331         defer C.free(unsafe.Pointer(cname))
1332         v.C = C.LLVMBuildFDiv(b.C, lhs.C, rhs.C, cname)
1333         return
1334 }
1335 func (b Builder) CreateURem(lhs, rhs Value, name string) (v Value) {
1336         cname := C.CString(name)
1337         defer C.free(unsafe.Pointer(cname))
1338         v.C = C.LLVMBuildURem(b.C, lhs.C, rhs.C, cname)
1339         return
1340 }
1341 func (b Builder) CreateSRem(lhs, rhs Value, name string) (v Value) {
1342         cname := C.CString(name)
1343         defer C.free(unsafe.Pointer(cname))
1344         v.C = C.LLVMBuildSRem(b.C, lhs.C, rhs.C, cname)
1345         return
1346 }
1347 func (b Builder) CreateFRem(lhs, rhs Value, name string) (v Value) {
1348         cname := C.CString(name)
1349         defer C.free(unsafe.Pointer(cname))
1350         v.C = C.LLVMBuildFRem(b.C, lhs.C, rhs.C, cname)
1351         return
1352 }
1353 func (b Builder) CreateShl(lhs, rhs Value, name string) (v Value) {
1354         cname := C.CString(name)
1355         defer C.free(unsafe.Pointer(cname))
1356         v.C = C.LLVMBuildShl(b.C, lhs.C, rhs.C, cname)
1357         return
1358 }
1359 func (b Builder) CreateLShr(lhs, rhs Value, name string) (v Value) {
1360         cname := C.CString(name)
1361         defer C.free(unsafe.Pointer(cname))
1362         v.C = C.LLVMBuildLShr(b.C, lhs.C, rhs.C, cname)
1363         return
1364 }
1365 func (b Builder) CreateAShr(lhs, rhs Value, name string) (v Value) {
1366         cname := C.CString(name)
1367         defer C.free(unsafe.Pointer(cname))
1368         v.C = C.LLVMBuildAShr(b.C, lhs.C, rhs.C, cname)
1369         return
1370 }
1371 func (b Builder) CreateAnd(lhs, rhs Value, name string) (v Value) {
1372         cname := C.CString(name)
1373         defer C.free(unsafe.Pointer(cname))
1374         v.C = C.LLVMBuildAnd(b.C, lhs.C, rhs.C, cname)
1375         return
1376 }
1377 func (b Builder) CreateOr(lhs, rhs Value, name string) (v Value) {
1378         cname := C.CString(name)
1379         defer C.free(unsafe.Pointer(cname))
1380         v.C = C.LLVMBuildOr(b.C, lhs.C, rhs.C, cname)
1381         return
1382 }
1383 func (b Builder) CreateXor(lhs, rhs Value, name string) (v Value) {
1384         cname := C.CString(name)
1385         defer C.free(unsafe.Pointer(cname))
1386         v.C = C.LLVMBuildXor(b.C, lhs.C, rhs.C, cname)
1387         return
1388 }
1389 func (b Builder) CreateBinOp(op Opcode, lhs, rhs Value, name string) (v Value) {
1390         cname := C.CString(name)
1391         defer C.free(unsafe.Pointer(cname))
1392         v.C = C.LLVMBuildBinOp(b.C, C.LLVMOpcode(op), lhs.C, rhs.C, cname)
1393         return
1394 }
1395 func (b Builder) CreateNeg(v Value, name string) (rv Value) {
1396         cname := C.CString(name)
1397         defer C.free(unsafe.Pointer(cname))
1398         rv.C = C.LLVMBuildNeg(b.C, v.C, cname)
1399         return
1400 }
1401 func (b Builder) CreateNSWNeg(v Value, name string) (rv Value) {
1402         cname := C.CString(name)
1403         defer C.free(unsafe.Pointer(cname))
1404         rv.C = C.LLVMBuildNSWNeg(b.C, v.C, cname)
1405         return
1406 }
1407 func (b Builder) CreateNUWNeg(v Value, name string) (rv Value) {
1408         cname := C.CString(name)
1409         defer C.free(unsafe.Pointer(cname))
1410         rv.C = C.LLVMBuildNUWNeg(b.C, v.C, cname)
1411         return
1412 }
1413 func (b Builder) CreateFNeg(v Value, name string) (rv Value) {
1414         cname := C.CString(name)
1415         defer C.free(unsafe.Pointer(cname))
1416         rv.C = C.LLVMBuildFNeg(b.C, v.C, cname)
1417         return
1418 }
1419 func (b Builder) CreateNot(v Value, name string) (rv Value) {
1420         cname := C.CString(name)
1421         defer C.free(unsafe.Pointer(cname))
1422         rv.C = C.LLVMBuildNot(b.C, v.C, cname)
1423         return
1424 }
1425
1426 // Memory
1427
1428 func (b Builder) CreateMalloc(t Type, name string) (v Value) {
1429         cname := C.CString(name)
1430         defer C.free(unsafe.Pointer(cname))
1431         v.C = C.LLVMBuildMalloc(b.C, t.C, cname)
1432         return
1433 }
1434 func (b Builder) CreateArrayMalloc(t Type, val Value, name string) (v Value) {
1435         cname := C.CString(name)
1436         defer C.free(unsafe.Pointer(cname))
1437         v.C = C.LLVMBuildArrayMalloc(b.C, t.C, val.C, cname)
1438         return
1439 }
1440 func (b Builder) CreateAlloca(t Type, name string) (v Value) {
1441         cname := C.CString(name)
1442         defer C.free(unsafe.Pointer(cname))
1443         v.C = C.LLVMBuildAlloca(b.C, t.C, cname)
1444         return
1445 }
1446 func (b Builder) CreateArrayAlloca(t Type, val Value, name string) (v Value) {
1447         cname := C.CString(name)
1448         defer C.free(unsafe.Pointer(cname))
1449         v.C = C.LLVMBuildArrayAlloca(b.C, t.C, val.C, cname)
1450         return
1451 }
1452 func (b Builder) CreateFree(p Value) (v Value) {
1453         v.C = C.LLVMBuildFree(b.C, p.C)
1454         return
1455 }
1456 func (b Builder) CreateLoad(p Value, name string) (v Value) {
1457         cname := C.CString(name)
1458         defer C.free(unsafe.Pointer(cname))
1459         v.C = C.LLVMBuildLoad(b.C, p.C, cname)
1460         return
1461 }
1462 func (b Builder) CreateStore(val Value, p Value) (v Value) {
1463         v.C = C.LLVMBuildStore(b.C, val.C, p.C)
1464         return
1465 }
1466 func (b Builder) CreateGEP(p Value, indices []Value, name string) (v Value) {
1467         cname := C.CString(name)
1468         defer C.free(unsafe.Pointer(cname))
1469         ptr, nvals := llvmValueRefs(indices)
1470         v.C = C.LLVMBuildGEP(b.C, p.C, ptr, nvals, cname)
1471         return
1472 }
1473 func (b Builder) CreateInBoundsGEP(p Value, indices []Value, name string) (v Value) {
1474         cname := C.CString(name)
1475         defer C.free(unsafe.Pointer(cname))
1476         ptr, nvals := llvmValueRefs(indices)
1477         v.C = C.LLVMBuildInBoundsGEP(b.C, p.C, ptr, nvals, cname)
1478         return
1479 }
1480 func (b Builder) CreateStructGEP(p Value, i int, name string) (v Value) {
1481         cname := C.CString(name)
1482         defer C.free(unsafe.Pointer(cname))
1483         v.C = C.LLVMBuildStructGEP(b.C, p.C, C.unsigned(i), cname)
1484         return
1485 }
1486 func (b Builder) CreateGlobalString(str, name string) (v Value) {
1487         cstr := C.CString(str)
1488         defer C.free(unsafe.Pointer(cstr))
1489         cname := C.CString(name)
1490         defer C.free(unsafe.Pointer(cname))
1491         v.C = C.LLVMBuildGlobalString(b.C, cstr, cname)
1492         return
1493 }
1494 func (b Builder) CreateGlobalStringPtr(str, name string) (v Value) {
1495         cstr := C.CString(str)
1496         defer C.free(unsafe.Pointer(cstr))
1497         cname := C.CString(name)
1498         defer C.free(unsafe.Pointer(cname))
1499         v.C = C.LLVMBuildGlobalStringPtr(b.C, cstr, cname)
1500         return
1501 }
1502
1503 // Casts
1504 func (b Builder) CreateTrunc(val Value, t Type, name string) (v Value) {
1505         cname := C.CString(name)
1506         defer C.free(unsafe.Pointer(cname))
1507         v.C = C.LLVMBuildTrunc(b.C, val.C, t.C, cname)
1508         return
1509 }
1510 func (b Builder) CreateZExt(val Value, t Type, name string) (v Value) {
1511         cname := C.CString(name)
1512         defer C.free(unsafe.Pointer(cname))
1513         v.C = C.LLVMBuildZExt(b.C, val.C, t.C, cname)
1514         return
1515 }
1516 func (b Builder) CreateSExt(val Value, t Type, name string) (v Value) {
1517         cname := C.CString(name)
1518         defer C.free(unsafe.Pointer(cname))
1519         v.C = C.LLVMBuildSExt(b.C, val.C, t.C, cname)
1520         return
1521 }
1522 func (b Builder) CreateFPToUI(val Value, t Type, name string) (v Value) {
1523         cname := C.CString(name)
1524         defer C.free(unsafe.Pointer(cname))
1525         v.C = C.LLVMBuildFPToUI(b.C, val.C, t.C, cname)
1526         return
1527 }
1528 func (b Builder) CreateFPToSI(val Value, t Type, name string) (v Value) {
1529         cname := C.CString(name)
1530         defer C.free(unsafe.Pointer(cname))
1531         v.C = C.LLVMBuildFPToSI(b.C, val.C, t.C, cname)
1532         return
1533 }
1534 func (b Builder) CreateUIToFP(val Value, t Type, name string) (v Value) {
1535         cname := C.CString(name)
1536         defer C.free(unsafe.Pointer(cname))
1537         v.C = C.LLVMBuildUIToFP(b.C, val.C, t.C, cname)
1538         return
1539 }
1540 func (b Builder) CreateSIToFP(val Value, t Type, name string) (v Value) {
1541         cname := C.CString(name)
1542         defer C.free(unsafe.Pointer(cname))
1543         v.C = C.LLVMBuildSIToFP(b.C, val.C, t.C, cname)
1544         return
1545 }
1546 func (b Builder) CreateFPTrunc(val Value, t Type, name string) (v Value) {
1547         cname := C.CString(name)
1548         defer C.free(unsafe.Pointer(cname))
1549         v.C = C.LLVMBuildFPTrunc(b.C, val.C, t.C, cname)
1550         return
1551 }
1552 func (b Builder) CreateFPExt(val Value, t Type, name string) (v Value) {
1553         cname := C.CString(name)
1554         defer C.free(unsafe.Pointer(cname))
1555         v.C = C.LLVMBuildFPExt(b.C, val.C, t.C, cname)
1556         return
1557 }
1558 func (b Builder) CreatePtrToInt(val Value, t Type, name string) (v Value) {
1559         cname := C.CString(name)
1560         defer C.free(unsafe.Pointer(cname))
1561         v.C = C.LLVMBuildPtrToInt(b.C, val.C, t.C, cname)
1562         return
1563 }
1564 func (b Builder) CreateIntToPtr(val Value, t Type, name string) (v Value) {
1565         cname := C.CString(name)
1566         defer C.free(unsafe.Pointer(cname))
1567         v.C = C.LLVMBuildIntToPtr(b.C, val.C, t.C, cname)
1568         return
1569 }
1570 func (b Builder) CreateBitCast(val Value, t Type, name string) (v Value) {
1571         cname := C.CString(name)
1572         defer C.free(unsafe.Pointer(cname))
1573         v.C = C.LLVMBuildBitCast(b.C, val.C, t.C, cname)
1574         return
1575 }
1576 func (b Builder) CreateZExtOrBitCast(val Value, t Type, name string) (v Value) {
1577         cname := C.CString(name)
1578         defer C.free(unsafe.Pointer(cname))
1579         v.C = C.LLVMBuildZExtOrBitCast(b.C, val.C, t.C, cname)
1580         return
1581 }
1582 func (b Builder) CreateSExtOrBitCast(val Value, t Type, name string) (v Value) {
1583         cname := C.CString(name)
1584         defer C.free(unsafe.Pointer(cname))
1585         v.C = C.LLVMBuildSExtOrBitCast(b.C, val.C, t.C, cname)
1586         return
1587 }
1588 func (b Builder) CreateTruncOrBitCast(val Value, t Type, name string) (v Value) {
1589         cname := C.CString(name)
1590         defer C.free(unsafe.Pointer(cname))
1591         v.C = C.LLVMBuildTruncOrBitCast(b.C, val.C, t.C, cname)
1592         return
1593 }
1594 func (b Builder) CreateCast(val Value, op Opcode, t Type, name string) (v Value) {
1595         cname := C.CString(name)
1596         defer C.free(unsafe.Pointer(cname))
1597         v.C = C.LLVMBuildCast(b.C, C.LLVMOpcode(op), val.C, t.C, cname)
1598         return
1599 } //
1600 func (b Builder) CreatePointerCast(val Value, t Type, name string) (v Value) {
1601         cname := C.CString(name)
1602         defer C.free(unsafe.Pointer(cname))
1603         v.C = C.LLVMBuildPointerCast(b.C, val.C, t.C, cname)
1604         return
1605 }
1606 func (b Builder) CreateIntCast(val Value, t Type, name string) (v Value) {
1607         cname := C.CString(name)
1608         defer C.free(unsafe.Pointer(cname))
1609         v.C = C.LLVMBuildIntCast(b.C, val.C, t.C, cname)
1610         return
1611 }
1612 func (b Builder) CreateFPCast(val Value, t Type, name string) (v Value) {
1613         cname := C.CString(name)
1614         defer C.free(unsafe.Pointer(cname))
1615         v.C = C.LLVMBuildFPCast(b.C, val.C, t.C, cname)
1616         return
1617 }
1618
1619 // Comparisons
1620 func (b Builder) CreateICmp(pred IntPredicate, lhs, rhs Value, name string) (v Value) {
1621         cname := C.CString(name)
1622         defer C.free(unsafe.Pointer(cname))
1623         v.C = C.LLVMBuildICmp(b.C, C.LLVMIntPredicate(pred), lhs.C, rhs.C, cname)
1624         return
1625 }
1626 func (b Builder) CreateFCmp(pred FloatPredicate, lhs, rhs Value, name string) (v Value) {
1627         cname := C.CString(name)
1628         defer C.free(unsafe.Pointer(cname))
1629         v.C = C.LLVMBuildFCmp(b.C, C.LLVMRealPredicate(pred), lhs.C, rhs.C, cname)
1630         return
1631 }
1632
1633 // Miscellaneous instructions
1634 func (b Builder) CreatePHI(t Type, name string) (v Value) {
1635         cname := C.CString(name)
1636         defer C.free(unsafe.Pointer(cname))
1637         v.C = C.LLVMBuildPhi(b.C, t.C, cname)
1638         return
1639 }
1640 func (b Builder) CreateCall(fn Value, args []Value, name string) (v Value) {
1641         cname := C.CString(name)
1642         defer C.free(unsafe.Pointer(cname))
1643         ptr, nvals := llvmValueRefs(args)
1644         v.C = C.LLVMBuildCall(b.C, fn.C, ptr, nvals, cname)
1645         return
1646 }
1647
1648 func (b Builder) CreateSelect(ifv, thenv, elsev Value, name string) (v Value) {
1649         cname := C.CString(name)
1650         defer C.free(unsafe.Pointer(cname))
1651         v.C = C.LLVMBuildSelect(b.C, ifv.C, thenv.C, elsev.C, cname)
1652         return
1653 }
1654
1655 func (b Builder) CreateVAArg(list Value, t Type, name string) (v Value) {
1656         cname := C.CString(name)
1657         defer C.free(unsafe.Pointer(cname))
1658         v.C = C.LLVMBuildVAArg(b.C, list.C, t.C, cname)
1659         return
1660 }
1661 func (b Builder) CreateExtractElement(vec, i Value, name string) (v Value) {
1662         cname := C.CString(name)
1663         defer C.free(unsafe.Pointer(cname))
1664         v.C = C.LLVMBuildExtractElement(b.C, vec.C, i.C, cname)
1665         return
1666 }
1667 func (b Builder) CreateInsertElement(vec, elt, i Value, name string) (v Value) {
1668         cname := C.CString(name)
1669         defer C.free(unsafe.Pointer(cname))
1670         v.C = C.LLVMBuildInsertElement(b.C, vec.C, elt.C, i.C, cname)
1671         return
1672 }
1673 func (b Builder) CreateShuffleVector(v1, v2, mask Value, name string) (v Value) {
1674         cname := C.CString(name)
1675         defer C.free(unsafe.Pointer(cname))
1676         v.C = C.LLVMBuildShuffleVector(b.C, v1.C, v2.C, mask.C, cname)
1677         return
1678 }
1679 func (b Builder) CreateExtractValue(agg Value, i int, name string) (v Value) {
1680         cname := C.CString(name)
1681         defer C.free(unsafe.Pointer(cname))
1682         v.C = C.LLVMBuildExtractValue(b.C, agg.C, C.unsigned(i), cname)
1683         return
1684 }
1685 func (b Builder) CreateInsertValue(agg, elt Value, i int, name string) (v Value) {
1686         cname := C.CString(name)
1687         defer C.free(unsafe.Pointer(cname))
1688         v.C = C.LLVMBuildInsertValue(b.C, agg.C, elt.C, C.unsigned(i), cname)
1689         return
1690 }
1691
1692 func (b Builder) CreateIsNull(val Value, name string) (v Value) {
1693         cname := C.CString(name)
1694         defer C.free(unsafe.Pointer(cname))
1695         v.C = C.LLVMBuildIsNull(b.C, val.C, cname)
1696         return
1697 }
1698 func (b Builder) CreateIsNotNull(val Value, name string) (v Value) {
1699         cname := C.CString(name)
1700         defer C.free(unsafe.Pointer(cname))
1701         v.C = C.LLVMBuildIsNotNull(b.C, val.C, cname)
1702         return
1703 }
1704 func (b Builder) CreatePtrDiff(lhs, rhs Value, name string) (v Value) {
1705         cname := C.CString(name)
1706         defer C.free(unsafe.Pointer(cname))
1707         v.C = C.LLVMBuildPtrDiff(b.C, lhs.C, rhs.C, cname)
1708         return
1709 }
1710
1711 func (b Builder) CreateLandingPad(t Type, personality Value, nclauses int, name string) (l Value) {
1712         cname := C.CString(name)
1713         defer C.free(unsafe.Pointer(cname))
1714         l.C = C.LLVMBuildLandingPad(b.C, t.C, personality.C, C.unsigned(nclauses), cname)
1715         return l
1716 }
1717
1718 func (l Value) AddClause(v Value) {
1719         C.LLVMAddClause(l.C, v.C)
1720 }
1721
1722 func (l Value) SetCleanup(cleanup bool) {
1723         C.LLVMSetCleanup(l.C, boolToLLVMBool(cleanup))
1724 }
1725
1726 func (b Builder) CreateResume(ex Value) (v Value) {
1727         v.C = C.LLVMBuildResume(b.C, ex.C)
1728         return
1729 }
1730
1731 //-------------------------------------------------------------------------
1732 // llvm.ModuleProvider
1733 //-------------------------------------------------------------------------
1734
1735 // Changes the type of M so it can be passed to FunctionPassManagers and the
1736 // JIT. They take ModuleProviders for historical reasons.
1737 func NewModuleProviderForModule(m Module) (mp ModuleProvider) {
1738         mp.C = C.LLVMCreateModuleProviderForExistingModule(m.C)
1739         return
1740 }
1741
1742 // Destroys the module M.
1743 func (mp ModuleProvider) Dispose() { C.LLVMDisposeModuleProvider(mp.C) }
1744
1745 //-------------------------------------------------------------------------
1746 // llvm.MemoryBuffer
1747 //-------------------------------------------------------------------------
1748
1749 func NewMemoryBufferFromFile(path string) (b MemoryBuffer, err error) {
1750         var cmsg *C.char
1751         cpath := C.CString(path)
1752         defer C.free(unsafe.Pointer(cpath))
1753         fail := C.LLVMCreateMemoryBufferWithContentsOfFile(cpath, &b.C, &cmsg)
1754         if fail != 0 {
1755                 b.C = nil
1756                 err = errors.New(C.GoString(cmsg))
1757                 C.LLVMDisposeMessage(cmsg)
1758         }
1759         return
1760 }
1761
1762 func NewMemoryBufferFromStdin() (b MemoryBuffer, err error) {
1763         var cmsg *C.char
1764         fail := C.LLVMCreateMemoryBufferWithSTDIN(&b.C, &cmsg)
1765         if fail != 0 {
1766                 b.C = nil
1767                 err = errors.New(C.GoString(cmsg))
1768                 C.LLVMDisposeMessage(cmsg)
1769         }
1770         return
1771 }
1772
1773 func (b MemoryBuffer) Bytes() []byte {
1774         cstart := C.LLVMGetBufferStart(b.C)
1775         csize := C.LLVMGetBufferSize(b.C)
1776         return C.GoBytes(unsafe.Pointer(cstart), C.int(csize))
1777 }
1778
1779 func (b MemoryBuffer) Dispose() { C.LLVMDisposeMemoryBuffer(b.C) }
1780
1781 //-------------------------------------------------------------------------
1782 // llvm.PassManager
1783 //-------------------------------------------------------------------------
1784
1785 // Constructs a new whole-module pass pipeline. This type of pipeline is
1786 // suitable for link-time optimization and whole-module transformations.
1787 // See llvm::PassManager::PassManager.
1788 func NewPassManager() (pm PassManager) { pm.C = C.LLVMCreatePassManager(); return }
1789
1790 // Constructs a new function-by-function pass pipeline over the module
1791 // provider. It does not take ownership of the module provider. This type of
1792 // pipeline is suitable for code generation and JIT compilation tasks.
1793 // See llvm::FunctionPassManager::FunctionPassManager.
1794 func NewFunctionPassManagerForModule(m Module) (pm PassManager) {
1795         pm.C = C.LLVMCreateFunctionPassManagerForModule(m.C)
1796         return
1797 }
1798
1799 // Initializes, executes on the provided module, and finalizes all of the
1800 // passes scheduled in the pass manager. Returns 1 if any of the passes
1801 // modified the module, 0 otherwise. See llvm::PassManager::run(Module&).
1802 func (pm PassManager) Run(m Module) bool { return C.LLVMRunPassManager(pm.C, m.C) != 0 }
1803
1804 // Initializes all of the function passes scheduled in the function pass
1805 // manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1806 // See llvm::FunctionPassManager::doInitialization.
1807 func (pm PassManager) InitializeFunc() bool { return C.LLVMInitializeFunctionPassManager(pm.C) != 0 }
1808
1809 // Executes all of the function passes scheduled in the function pass manager
1810 // on the provided function. Returns 1 if any of the passes modified the
1811 // function, false otherwise.
1812 // See llvm::FunctionPassManager::run(Function&).
1813 func (pm PassManager) RunFunc(f Value) bool { return C.LLVMRunFunctionPassManager(pm.C, f.C) != 0 }
1814
1815 // Finalizes all of the function passes scheduled in in the function pass
1816 // manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1817 // See llvm::FunctionPassManager::doFinalization.
1818 func (pm PassManager) FinalizeFunc() bool { return C.LLVMFinalizeFunctionPassManager(pm.C) != 0 }
1819
1820 // Frees the memory of a pass pipeline. For function pipelines, does not free
1821 // the module provider.
1822 // See llvm::PassManagerBase::~PassManagerBase.
1823 func (pm PassManager) Dispose() { C.LLVMDisposePassManager(pm.C) }