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,
91 #[derive(Copy, Clone)]
93 LLVMDefaultVisibility = 0,
95 ProtectedVisibility = 2,
98 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
99 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
100 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
101 // they've been removed in upstream LLVM commit r203866.
102 #[derive(Copy, Clone)]
105 AvailableExternallyLinkage = 1,
106 LinkOnceAnyLinkage = 2,
107 LinkOnceODRLinkage = 3,
110 AppendingLinkage = 7,
113 ExternalWeakLinkage = 12,
118 #[derive(Copy, Clone, Debug)]
119 pub enum DiagnosticSeverity {
128 #[derive(Copy, Clone)]
129 pub enum DLLStorageClassTypes {
130 DefaultStorageClass = 0,
131 DLLImportStorageClass = 1,
132 DLLExportStorageClass = 2,
136 flags Attribute : u64 {
139 const NoReturn = 1 << 2,
140 const InReg = 1 << 3,
141 const StructRet = 1 << 4,
142 const NoUnwind = 1 << 5,
143 const NoAlias = 1 << 6,
144 const ByVal = 1 << 7,
146 const ReadNone = 1 << 9,
147 const ReadOnly = 1 << 10,
148 const NoInline = 1 << 11,
149 const AlwaysInline = 1 << 12,
150 const OptimizeForSize = 1 << 13,
151 const StackProtect = 1 << 14,
152 const StackProtectReq = 1 << 15,
153 const Alignment = 1 << 16,
154 const NoCapture = 1 << 21,
155 const NoRedZone = 1 << 22,
156 const NoImplicitFloat = 1 << 23,
157 const Naked = 1 << 24,
158 const InlineHint = 1 << 25,
159 const Stack = 7 << 26,
160 const ReturnsTwice = 1 << 29,
161 const UWTable = 1 << 30,
162 const NonLazyBind = 1 << 31,
163 const OptimizeNone = 1 << 42,
169 #[derive(Copy, Clone)]
170 pub enum OtherAttribute {
171 // The following are not really exposed in
172 // the LLVM C api so instead to add these
173 // we call a wrapper function in RustWrapper
174 // that uses the C++ api.
175 SanitizeAddressAttribute = 1 << 32,
176 MinSizeAttribute = 1 << 33,
177 NoDuplicateAttribute = 1 << 34,
178 StackProtectStrongAttribute = 1 << 35,
179 SanitizeThreadAttribute = 1 << 36,
180 SanitizeMemoryAttribute = 1 << 37,
181 NoBuiltinAttribute = 1 << 38,
182 ReturnedAttribute = 1 << 39,
183 ColdAttribute = 1 << 40,
184 BuiltinAttribute = 1 << 41,
185 OptimizeNoneAttribute = 1 << 42,
186 InAllocaAttribute = 1 << 43,
187 NonNullAttribute = 1 << 44,
190 #[derive(Copy, Clone)]
191 pub enum SpecialAttribute {
192 DereferenceableAttribute(u64)
196 #[derive(Copy, Clone)]
197 pub enum AttributeSet {
202 pub trait AttrHelper {
203 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
204 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
207 impl AttrHelper for Attribute {
208 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
210 LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
214 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
216 LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
221 impl AttrHelper for OtherAttribute {
222 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
224 LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
228 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
230 LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
235 impl AttrHelper for SpecialAttribute {
236 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
238 DereferenceableAttribute(bytes) => unsafe {
239 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
244 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
246 DereferenceableAttribute(bytes) => unsafe {
247 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
253 pub struct AttrBuilder {
254 attrs: Vec<(usize, Box<AttrHelper+'static>)>
258 pub fn new() -> AttrBuilder {
264 pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: usize, a: T) -> &'a mut AttrBuilder {
265 self.attrs.push((idx, box a as Box<AttrHelper+'static>));
269 pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
270 self.attrs.push((ReturnIndex as usize, box a as Box<AttrHelper+'static>));
274 pub fn apply_llfn(&self, llfn: ValueRef) {
275 for &(idx, ref attr) in &self.attrs {
276 attr.apply_llfn(idx as c_uint, llfn);
280 pub fn apply_callsite(&self, callsite: ValueRef) {
281 for &(idx, ref attr) in &self.attrs {
282 attr.apply_callsite(idx as c_uint, callsite);
287 // enum for the LLVM IntPredicate type
288 #[derive(Copy, Clone)]
289 pub enum IntPredicate {
302 // enum for the LLVM RealPredicate type
303 #[derive(Copy, Clone)]
304 pub enum RealPredicate {
305 RealPredicateFalse = 0,
320 RealPredicateTrue = 15,
323 // The LLVM TypeKind type - must stay in sync with the def of
324 // LLVMTypeKind in llvm/include/llvm-c/Core.h
325 #[derive(Copy, Clone, PartialEq, Debug)]
347 #[derive(Copy, Clone)]
348 pub enum AtomicBinOp {
363 #[derive(Copy, Clone)]
364 pub enum AtomicOrdering {
368 // Consume = 3, // Not specified yet.
372 SequentiallyConsistent = 7
376 #[derive(Copy, Clone)]
377 pub enum SynchronizationScope {
382 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
384 #[derive(Copy, Clone)]
386 AssemblyFileType = 0,
390 #[derive(Copy, Clone)]
391 pub enum MetadataType {
398 MD_invariant_load = 6,
402 MD_mem_parallel_loop_access = 10,
406 // Inline Asm Dialect
407 #[derive(Copy, Clone)]
408 pub enum AsmDialect {
413 #[derive(Copy, Clone, PartialEq)]
415 pub enum CodeGenOptLevel {
416 CodeGenLevelNone = 0,
417 CodeGenLevelLess = 1,
418 CodeGenLevelDefault = 2,
419 CodeGenLevelAggressive = 3,
422 #[derive(Copy, Clone, PartialEq)]
428 RelocDynamicNoPic = 3,
432 #[derive(Copy, Clone)]
433 pub enum CodeGenModel {
434 CodeModelDefault = 0,
435 CodeModelJITDefault = 1,
443 #[derive(Copy, Clone)]
444 pub enum DiagnosticKind {
447 DK_DebugMetadataVersion,
449 DK_OptimizationRemark,
450 DK_OptimizationRemarkMissed,
451 DK_OptimizationRemarkAnalysis,
452 DK_OptimizationFailure,
456 #[derive(Copy, Clone)]
457 pub enum ArchiveKind {
464 /// Represents the different LLVM passes Rust supports
465 #[derive(Copy, Clone, PartialEq, Debug)]
467 pub enum SupportedPassKind {
473 // Opaque pointer types
474 #[allow(missing_copy_implementations)]
475 pub enum Module_opaque {}
476 pub type ModuleRef = *mut Module_opaque;
477 #[allow(missing_copy_implementations)]
478 pub enum Context_opaque {}
479 pub type ContextRef = *mut Context_opaque;
480 #[allow(missing_copy_implementations)]
481 pub enum Type_opaque {}
482 pub type TypeRef = *mut Type_opaque;
483 #[allow(missing_copy_implementations)]
484 pub enum Value_opaque {}
485 pub type ValueRef = *mut Value_opaque;
486 #[allow(missing_copy_implementations)]
487 pub enum Metadata_opaque {}
488 pub type MetadataRef = *mut Metadata_opaque;
489 #[allow(missing_copy_implementations)]
490 pub enum BasicBlock_opaque {}
491 pub type BasicBlockRef = *mut BasicBlock_opaque;
492 #[allow(missing_copy_implementations)]
493 pub enum Builder_opaque {}
494 pub type BuilderRef = *mut Builder_opaque;
495 #[allow(missing_copy_implementations)]
496 pub enum ExecutionEngine_opaque {}
497 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
498 #[allow(missing_copy_implementations)]
499 pub enum MemoryBuffer_opaque {}
500 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
501 #[allow(missing_copy_implementations)]
502 pub enum PassManager_opaque {}
503 pub type PassManagerRef = *mut PassManager_opaque;
504 #[allow(missing_copy_implementations)]
505 pub enum PassManagerBuilder_opaque {}
506 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
507 #[allow(missing_copy_implementations)]
508 pub enum Use_opaque {}
509 pub type UseRef = *mut Use_opaque;
510 #[allow(missing_copy_implementations)]
511 pub enum TargetData_opaque {}
512 pub type TargetDataRef = *mut TargetData_opaque;
513 #[allow(missing_copy_implementations)]
514 pub enum ObjectFile_opaque {}
515 pub type ObjectFileRef = *mut ObjectFile_opaque;
516 #[allow(missing_copy_implementations)]
517 pub enum SectionIterator_opaque {}
518 pub type SectionIteratorRef = *mut SectionIterator_opaque;
519 #[allow(missing_copy_implementations)]
520 pub enum Pass_opaque {}
521 pub type PassRef = *mut Pass_opaque;
522 #[allow(missing_copy_implementations)]
523 pub enum TargetMachine_opaque {}
524 pub type TargetMachineRef = *mut TargetMachine_opaque;
525 pub enum Archive_opaque {}
526 pub type ArchiveRef = *mut Archive_opaque;
527 pub enum ArchiveIterator_opaque {}
528 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
529 pub enum ArchiveChild_opaque {}
530 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
531 #[allow(missing_copy_implementations)]
532 pub enum Twine_opaque {}
533 pub type TwineRef = *mut Twine_opaque;
534 #[allow(missing_copy_implementations)]
535 pub enum DiagnosticInfo_opaque {}
536 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
537 #[allow(missing_copy_implementations)]
538 pub enum DebugLoc_opaque {}
539 pub type DebugLocRef = *mut DebugLoc_opaque;
540 #[allow(missing_copy_implementations)]
541 pub enum SMDiagnostic_opaque {}
542 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
543 #[allow(missing_copy_implementations)]
544 pub enum RustArchiveMember_opaque {}
545 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
547 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
548 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
551 pub use self::DIDescriptorFlags::*;
552 use super::{MetadataRef};
554 #[allow(missing_copy_implementations)]
555 pub enum DIBuilder_opaque {}
556 pub type DIBuilderRef = *mut DIBuilder_opaque;
558 pub type DIDescriptor = MetadataRef;
559 pub type DIScope = DIDescriptor;
560 pub type DILocation = DIDescriptor;
561 pub type DIFile = DIScope;
562 pub type DILexicalBlock = DIScope;
563 pub type DISubprogram = DIScope;
564 pub type DINameSpace = DIScope;
565 pub type DIType = DIDescriptor;
566 pub type DIBasicType = DIType;
567 pub type DIDerivedType = DIType;
568 pub type DICompositeType = DIDerivedType;
569 pub type DIVariable = DIDescriptor;
570 pub type DIGlobalVariable = DIDescriptor;
571 pub type DIArray = DIDescriptor;
572 pub type DISubrange = DIDescriptor;
573 pub type DIEnumerator = DIDescriptor;
574 pub type DITemplateTypeParameter = DIDescriptor;
576 #[derive(Copy, Clone)]
577 pub enum DIDescriptorFlags {
578 FlagPrivate = 1 << 0,
579 FlagProtected = 1 << 1,
580 FlagFwdDecl = 1 << 2,
581 FlagAppleBlock = 1 << 3,
582 FlagBlockByrefStruct = 1 << 4,
583 FlagVirtual = 1 << 5,
584 FlagArtificial = 1 << 6,
585 FlagExplicit = 1 << 7,
586 FlagPrototyped = 1 << 8,
587 FlagObjcClassComplete = 1 << 9,
588 FlagObjectPointer = 1 << 10,
589 FlagVector = 1 << 11,
590 FlagStaticMember = 1 << 12,
591 FlagIndirectVariable = 1 << 13,
592 FlagLValueReference = 1 << 14,
593 FlagRValueReference = 1 << 15
598 // Link to our native llvm bindings (things that we need to use the C++ api
599 // for) and because llvm is written in C++ we need to link against libstdc++
601 // You'll probably notice that there is an omission of all LLVM libraries
602 // from this location. This is because the set of LLVM libraries that we
603 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
604 // figure out the exact set of libraries. To do this, the build system
605 // generates an llvmdeps.rs file next to this one which will be
606 // automatically updated whenever LLVM is updated to include an up-to-date
607 // set of the libraries we need to link to LLVM for.
608 #[link(name = "rustllvm", kind = "static")]
609 #[linked_from = "rustllvm"] // not quite true but good enough
611 /* Create and destroy contexts. */
612 pub fn LLVMContextCreate() -> ContextRef;
613 pub fn LLVMContextDispose(C: ContextRef);
614 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
619 /* Create and destroy modules. */
620 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
623 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
624 pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
625 pub fn LLVMDisposeModule(M: ModuleRef);
627 /// Data layout. See Module::getDataLayout.
628 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
629 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
631 /// Target triple. See Module::getTargetTriple.
632 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
633 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
635 /// See Module::dump.
636 pub fn LLVMDumpModule(M: ModuleRef);
638 /// See Module::setModuleInlineAsm.
639 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
641 /// See llvm::LLVMTypeKind::getTypeID.
642 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
644 /// See llvm::LLVMType::getContext.
645 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
647 /* Operations on integer types */
648 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
649 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
650 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
651 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
652 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
653 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
656 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
658 /* Operations on real types */
659 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
660 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
661 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
662 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
663 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
665 /* Operations on function types */
666 pub fn LLVMFunctionType(ReturnType: TypeRef,
667 ParamTypes: *const TypeRef,
671 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
672 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
673 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
674 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
676 /* Operations on struct types */
677 pub fn LLVMStructTypeInContext(C: ContextRef,
678 ElementTypes: *const TypeRef,
679 ElementCount: c_uint,
682 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
683 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
685 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
687 /* Operations on array, pointer, and vector types (sequence types) */
688 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
689 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
691 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
694 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
695 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
696 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
697 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
699 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
701 /* Operations on other types */
702 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
703 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
704 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
706 /* Operations on all values */
707 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
708 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
709 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
710 pub fn LLVMDumpValue(Val: ValueRef);
711 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
712 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
713 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
714 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
716 /* Operations on Uses */
717 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
718 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
719 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
720 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
722 /* Operations on Users */
723 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
724 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
725 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
727 /* Operations on constants of any type */
728 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
730 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
731 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
733 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
735 /* only for isize/vector */
736 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
737 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
738 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
739 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
740 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
742 /* Operations on metadata */
743 pub fn LLVMMDStringInContext(C: ContextRef,
747 pub fn LLVMMDNodeInContext(C: ContextRef,
748 Vals: *const ValueRef,
751 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
755 /* Operations on scalar constants */
756 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
758 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
760 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
765 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
766 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
768 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
772 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
773 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
776 /* Operations on composite constants */
777 pub fn LLVMConstStringInContext(C: ContextRef,
780 DontNullTerminate: Bool)
782 pub fn LLVMConstStructInContext(C: ContextRef,
783 ConstantVals: *const ValueRef,
788 pub fn LLVMConstArray(ElementTy: TypeRef,
789 ConstantVals: *const ValueRef,
792 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
795 /* Constant expressions */
796 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
797 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
798 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
799 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
800 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
801 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
802 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
803 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
805 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
807 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
809 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
811 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
813 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
815 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
817 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
819 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
821 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
823 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
825 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
827 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
829 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
831 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
832 RHSConstant: ValueRef)
834 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
836 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
838 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
840 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
842 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
844 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
846 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
848 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
850 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
852 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
854 pub fn LLVMConstGEP(ConstantVal: ValueRef,
855 ConstantIndices: *const ValueRef,
858 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
859 ConstantIndices: *const ValueRef,
862 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
864 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
866 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
868 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
870 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
872 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
874 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
876 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
878 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
880 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
882 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
884 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
886 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
888 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
890 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
892 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
894 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
898 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
900 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
901 ConstantIfTrue: ValueRef,
902 ConstantIfFalse: ValueRef)
904 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
905 IndexConstant: ValueRef)
907 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
908 ElementValueConstant: ValueRef,
909 IndexConstant: ValueRef)
911 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
912 VectorBConstant: ValueRef,
913 MaskConstant: ValueRef)
915 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
916 IdxList: *const c_uint,
919 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
920 ElementValueConstant: ValueRef,
921 IdxList: *const c_uint,
924 pub fn LLVMConstInlineAsm(Ty: TypeRef,
925 AsmString: *const c_char,
926 Constraints: *const c_char,
927 HasSideEffects: Bool,
930 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
934 /* Operations on global variables, functions, and aliases (globals) */
935 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
936 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
937 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
938 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
939 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
940 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
941 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
942 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
943 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
944 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
947 /* Operations on global variables */
948 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
949 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
951 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
954 AddressSpace: c_uint)
956 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
957 pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
958 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
959 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
960 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
961 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
962 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
963 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
964 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
965 ConstantVal: ValueRef);
966 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
967 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
968 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
969 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
970 pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
972 /* Operations on aliases */
973 pub fn LLVMAddAlias(M: ModuleRef,
979 /* Operations on functions */
980 pub fn LLVMAddFunction(M: ModuleRef,
984 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
985 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
986 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
987 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
988 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
989 pub fn LLVMDeleteFunction(Fn: ValueRef);
990 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
994 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
995 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
996 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
997 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
998 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
999 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
1000 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
1001 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1002 pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
1003 Name: *const c_char,
1004 Value: *const c_char);
1005 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1006 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
1007 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
1009 /* Operations on parameters */
1010 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1011 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1012 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1013 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1014 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1015 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1016 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1017 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1018 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1019 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1020 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1021 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1023 /* Operations on basic blocks */
1024 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1025 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1026 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1027 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1028 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1029 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1030 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1031 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1032 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1033 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1034 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1036 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1038 Name: *const c_char)
1040 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1042 Name: *const c_char)
1044 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1046 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1047 MoveAfter: BasicBlockRef);
1049 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1050 MoveBefore: BasicBlockRef);
1052 /* Operations on instructions */
1053 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1054 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1055 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1056 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1057 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1058 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1060 /* Operations on call sites */
1061 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1062 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1063 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1066 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1069 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1072 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1075 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1079 /* Operations on call instructions (only) */
1080 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1081 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1083 /* Operations on load/store instructions (only) */
1084 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1085 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1087 /* Operations on phi nodes */
1088 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1089 IncomingValues: *const ValueRef,
1090 IncomingBlocks: *const BasicBlockRef,
1092 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1093 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1095 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1098 /* Instruction builders */
1099 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1100 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1101 Block: BasicBlockRef,
1103 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1105 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1106 Block: BasicBlockRef);
1107 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1108 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1109 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1110 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1112 Name: *const c_char);
1113 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1115 /* Execution engine */
1116 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1117 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1118 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1119 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1120 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1121 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1125 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1126 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1127 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1130 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1131 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1132 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1133 RetVals: *const ValueRef,
1136 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1137 pub fn LLVMBuildCondBr(B: BuilderRef,
1139 Then: BasicBlockRef,
1140 Else: BasicBlockRef)
1142 pub fn LLVMBuildSwitch(B: BuilderRef,
1144 Else: BasicBlockRef,
1147 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1151 pub fn LLVMBuildInvoke(B: BuilderRef,
1153 Args: *const ValueRef,
1155 Then: BasicBlockRef,
1156 Catch: BasicBlockRef,
1157 Name: *const c_char)
1159 pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1163 Name: *const c_char,
1166 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1167 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1169 /* Add a case to the switch instruction */
1170 pub fn LLVMAddCase(Switch: ValueRef,
1172 Dest: BasicBlockRef);
1174 /* Add a destination to the indirectbr instruction */
1175 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1177 /* Add a clause to the landing pad instruction */
1178 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1180 /* Set the cleanup on a landing pad instruction */
1181 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1184 pub fn LLVMBuildAdd(B: BuilderRef,
1187 Name: *const c_char)
1189 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1192 Name: *const c_char)
1194 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1197 Name: *const c_char)
1199 pub fn LLVMBuildFAdd(B: BuilderRef,
1202 Name: *const c_char)
1204 pub fn LLVMBuildSub(B: BuilderRef,
1207 Name: *const c_char)
1209 pub fn LLVMBuildNSWSub(B: BuilderRef,
1212 Name: *const c_char)
1214 pub fn LLVMBuildNUWSub(B: BuilderRef,
1217 Name: *const c_char)
1219 pub fn LLVMBuildFSub(B: BuilderRef,
1222 Name: *const c_char)
1224 pub fn LLVMBuildMul(B: BuilderRef,
1227 Name: *const c_char)
1229 pub fn LLVMBuildNSWMul(B: BuilderRef,
1232 Name: *const c_char)
1234 pub fn LLVMBuildNUWMul(B: BuilderRef,
1237 Name: *const c_char)
1239 pub fn LLVMBuildFMul(B: BuilderRef,
1242 Name: *const c_char)
1244 pub fn LLVMBuildUDiv(B: BuilderRef,
1247 Name: *const c_char)
1249 pub fn LLVMBuildSDiv(B: BuilderRef,
1252 Name: *const c_char)
1254 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1257 Name: *const c_char)
1259 pub fn LLVMBuildFDiv(B: BuilderRef,
1262 Name: *const c_char)
1264 pub fn LLVMBuildURem(B: BuilderRef,
1267 Name: *const c_char)
1269 pub fn LLVMBuildSRem(B: BuilderRef,
1272 Name: *const c_char)
1274 pub fn LLVMBuildFRem(B: BuilderRef,
1277 Name: *const c_char)
1279 pub fn LLVMBuildShl(B: BuilderRef,
1282 Name: *const c_char)
1284 pub fn LLVMBuildLShr(B: BuilderRef,
1287 Name: *const c_char)
1289 pub fn LLVMBuildAShr(B: BuilderRef,
1292 Name: *const c_char)
1294 pub fn LLVMBuildAnd(B: BuilderRef,
1297 Name: *const c_char)
1299 pub fn LLVMBuildOr(B: BuilderRef,
1302 Name: *const c_char)
1304 pub fn LLVMBuildXor(B: BuilderRef,
1307 Name: *const c_char)
1309 pub fn LLVMBuildBinOp(B: BuilderRef,
1313 Name: *const c_char)
1315 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1317 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1319 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1321 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1323 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1327 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1329 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1330 pub fn LLVMBuildLoad(B: BuilderRef,
1331 PointerVal: ValueRef,
1332 Name: *const c_char)
1335 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1338 pub fn LLVMBuildGEP(B: BuilderRef,
1340 Indices: *const ValueRef,
1342 Name: *const c_char)
1344 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1346 Indices: *const ValueRef,
1348 Name: *const c_char)
1350 pub fn LLVMBuildStructGEP(B: BuilderRef,
1353 Name: *const c_char)
1355 pub fn LLVMBuildGlobalString(B: BuilderRef,
1357 Name: *const c_char)
1359 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1361 Name: *const c_char)
1365 pub fn LLVMBuildTrunc(B: BuilderRef,
1368 Name: *const c_char)
1370 pub fn LLVMBuildZExt(B: BuilderRef,
1373 Name: *const c_char)
1375 pub fn LLVMBuildSExt(B: BuilderRef,
1378 Name: *const c_char)
1380 pub fn LLVMBuildFPToUI(B: BuilderRef,
1383 Name: *const c_char)
1385 pub fn LLVMBuildFPToSI(B: BuilderRef,
1388 Name: *const c_char)
1390 pub fn LLVMBuildUIToFP(B: BuilderRef,
1393 Name: *const c_char)
1395 pub fn LLVMBuildSIToFP(B: BuilderRef,
1398 Name: *const c_char)
1400 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1403 Name: *const c_char)
1405 pub fn LLVMBuildFPExt(B: BuilderRef,
1408 Name: *const c_char)
1410 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1413 Name: *const c_char)
1415 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1418 Name: *const c_char)
1420 pub fn LLVMBuildBitCast(B: BuilderRef,
1423 Name: *const c_char)
1425 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1428 Name: *const c_char)
1430 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1433 Name: *const c_char)
1435 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1438 Name: *const c_char)
1440 pub fn LLVMBuildCast(B: BuilderRef,
1444 Name: *const c_char) -> ValueRef;
1445 pub fn LLVMBuildPointerCast(B: BuilderRef,
1448 Name: *const c_char)
1450 pub fn LLVMBuildIntCast(B: BuilderRef,
1453 Name: *const c_char)
1455 pub fn LLVMBuildFPCast(B: BuilderRef,
1458 Name: *const c_char)
1462 pub fn LLVMBuildICmp(B: BuilderRef,
1466 Name: *const c_char)
1468 pub fn LLVMBuildFCmp(B: BuilderRef,
1472 Name: *const c_char)
1475 /* Miscellaneous instructions */
1476 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1478 pub fn LLVMBuildCall(B: BuilderRef,
1480 Args: *const ValueRef,
1482 Name: *const c_char)
1484 pub fn LLVMBuildSelect(B: BuilderRef,
1488 Name: *const c_char)
1490 pub fn LLVMBuildVAArg(B: BuilderRef,
1493 Name: *const c_char)
1495 pub fn LLVMBuildExtractElement(B: BuilderRef,
1498 Name: *const c_char)
1500 pub fn LLVMBuildInsertElement(B: BuilderRef,
1504 Name: *const c_char)
1506 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1510 Name: *const c_char)
1512 pub fn LLVMBuildExtractValue(B: BuilderRef,
1515 Name: *const c_char)
1517 pub fn LLVMBuildInsertValue(B: BuilderRef,
1521 Name: *const c_char)
1524 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1526 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1528 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1531 Name: *const c_char)
1534 /* Atomic Operations */
1535 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1536 PointerVal: ValueRef,
1537 Name: *const c_char,
1538 Order: AtomicOrdering,
1542 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1545 Order: AtomicOrdering,
1549 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1553 Order: AtomicOrdering,
1554 FailureOrder: AtomicOrdering)
1556 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1560 Order: AtomicOrdering,
1561 SingleThreaded: Bool)
1564 pub fn LLVMBuildAtomicFence(B: BuilderRef,
1565 Order: AtomicOrdering,
1566 Scope: SynchronizationScope);
1569 /* Selected entries from the downcasts. */
1570 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1571 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1573 /// Writes a module to the specified path. Returns 0 on success.
1574 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1576 /// Creates target data from a target layout string.
1577 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1578 /// Adds the target data to the given pass manager. The pass manager
1579 /// references the target data only weakly.
1580 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1581 /// Number of bytes clobbered when doing a Store to *T.
1582 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1585 /// Number of bytes clobbered when doing a Store to *T.
1586 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1589 /// Distance between successive elements in an array of T. Includes ABI padding.
1590 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1592 /// Returns the preferred alignment of a type.
1593 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1595 /// Returns the minimum alignment of a type.
1596 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1599 /// Computes the byte offset of the indexed struct element for a
1601 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1606 /// Returns the minimum alignment of a type when part of a call frame.
1607 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1610 /// Disposes target data.
1611 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1613 /// Creates a pass manager.
1614 pub fn LLVMCreatePassManager() -> PassManagerRef;
1616 /// Creates a function-by-function pass manager
1617 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1620 /// Disposes a pass manager.
1621 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1623 /// Runs a pass manager on a module.
1624 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1626 /// Runs the function passes on the provided function.
1627 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1630 /// Initializes all the function passes scheduled in the manager
1631 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1633 /// Finalizes all the function passes scheduled in the manager
1634 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1636 pub fn LLVMInitializePasses();
1638 /// Adds a verification pass.
1639 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1641 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1642 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1643 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1644 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1645 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1646 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1647 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1648 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1649 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1650 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1651 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1652 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1653 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1654 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1655 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1656 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1657 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1658 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1659 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1660 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1661 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1662 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1663 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1664 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1665 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1666 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1667 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1668 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1669 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1670 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1671 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1672 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1673 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1674 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1675 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1677 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1678 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1679 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1680 OptimizationLevel: c_uint);
1681 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1683 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1684 PMB: PassManagerBuilderRef,
1686 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1687 PMB: PassManagerBuilderRef,
1689 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1690 PMB: PassManagerBuilderRef,
1692 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1693 PMB: PassManagerBuilderRef,
1695 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1696 PMB: PassManagerBuilderRef,
1697 PM: PassManagerRef);
1699 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1700 PMB: PassManagerBuilderRef,
1701 PM: PassManagerRef);
1702 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1703 PMB: PassManagerBuilderRef,
1708 /// Destroys a memory buffer.
1709 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1712 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1714 /// Opens an object file.
1715 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1716 /// Closes an object file.
1717 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1719 /// Enumerates the sections in an object file.
1720 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1721 /// Destroys a section iterator.
1722 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1723 /// Returns true if the section iterator is at the end of the section
1725 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1726 SI: SectionIteratorRef)
1728 /// Moves the section iterator to point to the next section.
1729 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1730 /// Returns the current section size.
1731 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1732 /// Returns the current section contents as a string buffer.
1733 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1735 /// Reads the given file and returns it as a memory buffer. Use
1736 /// LLVMDisposeMemoryBuffer() to get rid of it.
1737 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1739 /// Borrows the contents of the memory buffer (doesn't copy it)
1740 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1741 InputDataLength: size_t,
1742 BufferName: *const c_char,
1745 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1746 InputDataLength: size_t,
1747 BufferName: *const c_char)
1750 pub fn LLVMIsMultithreaded() -> Bool;
1751 pub fn LLVMStartMultithreaded() -> Bool;
1753 /// Returns a string describing the last error caused by an LLVMRust* call.
1754 pub fn LLVMRustGetLastError() -> *const c_char;
1756 /// Print the pass timings since static dtors aren't picking them up.
1757 pub fn LLVMRustPrintPassTimings();
1759 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1761 pub fn LLVMStructSetBody(StructTy: TypeRef,
1762 ElementTypes: *const TypeRef,
1763 ElementCount: c_uint,
1766 pub fn LLVMConstNamedStruct(S: TypeRef,
1767 ConstantVals: *const ValueRef,
1771 /// Enables LLVM debug output.
1772 pub fn LLVMSetDebug(Enabled: c_int);
1774 /// Prepares inline assembly.
1775 pub fn LLVMInlineAsm(Ty: TypeRef,
1776 AsmString: *const c_char,
1777 Constraints: *const c_char,
1783 pub fn LLVMRustDebugMetadataVersion() -> u32;
1784 pub fn LLVMVersionMajor() -> u32;
1785 pub fn LLVMVersionMinor() -> u32;
1787 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1788 name: *const c_char,
1791 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1793 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1795 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1797 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1799 File: *const c_char,
1801 Producer: *const c_char,
1803 Flags: *const c_char,
1805 SplitName: *const c_char)
1808 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1809 Filename: *const c_char,
1810 Directory: *const c_char)
1813 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1815 ParameterTypes: DIArray)
1818 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1819 Scope: DIDescriptor,
1820 Name: *const c_char,
1821 LinkageName: *const c_char,
1825 isLocalToUnit: bool,
1835 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1836 Name: *const c_char,
1837 SizeInBits: c_ulonglong,
1838 AlignInBits: c_ulonglong,
1842 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1844 SizeInBits: c_ulonglong,
1845 AlignInBits: c_ulonglong,
1846 Name: *const c_char)
1849 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1850 Scope: DIDescriptor,
1851 Name: *const c_char,
1854 SizeInBits: c_ulonglong,
1855 AlignInBits: c_ulonglong,
1857 DerivedFrom: DIType,
1859 RunTimeLang: c_uint,
1860 VTableHolder: DIType,
1861 UniqueId: *const c_char)
1864 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1865 Scope: DIDescriptor,
1866 Name: *const c_char,
1869 SizeInBits: c_ulonglong,
1870 AlignInBits: c_ulonglong,
1871 OffsetInBits: c_ulonglong,
1876 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1883 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1885 Name: *const c_char,
1886 LinkageName: *const c_char,
1890 isLocalToUnit: bool,
1893 -> DIGlobalVariable;
1895 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1897 Scope: DIDescriptor,
1898 Name: *const c_char,
1902 AlwaysPreserve: bool,
1904 AddrOps: *const i64,
1905 AddrOpsCount: c_uint,
1909 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1911 AlignInBits: c_ulonglong,
1913 Subscripts: DIArray)
1916 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1918 AlignInBits: c_ulonglong,
1920 Subscripts: DIArray)
1923 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1928 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1929 Ptr: *const DIDescriptor,
1933 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1935 VarInfo: DIVariable,
1936 AddrOps: *const i64,
1937 AddrOpsCount: c_uint,
1939 InsertAtEnd: BasicBlockRef)
1942 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1944 VarInfo: DIVariable,
1945 AddrOps: *const i64,
1946 AddrOpsCount: c_uint,
1948 InsertBefore: ValueRef)
1951 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1952 Name: *const c_char,
1956 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1958 Name: *const c_char,
1961 SizeInBits: c_ulonglong,
1962 AlignInBits: c_ulonglong,
1967 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1969 Name: *const c_char,
1972 SizeInBits: c_ulonglong,
1973 AlignInBits: c_ulonglong,
1976 RunTimeLang: c_uint,
1977 UniqueId: *const c_char)
1980 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1982 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1984 Name: *const c_char,
1989 -> DITemplateTypeParameter;
1991 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1993 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1995 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1997 Name: *const c_char,
2002 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
2006 InlinedAt: MetadataRef)
2009 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2010 CompositeType: DIType,
2011 TypeArray: DIArray);
2012 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2013 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2015 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2017 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2018 pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2020 pub fn LLVMRustPassKind(Pass: PassRef) -> SupportedPassKind;
2021 pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef;
2022 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef);
2024 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2026 Features: *const c_char,
2027 Model: CodeGenModel,
2029 Level: CodeGenOptLevel,
2031 PositionIndependentExecutable: bool,
2032 FunctionSections: bool,
2033 DataSections: bool) -> TargetMachineRef;
2034 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2035 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2038 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2040 DisableSimplifyLibCalls: bool);
2041 pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2042 OptLevel: CodeGenOptLevel,
2043 MergeFunctions: bool,
2045 LoopVectorize: bool);
2046 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2047 DisableSimplifyLibCalls: bool);
2048 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2049 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2052 Output: *const c_char,
2053 FileType: FileType) -> bool;
2054 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2056 Output: *const c_char);
2057 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2058 pub fn LLVMRustPrintPasses();
2059 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2060 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2061 AddLifetimes: bool);
2062 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2064 len: size_t) -> bool;
2065 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2066 syms: *const *const c_char,
2068 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2070 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2071 pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2072 pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2073 pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2074 size: *mut size_t) -> *const c_char;
2075 pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2076 size: *mut size_t) -> *const c_char;
2077 pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2078 pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2079 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2081 pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2082 C: DLLStorageClassTypes);
2084 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2085 data: *mut *const c_char) -> c_int;
2087 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2089 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2090 Handler: DiagnosticHandler,
2091 DiagnosticContext: *mut c_void);
2093 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2094 pass_name_out: *mut *const c_char,
2095 function_out: *mut ValueRef,
2096 debugloc_out: *mut DebugLocRef,
2097 message_out: *mut TwineRef);
2098 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2099 cookie_out: *mut c_uint,
2100 message_out: *mut TwineRef,
2101 instruction_out: *mut ValueRef);
2103 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2104 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2105 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2107 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2109 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2110 H: InlineAsmDiagHandler,
2113 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2115 pub fn LLVMRustWriteArchive(Dst: *const c_char,
2117 Members: *const RustArchiveMemberRef,
2119 Kind: ArchiveKind) -> c_int;
2120 pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2121 Name: *const c_char,
2122 Child: ArchiveChildRef) -> RustArchiveMemberRef;
2123 pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2125 pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2126 TM: TargetMachineRef);
2127 pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2130 #[cfg(have_component_x86)]
2132 pub fn LLVMInitializeX86TargetInfo();
2133 pub fn LLVMInitializeX86Target();
2134 pub fn LLVMInitializeX86TargetMC();
2135 pub fn LLVMInitializeX86AsmPrinter();
2136 pub fn LLVMInitializeX86AsmParser();
2138 #[cfg(have_component_arm)]
2140 pub fn LLVMInitializeARMTargetInfo();
2141 pub fn LLVMInitializeARMTarget();
2142 pub fn LLVMInitializeARMTargetMC();
2143 pub fn LLVMInitializeARMAsmPrinter();
2144 pub fn LLVMInitializeARMAsmParser();
2146 #[cfg(have_component_aarch64)]
2148 pub fn LLVMInitializeAArch64TargetInfo();
2149 pub fn LLVMInitializeAArch64Target();
2150 pub fn LLVMInitializeAArch64TargetMC();
2151 pub fn LLVMInitializeAArch64AsmPrinter();
2152 pub fn LLVMInitializeAArch64AsmParser();
2154 #[cfg(have_component_mips)]
2156 pub fn LLVMInitializeMipsTargetInfo();
2157 pub fn LLVMInitializeMipsTarget();
2158 pub fn LLVMInitializeMipsTargetMC();
2159 pub fn LLVMInitializeMipsAsmPrinter();
2160 pub fn LLVMInitializeMipsAsmParser();
2162 #[cfg(have_component_powerpc)]
2164 pub fn LLVMInitializePowerPCTargetInfo();
2165 pub fn LLVMInitializePowerPCTarget();
2166 pub fn LLVMInitializePowerPCTargetMC();
2167 pub fn LLVMInitializePowerPCAsmPrinter();
2168 pub fn LLVMInitializePowerPCAsmParser();
2170 #[cfg(have_component_pnacl)]
2172 pub fn LLVMInitializePNaClTargetInfo();
2173 pub fn LLVMInitializePNaClTarget();
2174 pub fn LLVMInitializePNaClTargetMC();
2177 // LLVM requires symbols from this library, but apparently they're not printed
2178 // during llvm-config?
2180 #[link(name = "ole32")]
2183 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2185 LLVMSetInstructionCallConv(instr, cc as c_uint);
2188 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2190 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2193 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2195 LLVMSetLinkage(global, link as c_uint);
2199 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2201 LLVMRustSetDLLStorageClass(global, class);
2205 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2207 LLVMSetUnnamedAddr(global, unnamed as Bool);
2211 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2213 LLVMSetThreadLocal(global, is_thread_local as Bool);
2217 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2219 LLVMConstICmp(pred as c_ushort, v1, v2)
2222 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2224 LLVMConstFCmp(pred as c_ushort, v1, v2)
2228 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2230 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2231 attr.bits() as uint64_t)
2235 /* Memory-managed interface to target data. */
2237 pub struct TargetData {
2238 pub lltd: TargetDataRef
2241 impl Drop for TargetData {
2242 fn drop(&mut self) {
2244 LLVMDisposeTargetData(self.lltd);
2249 pub fn mk_target_data(string_rep: &str) -> TargetData {
2250 let string_rep = CString::new(string_rep).unwrap();
2252 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2256 /* Memory-managed interface to object files. */
2258 pub struct ObjectFile {
2259 pub llof: ObjectFileRef,
2263 // This will take ownership of llmb
2264 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2266 let llof = LLVMCreateObjectFile(llmb);
2267 if llof as isize == 0 {
2268 // LLVMCreateObjectFile took ownership of llmb
2279 impl Drop for ObjectFile {
2280 fn drop(&mut self) {
2282 LLVMDisposeObjectFile(self.llof);
2287 /* Memory-managed interface to section iterators. */
2289 pub struct SectionIter {
2290 pub llsi: SectionIteratorRef
2293 impl Drop for SectionIter {
2294 fn drop(&mut self) {
2296 LLVMDisposeSectionIterator(self.llsi);
2301 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2304 llsi: LLVMGetSections(llof)
2309 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2310 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2312 assert!(index < LLVMCountParams(llfn));
2313 LLVMGetParam(llfn, index)
2317 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2319 let num_params = LLVMCountParams(llfn);
2320 let mut params = Vec::with_capacity(num_params as usize);
2321 for idx in 0..num_params {
2322 params.push(LLVMGetParam(llfn, idx));
2329 #[allow(missing_copy_implementations)]
2330 pub enum RustString_opaque {}
2331 pub type RustStringRef = *mut RustString_opaque;
2332 type RustStringRepr = *mut RefCell<Vec<u8>>;
2334 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2336 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2339 let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2341 let sr = sr as RustStringRepr;
2342 (*sr).borrow_mut().extend_from_slice(slice);
2345 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2346 let mut buf = RefCell::new(Vec::new());
2347 f(&mut buf as RustStringRepr as RustStringRef);
2348 String::from_utf8(buf.into_inner()).ok()
2351 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2352 build_string(|s| LLVMWriteTwineToString(tr, s))
2353 .expect("got a non-UTF8 Twine from LLVM")
2356 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2357 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2358 .expect("got a non-UTF8 DebugLoc from LLVM")
2361 pub fn initialize_available_targets() {
2362 macro_rules! init_target(
2363 ($cfg:ident $arch:ident) => { {
2367 let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
2369 let f = concat_idents!(LLVMInitialize, $arch, Target);
2371 let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
2373 let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
2375 let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
2385 init_target!(have_component_powerpc PowerPC);
2386 init_target!(have_component_mips Mips);
2387 init_target!(have_component_aarch64 AArch64);
2388 init_target!(have_component_arm ARM);
2389 init_target!(have_component_x86 X86);
2391 // PNaCl doesn't provide some of the optional target components, so we
2392 // manually initialize it here.
2393 #[cfg(have_component_pnacl)]
2396 LLVMInitializePNaClTargetInfo();
2397 LLVMInitializePNaClTarget();
2398 LLVMInitializePNaClTargetMC();
2401 #[cfg(not(have_component_pnacl))]
2406 // The module containing the native LLVM dependencies, generated by the build system
2407 // Note that this must come after the rustllvm extern declaration so that
2408 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2409 // Works to the above fix for #15460 to ensure LLVM dependencies that
2410 // are only used by rustllvm don't get stripped by the linker.
2412 include! { env!("CFG_LLVM_LINKAGE_FILE") }