/
llvm.rs
2003 lines (1801 loc) · 84.8 KB
/
llvm.rs
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
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[allow(non_uppercase_pattern_statics)];
#[allow(non_camel_case_types)];
use std::c_str::ToCStr;
use std::cell::RefCell;
use collections::HashMap;
use std::libc::{c_uint, c_ushort, c_void, free};
use std::str::raw::from_c_str;
use middle::trans::type_::Type;
pub type Opcode = u32;
pub type Bool = c_uint;
pub static True: Bool = 1 as Bool;
pub static False: Bool = 0 as Bool;
// Consts for the LLVM CallConv type, pre-cast to uint.
#[deriving(Eq)]
pub enum CallConv {
CCallConv = 0,
FastCallConv = 8,
ColdCallConv = 9,
X86StdcallCallConv = 64,
X86FastcallCallConv = 65,
X86_64_Win64 = 79,
}
pub enum Visibility {
LLVMDefaultVisibility = 0,
HiddenVisibility = 1,
ProtectedVisibility = 2,
}
// This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
// DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
// LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
// they've been removed in upstream LLVM commit r203866.
pub enum Linkage {
ExternalLinkage = 0,
AvailableExternallyLinkage = 1,
LinkOnceAnyLinkage = 2,
LinkOnceODRLinkage = 3,
WeakAnyLinkage = 5,
WeakODRLinkage = 6,
AppendingLinkage = 7,
InternalLinkage = 8,
PrivateLinkage = 9,
ExternalWeakLinkage = 12,
CommonLinkage = 14,
}
#[deriving(Clone)]
pub enum Attribute {
ZExtAttribute = 1 << 0,
SExtAttribute = 1 << 1,
NoReturnAttribute = 1 << 2,
InRegAttribute = 1 << 3,
StructRetAttribute = 1 << 4,
NoUnwindAttribute = 1 << 5,
NoAliasAttribute = 1 << 6,
ByValAttribute = 1 << 7,
NestAttribute = 1 << 8,
ReadNoneAttribute = 1 << 9,
ReadOnlyAttribute = 1 << 10,
NoInlineAttribute = 1 << 11,
AlwaysInlineAttribute = 1 << 12,
OptimizeForSizeAttribute = 1 << 13,
StackProtectAttribute = 1 << 14,
StackProtectReqAttribute = 1 << 15,
AlignmentAttribute = 31 << 16,
NoCaptureAttribute = 1 << 21,
NoRedZoneAttribute = 1 << 22,
NoImplicitFloatAttribute = 1 << 23,
NakedAttribute = 1 << 24,
InlineHintAttribute = 1 << 25,
StackAttribute = 7 << 26,
ReturnsTwiceAttribute = 1 << 29,
UWTableAttribute = 1 << 30,
NonLazyBindAttribute = 1 << 31,
}
// enum for the LLVM IntPredicate type
pub enum IntPredicate {
IntEQ = 32,
IntNE = 33,
IntUGT = 34,
IntUGE = 35,
IntULT = 36,
IntULE = 37,
IntSGT = 38,
IntSGE = 39,
IntSLT = 40,
IntSLE = 41,
}
// enum for the LLVM RealPredicate type
pub enum RealPredicate {
RealPredicateFalse = 0,
RealOEQ = 1,
RealOGT = 2,
RealOGE = 3,
RealOLT = 4,
RealOLE = 5,
RealONE = 6,
RealORD = 7,
RealUNO = 8,
RealUEQ = 9,
RealUGT = 10,
RealUGE = 11,
RealULT = 12,
RealULE = 13,
RealUNE = 14,
RealPredicateTrue = 15,
}
// The LLVM TypeKind type - must stay in sync with the def of
// LLVMTypeKind in llvm/include/llvm-c/Core.h
#[deriving(Eq)]
#[repr(C)]
pub enum TypeKind {
Void = 0,
Half = 1,
Float = 2,
Double = 3,
X86_FP80 = 4,
FP128 = 5,
PPC_FP128 = 6,
Label = 7,
Integer = 8,
Function = 9,
Struct = 10,
Array = 11,
Pointer = 12,
Vector = 13,
Metadata = 14,
X86_MMX = 15,
}
#[repr(C)]
pub enum AtomicBinOp {
Xchg = 0,
Add = 1,
Sub = 2,
And = 3,
Nand = 4,
Or = 5,
Xor = 6,
Max = 7,
Min = 8,
UMax = 9,
UMin = 10,
}
#[repr(C)]
pub enum AtomicOrdering {
NotAtomic = 0,
Unordered = 1,
Monotonic = 2,
// Consume = 3, // Not specified yet.
Acquire = 4,
Release = 5,
AcquireRelease = 6,
SequentiallyConsistent = 7
}
// Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
#[repr(C)]
pub enum FileType {
AssemblyFile = 0,
ObjectFile = 1
}
pub enum Metadata {
MD_dbg = 0,
MD_tbaa = 1,
MD_prof = 2,
MD_fpmath = 3,
MD_range = 4,
MD_tbaa_struct = 5
}
// Inline Asm Dialect
pub enum AsmDialect {
AD_ATT = 0,
AD_Intel = 1
}
#[deriving(Eq)]
#[repr(C)]
pub enum CodeGenOptLevel {
CodeGenLevelNone = 0,
CodeGenLevelLess = 1,
CodeGenLevelDefault = 2,
CodeGenLevelAggressive = 3,
}
#[repr(C)]
pub enum RelocMode {
RelocDefault = 0,
RelocStatic = 1,
RelocPIC = 2,
RelocDynamicNoPic = 3,
}
#[repr(C)]
pub enum CodeGenModel {
CodeModelDefault = 0,
CodeModelJITDefault = 1,
CodeModelSmall = 2,
CodeModelKernel = 3,
CodeModelMedium = 4,
CodeModelLarge = 5,
}
// Opaque pointer types
pub enum Module_opaque {}
pub type ModuleRef = *Module_opaque;
pub enum Context_opaque {}
pub type ContextRef = *Context_opaque;
pub enum Type_opaque {}
pub type TypeRef = *Type_opaque;
pub enum Value_opaque {}
pub type ValueRef = *Value_opaque;
pub enum BasicBlock_opaque {}
pub type BasicBlockRef = *BasicBlock_opaque;
pub enum Builder_opaque {}
pub type BuilderRef = *Builder_opaque;
pub enum ExecutionEngine_opaque {}
pub type ExecutionEngineRef = *ExecutionEngine_opaque;
pub enum MemoryBuffer_opaque {}
pub type MemoryBufferRef = *MemoryBuffer_opaque;
pub enum PassManager_opaque {}
pub type PassManagerRef = *PassManager_opaque;
pub enum PassManagerBuilder_opaque {}
pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
pub enum Use_opaque {}
pub type UseRef = *Use_opaque;
pub enum TargetData_opaque {}
pub type TargetDataRef = *TargetData_opaque;
pub enum ObjectFile_opaque {}
pub type ObjectFileRef = *ObjectFile_opaque;
pub enum SectionIterator_opaque {}
pub type SectionIteratorRef = *SectionIterator_opaque;
pub enum Pass_opaque {}
pub type PassRef = *Pass_opaque;
pub enum TargetMachine_opaque {}
pub type TargetMachineRef = *TargetMachine_opaque;
pub enum Archive_opaque {}
pub type ArchiveRef = *Archive_opaque;
pub mod debuginfo {
use super::{ValueRef};
pub enum DIBuilder_opaque {}
pub type DIBuilderRef = *DIBuilder_opaque;
pub type DIDescriptor = ValueRef;
pub type DIScope = DIDescriptor;
pub type DILocation = DIDescriptor;
pub type DIFile = DIScope;
pub type DILexicalBlock = DIScope;
pub type DISubprogram = DIScope;
pub type DIType = DIDescriptor;
pub type DIBasicType = DIType;
pub type DIDerivedType = DIType;
pub type DICompositeType = DIDerivedType;
pub type DIVariable = DIDescriptor;
pub type DIArray = DIDescriptor;
pub type DISubrange = DIDescriptor;
pub enum DIDescriptorFlags {
FlagPrivate = 1 << 0,
FlagProtected = 1 << 1,
FlagFwdDecl = 1 << 2,
FlagAppleBlock = 1 << 3,
FlagBlockByrefStruct = 1 << 4,
FlagVirtual = 1 << 5,
FlagArtificial = 1 << 6,
FlagExplicit = 1 << 7,
FlagPrototyped = 1 << 8,
FlagObjcClassComplete = 1 << 9,
FlagObjectPointer = 1 << 10,
FlagVector = 1 << 11,
FlagStaticMember = 1 << 12
}
}
pub mod llvm {
use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
use super::{ValueRef, TargetMachineRef, FileType, ArchiveRef};
use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
use super::debuginfo::*;
use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong,
size_t};
// Link to our native llvm bindings (things that we need to use the C++ api
// for) and because llvm is written in C++ we need to link against libstdc++
//
// You'll probably notice that there is an omission of all LLVM libraries
// from this location. This is because the set of LLVM libraries that we
// link to is mostly defined by LLVM, and the `llvm-config` tool is used to
// figure out the exact set of libraries. To do this, the build system
// generates an llvmdeps.rs file next to this one which will be
// automatically updated whenever LLVM is updated to include an up-to-date
// set of the libraries we need to link to LLVM for.
#[link(name = "rustllvm", kind = "static")]
extern {
/* Create and destroy contexts. */
pub fn LLVMContextCreate() -> ContextRef;
pub fn LLVMContextDispose(C: ContextRef);
pub fn LLVMGetMDKindIDInContext(C: ContextRef,
Name: *c_char,
SLen: c_uint)
-> c_uint;
/* Create and destroy modules. */
pub fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
C: ContextRef)
-> ModuleRef;
pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
pub fn LLVMDisposeModule(M: ModuleRef);
/** Data layout. See Module::getDataLayout. */
pub fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
/** Target triple. See Module::getTargetTriple. */
pub fn LLVMGetTarget(M: ModuleRef) -> *c_char;
pub fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
/** See Module::dump. */
pub fn LLVMDumpModule(M: ModuleRef);
/** See Module::setModuleInlineAsm. */
pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
/** See llvm::LLVMTypeKind::getTypeID. */
pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
/** See llvm::LLVMType::getContext. */
pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
/* Operations on integer types */
pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
-> TypeRef;
pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
/* Operations on real types */
pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
/* Operations on function types */
pub fn LLVMFunctionType(ReturnType: TypeRef,
ParamTypes: *TypeRef,
ParamCount: c_uint,
IsVarArg: Bool)
-> TypeRef;
pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
/* Operations on struct types */
pub fn LLVMStructTypeInContext(C: ContextRef,
ElementTypes: *TypeRef,
ElementCount: c_uint,
Packed: Bool)
-> TypeRef;
pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
Dest: *mut TypeRef);
pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
/* Operations on array, pointer, and vector types (sequence types) */
pub fn LLVMArrayType(ElementType: TypeRef, ElementCount: c_uint)
-> TypeRef;
pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
-> TypeRef;
pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
-> TypeRef;
pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
-> *();
pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
/* Operations on other types */
pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
/* Operations on all values */
pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
pub fn LLVMGetValueName(Val: ValueRef) -> *c_char;
pub fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
pub fn LLVMDumpValue(Val: ValueRef);
pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
/* Operations on Uses */
pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
pub fn LLVMGetUser(U: UseRef) -> ValueRef;
pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
/* Operations on Users */
pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
/* Operations on constants of any type */
pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
/* all zeroes */
pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
-> ValueRef;
pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
-> ValueRef;
/* only for int/vector */
pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
pub fn LLVMIsNull(Val: ValueRef) -> Bool;
pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
/* Operations on metadata */
pub fn LLVMMDStringInContext(C: ContextRef,
Str: *c_char,
SLen: c_uint)
-> ValueRef;
pub fn LLVMMDNodeInContext(C: ContextRef,
Vals: *ValueRef,
Count: c_uint)
-> ValueRef;
pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
Str: *c_char,
Val: ValueRef);
/* Operations on scalar constants */
pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
-> ValueRef;
pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8)
-> ValueRef;
pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
Text: *c_char,
SLen: c_uint,
Radix: u8)
-> ValueRef;
pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char)
-> ValueRef;
pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
Text: *c_char,
SLen: c_uint)
-> ValueRef;
pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
/* Operations on composite constants */
pub fn LLVMConstStringInContext(C: ContextRef,
Str: *c_char,
Length: c_uint,
DontNullTerminate: Bool)
-> ValueRef;
pub fn LLVMConstStructInContext(C: ContextRef,
ConstantVals: *ValueRef,
Count: c_uint,
Packed: Bool)
-> ValueRef;
pub fn LLVMConstArray(ElementTy: TypeRef,
ConstantVals: *ValueRef,
Length: c_uint)
-> ValueRef;
pub fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: c_uint)
-> ValueRef;
/* Constant expressions */
pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstGEP(ConstantVal: ValueRef,
ConstantIndices: *ValueRef,
NumIndices: c_uint)
-> ValueRef;
pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
ConstantIndices: *ValueRef,
NumIndices: c_uint)
-> ValueRef;
pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstIntCast(ConstantVal: ValueRef,
ToType: TypeRef,
isSigned: Bool)
-> ValueRef;
pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
-> ValueRef;
pub fn LLVMConstSelect(ConstantCondition: ValueRef,
ConstantIfTrue: ValueRef,
ConstantIfFalse: ValueRef)
-> ValueRef;
pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
IndexConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
ElementValueConstant: ValueRef,
IndexConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
VectorBConstant: ValueRef,
MaskConstant: ValueRef)
-> ValueRef;
pub fn LLVMConstExtractValue(AggConstant: ValueRef,
IdxList: *c_uint,
NumIdx: c_uint)
-> ValueRef;
pub fn LLVMConstInsertValue(AggConstant: ValueRef,
ElementValueConstant: ValueRef,
IdxList: *c_uint,
NumIdx: c_uint)
-> ValueRef;
pub fn LLVMConstInlineAsm(Ty: TypeRef,
AsmString: *c_char,
Constraints: *c_char,
HasSideEffects: Bool,
IsAlignStack: Bool)
-> ValueRef;
pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
/* Operations on global variables, functions, and aliases (globals) */
pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
pub fn LLVMGetSection(Global: ValueRef) -> *c_char;
pub fn LLVMSetSection(Global: ValueRef, Section: *c_char);
pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
/* Operations on global variables */
pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char)
-> ValueRef;
pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
Ty: TypeRef,
Name: *c_char,
AddressSpace: c_uint)
-> ValueRef;
pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
pub fn LLVMSetInitializer(GlobalVar: ValueRef,
ConstantVal: ValueRef);
pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
/* Operations on aliases */
pub fn LLVMAddAlias(M: ModuleRef,
Ty: TypeRef,
Aliasee: ValueRef,
Name: *c_char)
-> ValueRef;
/* Operations on functions */
pub fn LLVMAddFunction(M: ModuleRef,
Name: *c_char,
FunctionTy: TypeRef)
-> ValueRef;
pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
pub fn LLVMDeleteFunction(Fn: ValueRef);
pub fn LLVMGetOrInsertFunction(M: ModuleRef,
Name: *c_char,
FunctionTy: TypeRef)
-> ValueRef;
pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
pub fn LLVMAddColdAttribute(Fn: ValueRef);
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
PA: c_ulonglong,
HighPA: c_ulonglong);
/* Operations on parameters */
pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
/* Operations on basic blocks */
pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
Fn: ValueRef,
Name: *c_char)
-> BasicBlockRef;
pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
BB: BasicBlockRef,
Name: *c_char)
-> BasicBlockRef;
pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
MoveAfter: BasicBlockRef);
pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
MoveBefore: BasicBlockRef);
/* Operations on instructions */
pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
/* Operations on call sites */
pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
pub fn LLVMAddInstrAttribute(Instr: ValueRef,
index: c_uint,
IA: c_uint);
pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
index: c_uint,
IA: c_uint);
pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
index: c_uint,
align: c_uint);
/* Operations on call instructions (only) */
pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
/* Operations on load/store instructions (only) */
pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
/* Operations on phi nodes */
pub fn LLVMAddIncoming(PhiNode: ValueRef,
IncomingValues: *ValueRef,
IncomingBlocks: *BasicBlockRef,
Count: c_uint);
pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
-> ValueRef;
pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
-> BasicBlockRef;
/* Instruction builders */
pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
pub fn LLVMPositionBuilder(Builder: BuilderRef,
Block: BasicBlockRef,
Instr: ValueRef);
pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
Instr: ValueRef);
pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
Block: BasicBlockRef);
pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
Instr: ValueRef,
Name: *c_char);
pub fn LLVMDisposeBuilder(Builder: BuilderRef);
pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
/* Metadata */
pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
/* Terminators */
pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
pub fn LLVMBuildAggregateRet(B: BuilderRef,
RetVals: *ValueRef,
N: c_uint)
-> ValueRef;
pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
pub fn LLVMBuildCondBr(B: BuilderRef,
If: ValueRef,
Then: BasicBlockRef,
Else: BasicBlockRef)
-> ValueRef;
pub fn LLVMBuildSwitch(B: BuilderRef,
V: ValueRef,
Else: BasicBlockRef,
NumCases: c_uint)
-> ValueRef;
pub fn LLVMBuildIndirectBr(B: BuilderRef,
Addr: ValueRef,
NumDests: c_uint)
-> ValueRef;
pub fn LLVMBuildInvoke(B: BuilderRef,
Fn: ValueRef,
Args: *ValueRef,
NumArgs: c_uint,
Then: BasicBlockRef,
Catch: BasicBlockRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildLandingPad(B: BuilderRef,
Ty: TypeRef,
PersFn: ValueRef,
NumClauses: c_uint,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
/* Add a case to the switch instruction */
pub fn LLVMAddCase(Switch: ValueRef,
OnVal: ValueRef,
Dest: BasicBlockRef);
/* Add a destination to the indirectbr instruction */
pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
/* Add a clause to the landing pad instruction */
pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
/* Set the cleanup on a landing pad instruction */
pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
/* Arithmetic */
pub fn LLVMBuildAdd(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildNSWAdd(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildNUWAdd(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildFAdd(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildSub(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildNSWSub(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildNUWSub(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildFSub(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildMul(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildNSWMul(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildNUWMul(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildFMul(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildUDiv(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildSDiv(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildExactSDiv(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildFDiv(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildURem(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildSRem(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildFRem(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildShl(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildLShr(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildAShr(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildAnd(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;
pub fn LLVMBuildOr(B: BuilderRef,
LHS: ValueRef,
RHS: ValueRef,
Name: *c_char)
-> ValueRef;