Make sure that the go bindings call LLVMInitializeMCJITCompilerOptions
[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 func (v Value) SetUnnamedAddr(ua bool)      { C.LLVMSetUnnamedAddr(v.C, boolToLLVMBool(ua)) }
960
961 // Operations on global variables
962 func AddGlobal(m Module, t Type, name string) (v Value) {
963         cname := C.CString(name)
964         defer C.free(unsafe.Pointer(cname))
965         v.C = C.LLVMAddGlobal(m.C, t.C, cname)
966         return
967 }
968 func AddGlobalInAddressSpace(m Module, t Type, name string, addressSpace int) (v Value) {
969         cname := C.CString(name)
970         defer C.free(unsafe.Pointer(cname))
971         v.C = C.LLVMAddGlobalInAddressSpace(m.C, t.C, cname, C.unsigned(addressSpace))
972         return
973 }
974 func (m Module) NamedGlobal(name string) (v Value) {
975         cname := C.CString(name)
976         defer C.free(unsafe.Pointer(cname))
977         v.C = C.LLVMGetNamedGlobal(m.C, cname)
978         return
979 }
980
981 func (m Module) FirstGlobal() (v Value)   { v.C = C.LLVMGetFirstGlobal(m.C); return }
982 func (m Module) LastGlobal() (v Value)    { v.C = C.LLVMGetLastGlobal(m.C); return }
983 func NextGlobal(v Value) (rv Value)       { rv.C = C.LLVMGetNextGlobal(v.C); return }
984 func PrevGlobal(v Value) (rv Value)       { rv.C = C.LLVMGetPreviousGlobal(v.C); return }
985 func (v Value) EraseFromParentAsGlobal()  { C.LLVMDeleteGlobal(v.C) }
986 func (v Value) Initializer() (rv Value)   { rv.C = C.LLVMGetInitializer(v.C); return }
987 func (v Value) SetInitializer(cv Value)   { C.LLVMSetInitializer(v.C, cv.C) }
988 func (v Value) IsThreadLocal() bool       { return C.LLVMIsThreadLocal(v.C) != 0 }
989 func (v Value) SetThreadLocal(tl bool)    { C.LLVMSetThreadLocal(v.C, boolToLLVMBool(tl)) }
990 func (v Value) IsGlobalConstant() bool    { return C.LLVMIsGlobalConstant(v.C) != 0 }
991 func (v Value) SetGlobalConstant(gc bool) { C.LLVMSetGlobalConstant(v.C, boolToLLVMBool(gc)) }
992
993 // Operations on aliases
994 func AddAlias(m Module, t Type, aliasee Value, name string) (v Value) {
995         cname := C.CString(name)
996         defer C.free(unsafe.Pointer(cname))
997         v.C = C.LLVMAddAlias(m.C, t.C, aliasee.C, cname)
998         return
999 }
1000
1001 // Operations on functions
1002 func AddFunction(m Module, name string, ft Type) (v Value) {
1003         cname := C.CString(name)
1004         defer C.free(unsafe.Pointer(cname))
1005         v.C = C.LLVMAddFunction(m.C, cname, ft.C)
1006         return
1007 }
1008
1009 func (m Module) NamedFunction(name string) (v Value) {
1010         cname := C.CString(name)
1011         defer C.free(unsafe.Pointer(cname))
1012         v.C = C.LLVMGetNamedFunction(m.C, cname)
1013         return
1014 }
1015
1016 func (m Module) FirstFunction() (v Value)  { v.C = C.LLVMGetFirstFunction(m.C); return }
1017 func (m Module) LastFunction() (v Value)   { v.C = C.LLVMGetLastFunction(m.C); return }
1018 func NextFunction(v Value) (rv Value)      { rv.C = C.LLVMGetNextFunction(v.C); return }
1019 func PrevFunction(v Value) (rv Value)      { rv.C = C.LLVMGetPreviousFunction(v.C); return }
1020 func (v Value) EraseFromParentAsFunction() { C.LLVMDeleteFunction(v.C) }
1021 func (v Value) IntrinsicID() int           { return int(C.LLVMGetIntrinsicID(v.C)) }
1022 func (v Value) FunctionCallConv() CallConv {
1023         return CallConv(C.LLVMCallConv(C.LLVMGetFunctionCallConv(v.C)))
1024 }
1025 func (v Value) SetFunctionCallConv(cc CallConv) { C.LLVMSetFunctionCallConv(v.C, C.unsigned(cc)) }
1026 func (v Value) GC() string                      { return C.GoString(C.LLVMGetGC(v.C)) }
1027 func (v Value) SetGC(name string) {
1028         cname := C.CString(name)
1029         defer C.free(unsafe.Pointer(cname))
1030         C.LLVMSetGC(v.C, cname)
1031 }
1032 func (v Value) AddFunctionAttr(a Attribute)    { C.LLVMAddFunctionAttr2(v.C, C.uint64_t(a)) }
1033 func (v Value) FunctionAttr() Attribute        { return Attribute(C.LLVMGetFunctionAttr2(v.C)) }
1034 func (v Value) RemoveFunctionAttr(a Attribute) { C.LLVMRemoveFunctionAttr2(v.C, C.uint64_t(a)) }
1035 func (v Value) AddTargetDependentFunctionAttr(attr, value string) {
1036         cattr := C.CString(attr)
1037         defer C.free(unsafe.Pointer(cattr))
1038         cvalue := C.CString(value)
1039         defer C.free(unsafe.Pointer(cvalue))
1040         C.LLVMAddTargetDependentFunctionAttr(v.C, cattr, cvalue)
1041 }
1042
1043 // Operations on parameters
1044 func (v Value) ParamsCount() int { return int(C.LLVMCountParams(v.C)) }
1045 func (v Value) Params() []Value {
1046         out := make([]Value, v.ParamsCount())
1047         if len(out) > 0 {
1048                 C.LLVMGetParams(v.C, llvmValueRefPtr(&out[0]))
1049         }
1050         return out
1051 }
1052 func (v Value) Param(i int) (rv Value)  { rv.C = C.LLVMGetParam(v.C, C.unsigned(i)); return }
1053 func (v Value) ParamParent() (rv Value) { rv.C = C.LLVMGetParamParent(v.C); return }
1054 func (v Value) FirstParam() (rv Value)  { rv.C = C.LLVMGetFirstParam(v.C); return }
1055 func (v Value) LastParam() (rv Value)   { rv.C = C.LLVMGetLastParam(v.C); return }
1056 func NextParam(v Value) (rv Value)      { rv.C = C.LLVMGetNextParam(v.C); return }
1057 func PrevParam(v Value) (rv Value)      { rv.C = C.LLVMGetPreviousParam(v.C); return }
1058 func (v Value) AddAttribute(a Attribute) {
1059         if a >= 1<<32 {
1060                 panic("attribute value currently unsupported")
1061         }
1062         C.LLVMAddAttribute(v.C, C.LLVMAttribute(a))
1063 }
1064 func (v Value) RemoveAttribute(a Attribute) {
1065         if a >= 1<<32 {
1066                 panic("attribute value currently unsupported")
1067         }
1068         C.LLVMRemoveAttribute(v.C, C.LLVMAttribute(a))
1069 }
1070 func (v Value) Attribute() Attribute        { return Attribute(C.LLVMGetAttribute(v.C)) }
1071 func (v Value) SetParamAlignment(align int) { C.LLVMSetParamAlignment(v.C, C.unsigned(align)) }
1072
1073 // Operations on basic blocks
1074 func (bb BasicBlock) AsValue() (v Value)      { v.C = C.LLVMBasicBlockAsValue(bb.C); return }
1075 func (v Value) IsBasicBlock() bool            { return C.LLVMValueIsBasicBlock(v.C) != 0 }
1076 func (v Value) AsBasicBlock() (bb BasicBlock) { bb.C = C.LLVMValueAsBasicBlock(v.C); return }
1077 func (bb BasicBlock) Parent() (v Value)       { v.C = C.LLVMGetBasicBlockParent(bb.C); return }
1078 func (v Value) BasicBlocksCount() int         { return int(C.LLVMCountBasicBlocks(v.C)) }
1079 func (v Value) BasicBlocks() []BasicBlock {
1080         out := make([]BasicBlock, v.BasicBlocksCount())
1081         C.LLVMGetBasicBlocks(v.C, llvmBasicBlockRefPtr(&out[0]))
1082         return out
1083 }
1084 func (v Value) FirstBasicBlock() (bb BasicBlock)    { bb.C = C.LLVMGetFirstBasicBlock(v.C); return }
1085 func (v Value) LastBasicBlock() (bb BasicBlock)     { bb.C = C.LLVMGetLastBasicBlock(v.C); return }
1086 func NextBasicBlock(bb BasicBlock) (rbb BasicBlock) { rbb.C = C.LLVMGetNextBasicBlock(bb.C); return }
1087 func PrevBasicBlock(bb BasicBlock) (rbb BasicBlock) { rbb.C = C.LLVMGetPreviousBasicBlock(bb.C); return }
1088 func (v Value) EntryBasicBlock() (bb BasicBlock)    { bb.C = C.LLVMGetEntryBasicBlock(v.C); return }
1089 func (c Context) AddBasicBlock(f Value, name string) (bb BasicBlock) {
1090         cname := C.CString(name)
1091         defer C.free(unsafe.Pointer(cname))
1092         bb.C = C.LLVMAppendBasicBlockInContext(c.C, f.C, cname)
1093         return
1094 }
1095 func (c Context) InsertBasicBlock(ref BasicBlock, name string) (bb BasicBlock) {
1096         cname := C.CString(name)
1097         defer C.free(unsafe.Pointer(cname))
1098         bb.C = C.LLVMInsertBasicBlockInContext(c.C, ref.C, cname)
1099         return
1100 }
1101 func AddBasicBlock(f Value, name string) (bb BasicBlock) {
1102         cname := C.CString(name)
1103         defer C.free(unsafe.Pointer(cname))
1104         bb.C = C.LLVMAppendBasicBlock(f.C, cname)
1105         return
1106 }
1107 func InsertBasicBlock(ref BasicBlock, name string) (bb BasicBlock) {
1108         cname := C.CString(name)
1109         defer C.free(unsafe.Pointer(cname))
1110         bb.C = C.LLVMInsertBasicBlock(ref.C, cname)
1111         return
1112 }
1113 func (bb BasicBlock) EraseFromParent()          { C.LLVMDeleteBasicBlock(bb.C) }
1114 func (bb BasicBlock) MoveBefore(pos BasicBlock) { C.LLVMMoveBasicBlockBefore(bb.C, pos.C) }
1115 func (bb BasicBlock) MoveAfter(pos BasicBlock)  { C.LLVMMoveBasicBlockAfter(bb.C, pos.C) }
1116
1117 // Operations on instructions
1118 func (v Value) InstructionParent() (bb BasicBlock) { bb.C = C.LLVMGetInstructionParent(v.C); return }
1119 func (bb BasicBlock) FirstInstruction() (v Value)  { v.C = C.LLVMGetFirstInstruction(bb.C); return }
1120 func (bb BasicBlock) LastInstruction() (v Value)   { v.C = C.LLVMGetLastInstruction(bb.C); return }
1121 func NextInstruction(v Value) (rv Value)           { rv.C = C.LLVMGetNextInstruction(v.C); return }
1122 func PrevInstruction(v Value) (rv Value)           { rv.C = C.LLVMGetPreviousInstruction(v.C); return }
1123
1124 // Operations on call sites
1125 func (v Value) SetInstructionCallConv(cc CallConv) {
1126         C.LLVMSetInstructionCallConv(v.C, C.unsigned(cc))
1127 }
1128 func (v Value) InstructionCallConv() CallConv {
1129         return CallConv(C.LLVMCallConv(C.LLVMGetInstructionCallConv(v.C)))
1130 }
1131 func (v Value) AddInstrAttribute(i int, a Attribute) {
1132         if a >= 1<<32 {
1133                 panic("attribute value currently unsupported")
1134         }
1135         C.LLVMAddInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a))
1136 }
1137 func (v Value) RemoveInstrAttribute(i int, a Attribute) {
1138         if a >= 1<<32 {
1139                 panic("attribute value currently unsupported")
1140         }
1141         C.LLVMRemoveInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a))
1142 }
1143 func (v Value) SetInstrParamAlignment(i int, align int) {
1144         C.LLVMSetInstrParamAlignment(v.C, C.unsigned(i), C.unsigned(align))
1145 }
1146
1147 // Operations on call instructions (only)
1148 func (v Value) IsTailCall() bool    { return C.LLVMIsTailCall(v.C) != 0 }
1149 func (v Value) SetTailCall(is bool) { C.LLVMSetTailCall(v.C, boolToLLVMBool(is)) }
1150
1151 // Operations on phi nodes
1152 func (v Value) AddIncoming(vals []Value, blocks []BasicBlock) {
1153         ptr, nvals := llvmValueRefs(vals)
1154         C.LLVMAddIncoming(v.C, ptr, llvmBasicBlockRefPtr(&blocks[0]), nvals)
1155 }
1156 func (v Value) IncomingCount() int { return int(C.LLVMCountIncoming(v.C)) }
1157 func (v Value) IncomingValue(i int) (rv Value) {
1158         rv.C = C.LLVMGetIncomingValue(v.C, C.unsigned(i))
1159         return
1160 }
1161 func (v Value) IncomingBlock(i int) (bb BasicBlock) {
1162         bb.C = C.LLVMGetIncomingBlock(v.C, C.unsigned(i))
1163         return
1164 }
1165
1166 //-------------------------------------------------------------------------
1167 // llvm.Builder
1168 //-------------------------------------------------------------------------
1169
1170 // An instruction builder represents a point within a basic block, and is the
1171 // exclusive means of building instructions using the C interface.
1172
1173 func (c Context) NewBuilder() (b Builder) { b.C = C.LLVMCreateBuilderInContext(c.C); return }
1174 func NewBuilder() (b Builder)             { b.C = C.LLVMCreateBuilder(); return }
1175 func (b Builder) SetInsertPoint(block BasicBlock, instr Value) {
1176         C.LLVMPositionBuilder(b.C, block.C, instr.C)
1177 }
1178 func (b Builder) SetInsertPointBefore(instr Value)     { C.LLVMPositionBuilderBefore(b.C, instr.C) }
1179 func (b Builder) SetInsertPointAtEnd(block BasicBlock) { C.LLVMPositionBuilderAtEnd(b.C, block.C) }
1180 func (b Builder) GetInsertBlock() (bb BasicBlock)      { bb.C = C.LLVMGetInsertBlock(b.C); return }
1181 func (b Builder) ClearInsertionPoint()                 { C.LLVMClearInsertionPosition(b.C) }
1182 func (b Builder) Insert(instr Value)                   { C.LLVMInsertIntoBuilder(b.C, instr.C) }
1183 func (b Builder) InsertWithName(instr Value, name string) {
1184         cname := C.CString(name)
1185         defer C.free(unsafe.Pointer(cname))
1186         C.LLVMInsertIntoBuilderWithName(b.C, instr.C, cname)
1187 }
1188 func (b Builder) Dispose() { C.LLVMDisposeBuilder(b.C) }
1189
1190 // Metadata
1191 func (b Builder) SetCurrentDebugLocation(v Value) { C.LLVMSetCurrentDebugLocation(b.C, v.C) }
1192 func (b Builder) CurrentDebugLocation() (v Value) { v.C = C.LLVMGetCurrentDebugLocation(b.C); return }
1193 func (b Builder) SetInstDebugLocation(v Value)    { C.LLVMSetInstDebugLocation(b.C, v.C) }
1194 func (b Builder) InsertDeclare(module Module, storage Value, md Value) Value {
1195         f := module.NamedFunction("llvm.dbg.declare")
1196         if f.IsNil() {
1197                 ftyp := FunctionType(VoidType(), []Type{storage.Type(), md.Type()}, false)
1198                 f = AddFunction(module, "llvm.dbg.declare", ftyp)
1199         }
1200         return b.CreateCall(f, []Value{storage, md}, "")
1201 }
1202
1203 // Terminators
1204 func (b Builder) CreateRetVoid() (rv Value)    { rv.C = C.LLVMBuildRetVoid(b.C); return }
1205 func (b Builder) CreateRet(v Value) (rv Value) { rv.C = C.LLVMBuildRet(b.C, v.C); return }
1206 func (b Builder) CreateAggregateRet(vs []Value) (rv Value) {
1207         ptr, nvals := llvmValueRefs(vs)
1208         rv.C = C.LLVMBuildAggregateRet(b.C, ptr, nvals)
1209         return
1210 }
1211 func (b Builder) CreateBr(bb BasicBlock) (rv Value) { rv.C = C.LLVMBuildBr(b.C, bb.C); return }
1212 func (b Builder) CreateCondBr(ifv Value, thenb, elseb BasicBlock) (rv Value) {
1213         rv.C = C.LLVMBuildCondBr(b.C, ifv.C, thenb.C, elseb.C)
1214         return
1215 }
1216 func (b Builder) CreateSwitch(v Value, elseb BasicBlock, numCases int) (rv Value) {
1217         rv.C = C.LLVMBuildSwitch(b.C, v.C, elseb.C, C.unsigned(numCases))
1218         return
1219 }
1220 func (b Builder) CreateIndirectBr(addr Value, numDests int) (rv Value) {
1221         rv.C = C.LLVMBuildIndirectBr(b.C, addr.C, C.unsigned(numDests))
1222         return
1223 }
1224 func (b Builder) CreateInvoke(fn Value, args []Value, then, catch BasicBlock, name string) (rv Value) {
1225         cname := C.CString(name)
1226         defer C.free(unsafe.Pointer(cname))
1227         ptr, nvals := llvmValueRefs(args)
1228         rv.C = C.LLVMBuildInvoke(b.C, fn.C, ptr, nvals, then.C, catch.C, cname)
1229         return
1230 }
1231 func (b Builder) CreateUnreachable() (rv Value) { rv.C = C.LLVMBuildUnreachable(b.C); return }
1232
1233 // Add a case to the switch instruction
1234 func (v Value) AddCase(on Value, dest BasicBlock) { C.LLVMAddCase(v.C, on.C, dest.C) }
1235
1236 // Add a destination to the indirectbr instruction
1237 func (v Value) AddDest(dest BasicBlock) { C.LLVMAddDestination(v.C, dest.C) }
1238
1239 // Arithmetic
1240 func (b Builder) CreateAdd(lhs, rhs Value, name string) (v Value) {
1241         cname := C.CString(name)
1242         defer C.free(unsafe.Pointer(cname))
1243         v.C = C.LLVMBuildAdd(b.C, lhs.C, rhs.C, cname)
1244         return
1245 }
1246 func (b Builder) CreateNSWAdd(lhs, rhs Value, name string) (v Value) {
1247         cname := C.CString(name)
1248         defer C.free(unsafe.Pointer(cname))
1249         v.C = C.LLVMBuildNSWAdd(b.C, lhs.C, rhs.C, cname)
1250         return
1251 }
1252 func (b Builder) CreateNUWAdd(lhs, rhs Value, name string) (v Value) {
1253         cname := C.CString(name)
1254         defer C.free(unsafe.Pointer(cname))
1255         v.C = C.LLVMBuildNUWAdd(b.C, lhs.C, rhs.C, cname)
1256         return
1257 }
1258 func (b Builder) CreateFAdd(lhs, rhs Value, name string) (v Value) {
1259         cname := C.CString(name)
1260         defer C.free(unsafe.Pointer(cname))
1261         v.C = C.LLVMBuildFAdd(b.C, lhs.C, rhs.C, cname)
1262         return
1263 }
1264 func (b Builder) CreateSub(lhs, rhs Value, name string) (v Value) {
1265         cname := C.CString(name)
1266         defer C.free(unsafe.Pointer(cname))
1267         v.C = C.LLVMBuildSub(b.C, lhs.C, rhs.C, cname)
1268         return
1269 }
1270 func (b Builder) CreateNSWSub(lhs, rhs Value, name string) (v Value) {
1271         cname := C.CString(name)
1272         defer C.free(unsafe.Pointer(cname))
1273         v.C = C.LLVMBuildNSWSub(b.C, lhs.C, rhs.C, cname)
1274         return
1275 }
1276 func (b Builder) CreateNUWSub(lhs, rhs Value, name string) (v Value) {
1277         cname := C.CString(name)
1278         defer C.free(unsafe.Pointer(cname))
1279         v.C = C.LLVMBuildNUWSub(b.C, lhs.C, rhs.C, cname)
1280         return
1281 }
1282 func (b Builder) CreateFSub(lhs, rhs Value, name string) (v Value) {
1283         cname := C.CString(name)
1284         v.C = C.LLVMBuildFSub(b.C, lhs.C, rhs.C, cname)
1285         C.free(unsafe.Pointer(cname))
1286         return
1287 }
1288 func (b Builder) CreateMul(lhs, rhs Value, name string) (v Value) {
1289         cname := C.CString(name)
1290         defer C.free(unsafe.Pointer(cname))
1291         v.C = C.LLVMBuildMul(b.C, lhs.C, rhs.C, cname)
1292         return
1293 }
1294 func (b Builder) CreateNSWMul(lhs, rhs Value, name string) (v Value) {
1295         cname := C.CString(name)
1296         defer C.free(unsafe.Pointer(cname))
1297         v.C = C.LLVMBuildNSWMul(b.C, lhs.C, rhs.C, cname)
1298         return
1299 }
1300 func (b Builder) CreateNUWMul(lhs, rhs Value, name string) (v Value) {
1301         cname := C.CString(name)
1302         defer C.free(unsafe.Pointer(cname))
1303         v.C = C.LLVMBuildNUWMul(b.C, lhs.C, rhs.C, cname)
1304         return
1305 }
1306 func (b Builder) CreateFMul(lhs, rhs Value, name string) (v Value) {
1307         cname := C.CString(name)
1308         defer C.free(unsafe.Pointer(cname))
1309         v.C = C.LLVMBuildFMul(b.C, lhs.C, rhs.C, cname)
1310         return
1311 }
1312 func (b Builder) CreateUDiv(lhs, rhs Value, name string) (v Value) {
1313         cname := C.CString(name)
1314         defer C.free(unsafe.Pointer(cname))
1315         v.C = C.LLVMBuildUDiv(b.C, lhs.C, rhs.C, cname)
1316         return
1317 }
1318 func (b Builder) CreateSDiv(lhs, rhs Value, name string) (v Value) {
1319         cname := C.CString(name)
1320         defer C.free(unsafe.Pointer(cname))
1321         v.C = C.LLVMBuildSDiv(b.C, lhs.C, rhs.C, cname)
1322         return
1323 }
1324 func (b Builder) CreateExactSDiv(lhs, rhs Value, name string) (v Value) {
1325         cname := C.CString(name)
1326         defer C.free(unsafe.Pointer(cname))
1327         v.C = C.LLVMBuildExactSDiv(b.C, lhs.C, rhs.C, cname)
1328         return
1329 }
1330 func (b Builder) CreateFDiv(lhs, rhs Value, name string) (v Value) {
1331         cname := C.CString(name)
1332         defer C.free(unsafe.Pointer(cname))
1333         v.C = C.LLVMBuildFDiv(b.C, lhs.C, rhs.C, cname)
1334         return
1335 }
1336 func (b Builder) CreateURem(lhs, rhs Value, name string) (v Value) {
1337         cname := C.CString(name)
1338         defer C.free(unsafe.Pointer(cname))
1339         v.C = C.LLVMBuildURem(b.C, lhs.C, rhs.C, cname)
1340         return
1341 }
1342 func (b Builder) CreateSRem(lhs, rhs Value, name string) (v Value) {
1343         cname := C.CString(name)
1344         defer C.free(unsafe.Pointer(cname))
1345         v.C = C.LLVMBuildSRem(b.C, lhs.C, rhs.C, cname)
1346         return
1347 }
1348 func (b Builder) CreateFRem(lhs, rhs Value, name string) (v Value) {
1349         cname := C.CString(name)
1350         defer C.free(unsafe.Pointer(cname))
1351         v.C = C.LLVMBuildFRem(b.C, lhs.C, rhs.C, cname)
1352         return
1353 }
1354 func (b Builder) CreateShl(lhs, rhs Value, name string) (v Value) {
1355         cname := C.CString(name)
1356         defer C.free(unsafe.Pointer(cname))
1357         v.C = C.LLVMBuildShl(b.C, lhs.C, rhs.C, cname)
1358         return
1359 }
1360 func (b Builder) CreateLShr(lhs, rhs Value, name string) (v Value) {
1361         cname := C.CString(name)
1362         defer C.free(unsafe.Pointer(cname))
1363         v.C = C.LLVMBuildLShr(b.C, lhs.C, rhs.C, cname)
1364         return
1365 }
1366 func (b Builder) CreateAShr(lhs, rhs Value, name string) (v Value) {
1367         cname := C.CString(name)
1368         defer C.free(unsafe.Pointer(cname))
1369         v.C = C.LLVMBuildAShr(b.C, lhs.C, rhs.C, cname)
1370         return
1371 }
1372 func (b Builder) CreateAnd(lhs, rhs Value, name string) (v Value) {
1373         cname := C.CString(name)
1374         defer C.free(unsafe.Pointer(cname))
1375         v.C = C.LLVMBuildAnd(b.C, lhs.C, rhs.C, cname)
1376         return
1377 }
1378 func (b Builder) CreateOr(lhs, rhs Value, name string) (v Value) {
1379         cname := C.CString(name)
1380         defer C.free(unsafe.Pointer(cname))
1381         v.C = C.LLVMBuildOr(b.C, lhs.C, rhs.C, cname)
1382         return
1383 }
1384 func (b Builder) CreateXor(lhs, rhs Value, name string) (v Value) {
1385         cname := C.CString(name)
1386         defer C.free(unsafe.Pointer(cname))
1387         v.C = C.LLVMBuildXor(b.C, lhs.C, rhs.C, cname)
1388         return
1389 }
1390 func (b Builder) CreateBinOp(op Opcode, lhs, rhs Value, name string) (v Value) {
1391         cname := C.CString(name)
1392         defer C.free(unsafe.Pointer(cname))
1393         v.C = C.LLVMBuildBinOp(b.C, C.LLVMOpcode(op), lhs.C, rhs.C, cname)
1394         return
1395 }
1396 func (b Builder) CreateNeg(v Value, name string) (rv Value) {
1397         cname := C.CString(name)
1398         defer C.free(unsafe.Pointer(cname))
1399         rv.C = C.LLVMBuildNeg(b.C, v.C, cname)
1400         return
1401 }
1402 func (b Builder) CreateNSWNeg(v Value, name string) (rv Value) {
1403         cname := C.CString(name)
1404         defer C.free(unsafe.Pointer(cname))
1405         rv.C = C.LLVMBuildNSWNeg(b.C, v.C, cname)
1406         return
1407 }
1408 func (b Builder) CreateNUWNeg(v Value, name string) (rv Value) {
1409         cname := C.CString(name)
1410         defer C.free(unsafe.Pointer(cname))
1411         rv.C = C.LLVMBuildNUWNeg(b.C, v.C, cname)
1412         return
1413 }
1414 func (b Builder) CreateFNeg(v Value, name string) (rv Value) {
1415         cname := C.CString(name)
1416         defer C.free(unsafe.Pointer(cname))
1417         rv.C = C.LLVMBuildFNeg(b.C, v.C, cname)
1418         return
1419 }
1420 func (b Builder) CreateNot(v Value, name string) (rv Value) {
1421         cname := C.CString(name)
1422         defer C.free(unsafe.Pointer(cname))
1423         rv.C = C.LLVMBuildNot(b.C, v.C, cname)
1424         return
1425 }
1426
1427 // Memory
1428
1429 func (b Builder) CreateMalloc(t Type, name string) (v Value) {
1430         cname := C.CString(name)
1431         defer C.free(unsafe.Pointer(cname))
1432         v.C = C.LLVMBuildMalloc(b.C, t.C, cname)
1433         return
1434 }
1435 func (b Builder) CreateArrayMalloc(t Type, val Value, name string) (v Value) {
1436         cname := C.CString(name)
1437         defer C.free(unsafe.Pointer(cname))
1438         v.C = C.LLVMBuildArrayMalloc(b.C, t.C, val.C, cname)
1439         return
1440 }
1441 func (b Builder) CreateAlloca(t Type, name string) (v Value) {
1442         cname := C.CString(name)
1443         defer C.free(unsafe.Pointer(cname))
1444         v.C = C.LLVMBuildAlloca(b.C, t.C, cname)
1445         return
1446 }
1447 func (b Builder) CreateArrayAlloca(t Type, val Value, name string) (v Value) {
1448         cname := C.CString(name)
1449         defer C.free(unsafe.Pointer(cname))
1450         v.C = C.LLVMBuildArrayAlloca(b.C, t.C, val.C, cname)
1451         return
1452 }
1453 func (b Builder) CreateFree(p Value) (v Value) {
1454         v.C = C.LLVMBuildFree(b.C, p.C)
1455         return
1456 }
1457 func (b Builder) CreateLoad(p Value, name string) (v Value) {
1458         cname := C.CString(name)
1459         defer C.free(unsafe.Pointer(cname))
1460         v.C = C.LLVMBuildLoad(b.C, p.C, cname)
1461         return
1462 }
1463 func (b Builder) CreateStore(val Value, p Value) (v Value) {
1464         v.C = C.LLVMBuildStore(b.C, val.C, p.C)
1465         return
1466 }
1467 func (b Builder) CreateGEP(p Value, indices []Value, name string) (v Value) {
1468         cname := C.CString(name)
1469         defer C.free(unsafe.Pointer(cname))
1470         ptr, nvals := llvmValueRefs(indices)
1471         v.C = C.LLVMBuildGEP(b.C, p.C, ptr, nvals, cname)
1472         return
1473 }
1474 func (b Builder) CreateInBoundsGEP(p Value, indices []Value, name string) (v Value) {
1475         cname := C.CString(name)
1476         defer C.free(unsafe.Pointer(cname))
1477         ptr, nvals := llvmValueRefs(indices)
1478         v.C = C.LLVMBuildInBoundsGEP(b.C, p.C, ptr, nvals, cname)
1479         return
1480 }
1481 func (b Builder) CreateStructGEP(p Value, i int, name string) (v Value) {
1482         cname := C.CString(name)
1483         defer C.free(unsafe.Pointer(cname))
1484         v.C = C.LLVMBuildStructGEP(b.C, p.C, C.unsigned(i), cname)
1485         return
1486 }
1487 func (b Builder) CreateGlobalString(str, name string) (v Value) {
1488         cstr := C.CString(str)
1489         defer C.free(unsafe.Pointer(cstr))
1490         cname := C.CString(name)
1491         defer C.free(unsafe.Pointer(cname))
1492         v.C = C.LLVMBuildGlobalString(b.C, cstr, cname)
1493         return
1494 }
1495 func (b Builder) CreateGlobalStringPtr(str, name string) (v Value) {
1496         cstr := C.CString(str)
1497         defer C.free(unsafe.Pointer(cstr))
1498         cname := C.CString(name)
1499         defer C.free(unsafe.Pointer(cname))
1500         v.C = C.LLVMBuildGlobalStringPtr(b.C, cstr, cname)
1501         return
1502 }
1503
1504 // Casts
1505 func (b Builder) CreateTrunc(val Value, t Type, name string) (v Value) {
1506         cname := C.CString(name)
1507         defer C.free(unsafe.Pointer(cname))
1508         v.C = C.LLVMBuildTrunc(b.C, val.C, t.C, cname)
1509         return
1510 }
1511 func (b Builder) CreateZExt(val Value, t Type, name string) (v Value) {
1512         cname := C.CString(name)
1513         defer C.free(unsafe.Pointer(cname))
1514         v.C = C.LLVMBuildZExt(b.C, val.C, t.C, cname)
1515         return
1516 }
1517 func (b Builder) CreateSExt(val Value, t Type, name string) (v Value) {
1518         cname := C.CString(name)
1519         defer C.free(unsafe.Pointer(cname))
1520         v.C = C.LLVMBuildSExt(b.C, val.C, t.C, cname)
1521         return
1522 }
1523 func (b Builder) CreateFPToUI(val Value, t Type, name string) (v Value) {
1524         cname := C.CString(name)
1525         defer C.free(unsafe.Pointer(cname))
1526         v.C = C.LLVMBuildFPToUI(b.C, val.C, t.C, cname)
1527         return
1528 }
1529 func (b Builder) CreateFPToSI(val Value, t Type, name string) (v Value) {
1530         cname := C.CString(name)
1531         defer C.free(unsafe.Pointer(cname))
1532         v.C = C.LLVMBuildFPToSI(b.C, val.C, t.C, cname)
1533         return
1534 }
1535 func (b Builder) CreateUIToFP(val Value, t Type, name string) (v Value) {
1536         cname := C.CString(name)
1537         defer C.free(unsafe.Pointer(cname))
1538         v.C = C.LLVMBuildUIToFP(b.C, val.C, t.C, cname)
1539         return
1540 }
1541 func (b Builder) CreateSIToFP(val Value, t Type, name string) (v Value) {
1542         cname := C.CString(name)
1543         defer C.free(unsafe.Pointer(cname))
1544         v.C = C.LLVMBuildSIToFP(b.C, val.C, t.C, cname)
1545         return
1546 }
1547 func (b Builder) CreateFPTrunc(val Value, t Type, name string) (v Value) {
1548         cname := C.CString(name)
1549         defer C.free(unsafe.Pointer(cname))
1550         v.C = C.LLVMBuildFPTrunc(b.C, val.C, t.C, cname)
1551         return
1552 }
1553 func (b Builder) CreateFPExt(val Value, t Type, name string) (v Value) {
1554         cname := C.CString(name)
1555         defer C.free(unsafe.Pointer(cname))
1556         v.C = C.LLVMBuildFPExt(b.C, val.C, t.C, cname)
1557         return
1558 }
1559 func (b Builder) CreatePtrToInt(val Value, t Type, name string) (v Value) {
1560         cname := C.CString(name)
1561         defer C.free(unsafe.Pointer(cname))
1562         v.C = C.LLVMBuildPtrToInt(b.C, val.C, t.C, cname)
1563         return
1564 }
1565 func (b Builder) CreateIntToPtr(val Value, t Type, name string) (v Value) {
1566         cname := C.CString(name)
1567         defer C.free(unsafe.Pointer(cname))
1568         v.C = C.LLVMBuildIntToPtr(b.C, val.C, t.C, cname)
1569         return
1570 }
1571 func (b Builder) CreateBitCast(val Value, t Type, name string) (v Value) {
1572         cname := C.CString(name)
1573         defer C.free(unsafe.Pointer(cname))
1574         v.C = C.LLVMBuildBitCast(b.C, val.C, t.C, cname)
1575         return
1576 }
1577 func (b Builder) CreateZExtOrBitCast(val Value, t Type, name string) (v Value) {
1578         cname := C.CString(name)
1579         defer C.free(unsafe.Pointer(cname))
1580         v.C = C.LLVMBuildZExtOrBitCast(b.C, val.C, t.C, cname)
1581         return
1582 }
1583 func (b Builder) CreateSExtOrBitCast(val Value, t Type, name string) (v Value) {
1584         cname := C.CString(name)
1585         defer C.free(unsafe.Pointer(cname))
1586         v.C = C.LLVMBuildSExtOrBitCast(b.C, val.C, t.C, cname)
1587         return
1588 }
1589 func (b Builder) CreateTruncOrBitCast(val Value, t Type, name string) (v Value) {
1590         cname := C.CString(name)
1591         defer C.free(unsafe.Pointer(cname))
1592         v.C = C.LLVMBuildTruncOrBitCast(b.C, val.C, t.C, cname)
1593         return
1594 }
1595 func (b Builder) CreateCast(val Value, op Opcode, t Type, name string) (v Value) {
1596         cname := C.CString(name)
1597         defer C.free(unsafe.Pointer(cname))
1598         v.C = C.LLVMBuildCast(b.C, C.LLVMOpcode(op), val.C, t.C, cname)
1599         return
1600 } //
1601 func (b Builder) CreatePointerCast(val Value, t Type, name string) (v Value) {
1602         cname := C.CString(name)
1603         defer C.free(unsafe.Pointer(cname))
1604         v.C = C.LLVMBuildPointerCast(b.C, val.C, t.C, cname)
1605         return
1606 }
1607 func (b Builder) CreateIntCast(val Value, t Type, name string) (v Value) {
1608         cname := C.CString(name)
1609         defer C.free(unsafe.Pointer(cname))
1610         v.C = C.LLVMBuildIntCast(b.C, val.C, t.C, cname)
1611         return
1612 }
1613 func (b Builder) CreateFPCast(val Value, t Type, name string) (v Value) {
1614         cname := C.CString(name)
1615         defer C.free(unsafe.Pointer(cname))
1616         v.C = C.LLVMBuildFPCast(b.C, val.C, t.C, cname)
1617         return
1618 }
1619
1620 // Comparisons
1621 func (b Builder) CreateICmp(pred IntPredicate, lhs, rhs Value, name string) (v Value) {
1622         cname := C.CString(name)
1623         defer C.free(unsafe.Pointer(cname))
1624         v.C = C.LLVMBuildICmp(b.C, C.LLVMIntPredicate(pred), lhs.C, rhs.C, cname)
1625         return
1626 }
1627 func (b Builder) CreateFCmp(pred FloatPredicate, lhs, rhs Value, name string) (v Value) {
1628         cname := C.CString(name)
1629         defer C.free(unsafe.Pointer(cname))
1630         v.C = C.LLVMBuildFCmp(b.C, C.LLVMRealPredicate(pred), lhs.C, rhs.C, cname)
1631         return
1632 }
1633
1634 // Miscellaneous instructions
1635 func (b Builder) CreatePHI(t Type, name string) (v Value) {
1636         cname := C.CString(name)
1637         defer C.free(unsafe.Pointer(cname))
1638         v.C = C.LLVMBuildPhi(b.C, t.C, cname)
1639         return
1640 }
1641 func (b Builder) CreateCall(fn Value, args []Value, name string) (v Value) {
1642         cname := C.CString(name)
1643         defer C.free(unsafe.Pointer(cname))
1644         ptr, nvals := llvmValueRefs(args)
1645         v.C = C.LLVMBuildCall(b.C, fn.C, ptr, nvals, cname)
1646         return
1647 }
1648
1649 func (b Builder) CreateSelect(ifv, thenv, elsev Value, name string) (v Value) {
1650         cname := C.CString(name)
1651         defer C.free(unsafe.Pointer(cname))
1652         v.C = C.LLVMBuildSelect(b.C, ifv.C, thenv.C, elsev.C, cname)
1653         return
1654 }
1655
1656 func (b Builder) CreateVAArg(list Value, t Type, name string) (v Value) {
1657         cname := C.CString(name)
1658         defer C.free(unsafe.Pointer(cname))
1659         v.C = C.LLVMBuildVAArg(b.C, list.C, t.C, cname)
1660         return
1661 }
1662 func (b Builder) CreateExtractElement(vec, i Value, name string) (v Value) {
1663         cname := C.CString(name)
1664         defer C.free(unsafe.Pointer(cname))
1665         v.C = C.LLVMBuildExtractElement(b.C, vec.C, i.C, cname)
1666         return
1667 }
1668 func (b Builder) CreateInsertElement(vec, elt, i Value, name string) (v Value) {
1669         cname := C.CString(name)
1670         defer C.free(unsafe.Pointer(cname))
1671         v.C = C.LLVMBuildInsertElement(b.C, vec.C, elt.C, i.C, cname)
1672         return
1673 }
1674 func (b Builder) CreateShuffleVector(v1, v2, mask Value, name string) (v Value) {
1675         cname := C.CString(name)
1676         defer C.free(unsafe.Pointer(cname))
1677         v.C = C.LLVMBuildShuffleVector(b.C, v1.C, v2.C, mask.C, cname)
1678         return
1679 }
1680 func (b Builder) CreateExtractValue(agg Value, i int, name string) (v Value) {
1681         cname := C.CString(name)
1682         defer C.free(unsafe.Pointer(cname))
1683         v.C = C.LLVMBuildExtractValue(b.C, agg.C, C.unsigned(i), cname)
1684         return
1685 }
1686 func (b Builder) CreateInsertValue(agg, elt Value, i int, name string) (v Value) {
1687         cname := C.CString(name)
1688         defer C.free(unsafe.Pointer(cname))
1689         v.C = C.LLVMBuildInsertValue(b.C, agg.C, elt.C, C.unsigned(i), cname)
1690         return
1691 }
1692
1693 func (b Builder) CreateIsNull(val Value, name string) (v Value) {
1694         cname := C.CString(name)
1695         defer C.free(unsafe.Pointer(cname))
1696         v.C = C.LLVMBuildIsNull(b.C, val.C, cname)
1697         return
1698 }
1699 func (b Builder) CreateIsNotNull(val Value, name string) (v Value) {
1700         cname := C.CString(name)
1701         defer C.free(unsafe.Pointer(cname))
1702         v.C = C.LLVMBuildIsNotNull(b.C, val.C, cname)
1703         return
1704 }
1705 func (b Builder) CreatePtrDiff(lhs, rhs Value, name string) (v Value) {
1706         cname := C.CString(name)
1707         defer C.free(unsafe.Pointer(cname))
1708         v.C = C.LLVMBuildPtrDiff(b.C, lhs.C, rhs.C, cname)
1709         return
1710 }
1711
1712 func (b Builder) CreateLandingPad(t Type, personality Value, nclauses int, name string) (l Value) {
1713         cname := C.CString(name)
1714         defer C.free(unsafe.Pointer(cname))
1715         l.C = C.LLVMBuildLandingPad(b.C, t.C, personality.C, C.unsigned(nclauses), cname)
1716         return l
1717 }
1718
1719 func (l Value) AddClause(v Value) {
1720         C.LLVMAddClause(l.C, v.C)
1721 }
1722
1723 func (l Value) SetCleanup(cleanup bool) {
1724         C.LLVMSetCleanup(l.C, boolToLLVMBool(cleanup))
1725 }
1726
1727 func (b Builder) CreateResume(ex Value) (v Value) {
1728         v.C = C.LLVMBuildResume(b.C, ex.C)
1729         return
1730 }
1731
1732 //-------------------------------------------------------------------------
1733 // llvm.ModuleProvider
1734 //-------------------------------------------------------------------------
1735
1736 // Changes the type of M so it can be passed to FunctionPassManagers and the
1737 // JIT. They take ModuleProviders for historical reasons.
1738 func NewModuleProviderForModule(m Module) (mp ModuleProvider) {
1739         mp.C = C.LLVMCreateModuleProviderForExistingModule(m.C)
1740         return
1741 }
1742
1743 // Destroys the module M.
1744 func (mp ModuleProvider) Dispose() { C.LLVMDisposeModuleProvider(mp.C) }
1745
1746 //-------------------------------------------------------------------------
1747 // llvm.MemoryBuffer
1748 //-------------------------------------------------------------------------
1749
1750 func NewMemoryBufferFromFile(path string) (b MemoryBuffer, err error) {
1751         var cmsg *C.char
1752         cpath := C.CString(path)
1753         defer C.free(unsafe.Pointer(cpath))
1754         fail := C.LLVMCreateMemoryBufferWithContentsOfFile(cpath, &b.C, &cmsg)
1755         if fail != 0 {
1756                 b.C = nil
1757                 err = errors.New(C.GoString(cmsg))
1758                 C.LLVMDisposeMessage(cmsg)
1759         }
1760         return
1761 }
1762
1763 func NewMemoryBufferFromStdin() (b MemoryBuffer, err error) {
1764         var cmsg *C.char
1765         fail := C.LLVMCreateMemoryBufferWithSTDIN(&b.C, &cmsg)
1766         if fail != 0 {
1767                 b.C = nil
1768                 err = errors.New(C.GoString(cmsg))
1769                 C.LLVMDisposeMessage(cmsg)
1770         }
1771         return
1772 }
1773
1774 func (b MemoryBuffer) Bytes() []byte {
1775         cstart := C.LLVMGetBufferStart(b.C)
1776         csize := C.LLVMGetBufferSize(b.C)
1777         return C.GoBytes(unsafe.Pointer(cstart), C.int(csize))
1778 }
1779
1780 func (b MemoryBuffer) Dispose() { C.LLVMDisposeMemoryBuffer(b.C) }
1781
1782 //-------------------------------------------------------------------------
1783 // llvm.PassManager
1784 //-------------------------------------------------------------------------
1785
1786 // Constructs a new whole-module pass pipeline. This type of pipeline is
1787 // suitable for link-time optimization and whole-module transformations.
1788 // See llvm::PassManager::PassManager.
1789 func NewPassManager() (pm PassManager) { pm.C = C.LLVMCreatePassManager(); return }
1790
1791 // Constructs a new function-by-function pass pipeline over the module
1792 // provider. It does not take ownership of the module provider. This type of
1793 // pipeline is suitable for code generation and JIT compilation tasks.
1794 // See llvm::FunctionPassManager::FunctionPassManager.
1795 func NewFunctionPassManagerForModule(m Module) (pm PassManager) {
1796         pm.C = C.LLVMCreateFunctionPassManagerForModule(m.C)
1797         return
1798 }
1799
1800 // Initializes, executes on the provided module, and finalizes all of the
1801 // passes scheduled in the pass manager. Returns 1 if any of the passes
1802 // modified the module, 0 otherwise. See llvm::PassManager::run(Module&).
1803 func (pm PassManager) Run(m Module) bool { return C.LLVMRunPassManager(pm.C, m.C) != 0 }
1804
1805 // Initializes all of the function passes scheduled in the function pass
1806 // manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1807 // See llvm::FunctionPassManager::doInitialization.
1808 func (pm PassManager) InitializeFunc() bool { return C.LLVMInitializeFunctionPassManager(pm.C) != 0 }
1809
1810 // Executes all of the function passes scheduled in the function pass manager
1811 // on the provided function. Returns 1 if any of the passes modified the
1812 // function, false otherwise.
1813 // See llvm::FunctionPassManager::run(Function&).
1814 func (pm PassManager) RunFunc(f Value) bool { return C.LLVMRunFunctionPassManager(pm.C, f.C) != 0 }
1815
1816 // Finalizes all of the function passes scheduled in in the function pass
1817 // manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1818 // See llvm::FunctionPassManager::doFinalization.
1819 func (pm PassManager) FinalizeFunc() bool { return C.LLVMFinalizeFunctionPassManager(pm.C) != 0 }
1820
1821 // Frees the memory of a pass pipeline. For function pipelines, does not free
1822 // the module provider.
1823 // See llvm::PassManagerBase::~PassManagerBase.
1824 func (pm PassManager) Dispose() { C.LLVMDisposePassManager(pm.C) }