-
Notifications
You must be signed in to change notification settings - Fork 12.7k
/
lib.rs
2472 lines (2229 loc) · 100 KB
/
lib.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-2015 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_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![crate_name = "rustc_llvm"]
#![unstable(feature = "rustc_private", issue = "27812")]
#![crate_type = "dylib"]
#![crate_type = "rlib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/")]
#![cfg_attr(not(stage0), deny(warnings))]
#![feature(associated_consts)]
#![feature(box_syntax)]
#![feature(libc)]
#![feature(link_args)]
#![feature(staged_api)]
#![feature(linked_from)]
#![feature(concat_idents)]
extern crate libc;
#[macro_use] #[no_link] extern crate rustc_bitflags;
pub use self::AttributeSet::*;
pub use self::IntPredicate::*;
pub use self::RealPredicate::*;
pub use self::TypeKind::*;
pub use self::AtomicBinOp::*;
pub use self::AtomicOrdering::*;
pub use self::SynchronizationScope::*;
pub use self::FileType::*;
pub use self::MetadataType::*;
pub use self::AsmDialect::*;
pub use self::CodeGenOptLevel::*;
pub use self::CodeGenOptSize::*;
pub use self::RelocMode::*;
pub use self::CodeGenModel::*;
pub use self::DiagnosticKind::*;
pub use self::CallConv::*;
pub use self::Visibility::*;
pub use self::DiagnosticSeverity::*;
pub use self::Linkage::*;
pub use self::DLLStorageClassTypes::*;
use std::str::FromStr;
use std::ffi::{CString, CStr};
use std::cell::RefCell;
use std::slice;
use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
use libc::{c_longlong, c_ulonglong, c_void};
use debuginfo::{DIBuilderRef, DIDescriptor,
DIFile, DILexicalBlock, DISubprogram, DIType,
DIBasicType, DIDerivedType, DICompositeType, DIScope,
DIVariable, DIGlobalVariable, DIArray, DISubrange,
DITemplateTypeParameter, DIEnumerator, DINameSpace};
pub mod archive_ro;
pub mod diagnostic;
pub type Opcode = u32;
pub type Bool = c_uint;
pub const True: Bool = 1 as Bool;
pub const False: Bool = 0 as Bool;
// Consts for the LLVM CallConv type, pre-cast to usize.
#[derive(Copy, Clone, PartialEq)]
pub enum CallConv {
CCallConv = 0,
FastCallConv = 8,
ColdCallConv = 9,
X86StdcallCallConv = 64,
X86FastcallCallConv = 65,
X86_64_Win64 = 79,
X86_VectorCall = 80
}
#[derive(Copy, Clone)]
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.
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
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,
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub enum DiagnosticSeverity {
Error,
Warning,
Remark,
Note,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum DLLStorageClassTypes {
DefaultStorageClass = 0,
DLLImportStorageClass = 1,
DLLExportStorageClass = 2,
}
bitflags! {
#[derive(Default, Debug)]
flags Attribute : u64 {
const ZExt = 1 << 0,
const SExt = 1 << 1,
const NoReturn = 1 << 2,
const InReg = 1 << 3,
const StructRet = 1 << 4,
const NoUnwind = 1 << 5,
const NoAlias = 1 << 6,
const ByVal = 1 << 7,
const Nest = 1 << 8,
const ReadNone = 1 << 9,
const ReadOnly = 1 << 10,
const NoInline = 1 << 11,
const AlwaysInline = 1 << 12,
const OptimizeForSize = 1 << 13,
const StackProtect = 1 << 14,
const StackProtectReq = 1 << 15,
const NoCapture = 1 << 21,
const NoRedZone = 1 << 22,
const NoImplicitFloat = 1 << 23,
const Naked = 1 << 24,
const InlineHint = 1 << 25,
const ReturnsTwice = 1 << 29,
const UWTable = 1 << 30,
const NonLazyBind = 1 << 31,
// Some of these are missing from the LLVM C API, the rest are
// present, but commented out, and preceded by the following warning:
// FIXME: These attributes are currently not included in the C API as
// a temporary measure until the API/ABI impact to the C API is understood
// and the path forward agreed upon.
const SanitizeAddress = 1 << 32,
const MinSize = 1 << 33,
const NoDuplicate = 1 << 34,
const StackProtectStrong = 1 << 35,
const SanitizeThread = 1 << 36,
const SanitizeMemory = 1 << 37,
const NoBuiltin = 1 << 38,
const Returned = 1 << 39,
const Cold = 1 << 40,
const Builtin = 1 << 41,
const OptimizeNone = 1 << 42,
const InAlloca = 1 << 43,
const NonNull = 1 << 44,
const JumpTable = 1 << 45,
const Convergent = 1 << 46,
const SafeStack = 1 << 47,
const NoRecurse = 1 << 48,
const InaccessibleMemOnly = 1 << 49,
const InaccessibleMemOrArgMemOnly = 1 << 50,
}
}
#[derive(Copy, Clone, Default, Debug)]
pub struct Attributes {
regular: Attribute,
dereferenceable_bytes: u64
}
impl Attributes {
pub fn set(&mut self, attr: Attribute) -> &mut Self {
self.regular = self.regular | attr;
self
}
pub fn unset(&mut self, attr: Attribute) -> &mut Self {
self.regular = self.regular - attr;
self
}
pub fn set_dereferenceable(&mut self, bytes: u64) -> &mut Self {
self.dereferenceable_bytes = bytes;
self
}
pub fn unset_dereferenceable(&mut self) -> &mut Self {
self.dereferenceable_bytes = 0;
self
}
pub fn apply_llfn(&self, idx: usize, llfn: ValueRef) {
unsafe {
LLVMAddFunctionAttribute(llfn, idx as c_uint, self.regular.bits());
if self.dereferenceable_bytes != 0 {
LLVMAddDereferenceableAttr(llfn, idx as c_uint,
self.dereferenceable_bytes);
}
}
}
pub fn apply_callsite(&self, idx: usize, callsite: ValueRef) {
unsafe {
LLVMAddCallSiteAttribute(callsite, idx as c_uint, self.regular.bits());
if self.dereferenceable_bytes != 0 {
LLVMAddDereferenceableCallSiteAttr(callsite, idx as c_uint,
self.dereferenceable_bytes);
}
}
}
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum AttributeSet {
ReturnIndex = 0,
FunctionIndex = !0
}
// enum for the LLVM IntPredicate type
#[derive(Copy, Clone)]
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
#[derive(Copy, Clone)]
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
#[derive(Copy, Clone, PartialEq, Debug)]
#[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)]
#[derive(Copy, Clone)]
pub enum AtomicBinOp {
AtomicXchg = 0,
AtomicAdd = 1,
AtomicSub = 2,
AtomicAnd = 3,
AtomicNand = 4,
AtomicOr = 5,
AtomicXor = 6,
AtomicMax = 7,
AtomicMin = 8,
AtomicUMax = 9,
AtomicUMin = 10,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum AtomicOrdering {
NotAtomic = 0,
Unordered = 1,
Monotonic = 2,
// Consume = 3, // Not specified yet.
Acquire = 4,
Release = 5,
AcquireRelease = 6,
SequentiallyConsistent = 7
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum SynchronizationScope {
SingleThread = 0,
CrossThread = 1
}
// Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
#[repr(C)]
#[derive(Copy, Clone)]
pub enum FileType {
AssemblyFileType = 0,
ObjectFileType = 1
}
#[derive(Copy, Clone)]
pub enum MetadataType {
MD_dbg = 0,
MD_tbaa = 1,
MD_prof = 2,
MD_fpmath = 3,
MD_range = 4,
MD_tbaa_struct = 5,
MD_invariant_load = 6,
MD_alias_scope = 7,
MD_noalias = 8,
MD_nontemporal = 9,
MD_mem_parallel_loop_access = 10,
MD_nonnull = 11,
}
// Inline Asm Dialect
#[derive(Copy, Clone)]
pub enum AsmDialect {
AD_ATT = 0,
AD_Intel = 1
}
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub enum CodeGenOptLevel {
CodeGenLevelNone = 0,
CodeGenLevelLess = 1,
CodeGenLevelDefault = 2,
CodeGenLevelAggressive = 3,
}
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub enum CodeGenOptSize {
CodeGenOptSizeNone = 0,
CodeGenOptSizeDefault = 1,
CodeGenOptSizeAggressive = 2,
}
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub enum RelocMode {
RelocDefault = 0,
RelocStatic = 1,
RelocPIC = 2,
RelocDynamicNoPic = 3,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum CodeGenModel {
CodeModelDefault = 0,
CodeModelJITDefault = 1,
CodeModelSmall = 2,
CodeModelKernel = 3,
CodeModelMedium = 4,
CodeModelLarge = 5,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum DiagnosticKind {
DK_InlineAsm = 0,
DK_StackSize,
DK_DebugMetadataVersion,
DK_SampleProfile,
DK_OptimizationRemark,
DK_OptimizationRemarkMissed,
DK_OptimizationRemarkAnalysis,
DK_OptimizationFailure,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub enum ArchiveKind {
K_GNU,
K_MIPS64,
K_BSD,
K_COFF,
}
impl FromStr for ArchiveKind {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"gnu" => Ok(ArchiveKind::K_GNU),
"mips64" => Ok(ArchiveKind::K_MIPS64),
"bsd" => Ok(ArchiveKind::K_BSD),
"coff" => Ok(ArchiveKind::K_COFF),
_ => Err(()),
}
}
}
/// Represents the different LLVM passes Rust supports
#[derive(Copy, Clone, PartialEq, Debug)]
#[repr(C)]
pub enum SupportedPassKind {
Function,
Module,
Unsupported,
}
// Opaque pointer types
#[allow(missing_copy_implementations)]
pub enum Module_opaque {}
pub type ModuleRef = *mut Module_opaque;
#[allow(missing_copy_implementations)]
pub enum Context_opaque {}
pub type ContextRef = *mut Context_opaque;
#[allow(missing_copy_implementations)]
pub enum Type_opaque {}
pub type TypeRef = *mut Type_opaque;
#[allow(missing_copy_implementations)]
pub enum Value_opaque {}
pub type ValueRef = *mut Value_opaque;
#[allow(missing_copy_implementations)]
pub enum Metadata_opaque {}
pub type MetadataRef = *mut Metadata_opaque;
#[allow(missing_copy_implementations)]
pub enum BasicBlock_opaque {}
pub type BasicBlockRef = *mut BasicBlock_opaque;
#[allow(missing_copy_implementations)]
pub enum Builder_opaque {}
pub type BuilderRef = *mut Builder_opaque;
#[allow(missing_copy_implementations)]
pub enum ExecutionEngine_opaque {}
pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
#[allow(missing_copy_implementations)]
pub enum MemoryBuffer_opaque {}
pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
#[allow(missing_copy_implementations)]
pub enum PassManager_opaque {}
pub type PassManagerRef = *mut PassManager_opaque;
#[allow(missing_copy_implementations)]
pub enum PassManagerBuilder_opaque {}
pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
#[allow(missing_copy_implementations)]
pub enum Use_opaque {}
pub type UseRef = *mut Use_opaque;
#[allow(missing_copy_implementations)]
pub enum TargetData_opaque {}
pub type TargetDataRef = *mut TargetData_opaque;
#[allow(missing_copy_implementations)]
pub enum ObjectFile_opaque {}
pub type ObjectFileRef = *mut ObjectFile_opaque;
#[allow(missing_copy_implementations)]
pub enum SectionIterator_opaque {}
pub type SectionIteratorRef = *mut SectionIterator_opaque;
#[allow(missing_copy_implementations)]
pub enum Pass_opaque {}
pub type PassRef = *mut Pass_opaque;
#[allow(missing_copy_implementations)]
pub enum TargetMachine_opaque {}
pub type TargetMachineRef = *mut TargetMachine_opaque;
pub enum Archive_opaque {}
pub type ArchiveRef = *mut Archive_opaque;
pub enum ArchiveIterator_opaque {}
pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
pub enum ArchiveChild_opaque {}
pub type ArchiveChildRef = *mut ArchiveChild_opaque;
#[allow(missing_copy_implementations)]
pub enum Twine_opaque {}
pub type TwineRef = *mut Twine_opaque;
#[allow(missing_copy_implementations)]
pub enum DiagnosticInfo_opaque {}
pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
#[allow(missing_copy_implementations)]
pub enum DebugLoc_opaque {}
pub type DebugLocRef = *mut DebugLoc_opaque;
#[allow(missing_copy_implementations)]
pub enum SMDiagnostic_opaque {}
pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
#[allow(missing_copy_implementations)]
pub enum RustArchiveMember_opaque {}
pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
#[allow(missing_copy_implementations)]
pub enum OperandBundleDef_opaque {}
pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
pub mod debuginfo {
pub use self::DIDescriptorFlags::*;
use super::{MetadataRef};
#[allow(missing_copy_implementations)]
pub enum DIBuilder_opaque {}
pub type DIBuilderRef = *mut DIBuilder_opaque;
pub type DIDescriptor = MetadataRef;
pub type DIScope = DIDescriptor;
pub type DILocation = DIDescriptor;
pub type DIFile = DIScope;
pub type DILexicalBlock = DIScope;
pub type DISubprogram = DIScope;
pub type DINameSpace = DIScope;
pub type DIType = DIDescriptor;
pub type DIBasicType = DIType;
pub type DIDerivedType = DIType;
pub type DICompositeType = DIDerivedType;
pub type DIVariable = DIDescriptor;
pub type DIGlobalVariable = DIDescriptor;
pub type DIArray = DIDescriptor;
pub type DISubrange = DIDescriptor;
pub type DIEnumerator = DIDescriptor;
pub type DITemplateTypeParameter = DIDescriptor;
#[derive(Copy, Clone)]
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,
FlagIndirectVariable = 1 << 13,
FlagLValueReference = 1 << 14,
FlagRValueReference = 1 << 15
}
}
// 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")]
#[cfg(not(cargobuild))]
extern {}
#[linked_from = "rustllvm"] // not quite true but good enough
extern {
/* Create and destroy contexts. */
pub fn LLVMContextCreate() -> ContextRef;
pub fn LLVMContextDispose(C: ContextRef);
pub fn LLVMGetMDKindIDInContext(C: ContextRef,
Name: *const c_char,
SLen: c_uint)
-> c_uint;
/* Create and destroy modules. */
pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
C: ContextRef)
-> ModuleRef;
pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
pub fn LLVMDisposeModule(M: ModuleRef);
/// Data layout. See Module::getDataLayout.
pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
/// Target triple. See Module::getTargetTriple.
pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
/// See Module::dump.
pub fn LLVMDumpModule(M: ModuleRef);
/// See Module::setModuleInlineAsm.
pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const 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: *const 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: *mut TypeRef);
/* Operations on struct types */
pub fn LLVMStructTypeInContext(C: ContextRef,
ElementTypes: *const 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 LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> 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)
-> *const c_void;
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) -> *const c_char;
pub fn LLVMSetValueName(Val: ValueRef, Name: *const 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 isize/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: *const c_char,
SLen: c_uint)
-> ValueRef;
pub fn LLVMMDNodeInContext(C: ContextRef,
Vals: *const ValueRef,
Count: c_uint)
-> ValueRef;
pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
Str: *const 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: *const c_char, Radix: u8)
-> ValueRef;
pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
Text: *const c_char,
SLen: c_uint,
Radix: u8)
-> ValueRef;
pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
-> ValueRef;
pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
Text: *const 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: *const c_char,
Length: c_uint,
DontNullTerminate: Bool)
-> ValueRef;
pub fn LLVMConstStructInContext(C: ContextRef,
ConstantVals: *const ValueRef,
Count: c_uint,
Packed: Bool)
-> ValueRef;
pub fn LLVMConstArray(ElementTy: TypeRef,
ConstantVals: *const ValueRef,
Length: c_uint)
-> ValueRef;
pub fn LLVMConstVector(ScalarConstantVals: *const 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: *const ValueRef,
NumIndices: c_uint)
-> ValueRef;
pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
ConstantIndices: *const 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: *const c_uint,
NumIdx: c_uint)
-> ValueRef;
pub fn LLVMConstInsertValue(AggConstant: ValueRef,
ElementValueConstant: ValueRef,
IdxList: *const c_uint,
NumIdx: c_uint)
-> ValueRef;
pub fn LLVMConstInlineAsm(Ty: TypeRef,
AsmString: *const c_char,
Constraints: *const 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) -> *const c_char;
pub fn LLVMSetSection(Global: ValueRef, Section: *const 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 LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
-> ValueRef;
pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
Ty: TypeRef,
Name: *const c_char,
AddressSpace: c_uint)
-> ValueRef;
pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> 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);
pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
/* Operations on aliases */
pub fn LLVMAddAlias(M: ModuleRef,
Ty: TypeRef,
Aliasee: ValueRef,
Name: *const c_char)
-> ValueRef;
/* Operations on functions */
pub fn LLVMAddFunction(M: ModuleRef,
Name: *const c_char,
FunctionTy: TypeRef)
-> ValueRef;
pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const 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: *const 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) -> *const c_char;
pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
Name: *const c_char,
Value: *const c_char);
pub fn LLVMRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: uint64_t);
pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_uint;
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_uint);
/* Operations on parameters */
pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;