-
Notifications
You must be signed in to change notification settings - Fork 46
/
ir.go
2075 lines (1906 loc) · 76.4 KB
/
ir.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//===- ir.go - Bindings for ir --------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines bindings for the ir component.
//
//===----------------------------------------------------------------------===//
package llvm
/*
#include "llvm-c/Core.h"
#include "llvm-c/Comdat.h"
#include "IRBindings.h"
#include <stdlib.h>
*/
import "C"
import (
"errors"
"unsafe"
)
type (
// We use these weird structs here because *Ref types are pointers and
// Go's spec says that a pointer cannot be used as a receiver base type.
Context struct {
C C.LLVMContextRef
}
Module struct {
C C.LLVMModuleRef
}
Type struct {
C C.LLVMTypeRef
}
Value struct {
C C.LLVMValueRef
}
Comdat struct {
C C.LLVMComdatRef
}
BasicBlock struct {
C C.LLVMBasicBlockRef
}
Builder struct {
C C.LLVMBuilderRef
}
ModuleProvider struct {
C C.LLVMModuleProviderRef
}
MemoryBuffer struct {
C C.LLVMMemoryBufferRef
}
PassManager struct {
C C.LLVMPassManagerRef
}
Use struct {
C C.LLVMUseRef
}
Metadata struct {
C C.LLVMMetadataRef
}
Attribute struct {
C C.LLVMAttributeRef
}
Opcode C.LLVMOpcode
AtomicRMWBinOp C.LLVMAtomicRMWBinOp
AtomicOrdering C.LLVMAtomicOrdering
TypeKind C.LLVMTypeKind
Linkage C.LLVMLinkage
Visibility C.LLVMVisibility
CallConv C.LLVMCallConv
ComdatSelectionKind C.LLVMComdatSelectionKind
IntPredicate C.LLVMIntPredicate
FloatPredicate C.LLVMRealPredicate
LandingPadClause C.LLVMLandingPadClauseTy
InlineAsmDialect C.LLVMInlineAsmDialect
)
func (c Context) IsNil() bool { return c.C == nil }
func (c Module) IsNil() bool { return c.C == nil }
func (c Type) IsNil() bool { return c.C == nil }
func (c Value) IsNil() bool { return c.C == nil }
func (c BasicBlock) IsNil() bool { return c.C == nil }
func (c Builder) IsNil() bool { return c.C == nil }
func (c ModuleProvider) IsNil() bool { return c.C == nil }
func (c MemoryBuffer) IsNil() bool { return c.C == nil }
func (c PassManager) IsNil() bool { return c.C == nil }
func (c Use) IsNil() bool { return c.C == nil }
func (c Attribute) IsNil() bool { return c.C == nil }
func (c Metadata) IsNil() bool { return c.C == nil }
// helpers
func llvmTypeRefPtr(t *Type) *C.LLVMTypeRef { return (*C.LLVMTypeRef)(unsafe.Pointer(t)) }
func llvmValueRefPtr(t *Value) *C.LLVMValueRef { return (*C.LLVMValueRef)(unsafe.Pointer(t)) }
func llvmMetadataRefPtr(t *Metadata) *C.LLVMMetadataRef {
return (*C.LLVMMetadataRef)(unsafe.Pointer(t))
}
func llvmBasicBlockRefPtr(t *BasicBlock) *C.LLVMBasicBlockRef {
return (*C.LLVMBasicBlockRef)(unsafe.Pointer(t))
}
func boolToLLVMBool(b bool) C.LLVMBool {
if b {
return C.LLVMBool(1)
}
return C.LLVMBool(0)
}
func llvmValueRefs(values []Value) (*C.LLVMValueRef, C.unsigned) {
var pt *C.LLVMValueRef
ptlen := C.unsigned(len(values))
if ptlen > 0 {
pt = llvmValueRefPtr(&values[0])
}
return pt, ptlen
}
func llvmMetadataRefs(mds []Metadata) (*C.LLVMMetadataRef, C.unsigned) {
var pt *C.LLVMMetadataRef
ptlen := C.unsigned(len(mds))
if ptlen > 0 {
pt = llvmMetadataRefPtr(&mds[0])
}
return pt, ptlen
}
//-------------------------------------------------------------------------
// llvm.Opcode
//-------------------------------------------------------------------------
const (
Ret Opcode = C.LLVMRet
Br Opcode = C.LLVMBr
Switch Opcode = C.LLVMSwitch
IndirectBr Opcode = C.LLVMIndirectBr
Invoke Opcode = C.LLVMInvoke
Unreachable Opcode = C.LLVMUnreachable
// Standard Binary Operators
Add Opcode = C.LLVMAdd
FAdd Opcode = C.LLVMFAdd
Sub Opcode = C.LLVMSub
FSub Opcode = C.LLVMFSub
Mul Opcode = C.LLVMMul
FMul Opcode = C.LLVMFMul
UDiv Opcode = C.LLVMUDiv
SDiv Opcode = C.LLVMSDiv
FDiv Opcode = C.LLVMFDiv
URem Opcode = C.LLVMURem
SRem Opcode = C.LLVMSRem
FRem Opcode = C.LLVMFRem
// Logical Operators
Shl Opcode = C.LLVMShl
LShr Opcode = C.LLVMLShr
AShr Opcode = C.LLVMAShr
And Opcode = C.LLVMAnd
Or Opcode = C.LLVMOr
Xor Opcode = C.LLVMXor
// Memory Operators
Alloca Opcode = C.LLVMAlloca
Load Opcode = C.LLVMLoad
Store Opcode = C.LLVMStore
GetElementPtr Opcode = C.LLVMGetElementPtr
// Cast Operators
Trunc Opcode = C.LLVMTrunc
ZExt Opcode = C.LLVMZExt
SExt Opcode = C.LLVMSExt
FPToUI Opcode = C.LLVMFPToUI
FPToSI Opcode = C.LLVMFPToSI
UIToFP Opcode = C.LLVMUIToFP
SIToFP Opcode = C.LLVMSIToFP
FPTrunc Opcode = C.LLVMFPTrunc
FPExt Opcode = C.LLVMFPExt
PtrToInt Opcode = C.LLVMPtrToInt
IntToPtr Opcode = C.LLVMIntToPtr
BitCast Opcode = C.LLVMBitCast
// Other Operators
ICmp Opcode = C.LLVMICmp
FCmp Opcode = C.LLVMFCmp
PHI Opcode = C.LLVMPHI
Call Opcode = C.LLVMCall
Select Opcode = C.LLVMSelect
// UserOp1
// UserOp2
VAArg Opcode = C.LLVMVAArg
ExtractElement Opcode = C.LLVMExtractElement
InsertElement Opcode = C.LLVMInsertElement
ShuffleVector Opcode = C.LLVMShuffleVector
ExtractValue Opcode = C.LLVMExtractValue
InsertValue Opcode = C.LLVMInsertValue
// Exception Handling Operators
Resume Opcode = C.LLVMResume
LandingPad Opcode = C.LLVMLandingPad
CleanupRet Opcode = C.LLVMCleanupRet
CatchRet Opcode = C.LLVMCatchRet
CatchPad Opcode = C.LLVMCatchPad
CleanupPad Opcode = C.LLVMCleanupPad
CatchSwitch Opcode = C.LLVMCatchSwitch
)
const (
AtomicRMWBinOpXchg AtomicRMWBinOp = C.LLVMAtomicRMWBinOpXchg
AtomicRMWBinOpAdd AtomicRMWBinOp = C.LLVMAtomicRMWBinOpAdd
AtomicRMWBinOpSub AtomicRMWBinOp = C.LLVMAtomicRMWBinOpSub
AtomicRMWBinOpAnd AtomicRMWBinOp = C.LLVMAtomicRMWBinOpAnd
AtomicRMWBinOpNand AtomicRMWBinOp = C.LLVMAtomicRMWBinOpNand
AtomicRMWBinOpOr AtomicRMWBinOp = C.LLVMAtomicRMWBinOpOr
AtomicRMWBinOpXor AtomicRMWBinOp = C.LLVMAtomicRMWBinOpXor
AtomicRMWBinOpMax AtomicRMWBinOp = C.LLVMAtomicRMWBinOpMax
AtomicRMWBinOpMin AtomicRMWBinOp = C.LLVMAtomicRMWBinOpMin
AtomicRMWBinOpUMax AtomicRMWBinOp = C.LLVMAtomicRMWBinOpUMax
AtomicRMWBinOpUMin AtomicRMWBinOp = C.LLVMAtomicRMWBinOpUMin
)
const (
AtomicOrderingNotAtomic AtomicOrdering = C.LLVMAtomicOrderingNotAtomic
AtomicOrderingUnordered AtomicOrdering = C.LLVMAtomicOrderingUnordered
AtomicOrderingMonotonic AtomicOrdering = C.LLVMAtomicOrderingMonotonic
AtomicOrderingAcquire AtomicOrdering = C.LLVMAtomicOrderingAcquire
AtomicOrderingRelease AtomicOrdering = C.LLVMAtomicOrderingRelease
AtomicOrderingAcquireRelease AtomicOrdering = C.LLVMAtomicOrderingAcquireRelease
AtomicOrderingSequentiallyConsistent AtomicOrdering = C.LLVMAtomicOrderingSequentiallyConsistent
)
//-------------------------------------------------------------------------
// llvm.TypeKind
//-------------------------------------------------------------------------
const (
VoidTypeKind TypeKind = C.LLVMVoidTypeKind
FloatTypeKind TypeKind = C.LLVMFloatTypeKind
DoubleTypeKind TypeKind = C.LLVMDoubleTypeKind
X86_FP80TypeKind TypeKind = C.LLVMX86_FP80TypeKind
FP128TypeKind TypeKind = C.LLVMFP128TypeKind
PPC_FP128TypeKind TypeKind = C.LLVMPPC_FP128TypeKind
LabelTypeKind TypeKind = C.LLVMLabelTypeKind
IntegerTypeKind TypeKind = C.LLVMIntegerTypeKind
FunctionTypeKind TypeKind = C.LLVMFunctionTypeKind
StructTypeKind TypeKind = C.LLVMStructTypeKind
ArrayTypeKind TypeKind = C.LLVMArrayTypeKind
PointerTypeKind TypeKind = C.LLVMPointerTypeKind
VectorTypeKind TypeKind = C.LLVMVectorTypeKind
MetadataTypeKind TypeKind = C.LLVMMetadataTypeKind
TokenTypeKind TypeKind = C.LLVMTokenTypeKind
)
//-------------------------------------------------------------------------
// llvm.Linkage
//-------------------------------------------------------------------------
const (
ExternalLinkage Linkage = C.LLVMExternalLinkage
AvailableExternallyLinkage Linkage = C.LLVMAvailableExternallyLinkage
LinkOnceAnyLinkage Linkage = C.LLVMLinkOnceAnyLinkage
LinkOnceODRLinkage Linkage = C.LLVMLinkOnceODRLinkage
WeakAnyLinkage Linkage = C.LLVMWeakAnyLinkage
WeakODRLinkage Linkage = C.LLVMWeakODRLinkage
AppendingLinkage Linkage = C.LLVMAppendingLinkage
InternalLinkage Linkage = C.LLVMInternalLinkage
PrivateLinkage Linkage = C.LLVMPrivateLinkage
ExternalWeakLinkage Linkage = C.LLVMExternalWeakLinkage
CommonLinkage Linkage = C.LLVMCommonLinkage
)
//-------------------------------------------------------------------------
// llvm.Visibility
//-------------------------------------------------------------------------
const (
DefaultVisibility Visibility = C.LLVMDefaultVisibility
HiddenVisibility Visibility = C.LLVMHiddenVisibility
ProtectedVisibility Visibility = C.LLVMProtectedVisibility
)
//-------------------------------------------------------------------------
// llvm.CallConv
//-------------------------------------------------------------------------
const (
CCallConv CallConv = C.LLVMCCallConv
FastCallConv CallConv = C.LLVMFastCallConv
ColdCallConv CallConv = C.LLVMColdCallConv
X86StdcallCallConv CallConv = C.LLVMX86StdcallCallConv
X86FastcallCallConv CallConv = C.LLVMX86FastcallCallConv
)
//-------------------------------------------------------------------------
// llvm.ComdatSelectionKind
//-------------------------------------------------------------------------
const (
AnyComdatSelectionKind ComdatSelectionKind = C.LLVMAnyComdatSelectionKind
ExactMatchComdatSelectionKind ComdatSelectionKind = C.LLVMExactMatchComdatSelectionKind
LargestComdatSelectionKind ComdatSelectionKind = C.LLVMLargestComdatSelectionKind
NoDeduplicateComdatSelectionKind ComdatSelectionKind = C.LLVMNoDeduplicateComdatSelectionKind
SameSizeComdatSelectionKind ComdatSelectionKind = C.LLVMSameSizeComdatSelectionKind
)
//-------------------------------------------------------------------------
// llvm.IntPredicate
//-------------------------------------------------------------------------
const (
IntEQ IntPredicate = C.LLVMIntEQ
IntNE IntPredicate = C.LLVMIntNE
IntUGT IntPredicate = C.LLVMIntUGT
IntUGE IntPredicate = C.LLVMIntUGE
IntULT IntPredicate = C.LLVMIntULT
IntULE IntPredicate = C.LLVMIntULE
IntSGT IntPredicate = C.LLVMIntSGT
IntSGE IntPredicate = C.LLVMIntSGE
IntSLT IntPredicate = C.LLVMIntSLT
IntSLE IntPredicate = C.LLVMIntSLE
)
//-------------------------------------------------------------------------
// llvm.FloatPredicate
//-------------------------------------------------------------------------
const (
FloatPredicateFalse FloatPredicate = C.LLVMRealPredicateFalse
FloatOEQ FloatPredicate = C.LLVMRealOEQ
FloatOGT FloatPredicate = C.LLVMRealOGT
FloatOGE FloatPredicate = C.LLVMRealOGE
FloatOLT FloatPredicate = C.LLVMRealOLT
FloatOLE FloatPredicate = C.LLVMRealOLE
FloatONE FloatPredicate = C.LLVMRealONE
FloatORD FloatPredicate = C.LLVMRealORD
FloatUNO FloatPredicate = C.LLVMRealUNO
FloatUEQ FloatPredicate = C.LLVMRealUEQ
FloatUGT FloatPredicate = C.LLVMRealUGT
FloatUGE FloatPredicate = C.LLVMRealUGE
FloatULT FloatPredicate = C.LLVMRealULT
FloatULE FloatPredicate = C.LLVMRealULE
FloatUNE FloatPredicate = C.LLVMRealUNE
FloatPredicateTrue FloatPredicate = C.LLVMRealPredicateTrue
)
//-------------------------------------------------------------------------
// llvm.LandingPadClause
//-------------------------------------------------------------------------
const (
LandingPadCatch LandingPadClause = C.LLVMLandingPadCatch
LandingPadFilter LandingPadClause = C.LLVMLandingPadFilter
)
//-------------------------------------------------------------------------
// llvm.InlineAsmDialect
//-------------------------------------------------------------------------
const (
InlineAsmDialectATT InlineAsmDialect = C.LLVMInlineAsmDialectATT
InlineAsmDialectIntel InlineAsmDialect = C.LLVMInlineAsmDialectIntel
)
//-------------------------------------------------------------------------
// llvm.Context
//-------------------------------------------------------------------------
func NewContext() Context { return Context{C.LLVMContextCreate()} }
func GlobalContext() Context { return Context{C.LLVMGetGlobalContext()} }
func (c Context) Dispose() { C.LLVMContextDispose(c.C) }
func (c Context) MDKindID(name string) (id int) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
id = int(C.LLVMGetMDKindIDInContext(c.C, cname, C.unsigned(len(name))))
return
}
func MDKindID(name string) (id int) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
id = int(C.LLVMGetMDKindID(cname, C.unsigned(len(name))))
return
}
//-------------------------------------------------------------------------
// llvm.Attribute
//-------------------------------------------------------------------------
func AttributeKindID(name string) (id uint) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
id = uint(C.LLVMGetEnumAttributeKindForName(cname, C.size_t(len(name))))
return
}
func (c Context) CreateEnumAttribute(kind uint, val uint64) (a Attribute) {
a.C = C.LLVMCreateEnumAttribute(c.C, C.unsigned(kind), C.uint64_t(val))
return
}
func (c Context) CreateTypeAttribute(kind uint, t Type) (a Attribute) {
a.C = C.LLVMCreateTypeAttribute(c.C, C.unsigned(kind), t.C)
return
}
func (a Attribute) GetTypeValue() (t Type) {
t.C = C.LLVMGetTypeAttributeValue(a.C)
return
}
func (a Attribute) GetEnumKind() (id int) {
id = int(C.LLVMGetEnumAttributeKind(a.C))
return
}
func (a Attribute) GetEnumValue() (val uint64) {
val = uint64(C.LLVMGetEnumAttributeValue(a.C))
return
}
func (c Context) CreateStringAttribute(kind string, val string) (a Attribute) {
ckind := C.CString(kind)
defer C.free(unsafe.Pointer(ckind))
cval := C.CString(val)
defer C.free(unsafe.Pointer(cval))
a.C = C.LLVMCreateStringAttribute(c.C,
ckind, C.unsigned(len(kind)),
cval, C.unsigned(len(val)))
return
}
func (a Attribute) GetStringKind() string {
length := C.unsigned(0)
ckind := C.LLVMGetStringAttributeKind(a.C, &length)
return C.GoStringN(ckind, C.int(length))
}
func (a Attribute) GetStringValue() string {
length := C.unsigned(0)
ckind := C.LLVMGetStringAttributeValue(a.C, &length)
return C.GoStringN(ckind, C.int(length))
}
func (a Attribute) IsEnum() bool {
return C.LLVMIsEnumAttribute(a.C) != 0
}
func (a Attribute) IsString() bool {
return C.LLVMIsStringAttribute(a.C) != 0
}
//-------------------------------------------------------------------------
// llvm.Module
//-------------------------------------------------------------------------
// Create and destroy modules.
// See llvm::Module::Module.
func (c Context) NewModule(name string) (m Module) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
m.C = C.LLVMModuleCreateWithNameInContext(cname, c.C)
return
}
// See llvm::Module::~Module
func (m Module) Dispose() { C.LLVMDisposeModule(m.C) }
// Data layout. See Module::getDataLayout.
func (m Module) DataLayout() string {
clayout := C.LLVMGetDataLayout(m.C)
return C.GoString(clayout)
}
func (m Module) SetDataLayout(layout string) {
clayout := C.CString(layout)
defer C.free(unsafe.Pointer(clayout))
C.LLVMSetDataLayout(m.C, clayout)
}
// Target triple. See Module::getTargetTriple.
func (m Module) Target() string {
ctarget := C.LLVMGetTarget(m.C)
return C.GoString(ctarget)
}
func (m Module) SetTarget(target string) {
ctarget := C.CString(target)
defer C.free(unsafe.Pointer(ctarget))
C.LLVMSetTarget(m.C, ctarget)
}
func (m Module) GetTypeByName(name string) (t Type) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
t.C = C.LLVMGetTypeByName(m.C, cname)
return
}
// See Module::dump.
func (m Module) Dump() {
C.LLVMDumpModule(m.C)
}
func (m Module) String() string {
cir := C.LLVMPrintModuleToString(m.C)
defer C.LLVMDisposeMessage(cir)
ir := C.GoString(cir)
return ir
}
// See Module::setModuleInlineAsm.
func (m Module) SetInlineAsm(asm string) {
casm := C.CString(asm)
defer C.free(unsafe.Pointer(casm))
C.LLVMSetModuleInlineAsm(m.C, casm)
}
func (m Module) AddNamedMetadataOperand(name string, operand Metadata) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
C.LLVMAddNamedMetadataOperand2(m.C, cname, operand.C)
}
func (m Module) Context() (c Context) {
c.C = C.LLVMGetModuleContext(m.C)
return
}
//-------------------------------------------------------------------------
// llvm.Type
//-------------------------------------------------------------------------
// LLVM types conform to the following hierarchy:
//
// types:
// integer type
// real type
// function type
// sequence types:
// array type
// pointer type
// vector type
// void type
// label type
// opaque type
// See llvm::LLVMTypeKind::getTypeID.
func (t Type) TypeKind() TypeKind { return TypeKind(C.LLVMGetTypeKind(t.C)) }
// See llvm::LLVMType::getContext.
func (t Type) Context() (c Context) {
c.C = C.LLVMGetTypeContext(t.C)
return
}
// Operations on integer types
func (c Context) Int1Type() (t Type) { t.C = C.LLVMInt1TypeInContext(c.C); return }
func (c Context) Int8Type() (t Type) { t.C = C.LLVMInt8TypeInContext(c.C); return }
func (c Context) Int16Type() (t Type) { t.C = C.LLVMInt16TypeInContext(c.C); return }
func (c Context) Int32Type() (t Type) { t.C = C.LLVMInt32TypeInContext(c.C); return }
func (c Context) Int64Type() (t Type) { t.C = C.LLVMInt64TypeInContext(c.C); return }
func (c Context) IntType(numbits int) (t Type) {
t.C = C.LLVMIntTypeInContext(c.C, C.unsigned(numbits))
return
}
func (t Type) IntTypeWidth() int {
return int(C.LLVMGetIntTypeWidth(t.C))
}
// Operations on real types
func (c Context) FloatType() (t Type) { t.C = C.LLVMFloatTypeInContext(c.C); return }
func (c Context) DoubleType() (t Type) { t.C = C.LLVMDoubleTypeInContext(c.C); return }
func (c Context) X86FP80Type() (t Type) { t.C = C.LLVMX86FP80TypeInContext(c.C); return }
func (c Context) FP128Type() (t Type) { t.C = C.LLVMFP128TypeInContext(c.C); return }
func (c Context) PPCFP128Type() (t Type) { t.C = C.LLVMPPCFP128TypeInContext(c.C); return }
// Operations on function types
func FunctionType(returnType Type, paramTypes []Type, isVarArg bool) (t Type) {
var pt *C.LLVMTypeRef
var ptlen C.unsigned
if len(paramTypes) > 0 {
pt = llvmTypeRefPtr(¶mTypes[0])
ptlen = C.unsigned(len(paramTypes))
}
t.C = C.LLVMFunctionType(returnType.C,
pt,
ptlen,
boolToLLVMBool(isVarArg))
return
}
func (t Type) IsFunctionVarArg() bool { return C.LLVMIsFunctionVarArg(t.C) != 0 }
func (t Type) ReturnType() (rt Type) { rt.C = C.LLVMGetReturnType(t.C); return }
func (t Type) ParamTypesCount() int { return int(C.LLVMCountParamTypes(t.C)) }
func (t Type) ParamTypes() []Type {
count := t.ParamTypesCount()
if count > 0 {
out := make([]Type, count)
C.LLVMGetParamTypes(t.C, llvmTypeRefPtr(&out[0]))
return out
}
return nil
}
// Operations on struct types
func (c Context) StructType(elementTypes []Type, packed bool) (t Type) {
var pt *C.LLVMTypeRef
var ptlen C.unsigned
if len(elementTypes) > 0 {
pt = llvmTypeRefPtr(&elementTypes[0])
ptlen = C.unsigned(len(elementTypes))
}
t.C = C.LLVMStructTypeInContext(c.C,
pt,
ptlen,
boolToLLVMBool(packed))
return
}
func StructType(elementTypes []Type, packed bool) (t Type) {
var pt *C.LLVMTypeRef
var ptlen C.unsigned
if len(elementTypes) > 0 {
pt = llvmTypeRefPtr(&elementTypes[0])
ptlen = C.unsigned(len(elementTypes))
}
t.C = C.LLVMStructType(pt, ptlen, boolToLLVMBool(packed))
return
}
func (c Context) StructCreateNamed(name string) (t Type) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
t.C = C.LLVMStructCreateNamed(c.C, cname)
return
}
func (t Type) StructName() string {
return C.GoString(C.LLVMGetStructName(t.C))
}
func (t Type) StructSetBody(elementTypes []Type, packed bool) {
var pt *C.LLVMTypeRef
var ptlen C.unsigned
if len(elementTypes) > 0 {
pt = llvmTypeRefPtr(&elementTypes[0])
ptlen = C.unsigned(len(elementTypes))
}
C.LLVMStructSetBody(t.C, pt, ptlen, boolToLLVMBool(packed))
}
func (t Type) IsStructPacked() bool { return C.LLVMIsPackedStruct(t.C) != 0 }
func (t Type) StructElementTypesCount() int { return int(C.LLVMCountStructElementTypes(t.C)) }
func (t Type) StructElementTypes() []Type {
out := make([]Type, t.StructElementTypesCount())
if len(out) > 0 {
C.LLVMGetStructElementTypes(t.C, llvmTypeRefPtr(&out[0]))
}
return out
}
// Operations on array, pointer, and vector types (sequence types)
func (t Type) Subtypes() (ret []Type) {
ret = make([]Type, C.LLVMGetNumContainedTypes(t.C))
C.LLVMGetSubtypes(t.C, llvmTypeRefPtr(&ret[0]))
return
}
func ArrayType(elementType Type, elementCount int) (t Type) {
t.C = C.LLVMArrayType(elementType.C, C.unsigned(elementCount))
return
}
func PointerType(elementType Type, addressSpace int) (t Type) {
t.C = C.LLVMPointerType(elementType.C, C.unsigned(addressSpace))
return
}
func VectorType(elementType Type, elementCount int) (t Type) {
t.C = C.LLVMVectorType(elementType.C, C.unsigned(elementCount))
return
}
func (t Type) ElementType() (rt Type) { rt.C = C.LLVMGetElementType(t.C); return }
func (t Type) ArrayLength() int { return int(C.LLVMGetArrayLength(t.C)) }
func (t Type) PointerAddressSpace() int { return int(C.LLVMGetPointerAddressSpace(t.C)) }
func (t Type) VectorSize() int { return int(C.LLVMGetVectorSize(t.C)) }
// Operations on other types
func (c Context) VoidType() (t Type) { t.C = C.LLVMVoidTypeInContext(c.C); return }
func (c Context) LabelType() (t Type) { t.C = C.LLVMLabelTypeInContext(c.C); return }
func (c Context) TokenType() (t Type) { t.C = C.LLVMTokenTypeInContext(c.C); return }
//-------------------------------------------------------------------------
// llvm.Value
//-------------------------------------------------------------------------
// Operations on all values
func (v Value) Type() (t Type) { t.C = C.LLVMTypeOf(v.C); return }
func (v Value) Name() string { return C.GoString(C.LLVMGetValueName(v.C)) }
func (v Value) SetName(name string) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
C.LLVMSetValueName(v.C, cname)
}
func (v Value) Dump() { C.LLVMDumpValue(v.C) }
func (v Value) ReplaceAllUsesWith(nv Value) { C.LLVMReplaceAllUsesWith(v.C, nv.C) }
func (v Value) HasMetadata() bool { return C.LLVMHasMetadata(v.C) != 0 }
func (v Value) Metadata(kind int) (rv Value) {
rv.C = C.LLVMGetMetadata(v.C, C.unsigned(kind))
return
}
func (v Value) SetMetadata(kind int, node Metadata) {
C.LLVMSetMetadata2(v.C, C.unsigned(kind), node.C)
}
// Obtain the string value of the instruction. Same as would be printed with
// Value.Dump() (with two spaces at the start but no newline at the end).
func (v Value) String() string {
cstr := C.LLVMPrintValueToString(v.C)
defer C.LLVMDisposeMessage(cstr)
return C.GoString(cstr)
}
// Conversion functions.
// Return the input value if it is an instance of the specified class, otherwise NULL.
// See llvm::dyn_cast_or_null<>.
func (v Value) IsAArgument() (rv Value) { rv.C = C.LLVMIsAArgument(v.C); return }
func (v Value) IsABasicBlock() (rv Value) { rv.C = C.LLVMIsABasicBlock(v.C); return }
func (v Value) IsAInlineAsm() (rv Value) { rv.C = C.LLVMIsAInlineAsm(v.C); return }
func (v Value) IsAUser() (rv Value) { rv.C = C.LLVMIsAUser(v.C); return }
func (v Value) IsAConstant() (rv Value) { rv.C = C.LLVMIsAConstant(v.C); return }
func (v Value) IsAConstantAggregateZero() (rv Value) {
rv.C = C.LLVMIsAConstantAggregateZero(v.C)
return
}
func (v Value) IsAConstantArray() (rv Value) { rv.C = C.LLVMIsAConstantArray(v.C); return }
func (v Value) IsAConstantExpr() (rv Value) { rv.C = C.LLVMIsAConstantExpr(v.C); return }
func (v Value) IsAConstantFP() (rv Value) { rv.C = C.LLVMIsAConstantFP(v.C); return }
func (v Value) IsAConstantInt() (rv Value) { rv.C = C.LLVMIsAConstantInt(v.C); return }
func (v Value) IsAConstantPointerNull() (rv Value) { rv.C = C.LLVMIsAConstantPointerNull(v.C); return }
func (v Value) IsAConstantStruct() (rv Value) { rv.C = C.LLVMIsAConstantStruct(v.C); return }
func (v Value) IsAConstantVector() (rv Value) { rv.C = C.LLVMIsAConstantVector(v.C); return }
func (v Value) IsAGlobalValue() (rv Value) { rv.C = C.LLVMIsAGlobalValue(v.C); return }
func (v Value) IsAFunction() (rv Value) { rv.C = C.LLVMIsAFunction(v.C); return }
func (v Value) IsAGlobalAlias() (rv Value) { rv.C = C.LLVMIsAGlobalAlias(v.C); return }
func (v Value) IsAGlobalVariable() (rv Value) { rv.C = C.LLVMIsAGlobalVariable(v.C); return }
func (v Value) IsAUndefValue() (rv Value) { rv.C = C.LLVMIsAUndefValue(v.C); return }
func (v Value) IsAInstruction() (rv Value) { rv.C = C.LLVMIsAInstruction(v.C); return }
func (v Value) IsABinaryOperator() (rv Value) { rv.C = C.LLVMIsABinaryOperator(v.C); return }
func (v Value) IsACallInst() (rv Value) { rv.C = C.LLVMIsACallInst(v.C); return }
func (v Value) IsAIntrinsicInst() (rv Value) { rv.C = C.LLVMIsAIntrinsicInst(v.C); return }
func (v Value) IsADbgInfoIntrinsic() (rv Value) { rv.C = C.LLVMIsADbgInfoIntrinsic(v.C); return }
func (v Value) IsADbgDeclareInst() (rv Value) { rv.C = C.LLVMIsADbgDeclareInst(v.C); return }
func (v Value) IsAMemIntrinsic() (rv Value) { rv.C = C.LLVMIsAMemIntrinsic(v.C); return }
func (v Value) IsAMemCpyInst() (rv Value) { rv.C = C.LLVMIsAMemCpyInst(v.C); return }
func (v Value) IsAMemMoveInst() (rv Value) { rv.C = C.LLVMIsAMemMoveInst(v.C); return }
func (v Value) IsAMemSetInst() (rv Value) { rv.C = C.LLVMIsAMemSetInst(v.C); return }
func (v Value) IsACmpInst() (rv Value) { rv.C = C.LLVMIsACmpInst(v.C); return }
func (v Value) IsAFCmpInst() (rv Value) { rv.C = C.LLVMIsAFCmpInst(v.C); return }
func (v Value) IsAICmpInst() (rv Value) { rv.C = C.LLVMIsAICmpInst(v.C); return }
func (v Value) IsAExtractElementInst() (rv Value) { rv.C = C.LLVMIsAExtractElementInst(v.C); return }
func (v Value) IsAGetElementPtrInst() (rv Value) { rv.C = C.LLVMIsAGetElementPtrInst(v.C); return }
func (v Value) IsAInsertElementInst() (rv Value) { rv.C = C.LLVMIsAInsertElementInst(v.C); return }
func (v Value) IsAInsertValueInst() (rv Value) { rv.C = C.LLVMIsAInsertValueInst(v.C); return }
func (v Value) IsAPHINode() (rv Value) { rv.C = C.LLVMIsAPHINode(v.C); return }
func (v Value) IsASelectInst() (rv Value) { rv.C = C.LLVMIsASelectInst(v.C); return }
func (v Value) IsAShuffleVectorInst() (rv Value) { rv.C = C.LLVMIsAShuffleVectorInst(v.C); return }
func (v Value) IsAStoreInst() (rv Value) { rv.C = C.LLVMIsAStoreInst(v.C); return }
func (v Value) IsABranchInst() (rv Value) { rv.C = C.LLVMIsABranchInst(v.C); return }
func (v Value) IsAInvokeInst() (rv Value) { rv.C = C.LLVMIsAInvokeInst(v.C); return }
func (v Value) IsAReturnInst() (rv Value) { rv.C = C.LLVMIsAReturnInst(v.C); return }
func (v Value) IsASwitchInst() (rv Value) { rv.C = C.LLVMIsASwitchInst(v.C); return }
func (v Value) IsAUnreachableInst() (rv Value) { rv.C = C.LLVMIsAUnreachableInst(v.C); return }
func (v Value) IsAUnaryInstruction() (rv Value) { rv.C = C.LLVMIsAUnaryInstruction(v.C); return }
func (v Value) IsAAllocaInst() (rv Value) { rv.C = C.LLVMIsAAllocaInst(v.C); return }
func (v Value) IsACastInst() (rv Value) { rv.C = C.LLVMIsACastInst(v.C); return }
func (v Value) IsABitCastInst() (rv Value) { rv.C = C.LLVMIsABitCastInst(v.C); return }
func (v Value) IsAFPExtInst() (rv Value) { rv.C = C.LLVMIsAFPExtInst(v.C); return }
func (v Value) IsAFPToSIInst() (rv Value) { rv.C = C.LLVMIsAFPToSIInst(v.C); return }
func (v Value) IsAFPToUIInst() (rv Value) { rv.C = C.LLVMIsAFPToUIInst(v.C); return }
func (v Value) IsAFPTruncInst() (rv Value) { rv.C = C.LLVMIsAFPTruncInst(v.C); return }
func (v Value) IsAIntToPtrInst() (rv Value) { rv.C = C.LLVMIsAIntToPtrInst(v.C); return }
func (v Value) IsAPtrToIntInst() (rv Value) { rv.C = C.LLVMIsAPtrToIntInst(v.C); return }
func (v Value) IsASExtInst() (rv Value) { rv.C = C.LLVMIsASExtInst(v.C); return }
func (v Value) IsASIToFPInst() (rv Value) { rv.C = C.LLVMIsASIToFPInst(v.C); return }
func (v Value) IsATruncInst() (rv Value) { rv.C = C.LLVMIsATruncInst(v.C); return }
func (v Value) IsAUIToFPInst() (rv Value) { rv.C = C.LLVMIsAUIToFPInst(v.C); return }
func (v Value) IsAZExtInst() (rv Value) { rv.C = C.LLVMIsAZExtInst(v.C); return }
func (v Value) IsAExtractValueInst() (rv Value) { rv.C = C.LLVMIsAExtractValueInst(v.C); return }
func (v Value) IsALoadInst() (rv Value) { rv.C = C.LLVMIsALoadInst(v.C); return }
func (v Value) IsAVAArgInst() (rv Value) { rv.C = C.LLVMIsAVAArgInst(v.C); return }
// Operations on Uses
func (v Value) FirstUse() (u Use) { u.C = C.LLVMGetFirstUse(v.C); return }
func (u Use) NextUse() (ru Use) { ru.C = C.LLVMGetNextUse(u.C); return }
func (u Use) User() (v Value) { v.C = C.LLVMGetUser(u.C); return }
func (u Use) UsedValue() (v Value) { v.C = C.LLVMGetUsedValue(u.C); return }
// Operations on Users
func (v Value) Operand(i int) (rv Value) { rv.C = C.LLVMGetOperand(v.C, C.unsigned(i)); return }
func (v Value) SetOperand(i int, op Value) { C.LLVMSetOperand(v.C, C.unsigned(i), op.C) }
func (v Value) OperandsCount() int { return int(C.LLVMGetNumOperands(v.C)) }
// Operations on constants of any type
func ConstNull(t Type) (v Value) { v.C = C.LLVMConstNull(t.C); return }
func ConstAllOnes(t Type) (v Value) { v.C = C.LLVMConstAllOnes(t.C); return }
func Undef(t Type) (v Value) { v.C = C.LLVMGetUndef(t.C); return }
func (v Value) IsConstant() bool { return C.LLVMIsConstant(v.C) != 0 }
func (v Value) IsNull() bool { return C.LLVMIsNull(v.C) != 0 }
func (v Value) IsUndef() bool { return C.LLVMIsUndef(v.C) != 0 }
func ConstPointerNull(t Type) (v Value) { v.C = C.LLVMConstPointerNull(t.C); return }
// Operations on metadata
func (c Context) MDString(str string) (md Metadata) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
md.C = C.LLVMMDString2(c.C, cstr, C.unsigned(len(str)))
return
}
func (c Context) MDNode(mds []Metadata) (md Metadata) {
ptr, nvals := llvmMetadataRefs(mds)
md.C = C.LLVMMDNode2(c.C, ptr, nvals)
return
}
func (v Value) ConstantAsMetadata() (md Metadata) {
md.C = C.LLVMConstantAsMetadata(v.C)
return
}
// Operations on scalar constants
func ConstInt(t Type, n uint64, signExtend bool) (v Value) {
v.C = C.LLVMConstInt(t.C,
C.ulonglong(n),
boolToLLVMBool(signExtend))
return
}
func ConstIntFromString(t Type, str string, radix int) (v Value) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
v.C = C.LLVMConstIntOfString(t.C, cstr, C.uint8_t(radix))
return
}
func ConstFloat(t Type, n float64) (v Value) {
v.C = C.LLVMConstReal(t.C, C.double(n))
return
}
func ConstFloatFromString(t Type, str string) (v Value) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
v.C = C.LLVMConstRealOfString(t.C, cstr)
return
}
func (v Value) ZExtValue() uint64 { return uint64(C.LLVMConstIntGetZExtValue(v.C)) }
func (v Value) SExtValue() int64 { return int64(C.LLVMConstIntGetSExtValue(v.C)) }
func (v Value) DoubleValue() (result float64, inexact bool) {
var losesInfo C.LLVMBool
doubleResult := C.LLVMConstRealGetDouble(v.C, &losesInfo)
return float64(doubleResult), losesInfo != 0
}
// Operations on composite constants
func (c Context) ConstString(str string, addnull bool) (v Value) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
v.C = C.LLVMConstStringInContext(c.C, cstr,
C.unsigned(len(str)), boolToLLVMBool(!addnull))
return
}
func (c Context) ConstStruct(constVals []Value, packed bool) (v Value) {
ptr, nvals := llvmValueRefs(constVals)
v.C = C.LLVMConstStructInContext(c.C, ptr, nvals,
boolToLLVMBool(packed))
return
}
func ConstNamedStruct(t Type, constVals []Value) (v Value) {
ptr, nvals := llvmValueRefs(constVals)
v.C = C.LLVMConstNamedStruct(t.C, ptr, nvals)
return
}
func ConstString(str string, addnull bool) (v Value) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
v.C = C.LLVMConstString(cstr,
C.unsigned(len(str)), boolToLLVMBool(!addnull))
return
}
func ConstArray(t Type, constVals []Value) (v Value) {
ptr, nvals := llvmValueRefs(constVals)
v.C = C.LLVMConstArray(t.C, ptr, nvals)
return
}
func ConstStruct(constVals []Value, packed bool) (v Value) {
ptr, nvals := llvmValueRefs(constVals)
v.C = C.LLVMConstStruct(ptr, nvals, boolToLLVMBool(packed))
return
}
func ConstVector(scalarConstVals []Value, packed bool) (v Value) {
ptr, nvals := llvmValueRefs(scalarConstVals)
v.C = C.LLVMConstVector(ptr, nvals)
return
}
// IsConstantString checks if the constant is an array of i8.
func (v Value) IsConstantString() bool {
return C.LLVMIsConstantString(v.C) != 0
}
// ConstGetAsString will return the string contained in a constant.
func (v Value) ConstGetAsString() string {
length := C.size_t(0)
cstr := C.LLVMGetAsString(v.C, &length)
return C.GoStringN(cstr, C.int(length))
}
// Constant expressions
func (v Value) Opcode() Opcode { return Opcode(C.LLVMGetConstOpcode(v.C)) }
func (v Value) InstructionOpcode() Opcode { return Opcode(C.LLVMGetInstructionOpcode(v.C)) }
func AlignOf(t Type) (v Value) { v.C = C.LLVMAlignOf(t.C); return }
func SizeOf(t Type) (v Value) { v.C = C.LLVMSizeOf(t.C); return }
func ConstNeg(v Value) (rv Value) { rv.C = C.LLVMConstNeg(v.C); return }
func ConstNSWNeg(v Value) (rv Value) { rv.C = C.LLVMConstNSWNeg(v.C); return }
func ConstNUWNeg(v Value) (rv Value) { rv.C = C.LLVMConstNUWNeg(v.C); return }
func ConstNot(v Value) (rv Value) { rv.C = C.LLVMConstNot(v.C); return }
func ConstAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAdd(lhs.C, rhs.C); return }
func ConstNSWAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWAdd(lhs.C, rhs.C); return }
func ConstNUWAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWAdd(lhs.C, rhs.C); return }
func ConstSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstSub(lhs.C, rhs.C); return }
func ConstNSWSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWSub(lhs.C, rhs.C); return }
func ConstNUWSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWSub(lhs.C, rhs.C); return }
func ConstMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstMul(lhs.C, rhs.C); return }
func ConstNSWMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNSWMul(lhs.C, rhs.C); return }
func ConstNUWMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstNUWMul(lhs.C, rhs.C); return }
func ConstXor(lhs, rhs Value) (v Value) { v.C = C.LLVMConstXor(lhs.C, rhs.C); return }
func ConstICmp(pred IntPredicate, lhs, rhs Value) (v Value) {
v.C = C.LLVMConstICmp(C.LLVMIntPredicate(pred), lhs.C, rhs.C)
return
}
func ConstFCmp(pred FloatPredicate, lhs, rhs Value) (v Value) {
v.C = C.LLVMConstFCmp(C.LLVMRealPredicate(pred), lhs.C, rhs.C)
return
}
func ConstShl(lhs, rhs Value) (v Value) { v.C = C.LLVMConstShl(lhs.C, rhs.C); return }
func ConstGEP(t Type, v Value, indices []Value) (rv Value) {
ptr, nvals := llvmValueRefs(indices)
rv.C = C.LLVMConstGEP2(t.C, v.C, ptr, nvals)
return
}
func ConstInBoundsGEP(t Type, v Value, indices []Value) (rv Value) {
ptr, nvals := llvmValueRefs(indices)
rv.C = C.LLVMConstInBoundsGEP2(t.C, v.C, ptr, nvals)
return
}
func ConstTrunc(v Value, t Type) (rv Value) { rv.C = C.LLVMConstTrunc(v.C, t.C); return }
func ConstPtrToInt(v Value, t Type) (rv Value) { rv.C = C.LLVMConstPtrToInt(v.C, t.C); return }
func ConstIntToPtr(v Value, t Type) (rv Value) { rv.C = C.LLVMConstIntToPtr(v.C, t.C); return }
func ConstBitCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstBitCast(v.C, t.C); return }
func ConstTruncOrBitCast(v Value, t Type) (rv Value) {
rv.C = C.LLVMConstTruncOrBitCast(v.C, t.C)
return
}
func ConstPointerCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstPointerCast(v.C, t.C); return }
func ConstExtractElement(vec, i Value) (rv Value) {
rv.C = C.LLVMConstExtractElement(vec.C, i.C)
return
}
func ConstInsertElement(vec, elem, i Value) (rv Value) {
rv.C = C.LLVMConstInsertElement(vec.C, elem.C, i.C)
return
}
func ConstShuffleVector(veca, vecb, mask Value) (rv Value) {
rv.C = C.LLVMConstShuffleVector(veca.C, vecb.C, mask.C)
return
}
func BlockAddress(f Value, bb BasicBlock) (v Value) {
v.C = C.LLVMBlockAddress(f.C, bb.C)
return
}
// Operations on global variables, functions, and aliases (globals)
func (v Value) GlobalParent() (m Module) { m.C = C.LLVMGetGlobalParent(v.C); return }
func (v Value) IsDeclaration() bool { return C.LLVMIsDeclaration(v.C) != 0 }
func (v Value) Linkage() Linkage { return Linkage(C.LLVMGetLinkage(v.C)) }
func (v Value) SetLinkage(l Linkage) { C.LLVMSetLinkage(v.C, C.LLVMLinkage(l)) }
func (v Value) Section() string { return C.GoString(C.LLVMGetSection(v.C)) }
func (v Value) SetSection(str string) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
C.LLVMSetSection(v.C, cstr)
}
func (v Value) Visibility() Visibility { return Visibility(C.LLVMGetVisibility(v.C)) }
func (v Value) SetVisibility(vi Visibility) { C.LLVMSetVisibility(v.C, C.LLVMVisibility(vi)) }
func (v Value) Alignment() int { return int(C.LLVMGetAlignment(v.C)) }
func (v Value) SetAlignment(a int) { C.LLVMSetAlignment(v.C, C.unsigned(a)) }
func (v Value) SetUnnamedAddr(ua bool) { C.LLVMSetUnnamedAddr(v.C, boolToLLVMBool(ua)) }