1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![allow(non_upper_case_globals)]
12 #![allow(non_camel_case_types)]
13 #![allow(non_snake_case)]
15 #![allow(trivial_casts)]
17 #![crate_name = "rustc_llvm"]
18 #![unstable(feature = "rustc_private", issue = "27812")]
19 #![crate_type = "dylib"]
20 #![crate_type = "rlib"]
21 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
22 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
23 html_root_url = "https://doc.rust-lang.org/nightly/")]
25 #![feature(associated_consts)]
26 #![feature(box_syntax)]
28 #![feature(link_args)]
29 #![feature(staged_api)]
30 #![feature(linked_from)]
31 #![feature(concat_idents)]
34 #[macro_use] #[no_link] extern crate rustc_bitflags;
36 pub use self::OtherAttribute::*;
37 pub use self::SpecialAttribute::*;
38 pub use self::AttributeSet::*;
39 pub use self::IntPredicate::*;
40 pub use self::RealPredicate::*;
41 pub use self::TypeKind::*;
42 pub use self::AtomicBinOp::*;
43 pub use self::AtomicOrdering::*;
44 pub use self::SynchronizationScope::*;
45 pub use self::FileType::*;
46 pub use self::MetadataType::*;
47 pub use self::AsmDialect::*;
48 pub use self::CodeGenOptLevel::*;
49 pub use self::RelocMode::*;
50 pub use self::CodeGenModel::*;
51 pub use self::DiagnosticKind::*;
52 pub use self::CallConv::*;
53 pub use self::Visibility::*;
54 pub use self::DiagnosticSeverity::*;
55 pub use self::Linkage::*;
56 pub use self::DLLStorageClassTypes::*;
58 use std::ffi::CString;
59 use std::cell::RefCell;
61 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
62 use libc::{c_longlong, c_ulonglong, c_void};
63 use debuginfo::{DIBuilderRef, DIDescriptor,
64 DIFile, DILexicalBlock, DISubprogram, DIType,
65 DIBasicType, DIDerivedType, DICompositeType, DIScope,
66 DIVariable, DIGlobalVariable, DIArray, DISubrange,
67 DITemplateTypeParameter, DIEnumerator, DINameSpace};
72 pub type Opcode = u32;
73 pub type Bool = c_uint;
75 pub const True: Bool = 1 as Bool;
76 pub const False: Bool = 0 as Bool;
78 // Consts for the LLVM CallConv type, pre-cast to usize.
80 #[derive(Copy, Clone, PartialEq)]
85 X86StdcallCallConv = 64,
86 X86FastcallCallConv = 65,
90 #[derive(Copy, Clone)]
92 LLVMDefaultVisibility = 0,
94 ProtectedVisibility = 2,
97 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
98 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
99 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
100 // they've been removed in upstream LLVM commit r203866.
101 #[derive(Copy, Clone)]
104 AvailableExternallyLinkage = 1,
105 LinkOnceAnyLinkage = 2,
106 LinkOnceODRLinkage = 3,
109 AppendingLinkage = 7,
112 ExternalWeakLinkage = 12,
117 #[derive(Copy, Clone, Debug)]
118 pub enum DiagnosticSeverity {
127 #[derive(Copy, Clone)]
128 pub enum DLLStorageClassTypes {
129 DefaultStorageClass = 0,
130 DLLImportStorageClass = 1,
131 DLLExportStorageClass = 2,
135 flags Attribute : u64 {
138 const NoReturn = 1 << 2,
139 const InReg = 1 << 3,
140 const StructRet = 1 << 4,
141 const NoUnwind = 1 << 5,
142 const NoAlias = 1 << 6,
143 const ByVal = 1 << 7,
145 const ReadNone = 1 << 9,
146 const ReadOnly = 1 << 10,
147 const NoInline = 1 << 11,
148 const AlwaysInline = 1 << 12,
149 const OptimizeForSize = 1 << 13,
150 const StackProtect = 1 << 14,
151 const StackProtectReq = 1 << 15,
152 const Alignment = 1 << 16,
153 const NoCapture = 1 << 21,
154 const NoRedZone = 1 << 22,
155 const NoImplicitFloat = 1 << 23,
156 const Naked = 1 << 24,
157 const InlineHint = 1 << 25,
158 const Stack = 7 << 26,
159 const ReturnsTwice = 1 << 29,
160 const UWTable = 1 << 30,
161 const NonLazyBind = 1 << 31,
162 const OptimizeNone = 1 << 42,
168 #[derive(Copy, Clone)]
169 pub enum OtherAttribute {
170 // The following are not really exposed in
171 // the LLVM C api so instead to add these
172 // we call a wrapper function in RustWrapper
173 // that uses the C++ api.
174 SanitizeAddressAttribute = 1 << 32,
175 MinSizeAttribute = 1 << 33,
176 NoDuplicateAttribute = 1 << 34,
177 StackProtectStrongAttribute = 1 << 35,
178 SanitizeThreadAttribute = 1 << 36,
179 SanitizeMemoryAttribute = 1 << 37,
180 NoBuiltinAttribute = 1 << 38,
181 ReturnedAttribute = 1 << 39,
182 ColdAttribute = 1 << 40,
183 BuiltinAttribute = 1 << 41,
184 OptimizeNoneAttribute = 1 << 42,
185 InAllocaAttribute = 1 << 43,
186 NonNullAttribute = 1 << 44,
189 #[derive(Copy, Clone)]
190 pub enum SpecialAttribute {
191 DereferenceableAttribute(u64)
195 #[derive(Copy, Clone)]
196 pub enum AttributeSet {
201 pub trait AttrHelper {
202 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
203 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
206 impl AttrHelper for Attribute {
207 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
209 LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
213 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
215 LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
220 impl AttrHelper for OtherAttribute {
221 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
223 LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
227 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
229 LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
234 impl AttrHelper for SpecialAttribute {
235 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
237 DereferenceableAttribute(bytes) => unsafe {
238 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
243 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
245 DereferenceableAttribute(bytes) => unsafe {
246 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
252 pub struct AttrBuilder {
253 attrs: Vec<(usize, Box<AttrHelper+'static>)>
257 pub fn new() -> AttrBuilder {
263 pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: usize, a: T) -> &'a mut AttrBuilder {
264 self.attrs.push((idx, box a as Box<AttrHelper+'static>));
268 pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
269 self.attrs.push((ReturnIndex as usize, box a as Box<AttrHelper+'static>));
273 pub fn apply_llfn(&self, llfn: ValueRef) {
274 for &(idx, ref attr) in &self.attrs {
275 attr.apply_llfn(idx as c_uint, llfn);
279 pub fn apply_callsite(&self, callsite: ValueRef) {
280 for &(idx, ref attr) in &self.attrs {
281 attr.apply_callsite(idx as c_uint, callsite);
286 // enum for the LLVM IntPredicate type
287 #[derive(Copy, Clone)]
288 pub enum IntPredicate {
301 // enum for the LLVM RealPredicate type
302 #[derive(Copy, Clone)]
303 pub enum RealPredicate {
304 RealPredicateFalse = 0,
319 RealPredicateTrue = 15,
322 // The LLVM TypeKind type - must stay in sync with the def of
323 // LLVMTypeKind in llvm/include/llvm-c/Core.h
324 #[derive(Copy, Clone, PartialEq, Debug)]
346 #[derive(Copy, Clone)]
347 pub enum AtomicBinOp {
362 #[derive(Copy, Clone)]
363 pub enum AtomicOrdering {
367 // Consume = 3, // Not specified yet.
371 SequentiallyConsistent = 7
375 #[derive(Copy, Clone)]
376 pub enum SynchronizationScope {
381 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
383 #[derive(Copy, Clone)]
385 AssemblyFileType = 0,
389 #[derive(Copy, Clone)]
390 pub enum MetadataType {
397 MD_invariant_load = 6,
401 MD_mem_parallel_loop_access = 10,
405 // Inline Asm Dialect
406 #[derive(Copy, Clone)]
407 pub enum AsmDialect {
412 #[derive(Copy, Clone, PartialEq)]
414 pub enum CodeGenOptLevel {
415 CodeGenLevelNone = 0,
416 CodeGenLevelLess = 1,
417 CodeGenLevelDefault = 2,
418 CodeGenLevelAggressive = 3,
421 #[derive(Copy, Clone, PartialEq)]
427 RelocDynamicNoPic = 3,
431 #[derive(Copy, Clone)]
432 pub enum CodeGenModel {
433 CodeModelDefault = 0,
434 CodeModelJITDefault = 1,
442 #[derive(Copy, Clone)]
443 pub enum DiagnosticKind {
446 DK_DebugMetadataVersion,
448 DK_OptimizationRemark,
449 DK_OptimizationRemarkMissed,
450 DK_OptimizationRemarkAnalysis,
451 DK_OptimizationFailure,
455 #[derive(Copy, Clone)]
456 pub enum ArchiveKind {
463 // Opaque pointer types
464 #[allow(missing_copy_implementations)]
465 pub enum Module_opaque {}
466 pub type ModuleRef = *mut Module_opaque;
467 #[allow(missing_copy_implementations)]
468 pub enum Context_opaque {}
469 pub type ContextRef = *mut Context_opaque;
470 #[allow(missing_copy_implementations)]
471 pub enum Type_opaque {}
472 pub type TypeRef = *mut Type_opaque;
473 #[allow(missing_copy_implementations)]
474 pub enum Value_opaque {}
475 pub type ValueRef = *mut Value_opaque;
476 #[allow(missing_copy_implementations)]
477 pub enum Metadata_opaque {}
478 pub type MetadataRef = *mut Metadata_opaque;
479 #[allow(missing_copy_implementations)]
480 pub enum BasicBlock_opaque {}
481 pub type BasicBlockRef = *mut BasicBlock_opaque;
482 #[allow(missing_copy_implementations)]
483 pub enum Builder_opaque {}
484 pub type BuilderRef = *mut Builder_opaque;
485 #[allow(missing_copy_implementations)]
486 pub enum ExecutionEngine_opaque {}
487 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
488 #[allow(missing_copy_implementations)]
489 pub enum MemoryBuffer_opaque {}
490 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
491 #[allow(missing_copy_implementations)]
492 pub enum PassManager_opaque {}
493 pub type PassManagerRef = *mut PassManager_opaque;
494 #[allow(missing_copy_implementations)]
495 pub enum PassManagerBuilder_opaque {}
496 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
497 #[allow(missing_copy_implementations)]
498 pub enum Use_opaque {}
499 pub type UseRef = *mut Use_opaque;
500 #[allow(missing_copy_implementations)]
501 pub enum TargetData_opaque {}
502 pub type TargetDataRef = *mut TargetData_opaque;
503 #[allow(missing_copy_implementations)]
504 pub enum ObjectFile_opaque {}
505 pub type ObjectFileRef = *mut ObjectFile_opaque;
506 #[allow(missing_copy_implementations)]
507 pub enum SectionIterator_opaque {}
508 pub type SectionIteratorRef = *mut SectionIterator_opaque;
509 #[allow(missing_copy_implementations)]
510 pub enum Pass_opaque {}
511 pub type PassRef = *mut Pass_opaque;
512 #[allow(missing_copy_implementations)]
513 pub enum TargetMachine_opaque {}
514 pub type TargetMachineRef = *mut TargetMachine_opaque;
515 pub enum Archive_opaque {}
516 pub type ArchiveRef = *mut Archive_opaque;
517 pub enum ArchiveIterator_opaque {}
518 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
519 pub enum ArchiveChild_opaque {}
520 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
521 #[allow(missing_copy_implementations)]
522 pub enum Twine_opaque {}
523 pub type TwineRef = *mut Twine_opaque;
524 #[allow(missing_copy_implementations)]
525 pub enum DiagnosticInfo_opaque {}
526 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
527 #[allow(missing_copy_implementations)]
528 pub enum DebugLoc_opaque {}
529 pub type DebugLocRef = *mut DebugLoc_opaque;
530 #[allow(missing_copy_implementations)]
531 pub enum SMDiagnostic_opaque {}
532 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
533 #[allow(missing_copy_implementations)]
534 pub enum RustArchiveMember_opaque {}
535 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
537 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
538 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
541 pub use self::DIDescriptorFlags::*;
542 use super::{MetadataRef};
544 #[allow(missing_copy_implementations)]
545 pub enum DIBuilder_opaque {}
546 pub type DIBuilderRef = *mut DIBuilder_opaque;
548 pub type DIDescriptor = MetadataRef;
549 pub type DIScope = DIDescriptor;
550 pub type DILocation = DIDescriptor;
551 pub type DIFile = DIScope;
552 pub type DILexicalBlock = DIScope;
553 pub type DISubprogram = DIScope;
554 pub type DINameSpace = DIScope;
555 pub type DIType = DIDescriptor;
556 pub type DIBasicType = DIType;
557 pub type DIDerivedType = DIType;
558 pub type DICompositeType = DIDerivedType;
559 pub type DIVariable = DIDescriptor;
560 pub type DIGlobalVariable = DIDescriptor;
561 pub type DIArray = DIDescriptor;
562 pub type DISubrange = DIDescriptor;
563 pub type DIEnumerator = DIDescriptor;
564 pub type DITemplateTypeParameter = DIDescriptor;
566 #[derive(Copy, Clone)]
567 pub enum DIDescriptorFlags {
568 FlagPrivate = 1 << 0,
569 FlagProtected = 1 << 1,
570 FlagFwdDecl = 1 << 2,
571 FlagAppleBlock = 1 << 3,
572 FlagBlockByrefStruct = 1 << 4,
573 FlagVirtual = 1 << 5,
574 FlagArtificial = 1 << 6,
575 FlagExplicit = 1 << 7,
576 FlagPrototyped = 1 << 8,
577 FlagObjcClassComplete = 1 << 9,
578 FlagObjectPointer = 1 << 10,
579 FlagVector = 1 << 11,
580 FlagStaticMember = 1 << 12,
581 FlagIndirectVariable = 1 << 13,
582 FlagLValueReference = 1 << 14,
583 FlagRValueReference = 1 << 15
588 // Link to our native llvm bindings (things that we need to use the C++ api
589 // for) and because llvm is written in C++ we need to link against libstdc++
591 // You'll probably notice that there is an omission of all LLVM libraries
592 // from this location. This is because the set of LLVM libraries that we
593 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
594 // figure out the exact set of libraries. To do this, the build system
595 // generates an llvmdeps.rs file next to this one which will be
596 // automatically updated whenever LLVM is updated to include an up-to-date
597 // set of the libraries we need to link to LLVM for.
598 #[link(name = "rustllvm", kind = "static")]
599 #[linked_from = "rustllvm"] // not quite true but good enough
601 /* Create and destroy contexts. */
602 pub fn LLVMContextCreate() -> ContextRef;
603 pub fn LLVMContextDispose(C: ContextRef);
604 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
609 /* Create and destroy modules. */
610 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
613 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
614 pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
615 pub fn LLVMDisposeModule(M: ModuleRef);
617 /// Data layout. See Module::getDataLayout.
618 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
619 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
621 /// Target triple. See Module::getTargetTriple.
622 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
623 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
625 /// See Module::dump.
626 pub fn LLVMDumpModule(M: ModuleRef);
628 /// See Module::setModuleInlineAsm.
629 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
631 /// See llvm::LLVMTypeKind::getTypeID.
632 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
634 /// See llvm::LLVMType::getContext.
635 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
637 /* Operations on integer types */
638 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
639 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
640 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
641 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
642 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
643 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
646 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
648 /* Operations on real types */
649 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
650 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
651 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
652 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
653 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
655 /* Operations on function types */
656 pub fn LLVMFunctionType(ReturnType: TypeRef,
657 ParamTypes: *const TypeRef,
661 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
662 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
663 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
664 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
666 /* Operations on struct types */
667 pub fn LLVMStructTypeInContext(C: ContextRef,
668 ElementTypes: *const TypeRef,
669 ElementCount: c_uint,
672 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
673 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
675 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
677 /* Operations on array, pointer, and vector types (sequence types) */
678 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
679 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
681 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
684 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
685 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
686 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
687 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
689 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
691 /* Operations on other types */
692 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
693 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
694 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
696 /* Operations on all values */
697 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
698 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
699 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
700 pub fn LLVMDumpValue(Val: ValueRef);
701 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
702 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
703 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
704 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
706 /* Operations on Uses */
707 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
708 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
709 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
710 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
712 /* Operations on Users */
713 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
714 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
715 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
717 /* Operations on constants of any type */
718 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
720 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
721 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
723 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
725 /* only for isize/vector */
726 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
727 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
728 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
729 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
730 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
732 /* Operations on metadata */
733 pub fn LLVMMDStringInContext(C: ContextRef,
737 pub fn LLVMMDNodeInContext(C: ContextRef,
738 Vals: *const ValueRef,
741 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
745 /* Operations on scalar constants */
746 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
748 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
750 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
755 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
756 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
758 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
762 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
763 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
766 /* Operations on composite constants */
767 pub fn LLVMConstStringInContext(C: ContextRef,
770 DontNullTerminate: Bool)
772 pub fn LLVMConstStructInContext(C: ContextRef,
773 ConstantVals: *const ValueRef,
778 pub fn LLVMConstArray(ElementTy: TypeRef,
779 ConstantVals: *const ValueRef,
782 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
785 /* Constant expressions */
786 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
787 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
788 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
789 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
790 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
791 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
792 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
793 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
795 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
797 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
799 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
801 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
803 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
805 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
807 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
809 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
811 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
813 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
815 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
817 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
819 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
821 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
822 RHSConstant: ValueRef)
824 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
826 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
828 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
830 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
832 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
834 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
836 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
838 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
840 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
842 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
844 pub fn LLVMConstGEP(ConstantVal: ValueRef,
845 ConstantIndices: *const ValueRef,
848 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
849 ConstantIndices: *const ValueRef,
852 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
854 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
856 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
858 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
860 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
862 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
864 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
866 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
868 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
870 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
872 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
874 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
876 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
878 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
880 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
882 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
884 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
888 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
890 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
891 ConstantIfTrue: ValueRef,
892 ConstantIfFalse: ValueRef)
894 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
895 IndexConstant: ValueRef)
897 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
898 ElementValueConstant: ValueRef,
899 IndexConstant: ValueRef)
901 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
902 VectorBConstant: ValueRef,
903 MaskConstant: ValueRef)
905 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
906 IdxList: *const c_uint,
909 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
910 ElementValueConstant: ValueRef,
911 IdxList: *const c_uint,
914 pub fn LLVMConstInlineAsm(Ty: TypeRef,
915 AsmString: *const c_char,
916 Constraints: *const c_char,
917 HasSideEffects: Bool,
920 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
924 /* Operations on global variables, functions, and aliases (globals) */
925 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
926 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
927 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
928 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
929 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
930 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
931 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
932 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
933 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
934 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
937 /* Operations on global variables */
938 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
939 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
941 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
944 AddressSpace: c_uint)
946 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
947 pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
948 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
949 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
950 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
951 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
952 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
953 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
954 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
955 ConstantVal: ValueRef);
956 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
957 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
958 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
959 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
960 pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
962 /* Operations on aliases */
963 pub fn LLVMAddAlias(M: ModuleRef,
969 /* Operations on functions */
970 pub fn LLVMAddFunction(M: ModuleRef,
974 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
975 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
976 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
977 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
978 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
979 pub fn LLVMDeleteFunction(Fn: ValueRef);
980 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
984 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
985 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
986 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
987 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
988 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
989 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
990 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
991 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
992 pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
994 Value: *const c_char);
995 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
996 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
997 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
999 /* Operations on parameters */
1000 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1001 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1002 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1003 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1004 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1005 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1006 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1007 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1008 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1009 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1010 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1011 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1013 /* Operations on basic blocks */
1014 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1015 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1016 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1017 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1018 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1019 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1020 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1021 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1022 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1023 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1024 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1026 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1028 Name: *const c_char)
1030 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1032 Name: *const c_char)
1034 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1036 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1037 MoveAfter: BasicBlockRef);
1039 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1040 MoveBefore: BasicBlockRef);
1042 /* Operations on instructions */
1043 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1044 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1045 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1046 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1047 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1048 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1050 /* Operations on call sites */
1051 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1052 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1053 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1056 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1059 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1062 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1065 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1069 /* Operations on call instructions (only) */
1070 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1071 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1073 /* Operations on load/store instructions (only) */
1074 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1075 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1077 /* Operations on phi nodes */
1078 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1079 IncomingValues: *const ValueRef,
1080 IncomingBlocks: *const BasicBlockRef,
1082 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1083 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1085 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1088 /* Instruction builders */
1089 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1090 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1091 Block: BasicBlockRef,
1093 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1095 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1096 Block: BasicBlockRef);
1097 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1098 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1099 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1100 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1102 Name: *const c_char);
1103 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1105 /* Execution engine */
1106 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1107 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1108 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1109 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1110 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1111 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1115 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1116 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1117 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1120 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1121 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1122 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1123 RetVals: *const ValueRef,
1126 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1127 pub fn LLVMBuildCondBr(B: BuilderRef,
1129 Then: BasicBlockRef,
1130 Else: BasicBlockRef)
1132 pub fn LLVMBuildSwitch(B: BuilderRef,
1134 Else: BasicBlockRef,
1137 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1141 pub fn LLVMBuildInvoke(B: BuilderRef,
1143 Args: *const ValueRef,
1145 Then: BasicBlockRef,
1146 Catch: BasicBlockRef,
1147 Name: *const c_char)
1149 pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1153 Name: *const c_char,
1156 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1157 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1159 /* Add a case to the switch instruction */
1160 pub fn LLVMAddCase(Switch: ValueRef,
1162 Dest: BasicBlockRef);
1164 /* Add a destination to the indirectbr instruction */
1165 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1167 /* Add a clause to the landing pad instruction */
1168 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1170 /* Set the cleanup on a landing pad instruction */
1171 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1174 pub fn LLVMBuildAdd(B: BuilderRef,
1177 Name: *const c_char)
1179 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1182 Name: *const c_char)
1184 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1187 Name: *const c_char)
1189 pub fn LLVMBuildFAdd(B: BuilderRef,
1192 Name: *const c_char)
1194 pub fn LLVMBuildSub(B: BuilderRef,
1197 Name: *const c_char)
1199 pub fn LLVMBuildNSWSub(B: BuilderRef,
1202 Name: *const c_char)
1204 pub fn LLVMBuildNUWSub(B: BuilderRef,
1207 Name: *const c_char)
1209 pub fn LLVMBuildFSub(B: BuilderRef,
1212 Name: *const c_char)
1214 pub fn LLVMBuildMul(B: BuilderRef,
1217 Name: *const c_char)
1219 pub fn LLVMBuildNSWMul(B: BuilderRef,
1222 Name: *const c_char)
1224 pub fn LLVMBuildNUWMul(B: BuilderRef,
1227 Name: *const c_char)
1229 pub fn LLVMBuildFMul(B: BuilderRef,
1232 Name: *const c_char)
1234 pub fn LLVMBuildUDiv(B: BuilderRef,
1237 Name: *const c_char)
1239 pub fn LLVMBuildSDiv(B: BuilderRef,
1242 Name: *const c_char)
1244 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1247 Name: *const c_char)
1249 pub fn LLVMBuildFDiv(B: BuilderRef,
1252 Name: *const c_char)
1254 pub fn LLVMBuildURem(B: BuilderRef,
1257 Name: *const c_char)
1259 pub fn LLVMBuildSRem(B: BuilderRef,
1262 Name: *const c_char)
1264 pub fn LLVMBuildFRem(B: BuilderRef,
1267 Name: *const c_char)
1269 pub fn LLVMBuildShl(B: BuilderRef,
1272 Name: *const c_char)
1274 pub fn LLVMBuildLShr(B: BuilderRef,
1277 Name: *const c_char)
1279 pub fn LLVMBuildAShr(B: BuilderRef,
1282 Name: *const c_char)
1284 pub fn LLVMBuildAnd(B: BuilderRef,
1287 Name: *const c_char)
1289 pub fn LLVMBuildOr(B: BuilderRef,
1292 Name: *const c_char)
1294 pub fn LLVMBuildXor(B: BuilderRef,
1297 Name: *const c_char)
1299 pub fn LLVMBuildBinOp(B: BuilderRef,
1303 Name: *const c_char)
1305 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1307 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1309 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1311 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1313 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1317 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1319 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1320 pub fn LLVMBuildLoad(B: BuilderRef,
1321 PointerVal: ValueRef,
1322 Name: *const c_char)
1325 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1328 pub fn LLVMBuildGEP(B: BuilderRef,
1330 Indices: *const ValueRef,
1332 Name: *const c_char)
1334 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1336 Indices: *const ValueRef,
1338 Name: *const c_char)
1340 pub fn LLVMBuildStructGEP(B: BuilderRef,
1343 Name: *const c_char)
1345 pub fn LLVMBuildGlobalString(B: BuilderRef,
1347 Name: *const c_char)
1349 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1351 Name: *const c_char)
1355 pub fn LLVMBuildTrunc(B: BuilderRef,
1358 Name: *const c_char)
1360 pub fn LLVMBuildZExt(B: BuilderRef,
1363 Name: *const c_char)
1365 pub fn LLVMBuildSExt(B: BuilderRef,
1368 Name: *const c_char)
1370 pub fn LLVMBuildFPToUI(B: BuilderRef,
1373 Name: *const c_char)
1375 pub fn LLVMBuildFPToSI(B: BuilderRef,
1378 Name: *const c_char)
1380 pub fn LLVMBuildUIToFP(B: BuilderRef,
1383 Name: *const c_char)
1385 pub fn LLVMBuildSIToFP(B: BuilderRef,
1388 Name: *const c_char)
1390 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1393 Name: *const c_char)
1395 pub fn LLVMBuildFPExt(B: BuilderRef,
1398 Name: *const c_char)
1400 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1403 Name: *const c_char)
1405 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1408 Name: *const c_char)
1410 pub fn LLVMBuildBitCast(B: BuilderRef,
1413 Name: *const c_char)
1415 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1418 Name: *const c_char)
1420 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1423 Name: *const c_char)
1425 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1428 Name: *const c_char)
1430 pub fn LLVMBuildCast(B: BuilderRef,
1434 Name: *const c_char) -> ValueRef;
1435 pub fn LLVMBuildPointerCast(B: BuilderRef,
1438 Name: *const c_char)
1440 pub fn LLVMBuildIntCast(B: BuilderRef,
1443 Name: *const c_char)
1445 pub fn LLVMBuildFPCast(B: BuilderRef,
1448 Name: *const c_char)
1452 pub fn LLVMBuildICmp(B: BuilderRef,
1456 Name: *const c_char)
1458 pub fn LLVMBuildFCmp(B: BuilderRef,
1462 Name: *const c_char)
1465 /* Miscellaneous instructions */
1466 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1468 pub fn LLVMBuildCall(B: BuilderRef,
1470 Args: *const ValueRef,
1472 Name: *const c_char)
1474 pub fn LLVMBuildSelect(B: BuilderRef,
1478 Name: *const c_char)
1480 pub fn LLVMBuildVAArg(B: BuilderRef,
1483 Name: *const c_char)
1485 pub fn LLVMBuildExtractElement(B: BuilderRef,
1488 Name: *const c_char)
1490 pub fn LLVMBuildInsertElement(B: BuilderRef,
1494 Name: *const c_char)
1496 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1500 Name: *const c_char)
1502 pub fn LLVMBuildExtractValue(B: BuilderRef,
1505 Name: *const c_char)
1507 pub fn LLVMBuildInsertValue(B: BuilderRef,
1511 Name: *const c_char)
1514 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1516 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1518 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1521 Name: *const c_char)
1524 /* Atomic Operations */
1525 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1526 PointerVal: ValueRef,
1527 Name: *const c_char,
1528 Order: AtomicOrdering,
1532 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1535 Order: AtomicOrdering,
1539 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1543 Order: AtomicOrdering,
1544 FailureOrder: AtomicOrdering)
1546 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1550 Order: AtomicOrdering,
1551 SingleThreaded: Bool)
1554 pub fn LLVMBuildAtomicFence(B: BuilderRef,
1555 Order: AtomicOrdering,
1556 Scope: SynchronizationScope);
1559 /* Selected entries from the downcasts. */
1560 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1561 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1563 /// Writes a module to the specified path. Returns 0 on success.
1564 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1566 /// Creates target data from a target layout string.
1567 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1568 /// Adds the target data to the given pass manager. The pass manager
1569 /// references the target data only weakly.
1570 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1571 /// Number of bytes clobbered when doing a Store to *T.
1572 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1575 /// Number of bytes clobbered when doing a Store to *T.
1576 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1579 /// Distance between successive elements in an array of T. Includes ABI padding.
1580 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1582 /// Returns the preferred alignment of a type.
1583 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1585 /// Returns the minimum alignment of a type.
1586 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1589 /// Computes the byte offset of the indexed struct element for a
1591 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1596 /// Returns the minimum alignment of a type when part of a call frame.
1597 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1600 /// Disposes target data.
1601 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1603 /// Creates a pass manager.
1604 pub fn LLVMCreatePassManager() -> PassManagerRef;
1606 /// Creates a function-by-function pass manager
1607 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1610 /// Disposes a pass manager.
1611 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1613 /// Runs a pass manager on a module.
1614 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1616 /// Runs the function passes on the provided function.
1617 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1620 /// Initializes all the function passes scheduled in the manager
1621 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1623 /// Finalizes all the function passes scheduled in the manager
1624 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1626 pub fn LLVMInitializePasses();
1628 /// Adds a verification pass.
1629 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1631 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1632 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1633 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1634 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1635 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1636 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1637 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1638 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1639 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1640 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1641 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1642 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1643 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1644 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1645 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1646 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1647 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1648 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1649 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1650 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1651 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1652 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1653 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1654 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1655 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1656 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1657 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1658 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1659 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1660 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1661 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1662 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1663 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1664 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1665 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1667 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1668 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1669 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1670 OptimizationLevel: c_uint);
1671 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1673 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1674 PMB: PassManagerBuilderRef,
1676 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1677 PMB: PassManagerBuilderRef,
1679 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1680 PMB: PassManagerBuilderRef,
1682 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1683 PMB: PassManagerBuilderRef,
1685 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1686 PMB: PassManagerBuilderRef,
1687 PM: PassManagerRef);
1689 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1690 PMB: PassManagerBuilderRef,
1691 PM: PassManagerRef);
1692 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1693 PMB: PassManagerBuilderRef,
1698 /// Destroys a memory buffer.
1699 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1702 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1704 /// Opens an object file.
1705 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1706 /// Closes an object file.
1707 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1709 /// Enumerates the sections in an object file.
1710 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1711 /// Destroys a section iterator.
1712 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1713 /// Returns true if the section iterator is at the end of the section
1715 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1716 SI: SectionIteratorRef)
1718 /// Moves the section iterator to point to the next section.
1719 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1720 /// Returns the current section size.
1721 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1722 /// Returns the current section contents as a string buffer.
1723 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1725 /// Reads the given file and returns it as a memory buffer. Use
1726 /// LLVMDisposeMemoryBuffer() to get rid of it.
1727 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1729 /// Borrows the contents of the memory buffer (doesn't copy it)
1730 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1731 InputDataLength: size_t,
1732 BufferName: *const c_char,
1735 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1736 InputDataLength: size_t,
1737 BufferName: *const c_char)
1740 pub fn LLVMIsMultithreaded() -> Bool;
1741 pub fn LLVMStartMultithreaded() -> Bool;
1743 /// Returns a string describing the last error caused by an LLVMRust* call.
1744 pub fn LLVMRustGetLastError() -> *const c_char;
1746 /// Print the pass timings since static dtors aren't picking them up.
1747 pub fn LLVMRustPrintPassTimings();
1749 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1751 pub fn LLVMStructSetBody(StructTy: TypeRef,
1752 ElementTypes: *const TypeRef,
1753 ElementCount: c_uint,
1756 pub fn LLVMConstNamedStruct(S: TypeRef,
1757 ConstantVals: *const ValueRef,
1761 /// Enables LLVM debug output.
1762 pub fn LLVMSetDebug(Enabled: c_int);
1764 /// Prepares inline assembly.
1765 pub fn LLVMInlineAsm(Ty: TypeRef,
1766 AsmString: *const c_char,
1767 Constraints: *const c_char,
1773 pub fn LLVMRustDebugMetadataVersion() -> u32;
1774 pub fn LLVMVersionMajor() -> u32;
1775 pub fn LLVMVersionMinor() -> u32;
1777 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1778 name: *const c_char,
1781 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1783 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1785 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1787 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1789 File: *const c_char,
1791 Producer: *const c_char,
1793 Flags: *const c_char,
1795 SplitName: *const c_char)
1798 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1799 Filename: *const c_char,
1800 Directory: *const c_char)
1803 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1805 ParameterTypes: DIArray)
1808 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1809 Scope: DIDescriptor,
1810 Name: *const c_char,
1811 LinkageName: *const c_char,
1815 isLocalToUnit: bool,
1825 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1826 Name: *const c_char,
1827 SizeInBits: c_ulonglong,
1828 AlignInBits: c_ulonglong,
1832 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1834 SizeInBits: c_ulonglong,
1835 AlignInBits: c_ulonglong,
1836 Name: *const c_char)
1839 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1840 Scope: DIDescriptor,
1841 Name: *const c_char,
1844 SizeInBits: c_ulonglong,
1845 AlignInBits: c_ulonglong,
1847 DerivedFrom: DIType,
1849 RunTimeLang: c_uint,
1850 VTableHolder: DIType,
1851 UniqueId: *const c_char)
1854 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1855 Scope: DIDescriptor,
1856 Name: *const c_char,
1859 SizeInBits: c_ulonglong,
1860 AlignInBits: c_ulonglong,
1861 OffsetInBits: c_ulonglong,
1866 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1873 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1875 Name: *const c_char,
1876 LinkageName: *const c_char,
1880 isLocalToUnit: bool,
1883 -> DIGlobalVariable;
1885 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1887 Scope: DIDescriptor,
1888 Name: *const c_char,
1892 AlwaysPreserve: bool,
1894 AddrOps: *const i64,
1895 AddrOpsCount: c_uint,
1899 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1901 AlignInBits: c_ulonglong,
1903 Subscripts: DIArray)
1906 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1908 AlignInBits: c_ulonglong,
1910 Subscripts: DIArray)
1913 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1918 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1919 Ptr: *const DIDescriptor,
1923 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1925 VarInfo: DIVariable,
1926 AddrOps: *const i64,
1927 AddrOpsCount: c_uint,
1929 InsertAtEnd: BasicBlockRef)
1932 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1934 VarInfo: DIVariable,
1935 AddrOps: *const i64,
1936 AddrOpsCount: c_uint,
1938 InsertBefore: ValueRef)
1941 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1942 Name: *const c_char,
1946 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1948 Name: *const c_char,
1951 SizeInBits: c_ulonglong,
1952 AlignInBits: c_ulonglong,
1957 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1959 Name: *const c_char,
1962 SizeInBits: c_ulonglong,
1963 AlignInBits: c_ulonglong,
1966 RunTimeLang: c_uint,
1967 UniqueId: *const c_char)
1970 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1972 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1974 Name: *const c_char,
1979 -> DITemplateTypeParameter;
1981 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1983 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1985 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1987 Name: *const c_char,
1992 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
1996 InlinedAt: MetadataRef)
1999 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2000 CompositeType: DIType,
2001 TypeArray: DIArray);
2002 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2003 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2005 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2007 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2008 pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2010 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
2011 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2013 Features: *const c_char,
2014 Model: CodeGenModel,
2016 Level: CodeGenOptLevel,
2018 PositionIndependentExecutable: bool,
2019 FunctionSections: bool,
2020 DataSections: bool) -> TargetMachineRef;
2021 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2022 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2025 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2027 DisableSimplifyLibCalls: bool);
2028 pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2029 OptLevel: CodeGenOptLevel,
2030 MergeFunctions: bool,
2032 LoopVectorize: bool);
2033 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2034 DisableSimplifyLibCalls: bool);
2035 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2036 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2039 Output: *const c_char,
2040 FileType: FileType) -> bool;
2041 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2043 Output: *const c_char);
2044 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2045 pub fn LLVMRustPrintPasses();
2046 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2047 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2048 AddLifetimes: bool);
2049 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2051 len: size_t) -> bool;
2052 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2053 syms: *const *const c_char,
2055 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2057 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2058 pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2059 pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2060 pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2061 size: *mut size_t) -> *const c_char;
2062 pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2063 size: *mut size_t) -> *const c_char;
2064 pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2065 pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2066 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2068 pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2069 C: DLLStorageClassTypes);
2071 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2072 data: *mut *const c_char) -> c_int;
2074 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2076 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2077 Handler: DiagnosticHandler,
2078 DiagnosticContext: *mut c_void);
2080 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2081 pass_name_out: *mut *const c_char,
2082 function_out: *mut ValueRef,
2083 debugloc_out: *mut DebugLocRef,
2084 message_out: *mut TwineRef);
2085 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2086 cookie_out: *mut c_uint,
2087 message_out: *mut TwineRef,
2088 instruction_out: *mut ValueRef);
2090 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2091 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2092 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2094 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2096 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2097 H: InlineAsmDiagHandler,
2100 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2102 pub fn LLVMRustWriteArchive(Dst: *const c_char,
2104 Members: *const RustArchiveMemberRef,
2106 Kind: ArchiveKind) -> c_int;
2107 pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2108 Name: *const c_char,
2109 Child: ArchiveChildRef) -> RustArchiveMemberRef;
2110 pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2112 pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2113 TM: TargetMachineRef);
2114 pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2117 #[cfg(have_component_x86)]
2119 pub fn LLVMInitializeX86TargetInfo();
2120 pub fn LLVMInitializeX86Target();
2121 pub fn LLVMInitializeX86TargetMC();
2122 pub fn LLVMInitializeX86AsmPrinter();
2123 pub fn LLVMInitializeX86AsmParser();
2125 #[cfg(have_component_arm)]
2127 pub fn LLVMInitializeARMTargetInfo();
2128 pub fn LLVMInitializeARMTarget();
2129 pub fn LLVMInitializeARMTargetMC();
2130 pub fn LLVMInitializeARMAsmPrinter();
2131 pub fn LLVMInitializeARMAsmParser();
2133 #[cfg(have_component_aarch64)]
2135 pub fn LLVMInitializeAArch64TargetInfo();
2136 pub fn LLVMInitializeAArch64Target();
2137 pub fn LLVMInitializeAArch64TargetMC();
2138 pub fn LLVMInitializeAArch64AsmPrinter();
2139 pub fn LLVMInitializeAArch64AsmParser();
2141 #[cfg(have_component_mips)]
2143 pub fn LLVMInitializeMipsTargetInfo();
2144 pub fn LLVMInitializeMipsTarget();
2145 pub fn LLVMInitializeMipsTargetMC();
2146 pub fn LLVMInitializeMipsAsmPrinter();
2147 pub fn LLVMInitializeMipsAsmParser();
2149 #[cfg(have_component_powerpc)]
2151 pub fn LLVMInitializePowerPCTargetInfo();
2152 pub fn LLVMInitializePowerPCTarget();
2153 pub fn LLVMInitializePowerPCTargetMC();
2154 pub fn LLVMInitializePowerPCAsmPrinter();
2155 pub fn LLVMInitializePowerPCAsmParser();
2157 #[cfg(have_component_pnacl)]
2159 pub fn LLVMInitializePNaClTargetInfo();
2160 pub fn LLVMInitializePNaClTarget();
2161 pub fn LLVMInitializePNaClTargetMC();
2164 // LLVM requires symbols from this library, but apparently they're not printed
2165 // during llvm-config?
2167 #[link(name = "ole32")]
2170 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2172 LLVMSetInstructionCallConv(instr, cc as c_uint);
2175 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2177 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2180 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2182 LLVMSetLinkage(global, link as c_uint);
2186 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2188 LLVMRustSetDLLStorageClass(global, class);
2192 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2194 LLVMSetUnnamedAddr(global, unnamed as Bool);
2198 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2200 LLVMSetThreadLocal(global, is_thread_local as Bool);
2204 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2206 LLVMConstICmp(pred as c_ushort, v1, v2)
2209 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2211 LLVMConstFCmp(pred as c_ushort, v1, v2)
2215 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2217 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2218 attr.bits() as uint64_t)
2222 /* Memory-managed interface to target data. */
2224 pub struct TargetData {
2225 pub lltd: TargetDataRef
2228 impl Drop for TargetData {
2229 fn drop(&mut self) {
2231 LLVMDisposeTargetData(self.lltd);
2236 pub fn mk_target_data(string_rep: &str) -> TargetData {
2237 let string_rep = CString::new(string_rep).unwrap();
2239 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2243 /* Memory-managed interface to object files. */
2245 pub struct ObjectFile {
2246 pub llof: ObjectFileRef,
2250 // This will take ownership of llmb
2251 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2253 let llof = LLVMCreateObjectFile(llmb);
2254 if llof as isize == 0 {
2255 // LLVMCreateObjectFile took ownership of llmb
2266 impl Drop for ObjectFile {
2267 fn drop(&mut self) {
2269 LLVMDisposeObjectFile(self.llof);
2274 /* Memory-managed interface to section iterators. */
2276 pub struct SectionIter {
2277 pub llsi: SectionIteratorRef
2280 impl Drop for SectionIter {
2281 fn drop(&mut self) {
2283 LLVMDisposeSectionIterator(self.llsi);
2288 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2291 llsi: LLVMGetSections(llof)
2296 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2297 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2299 assert!(index < LLVMCountParams(llfn));
2300 LLVMGetParam(llfn, index)
2304 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2306 let num_params = LLVMCountParams(llfn);
2307 let mut params = Vec::with_capacity(num_params as usize);
2308 for idx in 0..num_params {
2309 params.push(LLVMGetParam(llfn, idx));
2316 #[allow(missing_copy_implementations)]
2317 pub enum RustString_opaque {}
2318 pub type RustStringRef = *mut RustString_opaque;
2319 type RustStringRepr = *mut RefCell<Vec<u8>>;
2321 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2323 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2326 let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2328 let sr = sr as RustStringRepr;
2329 (*sr).borrow_mut().extend_from_slice(slice);
2332 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2333 let mut buf = RefCell::new(Vec::new());
2334 f(&mut buf as RustStringRepr as RustStringRef);
2335 String::from_utf8(buf.into_inner()).ok()
2338 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2339 build_string(|s| LLVMWriteTwineToString(tr, s))
2340 .expect("got a non-UTF8 Twine from LLVM")
2343 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2344 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2345 .expect("got a non-UTF8 DebugLoc from LLVM")
2348 pub fn initialize_available_targets() {
2349 macro_rules! init_target(
2350 ($cfg:ident $arch:ident) => { {
2354 let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
2356 let f = concat_idents!(LLVMInitialize, $arch, Target);
2358 let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
2360 let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
2362 let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
2372 init_target!(have_component_powerpc PowerPC);
2373 init_target!(have_component_mips Mips);
2374 init_target!(have_component_aarch64 AArch64);
2375 init_target!(have_component_arm ARM);
2376 init_target!(have_component_x86 X86);
2378 // PNaCl doesn't provide some of the optional target components, so we
2379 // manually initialize it here.
2380 #[cfg(have_component_pnacl)]
2383 LLVMInitializePNaClTargetInfo();
2384 LLVMInitializePNaClTarget();
2385 LLVMInitializePNaClTargetMC();
2388 #[cfg(not(have_component_pnacl))]
2393 // The module containing the native LLVM dependencies, generated by the build system
2394 // Note that this must come after the rustllvm extern declaration so that
2395 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2396 // Works to the above fix for #15460 to ensure LLVM dependencies that
2397 // are only used by rustllvm don't get stripped by the linker.
2399 include! { env!("CFG_LLVM_LINKAGE_FILE") }