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 // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
12 #![cfg_attr(stage0, feature(custom_attribute))]
13 #![allow(non_upper_case_globals)]
14 #![allow(non_camel_case_types)]
15 #![allow(non_snake_case)]
17 #![allow(trivial_casts)]
19 #![crate_name = "rustc_llvm"]
20 #![unstable(feature = "rustc_private")]
22 #![crate_type = "dylib"]
23 #![crate_type = "rlib"]
24 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
25 html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
26 html_root_url = "http://doc.rust-lang.org/nightly/")]
28 #![feature(associated_consts)]
29 #![feature(box_syntax)]
31 #![feature(link_args)]
32 #![feature(staged_api)]
33 #![feature(vec_push_all)]
36 #[macro_use] #[no_link] extern crate rustc_bitflags;
38 pub use self::OtherAttribute::*;
39 pub use self::SpecialAttribute::*;
40 pub use self::AttributeSet::*;
41 pub use self::IntPredicate::*;
42 pub use self::RealPredicate::*;
43 pub use self::TypeKind::*;
44 pub use self::AtomicBinOp::*;
45 pub use self::AtomicOrdering::*;
46 pub use self::SynchronizationScope::*;
47 pub use self::FileType::*;
48 pub use self::MetadataType::*;
49 pub use self::AsmDialect::*;
50 pub use self::CodeGenOptLevel::*;
51 pub use self::RelocMode::*;
52 pub use self::CodeGenModel::*;
53 pub use self::DiagnosticKind::*;
54 pub use self::CallConv::*;
55 pub use self::Visibility::*;
56 pub use self::DiagnosticSeverity::*;
57 pub use self::Linkage::*;
58 pub use self::DLLStorageClassTypes::*;
60 use std::ffi::CString;
61 use std::cell::RefCell;
62 use std::{slice, mem};
63 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
64 use libc::{c_longlong, c_ulonglong, c_void};
65 use debuginfo::{DIBuilderRef, DIDescriptor,
66 DIFile, DILexicalBlock, DISubprogram, DIType,
67 DIBasicType, DIDerivedType, DICompositeType, DIScope,
68 DIVariable, DIGlobalVariable, DIArray, DISubrange,
69 DITemplateTypeParameter, DIEnumerator, DINameSpace};
74 pub type Opcode = u32;
75 pub type Bool = c_uint;
77 pub const True: Bool = 1 as Bool;
78 pub const False: Bool = 0 as Bool;
80 // Consts for the LLVM CallConv type, pre-cast to usize.
82 #[derive(Copy, Clone, PartialEq)]
87 X86StdcallCallConv = 64,
88 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 : u32 {
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,
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,
455 // Opaque pointer types
456 #[allow(missing_copy_implementations)]
457 pub enum Module_opaque {}
458 pub type ModuleRef = *mut Module_opaque;
459 #[allow(missing_copy_implementations)]
460 pub enum Context_opaque {}
461 pub type ContextRef = *mut Context_opaque;
462 #[allow(missing_copy_implementations)]
463 pub enum Type_opaque {}
464 pub type TypeRef = *mut Type_opaque;
465 #[allow(missing_copy_implementations)]
466 pub enum Value_opaque {}
467 pub type ValueRef = *mut Value_opaque;
468 #[allow(missing_copy_implementations)]
469 pub enum Metadata_opaque {}
470 pub type MetadataRef = *mut Metadata_opaque;
471 #[allow(missing_copy_implementations)]
472 pub enum BasicBlock_opaque {}
473 pub type BasicBlockRef = *mut BasicBlock_opaque;
474 #[allow(missing_copy_implementations)]
475 pub enum Builder_opaque {}
476 pub type BuilderRef = *mut Builder_opaque;
477 #[allow(missing_copy_implementations)]
478 pub enum ExecutionEngine_opaque {}
479 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
480 #[allow(missing_copy_implementations)]
481 pub enum MemoryBuffer_opaque {}
482 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
483 #[allow(missing_copy_implementations)]
484 pub enum PassManager_opaque {}
485 pub type PassManagerRef = *mut PassManager_opaque;
486 #[allow(missing_copy_implementations)]
487 pub enum PassManagerBuilder_opaque {}
488 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
489 #[allow(missing_copy_implementations)]
490 pub enum Use_opaque {}
491 pub type UseRef = *mut Use_opaque;
492 #[allow(missing_copy_implementations)]
493 pub enum TargetData_opaque {}
494 pub type TargetDataRef = *mut TargetData_opaque;
495 #[allow(missing_copy_implementations)]
496 pub enum ObjectFile_opaque {}
497 pub type ObjectFileRef = *mut ObjectFile_opaque;
498 #[allow(missing_copy_implementations)]
499 pub enum SectionIterator_opaque {}
500 pub type SectionIteratorRef = *mut SectionIterator_opaque;
501 #[allow(missing_copy_implementations)]
502 pub enum Pass_opaque {}
503 pub type PassRef = *mut Pass_opaque;
504 #[allow(missing_copy_implementations)]
505 pub enum TargetMachine_opaque {}
506 pub type TargetMachineRef = *mut TargetMachine_opaque;
507 pub enum Archive_opaque {}
508 pub type ArchiveRef = *mut Archive_opaque;
509 pub enum ArchiveIterator_opaque {}
510 pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
511 pub enum ArchiveChild_opaque {}
512 pub type ArchiveChildRef = *mut ArchiveChild_opaque;
513 #[allow(missing_copy_implementations)]
514 pub enum Twine_opaque {}
515 pub type TwineRef = *mut Twine_opaque;
516 #[allow(missing_copy_implementations)]
517 pub enum DiagnosticInfo_opaque {}
518 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
519 #[allow(missing_copy_implementations)]
520 pub enum DebugLoc_opaque {}
521 pub type DebugLocRef = *mut DebugLoc_opaque;
522 #[allow(missing_copy_implementations)]
523 pub enum SMDiagnostic_opaque {}
524 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
525 #[allow(missing_copy_implementations)]
526 pub enum RustArchiveMember_opaque {}
527 pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
529 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
530 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
533 pub use self::DIDescriptorFlags::*;
534 use super::{MetadataRef};
536 #[allow(missing_copy_implementations)]
537 pub enum DIBuilder_opaque {}
538 pub type DIBuilderRef = *mut DIBuilder_opaque;
540 pub type DIDescriptor = MetadataRef;
541 pub type DIScope = DIDescriptor;
542 pub type DILocation = DIDescriptor;
543 pub type DIFile = DIScope;
544 pub type DILexicalBlock = DIScope;
545 pub type DISubprogram = DIScope;
546 pub type DINameSpace = DIScope;
547 pub type DIType = DIDescriptor;
548 pub type DIBasicType = DIType;
549 pub type DIDerivedType = DIType;
550 pub type DICompositeType = DIDerivedType;
551 pub type DIVariable = DIDescriptor;
552 pub type DIGlobalVariable = DIDescriptor;
553 pub type DIArray = DIDescriptor;
554 pub type DISubrange = DIDescriptor;
555 pub type DIEnumerator = DIDescriptor;
556 pub type DITemplateTypeParameter = DIDescriptor;
558 #[derive(Copy, Clone)]
559 pub enum DIDescriptorFlags {
560 FlagPrivate = 1 << 0,
561 FlagProtected = 1 << 1,
562 FlagFwdDecl = 1 << 2,
563 FlagAppleBlock = 1 << 3,
564 FlagBlockByrefStruct = 1 << 4,
565 FlagVirtual = 1 << 5,
566 FlagArtificial = 1 << 6,
567 FlagExplicit = 1 << 7,
568 FlagPrototyped = 1 << 8,
569 FlagObjcClassComplete = 1 << 9,
570 FlagObjectPointer = 1 << 10,
571 FlagVector = 1 << 11,
572 FlagStaticMember = 1 << 12,
573 FlagIndirectVariable = 1 << 13,
574 FlagLValueReference = 1 << 14,
575 FlagRValueReference = 1 << 15
580 // Link to our native llvm bindings (things that we need to use the C++ api
581 // for) and because llvm is written in C++ we need to link against libstdc++
583 // You'll probably notice that there is an omission of all LLVM libraries
584 // from this location. This is because the set of LLVM libraries that we
585 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
586 // figure out the exact set of libraries. To do this, the build system
587 // generates an llvmdeps.rs file next to this one which will be
588 // automatically updated whenever LLVM is updated to include an up-to-date
589 // set of the libraries we need to link to LLVM for.
590 #[link(name = "rustllvm", kind = "static")]
592 /* Create and destroy contexts. */
593 pub fn LLVMContextCreate() -> ContextRef;
594 pub fn LLVMContextDispose(C: ContextRef);
595 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
600 /* Create and destroy modules. */
601 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
604 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
605 pub fn LLVMDisposeModule(M: ModuleRef);
607 /// Data layout. See Module::getDataLayout.
608 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
609 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
611 /// Target triple. See Module::getTargetTriple.
612 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
613 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
615 /// See Module::dump.
616 pub fn LLVMDumpModule(M: ModuleRef);
618 /// See Module::setModuleInlineAsm.
619 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
621 /// See llvm::LLVMTypeKind::getTypeID.
622 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
624 /// See llvm::LLVMType::getContext.
625 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
627 /* Operations on integer types */
628 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
629 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
630 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
631 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
632 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
633 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
636 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
638 /* Operations on real types */
639 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
640 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
641 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
642 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
643 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
645 /* Operations on function types */
646 pub fn LLVMFunctionType(ReturnType: TypeRef,
647 ParamTypes: *const TypeRef,
651 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
652 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
653 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
654 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
656 /* Operations on struct types */
657 pub fn LLVMStructTypeInContext(C: ContextRef,
658 ElementTypes: *const TypeRef,
659 ElementCount: c_uint,
662 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
663 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
665 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
667 /* Operations on array, pointer, and vector types (sequence types) */
668 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
669 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
671 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
674 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
675 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
676 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
677 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
679 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
681 /* Operations on other types */
682 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
683 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
684 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
686 /* Operations on all values */
687 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
688 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
689 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
690 pub fn LLVMDumpValue(Val: ValueRef);
691 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
692 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
693 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
694 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
696 /* Operations on Uses */
697 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
698 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
699 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
700 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
702 /* Operations on Users */
703 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
704 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
705 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
707 /* Operations on constants of any type */
708 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
710 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
711 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
713 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
715 /* only for isize/vector */
716 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
717 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
718 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
719 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
720 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
722 /* Operations on metadata */
723 pub fn LLVMMDStringInContext(C: ContextRef,
727 pub fn LLVMMDNodeInContext(C: ContextRef,
728 Vals: *const ValueRef,
731 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
735 /* Operations on scalar constants */
736 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
738 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
740 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
745 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
746 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
748 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
752 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
753 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
756 /* Operations on composite constants */
757 pub fn LLVMConstStringInContext(C: ContextRef,
760 DontNullTerminate: Bool)
762 pub fn LLVMConstStructInContext(C: ContextRef,
763 ConstantVals: *const ValueRef,
768 pub fn LLVMConstArray(ElementTy: TypeRef,
769 ConstantVals: *const ValueRef,
772 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
775 /* Constant expressions */
776 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
777 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
778 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
779 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
780 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
781 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
782 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
783 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
785 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
787 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
789 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
791 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
793 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
795 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
797 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
799 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
801 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
803 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
805 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
807 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
809 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
811 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
812 RHSConstant: ValueRef)
814 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
816 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
818 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
820 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
822 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
824 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
826 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
828 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
830 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
832 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
834 pub fn LLVMConstGEP(ConstantVal: ValueRef,
835 ConstantIndices: *const ValueRef,
838 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
839 ConstantIndices: *const ValueRef,
842 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
844 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
846 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
848 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
850 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
852 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
854 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
856 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
858 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
860 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
862 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
864 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
866 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
868 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
870 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
872 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
874 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
878 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
880 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
881 ConstantIfTrue: ValueRef,
882 ConstantIfFalse: ValueRef)
884 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
885 IndexConstant: ValueRef)
887 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
888 ElementValueConstant: ValueRef,
889 IndexConstant: ValueRef)
891 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
892 VectorBConstant: ValueRef,
893 MaskConstant: ValueRef)
895 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
896 IdxList: *const c_uint,
899 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
900 ElementValueConstant: ValueRef,
901 IdxList: *const c_uint,
904 pub fn LLVMConstInlineAsm(Ty: TypeRef,
905 AsmString: *const c_char,
906 Constraints: *const c_char,
907 HasSideEffects: Bool,
910 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
914 /* Operations on global variables, functions, and aliases (globals) */
915 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
916 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
917 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
918 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
919 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
920 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
921 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
922 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
923 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
924 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
927 /* Operations on global variables */
928 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
929 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
931 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
934 AddressSpace: c_uint)
936 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
937 pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
938 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
939 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
940 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
941 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
942 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
943 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
944 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
945 ConstantVal: ValueRef);
946 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
947 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
948 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
949 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
950 pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
952 /* Operations on aliases */
953 pub fn LLVMAddAlias(M: ModuleRef,
959 /* Operations on functions */
960 pub fn LLVMAddFunction(M: ModuleRef,
964 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
965 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
966 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
967 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
968 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
969 pub fn LLVMDeleteFunction(Fn: ValueRef);
970 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
974 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
975 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
976 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
977 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
978 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
979 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
980 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
981 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
982 pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
984 Value: *const c_char);
985 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
986 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
987 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
989 /* Operations on parameters */
990 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
991 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
992 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
993 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
994 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
995 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
996 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
997 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
998 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
999 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
1000 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
1001 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1003 /* Operations on basic blocks */
1004 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1005 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1006 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1007 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1008 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1009 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1010 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1011 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1012 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1013 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1014 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1016 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1018 Name: *const c_char)
1020 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1022 Name: *const c_char)
1024 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1026 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1027 MoveAfter: BasicBlockRef);
1029 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1030 MoveBefore: BasicBlockRef);
1032 /* Operations on instructions */
1033 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1034 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1035 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1036 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1037 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1038 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1040 /* Operations on call sites */
1041 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1042 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1043 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1046 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1049 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1052 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1055 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1059 /* Operations on call instructions (only) */
1060 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1061 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1063 /* Operations on load/store instructions (only) */
1064 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1065 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1067 /* Operations on phi nodes */
1068 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1069 IncomingValues: *const ValueRef,
1070 IncomingBlocks: *const BasicBlockRef,
1072 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1073 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1075 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1078 /* Instruction builders */
1079 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1080 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1081 Block: BasicBlockRef,
1083 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1085 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1086 Block: BasicBlockRef);
1087 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1088 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1089 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1090 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1092 Name: *const c_char);
1093 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1095 /* Execution engine */
1096 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1097 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1098 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1099 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1100 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1101 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1105 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1106 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1107 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1110 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1111 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1112 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1113 RetVals: *const ValueRef,
1116 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1117 pub fn LLVMBuildCondBr(B: BuilderRef,
1119 Then: BasicBlockRef,
1120 Else: BasicBlockRef)
1122 pub fn LLVMBuildSwitch(B: BuilderRef,
1124 Else: BasicBlockRef,
1127 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1131 pub fn LLVMBuildInvoke(B: BuilderRef,
1133 Args: *const ValueRef,
1135 Then: BasicBlockRef,
1136 Catch: BasicBlockRef,
1137 Name: *const c_char)
1139 pub fn LLVMBuildLandingPad(B: BuilderRef,
1143 Name: *const c_char)
1145 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1146 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1148 /* Add a case to the switch instruction */
1149 pub fn LLVMAddCase(Switch: ValueRef,
1151 Dest: BasicBlockRef);
1153 /* Add a destination to the indirectbr instruction */
1154 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1156 /* Add a clause to the landing pad instruction */
1157 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1159 /* Set the cleanup on a landing pad instruction */
1160 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1163 pub fn LLVMBuildAdd(B: BuilderRef,
1166 Name: *const c_char)
1168 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1171 Name: *const c_char)
1173 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1176 Name: *const c_char)
1178 pub fn LLVMBuildFAdd(B: BuilderRef,
1181 Name: *const c_char)
1183 pub fn LLVMBuildSub(B: BuilderRef,
1186 Name: *const c_char)
1188 pub fn LLVMBuildNSWSub(B: BuilderRef,
1191 Name: *const c_char)
1193 pub fn LLVMBuildNUWSub(B: BuilderRef,
1196 Name: *const c_char)
1198 pub fn LLVMBuildFSub(B: BuilderRef,
1201 Name: *const c_char)
1203 pub fn LLVMBuildMul(B: BuilderRef,
1206 Name: *const c_char)
1208 pub fn LLVMBuildNSWMul(B: BuilderRef,
1211 Name: *const c_char)
1213 pub fn LLVMBuildNUWMul(B: BuilderRef,
1216 Name: *const c_char)
1218 pub fn LLVMBuildFMul(B: BuilderRef,
1221 Name: *const c_char)
1223 pub fn LLVMBuildUDiv(B: BuilderRef,
1226 Name: *const c_char)
1228 pub fn LLVMBuildSDiv(B: BuilderRef,
1231 Name: *const c_char)
1233 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1236 Name: *const c_char)
1238 pub fn LLVMBuildFDiv(B: BuilderRef,
1241 Name: *const c_char)
1243 pub fn LLVMBuildURem(B: BuilderRef,
1246 Name: *const c_char)
1248 pub fn LLVMBuildSRem(B: BuilderRef,
1251 Name: *const c_char)
1253 pub fn LLVMBuildFRem(B: BuilderRef,
1256 Name: *const c_char)
1258 pub fn LLVMBuildShl(B: BuilderRef,
1261 Name: *const c_char)
1263 pub fn LLVMBuildLShr(B: BuilderRef,
1266 Name: *const c_char)
1268 pub fn LLVMBuildAShr(B: BuilderRef,
1271 Name: *const c_char)
1273 pub fn LLVMBuildAnd(B: BuilderRef,
1276 Name: *const c_char)
1278 pub fn LLVMBuildOr(B: BuilderRef,
1281 Name: *const c_char)
1283 pub fn LLVMBuildXor(B: BuilderRef,
1286 Name: *const c_char)
1288 pub fn LLVMBuildBinOp(B: BuilderRef,
1292 Name: *const c_char)
1294 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1296 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1298 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1300 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1302 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1306 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1308 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1309 pub fn LLVMBuildLoad(B: BuilderRef,
1310 PointerVal: ValueRef,
1311 Name: *const c_char)
1314 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1317 pub fn LLVMBuildGEP(B: BuilderRef,
1319 Indices: *const ValueRef,
1321 Name: *const c_char)
1323 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1325 Indices: *const ValueRef,
1327 Name: *const c_char)
1329 pub fn LLVMBuildStructGEP(B: BuilderRef,
1332 Name: *const c_char)
1334 pub fn LLVMBuildGlobalString(B: BuilderRef,
1336 Name: *const c_char)
1338 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1340 Name: *const c_char)
1344 pub fn LLVMBuildTrunc(B: BuilderRef,
1347 Name: *const c_char)
1349 pub fn LLVMBuildZExt(B: BuilderRef,
1352 Name: *const c_char)
1354 pub fn LLVMBuildSExt(B: BuilderRef,
1357 Name: *const c_char)
1359 pub fn LLVMBuildFPToUI(B: BuilderRef,
1362 Name: *const c_char)
1364 pub fn LLVMBuildFPToSI(B: BuilderRef,
1367 Name: *const c_char)
1369 pub fn LLVMBuildUIToFP(B: BuilderRef,
1372 Name: *const c_char)
1374 pub fn LLVMBuildSIToFP(B: BuilderRef,
1377 Name: *const c_char)
1379 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1382 Name: *const c_char)
1384 pub fn LLVMBuildFPExt(B: BuilderRef,
1387 Name: *const c_char)
1389 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1392 Name: *const c_char)
1394 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1397 Name: *const c_char)
1399 pub fn LLVMBuildBitCast(B: BuilderRef,
1402 Name: *const c_char)
1404 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1407 Name: *const c_char)
1409 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1412 Name: *const c_char)
1414 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1417 Name: *const c_char)
1419 pub fn LLVMBuildCast(B: BuilderRef,
1423 Name: *const c_char) -> ValueRef;
1424 pub fn LLVMBuildPointerCast(B: BuilderRef,
1427 Name: *const c_char)
1429 pub fn LLVMBuildIntCast(B: BuilderRef,
1432 Name: *const c_char)
1434 pub fn LLVMBuildFPCast(B: BuilderRef,
1437 Name: *const c_char)
1441 pub fn LLVMBuildICmp(B: BuilderRef,
1445 Name: *const c_char)
1447 pub fn LLVMBuildFCmp(B: BuilderRef,
1451 Name: *const c_char)
1454 /* Miscellaneous instructions */
1455 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1457 pub fn LLVMBuildCall(B: BuilderRef,
1459 Args: *const ValueRef,
1461 Name: *const c_char)
1463 pub fn LLVMBuildSelect(B: BuilderRef,
1467 Name: *const c_char)
1469 pub fn LLVMBuildVAArg(B: BuilderRef,
1472 Name: *const c_char)
1474 pub fn LLVMBuildExtractElement(B: BuilderRef,
1477 Name: *const c_char)
1479 pub fn LLVMBuildInsertElement(B: BuilderRef,
1483 Name: *const c_char)
1485 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1489 Name: *const c_char)
1491 pub fn LLVMBuildExtractValue(B: BuilderRef,
1494 Name: *const c_char)
1496 pub fn LLVMBuildInsertValue(B: BuilderRef,
1500 Name: *const c_char)
1503 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1505 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1507 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1510 Name: *const c_char)
1513 /* Atomic Operations */
1514 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1515 PointerVal: ValueRef,
1516 Name: *const c_char,
1517 Order: AtomicOrdering,
1521 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1524 Order: AtomicOrdering,
1528 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1532 Order: AtomicOrdering,
1533 FailureOrder: AtomicOrdering)
1535 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1539 Order: AtomicOrdering,
1540 SingleThreaded: Bool)
1543 pub fn LLVMBuildAtomicFence(B: BuilderRef,
1544 Order: AtomicOrdering,
1545 Scope: SynchronizationScope);
1548 /* Selected entries from the downcasts. */
1549 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1550 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1552 /// Writes a module to the specified path. Returns 0 on success.
1553 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1555 /// Creates target data from a target layout string.
1556 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1557 /// Adds the target data to the given pass manager. The pass manager
1558 /// references the target data only weakly.
1559 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1560 /// Number of bytes clobbered when doing a Store to *T.
1561 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1564 /// Number of bytes clobbered when doing a Store to *T.
1565 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1568 /// Distance between successive elements in an array of T. Includes ABI padding.
1569 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1571 /// Returns the preferred alignment of a type.
1572 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1574 /// Returns the minimum alignment of a type.
1575 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1578 /// Computes the byte offset of the indexed struct element for a
1580 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1585 /// Returns the minimum alignment of a type when part of a call frame.
1586 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1589 /// Disposes target data.
1590 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1592 /// Creates a pass manager.
1593 pub fn LLVMCreatePassManager() -> PassManagerRef;
1595 /// Creates a function-by-function pass manager
1596 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1599 /// Disposes a pass manager.
1600 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1602 /// Runs a pass manager on a module.
1603 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1605 /// Runs the function passes on the provided function.
1606 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1609 /// Initializes all the function passes scheduled in the manager
1610 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1612 /// Finalizes all the function passes scheduled in the manager
1613 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1615 pub fn LLVMInitializePasses();
1617 /// Adds a verification pass.
1618 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1620 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1621 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1622 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1623 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1624 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1625 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1626 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1627 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1628 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1629 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1630 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1631 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1632 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1633 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1634 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1635 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1636 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1637 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1638 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1639 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1640 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1641 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1642 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1643 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1644 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1645 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1646 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1647 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1648 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1649 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1650 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1651 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1652 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1653 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1654 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1656 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1657 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1658 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1659 OptimizationLevel: c_uint);
1660 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1662 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1663 PMB: PassManagerBuilderRef,
1665 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1666 PMB: PassManagerBuilderRef,
1668 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1669 PMB: PassManagerBuilderRef,
1671 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1672 PMB: PassManagerBuilderRef,
1674 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1675 PMB: PassManagerBuilderRef,
1676 PM: PassManagerRef);
1678 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1679 PMB: PassManagerBuilderRef,
1680 PM: PassManagerRef);
1681 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1682 PMB: PassManagerBuilderRef,
1687 /// Destroys a memory buffer.
1688 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1691 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1693 /// Opens an object file.
1694 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1695 /// Closes an object file.
1696 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1698 /// Enumerates the sections in an object file.
1699 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1700 /// Destroys a section iterator.
1701 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1702 /// Returns true if the section iterator is at the end of the section
1704 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1705 SI: SectionIteratorRef)
1707 /// Moves the section iterator to point to the next section.
1708 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1709 /// Returns the current section size.
1710 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1711 /// Returns the current section contents as a string buffer.
1712 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1714 /// Reads the given file and returns it as a memory buffer. Use
1715 /// LLVMDisposeMemoryBuffer() to get rid of it.
1716 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1718 /// Borrows the contents of the memory buffer (doesn't copy it)
1719 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1720 InputDataLength: size_t,
1721 BufferName: *const c_char,
1724 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1725 InputDataLength: size_t,
1726 BufferName: *const c_char)
1729 pub fn LLVMIsMultithreaded() -> Bool;
1730 pub fn LLVMStartMultithreaded() -> Bool;
1732 /// Returns a string describing the last error caused by an LLVMRust* call.
1733 pub fn LLVMRustGetLastError() -> *const c_char;
1735 /// Print the pass timings since static dtors aren't picking them up.
1736 pub fn LLVMRustPrintPassTimings();
1738 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1740 pub fn LLVMStructSetBody(StructTy: TypeRef,
1741 ElementTypes: *const TypeRef,
1742 ElementCount: c_uint,
1745 pub fn LLVMConstNamedStruct(S: TypeRef,
1746 ConstantVals: *const ValueRef,
1750 /// Enables LLVM debug output.
1751 pub fn LLVMSetDebug(Enabled: c_int);
1753 /// Prepares inline assembly.
1754 pub fn LLVMInlineAsm(Ty: TypeRef,
1755 AsmString: *const c_char,
1756 Constraints: *const c_char,
1762 pub fn LLVMRustDebugMetadataVersion() -> u32;
1763 pub fn LLVMVersionMajor() -> u32;
1764 pub fn LLVMVersionMinor() -> u32;
1766 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1767 name: *const c_char,
1770 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1772 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1774 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1776 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1778 File: *const c_char,
1780 Producer: *const c_char,
1782 Flags: *const c_char,
1784 SplitName: *const c_char)
1787 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1788 Filename: *const c_char,
1789 Directory: *const c_char)
1792 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1794 ParameterTypes: DIArray)
1797 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1798 Scope: DIDescriptor,
1799 Name: *const c_char,
1800 LinkageName: *const c_char,
1804 isLocalToUnit: bool,
1814 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1815 Name: *const c_char,
1816 SizeInBits: c_ulonglong,
1817 AlignInBits: c_ulonglong,
1821 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1823 SizeInBits: c_ulonglong,
1824 AlignInBits: c_ulonglong,
1825 Name: *const c_char)
1828 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1829 Scope: DIDescriptor,
1830 Name: *const c_char,
1833 SizeInBits: c_ulonglong,
1834 AlignInBits: c_ulonglong,
1836 DerivedFrom: DIType,
1838 RunTimeLang: c_uint,
1839 VTableHolder: DIType,
1840 UniqueId: *const c_char)
1843 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1844 Scope: DIDescriptor,
1845 Name: *const c_char,
1848 SizeInBits: c_ulonglong,
1849 AlignInBits: c_ulonglong,
1850 OffsetInBits: c_ulonglong,
1855 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1862 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1864 Name: *const c_char,
1865 LinkageName: *const c_char,
1869 isLocalToUnit: bool,
1872 -> DIGlobalVariable;
1874 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1876 Scope: DIDescriptor,
1877 Name: *const c_char,
1881 AlwaysPreserve: bool,
1883 AddrOps: *const i64,
1884 AddrOpsCount: c_uint,
1888 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1890 AlignInBits: c_ulonglong,
1892 Subscripts: DIArray)
1895 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1897 AlignInBits: c_ulonglong,
1899 Subscripts: DIArray)
1902 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1907 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1908 Ptr: *const DIDescriptor,
1912 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1914 VarInfo: DIVariable,
1915 AddrOps: *const i64,
1916 AddrOpsCount: c_uint,
1918 InsertAtEnd: BasicBlockRef)
1921 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1923 VarInfo: DIVariable,
1924 AddrOps: *const i64,
1925 AddrOpsCount: c_uint,
1927 InsertBefore: ValueRef)
1930 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1931 Name: *const c_char,
1935 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1937 Name: *const c_char,
1940 SizeInBits: c_ulonglong,
1941 AlignInBits: c_ulonglong,
1946 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1948 Name: *const c_char,
1951 SizeInBits: c_ulonglong,
1952 AlignInBits: c_ulonglong,
1955 RunTimeLang: c_uint,
1956 UniqueId: *const c_char)
1959 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1961 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1963 Name: *const c_char,
1968 -> DITemplateTypeParameter;
1970 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1972 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1974 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1976 Name: *const c_char,
1981 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
1985 InlinedAt: MetadataRef)
1988 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
1989 CompositeType: DIType,
1990 TypeArray: DIArray);
1991 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
1992 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
1994 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1996 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1997 pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
1999 pub fn LLVMInitializeX86TargetInfo();
2000 pub fn LLVMInitializeX86Target();
2001 pub fn LLVMInitializeX86TargetMC();
2002 pub fn LLVMInitializeX86AsmPrinter();
2003 pub fn LLVMInitializeX86AsmParser();
2004 pub fn LLVMInitializeARMTargetInfo();
2005 pub fn LLVMInitializeARMTarget();
2006 pub fn LLVMInitializeARMTargetMC();
2007 pub fn LLVMInitializeARMAsmPrinter();
2008 pub fn LLVMInitializeARMAsmParser();
2009 pub fn LLVMInitializeAArch64TargetInfo();
2010 pub fn LLVMInitializeAArch64Target();
2011 pub fn LLVMInitializeAArch64TargetMC();
2012 pub fn LLVMInitializeAArch64AsmPrinter();
2013 pub fn LLVMInitializeAArch64AsmParser();
2014 pub fn LLVMInitializeMipsTargetInfo();
2015 pub fn LLVMInitializeMipsTarget();
2016 pub fn LLVMInitializeMipsTargetMC();
2017 pub fn LLVMInitializeMipsAsmPrinter();
2018 pub fn LLVMInitializeMipsAsmParser();
2019 pub fn LLVMInitializePowerPCTargetInfo();
2020 pub fn LLVMInitializePowerPCTarget();
2021 pub fn LLVMInitializePowerPCTargetMC();
2022 pub fn LLVMInitializePowerPCAsmPrinter();
2023 pub fn LLVMInitializePowerPCAsmParser();
2025 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
2026 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2028 Features: *const c_char,
2029 Model: CodeGenModel,
2031 Level: CodeGenOptLevel,
2034 PositionIndependentExecutable: bool,
2035 FunctionSections: bool,
2036 DataSections: bool) -> TargetMachineRef;
2037 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2038 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2041 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2043 DisableSimplifyLibCalls: bool);
2044 pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2045 OptLevel: CodeGenOptLevel,
2046 MergeFunctions: bool,
2048 LoopVectorize: bool);
2049 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2050 DisableSimplifyLibCalls: bool);
2051 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2052 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2055 Output: *const c_char,
2056 FileType: FileType) -> bool;
2057 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2059 Output: *const c_char);
2060 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2061 pub fn LLVMRustPrintPasses();
2062 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2063 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2064 AddLifetimes: bool);
2065 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2067 len: size_t) -> bool;
2068 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2069 syms: *const *const c_char,
2071 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2073 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2074 pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2075 pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2076 pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2077 size: *mut size_t) -> *const c_char;
2078 pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2079 size: *mut size_t) -> *const c_char;
2080 pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2081 pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2082 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2084 pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2085 C: DLLStorageClassTypes);
2087 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2088 data: *mut *const c_char) -> c_int;
2090 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2092 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2093 Handler: DiagnosticHandler,
2094 DiagnosticContext: *mut c_void);
2096 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2097 pass_name_out: *mut *const c_char,
2098 function_out: *mut ValueRef,
2099 debugloc_out: *mut DebugLocRef,
2100 message_out: *mut TwineRef);
2101 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2102 cookie_out: *mut c_uint,
2103 message_out: *mut TwineRef,
2104 instruction_out: *mut ValueRef);
2106 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2107 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2108 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2110 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2112 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2113 H: InlineAsmDiagHandler,
2116 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2118 pub fn LLVMRustWriteArchive(Dst: *const c_char,
2120 Members: *const RustArchiveMemberRef,
2121 WriteSymbtab: bool) -> c_int;
2122 pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
2123 Name: *const c_char,
2124 Child: ArchiveChildRef) -> RustArchiveMemberRef;
2125 pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2128 // LLVM requires symbols from this library, but apparently they're not printed
2129 // during llvm-config?
2131 #[link(name = "ole32")]
2134 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2136 LLVMSetInstructionCallConv(instr, cc as c_uint);
2139 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2141 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2144 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2146 LLVMSetLinkage(global, link as c_uint);
2150 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2152 LLVMRustSetDLLStorageClass(global, class);
2156 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2158 LLVMSetUnnamedAddr(global, unnamed as Bool);
2162 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2164 LLVMSetThreadLocal(global, is_thread_local as Bool);
2168 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2170 LLVMConstICmp(pred as c_ushort, v1, v2)
2173 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2175 LLVMConstFCmp(pred as c_ushort, v1, v2)
2179 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2181 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr.bits() as uint64_t)
2185 /* Memory-managed interface to target data. */
2187 pub struct TargetData {
2188 pub lltd: TargetDataRef
2191 impl Drop for TargetData {
2192 fn drop(&mut self) {
2194 LLVMDisposeTargetData(self.lltd);
2199 pub fn mk_target_data(string_rep: &str) -> TargetData {
2200 let string_rep = CString::new(string_rep).unwrap();
2202 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2206 /* Memory-managed interface to object files. */
2208 pub struct ObjectFile {
2209 pub llof: ObjectFileRef,
2213 // This will take ownership of llmb
2214 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2216 let llof = LLVMCreateObjectFile(llmb);
2217 if llof as isize == 0 {
2218 // LLVMCreateObjectFile took ownership of llmb
2229 impl Drop for ObjectFile {
2230 fn drop(&mut self) {
2232 LLVMDisposeObjectFile(self.llof);
2237 /* Memory-managed interface to section iterators. */
2239 pub struct SectionIter {
2240 pub llsi: SectionIteratorRef
2243 impl Drop for SectionIter {
2244 fn drop(&mut self) {
2246 LLVMDisposeSectionIterator(self.llsi);
2251 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2254 llsi: LLVMGetSections(llof)
2259 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2260 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2262 assert!(index < LLVMCountParams(llfn));
2263 LLVMGetParam(llfn, index)
2267 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2269 let num_params = LLVMCountParams(llfn);
2270 let mut params = Vec::with_capacity(num_params as usize);
2271 for idx in 0..num_params {
2272 params.push(LLVMGetParam(llfn, idx));
2279 #[allow(missing_copy_implementations)]
2280 pub enum RustString_opaque {}
2281 pub type RustStringRef = *mut RustString_opaque;
2282 type RustStringRepr = *mut RefCell<Vec<u8>>;
2284 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2286 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2289 let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2291 let sr: RustStringRepr = mem::transmute(sr);
2292 (*sr).borrow_mut().push_all(slice);
2295 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2296 let mut buf = RefCell::new(Vec::new());
2297 f(&mut buf as RustStringRepr as RustStringRef);
2298 String::from_utf8(buf.into_inner()).ok()
2301 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2302 build_string(|s| LLVMWriteTwineToString(tr, s))
2303 .expect("got a non-UTF8 Twine from LLVM")
2306 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2307 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2308 .expect("got a non-UTF8 DebugLoc from LLVM")
2311 // The module containing the native LLVM dependencies, generated by the build system
2312 // Note that this must come after the rustllvm extern declaration so that
2313 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2314 // Works to the above fix for #15460 to ensure LLVM dependencies that
2315 // are only used by rustllvm don't get stripped by the linker.
2317 include! { env!("CFG_LLVM_LINKAGE_FILE") }