af2aeffcc1563481a88b83d5c2fcacc4cf1e4691
[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 (c Context) MDNode(vals []Value) (v Value) {
733         ptr, nvals := llvmValueRefs(vals)
734         v.C = C.LLVMMDNodeInContext(c.C, ptr, nvals)
735         return
736 }
737
738 // Operations on scalar constants
739 func ConstInt(t Type, n uint64, signExtend bool) (v Value) {
740         v.C = C.LLVMConstInt(t.C,
741                 C.ulonglong(n),
742                 boolToLLVMBool(signExtend))
743         return
744 }
745 func ConstIntFromString(t Type, str string, radix int) (v Value) {
746         cstr := C.CString(str)
747         defer C.free(unsafe.Pointer(cstr))
748         v.C = C.LLVMConstIntOfString(t.C, cstr, C.uint8_t(radix))
749         return
750 }
751 func ConstFloat(t Type, n float64) (v Value) {
752         v.C = C.LLVMConstReal(t.C, C.double(n))
753         return
754 }
755 func ConstFloatFromString(t Type, str string) (v Value) {
756         cstr := C.CString(str)
757         defer C.free(unsafe.Pointer(cstr))
758         v.C = C.LLVMConstRealOfString(t.C, cstr)
759         return
760 }
761
762 func (v Value) ZExtValue() uint64 { return uint64(C.LLVMConstIntGetZExtValue(v.C)) }
763 func (v Value) SExtValue() int64  { return int64(C.LLVMConstIntGetSExtValue(v.C)) }
764
765 // Operations on composite constants
766 func (c Context) ConstString(str string, addnull bool) (v Value) {
767         cstr := C.CString(str)
768         defer C.free(unsafe.Pointer(cstr))
769         v.C = C.LLVMConstStringInContext(c.C, cstr,
770                 C.unsigned(len(str)), boolToLLVMBool(!addnull))
771         return
772 }
773 func (c Context) ConstStruct(constVals []Value, packed bool) (v Value) {
774         ptr, nvals := llvmValueRefs(constVals)
775         v.C = C.LLVMConstStructInContext(c.C, ptr, nvals,
776                 boolToLLVMBool(packed))
777         return
778 }
779 func ConstNamedStruct(t Type, constVals []Value) (v Value) {
780         ptr, nvals := llvmValueRefs(constVals)
781         v.C = C.LLVMConstNamedStruct(t.C, ptr, nvals)
782         return
783 }
784 func ConstString(str string, addnull bool) (v Value) {
785         cstr := C.CString(str)
786         defer C.free(unsafe.Pointer(cstr))
787         v.C = C.LLVMConstString(cstr,
788                 C.unsigned(len(str)), boolToLLVMBool(!addnull))
789         return
790 }
791 func ConstArray(t Type, constVals []Value) (v Value) {
792         ptr, nvals := llvmValueRefs(constVals)
793         v.C = C.LLVMConstArray(t.C, ptr, nvals)
794         return
795 }
796 func ConstStruct(constVals []Value, packed bool) (v Value) {
797         ptr, nvals := llvmValueRefs(constVals)
798         v.C = C.LLVMConstStruct(ptr, nvals, boolToLLVMBool(packed))
799         return
800 }
801 func ConstVector(scalarConstVals []Value, packed bool) (v Value) {
802         ptr, nvals := llvmValueRefs(scalarConstVals)
803         v.C = C.LLVMConstVector(ptr, nvals)
804         return
805 }
806
807 // Constant expressions
808 func (v Value) Opcode() Opcode                { return Opcode(C.LLVMGetConstOpcode(v.C)) }
809 func (v Value) InstructionOpcode() Opcode     { return Opcode(C.LLVMGetInstructionOpcode(v.C)) }
810 func AlignOf(t Type) (v Value)                { v.C = C.LLVMAlignOf(t.C); return }
811 func SizeOf(t Type) (v Value)                 { v.C = C.LLVMSizeOf(t.C); return }
812 func ConstNeg(v Value) (rv Value)             { rv.C = C.LLVMConstNeg(v.C); return }
813 func ConstNSWNeg(v Value) (rv Value)          { rv.C = C.LLVMConstNSWNeg(v.C); return }
814 func ConstNUWNeg(v Value) (rv Value)          { rv.C = C.LLVMConstNUWNeg(v.C); return }
815 func ConstFNeg(v Value) (rv Value)            { rv.C = C.LLVMConstFNeg(v.C); return }
816 func ConstNot(v Value) (rv Value)             { rv.C = C.LLVMConstNot(v.C); return }
817 func ConstAdd(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstAdd(lhs.C, rhs.C); return }
818 func ConstNSWAdd(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNSWAdd(lhs.C, rhs.C); return }
819 func ConstNUWAdd(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNUWAdd(lhs.C, rhs.C); return }
820 func ConstFAdd(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFAdd(lhs.C, rhs.C); return }
821 func ConstSub(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstSub(lhs.C, rhs.C); return }
822 func ConstNSWSub(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNSWSub(lhs.C, rhs.C); return }
823 func ConstNUWSub(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNUWSub(lhs.C, rhs.C); return }
824 func ConstFSub(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFSub(lhs.C, rhs.C); return }
825 func ConstMul(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstMul(lhs.C, rhs.C); return }
826 func ConstNSWMul(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNSWMul(lhs.C, rhs.C); return }
827 func ConstNUWMul(lhs, rhs Value) (v Value)    { v.C = C.LLVMConstNUWMul(lhs.C, rhs.C); return }
828 func ConstFMul(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFMul(lhs.C, rhs.C); return }
829 func ConstUDiv(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstUDiv(lhs.C, rhs.C); return }
830 func ConstSDiv(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstSDiv(lhs.C, rhs.C); return }
831 func ConstExactSDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstExactSDiv(lhs.C, rhs.C); return }
832 func ConstFDiv(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFDiv(lhs.C, rhs.C); return }
833 func ConstURem(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstURem(lhs.C, rhs.C); return }
834 func ConstSRem(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstSRem(lhs.C, rhs.C); return }
835 func ConstFRem(lhs, rhs Value) (v Value)      { v.C = C.LLVMConstFRem(lhs.C, rhs.C); return }
836 func ConstAnd(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstAnd(lhs.C, rhs.C); return }
837 func ConstOr(lhs, rhs Value) (v Value)        { v.C = C.LLVMConstOr(lhs.C, rhs.C); return }
838 func ConstXor(lhs, rhs Value) (v Value)       { v.C = C.LLVMConstXor(lhs.C, rhs.C); return }
839
840 func ConstICmp(pred IntPredicate, lhs, rhs Value) (v Value) {
841         v.C = C.LLVMConstICmp(C.LLVMIntPredicate(pred), lhs.C, rhs.C)
842         return
843 }
844 func ConstFCmp(pred FloatPredicate, lhs, rhs Value) (v Value) {
845         v.C = C.LLVMConstFCmp(C.LLVMRealPredicate(pred), lhs.C, rhs.C)
846         return
847 }
848
849 func ConstShl(lhs, rhs Value) (v Value)  { v.C = C.LLVMConstShl(lhs.C, rhs.C); return }
850 func ConstLShr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstLShr(lhs.C, rhs.C); return }
851 func ConstAShr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAShr(lhs.C, rhs.C); return }
852
853 func ConstGEP(v Value, indices []Value) (rv Value) {
854         ptr, nvals := llvmValueRefs(indices)
855         rv.C = C.LLVMConstGEP(v.C, ptr, nvals)
856         return
857 }
858 func ConstInBoundsGEP(v Value, indices []Value) (rv Value) {
859         ptr, nvals := llvmValueRefs(indices)
860         rv.C = C.LLVMConstInBoundsGEP(v.C, ptr, nvals)
861         return
862 }
863 func ConstTrunc(v Value, t Type) (rv Value)         { rv.C = C.LLVMConstTrunc(v.C, t.C); return }
864 func ConstSExt(v Value, t Type) (rv Value)          { rv.C = C.LLVMConstSExt(v.C, t.C); return }
865 func ConstZExt(v Value, t Type) (rv Value)          { rv.C = C.LLVMConstZExt(v.C, t.C); return }
866 func ConstFPTrunc(v Value, t Type) (rv Value)       { rv.C = C.LLVMConstFPTrunc(v.C, t.C); return }
867 func ConstFPExt(v Value, t Type) (rv Value)         { rv.C = C.LLVMConstFPExt(v.C, t.C); return }
868 func ConstUIToFP(v Value, t Type) (rv Value)        { rv.C = C.LLVMConstUIToFP(v.C, t.C); return }
869 func ConstSIToFP(v Value, t Type) (rv Value)        { rv.C = C.LLVMConstSIToFP(v.C, t.C); return }
870 func ConstFPToUI(v Value, t Type) (rv Value)        { rv.C = C.LLVMConstFPToUI(v.C, t.C); return }
871 func ConstFPToSI(v Value, t Type) (rv Value)        { rv.C = C.LLVMConstFPToSI(v.C, t.C); return }
872 func ConstPtrToInt(v Value, t Type) (rv Value)      { rv.C = C.LLVMConstPtrToInt(v.C, t.C); return }
873 func ConstIntToPtr(v Value, t Type) (rv Value)      { rv.C = C.LLVMConstIntToPtr(v.C, t.C); return }
874 func ConstBitCast(v Value, t Type) (rv Value)       { rv.C = C.LLVMConstBitCast(v.C, t.C); return }
875 func ConstZExtOrBitCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstZExtOrBitCast(v.C, t.C); return }
876 func ConstSExtOrBitCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstSExtOrBitCast(v.C, t.C); return }
877 func ConstTruncOrBitCast(v Value, t Type) (rv Value) {
878         rv.C = C.LLVMConstTruncOrBitCast(v.C, t.C)
879         return
880 }
881 func ConstPointerCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstPointerCast(v.C, t.C); return }
882 func ConstIntCast(v Value, t Type, signed bool) (rv Value) {
883         rv.C = C.LLVMConstIntCast(v.C, t.C, boolToLLVMBool(signed))
884         return
885 }
886 func ConstFPCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstFPCast(v.C, t.C); return }
887 func ConstSelect(cond, iftrue, iffalse Value) (rv Value) {
888         rv.C = C.LLVMConstSelect(cond.C, iftrue.C, iffalse.C)
889         return
890 }
891 func ConstExtractElement(vec, i Value) (rv Value) {
892         rv.C = C.LLVMConstExtractElement(vec.C, i.C)
893         return
894 }
895 func ConstInsertElement(vec, elem, i Value) (rv Value) {
896         rv.C = C.LLVMConstInsertElement(vec.C, elem.C, i.C)
897         return
898 }
899 func ConstShuffleVector(veca, vecb, mask Value) (rv Value) {
900         rv.C = C.LLVMConstShuffleVector(veca.C, vecb.C, mask.C)
901         return
902 }
903
904 //TODO
905 //LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
906 //                                   unsigned NumIdx);
907
908 func ConstExtractValue(agg Value, indices []uint32) (rv Value) {
909         n := len(indices)
910         if n == 0 {
911                 panic("one or more indices are required")
912         }
913         ptr := (*C.unsigned)(&indices[0])
914         rv.C = C.LLVMConstExtractValue(agg.C, ptr, C.unsigned(n))
915         return
916 }
917
918 func ConstInsertValue(agg, val Value, indices []uint32) (rv Value) {
919         n := len(indices)
920         if n == 0 {
921                 panic("one or more indices are required")
922         }
923         ptr := (*C.unsigned)(&indices[0])
924         rv.C = C.LLVMConstInsertValue(agg.C, val.C, ptr, C.unsigned(n))
925         return
926 }
927
928 func BlockAddress(f Value, bb BasicBlock) (v Value) {
929         v.C = C.LLVMBlockAddress(f.C, bb.C)
930         return
931 }
932
933 // Operations on global variables, functions, and aliases (globals)
934 func (v Value) GlobalParent() (m Module) { m.C = C.LLVMGetGlobalParent(v.C); return }
935 func (v Value) IsDeclaration() bool      { return C.LLVMIsDeclaration(v.C) != 0 }
936 func (v Value) Linkage() Linkage         { return Linkage(C.LLVMGetLinkage(v.C)) }
937 func (v Value) SetLinkage(l Linkage)     { C.LLVMSetLinkage(v.C, C.LLVMLinkage(l)) }
938 func (v Value) Section() string          { return C.GoString(C.LLVMGetSection(v.C)) }
939 func (v Value) SetSection(str string) {
940         cstr := C.CString(str)
941         defer C.free(unsafe.Pointer(cstr))
942         C.LLVMSetSection(v.C, cstr)
943 }
944 func (v Value) Visibility() Visibility      { return Visibility(C.LLVMGetVisibility(v.C)) }
945 func (v Value) SetVisibility(vi Visibility) { C.LLVMSetVisibility(v.C, C.LLVMVisibility(vi)) }
946 func (v Value) Alignment() int              { return int(C.LLVMGetAlignment(v.C)) }
947 func (v Value) SetAlignment(a int)          { C.LLVMSetAlignment(v.C, C.unsigned(a)) }
948 func (v Value) SetUnnamedAddr(ua bool)      { C.LLVMSetUnnamedAddr(v.C, boolToLLVMBool(ua)) }
949
950 // Operations on global variables
951 func AddGlobal(m Module, t Type, name string) (v Value) {
952         cname := C.CString(name)
953         defer C.free(unsafe.Pointer(cname))
954         v.C = C.LLVMAddGlobal(m.C, t.C, cname)
955         return
956 }
957 func AddGlobalInAddressSpace(m Module, t Type, name string, addressSpace int) (v Value) {
958         cname := C.CString(name)
959         defer C.free(unsafe.Pointer(cname))
960         v.C = C.LLVMAddGlobalInAddressSpace(m.C, t.C, cname, C.unsigned(addressSpace))
961         return
962 }
963 func (m Module) NamedGlobal(name string) (v Value) {
964         cname := C.CString(name)
965         defer C.free(unsafe.Pointer(cname))
966         v.C = C.LLVMGetNamedGlobal(m.C, cname)
967         return
968 }
969
970 func (m Module) FirstGlobal() (v Value)   { v.C = C.LLVMGetFirstGlobal(m.C); return }
971 func (m Module) LastGlobal() (v Value)    { v.C = C.LLVMGetLastGlobal(m.C); return }
972 func NextGlobal(v Value) (rv Value)       { rv.C = C.LLVMGetNextGlobal(v.C); return }
973 func PrevGlobal(v Value) (rv Value)       { rv.C = C.LLVMGetPreviousGlobal(v.C); return }
974 func (v Value) EraseFromParentAsGlobal()  { C.LLVMDeleteGlobal(v.C) }
975 func (v Value) Initializer() (rv Value)   { rv.C = C.LLVMGetInitializer(v.C); return }
976 func (v Value) SetInitializer(cv Value)   { C.LLVMSetInitializer(v.C, cv.C) }
977 func (v Value) IsThreadLocal() bool       { return C.LLVMIsThreadLocal(v.C) != 0 }
978 func (v Value) SetThreadLocal(tl bool)    { C.LLVMSetThreadLocal(v.C, boolToLLVMBool(tl)) }
979 func (v Value) IsGlobalConstant() bool    { return C.LLVMIsGlobalConstant(v.C) != 0 }
980 func (v Value) SetGlobalConstant(gc bool) { C.LLVMSetGlobalConstant(v.C, boolToLLVMBool(gc)) }
981
982 // Operations on aliases
983 func AddAlias(m Module, t Type, aliasee Value, name string) (v Value) {
984         cname := C.CString(name)
985         defer C.free(unsafe.Pointer(cname))
986         v.C = C.LLVMAddAlias(m.C, t.C, aliasee.C, cname)
987         return
988 }
989
990 // Operations on functions
991 func AddFunction(m Module, name string, ft Type) (v Value) {
992         cname := C.CString(name)
993         defer C.free(unsafe.Pointer(cname))
994         v.C = C.LLVMAddFunction(m.C, cname, ft.C)
995         return
996 }
997
998 func (m Module) NamedFunction(name string) (v Value) {
999         cname := C.CString(name)
1000         defer C.free(unsafe.Pointer(cname))
1001         v.C = C.LLVMGetNamedFunction(m.C, cname)
1002         return
1003 }
1004
1005 func (m Module) FirstFunction() (v Value)  { v.C = C.LLVMGetFirstFunction(m.C); return }
1006 func (m Module) LastFunction() (v Value)   { v.C = C.LLVMGetLastFunction(m.C); return }
1007 func NextFunction(v Value) (rv Value)      { rv.C = C.LLVMGetNextFunction(v.C); return }
1008 func PrevFunction(v Value) (rv Value)      { rv.C = C.LLVMGetPreviousFunction(v.C); return }
1009 func (v Value) EraseFromParentAsFunction() { C.LLVMDeleteFunction(v.C) }
1010 func (v Value) IntrinsicID() int           { return int(C.LLVMGetIntrinsicID(v.C)) }
1011 func (v Value) FunctionCallConv() CallConv {
1012         return CallConv(C.LLVMCallConv(C.LLVMGetFunctionCallConv(v.C)))
1013 }
1014 func (v Value) SetFunctionCallConv(cc CallConv) { C.LLVMSetFunctionCallConv(v.C, C.unsigned(cc)) }
1015 func (v Value) GC() string                      { return C.GoString(C.LLVMGetGC(v.C)) }
1016 func (v Value) SetGC(name string) {
1017         cname := C.CString(name)
1018         defer C.free(unsafe.Pointer(cname))
1019         C.LLVMSetGC(v.C, cname)
1020 }
1021 func (v Value) AddFunctionAttr(a Attribute)    { C.LLVMAddFunctionAttr2(v.C, C.uint64_t(a)) }
1022 func (v Value) FunctionAttr() Attribute        { return Attribute(C.LLVMGetFunctionAttr2(v.C)) }
1023 func (v Value) RemoveFunctionAttr(a Attribute) { C.LLVMRemoveFunctionAttr2(v.C, C.uint64_t(a)) }
1024 func (v Value) AddTargetDependentFunctionAttr(attr, value string) {
1025         cattr := C.CString(attr)
1026         defer C.free(unsafe.Pointer(cattr))
1027         cvalue := C.CString(value)
1028         defer C.free(unsafe.Pointer(cvalue))
1029         C.LLVMAddTargetDependentFunctionAttr(v.C, cattr, cvalue)
1030 }
1031
1032 // Operations on parameters
1033 func (v Value) ParamsCount() int { return int(C.LLVMCountParams(v.C)) }
1034 func (v Value) Params() []Value {
1035         out := make([]Value, v.ParamsCount())
1036         if len(out) > 0 {
1037                 C.LLVMGetParams(v.C, llvmValueRefPtr(&out[0]))
1038         }
1039         return out
1040 }
1041 func (v Value) Param(i int) (rv Value)  { rv.C = C.LLVMGetParam(v.C, C.unsigned(i)); return }
1042 func (v Value) ParamParent() (rv Value) { rv.C = C.LLVMGetParamParent(v.C); return }
1043 func (v Value) FirstParam() (rv Value)  { rv.C = C.LLVMGetFirstParam(v.C); return }
1044 func (v Value) LastParam() (rv Value)   { rv.C = C.LLVMGetLastParam(v.C); return }
1045 func NextParam(v Value) (rv Value)      { rv.C = C.LLVMGetNextParam(v.C); return }
1046 func PrevParam(v Value) (rv Value)      { rv.C = C.LLVMGetPreviousParam(v.C); return }
1047 func (v Value) AddAttribute(a Attribute) {
1048         if a >= 1<<32 {
1049                 panic("attribute value currently unsupported")
1050         }
1051         C.LLVMAddAttribute(v.C, C.LLVMAttribute(a))
1052 }
1053 func (v Value) RemoveAttribute(a Attribute) {
1054         if a >= 1<<32 {
1055                 panic("attribute value currently unsupported")
1056         }
1057         C.LLVMRemoveAttribute(v.C, C.LLVMAttribute(a))
1058 }
1059 func (v Value) Attribute() Attribute        { return Attribute(C.LLVMGetAttribute(v.C)) }
1060 func (v Value) SetParamAlignment(align int) { C.LLVMSetParamAlignment(v.C, C.unsigned(align)) }
1061
1062 // Operations on basic blocks
1063 func (bb BasicBlock) AsValue() (v Value)      { v.C = C.LLVMBasicBlockAsValue(bb.C); return }
1064 func (v Value) IsBasicBlock() bool            { return C.LLVMValueIsBasicBlock(v.C) != 0 }
1065 func (v Value) AsBasicBlock() (bb BasicBlock) { bb.C = C.LLVMValueAsBasicBlock(v.C); return }
1066 func (bb BasicBlock) Parent() (v Value)       { v.C = C.LLVMGetBasicBlockParent(bb.C); return }
1067 func (v Value) BasicBlocksCount() int         { return int(C.LLVMCountBasicBlocks(v.C)) }
1068 func (v Value) BasicBlocks() []BasicBlock {
1069         out := make([]BasicBlock, v.BasicBlocksCount())
1070         C.LLVMGetBasicBlocks(v.C, llvmBasicBlockRefPtr(&out[0]))
1071         return out
1072 }
1073 func (v Value) FirstBasicBlock() (bb BasicBlock)    { bb.C = C.LLVMGetFirstBasicBlock(v.C); return }
1074 func (v Value) LastBasicBlock() (bb BasicBlock)     { bb.C = C.LLVMGetLastBasicBlock(v.C); return }
1075 func NextBasicBlock(bb BasicBlock) (rbb BasicBlock) { rbb.C = C.LLVMGetNextBasicBlock(bb.C); return }
1076 func PrevBasicBlock(bb BasicBlock) (rbb BasicBlock) { rbb.C = C.LLVMGetPreviousBasicBlock(bb.C); return }
1077 func (v Value) EntryBasicBlock() (bb BasicBlock)    { bb.C = C.LLVMGetEntryBasicBlock(v.C); return }
1078 func (c Context) AddBasicBlock(f Value, name string) (bb BasicBlock) {
1079         cname := C.CString(name)
1080         defer C.free(unsafe.Pointer(cname))
1081         bb.C = C.LLVMAppendBasicBlockInContext(c.C, f.C, cname)
1082         return
1083 }
1084 func (c Context) InsertBasicBlock(ref BasicBlock, name string) (bb BasicBlock) {
1085         cname := C.CString(name)
1086         defer C.free(unsafe.Pointer(cname))
1087         bb.C = C.LLVMInsertBasicBlockInContext(c.C, ref.C, cname)
1088         return
1089 }
1090 func AddBasicBlock(f Value, name string) (bb BasicBlock) {
1091         cname := C.CString(name)
1092         defer C.free(unsafe.Pointer(cname))
1093         bb.C = C.LLVMAppendBasicBlock(f.C, cname)
1094         return
1095 }
1096 func InsertBasicBlock(ref BasicBlock, name string) (bb BasicBlock) {
1097         cname := C.CString(name)
1098         defer C.free(unsafe.Pointer(cname))
1099         bb.C = C.LLVMInsertBasicBlock(ref.C, cname)
1100         return
1101 }
1102 func (bb BasicBlock) EraseFromParent()          { C.LLVMDeleteBasicBlock(bb.C) }
1103 func (bb BasicBlock) MoveBefore(pos BasicBlock) { C.LLVMMoveBasicBlockBefore(bb.C, pos.C) }
1104 func (bb BasicBlock) MoveAfter(pos BasicBlock)  { C.LLVMMoveBasicBlockAfter(bb.C, pos.C) }
1105
1106 // Operations on instructions
1107 func (v Value) InstructionParent() (bb BasicBlock) { bb.C = C.LLVMGetInstructionParent(v.C); return }
1108 func (bb BasicBlock) FirstInstruction() (v Value)  { v.C = C.LLVMGetFirstInstruction(bb.C); return }
1109 func (bb BasicBlock) LastInstruction() (v Value)   { v.C = C.LLVMGetLastInstruction(bb.C); return }
1110 func NextInstruction(v Value) (rv Value)           { rv.C = C.LLVMGetNextInstruction(v.C); return }
1111 func PrevInstruction(v Value) (rv Value)           { rv.C = C.LLVMGetPreviousInstruction(v.C); return }
1112
1113 // Operations on call sites
1114 func (v Value) SetInstructionCallConv(cc CallConv) {
1115         C.LLVMSetInstructionCallConv(v.C, C.unsigned(cc))
1116 }
1117 func (v Value) InstructionCallConv() CallConv {
1118         return CallConv(C.LLVMCallConv(C.LLVMGetInstructionCallConv(v.C)))
1119 }
1120 func (v Value) AddInstrAttribute(i int, a Attribute) {
1121         if a >= 1<<32 {
1122                 panic("attribute value currently unsupported")
1123         }
1124         C.LLVMAddInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a))
1125 }
1126 func (v Value) RemoveInstrAttribute(i int, a Attribute) {
1127         if a >= 1<<32 {
1128                 panic("attribute value currently unsupported")
1129         }
1130         C.LLVMRemoveInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a))
1131 }
1132 func (v Value) SetInstrParamAlignment(i int, align int) {
1133         C.LLVMSetInstrParamAlignment(v.C, C.unsigned(i), C.unsigned(align))
1134 }
1135
1136 // Operations on call instructions (only)
1137 func (v Value) IsTailCall() bool    { return C.LLVMIsTailCall(v.C) != 0 }
1138 func (v Value) SetTailCall(is bool) { C.LLVMSetTailCall(v.C, boolToLLVMBool(is)) }
1139
1140 // Operations on phi nodes
1141 func (v Value) AddIncoming(vals []Value, blocks []BasicBlock) {
1142         ptr, nvals := llvmValueRefs(vals)
1143         C.LLVMAddIncoming(v.C, ptr, llvmBasicBlockRefPtr(&blocks[0]), nvals)
1144 }
1145 func (v Value) IncomingCount() int { return int(C.LLVMCountIncoming(v.C)) }
1146 func (v Value) IncomingValue(i int) (rv Value) {
1147         rv.C = C.LLVMGetIncomingValue(v.C, C.unsigned(i))
1148         return
1149 }
1150 func (v Value) IncomingBlock(i int) (bb BasicBlock) {
1151         bb.C = C.LLVMGetIncomingBlock(v.C, C.unsigned(i))
1152         return
1153 }
1154
1155 //-------------------------------------------------------------------------
1156 // llvm.Builder
1157 //-------------------------------------------------------------------------
1158
1159 // An instruction builder represents a point within a basic block, and is the
1160 // exclusive means of building instructions using the C interface.
1161
1162 func (c Context) NewBuilder() (b Builder) { b.C = C.LLVMCreateBuilderInContext(c.C); return }
1163 func NewBuilder() (b Builder)             { b.C = C.LLVMCreateBuilder(); return }
1164 func (b Builder) SetInsertPoint(block BasicBlock, instr Value) {
1165         C.LLVMPositionBuilder(b.C, block.C, instr.C)
1166 }
1167 func (b Builder) SetInsertPointBefore(instr Value)     { C.LLVMPositionBuilderBefore(b.C, instr.C) }
1168 func (b Builder) SetInsertPointAtEnd(block BasicBlock) { C.LLVMPositionBuilderAtEnd(b.C, block.C) }
1169 func (b Builder) GetInsertBlock() (bb BasicBlock)      { bb.C = C.LLVMGetInsertBlock(b.C); return }
1170 func (b Builder) ClearInsertionPoint()                 { C.LLVMClearInsertionPosition(b.C) }
1171 func (b Builder) Insert(instr Value)                   { C.LLVMInsertIntoBuilder(b.C, instr.C) }
1172 func (b Builder) InsertWithName(instr Value, name string) {
1173         cname := C.CString(name)
1174         defer C.free(unsafe.Pointer(cname))
1175         C.LLVMInsertIntoBuilderWithName(b.C, instr.C, cname)
1176 }
1177 func (b Builder) Dispose() { C.LLVMDisposeBuilder(b.C) }
1178
1179 // Metadata
1180 func (b Builder) SetCurrentDebugLocation(v Value) { C.LLVMSetCurrentDebugLocation(b.C, v.C) }
1181 func (b Builder) CurrentDebugLocation() (v Value) { v.C = C.LLVMGetCurrentDebugLocation(b.C); return }
1182 func (b Builder) SetInstDebugLocation(v Value)    { C.LLVMSetInstDebugLocation(b.C, v.C) }
1183 func (b Builder) InsertDeclare(module Module, storage Value, md Value) Value {
1184         f := module.NamedFunction("llvm.dbg.declare")
1185         if f.IsNil() {
1186                 ftyp := FunctionType(VoidType(), []Type{storage.Type(), md.Type()}, false)
1187                 f = AddFunction(module, "llvm.dbg.declare", ftyp)
1188         }
1189         return b.CreateCall(f, []Value{storage, md}, "")
1190 }
1191
1192 // Terminators
1193 func (b Builder) CreateRetVoid() (rv Value)    { rv.C = C.LLVMBuildRetVoid(b.C); return }
1194 func (b Builder) CreateRet(v Value) (rv Value) { rv.C = C.LLVMBuildRet(b.C, v.C); return }
1195 func (b Builder) CreateAggregateRet(vs []Value) (rv Value) {
1196         ptr, nvals := llvmValueRefs(vs)
1197         rv.C = C.LLVMBuildAggregateRet(b.C, ptr, nvals)
1198         return
1199 }
1200 func (b Builder) CreateBr(bb BasicBlock) (rv Value) { rv.C = C.LLVMBuildBr(b.C, bb.C); return }
1201 func (b Builder) CreateCondBr(ifv Value, thenb, elseb BasicBlock) (rv Value) {
1202         rv.C = C.LLVMBuildCondBr(b.C, ifv.C, thenb.C, elseb.C)
1203         return
1204 }
1205 func (b Builder) CreateSwitch(v Value, elseb BasicBlock, numCases int) (rv Value) {
1206         rv.C = C.LLVMBuildSwitch(b.C, v.C, elseb.C, C.unsigned(numCases))
1207         return
1208 }
1209 func (b Builder) CreateIndirectBr(addr Value, numDests int) (rv Value) {
1210         rv.C = C.LLVMBuildIndirectBr(b.C, addr.C, C.unsigned(numDests))
1211         return
1212 }
1213 func (b Builder) CreateInvoke(fn Value, args []Value, then, catch BasicBlock, name string) (rv Value) {
1214         cname := C.CString(name)
1215         defer C.free(unsafe.Pointer(cname))
1216         ptr, nvals := llvmValueRefs(args)
1217         rv.C = C.LLVMBuildInvoke(b.C, fn.C, ptr, nvals, then.C, catch.C, cname)
1218         return
1219 }
1220 func (b Builder) CreateUnreachable() (rv Value) { rv.C = C.LLVMBuildUnreachable(b.C); return }
1221
1222 // Add a case to the switch instruction
1223 func (v Value) AddCase(on Value, dest BasicBlock) { C.LLVMAddCase(v.C, on.C, dest.C) }
1224
1225 // Add a destination to the indirectbr instruction
1226 func (v Value) AddDest(dest BasicBlock) { C.LLVMAddDestination(v.C, dest.C) }
1227
1228 // Arithmetic
1229 func (b Builder) CreateAdd(lhs, rhs Value, name string) (v Value) {
1230         cname := C.CString(name)
1231         defer C.free(unsafe.Pointer(cname))
1232         v.C = C.LLVMBuildAdd(b.C, lhs.C, rhs.C, cname)
1233         return
1234 }
1235 func (b Builder) CreateNSWAdd(lhs, rhs Value, name string) (v Value) {
1236         cname := C.CString(name)
1237         defer C.free(unsafe.Pointer(cname))
1238         v.C = C.LLVMBuildNSWAdd(b.C, lhs.C, rhs.C, cname)
1239         return
1240 }
1241 func (b Builder) CreateNUWAdd(lhs, rhs Value, name string) (v Value) {
1242         cname := C.CString(name)
1243         defer C.free(unsafe.Pointer(cname))
1244         v.C = C.LLVMBuildNUWAdd(b.C, lhs.C, rhs.C, cname)
1245         return
1246 }
1247 func (b Builder) CreateFAdd(lhs, rhs Value, name string) (v Value) {
1248         cname := C.CString(name)
1249         defer C.free(unsafe.Pointer(cname))
1250         v.C = C.LLVMBuildFAdd(b.C, lhs.C, rhs.C, cname)
1251         return
1252 }
1253 func (b Builder) CreateSub(lhs, rhs Value, name string) (v Value) {
1254         cname := C.CString(name)
1255         defer C.free(unsafe.Pointer(cname))
1256         v.C = C.LLVMBuildSub(b.C, lhs.C, rhs.C, cname)
1257         return
1258 }
1259 func (b Builder) CreateNSWSub(lhs, rhs Value, name string) (v Value) {
1260         cname := C.CString(name)
1261         defer C.free(unsafe.Pointer(cname))
1262         v.C = C.LLVMBuildNSWSub(b.C, lhs.C, rhs.C, cname)
1263         return
1264 }
1265 func (b Builder) CreateNUWSub(lhs, rhs Value, name string) (v Value) {
1266         cname := C.CString(name)
1267         defer C.free(unsafe.Pointer(cname))
1268         v.C = C.LLVMBuildNUWSub(b.C, lhs.C, rhs.C, cname)
1269         return
1270 }
1271 func (b Builder) CreateFSub(lhs, rhs Value, name string) (v Value) {
1272         cname := C.CString(name)
1273         v.C = C.LLVMBuildFSub(b.C, lhs.C, rhs.C, cname)
1274         C.free(unsafe.Pointer(cname))
1275         return
1276 }
1277 func (b Builder) CreateMul(lhs, rhs Value, name string) (v Value) {
1278         cname := C.CString(name)
1279         defer C.free(unsafe.Pointer(cname))
1280         v.C = C.LLVMBuildMul(b.C, lhs.C, rhs.C, cname)
1281         return
1282 }
1283 func (b Builder) CreateNSWMul(lhs, rhs Value, name string) (v Value) {
1284         cname := C.CString(name)
1285         defer C.free(unsafe.Pointer(cname))
1286         v.C = C.LLVMBuildNSWMul(b.C, lhs.C, rhs.C, cname)
1287         return
1288 }
1289 func (b Builder) CreateNUWMul(lhs, rhs Value, name string) (v Value) {
1290         cname := C.CString(name)
1291         defer C.free(unsafe.Pointer(cname))
1292         v.C = C.LLVMBuildNUWMul(b.C, lhs.C, rhs.C, cname)
1293         return
1294 }
1295 func (b Builder) CreateFMul(lhs, rhs Value, name string) (v Value) {
1296         cname := C.CString(name)
1297         defer C.free(unsafe.Pointer(cname))
1298         v.C = C.LLVMBuildFMul(b.C, lhs.C, rhs.C, cname)
1299         return
1300 }
1301 func (b Builder) CreateUDiv(lhs, rhs Value, name string) (v Value) {
1302         cname := C.CString(name)
1303         defer C.free(unsafe.Pointer(cname))
1304         v.C = C.LLVMBuildUDiv(b.C, lhs.C, rhs.C, cname)
1305         return
1306 }
1307 func (b Builder) CreateSDiv(lhs, rhs Value, name string) (v Value) {
1308         cname := C.CString(name)
1309         defer C.free(unsafe.Pointer(cname))
1310         v.C = C.LLVMBuildSDiv(b.C, lhs.C, rhs.C, cname)
1311         return
1312 }
1313 func (b Builder) CreateExactSDiv(lhs, rhs Value, name string) (v Value) {
1314         cname := C.CString(name)
1315         defer C.free(unsafe.Pointer(cname))
1316         v.C = C.LLVMBuildExactSDiv(b.C, lhs.C, rhs.C, cname)
1317         return
1318 }
1319 func (b Builder) CreateFDiv(lhs, rhs Value, name string) (v Value) {
1320         cname := C.CString(name)
1321         defer C.free(unsafe.Pointer(cname))
1322         v.C = C.LLVMBuildFDiv(b.C, lhs.C, rhs.C, cname)
1323         return
1324 }
1325 func (b Builder) CreateURem(lhs, rhs Value, name string) (v Value) {
1326         cname := C.CString(name)
1327         defer C.free(unsafe.Pointer(cname))
1328         v.C = C.LLVMBuildURem(b.C, lhs.C, rhs.C, cname)
1329         return
1330 }
1331 func (b Builder) CreateSRem(lhs, rhs Value, name string) (v Value) {
1332         cname := C.CString(name)
1333         defer C.free(unsafe.Pointer(cname))
1334         v.C = C.LLVMBuildSRem(b.C, lhs.C, rhs.C, cname)
1335         return
1336 }
1337 func (b Builder) CreateFRem(lhs, rhs Value, name string) (v Value) {
1338         cname := C.CString(name)
1339         defer C.free(unsafe.Pointer(cname))
1340         v.C = C.LLVMBuildFRem(b.C, lhs.C, rhs.C, cname)
1341         return
1342 }
1343 func (b Builder) CreateShl(lhs, rhs Value, name string) (v Value) {
1344         cname := C.CString(name)
1345         defer C.free(unsafe.Pointer(cname))
1346         v.C = C.LLVMBuildShl(b.C, lhs.C, rhs.C, cname)
1347         return
1348 }
1349 func (b Builder) CreateLShr(lhs, rhs Value, name string) (v Value) {
1350         cname := C.CString(name)
1351         defer C.free(unsafe.Pointer(cname))
1352         v.C = C.LLVMBuildLShr(b.C, lhs.C, rhs.C, cname)
1353         return
1354 }
1355 func (b Builder) CreateAShr(lhs, rhs Value, name string) (v Value) {
1356         cname := C.CString(name)
1357         defer C.free(unsafe.Pointer(cname))
1358         v.C = C.LLVMBuildAShr(b.C, lhs.C, rhs.C, cname)
1359         return
1360 }
1361 func (b Builder) CreateAnd(lhs, rhs Value, name string) (v Value) {
1362         cname := C.CString(name)
1363         defer C.free(unsafe.Pointer(cname))
1364         v.C = C.LLVMBuildAnd(b.C, lhs.C, rhs.C, cname)
1365         return
1366 }
1367 func (b Builder) CreateOr(lhs, rhs Value, name string) (v Value) {
1368         cname := C.CString(name)
1369         defer C.free(unsafe.Pointer(cname))
1370         v.C = C.LLVMBuildOr(b.C, lhs.C, rhs.C, cname)
1371         return
1372 }
1373 func (b Builder) CreateXor(lhs, rhs Value, name string) (v Value) {
1374         cname := C.CString(name)
1375         defer C.free(unsafe.Pointer(cname))
1376         v.C = C.LLVMBuildXor(b.C, lhs.C, rhs.C, cname)
1377         return
1378 }
1379 func (b Builder) CreateBinOp(op Opcode, lhs, rhs Value, name string) (v Value) {
1380         cname := C.CString(name)
1381         defer C.free(unsafe.Pointer(cname))
1382         v.C = C.LLVMBuildBinOp(b.C, C.LLVMOpcode(op), lhs.C, rhs.C, cname)
1383         return
1384 }
1385 func (b Builder) CreateNeg(v Value, name string) (rv Value) {
1386         cname := C.CString(name)
1387         defer C.free(unsafe.Pointer(cname))
1388         rv.C = C.LLVMBuildNeg(b.C, v.C, cname)
1389         return
1390 }
1391 func (b Builder) CreateNSWNeg(v Value, name string) (rv Value) {
1392         cname := C.CString(name)
1393         defer C.free(unsafe.Pointer(cname))
1394         rv.C = C.LLVMBuildNSWNeg(b.C, v.C, cname)
1395         return
1396 }
1397 func (b Builder) CreateNUWNeg(v Value, name string) (rv Value) {
1398         cname := C.CString(name)
1399         defer C.free(unsafe.Pointer(cname))
1400         rv.C = C.LLVMBuildNUWNeg(b.C, v.C, cname)
1401         return
1402 }
1403 func (b Builder) CreateFNeg(v Value, name string) (rv Value) {
1404         cname := C.CString(name)
1405         defer C.free(unsafe.Pointer(cname))
1406         rv.C = C.LLVMBuildFNeg(b.C, v.C, cname)
1407         return
1408 }
1409 func (b Builder) CreateNot(v Value, name string) (rv Value) {
1410         cname := C.CString(name)
1411         defer C.free(unsafe.Pointer(cname))
1412         rv.C = C.LLVMBuildNot(b.C, v.C, cname)
1413         return
1414 }
1415
1416 // Memory
1417
1418 func (b Builder) CreateMalloc(t Type, name string) (v Value) {
1419         cname := C.CString(name)
1420         defer C.free(unsafe.Pointer(cname))
1421         v.C = C.LLVMBuildMalloc(b.C, t.C, cname)
1422         return
1423 }
1424 func (b Builder) CreateArrayMalloc(t Type, val Value, name string) (v Value) {
1425         cname := C.CString(name)
1426         defer C.free(unsafe.Pointer(cname))
1427         v.C = C.LLVMBuildArrayMalloc(b.C, t.C, val.C, cname)
1428         return
1429 }
1430 func (b Builder) CreateAlloca(t Type, name string) (v Value) {
1431         cname := C.CString(name)
1432         defer C.free(unsafe.Pointer(cname))
1433         v.C = C.LLVMBuildAlloca(b.C, t.C, cname)
1434         return
1435 }
1436 func (b Builder) CreateArrayAlloca(t Type, val Value, name string) (v Value) {
1437         cname := C.CString(name)
1438         defer C.free(unsafe.Pointer(cname))
1439         v.C = C.LLVMBuildArrayAlloca(b.C, t.C, val.C, cname)
1440         return
1441 }
1442 func (b Builder) CreateFree(p Value) (v Value) {
1443         v.C = C.LLVMBuildFree(b.C, p.C)
1444         return
1445 }
1446 func (b Builder) CreateLoad(p Value, name string) (v Value) {
1447         cname := C.CString(name)
1448         defer C.free(unsafe.Pointer(cname))
1449         v.C = C.LLVMBuildLoad(b.C, p.C, cname)
1450         return
1451 }
1452 func (b Builder) CreateStore(val Value, p Value) (v Value) {
1453         v.C = C.LLVMBuildStore(b.C, val.C, p.C)
1454         return
1455 }
1456 func (b Builder) CreateGEP(p Value, indices []Value, name string) (v Value) {
1457         cname := C.CString(name)
1458         defer C.free(unsafe.Pointer(cname))
1459         ptr, nvals := llvmValueRefs(indices)
1460         v.C = C.LLVMBuildGEP(b.C, p.C, ptr, nvals, cname)
1461         return
1462 }
1463 func (b Builder) CreateInBoundsGEP(p Value, indices []Value, name string) (v Value) {
1464         cname := C.CString(name)
1465         defer C.free(unsafe.Pointer(cname))
1466         ptr, nvals := llvmValueRefs(indices)
1467         v.C = C.LLVMBuildInBoundsGEP(b.C, p.C, ptr, nvals, cname)
1468         return
1469 }
1470 func (b Builder) CreateStructGEP(p Value, i int, name string) (v Value) {
1471         cname := C.CString(name)
1472         defer C.free(unsafe.Pointer(cname))
1473         v.C = C.LLVMBuildStructGEP(b.C, p.C, C.unsigned(i), cname)
1474         return
1475 }
1476 func (b Builder) CreateGlobalString(str, name string) (v Value) {
1477         cstr := C.CString(str)
1478         defer C.free(unsafe.Pointer(cstr))
1479         cname := C.CString(name)
1480         defer C.free(unsafe.Pointer(cname))
1481         v.C = C.LLVMBuildGlobalString(b.C, cstr, cname)
1482         return
1483 }
1484 func (b Builder) CreateGlobalStringPtr(str, name string) (v Value) {
1485         cstr := C.CString(str)
1486         defer C.free(unsafe.Pointer(cstr))
1487         cname := C.CString(name)
1488         defer C.free(unsafe.Pointer(cname))
1489         v.C = C.LLVMBuildGlobalStringPtr(b.C, cstr, cname)
1490         return
1491 }
1492
1493 // Casts
1494 func (b Builder) CreateTrunc(val Value, t Type, name string) (v Value) {
1495         cname := C.CString(name)
1496         defer C.free(unsafe.Pointer(cname))
1497         v.C = C.LLVMBuildTrunc(b.C, val.C, t.C, cname)
1498         return
1499 }
1500 func (b Builder) CreateZExt(val Value, t Type, name string) (v Value) {
1501         cname := C.CString(name)
1502         defer C.free(unsafe.Pointer(cname))
1503         v.C = C.LLVMBuildZExt(b.C, val.C, t.C, cname)
1504         return
1505 }
1506 func (b Builder) CreateSExt(val Value, t Type, name string) (v Value) {
1507         cname := C.CString(name)
1508         defer C.free(unsafe.Pointer(cname))
1509         v.C = C.LLVMBuildSExt(b.C, val.C, t.C, cname)
1510         return
1511 }
1512 func (b Builder) CreateFPToUI(val Value, t Type, name string) (v Value) {
1513         cname := C.CString(name)
1514         defer C.free(unsafe.Pointer(cname))
1515         v.C = C.LLVMBuildFPToUI(b.C, val.C, t.C, cname)
1516         return
1517 }
1518 func (b Builder) CreateFPToSI(val Value, t Type, name string) (v Value) {
1519         cname := C.CString(name)
1520         defer C.free(unsafe.Pointer(cname))
1521         v.C = C.LLVMBuildFPToSI(b.C, val.C, t.C, cname)
1522         return
1523 }
1524 func (b Builder) CreateUIToFP(val Value, t Type, name string) (v Value) {
1525         cname := C.CString(name)
1526         defer C.free(unsafe.Pointer(cname))
1527         v.C = C.LLVMBuildUIToFP(b.C, val.C, t.C, cname)
1528         return
1529 }
1530 func (b Builder) CreateSIToFP(val Value, t Type, name string) (v Value) {
1531         cname := C.CString(name)
1532         defer C.free(unsafe.Pointer(cname))
1533         v.C = C.LLVMBuildSIToFP(b.C, val.C, t.C, cname)
1534         return
1535 }
1536 func (b Builder) CreateFPTrunc(val Value, t Type, name string) (v Value) {
1537         cname := C.CString(name)
1538         defer C.free(unsafe.Pointer(cname))
1539         v.C = C.LLVMBuildFPTrunc(b.C, val.C, t.C, cname)
1540         return
1541 }
1542 func (b Builder) CreateFPExt(val Value, t Type, name string) (v Value) {
1543         cname := C.CString(name)
1544         defer C.free(unsafe.Pointer(cname))
1545         v.C = C.LLVMBuildFPExt(b.C, val.C, t.C, cname)
1546         return
1547 }
1548 func (b Builder) CreatePtrToInt(val Value, t Type, name string) (v Value) {
1549         cname := C.CString(name)
1550         defer C.free(unsafe.Pointer(cname))
1551         v.C = C.LLVMBuildPtrToInt(b.C, val.C, t.C, cname)
1552         return
1553 }
1554 func (b Builder) CreateIntToPtr(val Value, t Type, name string) (v Value) {
1555         cname := C.CString(name)
1556         defer C.free(unsafe.Pointer(cname))
1557         v.C = C.LLVMBuildIntToPtr(b.C, val.C, t.C, cname)
1558         return
1559 }
1560 func (b Builder) CreateBitCast(val Value, t Type, name string) (v Value) {
1561         cname := C.CString(name)
1562         defer C.free(unsafe.Pointer(cname))
1563         v.C = C.LLVMBuildBitCast(b.C, val.C, t.C, cname)
1564         return
1565 }
1566 func (b Builder) CreateZExtOrBitCast(val Value, t Type, name string) (v Value) {
1567         cname := C.CString(name)
1568         defer C.free(unsafe.Pointer(cname))
1569         v.C = C.LLVMBuildZExtOrBitCast(b.C, val.C, t.C, cname)
1570         return
1571 }
1572 func (b Builder) CreateSExtOrBitCast(val Value, t Type, name string) (v Value) {
1573         cname := C.CString(name)
1574         defer C.free(unsafe.Pointer(cname))
1575         v.C = C.LLVMBuildSExtOrBitCast(b.C, val.C, t.C, cname)
1576         return
1577 }
1578 func (b Builder) CreateTruncOrBitCast(val Value, t Type, name string) (v Value) {
1579         cname := C.CString(name)
1580         defer C.free(unsafe.Pointer(cname))
1581         v.C = C.LLVMBuildTruncOrBitCast(b.C, val.C, t.C, cname)
1582         return
1583 }
1584 func (b Builder) CreateCast(val Value, op Opcode, t Type, name string) (v Value) {
1585         cname := C.CString(name)
1586         defer C.free(unsafe.Pointer(cname))
1587         v.C = C.LLVMBuildCast(b.C, C.LLVMOpcode(op), val.C, t.C, cname)
1588         return
1589 } //
1590 func (b Builder) CreatePointerCast(val Value, t Type, name string) (v Value) {
1591         cname := C.CString(name)
1592         defer C.free(unsafe.Pointer(cname))
1593         v.C = C.LLVMBuildPointerCast(b.C, val.C, t.C, cname)
1594         return
1595 }
1596 func (b Builder) CreateIntCast(val Value, t Type, name string) (v Value) {
1597         cname := C.CString(name)
1598         defer C.free(unsafe.Pointer(cname))
1599         v.C = C.LLVMBuildIntCast(b.C, val.C, t.C, cname)
1600         return
1601 }
1602 func (b Builder) CreateFPCast(val Value, t Type, name string) (v Value) {
1603         cname := C.CString(name)
1604         defer C.free(unsafe.Pointer(cname))
1605         v.C = C.LLVMBuildFPCast(b.C, val.C, t.C, cname)
1606         return
1607 }
1608
1609 // Comparisons
1610 func (b Builder) CreateICmp(pred IntPredicate, lhs, rhs Value, name string) (v Value) {
1611         cname := C.CString(name)
1612         defer C.free(unsafe.Pointer(cname))
1613         v.C = C.LLVMBuildICmp(b.C, C.LLVMIntPredicate(pred), lhs.C, rhs.C, cname)
1614         return
1615 }
1616 func (b Builder) CreateFCmp(pred FloatPredicate, lhs, rhs Value, name string) (v Value) {
1617         cname := C.CString(name)
1618         defer C.free(unsafe.Pointer(cname))
1619         v.C = C.LLVMBuildFCmp(b.C, C.LLVMRealPredicate(pred), lhs.C, rhs.C, cname)
1620         return
1621 }
1622
1623 // Miscellaneous instructions
1624 func (b Builder) CreatePHI(t Type, name string) (v Value) {
1625         cname := C.CString(name)
1626         defer C.free(unsafe.Pointer(cname))
1627         v.C = C.LLVMBuildPhi(b.C, t.C, cname)
1628         return
1629 }
1630 func (b Builder) CreateCall(fn Value, args []Value, name string) (v Value) {
1631         cname := C.CString(name)
1632         defer C.free(unsafe.Pointer(cname))
1633         ptr, nvals := llvmValueRefs(args)
1634         v.C = C.LLVMBuildCall(b.C, fn.C, ptr, nvals, cname)
1635         return
1636 }
1637
1638 func (b Builder) CreateSelect(ifv, thenv, elsev Value, name string) (v Value) {
1639         cname := C.CString(name)
1640         defer C.free(unsafe.Pointer(cname))
1641         v.C = C.LLVMBuildSelect(b.C, ifv.C, thenv.C, elsev.C, cname)
1642         return
1643 }
1644
1645 func (b Builder) CreateVAArg(list Value, t Type, name string) (v Value) {
1646         cname := C.CString(name)
1647         defer C.free(unsafe.Pointer(cname))
1648         v.C = C.LLVMBuildVAArg(b.C, list.C, t.C, cname)
1649         return
1650 }
1651 func (b Builder) CreateExtractElement(vec, i Value, name string) (v Value) {
1652         cname := C.CString(name)
1653         defer C.free(unsafe.Pointer(cname))
1654         v.C = C.LLVMBuildExtractElement(b.C, vec.C, i.C, cname)
1655         return
1656 }
1657 func (b Builder) CreateInsertElement(vec, elt, i Value, name string) (v Value) {
1658         cname := C.CString(name)
1659         defer C.free(unsafe.Pointer(cname))
1660         v.C = C.LLVMBuildInsertElement(b.C, vec.C, elt.C, i.C, cname)
1661         return
1662 }
1663 func (b Builder) CreateShuffleVector(v1, v2, mask Value, name string) (v Value) {
1664         cname := C.CString(name)
1665         defer C.free(unsafe.Pointer(cname))
1666         v.C = C.LLVMBuildShuffleVector(b.C, v1.C, v2.C, mask.C, cname)
1667         return
1668 }
1669 func (b Builder) CreateExtractValue(agg Value, i int, name string) (v Value) {
1670         cname := C.CString(name)
1671         defer C.free(unsafe.Pointer(cname))
1672         v.C = C.LLVMBuildExtractValue(b.C, agg.C, C.unsigned(i), cname)
1673         return
1674 }
1675 func (b Builder) CreateInsertValue(agg, elt Value, i int, name string) (v Value) {
1676         cname := C.CString(name)
1677         defer C.free(unsafe.Pointer(cname))
1678         v.C = C.LLVMBuildInsertValue(b.C, agg.C, elt.C, C.unsigned(i), cname)
1679         return
1680 }
1681
1682 func (b Builder) CreateIsNull(val Value, name string) (v Value) {
1683         cname := C.CString(name)
1684         defer C.free(unsafe.Pointer(cname))
1685         v.C = C.LLVMBuildIsNull(b.C, val.C, cname)
1686         return
1687 }
1688 func (b Builder) CreateIsNotNull(val Value, name string) (v Value) {
1689         cname := C.CString(name)
1690         defer C.free(unsafe.Pointer(cname))
1691         v.C = C.LLVMBuildIsNotNull(b.C, val.C, cname)
1692         return
1693 }
1694 func (b Builder) CreatePtrDiff(lhs, rhs Value, name string) (v Value) {
1695         cname := C.CString(name)
1696         defer C.free(unsafe.Pointer(cname))
1697         v.C = C.LLVMBuildPtrDiff(b.C, lhs.C, rhs.C, cname)
1698         return
1699 }
1700
1701 func (b Builder) CreateLandingPad(t Type, personality Value, nclauses int, name string) (l Value) {
1702         cname := C.CString(name)
1703         defer C.free(unsafe.Pointer(cname))
1704         l.C = C.LLVMBuildLandingPad(b.C, t.C, personality.C, C.unsigned(nclauses), cname)
1705         return l
1706 }
1707
1708 func (l Value) AddClause(v Value) {
1709         C.LLVMAddClause(l.C, v.C)
1710 }
1711
1712 func (l Value) SetCleanup(cleanup bool) {
1713         C.LLVMSetCleanup(l.C, boolToLLVMBool(cleanup))
1714 }
1715
1716 func (b Builder) CreateResume(ex Value) (v Value) {
1717         v.C = C.LLVMBuildResume(b.C, ex.C)
1718         return
1719 }
1720
1721 //-------------------------------------------------------------------------
1722 // llvm.ModuleProvider
1723 //-------------------------------------------------------------------------
1724
1725 // Changes the type of M so it can be passed to FunctionPassManagers and the
1726 // JIT. They take ModuleProviders for historical reasons.
1727 func NewModuleProviderForModule(m Module) (mp ModuleProvider) {
1728         mp.C = C.LLVMCreateModuleProviderForExistingModule(m.C)
1729         return
1730 }
1731
1732 // Destroys the module M.
1733 func (mp ModuleProvider) Dispose() { C.LLVMDisposeModuleProvider(mp.C) }
1734
1735 //-------------------------------------------------------------------------
1736 // llvm.MemoryBuffer
1737 //-------------------------------------------------------------------------
1738
1739 func NewMemoryBufferFromFile(path string) (b MemoryBuffer, err error) {
1740         var cmsg *C.char
1741         cpath := C.CString(path)
1742         defer C.free(unsafe.Pointer(cpath))
1743         fail := C.LLVMCreateMemoryBufferWithContentsOfFile(cpath, &b.C, &cmsg)
1744         if fail != 0 {
1745                 b.C = nil
1746                 err = errors.New(C.GoString(cmsg))
1747                 C.LLVMDisposeMessage(cmsg)
1748         }
1749         return
1750 }
1751
1752 func NewMemoryBufferFromStdin() (b MemoryBuffer, err error) {
1753         var cmsg *C.char
1754         fail := C.LLVMCreateMemoryBufferWithSTDIN(&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 (b MemoryBuffer) Bytes() []byte {
1764         cstart := C.LLVMGetBufferStart(b.C)
1765         csize := C.LLVMGetBufferSize(b.C)
1766         return C.GoBytes(unsafe.Pointer(cstart), C.int(csize))
1767 }
1768
1769 func (b MemoryBuffer) Dispose() { C.LLVMDisposeMemoryBuffer(b.C) }
1770
1771 //-------------------------------------------------------------------------
1772 // llvm.PassManager
1773 //-------------------------------------------------------------------------
1774
1775 // Constructs a new whole-module pass pipeline. This type of pipeline is
1776 // suitable for link-time optimization and whole-module transformations.
1777 // See llvm::PassManager::PassManager.
1778 func NewPassManager() (pm PassManager) { pm.C = C.LLVMCreatePassManager(); return }
1779
1780 // Constructs a new function-by-function pass pipeline over the module
1781 // provider. It does not take ownership of the module provider. This type of
1782 // pipeline is suitable for code generation and JIT compilation tasks.
1783 // See llvm::FunctionPassManager::FunctionPassManager.
1784 func NewFunctionPassManagerForModule(m Module) (pm PassManager) {
1785         pm.C = C.LLVMCreateFunctionPassManagerForModule(m.C)
1786         return
1787 }
1788
1789 // Initializes, executes on the provided module, and finalizes all of the
1790 // passes scheduled in the pass manager. Returns 1 if any of the passes
1791 // modified the module, 0 otherwise. See llvm::PassManager::run(Module&).
1792 func (pm PassManager) Run(m Module) bool { return C.LLVMRunPassManager(pm.C, m.C) != 0 }
1793
1794 // Initializes all of the function passes scheduled in the function pass
1795 // manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1796 // See llvm::FunctionPassManager::doInitialization.
1797 func (pm PassManager) InitializeFunc() bool { return C.LLVMInitializeFunctionPassManager(pm.C) != 0 }
1798
1799 // Executes all of the function passes scheduled in the function pass manager
1800 // on the provided function. Returns 1 if any of the passes modified the
1801 // function, false otherwise.
1802 // See llvm::FunctionPassManager::run(Function&).
1803 func (pm PassManager) RunFunc(f Value) bool { return C.LLVMRunFunctionPassManager(pm.C, f.C) != 0 }
1804
1805 // Finalizes all of the function passes scheduled in in the function pass
1806 // manager. Returns 1 if any of the passes modified the module, 0 otherwise.
1807 // See llvm::FunctionPassManager::doFinalization.
1808 func (pm PassManager) FinalizeFunc() bool { return C.LLVMFinalizeFunctionPassManager(pm.C) != 0 }
1809
1810 // Frees the memory of a pass pipeline. For function pipelines, does not free
1811 // the module provider.
1812 // See llvm::PassManagerBase::~PassManagerBase.
1813 func (pm PassManager) Dispose() { C.LLVMDisposePassManager(pm.C) }