forked from nsf/gollvm
-
Notifications
You must be signed in to change notification settings - Fork 21
/
core.go
1904 lines (1765 loc) · 72.8 KB
/
core.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
package llvm
/*
#include <llvm-c/Core.h>
#include "core.h"
#include <stdlib.h>
*/
import "C"
import "unsafe"
import "errors"
// TODO: Add comments
// TODO: Use Go's reflection in order to simplify bindings?
// TODO: Add type safety?
type (
// I'm using these weird structs here, because *Ref types are pointers
// and Go's spec says that I can't use a pointer 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
}
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
}
Attribute uint64
Opcode C.LLVMOpcode
TypeKind C.LLVMTypeKind
Linkage C.LLVMLinkage
Visibility C.LLVMVisibility
CallConv C.LLVMCallConv
IntPredicate C.LLVMIntPredicate
FloatPredicate C.LLVMRealPredicate
LandingPadClause C.LLVMLandingPadClauseTy
)
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 }
// 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 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
}
//-------------------------------------------------------------------------
// llvm.Attribute
//-------------------------------------------------------------------------
const (
NoneAttribute Attribute = 0
ZExtAttribute Attribute = C.LLVMZExtAttribute
SExtAttribute Attribute = C.LLVMSExtAttribute
NoReturnAttribute Attribute = C.LLVMNoReturnAttribute
InRegAttribute Attribute = C.LLVMInRegAttribute
StructRetAttribute Attribute = C.LLVMStructRetAttribute
NoUnwindAttribute Attribute = C.LLVMNoUnwindAttribute
NoAliasAttribute Attribute = C.LLVMNoAliasAttribute
ByValAttribute Attribute = C.LLVMByValAttribute
NestAttribute Attribute = C.LLVMNestAttribute
ReadNoneAttribute Attribute = C.LLVMReadNoneAttribute
ReadOnlyAttribute Attribute = C.LLVMReadOnlyAttribute
NoInlineAttribute Attribute = C.LLVMNoInlineAttribute
AlwaysInlineAttribute Attribute = C.LLVMAlwaysInlineAttribute
OptimizeForSizeAttribute Attribute = C.LLVMOptimizeForSizeAttribute
StackProtectAttribute Attribute = C.LLVMStackProtectAttribute
StackProtectReqAttribute Attribute = C.LLVMStackProtectReqAttribute
Alignment Attribute = C.LLVMAlignment
NoCaptureAttribute Attribute = C.LLVMNoCaptureAttribute
NoRedZoneAttribute Attribute = C.LLVMNoRedZoneAttribute
NoImplicitFloatAttribute Attribute = C.LLVMNoImplicitFloatAttribute
NakedAttribute Attribute = C.LLVMNakedAttribute
InlineHintAttribute Attribute = C.LLVMInlineHintAttribute
StackAlignment Attribute = C.LLVMStackAlignment
ReturnsTwiceAttribute Attribute = C.LLVMReturnsTwice
UWTableAttribute Attribute = C.LLVMUWTable
NonLazyBindAttribute Attribute = 1 << 31
SanitizeAddressAttribute Attribute = 1 << 32
MinSizeAttribute Attribute = 1 << 33
NoDuplicateAttribute Attribute = 1 << 34
StackProtectStrongAttribute Attribute = 1 << 35
SanitizeThreadAttribute Attribute = 1 << 36
SanitizeMemoryAttribute Attribute = 1 << 37
NoBuiltinAttribute Attribute = 1 << 38
ReturnedAttribute Attribute = 1 << 39
ColdAttribute Attribute = 1 << 40
BuiltinAttribute Attribute = 1 << 41
OptimizeNoneAttribute Attribute = 1 << 42
InAllocaAttribute Attribute = 1 << 43
NonNullAttribute Attribute = 1 << 44
JumpTableAttribute Attribute = 1 << 45
)
//-------------------------------------------------------------------------
// 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
)
//-------------------------------------------------------------------------
// 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
)
//-------------------------------------------------------------------------
// 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
DLLImportLinkage Linkage = C.LLVMDLLImportLinkage
DLLExportLinkage Linkage = C.LLVMDLLExportLinkage
ExternalWeakLinkage Linkage = C.LLVMExternalWeakLinkage
GhostLinkage Linkage = C.LLVMGhostLinkage
CommonLinkage Linkage = C.LLVMCommonLinkage
LinkerPrivateLinkage Linkage = C.LLVMLinkerPrivateLinkage
LinkerPrivateWeakLinkage Linkage = C.LLVMLinkerPrivateWeakLinkage
//LinkerPrivateWeakDefAutoLinkage Linkage = C.LLVMLinkerPrivateWeakDefAutoLinkage
)
//-------------------------------------------------------------------------
// 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.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.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)
id = int(C.LLVMGetMDKindIDInContext(c.C, cname, C.unsigned(len(name))))
C.free(unsafe.Pointer(cname))
return
}
func MDKindID(name string) (id int) {
cname := C.CString(name)
id = int(C.LLVMGetMDKindID(cname, C.unsigned(len(name))))
C.free(unsafe.Pointer(cname))
return
}
//-------------------------------------------------------------------------
// llvm.Module
//-------------------------------------------------------------------------
// Create and destroy modules.
// See llvm::Module::Module.
func NewModule(name string) (m Module) {
cname := C.CString(name)
m.C = C.LLVMModuleCreateWithName(cname)
C.free(unsafe.Pointer(cname))
return
}
func (c Context) NewModule(name string) (m Module) {
cname := C.CString(name)
m.C = C.LLVMModuleCreateWithNameInContext(cname, c.C)
C.free(unsafe.Pointer(cname))
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)
C.LLVMSetDataLayout(m.C, clayout)
C.free(unsafe.Pointer(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)
C.LLVMSetTarget(m.C, ctarget)
C.free(unsafe.Pointer(ctarget))
}
func (m Module) GetTypeByName(name string) (t Type) {
cname := C.CString(name)
t.C = C.LLVMGetTypeByName(m.C, cname)
C.free(unsafe.Pointer(cname))
return
}
// See Module::dump.
func (m Module) Dump() {
C.LLVMDumpModule(m.C)
}
func (m Module) String() string {
cir := C.LLVMPrintModuleToString(m.C)
ir := C.GoString(cir)
C.free(unsafe.Pointer(cir))
return ir
}
// See Module::setModuleInlineAsm.
func (m Module) SetInlineAsm(asm string) {
casm := C.CString(asm)
C.LLVMSetModuleInlineAsm(m.C, casm)
C.free(unsafe.Pointer(casm))
}
func (m Module) AddNamedMetadataOperand(name string, operand Value) {
cname := C.CString(name)
C.LLVMAddNamedMetadataOperand(m.C, cname, operand.C)
C.free(unsafe.Pointer(cname))
}
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 Int1Type() (t Type) { t.C = C.LLVMInt1Type(); return }
func Int8Type() (t Type) { t.C = C.LLVMInt8Type(); return }
func Int16Type() (t Type) { t.C = C.LLVMInt16Type(); return }
func Int32Type() (t Type) { t.C = C.LLVMInt32Type(); return }
func Int64Type() (t Type) { t.C = C.LLVMInt64Type(); return }
func IntType(numbits int) (t Type) {
t.C = C.LLVMIntType(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 }
func FloatType() (t Type) { t.C = C.LLVMFloatType(); return }
func DoubleType() (t Type) { t.C = C.LLVMDoubleType(); return }
func X86FP80Type() (t Type) { t.C = C.LLVMX86FP80Type(); return }
func FP128Type() (t Type) { t.C = C.LLVMFP128Type(); return }
func PPCFP128Type() (t Type) { t.C = C.LLVMPPCFP128Type(); 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)
t.C = C.LLVMStructCreateNamed(c.C, cname)
C.free(unsafe.Pointer(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 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 VoidType() (t Type) { t.C = C.LLVMVoidType(); return }
func LabelType() (t Type) { t.C = C.LLVMLabelType(); 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)
C.LLVMSetValueName(v.C, cname)
C.free(unsafe.Pointer(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 Value) {
C.LLVMSetMetadata(v.C, C.unsigned(kind), node.C)
}
// The bulk of LLVM's object model consists of values, which comprise a very
// rich type hierarchy.
//#define LLVM_FOR_EACH_VALUE_SUBCLASS(macro) \
// macro(Argument) \
// macro(BasicBlock) \
// macro(InlineAsm) \
// macro(User) \
// macro(Constant) \
// macro(ConstantAggregateZero) \
// macro(ConstantArray) \
// macro(ConstantExpr) \
// macro(ConstantFP) \
// macro(ConstantInt) \
// macro(ConstantPointerNull) \
// macro(ConstantStruct) \
// macro(ConstantVector) \
// macro(GlobalValue) \
// macro(Function) \
// macro(GlobalAlias) \
// macro(GlobalVariable) \
// macro(UndefValue) \
// macro(Instruction) \
// macro(BinaryOperator) \
// macro(CallInst) \
// macro(IntrinsicInst) \
// macro(DbgInfoIntrinsic) \
// macro(DbgDeclareInst) \
// macro(EHSelectorInst) \
// macro(MemIntrinsic) \
// macro(MemCpyInst) \
// macro(MemMoveInst) \
// macro(MemSetInst) \
// macro(CmpInst) \
// macro(FCmpInst) \
// macro(ICmpInst) \
// macro(ExtractElementInst) \
// macro(GetElementPtrInst) \
// macro(InsertElementInst) \
// macro(InsertValueInst) \
// macro(PHINode) \
// macro(SelectInst) \
// macro(ShuffleVectorInst) \
// macro(StoreInst) \
// macro(TerminatorInst) \
// macro(BranchInst) \
// macro(InvokeInst) \
// macro(ReturnInst) \
// macro(SwitchInst) \
// macro(UnreachableInst) \
// macro(UnwindInst) \
// macro(UnaryInstruction) \
// macro(AllocaInst) \
// macro(CastInst) \
// macro(BitCastInst) \
// macro(FPExtInst) \
// macro(FPToSIInst) \
// macro(FPToUIInst) \
// macro(FPTruncInst) \
// macro(IntToPtrInst) \
// macro(PtrToIntInst) \
// macro(SExtInst) \
// macro(SIToFPInst) \
// macro(TruncInst) \
// macro(UIToFPInst) \
// macro(ZExtInst) \
// macro(ExtractValueInst) \
// macro(LoadInst) \
// macro(VAArgInst)
//#define LLVM_DECLARE_VALUE_CAST(name) \
// func (v Value) IsA##name() (rv Value) { rv.C = C.LLVMIsA##name(v.C); return } ||
//LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
// Conversion functions. Generated using preprocess statements above. 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) IsATerminatorInst() (rv Value) { rv.C = C.LLVMIsATerminatorInst(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) (v Value) {
cstr := C.CString(str)
v.C = C.LLVMMDStringInContext(c.C, cstr, C.unsigned(len(str)))
C.free(unsafe.Pointer(cstr))
return
}
func MDString(str string) (v Value) {
cstr := C.CString(str)
v.C = C.LLVMMDString(cstr, C.unsigned(len(str)))
C.free(unsafe.Pointer(cstr))
return
}
func (c Context) MDNode(vals []Value) (v Value) {
ptr, nvals := llvmValueRefs(vals)
v.C = C.LLVMMDNodeInContext(c.C, ptr, nvals)
return
}
func MDNode(vals []Value) (v Value) {
ptr, nvals := llvmValueRefs(vals)
v.C = C.LLVMMDNode(ptr, nvals)
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)
v.C = C.LLVMConstIntOfString(t.C, cstr, C.uint8_t(radix))
C.free(unsafe.Pointer(cstr))
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)
v.C = C.LLVMConstRealOfString(t.C, cstr)
C.free(unsafe.Pointer(cstr))
return
}
func (v Value) ZExtValue() uint64 { return uint64(C.LLVMConstIntGetZExtValue(v.C)) }
func (v Value) SExtValue() int64 { return int64(C.LLVMConstIntGetSExtValue(v.C)) }
// Operations on composite constants
func (c Context) ConstString(str string, addnull bool) (v Value) {
cstr := C.CString(str)
v.C = C.LLVMConstStringInContext(c.C, cstr,
C.unsigned(len(str)), boolToLLVMBool(!addnull))
C.free(unsafe.Pointer(cstr))
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)
v.C = C.LLVMConstString(cstr,
C.unsigned(len(str)), boolToLLVMBool(!addnull))
C.free(unsafe.Pointer(cstr))
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
}
// 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 ConstFNeg(v Value) (rv Value) { rv.C = C.LLVMConstFNeg(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 ConstFAdd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFAdd(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 ConstFSub(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFSub(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 ConstFMul(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFMul(lhs.C, rhs.C); return }
func ConstUDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstUDiv(lhs.C, rhs.C); return }
func ConstSDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstSDiv(lhs.C, rhs.C); return }
func ConstExactSDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstExactSDiv(lhs.C, rhs.C); return }
func ConstFDiv(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFDiv(lhs.C, rhs.C); return }
func ConstURem(lhs, rhs Value) (v Value) { v.C = C.LLVMConstURem(lhs.C, rhs.C); return }
func ConstSRem(lhs, rhs Value) (v Value) { v.C = C.LLVMConstSRem(lhs.C, rhs.C); return }
func ConstFRem(lhs, rhs Value) (v Value) { v.C = C.LLVMConstFRem(lhs.C, rhs.C); return }
func ConstAnd(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAnd(lhs.C, rhs.C); return }
func ConstOr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstOr(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 ConstLShr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstLShr(lhs.C, rhs.C); return }
func ConstAShr(lhs, rhs Value) (v Value) { v.C = C.LLVMConstAShr(lhs.C, rhs.C); return }
func ConstGEP(v Value, indices []Value) (rv Value) {
ptr, nvals := llvmValueRefs(indices)
rv.C = C.LLVMConstGEP(v.C, ptr, nvals)
return
}
func ConstInBoundsGEP(v Value, indices []Value) (rv Value) {
ptr, nvals := llvmValueRefs(indices)
rv.C = C.LLVMConstInBoundsGEP(v.C, ptr, nvals)
return
}
func ConstTrunc(v Value, t Type) (rv Value) { rv.C = C.LLVMConstTrunc(v.C, t.C); return }
func ConstSExt(v Value, t Type) (rv Value) { rv.C = C.LLVMConstSExt(v.C, t.C); return }
func ConstZExt(v Value, t Type) (rv Value) { rv.C = C.LLVMConstZExt(v.C, t.C); return }
func ConstFPTrunc(v Value, t Type) (rv Value) { rv.C = C.LLVMConstFPTrunc(v.C, t.C); return }
func ConstFPExt(v Value, t Type) (rv Value) { rv.C = C.LLVMConstFPExt(v.C, t.C); return }
func ConstUIToFP(v Value, t Type) (rv Value) { rv.C = C.LLVMConstUIToFP(v.C, t.C); return }
func ConstSIToFP(v Value, t Type) (rv Value) { rv.C = C.LLVMConstSIToFP(v.C, t.C); return }
func ConstFPToUI(v Value, t Type) (rv Value) { rv.C = C.LLVMConstFPToUI(v.C, t.C); return }
func ConstFPToSI(v Value, t Type) (rv Value) { rv.C = C.LLVMConstFPToSI(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 ConstZExtOrBitCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstZExtOrBitCast(v.C, t.C); return }
func ConstSExtOrBitCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstSExtOrBitCast(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 ConstIntCast(v Value, t Type, signed bool) (rv Value) {
rv.C = C.LLVMConstIntCast(v.C, t.C, boolToLLVMBool(signed))
return
}
func ConstFPCast(v Value, t Type) (rv Value) { rv.C = C.LLVMConstFPCast(v.C, t.C); return }
func ConstSelect(cond, iftrue, iffalse Value) (rv Value) {
rv.C = C.LLVMConstSelect(cond.C, iftrue.C, iffalse.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
}
//TODO
//LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
// unsigned NumIdx);
func ConstExtractValue(agg Value, indices []uint32) (rv Value) {
n := len(indices)
if n == 0 {
panic("one or more indices are required")
}
ptr := (*C.unsigned)(&indices[0])
rv.C = C.LLVMConstExtractValue(agg.C, ptr, C.unsigned(n))
return
}
func ConstInsertValue(agg, val Value, indices []uint32) (rv Value) {