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)]
16 #![crate_name = "rustc_llvm"]
17 #![unstable(feature = "rustc_private", issue = "27812")]
18 #![crate_type = "dylib"]
19 #![crate_type = "rlib"]
20 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
21 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
22 html_root_url = "https://doc.rust-lang.org/nightly/")]
23 #![cfg_attr(not(stage0), deny(warnings))]
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, CStr};
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;
546 #[allow(missing_copy_implementations)]
547 pub enum OperandBundleDef_opaque {}
548 pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
550 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
551 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
554 pub use self::DIDescriptorFlags::*;
555 use super::{MetadataRef};
557 #[allow(missing_copy_implementations)]
558 pub enum DIBuilder_opaque {}
559 pub type DIBuilderRef = *mut DIBuilder_opaque;
561 pub type DIDescriptor = MetadataRef;
562 pub type DIScope = DIDescriptor;
563 pub type DILocation = DIDescriptor;
564 pub type DIFile = DIScope;
565 pub type DILexicalBlock = DIScope;
566 pub type DISubprogram = DIScope;
567 pub type DINameSpace = DIScope;
568 pub type DIType = DIDescriptor;
569 pub type DIBasicType = DIType;
570 pub type DIDerivedType = DIType;
571 pub type DICompositeType = DIDerivedType;
572 pub type DIVariable = DIDescriptor;
573 pub type DIGlobalVariable = DIDescriptor;
574 pub type DIArray = DIDescriptor;
575 pub type DISubrange = DIDescriptor;
576 pub type DIEnumerator = DIDescriptor;
577 pub type DITemplateTypeParameter = DIDescriptor;
579 #[derive(Copy, Clone)]
580 pub enum DIDescriptorFlags {
581 FlagPrivate = 1 << 0,
582 FlagProtected = 1 << 1,
583 FlagFwdDecl = 1 << 2,
584 FlagAppleBlock = 1 << 3,
585 FlagBlockByrefStruct = 1 << 4,
586 FlagVirtual = 1 << 5,
587 FlagArtificial = 1 << 6,
588 FlagExplicit = 1 << 7,
589 FlagPrototyped = 1 << 8,
590 FlagObjcClassComplete = 1 << 9,
591 FlagObjectPointer = 1 << 10,
592 FlagVector = 1 << 11,
593 FlagStaticMember = 1 << 12,
594 FlagIndirectVariable = 1 << 13,
595 FlagLValueReference = 1 << 14,
596 FlagRValueReference = 1 << 15
601 // Link to our native llvm bindings (things that we need to use the C++ api
602 // for) and because llvm is written in C++ we need to link against libstdc++
604 // You'll probably notice that there is an omission of all LLVM libraries
605 // from this location. This is because the set of LLVM libraries that we
606 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
607 // figure out the exact set of libraries. To do this, the build system
608 // generates an llvmdeps.rs file next to this one which will be
609 // automatically updated whenever LLVM is updated to include an up-to-date
610 // set of the libraries we need to link to LLVM for.
611 #[link(name = "rustllvm", kind = "static")]
612 #[linked_from = "rustllvm"] // not quite true but good enough
614 /* Create and destroy contexts. */
615 pub fn LLVMContextCreate() -> ContextRef;
616 pub fn LLVMContextDispose(C: ContextRef);
617 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
622 /* Create and destroy modules. */
623 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
626 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
627 pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
628 pub fn LLVMDisposeModule(M: ModuleRef);
630 /// Data layout. See Module::getDataLayout.
631 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
632 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
634 /// Target triple. See Module::getTargetTriple.
635 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
636 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
638 /// See Module::dump.
639 pub fn LLVMDumpModule(M: ModuleRef);
641 /// See Module::setModuleInlineAsm.
642 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
644 /// See llvm::LLVMTypeKind::getTypeID.
645 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
647 /// See llvm::LLVMType::getContext.
648 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
650 /* Operations on integer types */
651 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
652 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
653 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
654 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
655 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
656 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
659 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
661 /* Operations on real types */
662 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
663 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
664 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
665 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
666 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
668 /* Operations on function types */
669 pub fn LLVMFunctionType(ReturnType: TypeRef,
670 ParamTypes: *const TypeRef,
674 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
675 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
676 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
677 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
679 /* Operations on struct types */
680 pub fn LLVMStructTypeInContext(C: ContextRef,
681 ElementTypes: *const TypeRef,
682 ElementCount: c_uint,
685 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
686 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
688 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
690 /* Operations on array, pointer, and vector types (sequence types) */
691 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
692 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
694 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
697 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
698 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
699 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
700 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
702 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
704 /* Operations on other types */
705 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
706 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
707 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
709 /* Operations on all values */
710 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
711 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
712 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
713 pub fn LLVMDumpValue(Val: ValueRef);
714 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
715 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
716 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
717 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
719 /* Operations on Uses */
720 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
721 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
722 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
723 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
725 /* Operations on Users */
726 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
727 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
728 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
730 /* Operations on constants of any type */
731 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
733 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
734 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
736 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
738 /* only for isize/vector */
739 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
740 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
741 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
742 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
743 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
745 /* Operations on metadata */
746 pub fn LLVMMDStringInContext(C: ContextRef,
750 pub fn LLVMMDNodeInContext(C: ContextRef,
751 Vals: *const ValueRef,
754 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
758 /* Operations on scalar constants */
759 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
761 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
763 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
768 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
769 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
771 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
775 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
776 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
779 /* Operations on composite constants */
780 pub fn LLVMConstStringInContext(C: ContextRef,
783 DontNullTerminate: Bool)
785 pub fn LLVMConstStructInContext(C: ContextRef,
786 ConstantVals: *const ValueRef,
791 pub fn LLVMConstArray(ElementTy: TypeRef,
792 ConstantVals: *const ValueRef,
795 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
798 /* Constant expressions */
799 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
800 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
801 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
802 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
803 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
804 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
805 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
806 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
808 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
810 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
812 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
814 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
816 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
818 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
820 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
822 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
824 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
826 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
828 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
830 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
832 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
834 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
835 RHSConstant: ValueRef)
837 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
839 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
841 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
843 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
845 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
847 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
849 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
851 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
853 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
855 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
857 pub fn LLVMConstGEP(ConstantVal: ValueRef,
858 ConstantIndices: *const ValueRef,
861 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
862 ConstantIndices: *const ValueRef,
865 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
867 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
869 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
871 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
873 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
875 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
877 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
879 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
881 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
883 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
885 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
887 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
889 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
891 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
893 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
895 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
897 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
901 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
903 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
904 ConstantIfTrue: ValueRef,
905 ConstantIfFalse: ValueRef)
907 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
908 IndexConstant: ValueRef)
910 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
911 ElementValueConstant: ValueRef,
912 IndexConstant: ValueRef)
914 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
915 VectorBConstant: ValueRef,
916 MaskConstant: ValueRef)
918 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
919 IdxList: *const c_uint,
922 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
923 ElementValueConstant: ValueRef,
924 IdxList: *const c_uint,
927 pub fn LLVMConstInlineAsm(Ty: TypeRef,
928 AsmString: *const c_char,
929 Constraints: *const c_char,
930 HasSideEffects: Bool,
933 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
937 /* Operations on global variables, functions, and aliases (globals) */
938 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
939 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
940 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
941 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
942 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
943 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
944 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
945 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
946 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
947 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
950 /* Operations on global variables */
951 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
952 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
954 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
957 AddressSpace: c_uint)
959 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
960 pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
961 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
962 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
963 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
964 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
965 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
966 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
967 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
968 ConstantVal: ValueRef);
969 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
970 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
971 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
972 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
973 pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
975 /* Operations on aliases */
976 pub fn LLVMAddAlias(M: ModuleRef,
982 /* Operations on functions */
983 pub fn LLVMAddFunction(M: ModuleRef,
987 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
988 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
989 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
990 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
991 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
992 pub fn LLVMDeleteFunction(Fn: ValueRef);
993 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
997 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
998 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
999 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
1000 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
1001 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
1002 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
1003 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
1004 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1005 pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
1006 Name: *const c_char,
1007 Value: *const c_char);
1008 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1009 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
1010 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
1012 /* Operations on parameters */
1013 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1014 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1015 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1016 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1017 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1018 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1019 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1020 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1021 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1022 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1023 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1024 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1026 /* Operations on basic blocks */
1027 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1028 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1029 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1030 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1031 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1032 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1033 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1034 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1035 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1036 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1037 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1039 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1041 Name: *const c_char)
1043 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1045 Name: *const c_char)
1047 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1049 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1050 MoveAfter: BasicBlockRef);
1052 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1053 MoveBefore: BasicBlockRef);
1055 /* Operations on instructions */
1056 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1057 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1058 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1059 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1060 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1061 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1063 /* Operations on call sites */
1064 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1065 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1066 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1069 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1072 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1075 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1078 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1082 /* Operations on call instructions (only) */
1083 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1084 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1086 /* Operations on load/store instructions (only) */
1087 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1088 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1090 /* Operations on phi nodes */
1091 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1092 IncomingValues: *const ValueRef,
1093 IncomingBlocks: *const BasicBlockRef,
1095 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1096 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1098 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1101 /* Instruction builders */
1102 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1103 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1104 Block: BasicBlockRef,
1106 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1108 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1109 Block: BasicBlockRef);
1110 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1111 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1112 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1113 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1115 Name: *const c_char);
1116 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1118 /* Execution engine */
1119 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1120 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1121 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1122 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1123 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1124 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1128 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1129 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1130 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1133 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1134 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1135 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1136 RetVals: *const ValueRef,
1139 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1140 pub fn LLVMBuildCondBr(B: BuilderRef,
1142 Then: BasicBlockRef,
1143 Else: BasicBlockRef)
1145 pub fn LLVMBuildSwitch(B: BuilderRef,
1147 Else: BasicBlockRef,
1150 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1154 pub fn LLVMRustBuildInvoke(B: BuilderRef,
1156 Args: *const ValueRef,
1158 Then: BasicBlockRef,
1159 Catch: BasicBlockRef,
1160 Bundle: OperandBundleDefRef,
1161 Name: *const c_char)
1163 pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1167 Name: *const c_char,
1170 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1171 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1173 pub fn LLVMRustBuildCleanupPad(B: BuilderRef,
1174 ParentPad: ValueRef,
1176 Args: *const ValueRef,
1177 Name: *const c_char) -> ValueRef;
1178 pub fn LLVMRustBuildCleanupRet(B: BuilderRef,
1179 CleanupPad: ValueRef,
1180 UnwindBB: BasicBlockRef) -> ValueRef;
1181 pub fn LLVMRustBuildCatchPad(B: BuilderRef,
1182 ParentPad: ValueRef,
1184 Args: *const ValueRef,
1185 Name: *const c_char) -> ValueRef;
1186 pub fn LLVMRustBuildCatchRet(B: BuilderRef,
1188 BB: BasicBlockRef) -> ValueRef;
1189 pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef,
1190 ParentPad: ValueRef,
1192 NumHandlers: c_uint,
1193 Name: *const c_char) -> ValueRef;
1194 pub fn LLVMRustAddHandler(CatchSwitch: ValueRef,
1195 Handler: BasicBlockRef);
1196 pub fn LLVMRustSetPersonalityFn(B: BuilderRef, Pers: ValueRef);
1198 /* Add a case to the switch instruction */
1199 pub fn LLVMAddCase(Switch: ValueRef,
1201 Dest: BasicBlockRef);
1203 /* Add a destination to the indirectbr instruction */
1204 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1206 /* Add a clause to the landing pad instruction */
1207 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1209 /* Set the cleanup on a landing pad instruction */
1210 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1213 pub fn LLVMBuildAdd(B: BuilderRef,
1216 Name: *const c_char)
1218 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1221 Name: *const c_char)
1223 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1226 Name: *const c_char)
1228 pub fn LLVMBuildFAdd(B: BuilderRef,
1231 Name: *const c_char)
1233 pub fn LLVMBuildSub(B: BuilderRef,
1236 Name: *const c_char)
1238 pub fn LLVMBuildNSWSub(B: BuilderRef,
1241 Name: *const c_char)
1243 pub fn LLVMBuildNUWSub(B: BuilderRef,
1246 Name: *const c_char)
1248 pub fn LLVMBuildFSub(B: BuilderRef,
1251 Name: *const c_char)
1253 pub fn LLVMBuildMul(B: BuilderRef,
1256 Name: *const c_char)
1258 pub fn LLVMBuildNSWMul(B: BuilderRef,
1261 Name: *const c_char)
1263 pub fn LLVMBuildNUWMul(B: BuilderRef,
1266 Name: *const c_char)
1268 pub fn LLVMBuildFMul(B: BuilderRef,
1271 Name: *const c_char)
1273 pub fn LLVMBuildUDiv(B: BuilderRef,
1276 Name: *const c_char)
1278 pub fn LLVMBuildSDiv(B: BuilderRef,
1281 Name: *const c_char)
1283 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1286 Name: *const c_char)
1288 pub fn LLVMBuildFDiv(B: BuilderRef,
1291 Name: *const c_char)
1293 pub fn LLVMBuildURem(B: BuilderRef,
1296 Name: *const c_char)
1298 pub fn LLVMBuildSRem(B: BuilderRef,
1301 Name: *const c_char)
1303 pub fn LLVMBuildFRem(B: BuilderRef,
1306 Name: *const c_char)
1308 pub fn LLVMBuildShl(B: BuilderRef,
1311 Name: *const c_char)
1313 pub fn LLVMBuildLShr(B: BuilderRef,
1316 Name: *const c_char)
1318 pub fn LLVMBuildAShr(B: BuilderRef,
1321 Name: *const c_char)
1323 pub fn LLVMBuildAnd(B: BuilderRef,
1326 Name: *const c_char)
1328 pub fn LLVMBuildOr(B: BuilderRef,
1331 Name: *const c_char)
1333 pub fn LLVMBuildXor(B: BuilderRef,
1336 Name: *const c_char)
1338 pub fn LLVMBuildBinOp(B: BuilderRef,
1342 Name: *const c_char)
1344 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1346 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1348 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1350 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1352 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1356 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1358 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1359 pub fn LLVMBuildLoad(B: BuilderRef,
1360 PointerVal: ValueRef,
1361 Name: *const c_char)
1364 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1367 pub fn LLVMBuildGEP(B: BuilderRef,
1369 Indices: *const ValueRef,
1371 Name: *const c_char)
1373 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1375 Indices: *const ValueRef,
1377 Name: *const c_char)
1379 pub fn LLVMBuildStructGEP(B: BuilderRef,
1382 Name: *const c_char)
1384 pub fn LLVMBuildGlobalString(B: BuilderRef,
1386 Name: *const c_char)
1388 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1390 Name: *const c_char)
1394 pub fn LLVMBuildTrunc(B: BuilderRef,
1397 Name: *const c_char)
1399 pub fn LLVMBuildZExt(B: BuilderRef,
1402 Name: *const c_char)
1404 pub fn LLVMBuildSExt(B: BuilderRef,
1407 Name: *const c_char)
1409 pub fn LLVMBuildFPToUI(B: BuilderRef,
1412 Name: *const c_char)
1414 pub fn LLVMBuildFPToSI(B: BuilderRef,
1417 Name: *const c_char)
1419 pub fn LLVMBuildUIToFP(B: BuilderRef,
1422 Name: *const c_char)
1424 pub fn LLVMBuildSIToFP(B: BuilderRef,
1427 Name: *const c_char)
1429 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1432 Name: *const c_char)
1434 pub fn LLVMBuildFPExt(B: BuilderRef,
1437 Name: *const c_char)
1439 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1442 Name: *const c_char)
1444 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1447 Name: *const c_char)
1449 pub fn LLVMBuildBitCast(B: BuilderRef,
1452 Name: *const c_char)
1454 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1457 Name: *const c_char)
1459 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1462 Name: *const c_char)
1464 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1467 Name: *const c_char)
1469 pub fn LLVMBuildCast(B: BuilderRef,
1473 Name: *const c_char) -> ValueRef;
1474 pub fn LLVMBuildPointerCast(B: BuilderRef,
1477 Name: *const c_char)
1479 pub fn LLVMBuildIntCast(B: BuilderRef,
1482 Name: *const c_char)
1484 pub fn LLVMBuildFPCast(B: BuilderRef,
1487 Name: *const c_char)
1491 pub fn LLVMBuildICmp(B: BuilderRef,
1495 Name: *const c_char)
1497 pub fn LLVMBuildFCmp(B: BuilderRef,
1501 Name: *const c_char)
1504 /* Miscellaneous instructions */
1505 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1507 pub fn LLVMRustBuildCall(B: BuilderRef,
1509 Args: *const ValueRef,
1511 Bundle: OperandBundleDefRef,
1512 Name: *const c_char)
1514 pub fn LLVMBuildSelect(B: BuilderRef,
1518 Name: *const c_char)
1520 pub fn LLVMBuildVAArg(B: BuilderRef,
1523 Name: *const c_char)
1525 pub fn LLVMBuildExtractElement(B: BuilderRef,
1528 Name: *const c_char)
1530 pub fn LLVMBuildInsertElement(B: BuilderRef,
1534 Name: *const c_char)
1536 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1540 Name: *const c_char)
1542 pub fn LLVMBuildExtractValue(B: BuilderRef,
1545 Name: *const c_char)
1547 pub fn LLVMBuildInsertValue(B: BuilderRef,
1551 Name: *const c_char)
1554 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1556 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1558 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1561 Name: *const c_char)
1564 /* Atomic Operations */
1565 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1566 PointerVal: ValueRef,
1567 Name: *const c_char,
1568 Order: AtomicOrdering,
1572 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1575 Order: AtomicOrdering,
1579 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1583 Order: AtomicOrdering,
1584 FailureOrder: AtomicOrdering)
1586 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1590 Order: AtomicOrdering,
1591 SingleThreaded: Bool)
1594 pub fn LLVMBuildAtomicFence(B: BuilderRef,
1595 Order: AtomicOrdering,
1596 Scope: SynchronizationScope);
1599 /* Selected entries from the downcasts. */
1600 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1601 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1603 /// Writes a module to the specified path. Returns 0 on success.
1604 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1606 /// Creates target data from a target layout string.
1607 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1608 /// Adds the target data to the given pass manager. The pass manager
1609 /// references the target data only weakly.
1610 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1611 /// Number of bytes clobbered when doing a Store to *T.
1612 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1615 /// Number of bytes clobbered when doing a Store to *T.
1616 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1619 /// Distance between successive elements in an array of T. Includes ABI padding.
1620 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1622 /// Returns the preferred alignment of a type.
1623 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1625 /// Returns the minimum alignment of a type.
1626 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1629 /// Computes the byte offset of the indexed struct element for a
1631 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1636 /// Returns the minimum alignment of a type when part of a call frame.
1637 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1640 /// Disposes target data.
1641 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1643 /// Creates a pass manager.
1644 pub fn LLVMCreatePassManager() -> PassManagerRef;
1646 /// Creates a function-by-function pass manager
1647 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1650 /// Disposes a pass manager.
1651 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1653 /// Runs a pass manager on a module.
1654 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1656 /// Runs the function passes on the provided function.
1657 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1660 /// Initializes all the function passes scheduled in the manager
1661 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1663 /// Finalizes all the function passes scheduled in the manager
1664 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1666 pub fn LLVMInitializePasses();
1668 /// Adds a verification pass.
1669 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1671 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1672 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1673 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1674 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1675 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1676 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1677 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1678 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1679 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1680 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1681 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1682 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1683 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1684 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1685 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1686 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1687 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1688 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1689 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1690 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1691 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1692 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1693 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1694 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1695 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1696 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1697 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1698 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1699 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1700 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1701 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1702 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1703 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1704 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1705 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1707 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1708 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1709 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1710 OptimizationLevel: c_uint);
1711 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1713 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1714 PMB: PassManagerBuilderRef,
1716 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1717 PMB: PassManagerBuilderRef,
1719 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1720 PMB: PassManagerBuilderRef,
1722 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1723 PMB: PassManagerBuilderRef,
1725 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1726 PMB: PassManagerBuilderRef,
1727 PM: PassManagerRef);
1729 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1730 PMB: PassManagerBuilderRef,
1731 PM: PassManagerRef);
1732 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1733 PMB: PassManagerBuilderRef,
1738 /// Destroys a memory buffer.
1739 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1742 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1744 /// Opens an object file.
1745 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1746 /// Closes an object file.
1747 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1749 /// Enumerates the sections in an object file.
1750 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1751 /// Destroys a section iterator.
1752 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1753 /// Returns true if the section iterator is at the end of the section
1755 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1756 SI: SectionIteratorRef)
1758 /// Moves the section iterator to point to the next section.
1759 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1760 /// Returns the current section size.
1761 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1762 /// Returns the current section contents as a string buffer.
1763 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1765 /// Reads the given file and returns it as a memory buffer. Use
1766 /// LLVMDisposeMemoryBuffer() to get rid of it.
1767 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1769 /// Borrows the contents of the memory buffer (doesn't copy it)
1770 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1771 InputDataLength: size_t,
1772 BufferName: *const c_char,
1775 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1776 InputDataLength: size_t,
1777 BufferName: *const c_char)
1780 pub fn LLVMIsMultithreaded() -> Bool;
1781 pub fn LLVMStartMultithreaded() -> Bool;
1783 /// Returns a string describing the last error caused by an LLVMRust* call.
1784 pub fn LLVMRustGetLastError() -> *const c_char;
1786 /// Print the pass timings since static dtors aren't picking them up.
1787 pub fn LLVMRustPrintPassTimings();
1789 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1791 pub fn LLVMStructSetBody(StructTy: TypeRef,
1792 ElementTypes: *const TypeRef,
1793 ElementCount: c_uint,
1796 pub fn LLVMConstNamedStruct(S: TypeRef,
1797 ConstantVals: *const ValueRef,
1801 /// Enables LLVM debug output.
1802 pub fn LLVMSetDebug(Enabled: c_int);
1804 /// Prepares inline assembly.
1805 pub fn LLVMInlineAsm(Ty: TypeRef,
1806 AsmString: *const c_char,
1807 Constraints: *const c_char,
1813 pub fn LLVMRustDebugMetadataVersion() -> u32;
1814 pub fn LLVMVersionMajor() -> u32;
1815 pub fn LLVMVersionMinor() -> u32;
1817 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1818 name: *const c_char,
1821 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1823 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1825 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1827 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1829 File: *const c_char,
1831 Producer: *const c_char,
1833 Flags: *const c_char,
1835 SplitName: *const c_char)
1838 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1839 Filename: *const c_char,
1840 Directory: *const c_char)
1843 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1845 ParameterTypes: DIArray)
1848 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1849 Scope: DIDescriptor,
1850 Name: *const c_char,
1851 LinkageName: *const c_char,
1855 isLocalToUnit: bool,
1865 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1866 Name: *const c_char,
1867 SizeInBits: c_ulonglong,
1868 AlignInBits: c_ulonglong,
1872 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1874 SizeInBits: c_ulonglong,
1875 AlignInBits: c_ulonglong,
1876 Name: *const c_char)
1879 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1880 Scope: DIDescriptor,
1881 Name: *const c_char,
1884 SizeInBits: c_ulonglong,
1885 AlignInBits: c_ulonglong,
1887 DerivedFrom: DIType,
1889 RunTimeLang: c_uint,
1890 VTableHolder: DIType,
1891 UniqueId: *const c_char)
1894 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1895 Scope: DIDescriptor,
1896 Name: *const c_char,
1899 SizeInBits: c_ulonglong,
1900 AlignInBits: c_ulonglong,
1901 OffsetInBits: c_ulonglong,
1906 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1913 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1915 Name: *const c_char,
1916 LinkageName: *const c_char,
1920 isLocalToUnit: bool,
1923 -> DIGlobalVariable;
1925 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1927 Scope: DIDescriptor,
1928 Name: *const c_char,
1932 AlwaysPreserve: bool,
1934 AddrOps: *const i64,
1935 AddrOpsCount: c_uint,
1939 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1941 AlignInBits: c_ulonglong,
1943 Subscripts: DIArray)
1946 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1948 AlignInBits: c_ulonglong,
1950 Subscripts: DIArray)
1953 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1958 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1959 Ptr: *const DIDescriptor,
1963 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1965 VarInfo: DIVariable,
1966 AddrOps: *const i64,
1967 AddrOpsCount: c_uint,
1969 InsertAtEnd: BasicBlockRef)
1972 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1974 VarInfo: DIVariable,
1975 AddrOps: *const i64,
1976 AddrOpsCount: c_uint,
1978 InsertBefore: ValueRef)
1981 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1982 Name: *const c_char,
1986 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1988 Name: *const c_char,
1991 SizeInBits: c_ulonglong,
1992 AlignInBits: c_ulonglong,
1997 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1999 Name: *const c_char,
2002 SizeInBits: c_ulonglong,
2003 AlignInBits: c_ulonglong,
2006 RunTimeLang: c_uint,
2007 UniqueId: *const c_char)
2010 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
2012 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
2014 Name: *const c_char,
2019 -> DITemplateTypeParameter;
2021 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
2023 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
2025 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
2027 Name: *const c_char,
2032 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
2036 InlinedAt: MetadataRef)
2039 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2040 CompositeType: DIType,
2041 TypeArray: DIArray);
2042 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2043 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2045 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2047 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2048 pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2050 pub fn LLVMRustPassKind(Pass: PassRef) -> SupportedPassKind;
2051 pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef;
2052 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef);
2054 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2056 Features: *const c_char,
2057 Model: CodeGenModel,
2059 Level: CodeGenOptLevel,
2061 PositionIndependentExecutable: bool,
2062 FunctionSections: bool,
2063 DataSections: bool) -> TargetMachineRef;
2064 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2065 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2068 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2070 DisableSimplifyLibCalls: bool);
2071 pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2072 OptLevel: CodeGenOptLevel,
2073 MergeFunctions: bool,
2075 LoopVectorize: bool);
2076 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2077 DisableSimplifyLibCalls: bool);
2078 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2079 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2082 Output: *const c_char,
2083 FileType: FileType) -> bool;
2084 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2086 Output: *const c_char);
2087 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2088 pub fn LLVMRustPrintPasses();
2089 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2090 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2091 AddLifetimes: bool);
2092 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2094 len: size_t) -> bool;
2095 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2096 syms: *const *const c_char,
2098 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2100 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2101 pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2102 pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2103 pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2104 size: *mut size_t) -> *const c_char;
2105 pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2106 size: *mut size_t) -> *const c_char;
2107 pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2108 pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2109 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2111 pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2112 C: DLLStorageClassTypes);
2114 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2115 data: *mut *const c_char) -> c_int;
2117 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2119 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2120 Handler: DiagnosticHandler,
2121 DiagnosticContext: *mut c_void);
2123 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2124 pass_name_out: *mut *const c_char,
2125 function_out: *mut ValueRef,
2126 debugloc_out: *mut DebugLocRef,
2127 message_out: *mut TwineRef);
2128 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2129 cookie_out: *mut c_uint,
2130 message_out: *mut TwineRef,
2131 instruction_out: *mut ValueRef);
2133 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2134 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2135 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2137 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2139 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2140 H: InlineAsmDiagHandler,
2143 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2145 pub fn LLVMRustWriteArchive(Dst: *const c_char,
2147 Members: *const RustArchiveMemberRef,
2149 Kind: ArchiveKind) -> c_int;
2150 pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2151 Name: *const c_char,
2152 Child: ArchiveChildRef) -> RustArchiveMemberRef;
2153 pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2155 pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2156 TM: TargetMachineRef);
2157 pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2159 pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
2160 Inputs: *const ValueRef,
2162 -> OperandBundleDefRef;
2163 pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
2166 #[cfg(have_component_x86)]
2168 pub fn LLVMInitializeX86TargetInfo();
2169 pub fn LLVMInitializeX86Target();
2170 pub fn LLVMInitializeX86TargetMC();
2171 pub fn LLVMInitializeX86AsmPrinter();
2172 pub fn LLVMInitializeX86AsmParser();
2174 #[cfg(have_component_arm)]
2176 pub fn LLVMInitializeARMTargetInfo();
2177 pub fn LLVMInitializeARMTarget();
2178 pub fn LLVMInitializeARMTargetMC();
2179 pub fn LLVMInitializeARMAsmPrinter();
2180 pub fn LLVMInitializeARMAsmParser();
2182 #[cfg(have_component_aarch64)]
2184 pub fn LLVMInitializeAArch64TargetInfo();
2185 pub fn LLVMInitializeAArch64Target();
2186 pub fn LLVMInitializeAArch64TargetMC();
2187 pub fn LLVMInitializeAArch64AsmPrinter();
2188 pub fn LLVMInitializeAArch64AsmParser();
2190 #[cfg(have_component_mips)]
2192 pub fn LLVMInitializeMipsTargetInfo();
2193 pub fn LLVMInitializeMipsTarget();
2194 pub fn LLVMInitializeMipsTargetMC();
2195 pub fn LLVMInitializeMipsAsmPrinter();
2196 pub fn LLVMInitializeMipsAsmParser();
2198 #[cfg(have_component_powerpc)]
2200 pub fn LLVMInitializePowerPCTargetInfo();
2201 pub fn LLVMInitializePowerPCTarget();
2202 pub fn LLVMInitializePowerPCTargetMC();
2203 pub fn LLVMInitializePowerPCAsmPrinter();
2204 pub fn LLVMInitializePowerPCAsmParser();
2206 #[cfg(have_component_pnacl)]
2208 pub fn LLVMInitializePNaClTargetInfo();
2209 pub fn LLVMInitializePNaClTarget();
2210 pub fn LLVMInitializePNaClTargetMC();
2213 // LLVM requires symbols from this library, but apparently they're not printed
2214 // during llvm-config?
2216 #[link(name = "ole32")]
2219 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2221 LLVMSetInstructionCallConv(instr, cc as c_uint);
2224 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2226 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2229 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2231 LLVMSetLinkage(global, link as c_uint);
2235 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2237 LLVMRustSetDLLStorageClass(global, class);
2241 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2243 LLVMSetUnnamedAddr(global, unnamed as Bool);
2247 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2249 LLVMSetThreadLocal(global, is_thread_local as Bool);
2253 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2255 LLVMConstICmp(pred as c_ushort, v1, v2)
2258 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2260 LLVMConstFCmp(pred as c_ushort, v1, v2)
2264 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2266 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2267 attr.bits() as uint64_t)
2271 /* Memory-managed interface to target data. */
2273 pub struct TargetData {
2274 pub lltd: TargetDataRef
2277 impl Drop for TargetData {
2278 fn drop(&mut self) {
2280 LLVMDisposeTargetData(self.lltd);
2285 pub fn mk_target_data(string_rep: &str) -> TargetData {
2286 let string_rep = CString::new(string_rep).unwrap();
2288 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2292 /* Memory-managed interface to object files. */
2294 pub struct ObjectFile {
2295 pub llof: ObjectFileRef,
2299 // This will take ownership of llmb
2300 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2302 let llof = LLVMCreateObjectFile(llmb);
2303 if llof as isize == 0 {
2304 // LLVMCreateObjectFile took ownership of llmb
2315 impl Drop for ObjectFile {
2316 fn drop(&mut self) {
2318 LLVMDisposeObjectFile(self.llof);
2323 /* Memory-managed interface to section iterators. */
2325 pub struct SectionIter {
2326 pub llsi: SectionIteratorRef
2329 impl Drop for SectionIter {
2330 fn drop(&mut self) {
2332 LLVMDisposeSectionIterator(self.llsi);
2337 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2340 llsi: LLVMGetSections(llof)
2345 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2346 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2348 assert!(index < LLVMCountParams(llfn));
2349 LLVMGetParam(llfn, index)
2353 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2355 let num_params = LLVMCountParams(llfn);
2356 let mut params = Vec::with_capacity(num_params as usize);
2357 for idx in 0..num_params {
2358 params.push(LLVMGetParam(llfn, idx));
2365 #[allow(missing_copy_implementations)]
2366 pub enum RustString_opaque {}
2367 pub type RustStringRef = *mut RustString_opaque;
2368 type RustStringRepr = *mut RefCell<Vec<u8>>;
2370 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2372 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2375 let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2377 let sr = sr as RustStringRepr;
2378 (*sr).borrow_mut().extend_from_slice(slice);
2381 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2382 let mut buf = RefCell::new(Vec::new());
2383 f(&mut buf as RustStringRepr as RustStringRef);
2384 String::from_utf8(buf.into_inner()).ok()
2387 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2388 build_string(|s| LLVMWriteTwineToString(tr, s))
2389 .expect("got a non-UTF8 Twine from LLVM")
2392 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2393 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2394 .expect("got a non-UTF8 DebugLoc from LLVM")
2397 pub fn initialize_available_targets() {
2398 macro_rules! init_target(
2399 ($cfg:ident $arch:ident) => { {
2403 let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
2405 let f = concat_idents!(LLVMInitialize, $arch, Target);
2407 let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
2409 let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
2411 let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
2421 init_target!(have_component_powerpc PowerPC);
2422 init_target!(have_component_mips Mips);
2423 init_target!(have_component_aarch64 AArch64);
2424 init_target!(have_component_arm ARM);
2425 init_target!(have_component_x86 X86);
2427 // PNaCl doesn't provide some of the optional target components, so we
2428 // manually initialize it here.
2429 #[cfg(have_component_pnacl)]
2432 LLVMInitializePNaClTargetInfo();
2433 LLVMInitializePNaClTarget();
2434 LLVMInitializePNaClTargetMC();
2437 #[cfg(not(have_component_pnacl))]
2442 pub fn last_error() -> Option<String> {
2444 let cstr = LLVMRustGetLastError();
2448 let err = CStr::from_ptr(cstr).to_bytes();
2449 let err = String::from_utf8_lossy(err).to_string();
2450 libc::free(cstr as *mut _);
2456 pub struct OperandBundleDef {
2457 inner: OperandBundleDefRef,
2460 impl OperandBundleDef {
2461 pub fn new(name: &str, vals: &[ValueRef]) -> OperandBundleDef {
2462 let name = CString::new(name).unwrap();
2464 LLVMRustBuildOperandBundleDef(name.as_ptr(),
2466 vals.len() as c_uint)
2468 OperandBundleDef { inner: def }
2471 pub fn raw(&self) -> OperandBundleDefRef {
2476 impl Drop for OperandBundleDef {
2477 fn drop(&mut self) {
2479 LLVMRustFreeOperandBundleDef(self.inner);
2484 // The module containing the native LLVM dependencies, generated by the build system
2485 // Note that this must come after the rustllvm extern declaration so that
2486 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2487 // Works to the above fix for #15460 to ensure LLVM dependencies that
2488 // are only used by rustllvm don't get stripped by the linker.
2490 include! { env!("CFG_LLVM_LINKAGE_FILE") }