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;
526 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
527 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
530 pub use self::DIDescriptorFlags::*;
531 use super::{MetadataRef};
533 #[allow(missing_copy_implementations)]
534 pub enum DIBuilder_opaque {}
535 pub type DIBuilderRef = *mut DIBuilder_opaque;
537 pub type DIDescriptor = MetadataRef;
538 pub type DIScope = DIDescriptor;
539 pub type DILocation = DIDescriptor;
540 pub type DIFile = DIScope;
541 pub type DILexicalBlock = DIScope;
542 pub type DISubprogram = DIScope;
543 pub type DINameSpace = DIScope;
544 pub type DIType = DIDescriptor;
545 pub type DIBasicType = DIType;
546 pub type DIDerivedType = DIType;
547 pub type DICompositeType = DIDerivedType;
548 pub type DIVariable = DIDescriptor;
549 pub type DIGlobalVariable = DIDescriptor;
550 pub type DIArray = DIDescriptor;
551 pub type DISubrange = DIDescriptor;
552 pub type DIEnumerator = DIDescriptor;
553 pub type DITemplateTypeParameter = DIDescriptor;
555 #[derive(Copy, Clone)]
556 pub enum DIDescriptorFlags {
557 FlagPrivate = 1 << 0,
558 FlagProtected = 1 << 1,
559 FlagFwdDecl = 1 << 2,
560 FlagAppleBlock = 1 << 3,
561 FlagBlockByrefStruct = 1 << 4,
562 FlagVirtual = 1 << 5,
563 FlagArtificial = 1 << 6,
564 FlagExplicit = 1 << 7,
565 FlagPrototyped = 1 << 8,
566 FlagObjcClassComplete = 1 << 9,
567 FlagObjectPointer = 1 << 10,
568 FlagVector = 1 << 11,
569 FlagStaticMember = 1 << 12,
570 FlagIndirectVariable = 1 << 13,
571 FlagLValueReference = 1 << 14,
572 FlagRValueReference = 1 << 15
577 // Link to our native llvm bindings (things that we need to use the C++ api
578 // for) and because llvm is written in C++ we need to link against libstdc++
580 // You'll probably notice that there is an omission of all LLVM libraries
581 // from this location. This is because the set of LLVM libraries that we
582 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
583 // figure out the exact set of libraries. To do this, the build system
584 // generates an llvmdeps.rs file next to this one which will be
585 // automatically updated whenever LLVM is updated to include an up-to-date
586 // set of the libraries we need to link to LLVM for.
587 #[link(name = "rustllvm", kind = "static")]
589 /* Create and destroy contexts. */
590 pub fn LLVMContextCreate() -> ContextRef;
591 pub fn LLVMContextDispose(C: ContextRef);
592 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
597 /* Create and destroy modules. */
598 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
601 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
602 pub fn LLVMDisposeModule(M: ModuleRef);
604 /// Data layout. See Module::getDataLayout.
605 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
606 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
608 /// Target triple. See Module::getTargetTriple.
609 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
610 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
612 /// See Module::dump.
613 pub fn LLVMDumpModule(M: ModuleRef);
615 /// See Module::setModuleInlineAsm.
616 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
618 /// See llvm::LLVMTypeKind::getTypeID.
619 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
621 /// See llvm::LLVMType::getContext.
622 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
624 /* Operations on integer types */
625 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
626 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
627 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
628 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
629 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
630 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
633 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
635 /* Operations on real types */
636 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
637 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
638 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
639 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
640 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
642 /* Operations on function types */
643 pub fn LLVMFunctionType(ReturnType: TypeRef,
644 ParamTypes: *const TypeRef,
648 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
649 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
650 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
651 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
653 /* Operations on struct types */
654 pub fn LLVMStructTypeInContext(C: ContextRef,
655 ElementTypes: *const TypeRef,
656 ElementCount: c_uint,
659 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
660 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
662 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
664 /* Operations on array, pointer, and vector types (sequence types) */
665 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
666 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
668 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
671 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
672 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
673 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
674 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
676 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
678 /* Operations on other types */
679 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
680 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
681 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
683 /* Operations on all values */
684 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
685 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
686 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
687 pub fn LLVMDumpValue(Val: ValueRef);
688 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
689 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
690 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
691 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
693 /* Operations on Uses */
694 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
695 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
696 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
697 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
699 /* Operations on Users */
700 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
701 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
702 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
704 /* Operations on constants of any type */
705 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
707 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
708 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
710 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
712 /* only for isize/vector */
713 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
714 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
715 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
716 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
717 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
719 /* Operations on metadata */
720 pub fn LLVMMDStringInContext(C: ContextRef,
724 pub fn LLVMMDNodeInContext(C: ContextRef,
725 Vals: *const ValueRef,
728 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
732 /* Operations on scalar constants */
733 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
735 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
737 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
742 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
743 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
745 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
749 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
750 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
753 /* Operations on composite constants */
754 pub fn LLVMConstStringInContext(C: ContextRef,
757 DontNullTerminate: Bool)
759 pub fn LLVMConstStructInContext(C: ContextRef,
760 ConstantVals: *const ValueRef,
765 pub fn LLVMConstArray(ElementTy: TypeRef,
766 ConstantVals: *const ValueRef,
769 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
772 /* Constant expressions */
773 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
774 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
775 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
776 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
777 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
778 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
779 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
780 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
782 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
784 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
786 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
788 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
790 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
792 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
794 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
796 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
798 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
800 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
802 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
804 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
806 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
808 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
809 RHSConstant: ValueRef)
811 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
813 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
815 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
817 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
819 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
821 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
823 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
825 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
827 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
829 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
831 pub fn LLVMConstGEP(ConstantVal: ValueRef,
832 ConstantIndices: *const ValueRef,
835 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
836 ConstantIndices: *const ValueRef,
839 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
841 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
843 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
845 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
847 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
849 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
851 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
853 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
855 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
857 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
859 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
861 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
863 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
865 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
867 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
869 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
871 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
875 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
877 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
878 ConstantIfTrue: ValueRef,
879 ConstantIfFalse: ValueRef)
881 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
882 IndexConstant: ValueRef)
884 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
885 ElementValueConstant: ValueRef,
886 IndexConstant: ValueRef)
888 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
889 VectorBConstant: ValueRef,
890 MaskConstant: ValueRef)
892 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
893 IdxList: *const c_uint,
896 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
897 ElementValueConstant: ValueRef,
898 IdxList: *const c_uint,
901 pub fn LLVMConstInlineAsm(Ty: TypeRef,
902 AsmString: *const c_char,
903 Constraints: *const c_char,
904 HasSideEffects: Bool,
907 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
911 /* Operations on global variables, functions, and aliases (globals) */
912 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
913 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
914 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
915 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
916 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
917 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
918 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
919 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
920 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
921 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
924 /* Operations on global variables */
925 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
926 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
928 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
931 AddressSpace: c_uint)
933 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
934 pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
935 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
936 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
937 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
938 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
939 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
940 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
941 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
942 ConstantVal: ValueRef);
943 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
944 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
945 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
946 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
947 pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
949 /* Operations on aliases */
950 pub fn LLVMAddAlias(M: ModuleRef,
956 /* Operations on functions */
957 pub fn LLVMAddFunction(M: ModuleRef,
961 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
962 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
963 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
964 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
965 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
966 pub fn LLVMDeleteFunction(Fn: ValueRef);
967 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
971 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
972 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
973 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
974 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
975 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
976 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
977 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
978 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
979 pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
981 Value: *const c_char);
982 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
983 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
984 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_ulonglong);
986 /* Operations on parameters */
987 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
988 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
989 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
990 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
991 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
992 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
993 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
994 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
995 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
996 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
997 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
998 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
1000 /* Operations on basic blocks */
1001 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
1002 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
1003 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
1004 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
1005 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
1006 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
1007 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1008 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1009 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1010 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
1011 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
1013 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
1015 Name: *const c_char)
1017 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
1019 Name: *const c_char)
1021 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
1023 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1024 MoveAfter: BasicBlockRef);
1026 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1027 MoveBefore: BasicBlockRef);
1029 /* Operations on instructions */
1030 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1031 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1032 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1033 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1034 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1035 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1037 /* Operations on call sites */
1038 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1039 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1040 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1043 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1046 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1049 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1052 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1056 /* Operations on call instructions (only) */
1057 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1058 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1060 /* Operations on load/store instructions (only) */
1061 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1062 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1064 /* Operations on phi nodes */
1065 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1066 IncomingValues: *const ValueRef,
1067 IncomingBlocks: *const BasicBlockRef,
1069 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1070 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1072 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1075 /* Instruction builders */
1076 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1077 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1078 Block: BasicBlockRef,
1080 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1082 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1083 Block: BasicBlockRef);
1084 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1085 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1086 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1087 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1089 Name: *const c_char);
1090 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1092 /* Execution engine */
1093 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef) -> ExecutionEngineRef;
1094 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1095 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1096 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1097 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1098 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1102 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1103 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1104 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1107 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1108 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1109 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1110 RetVals: *const ValueRef,
1113 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1114 pub fn LLVMBuildCondBr(B: BuilderRef,
1116 Then: BasicBlockRef,
1117 Else: BasicBlockRef)
1119 pub fn LLVMBuildSwitch(B: BuilderRef,
1121 Else: BasicBlockRef,
1124 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1128 pub fn LLVMBuildInvoke(B: BuilderRef,
1130 Args: *const ValueRef,
1132 Then: BasicBlockRef,
1133 Catch: BasicBlockRef,
1134 Name: *const c_char)
1136 pub fn LLVMBuildLandingPad(B: BuilderRef,
1140 Name: *const c_char)
1142 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1143 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1145 /* Add a case to the switch instruction */
1146 pub fn LLVMAddCase(Switch: ValueRef,
1148 Dest: BasicBlockRef);
1150 /* Add a destination to the indirectbr instruction */
1151 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1153 /* Add a clause to the landing pad instruction */
1154 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1156 /* Set the cleanup on a landing pad instruction */
1157 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1160 pub fn LLVMBuildAdd(B: BuilderRef,
1163 Name: *const c_char)
1165 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1168 Name: *const c_char)
1170 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1173 Name: *const c_char)
1175 pub fn LLVMBuildFAdd(B: BuilderRef,
1178 Name: *const c_char)
1180 pub fn LLVMBuildSub(B: BuilderRef,
1183 Name: *const c_char)
1185 pub fn LLVMBuildNSWSub(B: BuilderRef,
1188 Name: *const c_char)
1190 pub fn LLVMBuildNUWSub(B: BuilderRef,
1193 Name: *const c_char)
1195 pub fn LLVMBuildFSub(B: BuilderRef,
1198 Name: *const c_char)
1200 pub fn LLVMBuildMul(B: BuilderRef,
1203 Name: *const c_char)
1205 pub fn LLVMBuildNSWMul(B: BuilderRef,
1208 Name: *const c_char)
1210 pub fn LLVMBuildNUWMul(B: BuilderRef,
1213 Name: *const c_char)
1215 pub fn LLVMBuildFMul(B: BuilderRef,
1218 Name: *const c_char)
1220 pub fn LLVMBuildUDiv(B: BuilderRef,
1223 Name: *const c_char)
1225 pub fn LLVMBuildSDiv(B: BuilderRef,
1228 Name: *const c_char)
1230 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1233 Name: *const c_char)
1235 pub fn LLVMBuildFDiv(B: BuilderRef,
1238 Name: *const c_char)
1240 pub fn LLVMBuildURem(B: BuilderRef,
1243 Name: *const c_char)
1245 pub fn LLVMBuildSRem(B: BuilderRef,
1248 Name: *const c_char)
1250 pub fn LLVMBuildFRem(B: BuilderRef,
1253 Name: *const c_char)
1255 pub fn LLVMBuildShl(B: BuilderRef,
1258 Name: *const c_char)
1260 pub fn LLVMBuildLShr(B: BuilderRef,
1263 Name: *const c_char)
1265 pub fn LLVMBuildAShr(B: BuilderRef,
1268 Name: *const c_char)
1270 pub fn LLVMBuildAnd(B: BuilderRef,
1273 Name: *const c_char)
1275 pub fn LLVMBuildOr(B: BuilderRef,
1278 Name: *const c_char)
1280 pub fn LLVMBuildXor(B: BuilderRef,
1283 Name: *const c_char)
1285 pub fn LLVMBuildBinOp(B: BuilderRef,
1289 Name: *const c_char)
1291 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1293 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1295 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1297 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1299 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1303 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1305 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1306 pub fn LLVMBuildLoad(B: BuilderRef,
1307 PointerVal: ValueRef,
1308 Name: *const c_char)
1311 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1314 pub fn LLVMBuildGEP(B: BuilderRef,
1316 Indices: *const ValueRef,
1318 Name: *const c_char)
1320 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1322 Indices: *const ValueRef,
1324 Name: *const c_char)
1326 pub fn LLVMBuildStructGEP(B: BuilderRef,
1329 Name: *const c_char)
1331 pub fn LLVMBuildGlobalString(B: BuilderRef,
1333 Name: *const c_char)
1335 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1337 Name: *const c_char)
1341 pub fn LLVMBuildTrunc(B: BuilderRef,
1344 Name: *const c_char)
1346 pub fn LLVMBuildZExt(B: BuilderRef,
1349 Name: *const c_char)
1351 pub fn LLVMBuildSExt(B: BuilderRef,
1354 Name: *const c_char)
1356 pub fn LLVMBuildFPToUI(B: BuilderRef,
1359 Name: *const c_char)
1361 pub fn LLVMBuildFPToSI(B: BuilderRef,
1364 Name: *const c_char)
1366 pub fn LLVMBuildUIToFP(B: BuilderRef,
1369 Name: *const c_char)
1371 pub fn LLVMBuildSIToFP(B: BuilderRef,
1374 Name: *const c_char)
1376 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1379 Name: *const c_char)
1381 pub fn LLVMBuildFPExt(B: BuilderRef,
1384 Name: *const c_char)
1386 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1389 Name: *const c_char)
1391 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1394 Name: *const c_char)
1396 pub fn LLVMBuildBitCast(B: BuilderRef,
1399 Name: *const c_char)
1401 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1404 Name: *const c_char)
1406 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1409 Name: *const c_char)
1411 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1414 Name: *const c_char)
1416 pub fn LLVMBuildCast(B: BuilderRef,
1420 Name: *const c_char) -> ValueRef;
1421 pub fn LLVMBuildPointerCast(B: BuilderRef,
1424 Name: *const c_char)
1426 pub fn LLVMBuildIntCast(B: BuilderRef,
1429 Name: *const c_char)
1431 pub fn LLVMBuildFPCast(B: BuilderRef,
1434 Name: *const c_char)
1438 pub fn LLVMBuildICmp(B: BuilderRef,
1442 Name: *const c_char)
1444 pub fn LLVMBuildFCmp(B: BuilderRef,
1448 Name: *const c_char)
1451 /* Miscellaneous instructions */
1452 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1454 pub fn LLVMBuildCall(B: BuilderRef,
1456 Args: *const ValueRef,
1458 Name: *const c_char)
1460 pub fn LLVMBuildSelect(B: BuilderRef,
1464 Name: *const c_char)
1466 pub fn LLVMBuildVAArg(B: BuilderRef,
1469 Name: *const c_char)
1471 pub fn LLVMBuildExtractElement(B: BuilderRef,
1474 Name: *const c_char)
1476 pub fn LLVMBuildInsertElement(B: BuilderRef,
1480 Name: *const c_char)
1482 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1486 Name: *const c_char)
1488 pub fn LLVMBuildExtractValue(B: BuilderRef,
1491 Name: *const c_char)
1493 pub fn LLVMBuildInsertValue(B: BuilderRef,
1497 Name: *const c_char)
1500 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1502 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1504 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1507 Name: *const c_char)
1510 /* Atomic Operations */
1511 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1512 PointerVal: ValueRef,
1513 Name: *const c_char,
1514 Order: AtomicOrdering,
1518 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1521 Order: AtomicOrdering,
1525 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1529 Order: AtomicOrdering,
1530 FailureOrder: AtomicOrdering)
1532 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1536 Order: AtomicOrdering,
1537 SingleThreaded: Bool)
1540 pub fn LLVMBuildAtomicFence(B: BuilderRef,
1541 Order: AtomicOrdering,
1542 Scope: SynchronizationScope);
1545 /* Selected entries from the downcasts. */
1546 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1547 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1549 /// Writes a module to the specified path. Returns 0 on success.
1550 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1552 /// Creates target data from a target layout string.
1553 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1554 /// Adds the target data to the given pass manager. The pass manager
1555 /// references the target data only weakly.
1556 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1557 /// Number of bytes clobbered when doing a Store to *T.
1558 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1561 /// Number of bytes clobbered when doing a Store to *T.
1562 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1565 /// Distance between successive elements in an array of T. Includes ABI padding.
1566 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1568 /// Returns the preferred alignment of a type.
1569 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1571 /// Returns the minimum alignment of a type.
1572 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1575 /// Computes the byte offset of the indexed struct element for a
1577 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1582 /// Returns the minimum alignment of a type when part of a call frame.
1583 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1586 /// Disposes target data.
1587 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1589 /// Creates a pass manager.
1590 pub fn LLVMCreatePassManager() -> PassManagerRef;
1592 /// Creates a function-by-function pass manager
1593 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1596 /// Disposes a pass manager.
1597 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1599 /// Runs a pass manager on a module.
1600 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1602 /// Runs the function passes on the provided function.
1603 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1606 /// Initializes all the function passes scheduled in the manager
1607 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1609 /// Finalizes all the function passes scheduled in the manager
1610 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1612 pub fn LLVMInitializePasses();
1614 /// Adds a verification pass.
1615 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1617 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1618 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1619 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1620 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1621 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1622 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1623 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1624 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1625 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1626 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1627 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1628 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1629 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1630 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1631 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1632 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1633 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1634 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1635 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1636 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1637 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1638 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1639 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1640 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1641 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1642 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1643 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1644 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1645 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1646 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1647 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1648 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1649 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1650 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1651 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1653 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1654 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1655 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1656 OptimizationLevel: c_uint);
1657 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1659 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1660 PMB: PassManagerBuilderRef,
1662 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1663 PMB: PassManagerBuilderRef,
1665 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1666 PMB: PassManagerBuilderRef,
1668 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1669 PMB: PassManagerBuilderRef,
1671 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1672 PMB: PassManagerBuilderRef,
1673 PM: PassManagerRef);
1675 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1676 PMB: PassManagerBuilderRef,
1677 PM: PassManagerRef);
1678 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1679 PMB: PassManagerBuilderRef,
1684 /// Destroys a memory buffer.
1685 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1688 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1690 /// Opens an object file.
1691 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1692 /// Closes an object file.
1693 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1695 /// Enumerates the sections in an object file.
1696 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1697 /// Destroys a section iterator.
1698 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1699 /// Returns true if the section iterator is at the end of the section
1701 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1702 SI: SectionIteratorRef)
1704 /// Moves the section iterator to point to the next section.
1705 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1706 /// Returns the current section size.
1707 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1708 /// Returns the current section contents as a string buffer.
1709 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1711 /// Reads the given file and returns it as a memory buffer. Use
1712 /// LLVMDisposeMemoryBuffer() to get rid of it.
1713 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1715 /// Borrows the contents of the memory buffer (doesn't copy it)
1716 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1717 InputDataLength: size_t,
1718 BufferName: *const c_char,
1721 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1722 InputDataLength: size_t,
1723 BufferName: *const c_char)
1726 pub fn LLVMIsMultithreaded() -> Bool;
1727 pub fn LLVMStartMultithreaded() -> Bool;
1729 /// Returns a string describing the last error caused by an LLVMRust* call.
1730 pub fn LLVMRustGetLastError() -> *const c_char;
1732 /// Print the pass timings since static dtors aren't picking them up.
1733 pub fn LLVMRustPrintPassTimings();
1735 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1737 pub fn LLVMStructSetBody(StructTy: TypeRef,
1738 ElementTypes: *const TypeRef,
1739 ElementCount: c_uint,
1742 pub fn LLVMConstNamedStruct(S: TypeRef,
1743 ConstantVals: *const ValueRef,
1747 /// Enables LLVM debug output.
1748 pub fn LLVMSetDebug(Enabled: c_int);
1750 /// Prepares inline assembly.
1751 pub fn LLVMInlineAsm(Ty: TypeRef,
1752 AsmString: *const c_char,
1753 Constraints: *const c_char,
1759 pub fn LLVMRustDebugMetadataVersion() -> u32;
1760 pub fn LLVMVersionMajor() -> u32;
1761 pub fn LLVMVersionMinor() -> u32;
1763 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1764 name: *const c_char,
1767 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1769 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1771 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1773 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1775 File: *const c_char,
1777 Producer: *const c_char,
1779 Flags: *const c_char,
1781 SplitName: *const c_char)
1784 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1785 Filename: *const c_char,
1786 Directory: *const c_char)
1789 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1791 ParameterTypes: DIArray)
1794 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1795 Scope: DIDescriptor,
1796 Name: *const c_char,
1797 LinkageName: *const c_char,
1801 isLocalToUnit: bool,
1811 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1812 Name: *const c_char,
1813 SizeInBits: c_ulonglong,
1814 AlignInBits: c_ulonglong,
1818 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1820 SizeInBits: c_ulonglong,
1821 AlignInBits: c_ulonglong,
1822 Name: *const c_char)
1825 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1826 Scope: DIDescriptor,
1827 Name: *const c_char,
1830 SizeInBits: c_ulonglong,
1831 AlignInBits: c_ulonglong,
1833 DerivedFrom: DIType,
1835 RunTimeLang: c_uint,
1836 VTableHolder: DIType,
1837 UniqueId: *const c_char)
1840 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1841 Scope: DIDescriptor,
1842 Name: *const c_char,
1845 SizeInBits: c_ulonglong,
1846 AlignInBits: c_ulonglong,
1847 OffsetInBits: c_ulonglong,
1852 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1859 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1861 Name: *const c_char,
1862 LinkageName: *const c_char,
1866 isLocalToUnit: bool,
1869 -> DIGlobalVariable;
1871 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1873 Scope: DIDescriptor,
1874 Name: *const c_char,
1878 AlwaysPreserve: bool,
1880 AddrOps: *const i64,
1881 AddrOpsCount: c_uint,
1885 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1887 AlignInBits: c_ulonglong,
1889 Subscripts: DIArray)
1892 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1894 AlignInBits: c_ulonglong,
1896 Subscripts: DIArray)
1899 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1904 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1905 Ptr: *const DIDescriptor,
1909 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1911 VarInfo: DIVariable,
1912 AddrOps: *const i64,
1913 AddrOpsCount: c_uint,
1915 InsertAtEnd: BasicBlockRef)
1918 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1920 VarInfo: DIVariable,
1921 AddrOps: *const i64,
1922 AddrOpsCount: c_uint,
1924 InsertBefore: ValueRef)
1927 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1928 Name: *const c_char,
1932 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1934 Name: *const c_char,
1937 SizeInBits: c_ulonglong,
1938 AlignInBits: c_ulonglong,
1943 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1945 Name: *const c_char,
1948 SizeInBits: c_ulonglong,
1949 AlignInBits: c_ulonglong,
1952 RunTimeLang: c_uint,
1953 UniqueId: *const c_char)
1956 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1958 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1960 Name: *const c_char,
1965 -> DITemplateTypeParameter;
1967 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1969 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1971 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1973 Name: *const c_char,
1978 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
1982 InlinedAt: MetadataRef)
1985 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
1986 CompositeType: DIType,
1987 TypeArray: DIArray);
1988 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
1989 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
1991 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1993 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1994 pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
1996 pub fn LLVMInitializeX86TargetInfo();
1997 pub fn LLVMInitializeX86Target();
1998 pub fn LLVMInitializeX86TargetMC();
1999 pub fn LLVMInitializeX86AsmPrinter();
2000 pub fn LLVMInitializeX86AsmParser();
2001 pub fn LLVMInitializeARMTargetInfo();
2002 pub fn LLVMInitializeARMTarget();
2003 pub fn LLVMInitializeARMTargetMC();
2004 pub fn LLVMInitializeARMAsmPrinter();
2005 pub fn LLVMInitializeARMAsmParser();
2006 pub fn LLVMInitializeAArch64TargetInfo();
2007 pub fn LLVMInitializeAArch64Target();
2008 pub fn LLVMInitializeAArch64TargetMC();
2009 pub fn LLVMInitializeAArch64AsmPrinter();
2010 pub fn LLVMInitializeAArch64AsmParser();
2011 pub fn LLVMInitializeMipsTargetInfo();
2012 pub fn LLVMInitializeMipsTarget();
2013 pub fn LLVMInitializeMipsTargetMC();
2014 pub fn LLVMInitializeMipsAsmPrinter();
2015 pub fn LLVMInitializeMipsAsmParser();
2016 pub fn LLVMInitializePowerPCTargetInfo();
2017 pub fn LLVMInitializePowerPCTarget();
2018 pub fn LLVMInitializePowerPCTargetMC();
2019 pub fn LLVMInitializePowerPCAsmPrinter();
2020 pub fn LLVMInitializePowerPCAsmParser();
2022 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
2023 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2025 Features: *const c_char,
2026 Model: CodeGenModel,
2028 Level: CodeGenOptLevel,
2031 PositionIndependentExecutable: bool,
2032 FunctionSections: bool,
2033 DataSections: bool) -> TargetMachineRef;
2034 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2035 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2038 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2040 DisableSimplifyLibCalls: bool);
2041 pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
2042 OptLevel: CodeGenOptLevel,
2043 MergeFunctions: bool,
2045 LoopVectorize: bool);
2046 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2047 DisableSimplifyLibCalls: bool);
2048 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2049 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2052 Output: *const c_char,
2053 FileType: FileType) -> bool;
2054 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2056 Output: *const c_char);
2057 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2058 pub fn LLVMRustPrintPasses();
2059 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2060 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2061 AddLifetimes: bool);
2062 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2064 len: size_t) -> bool;
2065 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2066 syms: *const *const c_char,
2068 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2070 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2071 pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2072 pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef);
2073 pub fn LLVMRustArchiveIteratorCurrent(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2074 pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
2075 size: *mut size_t) -> *const c_char;
2076 pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
2077 size: *mut size_t) -> *const c_char;
2078 pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2079 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2081 pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
2082 C: DLLStorageClassTypes);
2084 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2085 data: *mut *const c_char) -> c_int;
2087 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2089 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2090 Handler: DiagnosticHandler,
2091 DiagnosticContext: *mut c_void);
2093 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2094 pass_name_out: *mut *const c_char,
2095 function_out: *mut ValueRef,
2096 debugloc_out: *mut DebugLocRef,
2097 message_out: *mut TwineRef);
2098 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2099 cookie_out: *mut c_uint,
2100 message_out: *mut TwineRef,
2101 instruction_out: *mut ValueRef);
2103 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2104 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2105 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2107 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2109 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2110 H: InlineAsmDiagHandler,
2113 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2116 // LLVM requires symbols from this library, but apparently they're not printed
2117 // during llvm-config?
2119 #[link(name = "ole32")]
2122 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2124 LLVMSetInstructionCallConv(instr, cc as c_uint);
2127 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2129 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2132 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2134 LLVMSetLinkage(global, link as c_uint);
2138 pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
2140 LLVMRustSetDLLStorageClass(global, class);
2144 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2146 LLVMSetUnnamedAddr(global, unnamed as Bool);
2150 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2152 LLVMSetThreadLocal(global, is_thread_local as Bool);
2156 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2158 LLVMConstICmp(pred as c_ushort, v1, v2)
2161 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2163 LLVMConstFCmp(pred as c_ushort, v1, v2)
2167 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2169 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr.bits() as uint64_t)
2173 /* Memory-managed interface to target data. */
2175 pub struct TargetData {
2176 pub lltd: TargetDataRef
2179 impl Drop for TargetData {
2180 fn drop(&mut self) {
2182 LLVMDisposeTargetData(self.lltd);
2187 pub fn mk_target_data(string_rep: &str) -> TargetData {
2188 let string_rep = CString::new(string_rep).unwrap();
2190 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2194 /* Memory-managed interface to object files. */
2196 pub struct ObjectFile {
2197 pub llof: ObjectFileRef,
2201 // This will take ownership of llmb
2202 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2204 let llof = LLVMCreateObjectFile(llmb);
2205 if llof as isize == 0 {
2206 // LLVMCreateObjectFile took ownership of llmb
2217 impl Drop for ObjectFile {
2218 fn drop(&mut self) {
2220 LLVMDisposeObjectFile(self.llof);
2225 /* Memory-managed interface to section iterators. */
2227 pub struct SectionIter {
2228 pub llsi: SectionIteratorRef
2231 impl Drop for SectionIter {
2232 fn drop(&mut self) {
2234 LLVMDisposeSectionIterator(self.llsi);
2239 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2242 llsi: LLVMGetSections(llof)
2247 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2248 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2250 assert!(index < LLVMCountParams(llfn));
2251 LLVMGetParam(llfn, index)
2255 pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
2257 let num_params = LLVMCountParams(llfn);
2258 let mut params = Vec::with_capacity(num_params as usize);
2259 for idx in 0..num_params {
2260 params.push(LLVMGetParam(llfn, idx));
2267 #[allow(missing_copy_implementations)]
2268 pub enum RustString_opaque {}
2269 pub type RustStringRef = *mut RustString_opaque;
2270 type RustStringRepr = *mut RefCell<Vec<u8>>;
2272 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2274 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2277 let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2279 let sr: RustStringRepr = mem::transmute(sr);
2280 (*sr).borrow_mut().push_all(slice);
2283 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2284 let mut buf = RefCell::new(Vec::new());
2285 f(&mut buf as RustStringRepr as RustStringRef);
2286 String::from_utf8(buf.into_inner()).ok()
2289 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2290 build_string(|s| LLVMWriteTwineToString(tr, s))
2291 .expect("got a non-UTF8 Twine from LLVM")
2294 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2295 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2296 .expect("got a non-UTF8 DebugLoc from LLVM")
2299 // The module containing the native LLVM dependencies, generated by the build system
2300 // Note that this must come after the rustllvm extern declaration so that
2301 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2302 // Works to the above fix for #15460 to ensure LLVM dependencies that
2303 // are only used by rustllvm don't get stripped by the linker.
2305 include! { env!("CFG_LLVM_LINKAGE_FILE") }