1 // Copyright 2012 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.
12 use std::hashmap::HashMap;
13 use std::libc::{c_uint, c_ushort};
17 use middle::trans::type_::Type;
19 pub type Opcode = u32;
20 pub type Bool = c_uint;
22 pub static True: Bool = 1 as Bool;
23 pub static False: Bool = 0 as Bool;
25 // Consts for the LLVM CallConv type, pre-cast to uint.
31 X86StdcallCallConv = 64,
32 X86FastcallCallConv = 65,
36 LLVMDefaultVisibility = 0,
38 ProtectedVisibility = 2,
43 AvailableExternallyLinkage = 1,
44 LinkOnceAnyLinkage = 2,
45 LinkOnceODRLinkage = 3,
46 LinkOnceODRAutoHideLinkage = 4,
52 DLLImportLinkage = 10,
53 DLLExportLinkage = 11,
54 ExternalWeakLinkage = 12,
57 LinkerPrivateLinkage = 15,
58 LinkerPrivateWeakLinkage = 16,
65 NoReturnAttribute = 4,
67 StructRetAttribute = 16,
68 NoUnwindAttribute = 32,
69 NoAliasAttribute = 64,
72 ReadNoneAttribute = 512,
73 ReadOnlyAttribute = 1024,
74 NoInlineAttribute = 2048,
75 AlwaysInlineAttribute = 4096,
76 OptimizeForSizeAttribute = 8192,
77 StackProtectAttribute = 16384,
78 StackProtectReqAttribute = 32768,
80 AlignmentAttribute = 2031616,
81 NoCaptureAttribute = 2097152,
82 NoRedZoneAttribute = 4194304,
83 NoImplicitFloatAttribute = 8388608,
84 NakedAttribute = 16777216,
85 InlineHintAttribute = 33554432,
87 StackAttribute = 469762048,
88 ReturnsTwiceAttribute = 536870912,
90 UWTableAttribute = 1073741824,
91 NonLazyBindAttribute = 2147483648,
94 // enum for the LLVM IntPredicate type
95 pub enum IntPredicate {
108 // enum for the LLVM RealPredicate type
109 pub enum RealPredicate {
110 RealPredicateFalse = 0,
125 RealPredicateTrue = 15,
128 // The LLVM TypeKind type - must stay in sync with the def of
129 // LLVMTypeKind in llvm/include/llvm-c/Core.h
130 pub type TypeKind = u32;
131 pub static Void: TypeKind = 0;
132 pub static Half: TypeKind = 1;
133 pub static Float: TypeKind = 2;
134 pub static Double: TypeKind = 3;
135 pub static X86_FP80: TypeKind = 4;
136 pub static FP128: TypeKind = 5;
137 pub static PPC_FP128: TypeKind = 6;
138 pub static Label: TypeKind = 7;
139 pub static Integer: TypeKind = 8;
140 pub static Function: TypeKind = 9;
141 pub static Struct: TypeKind = 10;
142 pub static Array: TypeKind = 11;
143 pub static Pointer: TypeKind = 12;
144 pub static Vector: TypeKind = 13;
145 pub static Metadata: TypeKind = 14;
146 pub static X86_MMX: TypeKind = 15;
148 pub enum AtomicBinOp {
162 pub enum AtomicOrdering {
166 // Consume = 3, // Not specified yet.
170 SequentiallyConsistent = 7
173 // FIXME: Not used right now, but will be once #2334 is fixed
174 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
189 // Inline Asm Dialect
190 pub enum AsmDialect {
195 // Opaque pointer types
196 pub enum Module_opaque {}
197 pub type ModuleRef = *Module_opaque;
198 pub enum Context_opaque {}
199 pub type ContextRef = *Context_opaque;
200 pub enum Type_opaque {}
201 pub type TypeRef = *Type_opaque;
202 pub enum Value_opaque {}
203 pub type ValueRef = *Value_opaque;
204 pub enum BasicBlock_opaque {}
205 pub type BasicBlockRef = *BasicBlock_opaque;
206 pub enum Builder_opaque {}
207 pub type BuilderRef = *Builder_opaque;
208 pub enum ExecutionEngine_opaque {}
209 pub type ExecutionEngineRef = *ExecutionEngine_opaque;
210 pub enum MemoryBuffer_opaque {}
211 pub type MemoryBufferRef = *MemoryBuffer_opaque;
212 pub enum PassManager_opaque {}
213 pub type PassManagerRef = *PassManager_opaque;
214 pub enum PassManagerBuilder_opaque {}
215 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
216 pub enum Use_opaque {}
217 pub type UseRef = *Use_opaque;
218 pub enum TargetData_opaque {}
219 pub type TargetDataRef = *TargetData_opaque;
220 pub enum ObjectFile_opaque {}
221 pub type ObjectFileRef = *ObjectFile_opaque;
222 pub enum SectionIterator_opaque {}
223 pub type SectionIteratorRef = *SectionIterator_opaque;
224 pub enum Pass_opaque {}
225 pub type PassRef = *Pass_opaque;
228 use super::{ValueRef};
230 pub enum DIBuilder_opaque {}
231 pub type DIBuilderRef = *DIBuilder_opaque;
233 pub type DIDescriptor = ValueRef;
234 pub type DIScope = DIDescriptor;
235 pub type DILocation = DIDescriptor;
236 pub type DIFile = DIScope;
237 pub type DILexicalBlock = DIScope;
238 pub type DISubprogram = DIScope;
239 pub type DIType = DIDescriptor;
240 pub type DIBasicType = DIType;
241 pub type DIDerivedType = DIType;
242 pub type DICompositeType = DIDerivedType;
243 pub type DIVariable = DIDescriptor;
244 pub type DIArray = DIDescriptor;
245 pub type DISubrange = DIDescriptor;
247 pub enum DIDescriptorFlags {
248 FlagPrivate = 1 << 0,
249 FlagProtected = 1 << 1,
250 FlagFwdDecl = 1 << 2,
251 FlagAppleBlock = 1 << 3,
252 FlagBlockByrefStruct = 1 << 4,
253 FlagVirtual = 1 << 5,
254 FlagArtificial = 1 << 6,
255 FlagExplicit = 1 << 7,
256 FlagPrototyped = 1 << 8,
257 FlagObjcClassComplete = 1 << 9,
258 FlagObjectPointer = 1 << 10,
259 FlagVector = 1 << 11,
260 FlagStaticMember = 1 << 12
265 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
266 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
267 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
268 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
269 use super::{ValueRef, PassRef};
270 use super::debuginfo::*;
271 use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};
273 #[link_args = "-Lrustllvm -lrustllvm"]
274 #[link_name = "rustllvm"]
277 /* Create and destroy contexts. */
279 pub unsafe fn LLVMContextCreate() -> ContextRef;
281 pub unsafe fn LLVMContextDispose(C: ContextRef);
283 pub unsafe fn LLVMGetMDKindIDInContext(C: ContextRef,
288 /* Create and destroy modules. */
290 pub unsafe fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
294 pub unsafe fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
296 pub unsafe fn LLVMDisposeModule(M: ModuleRef);
298 /** Data layout. See Module::getDataLayout. */
300 pub unsafe fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
302 pub unsafe fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
304 /** Target triple. See Module::getTargetTriple. */
306 pub unsafe fn LLVMGetTarget(M: ModuleRef) -> *c_char;
308 pub unsafe fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
310 /** See Module::dump. */
312 pub unsafe fn LLVMDumpModule(M: ModuleRef);
314 /** See Module::setModuleInlineAsm. */
316 pub unsafe fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
318 /** See llvm::LLVMTypeKind::getTypeID. */
319 pub unsafe fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
321 /** See llvm::LLVMType::getContext. */
323 pub unsafe fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
325 /* Operations on integer types */
327 pub unsafe fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
329 pub unsafe fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
331 pub unsafe fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
333 pub unsafe fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
335 pub unsafe fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
337 pub unsafe fn LLVMIntTypeInContext(C: ContextRef,
338 NumBits: c_uint) -> TypeRef;
341 pub unsafe fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
343 /* Operations on real types */
345 pub unsafe fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
347 pub unsafe fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
349 pub unsafe fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
351 pub unsafe fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
353 pub unsafe fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
355 /* Operations on function types */
357 pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
358 ParamTypes: *TypeRef,
363 pub unsafe fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
365 pub unsafe fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
367 pub unsafe fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
369 pub unsafe fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
371 /* Operations on struct types */
373 pub unsafe fn LLVMStructTypeInContext(C: ContextRef,
374 ElementTypes: *TypeRef,
375 ElementCount: c_uint,
376 Packed: Bool) -> TypeRef;
378 pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
381 pub unsafe fn LLVMGetStructElementTypes(StructTy: TypeRef,
384 pub unsafe fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
386 /* Operations on array, pointer, and vector types (sequence types) */
388 pub unsafe fn LLVMArrayType(ElementType: TypeRef,
389 ElementCount: c_uint) -> TypeRef;
391 pub unsafe fn LLVMPointerType(ElementType: TypeRef,
392 AddressSpace: c_uint) -> TypeRef;
394 pub unsafe fn LLVMVectorType(ElementType: TypeRef,
395 ElementCount: c_uint) -> TypeRef;
398 pub unsafe fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
400 pub unsafe fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
402 pub unsafe fn LLVMGetPointerAddressSpace(PointerTy: TypeRef)
405 pub unsafe fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef,
409 pub unsafe fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
411 /* Operations on other types */
413 pub unsafe fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
415 pub unsafe fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
417 pub unsafe fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
419 /* Operations on all values */
421 pub unsafe fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
423 pub unsafe fn LLVMGetValueName(Val: ValueRef) -> *c_char;
425 pub unsafe fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
427 pub unsafe fn LLVMDumpValue(Val: ValueRef);
429 pub unsafe fn LLVMReplaceAllUsesWith(OldVal: ValueRef,
432 pub unsafe fn LLVMHasMetadata(Val: ValueRef) -> c_int;
434 pub unsafe fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint)
437 pub unsafe fn LLVMSetMetadata(Val: ValueRef,
441 /* Operations on Uses */
443 pub unsafe fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
445 pub unsafe fn LLVMGetNextUse(U: UseRef) -> UseRef;
447 pub unsafe fn LLVMGetUser(U: UseRef) -> ValueRef;
449 pub unsafe fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
451 /* Operations on Users */
453 pub unsafe fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
455 pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint)
458 pub unsafe fn LLVMSetOperand(Val: ValueRef,
462 /* Operations on constants of any type */
464 pub unsafe fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
467 pub unsafe fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
469 pub unsafe fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) -> ValueRef;
471 pub unsafe fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) -> ValueRef;
472 /* only for int/vector */
474 pub unsafe fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
476 pub unsafe fn LLVMIsConstant(Val: ValueRef) -> Bool;
478 pub unsafe fn LLVMIsNull(Val: ValueRef) -> Bool;
480 pub unsafe fn LLVMIsUndef(Val: ValueRef) -> Bool;
482 pub unsafe fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
484 /* Operations on metadata */
486 pub unsafe fn LLVMMDStringInContext(C: ContextRef,
491 pub unsafe fn LLVMMDNodeInContext(C: ContextRef,
496 pub unsafe fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
499 /* Operations on scalar constants */
501 pub unsafe fn LLVMConstInt(IntTy: TypeRef,
506 pub unsafe fn LLVMConstIntOfString(IntTy: TypeRef,
511 pub unsafe fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
517 pub unsafe fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
519 pub unsafe fn LLVMConstRealOfString(RealTy: TypeRef,
523 pub unsafe fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
528 pub unsafe fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef)
531 pub unsafe fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef)
535 /* Operations on composite constants */
537 pub unsafe fn LLVMConstStringInContext(C: ContextRef,
540 DontNullTerminate: Bool)
543 pub unsafe fn LLVMConstStructInContext(C: ContextRef,
544 ConstantVals: *ValueRef,
546 Packed: Bool) -> ValueRef;
549 pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
550 ConstantVals: *ValueRef,
554 pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
555 Size: c_uint) -> ValueRef;
557 /* Constant expressions */
559 pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
561 pub unsafe fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
563 pub unsafe fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
565 pub unsafe fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
567 pub unsafe fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
569 pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
571 pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
573 pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
574 RHSConstant: ValueRef)
577 pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
578 RHSConstant: ValueRef)
581 pub unsafe fn LLVMConstNUWAdd(LHSConstant: ValueRef,
582 RHSConstant: ValueRef)
585 pub unsafe fn LLVMConstFAdd(LHSConstant: ValueRef,
586 RHSConstant: ValueRef)
589 pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
590 RHSConstant: ValueRef)
593 pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
594 RHSConstant: ValueRef)
597 pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
598 RHSConstant: ValueRef)
601 pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
602 RHSConstant: ValueRef)
605 pub unsafe fn LLVMConstMul(LHSConstant: ValueRef,
606 RHSConstant: ValueRef)
609 pub unsafe fn LLVMConstNSWMul(LHSConstant: ValueRef,
610 RHSConstant: ValueRef)
613 pub unsafe fn LLVMConstNUWMul(LHSConstant: ValueRef,
614 RHSConstant: ValueRef)
617 pub unsafe fn LLVMConstFMul(LHSConstant: ValueRef,
618 RHSConstant: ValueRef)
621 pub unsafe fn LLVMConstUDiv(LHSConstant: ValueRef,
622 RHSConstant: ValueRef)
625 pub unsafe fn LLVMConstSDiv(LHSConstant: ValueRef,
626 RHSConstant: ValueRef)
629 pub unsafe fn LLVMConstExactSDiv(LHSConstant: ValueRef,
630 RHSConstant: ValueRef)
633 pub unsafe fn LLVMConstFDiv(LHSConstant: ValueRef,
634 RHSConstant: ValueRef)
637 pub unsafe fn LLVMConstURem(LHSConstant: ValueRef,
638 RHSConstant: ValueRef)
641 pub unsafe fn LLVMConstSRem(LHSConstant: ValueRef,
642 RHSConstant: ValueRef)
645 pub unsafe fn LLVMConstFRem(LHSConstant: ValueRef,
646 RHSConstant: ValueRef)
649 pub unsafe fn LLVMConstAnd(LHSConstant: ValueRef,
650 RHSConstant: ValueRef)
653 pub unsafe fn LLVMConstOr(LHSConstant: ValueRef,
654 RHSConstant: ValueRef)
657 pub unsafe fn LLVMConstXor(LHSConstant: ValueRef,
658 RHSConstant: ValueRef)
661 pub unsafe fn LLVMConstShl(LHSConstant: ValueRef,
662 RHSConstant: ValueRef)
665 pub unsafe fn LLVMConstLShr(LHSConstant: ValueRef,
666 RHSConstant: ValueRef) -> ValueRef;
668 pub unsafe fn LLVMConstAShr(LHSConstant: ValueRef,
669 RHSConstant: ValueRef) -> ValueRef;
671 pub unsafe fn LLVMConstGEP(ConstantVal: ValueRef,
672 ConstantIndices: *ValueRef,
673 NumIndices: c_uint) -> ValueRef;
675 pub unsafe fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
676 ConstantIndices: *ValueRef,
680 pub unsafe fn LLVMConstTrunc(ConstantVal: ValueRef,
684 pub unsafe fn LLVMConstSExt(ConstantVal: ValueRef,
688 pub unsafe fn LLVMConstZExt(ConstantVal: ValueRef,
692 pub unsafe fn LLVMConstFPTrunc(ConstantVal: ValueRef,
696 pub unsafe fn LLVMConstFPExt(ConstantVal: ValueRef,
700 pub unsafe fn LLVMConstUIToFP(ConstantVal: ValueRef,
704 pub unsafe fn LLVMConstSIToFP(ConstantVal: ValueRef,
708 pub unsafe fn LLVMConstFPToUI(ConstantVal: ValueRef,
712 pub unsafe fn LLVMConstFPToSI(ConstantVal: ValueRef,
716 pub unsafe fn LLVMConstPtrToInt(ConstantVal: ValueRef,
720 pub unsafe fn LLVMConstIntToPtr(ConstantVal: ValueRef,
724 pub unsafe fn LLVMConstBitCast(ConstantVal: ValueRef,
728 pub unsafe fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef,
732 pub unsafe fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef,
736 pub unsafe fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef,
740 pub unsafe fn LLVMConstPointerCast(ConstantVal: ValueRef,
744 pub unsafe fn LLVMConstIntCast(ConstantVal: ValueRef,
749 pub unsafe fn LLVMConstFPCast(ConstantVal: ValueRef,
753 pub unsafe fn LLVMConstSelect(ConstantCondition: ValueRef,
754 ConstantIfTrue: ValueRef,
755 ConstantIfFalse: ValueRef)
758 pub unsafe fn LLVMConstExtractElement(VectorConstant: ValueRef,
759 IndexConstant: ValueRef) -> ValueRef;
761 pub unsafe fn LLVMConstInsertElement(VectorConstant: ValueRef,
762 ElementValueConstant: ValueRef,
763 IndexConstant: ValueRef) -> ValueRef;
765 pub unsafe fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
766 VectorBConstant: ValueRef,
767 MaskConstant: ValueRef) -> ValueRef;
769 pub unsafe fn LLVMConstExtractValue(AggConstant: ValueRef,
771 NumIdx: c_uint) -> ValueRef;
773 pub unsafe fn LLVMConstInsertValue(AggConstant: ValueRef,
774 ElementValueConstant: ValueRef,
779 pub unsafe fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
780 Constraints: *c_char, HasSideEffects: Bool,
781 IsAlignStack: Bool) -> ValueRef;
783 pub unsafe fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef)
788 /* Operations on global variables, functions, and aliases (globals) */
790 pub unsafe fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
792 pub unsafe fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
794 pub unsafe fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
796 pub unsafe fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
798 pub unsafe fn LLVMGetSection(Global: ValueRef) -> *c_char;
800 pub unsafe fn LLVMSetSection(Global: ValueRef, Section: *c_char);
802 pub unsafe fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
804 pub unsafe fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
806 pub unsafe fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
808 pub unsafe fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
811 /* Operations on global variables */
813 pub unsafe fn LLVMAddGlobal(M: ModuleRef,
818 pub unsafe fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
821 AddressSpace: c_uint)
824 pub unsafe fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char)
827 pub unsafe fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
829 pub unsafe fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
831 pub unsafe fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
833 pub unsafe fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
835 pub unsafe fn LLVMDeleteGlobal(GlobalVar: ValueRef);
837 pub unsafe fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
839 pub unsafe fn LLVMSetInitializer(GlobalVar: ValueRef,
840 ConstantVal: ValueRef);
842 pub unsafe fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
844 pub unsafe fn LLVMSetThreadLocal(GlobalVar: ValueRef,
845 IsThreadLocal: Bool);
847 pub unsafe fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
849 pub unsafe fn LLVMSetGlobalConstant(GlobalVar: ValueRef,
852 /* Operations on aliases */
854 pub unsafe fn LLVMAddAlias(M: ModuleRef,
860 /* Operations on functions */
862 pub unsafe fn LLVMAddFunction(M: ModuleRef,
867 pub unsafe fn LLVMGetNamedFunction(M: ModuleRef,
868 Name: *c_char) -> ValueRef;
870 pub unsafe fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
872 pub unsafe fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
874 pub unsafe fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
876 pub unsafe fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
878 pub unsafe fn LLVMDeleteFunction(Fn: ValueRef);
880 pub unsafe fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
881 FunctionTy: TypeRef) -> ValueRef;
883 pub unsafe fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
885 pub unsafe fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
887 pub unsafe fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
889 pub unsafe fn LLVMGetGC(Fn: ValueRef) -> *c_char;
891 pub unsafe fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
893 pub unsafe fn LLVMAddFunctionAttr(Fn: ValueRef,
897 pub unsafe fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
899 pub unsafe fn LLVMRemoveFunctionAttr(Fn: ValueRef,
901 HighPA: c_ulonglong);
903 /* Operations on parameters */
905 pub unsafe fn LLVMCountParams(Fn: ValueRef) -> c_uint;
907 pub unsafe fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
909 pub unsafe fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
911 pub unsafe fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
913 pub unsafe fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
915 pub unsafe fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
917 pub unsafe fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
919 pub unsafe fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
921 pub unsafe fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
923 pub unsafe fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
925 pub unsafe fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
927 pub unsafe fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
929 /* Operations on basic blocks */
931 pub unsafe fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
933 pub unsafe fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
935 pub unsafe fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
937 pub unsafe fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
939 pub unsafe fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
941 pub unsafe fn LLVMGetBasicBlocks(Fn: ValueRef,
942 BasicBlocks: *ValueRef);
944 pub unsafe fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
946 pub unsafe fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
948 pub unsafe fn LLVMGetNextBasicBlock(BB: BasicBlockRef)
951 pub unsafe fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef)
954 pub unsafe fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
957 pub unsafe fn LLVMAppendBasicBlockInContext(C: ContextRef,
962 pub unsafe fn LLVMInsertBasicBlockInContext(C: ContextRef,
967 pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
970 pub unsafe fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef, MoveAfter: BasicBlockRef);
973 pub unsafe fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef, MoveBefore: BasicBlockRef);
975 /* Operations on instructions */
977 pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef)
980 pub unsafe fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
982 pub unsafe fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
984 pub unsafe fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
986 pub unsafe fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
988 pub unsafe fn LLVMInstructionEraseFromParent(Inst: ValueRef);
990 /* Operations on call sites */
992 pub unsafe fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
994 pub unsafe fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
996 pub unsafe fn LLVMAddInstrAttribute(Instr: ValueRef,
1000 pub unsafe fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1004 pub unsafe fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1008 /* Operations on call instructions (only) */
1010 pub unsafe fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1012 pub unsafe fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1014 /* Operations on phi nodes */
1016 pub unsafe fn LLVMAddIncoming(PhiNode: ValueRef,
1017 IncomingValues: *ValueRef,
1018 IncomingBlocks: *BasicBlockRef,
1021 pub unsafe fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1023 pub unsafe fn LLVMGetIncomingValue(PhiNode: ValueRef,
1027 pub unsafe fn LLVMGetIncomingBlock(PhiNode: ValueRef,
1028 Index: c_uint) -> BasicBlockRef;
1030 /* Instruction builders */
1032 pub unsafe fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1034 pub unsafe fn LLVMPositionBuilder(Builder: BuilderRef,
1035 Block: BasicBlockRef,
1038 pub unsafe fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1041 pub unsafe fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1042 Block: BasicBlockRef);
1044 pub unsafe fn LLVMGetInsertBlock(Builder: BuilderRef)
1047 pub unsafe fn LLVMClearInsertionPosition(Builder: BuilderRef);
1049 pub unsafe fn LLVMInsertIntoBuilder(Builder: BuilderRef,
1052 pub unsafe fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1056 pub unsafe fn LLVMDisposeBuilder(Builder: BuilderRef);
1058 pub unsafe fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1062 pub unsafe fn LLVMSetCurrentDebugLocation(Builder: BuilderRef,
1065 pub unsafe fn LLVMGetCurrentDebugLocation(Builder: BuilderRef)
1068 pub unsafe fn LLVMSetInstDebugLocation(Builder: BuilderRef,
1073 pub unsafe fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1075 pub unsafe fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1077 pub unsafe fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
1078 N: c_uint) -> ValueRef;
1080 pub unsafe fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef)
1083 pub unsafe fn LLVMBuildCondBr(B: BuilderRef,
1085 Then: BasicBlockRef,
1086 Else: BasicBlockRef)
1089 pub unsafe fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef,
1090 Else: BasicBlockRef, NumCases: c_uint)
1093 pub unsafe fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef,
1094 NumDests: c_uint) -> ValueRef;
1096 pub unsafe fn LLVMBuildInvoke(B: BuilderRef,
1100 Then: BasicBlockRef,
1101 Catch: BasicBlockRef,
1102 Name: *c_char) -> ValueRef;
1104 pub unsafe fn LLVMBuildLandingPad(B: BuilderRef,
1111 pub unsafe fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef)
1114 pub unsafe fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1116 /* Add a case to the switch instruction */
1118 pub unsafe fn LLVMAddCase(Switch: ValueRef,
1120 Dest: BasicBlockRef);
1122 /* Add a destination to the indirectbr instruction */
1124 pub unsafe fn LLVMAddDestination(IndirectBr: ValueRef,
1125 Dest: BasicBlockRef);
1127 /* Add a clause to the landing pad instruction */
1129 pub unsafe fn LLVMAddClause(LandingPad: ValueRef,
1130 ClauseVal: ValueRef);
1132 /* Set the cleanup on a landing pad instruction */
1134 pub unsafe fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1138 pub unsafe fn LLVMBuildAdd(B: BuilderRef,
1144 pub unsafe fn LLVMBuildNSWAdd(B: BuilderRef,
1150 pub unsafe fn LLVMBuildNUWAdd(B: BuilderRef,
1156 pub unsafe fn LLVMBuildFAdd(B: BuilderRef,
1162 pub unsafe fn LLVMBuildSub(B: BuilderRef,
1168 pub unsafe fn LLVMBuildNSWSub(B: BuilderRef,
1174 pub unsafe fn LLVMBuildNUWSub(B: BuilderRef,
1180 pub unsafe fn LLVMBuildFSub(B: BuilderRef,
1186 pub unsafe fn LLVMBuildMul(B: BuilderRef,
1192 pub unsafe fn LLVMBuildNSWMul(B: BuilderRef,
1198 pub unsafe fn LLVMBuildNUWMul(B: BuilderRef,
1204 pub unsafe fn LLVMBuildFMul(B: BuilderRef,
1210 pub unsafe fn LLVMBuildUDiv(B: BuilderRef,
1216 pub unsafe fn LLVMBuildSDiv(B: BuilderRef,
1222 pub unsafe fn LLVMBuildExactSDiv(B: BuilderRef,
1228 pub unsafe fn LLVMBuildFDiv(B: BuilderRef,
1234 pub unsafe fn LLVMBuildURem(B: BuilderRef,
1240 pub unsafe fn LLVMBuildSRem(B: BuilderRef,
1246 pub unsafe fn LLVMBuildFRem(B: BuilderRef,
1252 pub unsafe fn LLVMBuildShl(B: BuilderRef,
1258 pub unsafe fn LLVMBuildLShr(B: BuilderRef,
1264 pub unsafe fn LLVMBuildAShr(B: BuilderRef,
1270 pub unsafe fn LLVMBuildAnd(B: BuilderRef,
1276 pub unsafe fn LLVMBuildOr(B: BuilderRef,
1282 pub unsafe fn LLVMBuildXor(B: BuilderRef,
1288 pub unsafe fn LLVMBuildBinOp(B: BuilderRef,
1295 pub unsafe fn LLVMBuildNeg(B: BuilderRef,
1300 pub unsafe fn LLVMBuildNSWNeg(B: BuilderRef,
1305 pub unsafe fn LLVMBuildNUWNeg(B: BuilderRef,
1310 pub unsafe fn LLVMBuildFNeg(B: BuilderRef,
1315 pub unsafe fn LLVMBuildNot(B: BuilderRef,
1322 pub unsafe fn LLVMBuildMalloc(B: BuilderRef,
1327 pub unsafe fn LLVMBuildArrayMalloc(B: BuilderRef,
1330 Name: *c_char) -> ValueRef;
1332 pub unsafe fn LLVMBuildAlloca(B: BuilderRef,
1337 pub unsafe fn LLVMBuildArrayAlloca(B: BuilderRef,
1340 Name: *c_char) -> ValueRef;
1342 pub unsafe fn LLVMBuildFree(B: BuilderRef,
1343 PointerVal: ValueRef) -> ValueRef;
1345 pub unsafe fn LLVMBuildLoad(B: BuilderRef,
1346 PointerVal: ValueRef,
1351 pub unsafe fn LLVMBuildStore(B: BuilderRef,
1357 pub unsafe fn LLVMBuildGEP(B: BuilderRef,
1364 pub unsafe fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
1365 Indices: *ValueRef, NumIndices: c_uint,
1369 pub unsafe fn LLVMBuildStructGEP(B: BuilderRef,
1375 pub unsafe fn LLVMBuildGlobalString(B: BuilderRef,
1380 pub unsafe fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1387 pub unsafe fn LLVMBuildTrunc(B: BuilderRef,
1390 Name: *c_char) -> ValueRef;
1392 pub unsafe fn LLVMBuildZExt(B: BuilderRef,
1398 pub unsafe fn LLVMBuildSExt(B: BuilderRef,
1404 pub unsafe fn LLVMBuildFPToUI(B: BuilderRef,
1407 Name: *c_char) -> ValueRef;
1409 pub unsafe fn LLVMBuildFPToSI(B: BuilderRef,
1412 Name: *c_char) -> ValueRef;
1414 pub unsafe fn LLVMBuildUIToFP(B: BuilderRef,
1417 Name: *c_char) -> ValueRef;
1419 pub unsafe fn LLVMBuildSIToFP(B: BuilderRef,
1422 Name: *c_char) -> ValueRef;
1424 pub unsafe fn LLVMBuildFPTrunc(B: BuilderRef,
1427 Name: *c_char) -> ValueRef;
1429 pub unsafe fn LLVMBuildFPExt(B: BuilderRef,
1432 Name: *c_char) -> ValueRef;
1434 pub unsafe fn LLVMBuildPtrToInt(B: BuilderRef,
1437 Name: *c_char) -> ValueRef;
1439 pub unsafe fn LLVMBuildIntToPtr(B: BuilderRef,
1442 Name: *c_char) -> ValueRef;
1444 pub unsafe fn LLVMBuildBitCast(B: BuilderRef,
1447 Name: *c_char) -> ValueRef;
1449 pub unsafe fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1455 pub unsafe fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1461 pub unsafe fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1467 pub unsafe fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
1468 DestTy: TypeRef, Name: *c_char) -> ValueRef;
1470 pub unsafe fn LLVMBuildPointerCast(B: BuilderRef,
1476 pub unsafe fn LLVMBuildIntCast(B: BuilderRef,
1479 Name: *c_char) -> ValueRef;
1481 pub unsafe fn LLVMBuildFPCast(B: BuilderRef,
1484 Name: *c_char) -> ValueRef;
1488 pub unsafe fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1489 RHS: ValueRef, Name: *c_char) -> ValueRef;
1491 pub unsafe fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1492 RHS: ValueRef, Name: *c_char) -> ValueRef;
1494 /* Miscellaneous instructions */
1496 pub unsafe fn LLVMBuildPhi(B: BuilderRef,
1501 pub unsafe fn LLVMBuildCall(B: BuilderRef,
1508 pub unsafe fn LLVMBuildSelect(B: BuilderRef,
1515 pub unsafe fn LLVMBuildVAArg(B: BuilderRef,
1521 pub unsafe fn LLVMBuildExtractElement(B: BuilderRef,
1527 pub unsafe fn LLVMBuildInsertElement(B: BuilderRef,
1534 pub unsafe fn LLVMBuildShuffleVector(B: BuilderRef,
1541 pub unsafe fn LLVMBuildExtractValue(B: BuilderRef,
1547 pub unsafe fn LLVMBuildInsertValue(B: BuilderRef,
1555 pub unsafe fn LLVMBuildIsNull(B: BuilderRef,
1560 pub unsafe fn LLVMBuildIsNotNull(B: BuilderRef,
1565 pub unsafe fn LLVMBuildPtrDiff(B: BuilderRef,
1568 Name: *c_char) -> ValueRef;
1570 /* Atomic Operations */
1571 pub unsafe fn LLVMBuildAtomicLoad(B: BuilderRef,
1572 PointerVal: ValueRef,
1574 Order: AtomicOrdering,
1578 pub unsafe fn LLVMBuildAtomicStore(B: BuilderRef,
1581 Order: AtomicOrdering,
1585 pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1589 Order: AtomicOrdering)
1591 pub unsafe fn LLVMBuildAtomicRMW(B: BuilderRef,
1595 Order: AtomicOrdering)
1598 /* Selected entries from the downcasts. */
1600 pub unsafe fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1602 /** Writes a module to the specified path. Returns 0 on success. */
1604 pub unsafe fn LLVMWriteBitcodeToFile(M: ModuleRef,
1605 Path: *c_char) -> c_int;
1607 /** Creates target data from a target layout string. */
1609 pub unsafe fn LLVMCreateTargetData(StringRep: *c_char)
1611 /** Adds the target data to the given pass manager. The pass manager
1612 references the target data only weakly. */
1614 pub unsafe fn LLVMAddTargetData(TD: TargetDataRef,
1615 PM: PassManagerRef);
1616 /** Number of bytes clobbered when doing a Store to *T. */
1618 pub unsafe fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1621 /** Number of bytes clobbered when doing a Store to *T. */
1623 pub unsafe fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1626 /** Distance between successive elements in an array of T.
1627 Includes ABI padding. */
1629 pub unsafe fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef)
1632 /** Returns the preferred alignment of a type. */
1634 pub unsafe fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
1635 Ty: TypeRef) -> c_uint;
1636 /** Returns the minimum alignment of a type. */
1638 pub unsafe fn LLVMABIAlignmentOfType(TD: TargetDataRef,
1639 Ty: TypeRef) -> c_uint;
1641 /** Computes the byte offset of the indexed struct element for a target. */
1643 pub unsafe fn LLVMOffsetOfElement(TD: TargetDataRef,
1649 * Returns the minimum alignment of a type when part of a call frame.
1652 pub unsafe fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
1656 /** Disposes target data. */
1658 pub unsafe fn LLVMDisposeTargetData(TD: TargetDataRef);
1660 /** Creates a pass manager. */
1662 pub unsafe fn LLVMCreatePassManager() -> PassManagerRef;
1663 /** Creates a function-by-function pass manager */
1665 pub unsafe fn LLVMCreateFunctionPassManagerForModule(M:ModuleRef) -> PassManagerRef;
1667 /** Disposes a pass manager. */
1669 pub unsafe fn LLVMDisposePassManager(PM: PassManagerRef);
1671 /** Runs a pass manager on a module. */
1673 pub unsafe fn LLVMRunPassManager(PM: PassManagerRef,
1674 M: ModuleRef) -> Bool;
1676 /** Runs the function passes on the provided function. */
1678 pub unsafe fn LLVMRunFunctionPassManager(FPM:PassManagerRef, F:ValueRef) -> Bool;
1680 /** Initializes all the function passes scheduled in the manager */
1682 pub unsafe fn LLVMInitializeFunctionPassManager(FPM:PassManagerRef) -> Bool;
1684 /** Finalizes all the function passes scheduled in the manager */
1686 pub unsafe fn LLVMFinalizeFunctionPassManager(FPM:PassManagerRef) -> Bool;
1689 pub unsafe fn LLVMInitializePasses();
1692 pub unsafe fn LLVMAddPass(PM:PassManagerRef,P:PassRef);
1695 pub unsafe fn LLVMCreatePass(PassName:*c_char) -> PassRef;
1698 pub unsafe fn LLVMDestroyPass(P: PassRef);
1700 /** Adds a verification pass. */
1702 pub unsafe fn LLVMAddVerifierPass(PM: PassManagerRef);
1705 pub unsafe fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1707 pub unsafe fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1709 pub unsafe fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1711 pub unsafe fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1713 pub unsafe fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1715 pub unsafe fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1717 pub unsafe fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1719 pub unsafe fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1721 pub unsafe fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1723 pub unsafe fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1725 pub unsafe fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1727 pub unsafe fn LLVMAddReassociatePass(PM: PassManagerRef);
1729 pub unsafe fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1731 pub unsafe fn LLVMAddLICMPass(PM: PassManagerRef);
1733 pub unsafe fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1735 pub unsafe fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1737 pub unsafe fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1739 pub unsafe fn LLVMAddGVNPass(PM: PassManagerRef);
1741 pub unsafe fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1743 pub unsafe fn LLVMAddSCCPPass(PM: PassManagerRef);
1745 pub unsafe fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1747 pub unsafe fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1749 pub unsafe fn LLVMAddConstantMergePass(PM: PassManagerRef);
1751 pub unsafe fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1753 pub unsafe fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1755 pub unsafe fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1757 pub unsafe fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1759 pub unsafe fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1761 pub unsafe fn LLVMAddCorrelatedValuePropagationPass(PM:
1764 pub unsafe fn LLVMAddPruneEHPass(PM: PassManagerRef);
1766 pub unsafe fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1768 pub unsafe fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1770 pub unsafe fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1772 pub unsafe fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1774 pub unsafe fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1777 pub unsafe fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1779 pub unsafe fn LLVMPassManagerBuilderDispose(PMB:
1780 PassManagerBuilderRef);
1782 pub unsafe fn LLVMPassManagerBuilderSetOptLevel(
1783 PMB: PassManagerBuilderRef, OptimizationLevel: c_uint);
1785 pub unsafe fn LLVMPassManagerBuilderSetSizeLevel(
1786 PMB: PassManagerBuilderRef, Value: Bool);
1788 pub unsafe fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1789 PMB: PassManagerBuilderRef, Value: Bool);
1791 pub unsafe fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1792 PMB: PassManagerBuilderRef, Value: Bool);
1794 pub unsafe fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
1795 (PMB: PassManagerBuilderRef, Value: Bool);
1797 pub unsafe fn LLVMPassManagerBuilderUseInlinerWithThreshold
1798 (PMB: PassManagerBuilderRef, threshold: c_uint);
1800 pub unsafe fn LLVMPassManagerBuilderPopulateModulePassManager
1801 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1804 pub unsafe fn LLVMPassManagerBuilderPopulateFunctionPassManager
1805 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1807 /** Destroys a memory buffer. */
1809 pub unsafe fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1812 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1814 /** Opens an object file. */
1816 pub unsafe fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef)
1818 /** Closes an object file. */
1820 pub unsafe fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1822 /** Enumerates the sections in an object file. */
1824 pub unsafe fn LLVMGetSections(ObjFile: ObjectFileRef)
1825 -> SectionIteratorRef;
1826 /** Destroys a section iterator. */
1828 pub unsafe fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1829 /** Returns true if the section iterator is at the end of the section
1832 pub unsafe fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1833 SI: SectionIteratorRef) -> Bool;
1834 /** Moves the section iterator to point to the next section. */
1836 pub unsafe fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1837 /** Returns the current section name. */
1839 pub unsafe fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1840 /** Returns the current section size. */
1842 pub unsafe fn LLVMGetSectionSize(SI: SectionIteratorRef)
1844 /** Returns the current section contents as a string buffer. */
1846 pub unsafe fn LLVMGetSectionContents(SI: SectionIteratorRef)
1849 /** Reads the given file and returns it as a memory buffer. Use
1850 LLVMDisposeMemoryBuffer() to get rid of it. */
1852 pub unsafe fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1857 pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
1862 // FIXME: When #2334 is fixed,
1863 // change c_uint to FileType
1866 EnableSegmentedStacks: bool)
1869 /** Returns a string describing the last error caused by an LLVMRust*
1872 pub unsafe fn LLVMRustGetLastError() -> *c_char;
1874 /** Prepare the JIT. Returns a memory manager that can load crates. */
1876 pub unsafe fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1878 /** Load a crate into the memory manager. */
1880 pub unsafe fn LLVMRustLoadCrate(MM: *(),
1884 /** Execute the JIT engine. */
1886 pub unsafe fn LLVMRustBuildJIT(MM: *(),
1888 EnableSegmentedStacks: bool) -> ExecutionEngineRef;
1890 /** Parses the bitcode in the given memory buffer. */
1892 pub unsafe fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef)
1895 /** Parses LLVM asm in the given file */
1897 pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char,
1902 pub unsafe fn LLVMRustAddPrintModulePass(PM: PassManagerRef,
1906 /** Turn on LLVM pass-timing. */
1908 pub unsafe fn LLVMRustEnableTimePasses();
1910 /// Print the pass timings since static dtors aren't picking them up.
1912 pub unsafe fn LLVMRustPrintPassTimings();
1915 pub unsafe fn LLVMRustStartMultithreading() -> bool;
1918 pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
1922 pub unsafe fn LLVMStructSetBody(StructTy: TypeRef,
1923 ElementTypes: *TypeRef,
1924 ElementCount: c_uint,
1928 pub unsafe fn LLVMConstNamedStruct(S: TypeRef,
1929 ConstantVals: *ValueRef,
1933 /** Enables LLVM debug output. */
1935 pub unsafe fn LLVMSetDebug(Enabled: c_int);
1937 /** Prepares inline assembly. */
1939 pub unsafe fn LLVMInlineAsm(Ty: TypeRef, AsmString: *c_char,
1940 Constraints: *c_char, SideEffects: Bool,
1941 AlignStack: Bool, Dialect: c_uint)
1946 pub unsafe fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1949 pub unsafe fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1952 pub unsafe fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1955 pub unsafe fn LLVMDIBuilderCreateCompileUnit(
1956 Builder: DIBuilderRef,
1964 SplitName: *c_char);
1967 pub unsafe fn LLVMDIBuilderCreateFile(
1968 Builder: DIBuilderRef,
1970 Directory: *c_char) -> DIFile;
1973 pub unsafe fn LLVMDIBuilderCreateSubroutineType(
1974 Builder: DIBuilderRef,
1976 ParameterTypes: DIArray) -> DICompositeType;
1979 pub unsafe fn LLVMDIBuilderCreateFunction(
1980 Builder: DIBuilderRef,
1981 Scope: DIDescriptor,
1983 LinkageName: *c_char,
1987 isLocalToUnit: bool,
1994 Decl: ValueRef) -> DISubprogram;
1997 pub unsafe fn LLVMDIBuilderCreateBasicType(
1998 Builder: DIBuilderRef,
2000 SizeInBits: c_ulonglong,
2001 AlignInBits: c_ulonglong,
2002 Encoding: c_uint) -> DIBasicType;
2005 pub unsafe fn LLVMDIBuilderCreatePointerType(
2006 Builder: DIBuilderRef,
2008 SizeInBits: c_ulonglong,
2009 AlignInBits: c_ulonglong,
2010 Name: *c_char) -> DIDerivedType;
2013 pub unsafe fn LLVMDIBuilderCreateStructType(
2014 Builder: DIBuilderRef,
2015 Scope: DIDescriptor,
2019 SizeInBits: c_ulonglong,
2020 AlignInBits: c_ulonglong,
2022 DerivedFrom: DIType,
2024 RunTimeLang: c_uint,
2025 VTableHolder: ValueRef) -> DICompositeType;
2028 pub unsafe fn LLVMDIBuilderCreateMemberType(
2029 Builder: DIBuilderRef,
2030 Scope: DIDescriptor,
2034 SizeInBits: c_ulonglong,
2035 AlignInBits: c_ulonglong,
2036 OffsetInBits: c_ulonglong,
2038 Ty: DIType) -> DIDerivedType;
2041 pub unsafe fn LLVMDIBuilderCreateLexicalBlock(
2042 Builder: DIBuilderRef,
2043 Scope: DIDescriptor,
2046 Col: c_uint) -> DILexicalBlock;
2049 pub unsafe fn LLVMDIBuilderCreateLocalVariable(
2050 Builder: DIBuilderRef,
2052 Scope: DIDescriptor,
2057 AlwaysPreserve: bool,
2059 ArgNo: c_uint) -> DIVariable;
2062 pub unsafe fn LLVMDIBuilderCreateArrayType(
2063 Builder: DIBuilderRef,
2065 AlignInBits: c_ulonglong,
2067 Subscripts: DIArray) -> DIType;
2070 pub unsafe fn LLVMDIBuilderCreateVectorType(
2071 Builder: DIBuilderRef,
2073 AlignInBits: c_ulonglong,
2075 Subscripts: DIArray) -> DIType;
2078 pub unsafe fn LLVMDIBuilderGetOrCreateSubrange(
2079 Builder: DIBuilderRef,
2081 Count: c_longlong) -> DISubrange;
2084 pub unsafe fn LLVMDIBuilderGetOrCreateArray(
2085 Builder: DIBuilderRef,
2087 Count: c_uint) -> DIArray;
2090 pub unsafe fn LLVMDIBuilderInsertDeclareAtEnd(
2091 Builder: DIBuilderRef,
2093 VarInfo: DIVariable,
2094 InsertAtEnd: BasicBlockRef) -> ValueRef;
2097 pub unsafe fn LLVMDIBuilderInsertDeclareBefore(
2098 Builder: DIBuilderRef,
2100 VarInfo: DIVariable,
2101 InsertBefore: ValueRef) -> ValueRef;
2104 pub unsafe fn LLVMDIBuilderCreateEnumerator(
2105 Builder: DIBuilderRef,
2107 Val: c_ulonglong) -> ValueRef;
2110 pub unsafe fn LLVMDIBuilderCreateEnumerationType(
2111 Builder: DIBuilderRef,
2116 SizeInBits: c_ulonglong,
2117 AlignInBits: c_ulonglong,
2119 ClassType: ValueRef) -> ValueRef;
2122 pub unsafe fn LLVMDIBuilderCreateUnionType(
2123 Builder: DIBuilderRef,
2128 SizeInBits: c_ulonglong,
2129 AlignInBits: c_ulonglong,
2132 RunTimeLang: c_uint) -> ValueRef;
2136 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
2138 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
2141 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
2143 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
2146 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
2148 llvm::LLVMSetLinkage(Global, Link as c_uint);
2152 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
2154 llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
2157 pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
2159 llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
2162 /* Memory-managed object interface to type handles. */
2164 pub struct TypeNames {
2165 type_names: HashMap<TypeRef, ~str>,
2166 named_types: HashMap<~str, TypeRef>
2170 pub fn new() -> TypeNames {
2172 type_names: HashMap::new(),
2173 named_types: HashMap::new()
2177 pub fn associate_type(&mut self, s: &str, t: &Type) {
2178 assert!(self.type_names.insert(t.to_ref(), s.to_owned()));
2179 assert!(self.named_types.insert(s.to_owned(), t.to_ref()));
2182 pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
2183 match self.type_names.find(&ty.to_ref()) {
2184 Some(a) => Some(a.slice(0, a.len())),
2189 pub fn find_type(&self, s: &str) -> Option<Type> {
2190 self.named_types.find_equiv(&s).map_consume(|x| Type::from_ref(*x))
2193 // We have a depth count, because we seem to make infinite types.
2194 pub fn type_to_str_depth(&self, ty: Type, depth: int) -> ~str {
2195 match self.find_name(&ty) {
2196 option::Some(name) => return name.to_owned(),
2205 let kind = ty.kind();
2211 Double => ~"Double",
2212 X86_FP80 => ~"X86_FP80",
2214 PPC_FP128 => ~"PPC_FP128",
2216 Vector => ~"Vector",
2217 Metadata => ~"Metadata",
2218 X86_MMX => ~"X86_MMAX",
2220 fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
2223 let out_ty = ty.return_type();
2224 let args = ty.func_params();
2226 args.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2227 let out_ty = self.type_to_str_depth(out_ty, depth-1);
2228 fmt!("fn(%s) -> %s", args, out_ty)
2231 let tys = ty.field_types();
2232 let tys = tys.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2236 let el_ty = ty.element_type();
2237 let el_ty = self.type_to_str_depth(el_ty, depth-1);
2238 let len = ty.array_length();
2239 fmt!("[%s x %u]", el_ty, len)
2242 let el_ty = ty.element_type();
2243 let el_ty = self.type_to_str_depth(el_ty, depth-1);
2246 _ => fail!("Unknown Type Kind (%u)", kind as uint)
2251 pub fn type_to_str(&self, ty: Type) -> ~str {
2252 self.type_to_str_depth(ty, 30)
2255 pub fn val_to_str(&self, val: ValueRef) -> ~str {
2257 let ty = Type::from_ref(llvm::LLVMTypeOf(val));
2258 self.type_to_str(ty)
2264 /* Memory-managed interface to target data. */
2266 pub struct target_data_res {
2270 impl Drop for target_data_res {
2273 llvm::LLVMDisposeTargetData(self.TD);
2278 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
2284 pub struct TargetData {
2285 lltd: TargetDataRef,
2286 dtor: @target_data_res
2289 pub fn mk_target_data(string_rep: &str) -> TargetData {
2291 str::as_c_str(string_rep, |buf| unsafe {
2292 llvm::LLVMCreateTargetData(buf)
2297 dtor: @target_data_res(lltd)
2301 /* Memory-managed interface to pass managers. */
2303 pub struct pass_manager_res {
2307 impl Drop for pass_manager_res {
2310 llvm::LLVMDisposePassManager(self.PM);
2315 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
2321 pub struct PassManager {
2322 llpm: PassManagerRef,
2323 dtor: @pass_manager_res
2326 pub fn mk_pass_manager() -> PassManager {
2328 let llpm = llvm::LLVMCreatePassManager();
2332 dtor: @pass_manager_res(llpm)
2337 /* Memory-managed interface to object files. */
2339 pub struct object_file_res {
2340 ObjectFile: ObjectFileRef,
2343 impl Drop for object_file_res {
2346 llvm::LLVMDisposeObjectFile(self.ObjectFile);
2351 pub fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
2357 pub struct ObjectFile {
2358 llof: ObjectFileRef,
2359 dtor: @object_file_res
2362 pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2364 let llof = llvm::LLVMCreateObjectFile(llmb);
2365 if llof as int == 0 { return option::None::<ObjectFile>; }
2367 option::Some(ObjectFile {
2369 dtor: @object_file_res(llof)
2374 /* Memory-managed interface to section iterators. */
2376 pub struct section_iter_res {
2377 SI: SectionIteratorRef,
2380 impl Drop for section_iter_res {
2383 llvm::LLVMDisposeSectionIterator(self.SI);
2388 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
2394 pub struct SectionIter {
2395 llsi: SectionIteratorRef,
2396 dtor: @section_iter_res
2399 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2401 let llsi = llvm::LLVMGetSections(llof);
2404 dtor: @section_iter_res(llsi)