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/")]
24 #![cfg_attr(not(stage0), deny(warnings))]
26 #![feature(associated_consts)]
27 #![feature(box_syntax)]
29 #![feature(link_args)]
30 #![feature(staged_api)]
31 #![feature(linked_from)]
32 #![feature(concat_idents)]
35 #[macro_use] #[no_link] extern crate rustc_bitflags;
37 pub use self::OtherAttribute::*;
38 pub use self::SpecialAttribute::*;
39 pub use self::AttributeSet::*;
40 pub use self::IntPredicate::*;
41 pub use self::RealPredicate::*;
42 pub use self::TypeKind::*;
43 pub use self::AtomicBinOp::*;
44 pub use self::AtomicOrdering::*;
45 pub use self::SynchronizationScope::*;
46 pub use self::FileType::*;
47 pub use self::MetadataType::*;
48 pub use self::AsmDialect::*;
49 pub use self::CodeGenOptLevel::*;
50 pub use self::RelocMode::*;
51 pub use self::CodeGenModel::*;
52 pub use self::DiagnosticKind::*;
53 pub use self::CallConv::*;
54 pub use self::Visibility::*;
55 pub use self::DiagnosticSeverity::*;
56 pub use self::Linkage::*;
57 pub use self::DLLStorageClassTypes::*;
59 use std::ffi::{CString, CStr};
60 use std::cell::RefCell;
62 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
63 use libc::{c_longlong, c_ulonglong, c_void};
64 use debuginfo::{DIBuilderRef, DIDescriptor,
65 DIFile, DILexicalBlock, DISubprogram, DIType,
66 DIBasicType, DIDerivedType, DICompositeType, DIScope,
67 DIVariable, DIGlobalVariable, DIArray, DISubrange,
68 DITemplateTypeParameter, DIEnumerator, DINameSpace};
73 pub type Opcode = u32;
74 pub type Bool = c_uint;
76 pub const True: Bool = 1 as Bool;
77 pub const False: Bool = 0 as Bool;
79 // Consts for the LLVM CallConv type, pre-cast to usize.
81 #[derive(Copy, Clone, PartialEq)]
86 X86StdcallCallConv = 64,
87 X86FastcallCallConv = 65,
92 #[derive(Copy, Clone)]
94 LLVMDefaultVisibility = 0,
96 ProtectedVisibility = 2,
99 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
100 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
101 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
102 // they've been removed in upstream LLVM commit r203866.
103 #[derive(Copy, Clone)]
106 AvailableExternallyLinkage = 1,
107 LinkOnceAnyLinkage = 2,
108 LinkOnceODRLinkage = 3,
111 AppendingLinkage = 7,
114 ExternalWeakLinkage = 12,
119 #[derive(Copy, Clone, Debug)]
120 pub enum DiagnosticSeverity {
129 #[derive(Copy, Clone)]
130 pub enum DLLStorageClassTypes {
131 DefaultStorageClass = 0,
132 DLLImportStorageClass = 1,
133 DLLExportStorageClass = 2,
137 flags Attribute : u64 {
140 const NoReturn = 1 << 2,
141 const InReg = 1 << 3,
142 const StructRet = 1 << 4,
143 const NoUnwind = 1 << 5,
144 const NoAlias = 1 << 6,
145 const ByVal = 1 << 7,
147 const ReadNone = 1 << 9,
148 const ReadOnly = 1 << 10,
149 const NoInline = 1 << 11,
150 const AlwaysInline = 1 << 12,
151 const OptimizeForSize = 1 << 13,
152 const StackProtect = 1 << 14,
153 const StackProtectReq = 1 << 15,
154 const Alignment = 1 << 16,
155 const NoCapture = 1 << 21,
156 const NoRedZone = 1 << 22,
157 const NoImplicitFloat = 1 << 23,
158 const Naked = 1 << 24,
159 const InlineHint = 1 << 25,
160 const Stack = 7 << 26,
161 const ReturnsTwice = 1 << 29,
162 const UWTable = 1 << 30,
163 const NonLazyBind = 1 << 31,
164 const OptimizeNone = 1 << 42,
170 #[derive(Copy, Clone)]
171 pub enum OtherAttribute {
172 // The following are not really exposed in
173 // the LLVM C api so instead to add these
174 // we call a wrapper function in RustWrapper
175 // that uses the C++ api.
176 SanitizeAddressAttribute = 1 << 32,
177 MinSizeAttribute = 1 << 33,
178 NoDuplicateAttribute = 1 << 34,
179 StackProtectStrongAttribute = 1 << 35,
180 SanitizeThreadAttribute = 1 << 36,
181 SanitizeMemoryAttribute = 1 << 37,
182 NoBuiltinAttribute = 1 << 38,
183 ReturnedAttribute = 1 << 39,
184 ColdAttribute = 1 << 40,
185 BuiltinAttribute = 1 << 41,
186 OptimizeNoneAttribute = 1 << 42,
187 InAllocaAttribute = 1 << 43,
188 NonNullAttribute = 1 << 44,
191 #[derive(Copy, Clone)]
192 pub enum SpecialAttribute {
193 DereferenceableAttribute(u64)
197 #[derive(Copy, Clone)]
198 pub enum AttributeSet {
203 pub trait AttrHelper {
204 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
205 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
208 impl AttrHelper for Attribute {
209 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
211 LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
215 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
217 LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
222 impl AttrHelper for OtherAttribute {
223 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
225 LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
229 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
231 LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
236 impl AttrHelper for SpecialAttribute {
237 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
239 DereferenceableAttribute(bytes) => unsafe {
240 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
245 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
247 DereferenceableAttribute(bytes) => unsafe {
248 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
254 pub struct AttrBuilder {
255 attrs: Vec<(usize, Box<AttrHelper+'static>)>
259 pub fn new() -> AttrBuilder {
265 pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: usize, a: T) -> &'a mut AttrBuilder {
266 self.attrs.push((idx, box a as Box<AttrHelper+'static>));
270 pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
271 self.attrs.push((ReturnIndex as usize, box a as Box<AttrHelper+'static>));
275 pub fn apply_llfn(&self, llfn: ValueRef) {
276 for &(idx, ref attr) in &self.attrs {
277 attr.apply_llfn(idx as c_uint, llfn);
281 pub fn apply_callsite(&self, callsite: ValueRef) {
282 for &(idx, ref attr) in &self.attrs {
283 attr.apply_callsite(idx as c_uint, callsite);
288 // enum for the LLVM IntPredicate type
289 #[derive(Copy, Clone)]
290 pub enum IntPredicate {
303 // enum for the LLVM RealPredicate type
304 #[derive(Copy, Clone)]
305 pub enum RealPredicate {
306 RealPredicateFalse = 0,
321 RealPredicateTrue = 15,
324 // The LLVM TypeKind type - must stay in sync with the def of
325 // LLVMTypeKind in llvm/include/llvm-c/Core.h
326 #[derive(Copy, Clone, PartialEq, Debug)]
348 #[derive(Copy, Clone)]
349 pub enum AtomicBinOp {
364 #[derive(Copy, Clone)]
365 pub enum AtomicOrdering {
369 // Consume = 3, // Not specified yet.
373 SequentiallyConsistent = 7
377 #[derive(Copy, Clone)]
378 pub enum SynchronizationScope {
383 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
385 #[derive(Copy, Clone)]
387 AssemblyFileType = 0,
391 #[derive(Copy, Clone)]
392 pub enum MetadataType {
399 MD_invariant_load = 6,
403 MD_mem_parallel_loop_access = 10,
407 // Inline Asm Dialect
408 #[derive(Copy, Clone)]
409 pub enum AsmDialect {
414 #[derive(Copy, Clone, PartialEq)]
416 pub enum CodeGenOptLevel {
417 CodeGenLevelNone = 0,
418 CodeGenLevelLess = 1,
419 CodeGenLevelDefault = 2,
420 CodeGenLevelAggressive = 3,
423 #[derive(Copy, Clone, PartialEq)]
429 RelocDynamicNoPic = 3,
433 #[derive(Copy, Clone)]
434 pub enum CodeGenModel {
435 CodeModelDefault = 0,
436 CodeModelJITDefault = 1,
444 #[derive(Copy, Clone)]
445 pub enum DiagnosticKind {
448 DK_DebugMetadataVersion,
450 DK_OptimizationRemark,
451 DK_OptimizationRemarkMissed,
452 DK_OptimizationRemarkAnalysis,
453 DK_OptimizationFailure,
457 #[derive(Copy, Clone)]
458 pub enum ArchiveKind {
465 /// Represents the different LLVM passes Rust supports
466 #[derive(Copy, Clone, PartialEq, Debug)]
468 pub enum SupportedPassKind {
474 // Opaque pointer types
475 #[allow(missing_copy_implementations)]
476 pub enum Module_opaque {}
477 pub type ModuleRef = *mut Module_opaque;
478 #[allow(missing_copy_implementations)]
479 pub enum Context_opaque {}
480 pub type ContextRef = *mut Context_opaque;
481 #[allow(missing_copy_implementations)]
482 pub enum Type_opaque {}
483 pub type TypeRef = *mut Type_opaque;
484 #[allow(missing_copy_implementations)]
485 pub enum Value_opaque {}
486 pub type ValueRef = *mut Value_opaque;
487 #[allow(missing_copy_implementations)]
488 pub enum Metadata_opaque {}
489 pub type MetadataRef = *mut Metadata_opaque;
490 #[allow(missing_copy_implementations)]
491 pub enum BasicBlock_opaque {}
492 pub type BasicBlockRef = *mut BasicBlock_opaque;
493 #[allow(missing_copy_implementations)]
494 pub enum Builder_opaque {}
495 pub type BuilderRef = *mut Builder_opaque;
496 #[allow(missing_copy_implementations)]
497 pub enum ExecutionEngine_opaque {}
498 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
499 #[allow(missing_copy_implementations)]
500 pub enum MemoryBuffer_opaque {}
501 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
502 #[allow(missing_copy_implementations)]
503 pub enum PassManager_opaque {}
504 pub type PassManagerRef = *mut PassManager_opaque;
505 #[allow(missing_copy_implementations)]
506 pub enum PassManagerBuilder_opaque {}
507 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
508 #[allow(missing_copy_implementations)]
509 pub enum Use_opaque {}
510 pub type UseRef = *mut Use_opaque;
511 #[allow(missing_copy_implementations)]
512 pub enum TargetData_opaque {}
513 pub type TargetDataRef = *mut TargetData_opaque;
514 #[allow(missing_copy_implementations)]
515 pub enum ObjectFile_opaque {}
516 pub type ObjectFileRef = *mut ObjectFile_opaque;
517 #[allow(missing_copy_implementations)]
518 pub enum SectionIterator_opaque {}
519 pub type SectionIteratorRef = *mut SectionIterator_opaque;
520 #[allow(missing_copy_implementations)]
521 pub enum Pass_opaque {}
522 pub type PassRef = *mut Pass_opaque;
523 #[allow(missing_copy_implementations)]
524 pub enum TargetMachine_opaque {}
525 pub type TargetMachineRef = *mut TargetMachine_opaque;
526 pub enum Archive_opaque {}
527 pub type ArchiveRef = *mut Archive_opaque;
528 pub enum ArchiveIterator_opaque {}
529 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
530 pub enum ArchiveChild_opaque {}
531 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
532 #[allow(missing_copy_implementations)]
533 pub enum Twine_opaque {}
534 pub type TwineRef = *mut Twine_opaque;
535 #[allow(missing_copy_implementations)]
536 pub enum DiagnosticInfo_opaque {}
537 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
538 #[allow(missing_copy_implementations)]
539 pub enum DebugLoc_opaque {}
540 pub type DebugLocRef = *mut DebugLoc_opaque;
541 #[allow(missing_copy_implementations)]
542 pub enum SMDiagnostic_opaque {}
543 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
544 #[allow(missing_copy_implementations)]
545 pub enum RustArchiveMember_opaque {}
546 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
547 #[allow(missing_copy_implementations)]
548 pub enum OperandBundleDef_opaque {}
549 pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
551 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
552 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
555 pub use self::DIDescriptorFlags::*;
556 use super::{MetadataRef};
558 #[allow(missing_copy_implementations)]
559 pub enum DIBuilder_opaque {}
560 pub type DIBuilderRef = *mut DIBuilder_opaque;
562 pub type DIDescriptor = MetadataRef;
563 pub type DIScope = DIDescriptor;
564 pub type DILocation = DIDescriptor;
565 pub type DIFile = DIScope;
566 pub type DILexicalBlock = DIScope;
567 pub type DISubprogram = DIScope;
568 pub type DINameSpace = DIScope;
569 pub type DIType = DIDescriptor;
570 pub type DIBasicType = DIType;
571 pub type DIDerivedType = DIType;
572 pub type DICompositeType = DIDerivedType;
573 pub type DIVariable = DIDescriptor;
574 pub type DIGlobalVariable = DIDescriptor;
575 pub type DIArray = DIDescriptor;
576 pub type DISubrange = DIDescriptor;
577 pub type DIEnumerator = DIDescriptor;
578 pub type DITemplateTypeParameter = DIDescriptor;
580 #[derive(Copy, Clone)]
581 pub enum DIDescriptorFlags {
582 FlagPrivate = 1 << 0,
583 FlagProtected = 1 << 1,
584 FlagFwdDecl = 1 << 2,
585 FlagAppleBlock = 1 << 3,
586 FlagBlockByrefStruct = 1 << 4,
587 FlagVirtual = 1 << 5,
588 FlagArtificial = 1 << 6,
589 FlagExplicit = 1 << 7,
590 FlagPrototyped = 1 << 8,
591 FlagObjcClassComplete = 1 << 9,
592 FlagObjectPointer = 1 << 10,
593 FlagVector = 1 << 11,
594 FlagStaticMember = 1 << 12,
595 FlagIndirectVariable = 1 << 13,
596 FlagLValueReference = 1 << 14,
597 FlagRValueReference = 1 << 15
602 // Link to our native llvm bindings (things that we need to use the C++ api
603 // for) and because llvm is written in C++ we need to link against libstdc++
605 // You'll probably notice that there is an omission of all LLVM libraries
606 // from this location. This is because the set of LLVM libraries that we
607 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
608 // figure out the exact set of libraries. To do this, the build system
609 // generates an llvmdeps.rs file next to this one which will be
610 // automatically updated whenever LLVM is updated to include an up-to-date
611 // set of the libraries we need to link to LLVM for.
612 #[link(name = "rustllvm", kind = "static")]
613 #[linked_from = "rustllvm"] // not quite true but good enough
615 /* Create and destroy contexts. */
616 pub fn LLVMContextCreate() -> ContextRef;
617 pub fn LLVMContextDispose(C: ContextRef);
618 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
623 /* Create and destroy modules. */
624 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
627 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
628 pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
629 pub fn LLVMDisposeModule(M: ModuleRef);
631 /// Data layout. See Module::getDataLayout.
632 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
633 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
635 /// Target triple. See Module::getTargetTriple.
636 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
637 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
639 /// See Module::dump.
640 pub fn LLVMDumpModule(M: ModuleRef);
642 /// See Module::setModuleInlineAsm.
643 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
645 /// See llvm::LLVMTypeKind::getTypeID.
646 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
648 /// See llvm::LLVMType::getContext.
649 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
651 /* Operations on integer types */
652 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
653 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
654 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
655 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
656 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
657 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
660 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
662 /* Operations on real types */
663 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
664 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
665 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
666 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
667 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
669 /* Operations on function types */
670 pub fn LLVMFunctionType(ReturnType: TypeRef,
671 ParamTypes: *const TypeRef,
675 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
676 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
677 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
678 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
680 /* Operations on struct types */
681 pub fn LLVMStructTypeInContext(C: ContextRef,
682 ElementTypes: *const TypeRef,
683 ElementCount: c_uint,
686 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
687 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
689 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
691 /* Operations on array, pointer, and vector types (sequence types) */
692 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
693 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
695 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
698 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
699 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
700 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
701 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
703 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
705 /* Operations on other types */
706 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
707 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
708 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
710 /* Operations on all values */
711 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
712 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
713 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
714 pub fn LLVMDumpValue(Val: ValueRef);
715 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
716 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
717 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
718 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
720 /* Operations on Uses */
721 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
722 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
723 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
724 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
726 /* Operations on Users */
727 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
728 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
729 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
731 /* Operations on constants of any type */
732 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
734 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
735 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
737 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
739 /* only for isize/vector */
740 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
741 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
742 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
743 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
744 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
746 /* Operations on metadata */
747 pub fn LLVMMDStringInContext(C: ContextRef,
751 pub fn LLVMMDNodeInContext(C: ContextRef,
752 Vals: *const ValueRef,
755 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
759 /* Operations on scalar constants */
760 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
762 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
764 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
769 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
770 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
772 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
776 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
777 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
780 /* Operations on composite constants */
781 pub fn LLVMConstStringInContext(C: ContextRef,
784 DontNullTerminate: Bool)
786 pub fn LLVMConstStructInContext(C: ContextRef,
787 ConstantVals: *const ValueRef,
792 pub fn LLVMConstArray(ElementTy: TypeRef,
793 ConstantVals: *const ValueRef,
796 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
799 /* Constant expressions */
800 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
801 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
802 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
803 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
804 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
805 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
806 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
807 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
809 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
811 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
813 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
815 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
817 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
819 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
821 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
823 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
825 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
827 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
829 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
831 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
833 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
835 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
836 RHSConstant: ValueRef)
838 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
840 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
842 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
844 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
846 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
848 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
850 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
852 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
854 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
856 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
858 pub fn LLVMConstGEP(ConstantVal: ValueRef,
859 ConstantIndices: *const ValueRef,
862 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
863 ConstantIndices: *const ValueRef,
866 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
868 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
870 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
872 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
874 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
876 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
878 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
880 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
882 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
884 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
886 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
888 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
890 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
892 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
894 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
896 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
898 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
902 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
904 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
905 ConstantIfTrue: ValueRef,
906 ConstantIfFalse: ValueRef)
908 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
909 IndexConstant: ValueRef)
911 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
912 ElementValueConstant: ValueRef,
913 IndexConstant: ValueRef)
915 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
916 VectorBConstant: ValueRef,
917 MaskConstant: ValueRef)
919 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
920 IdxList: *const c_uint,
923 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
924 ElementValueConstant: ValueRef,
925 IdxList: *const c_uint,
928 pub fn LLVMConstInlineAsm(Ty: TypeRef,
929 AsmString: *const c_char,
930 Constraints: *const c_char,
931 HasSideEffects: Bool,
934 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
938 /* Operations on global variables, functions, and aliases (globals) */
939 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
940 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
941 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
942 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
943 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
944 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
945 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
946 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
947 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
948 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
951 /* Operations on global variables */
952 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
953 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
955 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
958 AddressSpace: c_uint)
960 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
961 pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
962 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
963 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
964 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
965 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
966 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
967 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
968 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
969 ConstantVal: ValueRef);
970 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
971 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
972 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
973 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
974 pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
976 /* Operations on aliases */
977 pub fn LLVMAddAlias(M: ModuleRef,
983 /* Operations on functions */
984 pub fn LLVMAddFunction(M: ModuleRef,
988 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
989 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
990 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
991 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
992 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
993 pub fn LLVMDeleteFunction(Fn: ValueRef);
994 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
998 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
999 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
1000 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
1001 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
1002 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
1003 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
1004 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
1005 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1006 pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
1007 Name: *const c_char,
1008 Value: *const c_char);
1009 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1010 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
1011 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
1013 /* Operations on parameters */
1014 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1015 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1016 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1017 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1018 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1019 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1020 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1021 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1022 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1023 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1024 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1025 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1027 /* Operations on basic blocks */
1028 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1029 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1030 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1031 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1032 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1033 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1034 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1035 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1036 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1037 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1038 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1040 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1042 Name: *const c_char)
1044 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1046 Name: *const c_char)
1048 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1050 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1051 MoveAfter: BasicBlockRef);
1053 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1054 MoveBefore: BasicBlockRef);
1056 /* Operations on instructions */
1057 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1058 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1059 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1060 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1061 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1062 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1064 /* Operations on call sites */
1065 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1066 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1067 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1070 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1073 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1076 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1079 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1083 /* Operations on call instructions (only) */
1084 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1085 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1087 /* Operations on load/store instructions (only) */
1088 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1089 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1091 /* Operations on phi nodes */
1092 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1093 IncomingValues: *const ValueRef,
1094 IncomingBlocks: *const BasicBlockRef,
1096 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1097 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1099 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1102 /* Instruction builders */
1103 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1104 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1105 Block: BasicBlockRef,
1107 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1109 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1110 Block: BasicBlockRef);
1111 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1112 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1113 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1114 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1116 Name: *const c_char);
1117 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1119 /* Execution engine */
1120 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1121 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1122 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1123 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1124 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1125 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1129 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1130 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1131 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1134 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1135 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1136 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1137 RetVals: *const ValueRef,
1140 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1141 pub fn LLVMBuildCondBr(B: BuilderRef,
1143 Then: BasicBlockRef,
1144 Else: BasicBlockRef)
1146 pub fn LLVMBuildSwitch(B: BuilderRef,
1148 Else: BasicBlockRef,
1151 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1155 pub fn LLVMRustBuildInvoke(B: BuilderRef,
1157 Args: *const ValueRef,
1159 Then: BasicBlockRef,
1160 Catch: BasicBlockRef,
1161 Bundle: OperandBundleDefRef,
1162 Name: *const c_char)
1164 pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1168 Name: *const c_char,
1171 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1172 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1174 pub fn LLVMRustBuildCleanupPad(B: BuilderRef,
1175 ParentPad: ValueRef,
1177 Args: *const ValueRef,
1178 Name: *const c_char) -> ValueRef;
1179 pub fn LLVMRustBuildCleanupRet(B: BuilderRef,
1180 CleanupPad: ValueRef,
1181 UnwindBB: BasicBlockRef) -> ValueRef;
1182 pub fn LLVMRustBuildCatchPad(B: BuilderRef,
1183 ParentPad: ValueRef,
1185 Args: *const ValueRef,
1186 Name: *const c_char) -> ValueRef;
1187 pub fn LLVMRustBuildCatchRet(B: BuilderRef,
1189 BB: BasicBlockRef) -> ValueRef;
1190 pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef,
1191 ParentPad: ValueRef,
1193 NumHandlers: c_uint,
1194 Name: *const c_char) -> ValueRef;
1195 pub fn LLVMRustAddHandler(CatchSwitch: ValueRef,
1196 Handler: BasicBlockRef);
1197 pub fn LLVMRustSetPersonalityFn(B: BuilderRef, Pers: ValueRef);
1199 /* Add a case to the switch instruction */
1200 pub fn LLVMAddCase(Switch: ValueRef,
1202 Dest: BasicBlockRef);
1204 /* Add a destination to the indirectbr instruction */
1205 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1207 /* Add a clause to the landing pad instruction */
1208 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1210 /* Set the cleanup on a landing pad instruction */
1211 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1214 pub fn LLVMBuildAdd(B: BuilderRef,
1217 Name: *const c_char)
1219 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1222 Name: *const c_char)
1224 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1227 Name: *const c_char)
1229 pub fn LLVMBuildFAdd(B: BuilderRef,
1232 Name: *const c_char)
1234 pub fn LLVMBuildSub(B: BuilderRef,
1237 Name: *const c_char)
1239 pub fn LLVMBuildNSWSub(B: BuilderRef,
1242 Name: *const c_char)
1244 pub fn LLVMBuildNUWSub(B: BuilderRef,
1247 Name: *const c_char)
1249 pub fn LLVMBuildFSub(B: BuilderRef,
1252 Name: *const c_char)
1254 pub fn LLVMBuildMul(B: BuilderRef,
1257 Name: *const c_char)
1259 pub fn LLVMBuildNSWMul(B: BuilderRef,
1262 Name: *const c_char)
1264 pub fn LLVMBuildNUWMul(B: BuilderRef,
1267 Name: *const c_char)
1269 pub fn LLVMBuildFMul(B: BuilderRef,
1272 Name: *const c_char)
1274 pub fn LLVMBuildUDiv(B: BuilderRef,
1277 Name: *const c_char)
1279 pub fn LLVMBuildSDiv(B: BuilderRef,
1282 Name: *const c_char)
1284 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1287 Name: *const c_char)
1289 pub fn LLVMBuildFDiv(B: BuilderRef,
1292 Name: *const c_char)
1294 pub fn LLVMBuildURem(B: BuilderRef,
1297 Name: *const c_char)
1299 pub fn LLVMBuildSRem(B: BuilderRef,
1302 Name: *const c_char)
1304 pub fn LLVMBuildFRem(B: BuilderRef,
1307 Name: *const c_char)
1309 pub fn LLVMBuildShl(B: BuilderRef,
1312 Name: *const c_char)
1314 pub fn LLVMBuildLShr(B: BuilderRef,
1317 Name: *const c_char)
1319 pub fn LLVMBuildAShr(B: BuilderRef,
1322 Name: *const c_char)
1324 pub fn LLVMBuildAnd(B: BuilderRef,
1327 Name: *const c_char)
1329 pub fn LLVMBuildOr(B: BuilderRef,
1332 Name: *const c_char)
1334 pub fn LLVMBuildXor(B: BuilderRef,
1337 Name: *const c_char)
1339 pub fn LLVMBuildBinOp(B: BuilderRef,
1343 Name: *const c_char)
1345 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1347 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1349 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1351 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1353 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1357 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1359 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1360 pub fn LLVMBuildLoad(B: BuilderRef,
1361 PointerVal: ValueRef,
1362 Name: *const c_char)
1365 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1368 pub fn LLVMBuildGEP(B: BuilderRef,
1370 Indices: *const ValueRef,
1372 Name: *const c_char)
1374 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1376 Indices: *const ValueRef,
1378 Name: *const c_char)
1380 pub fn LLVMBuildStructGEP(B: BuilderRef,
1383 Name: *const c_char)
1385 pub fn LLVMBuildGlobalString(B: BuilderRef,
1387 Name: *const c_char)
1389 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1391 Name: *const c_char)
1395 pub fn LLVMBuildTrunc(B: BuilderRef,
1398 Name: *const c_char)
1400 pub fn LLVMBuildZExt(B: BuilderRef,
1403 Name: *const c_char)
1405 pub fn LLVMBuildSExt(B: BuilderRef,
1408 Name: *const c_char)
1410 pub fn LLVMBuildFPToUI(B: BuilderRef,
1413 Name: *const c_char)
1415 pub fn LLVMBuildFPToSI(B: BuilderRef,
1418 Name: *const c_char)
1420 pub fn LLVMBuildUIToFP(B: BuilderRef,
1423 Name: *const c_char)
1425 pub fn LLVMBuildSIToFP(B: BuilderRef,
1428 Name: *const c_char)
1430 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1433 Name: *const c_char)
1435 pub fn LLVMBuildFPExt(B: BuilderRef,
1438 Name: *const c_char)
1440 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1443 Name: *const c_char)
1445 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1448 Name: *const c_char)
1450 pub fn LLVMBuildBitCast(B: BuilderRef,
1453 Name: *const c_char)
1455 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1458 Name: *const c_char)
1460 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1463 Name: *const c_char)
1465 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1468 Name: *const c_char)
1470 pub fn LLVMBuildCast(B: BuilderRef,
1474 Name: *const c_char) -> ValueRef;
1475 pub fn LLVMBuildPointerCast(B: BuilderRef,
1478 Name: *const c_char)
1480 pub fn LLVMBuildIntCast(B: BuilderRef,
1483 Name: *const c_char)
1485 pub fn LLVMBuildFPCast(B: BuilderRef,
1488 Name: *const c_char)
1492 pub fn LLVMBuildICmp(B: BuilderRef,
1496 Name: *const c_char)
1498 pub fn LLVMBuildFCmp(B: BuilderRef,
1502 Name: *const c_char)
1505 /* Miscellaneous instructions */
1506 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1508 pub fn LLVMRustBuildCall(B: BuilderRef,
1510 Args: *const ValueRef,
1512 Bundle: OperandBundleDefRef,
1513 Name: *const c_char)
1515 pub fn LLVMBuildSelect(B: BuilderRef,
1519 Name: *const c_char)
1521 pub fn LLVMBuildVAArg(B: BuilderRef,
1524 Name: *const c_char)
1526 pub fn LLVMBuildExtractElement(B: BuilderRef,
1529 Name: *const c_char)
1531 pub fn LLVMBuildInsertElement(B: BuilderRef,
1535 Name: *const c_char)
1537 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1541 Name: *const c_char)
1543 pub fn LLVMBuildExtractValue(B: BuilderRef,
1546 Name: *const c_char)
1548 pub fn LLVMBuildInsertValue(B: BuilderRef,
1552 Name: *const c_char)
1555 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1557 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1559 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1562 Name: *const c_char)
1565 /* Atomic Operations */
1566 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1567 PointerVal: ValueRef,
1568 Name: *const c_char,
1569 Order: AtomicOrdering,
1573 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1576 Order: AtomicOrdering,
1580 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1584 Order: AtomicOrdering,
1585 FailureOrder: AtomicOrdering)
1587 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1591 Order: AtomicOrdering,
1592 SingleThreaded: Bool)
1595 pub fn LLVMBuildAtomicFence(B: BuilderRef,
1596 Order: AtomicOrdering,
1597 Scope: SynchronizationScope);
1600 /* Selected entries from the downcasts. */
1601 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1602 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1604 /// Writes a module to the specified path. Returns 0 on success.
1605 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1607 /// Creates target data from a target layout string.
1608 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1609 /// Adds the target data to the given pass manager. The pass manager
1610 /// references the target data only weakly.
1611 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1612 /// Number of bytes clobbered when doing a Store to *T.
1613 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1616 /// Number of bytes clobbered when doing a Store to *T.
1617 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1620 /// Distance between successive elements in an array of T. Includes ABI padding.
1621 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1623 /// Returns the preferred alignment of a type.
1624 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1626 /// Returns the minimum alignment of a type.
1627 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1630 /// Computes the byte offset of the indexed struct element for a
1632 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1637 /// Returns the minimum alignment of a type when part of a call frame.
1638 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1641 /// Disposes target data.
1642 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1644 /// Creates a pass manager.
1645 pub fn LLVMCreatePassManager() -> PassManagerRef;
1647 /// Creates a function-by-function pass manager
1648 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1651 /// Disposes a pass manager.
1652 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1654 /// Runs a pass manager on a module.
1655 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1657 /// Runs the function passes on the provided function.
1658 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1661 /// Initializes all the function passes scheduled in the manager
1662 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1664 /// Finalizes all the function passes scheduled in the manager
1665 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1667 pub fn LLVMInitializePasses();
1669 /// Adds a verification pass.
1670 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1672 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1673 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1674 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1675 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1676 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1677 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1678 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1679 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1680 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1681 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1682 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1683 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1684 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1685 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1686 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1687 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1688 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1689 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1690 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1691 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1692 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1693 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1694 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1695 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1696 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1697 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1698 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1699 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1700 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1701 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1702 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1703 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1704 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1705 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1706 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1708 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1709 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1710 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1711 OptimizationLevel: c_uint);
1712 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1714 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1715 PMB: PassManagerBuilderRef,
1717 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1718 PMB: PassManagerBuilderRef,
1720 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1721 PMB: PassManagerBuilderRef,
1723 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1724 PMB: PassManagerBuilderRef,
1726 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1727 PMB: PassManagerBuilderRef,
1728 PM: PassManagerRef);
1730 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1731 PMB: PassManagerBuilderRef,
1732 PM: PassManagerRef);
1733 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1734 PMB: PassManagerBuilderRef,
1739 /// Destroys a memory buffer.
1740 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1743 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1745 /// Opens an object file.
1746 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1747 /// Closes an object file.
1748 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1750 /// Enumerates the sections in an object file.
1751 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1752 /// Destroys a section iterator.
1753 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1754 /// Returns true if the section iterator is at the end of the section
1756 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1757 SI: SectionIteratorRef)
1759 /// Moves the section iterator to point to the next section.
1760 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1761 /// Returns the current section size.
1762 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1763 /// Returns the current section contents as a string buffer.
1764 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1766 /// Reads the given file and returns it as a memory buffer. Use
1767 /// LLVMDisposeMemoryBuffer() to get rid of it.
1768 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1770 /// Borrows the contents of the memory buffer (doesn't copy it)
1771 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1772 InputDataLength: size_t,
1773 BufferName: *const c_char,
1776 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1777 InputDataLength: size_t,
1778 BufferName: *const c_char)
1781 pub fn LLVMIsMultithreaded() -> Bool;
1782 pub fn LLVMStartMultithreaded() -> Bool;
1784 /// Returns a string describing the last error caused by an LLVMRust* call.
1785 pub fn LLVMRustGetLastError() -> *const c_char;
1787 /// Print the pass timings since static dtors aren't picking them up.
1788 pub fn LLVMRustPrintPassTimings();
1790 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1792 pub fn LLVMStructSetBody(StructTy: TypeRef,
1793 ElementTypes: *const TypeRef,
1794 ElementCount: c_uint,
1797 pub fn LLVMConstNamedStruct(S: TypeRef,
1798 ConstantVals: *const ValueRef,
1802 /// Enables LLVM debug output.
1803 pub fn LLVMSetDebug(Enabled: c_int);
1805 /// Prepares inline assembly.
1806 pub fn LLVMInlineAsm(Ty: TypeRef,
1807 AsmString: *const c_char,
1808 Constraints: *const c_char,
1814 pub fn LLVMRustDebugMetadataVersion() -> u32;
1815 pub fn LLVMVersionMajor() -> u32;
1816 pub fn LLVMVersionMinor() -> u32;
1818 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1819 name: *const c_char,
1822 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1824 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1826 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1828 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1830 File: *const c_char,
1832 Producer: *const c_char,
1834 Flags: *const c_char,
1836 SplitName: *const c_char)
1839 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1840 Filename: *const c_char,
1841 Directory: *const c_char)
1844 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1846 ParameterTypes: DIArray)
1849 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1850 Scope: DIDescriptor,
1851 Name: *const c_char,
1852 LinkageName: *const c_char,
1856 isLocalToUnit: bool,
1866 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1867 Name: *const c_char,
1868 SizeInBits: c_ulonglong,
1869 AlignInBits: c_ulonglong,
1873 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1875 SizeInBits: c_ulonglong,
1876 AlignInBits: c_ulonglong,
1877 Name: *const c_char)
1880 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1881 Scope: DIDescriptor,
1882 Name: *const c_char,
1885 SizeInBits: c_ulonglong,
1886 AlignInBits: c_ulonglong,
1888 DerivedFrom: DIType,
1890 RunTimeLang: c_uint,
1891 VTableHolder: DIType,
1892 UniqueId: *const c_char)
1895 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1896 Scope: DIDescriptor,
1897 Name: *const c_char,
1900 SizeInBits: c_ulonglong,
1901 AlignInBits: c_ulonglong,
1902 OffsetInBits: c_ulonglong,
1907 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1914 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1916 Name: *const c_char,
1917 LinkageName: *const c_char,
1921 isLocalToUnit: bool,
1924 -> DIGlobalVariable;
1926 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1928 Scope: DIDescriptor,
1929 Name: *const c_char,
1933 AlwaysPreserve: bool,
1935 AddrOps: *const i64,
1936 AddrOpsCount: c_uint,
1940 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1942 AlignInBits: c_ulonglong,
1944 Subscripts: DIArray)
1947 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1949 AlignInBits: c_ulonglong,
1951 Subscripts: DIArray)
1954 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1959 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1960 Ptr: *const DIDescriptor,
1964 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1966 VarInfo: DIVariable,
1967 AddrOps: *const i64,
1968 AddrOpsCount: c_uint,
1970 InsertAtEnd: BasicBlockRef)
1973 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1975 VarInfo: DIVariable,
1976 AddrOps: *const i64,
1977 AddrOpsCount: c_uint,
1979 InsertBefore: ValueRef)
1982 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1983 Name: *const c_char,
1987 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1989 Name: *const c_char,
1992 SizeInBits: c_ulonglong,
1993 AlignInBits: c_ulonglong,
1998 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
2000 Name: *const c_char,
2003 SizeInBits: c_ulonglong,
2004 AlignInBits: c_ulonglong,
2007 RunTimeLang: c_uint,
2008 UniqueId: *const c_char)
2011 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
2013 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
2015 Name: *const c_char,
2020 -> DITemplateTypeParameter;
2022 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
2024 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
2026 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
2028 Name: *const c_char,
2033 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
2037 InlinedAt: MetadataRef)
2040 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2041 CompositeType: DIType,
2042 TypeArray: DIArray);
2043 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2044 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2046 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2048 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2049 pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2051 pub fn LLVMRustPassKind(Pass: PassRef) -> SupportedPassKind;
2052 pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef;
2053 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef);
2055 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2057 Features: *const c_char,
2058 Model: CodeGenModel,
2060 Level: CodeGenOptLevel,
2062 PositionIndependentExecutable: bool,
2063 FunctionSections: bool,
2064 DataSections: bool) -> TargetMachineRef;
2065 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2066 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2069 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2071 DisableSimplifyLibCalls: bool);
2072 pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2073 OptLevel: CodeGenOptLevel,
2074 MergeFunctions: bool,
2076 LoopVectorize: bool);
2077 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2078 DisableSimplifyLibCalls: bool);
2079 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2080 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2083 Output: *const c_char,
2084 FileType: FileType) -> bool;
2085 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2087 Output: *const c_char);
2088 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2089 pub fn LLVMRustPrintPasses();
2090 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2091 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2092 AddLifetimes: bool);
2093 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2095 len: size_t) -> bool;
2096 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2097 syms: *const *const c_char,
2099 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2101 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2102 pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2103 pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2104 pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2105 size: *mut size_t) -> *const c_char;
2106 pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2107 size: *mut size_t) -> *const c_char;
2108 pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2109 pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2110 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2112 pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2113 C: DLLStorageClassTypes);
2115 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2116 data: *mut *const c_char) -> c_int;
2118 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2120 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2121 Handler: DiagnosticHandler,
2122 DiagnosticContext: *mut c_void);
2124 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2125 pass_name_out: *mut *const c_char,
2126 function_out: *mut ValueRef,
2127 debugloc_out: *mut DebugLocRef,
2128 message_out: *mut TwineRef);
2129 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2130 cookie_out: *mut c_uint,
2131 message_out: *mut TwineRef,
2132 instruction_out: *mut ValueRef);
2134 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2135 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2136 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2138 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2140 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2141 H: InlineAsmDiagHandler,
2144 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2146 pub fn LLVMRustWriteArchive(Dst: *const c_char,
2148 Members: *const RustArchiveMemberRef,
2150 Kind: ArchiveKind) -> c_int;
2151 pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2152 Name: *const c_char,
2153 Child: ArchiveChildRef) -> RustArchiveMemberRef;
2154 pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2156 pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2157 TM: TargetMachineRef);
2158 pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2160 pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
2161 Inputs: *const ValueRef,
2163 -> OperandBundleDefRef;
2164 pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
2167 #[cfg(have_component_x86)]
2169 pub fn LLVMInitializeX86TargetInfo();
2170 pub fn LLVMInitializeX86Target();
2171 pub fn LLVMInitializeX86TargetMC();
2172 pub fn LLVMInitializeX86AsmPrinter();
2173 pub fn LLVMInitializeX86AsmParser();
2175 #[cfg(have_component_arm)]
2177 pub fn LLVMInitializeARMTargetInfo();
2178 pub fn LLVMInitializeARMTarget();
2179 pub fn LLVMInitializeARMTargetMC();
2180 pub fn LLVMInitializeARMAsmPrinter();
2181 pub fn LLVMInitializeARMAsmParser();
2183 #[cfg(have_component_aarch64)]
2185 pub fn LLVMInitializeAArch64TargetInfo();
2186 pub fn LLVMInitializeAArch64Target();
2187 pub fn LLVMInitializeAArch64TargetMC();
2188 pub fn LLVMInitializeAArch64AsmPrinter();
2189 pub fn LLVMInitializeAArch64AsmParser();
2191 #[cfg(have_component_mips)]
2193 pub fn LLVMInitializeMipsTargetInfo();
2194 pub fn LLVMInitializeMipsTarget();
2195 pub fn LLVMInitializeMipsTargetMC();
2196 pub fn LLVMInitializeMipsAsmPrinter();
2197 pub fn LLVMInitializeMipsAsmParser();
2199 #[cfg(have_component_powerpc)]
2201 pub fn LLVMInitializePowerPCTargetInfo();
2202 pub fn LLVMInitializePowerPCTarget();
2203 pub fn LLVMInitializePowerPCTargetMC();
2204 pub fn LLVMInitializePowerPCAsmPrinter();
2205 pub fn LLVMInitializePowerPCAsmParser();
2207 #[cfg(have_component_pnacl)]
2209 pub fn LLVMInitializePNaClTargetInfo();
2210 pub fn LLVMInitializePNaClTarget();
2211 pub fn LLVMInitializePNaClTargetMC();
2214 // LLVM requires symbols from this library, but apparently they're not printed
2215 // during llvm-config?
2217 #[link(name = "ole32")]
2220 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2222 LLVMSetInstructionCallConv(instr, cc as c_uint);
2225 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2227 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2230 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2232 LLVMSetLinkage(global, link as c_uint);
2236 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2238 LLVMRustSetDLLStorageClass(global, class);
2242 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2244 LLVMSetUnnamedAddr(global, unnamed as Bool);
2248 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2250 LLVMSetThreadLocal(global, is_thread_local as Bool);
2254 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2256 LLVMConstICmp(pred as c_ushort, v1, v2)
2259 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2261 LLVMConstFCmp(pred as c_ushort, v1, v2)
2265 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2267 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2268 attr.bits() as uint64_t)
2272 /* Memory-managed interface to target data. */
2274 pub struct TargetData {
2275 pub lltd: TargetDataRef
2278 impl Drop for TargetData {
2279 fn drop(&mut self) {
2281 LLVMDisposeTargetData(self.lltd);
2286 pub fn mk_target_data(string_rep: &str) -> TargetData {
2287 let string_rep = CString::new(string_rep).unwrap();
2289 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2293 /* Memory-managed interface to object files. */
2295 pub struct ObjectFile {
2296 pub llof: ObjectFileRef,
2300 // This will take ownership of llmb
2301 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2303 let llof = LLVMCreateObjectFile(llmb);
2304 if llof as isize == 0 {
2305 // LLVMCreateObjectFile took ownership of llmb
2316 impl Drop for ObjectFile {
2317 fn drop(&mut self) {
2319 LLVMDisposeObjectFile(self.llof);
2324 /* Memory-managed interface to section iterators. */
2326 pub struct SectionIter {
2327 pub llsi: SectionIteratorRef
2330 impl Drop for SectionIter {
2331 fn drop(&mut self) {
2333 LLVMDisposeSectionIterator(self.llsi);
2338 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2341 llsi: LLVMGetSections(llof)
2346 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2347 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2349 assert!(index < LLVMCountParams(llfn));
2350 LLVMGetParam(llfn, index)
2354 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2356 let num_params = LLVMCountParams(llfn);
2357 let mut params = Vec::with_capacity(num_params as usize);
2358 for idx in 0..num_params {
2359 params.push(LLVMGetParam(llfn, idx));
2366 #[allow(missing_copy_implementations)]
2367 pub enum RustString_opaque {}
2368 pub type RustStringRef = *mut RustString_opaque;
2369 type RustStringRepr = *mut RefCell<Vec<u8>>;
2371 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2373 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2376 let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2378 let sr = sr as RustStringRepr;
2379 (*sr).borrow_mut().extend_from_slice(slice);
2382 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2383 let mut buf = RefCell::new(Vec::new());
2384 f(&mut buf as RustStringRepr as RustStringRef);
2385 String::from_utf8(buf.into_inner()).ok()
2388 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2389 build_string(|s| LLVMWriteTwineToString(tr, s))
2390 .expect("got a non-UTF8 Twine from LLVM")
2393 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2394 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2395 .expect("got a non-UTF8 DebugLoc from LLVM")
2398 pub fn initialize_available_targets() {
2399 macro_rules! init_target(
2400 ($cfg:ident $arch:ident) => { {
2404 let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
2406 let f = concat_idents!(LLVMInitialize, $arch, Target);
2408 let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
2410 let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
2412 let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
2422 init_target!(have_component_powerpc PowerPC);
2423 init_target!(have_component_mips Mips);
2424 init_target!(have_component_aarch64 AArch64);
2425 init_target!(have_component_arm ARM);
2426 init_target!(have_component_x86 X86);
2428 // PNaCl doesn't provide some of the optional target components, so we
2429 // manually initialize it here.
2430 #[cfg(have_component_pnacl)]
2433 LLVMInitializePNaClTargetInfo();
2434 LLVMInitializePNaClTarget();
2435 LLVMInitializePNaClTargetMC();
2438 #[cfg(not(have_component_pnacl))]
2443 pub fn last_error() -> Option<String> {
2445 let cstr = LLVMRustGetLastError();
2449 let err = CStr::from_ptr(cstr).to_bytes();
2450 let err = String::from_utf8_lossy(err).to_string();
2451 libc::free(cstr as *mut _);
2457 pub struct OperandBundleDef {
2458 inner: OperandBundleDefRef,
2461 impl OperandBundleDef {
2462 pub fn new(name: &str, vals: &[ValueRef]) -> OperandBundleDef {
2463 let name = CString::new(name).unwrap();
2465 LLVMRustBuildOperandBundleDef(name.as_ptr(),
2467 vals.len() as c_uint)
2469 OperandBundleDef { inner: def }
2472 pub fn raw(&self) -> OperandBundleDefRef {
2477 impl Drop for OperandBundleDef {
2478 fn drop(&mut self) {
2480 LLVMRustFreeOperandBundleDef(self.inner);
2485 // The module containing the native LLVM dependencies, generated by the build system
2486 // Note that this must come after the rustllvm extern declaration so that
2487 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2488 // Works to the above fix for #15460 to ensure LLVM dependencies that
2489 // are only used by rustllvm don't get stripped by the linker.
2491 include! { env!("CFG_LLVM_LINKAGE_FILE") }