1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![allow(non_upper_case_globals)]
12 #![allow(non_camel_case_types)]
13 #![allow(non_snake_case)]
15 #![allow(trivial_casts)]
17 #![crate_name = "rustc_llvm"]
18 #![unstable(feature = "rustc_private", issue = "27812")]
19 #![crate_type = "dylib"]
20 #![crate_type = "rlib"]
21 #![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
22 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
23 html_root_url = "https://doc.rust-lang.org/nightly/")]
25 #![feature(associated_consts)]
26 #![feature(box_syntax)]
28 #![feature(link_args)]
29 #![feature(staged_api)]
30 #![feature(linked_from)]
31 #![feature(concat_idents)]
34 #[macro_use] #[no_link] extern crate rustc_bitflags;
36 pub use self::OtherAttribute::*;
37 pub use self::SpecialAttribute::*;
38 pub use self::AttributeSet::*;
39 pub use self::IntPredicate::*;
40 pub use self::RealPredicate::*;
41 pub use self::TypeKind::*;
42 pub use self::AtomicBinOp::*;
43 pub use self::AtomicOrdering::*;
44 pub use self::SynchronizationScope::*;
45 pub use self::FileType::*;
46 pub use self::MetadataType::*;
47 pub use self::AsmDialect::*;
48 pub use self::CodeGenOptLevel::*;
49 pub use self::RelocMode::*;
50 pub use self::CodeGenModel::*;
51 pub use self::DiagnosticKind::*;
52 pub use self::CallConv::*;
53 pub use self::Visibility::*;
54 pub use self::DiagnosticSeverity::*;
55 pub use self::Linkage::*;
56 pub use self::DLLStorageClassTypes::*;
58 use std::ffi::CString;
59 use std::cell::RefCell;
61 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
62 use libc::{c_longlong, c_ulonglong, c_void};
63 use debuginfo::{DIBuilderRef, DIDescriptor,
64 DIFile, DILexicalBlock, DISubprogram, DIType,
65 DIBasicType, DIDerivedType, DICompositeType, DIScope,
66 DIVariable, DIGlobalVariable, DIArray, DISubrange,
67 DITemplateTypeParameter, DIEnumerator, DINameSpace};
72 pub type Opcode = u32;
73 pub type Bool = c_uint;
75 pub const True: Bool = 1 as Bool;
76 pub const False: Bool = 0 as Bool;
78 // Consts for the LLVM CallConv type, pre-cast to usize.
80 #[derive(Copy, Clone, PartialEq)]
85 X86StdcallCallConv = 64,
86 X86FastcallCallConv = 65,
91 #[derive(Copy, Clone)]
93 LLVMDefaultVisibility = 0,
95 ProtectedVisibility = 2,
98 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
99 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
100 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
101 // they've been removed in upstream LLVM commit r203866.
102 #[derive(Copy, Clone)]
105 AvailableExternallyLinkage = 1,
106 LinkOnceAnyLinkage = 2,
107 LinkOnceODRLinkage = 3,
110 AppendingLinkage = 7,
113 ExternalWeakLinkage = 12,
118 #[derive(Copy, Clone, Debug)]
119 pub enum DiagnosticSeverity {
128 #[derive(Copy, Clone)]
129 pub enum DLLStorageClassTypes {
130 DefaultStorageClass = 0,
131 DLLImportStorageClass = 1,
132 DLLExportStorageClass = 2,
136 flags Attribute : u64 {
139 const NoReturn = 1 << 2,
140 const InReg = 1 << 3,
141 const StructRet = 1 << 4,
142 const NoUnwind = 1 << 5,
143 const NoAlias = 1 << 6,
144 const ByVal = 1 << 7,
146 const ReadNone = 1 << 9,
147 const ReadOnly = 1 << 10,
148 const NoInline = 1 << 11,
149 const AlwaysInline = 1 << 12,
150 const OptimizeForSize = 1 << 13,
151 const StackProtect = 1 << 14,
152 const StackProtectReq = 1 << 15,
153 const Alignment = 1 << 16,
154 const NoCapture = 1 << 21,
155 const NoRedZone = 1 << 22,
156 const NoImplicitFloat = 1 << 23,
157 const Naked = 1 << 24,
158 const InlineHint = 1 << 25,
159 const Stack = 7 << 26,
160 const ReturnsTwice = 1 << 29,
161 const UWTable = 1 << 30,
162 const NonLazyBind = 1 << 31,
163 const OptimizeNone = 1 << 42,
169 #[derive(Copy, Clone)]
170 pub enum OtherAttribute {
171 // The following are not really exposed in
172 // the LLVM C api so instead to add these
173 // we call a wrapper function in RustWrapper
174 // that uses the C++ api.
175 SanitizeAddressAttribute = 1 << 32,
176 MinSizeAttribute = 1 << 33,
177 NoDuplicateAttribute = 1 << 34,
178 StackProtectStrongAttribute = 1 << 35,
179 SanitizeThreadAttribute = 1 << 36,
180 SanitizeMemoryAttribute = 1 << 37,
181 NoBuiltinAttribute = 1 << 38,
182 ReturnedAttribute = 1 << 39,
183 ColdAttribute = 1 << 40,
184 BuiltinAttribute = 1 << 41,
185 OptimizeNoneAttribute = 1 << 42,
186 InAllocaAttribute = 1 << 43,
187 NonNullAttribute = 1 << 44,
190 #[derive(Copy, Clone)]
191 pub enum SpecialAttribute {
192 DereferenceableAttribute(u64)
196 #[derive(Copy, Clone)]
197 pub enum AttributeSet {
202 pub trait AttrHelper {
203 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
204 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
207 impl AttrHelper for Attribute {
208 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
210 LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
214 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
216 LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
221 impl AttrHelper for OtherAttribute {
222 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
224 LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
228 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
230 LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
235 impl AttrHelper for SpecialAttribute {
236 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
238 DereferenceableAttribute(bytes) => unsafe {
239 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
244 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
246 DereferenceableAttribute(bytes) => unsafe {
247 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
253 pub struct AttrBuilder {
254 attrs: Vec<(usize, Box<AttrHelper+'static>)>
258 pub fn new() -> AttrBuilder {
264 pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: usize, a: T) -> &'a mut AttrBuilder {
265 self.attrs.push((idx, box a as Box<AttrHelper+'static>));
269 pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
270 self.attrs.push((ReturnIndex as usize, box a as Box<AttrHelper+'static>));
274 pub fn apply_llfn(&self, llfn: ValueRef) {
275 for &(idx, ref attr) in &self.attrs {
276 attr.apply_llfn(idx as c_uint, llfn);
280 pub fn apply_callsite(&self, callsite: ValueRef) {
281 for &(idx, ref attr) in &self.attrs {
282 attr.apply_callsite(idx as c_uint, callsite);
287 // enum for the LLVM IntPredicate type
288 #[derive(Copy, Clone)]
289 pub enum IntPredicate {
302 // enum for the LLVM RealPredicate type
303 #[derive(Copy, Clone)]
304 pub enum RealPredicate {
305 RealPredicateFalse = 0,
320 RealPredicateTrue = 15,
323 // The LLVM TypeKind type - must stay in sync with the def of
324 // LLVMTypeKind in llvm/include/llvm-c/Core.h
325 #[derive(Copy, Clone, PartialEq, Debug)]
347 #[derive(Copy, Clone)]
348 pub enum AtomicBinOp {
363 #[derive(Copy, Clone)]
364 pub enum AtomicOrdering {
368 // Consume = 3, // Not specified yet.
372 SequentiallyConsistent = 7
376 #[derive(Copy, Clone)]
377 pub enum SynchronizationScope {
382 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
384 #[derive(Copy, Clone)]
386 AssemblyFileType = 0,
390 #[derive(Copy, Clone)]
391 pub enum MetadataType {
398 MD_invariant_load = 6,
402 MD_mem_parallel_loop_access = 10,
406 // Inline Asm Dialect
407 #[derive(Copy, Clone)]
408 pub enum AsmDialect {
413 #[derive(Copy, Clone, PartialEq)]
415 pub enum CodeGenOptLevel {
416 CodeGenLevelNone = 0,
417 CodeGenLevelLess = 1,
418 CodeGenLevelDefault = 2,
419 CodeGenLevelAggressive = 3,
422 #[derive(Copy, Clone, PartialEq)]
428 RelocDynamicNoPic = 3,
432 #[derive(Copy, Clone)]
433 pub enum CodeGenModel {
434 CodeModelDefault = 0,
435 CodeModelJITDefault = 1,
443 #[derive(Copy, Clone)]
444 pub enum DiagnosticKind {
447 DK_DebugMetadataVersion,
449 DK_OptimizationRemark,
450 DK_OptimizationRemarkMissed,
451 DK_OptimizationRemarkAnalysis,
452 DK_OptimizationFailure,
456 #[derive(Copy, Clone)]
457 pub enum ArchiveKind {
464 // Opaque pointer types
465 #[allow(missing_copy_implementations)]
466 pub enum Module_opaque {}
467 pub type ModuleRef = *mut Module_opaque;
468 #[allow(missing_copy_implementations)]
469 pub enum Context_opaque {}
470 pub type ContextRef = *mut Context_opaque;
471 #[allow(missing_copy_implementations)]
472 pub enum Type_opaque {}
473 pub type TypeRef = *mut Type_opaque;
474 #[allow(missing_copy_implementations)]
475 pub enum Value_opaque {}
476 pub type ValueRef = *mut Value_opaque;
477 #[allow(missing_copy_implementations)]
478 pub enum Metadata_opaque {}
479 pub type MetadataRef = *mut Metadata_opaque;
480 #[allow(missing_copy_implementations)]
481 pub enum BasicBlock_opaque {}
482 pub type BasicBlockRef = *mut BasicBlock_opaque;
483 #[allow(missing_copy_implementations)]
484 pub enum Builder_opaque {}
485 pub type BuilderRef = *mut Builder_opaque;
486 #[allow(missing_copy_implementations)]
487 pub enum ExecutionEngine_opaque {}
488 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
489 #[allow(missing_copy_implementations)]
490 pub enum MemoryBuffer_opaque {}
491 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
492 #[allow(missing_copy_implementations)]
493 pub enum PassManager_opaque {}
494 pub type PassManagerRef = *mut PassManager_opaque;
495 #[allow(missing_copy_implementations)]
496 pub enum PassManagerBuilder_opaque {}
497 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
498 #[allow(missing_copy_implementations)]
499 pub enum Use_opaque {}
500 pub type UseRef = *mut Use_opaque;
501 #[allow(missing_copy_implementations)]
502 pub enum TargetData_opaque {}
503 pub type TargetDataRef = *mut TargetData_opaque;
504 #[allow(missing_copy_implementations)]
505 pub enum ObjectFile_opaque {}
506 pub type ObjectFileRef = *mut ObjectFile_opaque;
507 #[allow(missing_copy_implementations)]
508 pub enum SectionIterator_opaque {}
509 pub type SectionIteratorRef = *mut SectionIterator_opaque;
510 #[allow(missing_copy_implementations)]
511 pub enum Pass_opaque {}
512 pub type PassRef = *mut Pass_opaque;
513 #[allow(missing_copy_implementations)]
514 pub enum TargetMachine_opaque {}
515 pub type TargetMachineRef = *mut TargetMachine_opaque;
516 pub enum Archive_opaque {}
517 pub type ArchiveRef = *mut Archive_opaque;
518 pub enum ArchiveIterator_opaque {}
519 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
520 pub enum ArchiveChild_opaque {}
521 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
522 #[allow(missing_copy_implementations)]
523 pub enum Twine_opaque {}
524 pub type TwineRef = *mut Twine_opaque;
525 #[allow(missing_copy_implementations)]
526 pub enum DiagnosticInfo_opaque {}
527 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
528 #[allow(missing_copy_implementations)]
529 pub enum DebugLoc_opaque {}
530 pub type DebugLocRef = *mut DebugLoc_opaque;
531 #[allow(missing_copy_implementations)]
532 pub enum SMDiagnostic_opaque {}
533 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
534 #[allow(missing_copy_implementations)]
535 pub enum RustArchiveMember_opaque {}
536 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
538 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
539 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
542 pub use self::DIDescriptorFlags::*;
543 use super::{MetadataRef};
545 #[allow(missing_copy_implementations)]
546 pub enum DIBuilder_opaque {}
547 pub type DIBuilderRef = *mut DIBuilder_opaque;
549 pub type DIDescriptor = MetadataRef;
550 pub type DIScope = DIDescriptor;
551 pub type DILocation = DIDescriptor;
552 pub type DIFile = DIScope;
553 pub type DILexicalBlock = DIScope;
554 pub type DISubprogram = DIScope;
555 pub type DINameSpace = DIScope;
556 pub type DIType = DIDescriptor;
557 pub type DIBasicType = DIType;
558 pub type DIDerivedType = DIType;
559 pub type DICompositeType = DIDerivedType;
560 pub type DIVariable = DIDescriptor;
561 pub type DIGlobalVariable = DIDescriptor;
562 pub type DIArray = DIDescriptor;
563 pub type DISubrange = DIDescriptor;
564 pub type DIEnumerator = DIDescriptor;
565 pub type DITemplateTypeParameter = DIDescriptor;
567 #[derive(Copy, Clone)]
568 pub enum DIDescriptorFlags {
569 FlagPrivate = 1 << 0,
570 FlagProtected = 1 << 1,
571 FlagFwdDecl = 1 << 2,
572 FlagAppleBlock = 1 << 3,
573 FlagBlockByrefStruct = 1 << 4,
574 FlagVirtual = 1 << 5,
575 FlagArtificial = 1 << 6,
576 FlagExplicit = 1 << 7,
577 FlagPrototyped = 1 << 8,
578 FlagObjcClassComplete = 1 << 9,
579 FlagObjectPointer = 1 << 10,
580 FlagVector = 1 << 11,
581 FlagStaticMember = 1 << 12,
582 FlagIndirectVariable = 1 << 13,
583 FlagLValueReference = 1 << 14,
584 FlagRValueReference = 1 << 15
589 // Link to our native llvm bindings (things that we need to use the C++ api
590 // for) and because llvm is written in C++ we need to link against libstdc++
592 // You'll probably notice that there is an omission of all LLVM libraries
593 // from this location. This is because the set of LLVM libraries that we
594 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
595 // figure out the exact set of libraries. To do this, the build system
596 // generates an llvmdeps.rs file next to this one which will be
597 // automatically updated whenever LLVM is updated to include an up-to-date
598 // set of the libraries we need to link to LLVM for.
599 #[link(name = "rustllvm", kind = "static")]
600 #[linked_from = "rustllvm"] // not quite true but good enough
602 /* Create and destroy contexts. */
603 pub fn LLVMContextCreate() -> ContextRef;
604 pub fn LLVMContextDispose(C: ContextRef);
605 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
610 /* Create and destroy modules. */
611 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
614 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
615 pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
616 pub fn LLVMDisposeModule(M: ModuleRef);
618 /// Data layout. See Module::getDataLayout.
619 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
620 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
622 /// Target triple. See Module::getTargetTriple.
623 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
624 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
626 /// See Module::dump.
627 pub fn LLVMDumpModule(M: ModuleRef);
629 /// See Module::setModuleInlineAsm.
630 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
632 /// See llvm::LLVMTypeKind::getTypeID.
633 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
635 /// See llvm::LLVMType::getContext.
636 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
638 /* Operations on integer types */
639 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
640 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
641 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
642 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
643 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
644 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
647 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
649 /* Operations on real types */
650 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
651 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
652 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
653 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
654 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
656 /* Operations on function types */
657 pub fn LLVMFunctionType(ReturnType: TypeRef,
658 ParamTypes: *const TypeRef,
662 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
663 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
664 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
665 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
667 /* Operations on struct types */
668 pub fn LLVMStructTypeInContext(C: ContextRef,
669 ElementTypes: *const TypeRef,
670 ElementCount: c_uint,
673 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
674 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
676 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
678 /* Operations on array, pointer, and vector types (sequence types) */
679 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
680 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
682 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
685 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
686 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
687 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
688 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
690 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
692 /* Operations on other types */
693 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
694 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
695 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
697 /* Operations on all values */
698 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
699 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
700 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
701 pub fn LLVMDumpValue(Val: ValueRef);
702 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
703 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
704 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
705 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
707 /* Operations on Uses */
708 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
709 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
710 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
711 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
713 /* Operations on Users */
714 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
715 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
716 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
718 /* Operations on constants of any type */
719 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
721 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
722 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
724 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
726 /* only for isize/vector */
727 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
728 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
729 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
730 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
731 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
733 /* Operations on metadata */
734 pub fn LLVMMDStringInContext(C: ContextRef,
738 pub fn LLVMMDNodeInContext(C: ContextRef,
739 Vals: *const ValueRef,
742 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
746 /* Operations on scalar constants */
747 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
749 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
751 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
756 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
757 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
759 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
763 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
764 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
767 /* Operations on composite constants */
768 pub fn LLVMConstStringInContext(C: ContextRef,
771 DontNullTerminate: Bool)
773 pub fn LLVMConstStructInContext(C: ContextRef,
774 ConstantVals: *const ValueRef,
779 pub fn LLVMConstArray(ElementTy: TypeRef,
780 ConstantVals: *const ValueRef,
783 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
786 /* Constant expressions */
787 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
788 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
789 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
790 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
791 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
792 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
793 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
794 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
796 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
798 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
800 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
802 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
804 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
806 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
808 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
810 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
812 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
814 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
816 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
818 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
820 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
822 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
823 RHSConstant: ValueRef)
825 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
827 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
829 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
831 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
833 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
835 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
837 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
839 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
841 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
843 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
845 pub fn LLVMConstGEP(ConstantVal: ValueRef,
846 ConstantIndices: *const ValueRef,
849 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
850 ConstantIndices: *const ValueRef,
853 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
855 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
857 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
859 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
861 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
863 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
865 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
867 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
869 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
871 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
873 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
875 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
877 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
879 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
881 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
883 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
885 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
889 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
891 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
892 ConstantIfTrue: ValueRef,
893 ConstantIfFalse: ValueRef)
895 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
896 IndexConstant: ValueRef)
898 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
899 ElementValueConstant: ValueRef,
900 IndexConstant: ValueRef)
902 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
903 VectorBConstant: ValueRef,
904 MaskConstant: ValueRef)
906 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
907 IdxList: *const c_uint,
910 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
911 ElementValueConstant: ValueRef,
912 IdxList: *const c_uint,
915 pub fn LLVMConstInlineAsm(Ty: TypeRef,
916 AsmString: *const c_char,
917 Constraints: *const c_char,
918 HasSideEffects: Bool,
921 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
925 /* Operations on global variables, functions, and aliases (globals) */
926 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
927 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
928 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
929 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
930 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
931 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
932 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
933 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
934 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
935 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
938 /* Operations on global variables */
939 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
940 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
942 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
945 AddressSpace: c_uint)
947 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
948 pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
949 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
950 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
951 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
952 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
953 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
954 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
955 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
956 ConstantVal: ValueRef);
957 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
958 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
959 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
960 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
961 pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
963 /* Operations on aliases */
964 pub fn LLVMAddAlias(M: ModuleRef,
970 /* Operations on functions */
971 pub fn LLVMAddFunction(M: ModuleRef,
975 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
976 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
977 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
978 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
979 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
980 pub fn LLVMDeleteFunction(Fn: ValueRef);
981 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
985 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
986 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
987 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
988 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
989 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
990 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
991 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
992 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
993 pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
995 Value: *const c_char);
996 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
997 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
998 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
1000 /* Operations on parameters */
1001 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
1002 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
1003 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
1004 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
1005 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
1006 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
1007 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
1008 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
1009 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
1010 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1011 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1012 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1014 /* Operations on basic blocks */
1015 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1016 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1017 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1018 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1019 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1020 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1021 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1022 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1023 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1024 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1025 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1027 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1029 Name: *const c_char)
1031 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1033 Name: *const c_char)
1035 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1037 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1038 MoveAfter: BasicBlockRef);
1040 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1041 MoveBefore: BasicBlockRef);
1043 /* Operations on instructions */
1044 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1045 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1046 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1047 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1048 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1049 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1051 /* Operations on call sites */
1052 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1053 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1054 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1057 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1060 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1063 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1066 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1070 /* Operations on call instructions (only) */
1071 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1072 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1074 /* Operations on load/store instructions (only) */
1075 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1076 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1078 /* Operations on phi nodes */
1079 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1080 IncomingValues: *const ValueRef,
1081 IncomingBlocks: *const BasicBlockRef,
1083 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1084 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1086 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1089 /* Instruction builders */
1090 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1091 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1092 Block: BasicBlockRef,
1094 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1096 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1097 Block: BasicBlockRef);
1098 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1099 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1100 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1101 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1103 Name: *const c_char);
1104 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1106 /* Execution engine */
1107 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1108 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1109 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1110 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1111 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1112 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1116 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1117 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1118 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1121 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1122 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1123 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1124 RetVals: *const ValueRef,
1127 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1128 pub fn LLVMBuildCondBr(B: BuilderRef,
1130 Then: BasicBlockRef,
1131 Else: BasicBlockRef)
1133 pub fn LLVMBuildSwitch(B: BuilderRef,
1135 Else: BasicBlockRef,
1138 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1142 pub fn LLVMBuildInvoke(B: BuilderRef,
1144 Args: *const ValueRef,
1146 Then: BasicBlockRef,
1147 Catch: BasicBlockRef,
1148 Name: *const c_char)
1150 pub fn LLVMRustBuildLandingPad(B: BuilderRef,
1154 Name: *const c_char,
1157 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1158 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1160 /* Add a case to the switch instruction */
1161 pub fn LLVMAddCase(Switch: ValueRef,
1163 Dest: BasicBlockRef);
1165 /* Add a destination to the indirectbr instruction */
1166 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1168 /* Add a clause to the landing pad instruction */
1169 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1171 /* Set the cleanup on a landing pad instruction */
1172 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1175 pub fn LLVMBuildAdd(B: BuilderRef,
1178 Name: *const c_char)
1180 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1183 Name: *const c_char)
1185 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1188 Name: *const c_char)
1190 pub fn LLVMBuildFAdd(B: BuilderRef,
1193 Name: *const c_char)
1195 pub fn LLVMBuildSub(B: BuilderRef,
1198 Name: *const c_char)
1200 pub fn LLVMBuildNSWSub(B: BuilderRef,
1203 Name: *const c_char)
1205 pub fn LLVMBuildNUWSub(B: BuilderRef,
1208 Name: *const c_char)
1210 pub fn LLVMBuildFSub(B: BuilderRef,
1213 Name: *const c_char)
1215 pub fn LLVMBuildMul(B: BuilderRef,
1218 Name: *const c_char)
1220 pub fn LLVMBuildNSWMul(B: BuilderRef,
1223 Name: *const c_char)
1225 pub fn LLVMBuildNUWMul(B: BuilderRef,
1228 Name: *const c_char)
1230 pub fn LLVMBuildFMul(B: BuilderRef,
1233 Name: *const c_char)
1235 pub fn LLVMBuildUDiv(B: BuilderRef,
1238 Name: *const c_char)
1240 pub fn LLVMBuildSDiv(B: BuilderRef,
1243 Name: *const c_char)
1245 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1248 Name: *const c_char)
1250 pub fn LLVMBuildFDiv(B: BuilderRef,
1253 Name: *const c_char)
1255 pub fn LLVMBuildURem(B: BuilderRef,
1258 Name: *const c_char)
1260 pub fn LLVMBuildSRem(B: BuilderRef,
1263 Name: *const c_char)
1265 pub fn LLVMBuildFRem(B: BuilderRef,
1268 Name: *const c_char)
1270 pub fn LLVMBuildShl(B: BuilderRef,
1273 Name: *const c_char)
1275 pub fn LLVMBuildLShr(B: BuilderRef,
1278 Name: *const c_char)
1280 pub fn LLVMBuildAShr(B: BuilderRef,
1283 Name: *const c_char)
1285 pub fn LLVMBuildAnd(B: BuilderRef,
1288 Name: *const c_char)
1290 pub fn LLVMBuildOr(B: BuilderRef,
1293 Name: *const c_char)
1295 pub fn LLVMBuildXor(B: BuilderRef,
1298 Name: *const c_char)
1300 pub fn LLVMBuildBinOp(B: BuilderRef,
1304 Name: *const c_char)
1306 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1308 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1310 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1312 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1314 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1318 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1320 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1321 pub fn LLVMBuildLoad(B: BuilderRef,
1322 PointerVal: ValueRef,
1323 Name: *const c_char)
1326 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1329 pub fn LLVMBuildGEP(B: BuilderRef,
1331 Indices: *const ValueRef,
1333 Name: *const c_char)
1335 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1337 Indices: *const ValueRef,
1339 Name: *const c_char)
1341 pub fn LLVMBuildStructGEP(B: BuilderRef,
1344 Name: *const c_char)
1346 pub fn LLVMBuildGlobalString(B: BuilderRef,
1348 Name: *const c_char)
1350 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1352 Name: *const c_char)
1356 pub fn LLVMBuildTrunc(B: BuilderRef,
1359 Name: *const c_char)
1361 pub fn LLVMBuildZExt(B: BuilderRef,
1364 Name: *const c_char)
1366 pub fn LLVMBuildSExt(B: BuilderRef,
1369 Name: *const c_char)
1371 pub fn LLVMBuildFPToUI(B: BuilderRef,
1374 Name: *const c_char)
1376 pub fn LLVMBuildFPToSI(B: BuilderRef,
1379 Name: *const c_char)
1381 pub fn LLVMBuildUIToFP(B: BuilderRef,
1384 Name: *const c_char)
1386 pub fn LLVMBuildSIToFP(B: BuilderRef,
1389 Name: *const c_char)
1391 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1394 Name: *const c_char)
1396 pub fn LLVMBuildFPExt(B: BuilderRef,
1399 Name: *const c_char)
1401 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1404 Name: *const c_char)
1406 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1409 Name: *const c_char)
1411 pub fn LLVMBuildBitCast(B: BuilderRef,
1414 Name: *const c_char)
1416 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1419 Name: *const c_char)
1421 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1424 Name: *const c_char)
1426 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1429 Name: *const c_char)
1431 pub fn LLVMBuildCast(B: BuilderRef,
1435 Name: *const c_char) -> ValueRef;
1436 pub fn LLVMBuildPointerCast(B: BuilderRef,
1439 Name: *const c_char)
1441 pub fn LLVMBuildIntCast(B: BuilderRef,
1444 Name: *const c_char)
1446 pub fn LLVMBuildFPCast(B: BuilderRef,
1449 Name: *const c_char)
1453 pub fn LLVMBuildICmp(B: BuilderRef,
1457 Name: *const c_char)
1459 pub fn LLVMBuildFCmp(B: BuilderRef,
1463 Name: *const c_char)
1466 /* Miscellaneous instructions */
1467 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1469 pub fn LLVMBuildCall(B: BuilderRef,
1471 Args: *const ValueRef,
1473 Name: *const c_char)
1475 pub fn LLVMBuildSelect(B: BuilderRef,
1479 Name: *const c_char)
1481 pub fn LLVMBuildVAArg(B: BuilderRef,
1484 Name: *const c_char)
1486 pub fn LLVMBuildExtractElement(B: BuilderRef,
1489 Name: *const c_char)
1491 pub fn LLVMBuildInsertElement(B: BuilderRef,
1495 Name: *const c_char)
1497 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1501 Name: *const c_char)
1503 pub fn LLVMBuildExtractValue(B: BuilderRef,
1506 Name: *const c_char)
1508 pub fn LLVMBuildInsertValue(B: BuilderRef,
1512 Name: *const c_char)
1515 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1517 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1519 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1522 Name: *const c_char)
1525 /* Atomic Operations */
1526 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1527 PointerVal: ValueRef,
1528 Name: *const c_char,
1529 Order: AtomicOrdering,
1533 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1536 Order: AtomicOrdering,
1540 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1544 Order: AtomicOrdering,
1545 FailureOrder: AtomicOrdering)
1547 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1551 Order: AtomicOrdering,
1552 SingleThreaded: Bool)
1555 pub fn LLVMBuildAtomicFence(B: BuilderRef,
1556 Order: AtomicOrdering,
1557 Scope: SynchronizationScope);
1560 /* Selected entries from the downcasts. */
1561 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1562 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1564 /// Writes a module to the specified path. Returns 0 on success.
1565 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1567 /// Creates target data from a target layout string.
1568 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1569 /// Adds the target data to the given pass manager. The pass manager
1570 /// references the target data only weakly.
1571 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1572 /// Number of bytes clobbered when doing a Store to *T.
1573 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1576 /// Number of bytes clobbered when doing a Store to *T.
1577 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1580 /// Distance between successive elements in an array of T. Includes ABI padding.
1581 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1583 /// Returns the preferred alignment of a type.
1584 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1586 /// Returns the minimum alignment of a type.
1587 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1590 /// Computes the byte offset of the indexed struct element for a
1592 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1597 /// Returns the minimum alignment of a type when part of a call frame.
1598 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1601 /// Disposes target data.
1602 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1604 /// Creates a pass manager.
1605 pub fn LLVMCreatePassManager() -> PassManagerRef;
1607 /// Creates a function-by-function pass manager
1608 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1611 /// Disposes a pass manager.
1612 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1614 /// Runs a pass manager on a module.
1615 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1617 /// Runs the function passes on the provided function.
1618 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1621 /// Initializes all the function passes scheduled in the manager
1622 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1624 /// Finalizes all the function passes scheduled in the manager
1625 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1627 pub fn LLVMInitializePasses();
1629 /// Adds a verification pass.
1630 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1632 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1633 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1634 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1635 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1636 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1637 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1638 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1639 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1640 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1641 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1642 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1643 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1644 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1645 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1646 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1647 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1648 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1649 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1650 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1651 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1652 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1653 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1654 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1655 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1656 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1657 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1658 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1659 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1660 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1661 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1662 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1663 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1664 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1665 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1666 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1668 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1669 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1670 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1671 OptimizationLevel: c_uint);
1672 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1674 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1675 PMB: PassManagerBuilderRef,
1677 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1678 PMB: PassManagerBuilderRef,
1680 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1681 PMB: PassManagerBuilderRef,
1683 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1684 PMB: PassManagerBuilderRef,
1686 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1687 PMB: PassManagerBuilderRef,
1688 PM: PassManagerRef);
1690 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1691 PMB: PassManagerBuilderRef,
1692 PM: PassManagerRef);
1693 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1694 PMB: PassManagerBuilderRef,
1699 /// Destroys a memory buffer.
1700 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1703 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1705 /// Opens an object file.
1706 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1707 /// Closes an object file.
1708 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1710 /// Enumerates the sections in an object file.
1711 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1712 /// Destroys a section iterator.
1713 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1714 /// Returns true if the section iterator is at the end of the section
1716 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1717 SI: SectionIteratorRef)
1719 /// Moves the section iterator to point to the next section.
1720 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1721 /// Returns the current section size.
1722 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1723 /// Returns the current section contents as a string buffer.
1724 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1726 /// Reads the given file and returns it as a memory buffer. Use
1727 /// LLVMDisposeMemoryBuffer() to get rid of it.
1728 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1730 /// Borrows the contents of the memory buffer (doesn't copy it)
1731 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1732 InputDataLength: size_t,
1733 BufferName: *const c_char,
1736 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1737 InputDataLength: size_t,
1738 BufferName: *const c_char)
1741 pub fn LLVMIsMultithreaded() -> Bool;
1742 pub fn LLVMStartMultithreaded() -> Bool;
1744 /// Returns a string describing the last error caused by an LLVMRust* call.
1745 pub fn LLVMRustGetLastError() -> *const c_char;
1747 /// Print the pass timings since static dtors aren't picking them up.
1748 pub fn LLVMRustPrintPassTimings();
1750 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1752 pub fn LLVMStructSetBody(StructTy: TypeRef,
1753 ElementTypes: *const TypeRef,
1754 ElementCount: c_uint,
1757 pub fn LLVMConstNamedStruct(S: TypeRef,
1758 ConstantVals: *const ValueRef,
1762 /// Enables LLVM debug output.
1763 pub fn LLVMSetDebug(Enabled: c_int);
1765 /// Prepares inline assembly.
1766 pub fn LLVMInlineAsm(Ty: TypeRef,
1767 AsmString: *const c_char,
1768 Constraints: *const c_char,
1774 pub fn LLVMRustDebugMetadataVersion() -> u32;
1775 pub fn LLVMVersionMajor() -> u32;
1776 pub fn LLVMVersionMinor() -> u32;
1778 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1779 name: *const c_char,
1782 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1784 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1786 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1788 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1790 File: *const c_char,
1792 Producer: *const c_char,
1794 Flags: *const c_char,
1796 SplitName: *const c_char)
1799 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1800 Filename: *const c_char,
1801 Directory: *const c_char)
1804 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1806 ParameterTypes: DIArray)
1809 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1810 Scope: DIDescriptor,
1811 Name: *const c_char,
1812 LinkageName: *const c_char,
1816 isLocalToUnit: bool,
1826 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1827 Name: *const c_char,
1828 SizeInBits: c_ulonglong,
1829 AlignInBits: c_ulonglong,
1833 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1835 SizeInBits: c_ulonglong,
1836 AlignInBits: c_ulonglong,
1837 Name: *const c_char)
1840 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1841 Scope: DIDescriptor,
1842 Name: *const c_char,
1845 SizeInBits: c_ulonglong,
1846 AlignInBits: c_ulonglong,
1848 DerivedFrom: DIType,
1850 RunTimeLang: c_uint,
1851 VTableHolder: DIType,
1852 UniqueId: *const c_char)
1855 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1856 Scope: DIDescriptor,
1857 Name: *const c_char,
1860 SizeInBits: c_ulonglong,
1861 AlignInBits: c_ulonglong,
1862 OffsetInBits: c_ulonglong,
1867 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1874 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1876 Name: *const c_char,
1877 LinkageName: *const c_char,
1881 isLocalToUnit: bool,
1884 -> DIGlobalVariable;
1886 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1888 Scope: DIDescriptor,
1889 Name: *const c_char,
1893 AlwaysPreserve: bool,
1895 AddrOps: *const i64,
1896 AddrOpsCount: c_uint,
1900 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1902 AlignInBits: c_ulonglong,
1904 Subscripts: DIArray)
1907 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1909 AlignInBits: c_ulonglong,
1911 Subscripts: DIArray)
1914 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1919 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1920 Ptr: *const DIDescriptor,
1924 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1926 VarInfo: DIVariable,
1927 AddrOps: *const i64,
1928 AddrOpsCount: c_uint,
1930 InsertAtEnd: BasicBlockRef)
1933 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1935 VarInfo: DIVariable,
1936 AddrOps: *const i64,
1937 AddrOpsCount: c_uint,
1939 InsertBefore: ValueRef)
1942 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1943 Name: *const c_char,
1947 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1949 Name: *const c_char,
1952 SizeInBits: c_ulonglong,
1953 AlignInBits: c_ulonglong,
1958 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1960 Name: *const c_char,
1963 SizeInBits: c_ulonglong,
1964 AlignInBits: c_ulonglong,
1967 RunTimeLang: c_uint,
1968 UniqueId: *const c_char)
1971 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1973 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1975 Name: *const c_char,
1980 -> DITemplateTypeParameter;
1982 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1984 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1986 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1988 Name: *const c_char,
1993 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
1997 InlinedAt: MetadataRef)
2000 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
2001 CompositeType: DIType,
2002 TypeArray: DIArray);
2003 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
2004 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2006 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
2008 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2009 pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2011 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
2012 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2014 Features: *const c_char,
2015 Model: CodeGenModel,
2017 Level: CodeGenOptLevel,
2019 PositionIndependentExecutable: bool,
2020 FunctionSections: bool,
2021 DataSections: bool) -> TargetMachineRef;
2022 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2023 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2026 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2028 DisableSimplifyLibCalls: bool);
2029 pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2030 OptLevel: CodeGenOptLevel,
2031 MergeFunctions: bool,
2033 LoopVectorize: bool);
2034 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2035 DisableSimplifyLibCalls: bool);
2036 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2037 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2040 Output: *const c_char,
2041 FileType: FileType) -> bool;
2042 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2044 Output: *const c_char);
2045 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2046 pub fn LLVMRustPrintPasses();
2047 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2048 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2049 AddLifetimes: bool);
2050 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2052 len: size_t) -> bool;
2053 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2054 syms: *const *const c_char,
2056 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2058 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2059 pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2060 pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2061 pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2062 size: *mut size_t) -> *const c_char;
2063 pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2064 size: *mut size_t) -> *const c_char;
2065 pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2066 pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2067 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2069 pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2070 C: DLLStorageClassTypes);
2072 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2073 data: *mut *const c_char) -> c_int;
2075 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2077 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2078 Handler: DiagnosticHandler,
2079 DiagnosticContext: *mut c_void);
2081 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2082 pass_name_out: *mut *const c_char,
2083 function_out: *mut ValueRef,
2084 debugloc_out: *mut DebugLocRef,
2085 message_out: *mut TwineRef);
2086 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2087 cookie_out: *mut c_uint,
2088 message_out: *mut TwineRef,
2089 instruction_out: *mut ValueRef);
2091 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2092 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2093 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2095 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2097 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2098 H: InlineAsmDiagHandler,
2101 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2103 pub fn LLVMRustWriteArchive(Dst: *const c_char,
2105 Members: *const RustArchiveMemberRef,
2107 Kind: ArchiveKind) -> c_int;
2108 pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2109 Name: *const c_char,
2110 Child: ArchiveChildRef) -> RustArchiveMemberRef;
2111 pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2113 pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
2114 TM: TargetMachineRef);
2115 pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2118 #[cfg(have_component_x86)]
2120 pub fn LLVMInitializeX86TargetInfo();
2121 pub fn LLVMInitializeX86Target();
2122 pub fn LLVMInitializeX86TargetMC();
2123 pub fn LLVMInitializeX86AsmPrinter();
2124 pub fn LLVMInitializeX86AsmParser();
2126 #[cfg(have_component_arm)]
2128 pub fn LLVMInitializeARMTargetInfo();
2129 pub fn LLVMInitializeARMTarget();
2130 pub fn LLVMInitializeARMTargetMC();
2131 pub fn LLVMInitializeARMAsmPrinter();
2132 pub fn LLVMInitializeARMAsmParser();
2134 #[cfg(have_component_aarch64)]
2136 pub fn LLVMInitializeAArch64TargetInfo();
2137 pub fn LLVMInitializeAArch64Target();
2138 pub fn LLVMInitializeAArch64TargetMC();
2139 pub fn LLVMInitializeAArch64AsmPrinter();
2140 pub fn LLVMInitializeAArch64AsmParser();
2142 #[cfg(have_component_mips)]
2144 pub fn LLVMInitializeMipsTargetInfo();
2145 pub fn LLVMInitializeMipsTarget();
2146 pub fn LLVMInitializeMipsTargetMC();
2147 pub fn LLVMInitializeMipsAsmPrinter();
2148 pub fn LLVMInitializeMipsAsmParser();
2150 #[cfg(have_component_powerpc)]
2152 pub fn LLVMInitializePowerPCTargetInfo();
2153 pub fn LLVMInitializePowerPCTarget();
2154 pub fn LLVMInitializePowerPCTargetMC();
2155 pub fn LLVMInitializePowerPCAsmPrinter();
2156 pub fn LLVMInitializePowerPCAsmParser();
2158 #[cfg(have_component_pnacl)]
2160 pub fn LLVMInitializePNaClTargetInfo();
2161 pub fn LLVMInitializePNaClTarget();
2162 pub fn LLVMInitializePNaClTargetMC();
2165 // LLVM requires symbols from this library, but apparently they're not printed
2166 // during llvm-config?
2168 #[link(name = "ole32")]
2171 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2173 LLVMSetInstructionCallConv(instr, cc as c_uint);
2176 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2178 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2181 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2183 LLVMSetLinkage(global, link as c_uint);
2187 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2189 LLVMRustSetDLLStorageClass(global, class);
2193 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2195 LLVMSetUnnamedAddr(global, unnamed as Bool);
2199 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2201 LLVMSetThreadLocal(global, is_thread_local as Bool);
2205 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2207 LLVMConstICmp(pred as c_ushort, v1, v2)
2210 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2212 LLVMConstFCmp(pred as c_ushort, v1, v2)
2216 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2218 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
2219 attr.bits() as uint64_t)
2223 /* Memory-managed interface to target data. */
2225 pub struct TargetData {
2226 pub lltd: TargetDataRef
2229 impl Drop for TargetData {
2230 fn drop(&mut self) {
2232 LLVMDisposeTargetData(self.lltd);
2237 pub fn mk_target_data(string_rep: &str) -> TargetData {
2238 let string_rep = CString::new(string_rep).unwrap();
2240 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2244 /* Memory-managed interface to object files. */
2246 pub struct ObjectFile {
2247 pub llof: ObjectFileRef,
2251 // This will take ownership of llmb
2252 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2254 let llof = LLVMCreateObjectFile(llmb);
2255 if llof as isize == 0 {
2256 // LLVMCreateObjectFile took ownership of llmb
2267 impl Drop for ObjectFile {
2268 fn drop(&mut self) {
2270 LLVMDisposeObjectFile(self.llof);
2275 /* Memory-managed interface to section iterators. */
2277 pub struct SectionIter {
2278 pub llsi: SectionIteratorRef
2281 impl Drop for SectionIter {
2282 fn drop(&mut self) {
2284 LLVMDisposeSectionIterator(self.llsi);
2289 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2292 llsi: LLVMGetSections(llof)
2297 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2298 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2300 assert!(index < LLVMCountParams(llfn));
2301 LLVMGetParam(llfn, index)
2305 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2307 let num_params = LLVMCountParams(llfn);
2308 let mut params = Vec::with_capacity(num_params as usize);
2309 for idx in 0..num_params {
2310 params.push(LLVMGetParam(llfn, idx));
2317 #[allow(missing_copy_implementations)]
2318 pub enum RustString_opaque {}
2319 pub type RustStringRef = *mut RustString_opaque;
2320 type RustStringRepr = *mut RefCell<Vec<u8>>;
2322 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2324 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2327 let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2329 let sr = sr as RustStringRepr;
2330 (*sr).borrow_mut().extend_from_slice(slice);
2333 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2334 let mut buf = RefCell::new(Vec::new());
2335 f(&mut buf as RustStringRepr as RustStringRef);
2336 String::from_utf8(buf.into_inner()).ok()
2339 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2340 build_string(|s| LLVMWriteTwineToString(tr, s))
2341 .expect("got a non-UTF8 Twine from LLVM")
2344 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2345 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2346 .expect("got a non-UTF8 DebugLoc from LLVM")
2349 pub fn initialize_available_targets() {
2350 macro_rules! init_target(
2351 ($cfg:ident $arch:ident) => { {
2355 let f = concat_idents!(LLVMInitialize, $arch, TargetInfo);
2357 let f = concat_idents!(LLVMInitialize, $arch, Target);
2359 let f = concat_idents!(LLVMInitialize, $arch, TargetMC);
2361 let f = concat_idents!(LLVMInitialize, $arch, AsmPrinter);
2363 let f = concat_idents!(LLVMInitialize, $arch, AsmParser);
2373 init_target!(have_component_powerpc PowerPC);
2374 init_target!(have_component_mips Mips);
2375 init_target!(have_component_aarch64 AArch64);
2376 init_target!(have_component_arm ARM);
2377 init_target!(have_component_x86 X86);
2379 // PNaCl doesn't provide some of the optional target components, so we
2380 // manually initialize it here.
2381 #[cfg(have_component_pnacl)]
2384 LLVMInitializePNaClTargetInfo();
2385 LLVMInitializePNaClTarget();
2386 LLVMInitializePNaClTargetMC();
2389 #[cfg(not(have_component_pnacl))]
2394 // The module containing the native LLVM dependencies, generated by the build system
2395 // Note that this must come after the rustllvm extern declaration so that
2396 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2397 // Works to the above fix for #15460 to ensure LLVM dependencies that
2398 // are only used by rustllvm don't get stripped by the linker.
2400 include! { env!("CFG_LLVM_LINKAGE_FILE") }