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};
16 use middle::trans::type_::Type;
18 pub type Opcode = u32;
19 pub type Bool = c_uint;
21 pub static True: Bool = 1 as Bool;
22 pub static False: Bool = 0 as Bool;
24 // Consts for the LLVM CallConv type, pre-cast to uint.
30 X86StdcallCallConv = 64,
31 X86FastcallCallConv = 65,
35 LLVMDefaultVisibility = 0,
37 ProtectedVisibility = 2,
42 AvailableExternallyLinkage = 1,
43 LinkOnceAnyLinkage = 2,
44 LinkOnceODRLinkage = 3,
45 LinkOnceODRAutoHideLinkage = 4,
51 DLLImportLinkage = 10,
52 DLLExportLinkage = 11,
53 ExternalWeakLinkage = 12,
56 LinkerPrivateLinkage = 15,
57 LinkerPrivateWeakLinkage = 16,
64 NoReturnAttribute = 4,
66 StructRetAttribute = 16,
67 NoUnwindAttribute = 32,
68 NoAliasAttribute = 64,
71 ReadNoneAttribute = 512,
72 ReadOnlyAttribute = 1024,
73 NoInlineAttribute = 2048,
74 AlwaysInlineAttribute = 4096,
75 OptimizeForSizeAttribute = 8192,
76 StackProtectAttribute = 16384,
77 StackProtectReqAttribute = 32768,
79 AlignmentAttribute = 2031616,
80 NoCaptureAttribute = 2097152,
81 NoRedZoneAttribute = 4194304,
82 NoImplicitFloatAttribute = 8388608,
83 NakedAttribute = 16777216,
84 InlineHintAttribute = 33554432,
86 StackAttribute = 469762048,
87 ReturnsTwiceAttribute = 536870912,
89 UWTableAttribute = 1073741824,
90 NonLazyBindAttribute = 2147483648,
93 // enum for the LLVM IntPredicate type
94 pub enum IntPredicate {
107 // enum for the LLVM RealPredicate type
108 pub enum RealPredicate {
109 RealPredicateFalse = 0,
124 RealPredicateTrue = 15,
127 // The LLVM TypeKind type - must stay in sync with the def of
128 // LLVMTypeKind in llvm/include/llvm-c/Core.h
129 pub type TypeKind = u32;
130 pub static Void: TypeKind = 0;
131 pub static Half: TypeKind = 1;
132 pub static Float: TypeKind = 2;
133 pub static Double: TypeKind = 3;
134 pub static X86_FP80: TypeKind = 4;
135 pub static FP128: TypeKind = 5;
136 pub static PPC_FP128: TypeKind = 6;
137 pub static Label: TypeKind = 7;
138 pub static Integer: TypeKind = 8;
139 pub static Function: TypeKind = 9;
140 pub static Struct: TypeKind = 10;
141 pub static Array: TypeKind = 11;
142 pub static Pointer: TypeKind = 12;
143 pub static Vector: TypeKind = 13;
144 pub static Metadata: TypeKind = 14;
145 pub static X86_MMX: TypeKind = 15;
147 pub enum AtomicBinOp {
161 pub enum AtomicOrdering {
165 // Consume = 3, // Not specified yet.
169 SequentiallyConsistent = 7
172 // FIXME: Not used right now, but will be once #2334 is fixed
173 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
188 // Inline Asm Dialect
189 pub enum AsmDialect {
194 // Opaque pointer types
195 pub enum Module_opaque {}
196 pub type ModuleRef = *Module_opaque;
197 pub enum Context_opaque {}
198 pub type ContextRef = *Context_opaque;
199 pub enum Type_opaque {}
200 pub type TypeRef = *Type_opaque;
201 pub enum Value_opaque {}
202 pub type ValueRef = *Value_opaque;
203 pub enum BasicBlock_opaque {}
204 pub type BasicBlockRef = *BasicBlock_opaque;
205 pub enum Builder_opaque {}
206 pub type BuilderRef = *Builder_opaque;
207 pub enum ExecutionEngine_opaque {}
208 pub type ExecutionEngineRef = *ExecutionEngine_opaque;
209 pub enum MemoryBuffer_opaque {}
210 pub type MemoryBufferRef = *MemoryBuffer_opaque;
211 pub enum PassManager_opaque {}
212 pub type PassManagerRef = *PassManager_opaque;
213 pub enum PassManagerBuilder_opaque {}
214 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
215 pub enum Use_opaque {}
216 pub type UseRef = *Use_opaque;
217 pub enum TargetData_opaque {}
218 pub type TargetDataRef = *TargetData_opaque;
219 pub enum ObjectFile_opaque {}
220 pub type ObjectFileRef = *ObjectFile_opaque;
221 pub enum SectionIterator_opaque {}
222 pub type SectionIteratorRef = *SectionIterator_opaque;
223 pub enum Pass_opaque {}
224 pub type PassRef = *Pass_opaque;
227 use super::{ValueRef};
229 pub enum DIBuilder_opaque {}
230 pub type DIBuilderRef = *DIBuilder_opaque;
232 pub type DIDescriptor = ValueRef;
233 pub type DIScope = DIDescriptor;
234 pub type DILocation = DIDescriptor;
235 pub type DIFile = DIScope;
236 pub type DILexicalBlock = DIScope;
237 pub type DISubprogram = DIScope;
238 pub type DIType = DIDescriptor;
239 pub type DIBasicType = DIType;
240 pub type DIDerivedType = DIType;
241 pub type DICompositeType = DIDerivedType;
242 pub type DIVariable = DIDescriptor;
243 pub type DIArray = DIDescriptor;
244 pub type DISubrange = DIDescriptor;
246 pub enum DIDescriptorFlags {
247 FlagPrivate = 1 << 0,
248 FlagProtected = 1 << 1,
249 FlagFwdDecl = 1 << 2,
250 FlagAppleBlock = 1 << 3,
251 FlagBlockByrefStruct = 1 << 4,
252 FlagVirtual = 1 << 5,
253 FlagArtificial = 1 << 6,
254 FlagExplicit = 1 << 7,
255 FlagPrototyped = 1 << 8,
256 FlagObjcClassComplete = 1 << 9,
257 FlagObjectPointer = 1 << 10,
258 FlagVector = 1 << 11,
259 FlagStaticMember = 1 << 12
264 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
265 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
266 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
267 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
268 use super::{ValueRef, PassRef};
269 use super::debuginfo::*;
270 use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};
272 #[link_args = "-Lrustllvm -lrustllvm"]
273 #[link_name = "rustllvm"]
276 /* Create and destroy contexts. */
278 pub unsafe fn LLVMContextCreate() -> ContextRef;
280 pub unsafe fn LLVMContextDispose(C: ContextRef);
282 pub unsafe fn LLVMGetMDKindIDInContext(C: ContextRef,
287 /* Create and destroy modules. */
289 pub unsafe fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
293 pub unsafe fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
295 pub unsafe fn LLVMDisposeModule(M: ModuleRef);
297 /** Data layout. See Module::getDataLayout. */
299 pub unsafe fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
301 pub unsafe fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
303 /** Target triple. See Module::getTargetTriple. */
305 pub unsafe fn LLVMGetTarget(M: ModuleRef) -> *c_char;
307 pub unsafe fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
309 /** See Module::dump. */
311 pub unsafe fn LLVMDumpModule(M: ModuleRef);
313 /** See Module::setModuleInlineAsm. */
315 pub unsafe fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
317 /** See llvm::LLVMTypeKind::getTypeID. */
318 pub unsafe fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
320 /** See llvm::LLVMType::getContext. */
322 pub unsafe fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
324 /* Operations on integer types */
326 pub unsafe fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
328 pub unsafe fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
330 pub unsafe fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
332 pub unsafe fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
334 pub unsafe fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
336 pub unsafe fn LLVMIntTypeInContext(C: ContextRef,
337 NumBits: c_uint) -> TypeRef;
340 pub unsafe fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
342 /* Operations on real types */
344 pub unsafe fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
346 pub unsafe fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
348 pub unsafe fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
350 pub unsafe fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
352 pub unsafe fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
354 /* Operations on function types */
356 pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
357 ParamTypes: *TypeRef,
362 pub unsafe fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
364 pub unsafe fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
366 pub unsafe fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
368 pub unsafe fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
370 /* Operations on struct types */
372 pub unsafe fn LLVMStructTypeInContext(C: ContextRef,
373 ElementTypes: *TypeRef,
374 ElementCount: c_uint,
375 Packed: Bool) -> TypeRef;
377 pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
380 pub unsafe fn LLVMGetStructElementTypes(StructTy: TypeRef,
383 pub unsafe fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
385 /* Operations on array, pointer, and vector types (sequence types) */
387 pub unsafe fn LLVMArrayType(ElementType: TypeRef,
388 ElementCount: c_uint) -> TypeRef;
390 pub unsafe fn LLVMPointerType(ElementType: TypeRef,
391 AddressSpace: c_uint) -> TypeRef;
393 pub unsafe fn LLVMVectorType(ElementType: TypeRef,
394 ElementCount: c_uint) -> TypeRef;
397 pub unsafe fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
399 pub unsafe fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
401 pub unsafe fn LLVMGetPointerAddressSpace(PointerTy: TypeRef)
404 pub unsafe fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef,
408 pub unsafe fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
410 /* Operations on other types */
412 pub unsafe fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
414 pub unsafe fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
416 pub unsafe fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
418 /* Operations on all values */
420 pub unsafe fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
422 pub unsafe fn LLVMGetValueName(Val: ValueRef) -> *c_char;
424 pub unsafe fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
426 pub unsafe fn LLVMDumpValue(Val: ValueRef);
428 pub unsafe fn LLVMReplaceAllUsesWith(OldVal: ValueRef,
431 pub unsafe fn LLVMHasMetadata(Val: ValueRef) -> c_int;
433 pub unsafe fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint)
436 pub unsafe fn LLVMSetMetadata(Val: ValueRef,
440 /* Operations on Uses */
442 pub unsafe fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
444 pub unsafe fn LLVMGetNextUse(U: UseRef) -> UseRef;
446 pub unsafe fn LLVMGetUser(U: UseRef) -> ValueRef;
448 pub unsafe fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
450 /* Operations on Users */
452 pub unsafe fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
454 pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint)
457 pub unsafe fn LLVMSetOperand(Val: ValueRef,
461 /* Operations on constants of any type */
463 pub unsafe fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
466 pub unsafe fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
468 pub unsafe fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) -> ValueRef;
470 pub unsafe fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef) -> ValueRef;
471 /* only for int/vector */
473 pub unsafe fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
475 pub unsafe fn LLVMIsConstant(Val: ValueRef) -> Bool;
477 pub unsafe fn LLVMIsNull(Val: ValueRef) -> Bool;
479 pub unsafe fn LLVMIsUndef(Val: ValueRef) -> Bool;
481 pub unsafe fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
483 /* Operations on metadata */
485 pub unsafe fn LLVMMDStringInContext(C: ContextRef,
490 pub unsafe fn LLVMMDNodeInContext(C: ContextRef,
495 pub unsafe fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
498 /* Operations on scalar constants */
500 pub unsafe fn LLVMConstInt(IntTy: TypeRef,
505 pub unsafe fn LLVMConstIntOfString(IntTy: TypeRef,
510 pub unsafe fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
516 pub unsafe fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
518 pub unsafe fn LLVMConstRealOfString(RealTy: TypeRef,
522 pub unsafe fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
527 pub unsafe fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef)
530 pub unsafe fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef)
534 /* Operations on composite constants */
536 pub unsafe fn LLVMConstStringInContext(C: ContextRef,
539 DontNullTerminate: Bool)
542 pub unsafe fn LLVMConstStructInContext(C: ContextRef,
543 ConstantVals: *ValueRef,
545 Packed: Bool) -> ValueRef;
548 pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
549 ConstantVals: *ValueRef,
553 pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
554 Size: c_uint) -> ValueRef;
556 /* Constant expressions */
558 pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
560 pub unsafe fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
562 pub unsafe fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
564 pub unsafe fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
566 pub unsafe fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
568 pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
570 pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
572 pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
573 RHSConstant: ValueRef)
576 pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
577 RHSConstant: ValueRef)
580 pub unsafe fn LLVMConstNUWAdd(LHSConstant: ValueRef,
581 RHSConstant: ValueRef)
584 pub unsafe fn LLVMConstFAdd(LHSConstant: ValueRef,
585 RHSConstant: ValueRef)
588 pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
589 RHSConstant: ValueRef)
592 pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
593 RHSConstant: ValueRef)
596 pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
597 RHSConstant: ValueRef)
600 pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
601 RHSConstant: ValueRef)
604 pub unsafe fn LLVMConstMul(LHSConstant: ValueRef,
605 RHSConstant: ValueRef)
608 pub unsafe fn LLVMConstNSWMul(LHSConstant: ValueRef,
609 RHSConstant: ValueRef)
612 pub unsafe fn LLVMConstNUWMul(LHSConstant: ValueRef,
613 RHSConstant: ValueRef)
616 pub unsafe fn LLVMConstFMul(LHSConstant: ValueRef,
617 RHSConstant: ValueRef)
620 pub unsafe fn LLVMConstUDiv(LHSConstant: ValueRef,
621 RHSConstant: ValueRef)
624 pub unsafe fn LLVMConstSDiv(LHSConstant: ValueRef,
625 RHSConstant: ValueRef)
628 pub unsafe fn LLVMConstExactSDiv(LHSConstant: ValueRef,
629 RHSConstant: ValueRef)
632 pub unsafe fn LLVMConstFDiv(LHSConstant: ValueRef,
633 RHSConstant: ValueRef)
636 pub unsafe fn LLVMConstURem(LHSConstant: ValueRef,
637 RHSConstant: ValueRef)
640 pub unsafe fn LLVMConstSRem(LHSConstant: ValueRef,
641 RHSConstant: ValueRef)
644 pub unsafe fn LLVMConstFRem(LHSConstant: ValueRef,
645 RHSConstant: ValueRef)
648 pub unsafe fn LLVMConstAnd(LHSConstant: ValueRef,
649 RHSConstant: ValueRef)
652 pub unsafe fn LLVMConstOr(LHSConstant: ValueRef,
653 RHSConstant: ValueRef)
656 pub unsafe fn LLVMConstXor(LHSConstant: ValueRef,
657 RHSConstant: ValueRef)
660 pub unsafe fn LLVMConstShl(LHSConstant: ValueRef,
661 RHSConstant: ValueRef)
664 pub unsafe fn LLVMConstLShr(LHSConstant: ValueRef,
665 RHSConstant: ValueRef) -> ValueRef;
667 pub unsafe fn LLVMConstAShr(LHSConstant: ValueRef,
668 RHSConstant: ValueRef) -> ValueRef;
670 pub unsafe fn LLVMConstGEP(ConstantVal: ValueRef,
671 ConstantIndices: *ValueRef,
672 NumIndices: c_uint) -> ValueRef;
674 pub unsafe fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
675 ConstantIndices: *ValueRef,
679 pub unsafe fn LLVMConstTrunc(ConstantVal: ValueRef,
683 pub unsafe fn LLVMConstSExt(ConstantVal: ValueRef,
687 pub unsafe fn LLVMConstZExt(ConstantVal: ValueRef,
691 pub unsafe fn LLVMConstFPTrunc(ConstantVal: ValueRef,
695 pub unsafe fn LLVMConstFPExt(ConstantVal: ValueRef,
699 pub unsafe fn LLVMConstUIToFP(ConstantVal: ValueRef,
703 pub unsafe fn LLVMConstSIToFP(ConstantVal: ValueRef,
707 pub unsafe fn LLVMConstFPToUI(ConstantVal: ValueRef,
711 pub unsafe fn LLVMConstFPToSI(ConstantVal: ValueRef,
715 pub unsafe fn LLVMConstPtrToInt(ConstantVal: ValueRef,
719 pub unsafe fn LLVMConstIntToPtr(ConstantVal: ValueRef,
723 pub unsafe fn LLVMConstBitCast(ConstantVal: ValueRef,
727 pub unsafe fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef,
731 pub unsafe fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef,
735 pub unsafe fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef,
739 pub unsafe fn LLVMConstPointerCast(ConstantVal: ValueRef,
743 pub unsafe fn LLVMConstIntCast(ConstantVal: ValueRef,
748 pub unsafe fn LLVMConstFPCast(ConstantVal: ValueRef,
752 pub unsafe fn LLVMConstSelect(ConstantCondition: ValueRef,
753 ConstantIfTrue: ValueRef,
754 ConstantIfFalse: ValueRef)
757 pub unsafe fn LLVMConstExtractElement(VectorConstant: ValueRef,
758 IndexConstant: ValueRef) -> ValueRef;
760 pub unsafe fn LLVMConstInsertElement(VectorConstant: ValueRef,
761 ElementValueConstant: ValueRef,
762 IndexConstant: ValueRef) -> ValueRef;
764 pub unsafe fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
765 VectorBConstant: ValueRef,
766 MaskConstant: ValueRef) -> ValueRef;
768 pub unsafe fn LLVMConstExtractValue(AggConstant: ValueRef,
770 NumIdx: c_uint) -> ValueRef;
772 pub unsafe fn LLVMConstInsertValue(AggConstant: ValueRef,
773 ElementValueConstant: ValueRef,
778 pub unsafe fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
779 Constraints: *c_char, HasSideEffects: Bool,
780 IsAlignStack: Bool) -> ValueRef;
782 pub unsafe fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef)
787 /* Operations on global variables, functions, and aliases (globals) */
789 pub unsafe fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
791 pub unsafe fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
793 pub unsafe fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
795 pub unsafe fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
797 pub unsafe fn LLVMGetSection(Global: ValueRef) -> *c_char;
799 pub unsafe fn LLVMSetSection(Global: ValueRef, Section: *c_char);
801 pub unsafe fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
803 pub unsafe fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
805 pub unsafe fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
807 pub unsafe fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
810 /* Operations on global variables */
812 pub unsafe fn LLVMAddGlobal(M: ModuleRef,
817 pub unsafe fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
820 AddressSpace: c_uint)
823 pub unsafe fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char)
826 pub unsafe fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
828 pub unsafe fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
830 pub unsafe fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
832 pub unsafe fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
834 pub unsafe fn LLVMDeleteGlobal(GlobalVar: ValueRef);
836 pub unsafe fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
838 pub unsafe fn LLVMSetInitializer(GlobalVar: ValueRef,
839 ConstantVal: ValueRef);
841 pub unsafe fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
843 pub unsafe fn LLVMSetThreadLocal(GlobalVar: ValueRef,
844 IsThreadLocal: Bool);
846 pub unsafe fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
848 pub unsafe fn LLVMSetGlobalConstant(GlobalVar: ValueRef,
851 /* Operations on aliases */
853 pub unsafe fn LLVMAddAlias(M: ModuleRef,
859 /* Operations on functions */
861 pub unsafe fn LLVMAddFunction(M: ModuleRef,
866 pub unsafe fn LLVMGetNamedFunction(M: ModuleRef,
867 Name: *c_char) -> ValueRef;
869 pub unsafe fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
871 pub unsafe fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
873 pub unsafe fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
875 pub unsafe fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
877 pub unsafe fn LLVMDeleteFunction(Fn: ValueRef);
879 pub unsafe fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
880 FunctionTy: TypeRef) -> ValueRef;
882 pub unsafe fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
884 pub unsafe fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
886 pub unsafe fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
888 pub unsafe fn LLVMGetGC(Fn: ValueRef) -> *c_char;
890 pub unsafe fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
892 pub unsafe fn LLVMAddFunctionAttr(Fn: ValueRef,
896 pub unsafe fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
898 pub unsafe fn LLVMRemoveFunctionAttr(Fn: ValueRef,
900 HighPA: c_ulonglong);
902 /* Operations on parameters */
904 pub unsafe fn LLVMCountParams(Fn: ValueRef) -> c_uint;
906 pub unsafe fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
908 pub unsafe fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
910 pub unsafe fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
912 pub unsafe fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
914 pub unsafe fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
916 pub unsafe fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
918 pub unsafe fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
920 pub unsafe fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
922 pub unsafe fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
924 pub unsafe fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
926 pub unsafe fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
928 /* Operations on basic blocks */
930 pub unsafe fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
932 pub unsafe fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
934 pub unsafe fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
936 pub unsafe fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
938 pub unsafe fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
940 pub unsafe fn LLVMGetBasicBlocks(Fn: ValueRef,
941 BasicBlocks: *ValueRef);
943 pub unsafe fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
945 pub unsafe fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
947 pub unsafe fn LLVMGetNextBasicBlock(BB: BasicBlockRef)
950 pub unsafe fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef)
953 pub unsafe fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
956 pub unsafe fn LLVMAppendBasicBlockInContext(C: ContextRef,
961 pub unsafe fn LLVMInsertBasicBlockInContext(C: ContextRef,
966 pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
969 pub unsafe fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef, MoveAfter: BasicBlockRef);
972 pub unsafe fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef, MoveBefore: BasicBlockRef);
974 /* Operations on instructions */
976 pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef)
979 pub unsafe fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
981 pub unsafe fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
983 pub unsafe fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
985 pub unsafe fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
987 pub unsafe fn LLVMInstructionEraseFromParent(Inst: ValueRef);
989 /* Operations on call sites */
991 pub unsafe fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
993 pub unsafe fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
995 pub unsafe fn LLVMAddInstrAttribute(Instr: ValueRef,
999 pub unsafe fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1003 pub unsafe fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1007 /* Operations on call instructions (only) */
1009 pub unsafe fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1011 pub unsafe fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1013 /* Operations on phi nodes */
1015 pub unsafe fn LLVMAddIncoming(PhiNode: ValueRef,
1016 IncomingValues: *ValueRef,
1017 IncomingBlocks: *BasicBlockRef,
1020 pub unsafe fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1022 pub unsafe fn LLVMGetIncomingValue(PhiNode: ValueRef,
1026 pub unsafe fn LLVMGetIncomingBlock(PhiNode: ValueRef,
1027 Index: c_uint) -> BasicBlockRef;
1029 /* Instruction builders */
1031 pub unsafe fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1033 pub unsafe fn LLVMPositionBuilder(Builder: BuilderRef,
1034 Block: BasicBlockRef,
1037 pub unsafe fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1040 pub unsafe fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1041 Block: BasicBlockRef);
1043 pub unsafe fn LLVMGetInsertBlock(Builder: BuilderRef)
1046 pub unsafe fn LLVMClearInsertionPosition(Builder: BuilderRef);
1048 pub unsafe fn LLVMInsertIntoBuilder(Builder: BuilderRef,
1051 pub unsafe fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1055 pub unsafe fn LLVMDisposeBuilder(Builder: BuilderRef);
1057 pub unsafe fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1061 pub unsafe fn LLVMSetCurrentDebugLocation(Builder: BuilderRef,
1064 pub unsafe fn LLVMGetCurrentDebugLocation(Builder: BuilderRef)
1067 pub unsafe fn LLVMSetInstDebugLocation(Builder: BuilderRef,
1072 pub unsafe fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1074 pub unsafe fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1076 pub unsafe fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
1077 N: c_uint) -> ValueRef;
1079 pub unsafe fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef)
1082 pub unsafe fn LLVMBuildCondBr(B: BuilderRef,
1084 Then: BasicBlockRef,
1085 Else: BasicBlockRef)
1088 pub unsafe fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef,
1089 Else: BasicBlockRef, NumCases: c_uint)
1092 pub unsafe fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef,
1093 NumDests: c_uint) -> ValueRef;
1095 pub unsafe fn LLVMBuildInvoke(B: BuilderRef,
1099 Then: BasicBlockRef,
1100 Catch: BasicBlockRef,
1101 Name: *c_char) -> ValueRef;
1103 pub unsafe fn LLVMBuildLandingPad(B: BuilderRef,
1110 pub unsafe fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef)
1113 pub unsafe fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1115 /* Add a case to the switch instruction */
1117 pub unsafe fn LLVMAddCase(Switch: ValueRef,
1119 Dest: BasicBlockRef);
1121 /* Add a destination to the indirectbr instruction */
1123 pub unsafe fn LLVMAddDestination(IndirectBr: ValueRef,
1124 Dest: BasicBlockRef);
1126 /* Add a clause to the landing pad instruction */
1128 pub unsafe fn LLVMAddClause(LandingPad: ValueRef,
1129 ClauseVal: ValueRef);
1131 /* Set the cleanup on a landing pad instruction */
1133 pub unsafe fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1137 pub unsafe fn LLVMBuildAdd(B: BuilderRef,
1143 pub unsafe fn LLVMBuildNSWAdd(B: BuilderRef,
1149 pub unsafe fn LLVMBuildNUWAdd(B: BuilderRef,
1155 pub unsafe fn LLVMBuildFAdd(B: BuilderRef,
1161 pub unsafe fn LLVMBuildSub(B: BuilderRef,
1167 pub unsafe fn LLVMBuildNSWSub(B: BuilderRef,
1173 pub unsafe fn LLVMBuildNUWSub(B: BuilderRef,
1179 pub unsafe fn LLVMBuildFSub(B: BuilderRef,
1185 pub unsafe fn LLVMBuildMul(B: BuilderRef,
1191 pub unsafe fn LLVMBuildNSWMul(B: BuilderRef,
1197 pub unsafe fn LLVMBuildNUWMul(B: BuilderRef,
1203 pub unsafe fn LLVMBuildFMul(B: BuilderRef,
1209 pub unsafe fn LLVMBuildUDiv(B: BuilderRef,
1215 pub unsafe fn LLVMBuildSDiv(B: BuilderRef,
1221 pub unsafe fn LLVMBuildExactSDiv(B: BuilderRef,
1227 pub unsafe fn LLVMBuildFDiv(B: BuilderRef,
1233 pub unsafe fn LLVMBuildURem(B: BuilderRef,
1239 pub unsafe fn LLVMBuildSRem(B: BuilderRef,
1245 pub unsafe fn LLVMBuildFRem(B: BuilderRef,
1251 pub unsafe fn LLVMBuildShl(B: BuilderRef,
1257 pub unsafe fn LLVMBuildLShr(B: BuilderRef,
1263 pub unsafe fn LLVMBuildAShr(B: BuilderRef,
1269 pub unsafe fn LLVMBuildAnd(B: BuilderRef,
1275 pub unsafe fn LLVMBuildOr(B: BuilderRef,
1281 pub unsafe fn LLVMBuildXor(B: BuilderRef,
1287 pub unsafe fn LLVMBuildBinOp(B: BuilderRef,
1294 pub unsafe fn LLVMBuildNeg(B: BuilderRef,
1299 pub unsafe fn LLVMBuildNSWNeg(B: BuilderRef,
1304 pub unsafe fn LLVMBuildNUWNeg(B: BuilderRef,
1309 pub unsafe fn LLVMBuildFNeg(B: BuilderRef,
1314 pub unsafe fn LLVMBuildNot(B: BuilderRef,
1321 pub unsafe fn LLVMBuildMalloc(B: BuilderRef,
1326 pub unsafe fn LLVMBuildArrayMalloc(B: BuilderRef,
1329 Name: *c_char) -> ValueRef;
1331 pub unsafe fn LLVMBuildAlloca(B: BuilderRef,
1336 pub unsafe fn LLVMBuildArrayAlloca(B: BuilderRef,
1339 Name: *c_char) -> ValueRef;
1341 pub unsafe fn LLVMBuildFree(B: BuilderRef,
1342 PointerVal: ValueRef) -> ValueRef;
1344 pub unsafe fn LLVMBuildLoad(B: BuilderRef,
1345 PointerVal: ValueRef,
1350 pub unsafe fn LLVMBuildStore(B: BuilderRef,
1356 pub unsafe fn LLVMBuildGEP(B: BuilderRef,
1363 pub unsafe fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
1364 Indices: *ValueRef, NumIndices: c_uint,
1368 pub unsafe fn LLVMBuildStructGEP(B: BuilderRef,
1374 pub unsafe fn LLVMBuildGlobalString(B: BuilderRef,
1379 pub unsafe fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1386 pub unsafe fn LLVMBuildTrunc(B: BuilderRef,
1389 Name: *c_char) -> ValueRef;
1391 pub unsafe fn LLVMBuildZExt(B: BuilderRef,
1397 pub unsafe fn LLVMBuildSExt(B: BuilderRef,
1403 pub unsafe fn LLVMBuildFPToUI(B: BuilderRef,
1406 Name: *c_char) -> ValueRef;
1408 pub unsafe fn LLVMBuildFPToSI(B: BuilderRef,
1411 Name: *c_char) -> ValueRef;
1413 pub unsafe fn LLVMBuildUIToFP(B: BuilderRef,
1416 Name: *c_char) -> ValueRef;
1418 pub unsafe fn LLVMBuildSIToFP(B: BuilderRef,
1421 Name: *c_char) -> ValueRef;
1423 pub unsafe fn LLVMBuildFPTrunc(B: BuilderRef,
1426 Name: *c_char) -> ValueRef;
1428 pub unsafe fn LLVMBuildFPExt(B: BuilderRef,
1431 Name: *c_char) -> ValueRef;
1433 pub unsafe fn LLVMBuildPtrToInt(B: BuilderRef,
1436 Name: *c_char) -> ValueRef;
1438 pub unsafe fn LLVMBuildIntToPtr(B: BuilderRef,
1441 Name: *c_char) -> ValueRef;
1443 pub unsafe fn LLVMBuildBitCast(B: BuilderRef,
1446 Name: *c_char) -> ValueRef;
1448 pub unsafe fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1454 pub unsafe fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1460 pub unsafe fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1466 pub unsafe fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
1467 DestTy: TypeRef, Name: *c_char) -> ValueRef;
1469 pub unsafe fn LLVMBuildPointerCast(B: BuilderRef,
1475 pub unsafe fn LLVMBuildIntCast(B: BuilderRef,
1478 Name: *c_char) -> ValueRef;
1480 pub unsafe fn LLVMBuildFPCast(B: BuilderRef,
1483 Name: *c_char) -> ValueRef;
1487 pub unsafe fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1488 RHS: ValueRef, Name: *c_char) -> ValueRef;
1490 pub unsafe fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1491 RHS: ValueRef, Name: *c_char) -> ValueRef;
1493 /* Miscellaneous instructions */
1495 pub unsafe fn LLVMBuildPhi(B: BuilderRef,
1500 pub unsafe fn LLVMBuildCall(B: BuilderRef,
1507 pub unsafe fn LLVMBuildSelect(B: BuilderRef,
1514 pub unsafe fn LLVMBuildVAArg(B: BuilderRef,
1520 pub unsafe fn LLVMBuildExtractElement(B: BuilderRef,
1526 pub unsafe fn LLVMBuildInsertElement(B: BuilderRef,
1533 pub unsafe fn LLVMBuildShuffleVector(B: BuilderRef,
1540 pub unsafe fn LLVMBuildExtractValue(B: BuilderRef,
1546 pub unsafe fn LLVMBuildInsertValue(B: BuilderRef,
1554 pub unsafe fn LLVMBuildIsNull(B: BuilderRef,
1559 pub unsafe fn LLVMBuildIsNotNull(B: BuilderRef,
1564 pub unsafe fn LLVMBuildPtrDiff(B: BuilderRef,
1567 Name: *c_char) -> ValueRef;
1569 /* Atomic Operations */
1570 pub unsafe fn LLVMBuildAtomicLoad(B: BuilderRef,
1571 PointerVal: ValueRef,
1573 Order: AtomicOrdering,
1577 pub unsafe fn LLVMBuildAtomicStore(B: BuilderRef,
1580 Order: AtomicOrdering,
1584 pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1588 Order: AtomicOrdering)
1590 pub unsafe fn LLVMBuildAtomicRMW(B: BuilderRef,
1594 Order: AtomicOrdering)
1597 /* Selected entries from the downcasts. */
1599 pub unsafe fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1601 /** Writes a module to the specified path. Returns 0 on success. */
1603 pub unsafe fn LLVMWriteBitcodeToFile(M: ModuleRef,
1604 Path: *c_char) -> c_int;
1606 /** Creates target data from a target layout string. */
1608 pub unsafe fn LLVMCreateTargetData(StringRep: *c_char)
1610 /** Adds the target data to the given pass manager. The pass manager
1611 references the target data only weakly. */
1613 pub unsafe fn LLVMAddTargetData(TD: TargetDataRef,
1614 PM: PassManagerRef);
1615 /** Number of bytes clobbered when doing a Store to *T. */
1617 pub unsafe fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1620 /** Number of bytes clobbered when doing a Store to *T. */
1622 pub unsafe fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1625 /** Distance between successive elements in an array of T.
1626 Includes ABI padding. */
1628 pub unsafe fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef)
1631 /** Returns the preferred alignment of a type. */
1633 pub unsafe fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
1634 Ty: TypeRef) -> c_uint;
1635 /** Returns the minimum alignment of a type. */
1637 pub unsafe fn LLVMABIAlignmentOfType(TD: TargetDataRef,
1638 Ty: TypeRef) -> c_uint;
1640 /** Computes the byte offset of the indexed struct element for a target. */
1642 pub unsafe fn LLVMOffsetOfElement(TD: TargetDataRef,
1648 * Returns the minimum alignment of a type when part of a call frame.
1651 pub unsafe fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
1655 /** Disposes target data. */
1657 pub unsafe fn LLVMDisposeTargetData(TD: TargetDataRef);
1659 /** Creates a pass manager. */
1661 pub unsafe fn LLVMCreatePassManager() -> PassManagerRef;
1662 /** Creates a function-by-function pass manager */
1664 pub unsafe fn LLVMCreateFunctionPassManagerForModule(M:ModuleRef) -> PassManagerRef;
1666 /** Disposes a pass manager. */
1668 pub unsafe fn LLVMDisposePassManager(PM: PassManagerRef);
1670 /** Runs a pass manager on a module. */
1672 pub unsafe fn LLVMRunPassManager(PM: PassManagerRef,
1673 M: ModuleRef) -> Bool;
1675 /** Runs the function passes on the provided function. */
1677 pub unsafe fn LLVMRunFunctionPassManager(FPM:PassManagerRef, F:ValueRef) -> Bool;
1679 /** Initializes all the function passes scheduled in the manager */
1681 pub unsafe fn LLVMInitializeFunctionPassManager(FPM:PassManagerRef) -> Bool;
1683 /** Finalizes all the function passes scheduled in the manager */
1685 pub unsafe fn LLVMFinalizeFunctionPassManager(FPM:PassManagerRef) -> Bool;
1688 pub unsafe fn LLVMInitializePasses();
1691 pub unsafe fn LLVMAddPass(PM:PassManagerRef,P:PassRef);
1694 pub unsafe fn LLVMCreatePass(PassName:*c_char) -> PassRef;
1697 pub unsafe fn LLVMDestroyPass(P: PassRef);
1699 /** Adds a verification pass. */
1701 pub unsafe fn LLVMAddVerifierPass(PM: PassManagerRef);
1704 pub unsafe fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1706 pub unsafe fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1708 pub unsafe fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1710 pub unsafe fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1712 pub unsafe fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1714 pub unsafe fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1716 pub unsafe fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1718 pub unsafe fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1720 pub unsafe fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1722 pub unsafe fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1724 pub unsafe fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1726 pub unsafe fn LLVMAddReassociatePass(PM: PassManagerRef);
1728 pub unsafe fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1730 pub unsafe fn LLVMAddLICMPass(PM: PassManagerRef);
1732 pub unsafe fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1734 pub unsafe fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1736 pub unsafe fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1738 pub unsafe fn LLVMAddGVNPass(PM: PassManagerRef);
1740 pub unsafe fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1742 pub unsafe fn LLVMAddSCCPPass(PM: PassManagerRef);
1744 pub unsafe fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1746 pub unsafe fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1748 pub unsafe fn LLVMAddConstantMergePass(PM: PassManagerRef);
1750 pub unsafe fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1752 pub unsafe fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1754 pub unsafe fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1756 pub unsafe fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1758 pub unsafe fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1760 pub unsafe fn LLVMAddCorrelatedValuePropagationPass(PM:
1763 pub unsafe fn LLVMAddPruneEHPass(PM: PassManagerRef);
1765 pub unsafe fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1767 pub unsafe fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1769 pub unsafe fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1771 pub unsafe fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1773 pub unsafe fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1776 pub unsafe fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1778 pub unsafe fn LLVMPassManagerBuilderDispose(PMB:
1779 PassManagerBuilderRef);
1781 pub unsafe fn LLVMPassManagerBuilderSetOptLevel(
1782 PMB: PassManagerBuilderRef, OptimizationLevel: c_uint);
1784 pub unsafe fn LLVMPassManagerBuilderSetSizeLevel(
1785 PMB: PassManagerBuilderRef, Value: Bool);
1787 pub unsafe fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1788 PMB: PassManagerBuilderRef, Value: Bool);
1790 pub unsafe fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1791 PMB: PassManagerBuilderRef, Value: Bool);
1793 pub unsafe fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
1794 (PMB: PassManagerBuilderRef, Value: Bool);
1796 pub unsafe fn LLVMPassManagerBuilderUseInlinerWithThreshold
1797 (PMB: PassManagerBuilderRef, threshold: c_uint);
1799 pub unsafe fn LLVMPassManagerBuilderPopulateModulePassManager
1800 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1803 pub unsafe fn LLVMPassManagerBuilderPopulateFunctionPassManager
1804 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1806 /** Destroys a memory buffer. */
1808 pub unsafe fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1811 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1813 /** Opens an object file. */
1815 pub unsafe fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef)
1817 /** Closes an object file. */
1819 pub unsafe fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1821 /** Enumerates the sections in an object file. */
1823 pub unsafe fn LLVMGetSections(ObjFile: ObjectFileRef)
1824 -> SectionIteratorRef;
1825 /** Destroys a section iterator. */
1827 pub unsafe fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1828 /** Returns true if the section iterator is at the end of the section
1831 pub unsafe fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1832 SI: SectionIteratorRef) -> Bool;
1833 /** Moves the section iterator to point to the next section. */
1835 pub unsafe fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1836 /** Returns the current section name. */
1838 pub unsafe fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1839 /** Returns the current section size. */
1841 pub unsafe fn LLVMGetSectionSize(SI: SectionIteratorRef)
1843 /** Returns the current section contents as a string buffer. */
1845 pub unsafe fn LLVMGetSectionContents(SI: SectionIteratorRef)
1848 /** Reads the given file and returns it as a memory buffer. Use
1849 LLVMDisposeMemoryBuffer() to get rid of it. */
1851 pub unsafe fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1856 pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
1861 // FIXME: When #2334 is fixed,
1862 // change c_uint to FileType
1865 EnableSegmentedStacks: bool)
1868 /** Returns a string describing the last error caused by an LLVMRust*
1871 pub unsafe fn LLVMRustGetLastError() -> *c_char;
1873 /** Prepare the JIT. Returns a memory manager that can load crates. */
1875 pub unsafe fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1877 /** Load a crate into the memory manager. */
1879 pub unsafe fn LLVMRustLoadCrate(MM: *(),
1883 /** Execute the JIT engine. */
1885 pub unsafe fn LLVMRustBuildJIT(MM: *(),
1887 EnableSegmentedStacks: bool) -> ExecutionEngineRef;
1889 /** Parses the bitcode in the given memory buffer. */
1891 pub unsafe fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef)
1894 /** Parses LLVM asm in the given file */
1896 pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char,
1901 pub unsafe fn LLVMRustAddPrintModulePass(PM: PassManagerRef,
1905 /** Turn on LLVM pass-timing. */
1907 pub unsafe fn LLVMRustEnableTimePasses();
1909 /// Print the pass timings since static dtors aren't picking them up.
1911 pub unsafe fn LLVMRustPrintPassTimings();
1914 pub unsafe fn LLVMRustStartMultithreading() -> bool;
1917 pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
1921 pub unsafe fn LLVMStructSetBody(StructTy: TypeRef,
1922 ElementTypes: *TypeRef,
1923 ElementCount: c_uint,
1927 pub unsafe fn LLVMConstNamedStruct(S: TypeRef,
1928 ConstantVals: *ValueRef,
1932 /** Enables LLVM debug output. */
1934 pub unsafe fn LLVMSetDebug(Enabled: c_int);
1936 /** Prepares inline assembly. */
1938 pub unsafe fn LLVMInlineAsm(Ty: TypeRef, AsmString: *c_char,
1939 Constraints: *c_char, SideEffects: Bool,
1940 AlignStack: Bool, Dialect: c_uint)
1945 pub unsafe fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1948 pub unsafe fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1951 pub unsafe fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1954 pub unsafe fn LLVMDIBuilderCreateCompileUnit(
1955 Builder: DIBuilderRef,
1963 SplitName: *c_char);
1966 pub unsafe fn LLVMDIBuilderCreateFile(
1967 Builder: DIBuilderRef,
1969 Directory: *c_char) -> DIFile;
1972 pub unsafe fn LLVMDIBuilderCreateSubroutineType(
1973 Builder: DIBuilderRef,
1975 ParameterTypes: DIArray) -> DICompositeType;
1978 pub unsafe fn LLVMDIBuilderCreateFunction(
1979 Builder: DIBuilderRef,
1980 Scope: DIDescriptor,
1982 LinkageName: *c_char,
1986 isLocalToUnit: bool,
1993 Decl: ValueRef) -> DISubprogram;
1996 pub unsafe fn LLVMDIBuilderCreateBasicType(
1997 Builder: DIBuilderRef,
1999 SizeInBits: c_ulonglong,
2000 AlignInBits: c_ulonglong,
2001 Encoding: c_uint) -> DIBasicType;
2004 pub unsafe fn LLVMDIBuilderCreatePointerType(
2005 Builder: DIBuilderRef,
2007 SizeInBits: c_ulonglong,
2008 AlignInBits: c_ulonglong,
2009 Name: *c_char) -> DIDerivedType;
2012 pub unsafe fn LLVMDIBuilderCreateStructType(
2013 Builder: DIBuilderRef,
2014 Scope: DIDescriptor,
2018 SizeInBits: c_ulonglong,
2019 AlignInBits: c_ulonglong,
2021 DerivedFrom: DIType,
2023 RunTimeLang: c_uint,
2024 VTableHolder: ValueRef) -> DICompositeType;
2027 pub unsafe fn LLVMDIBuilderCreateMemberType(
2028 Builder: DIBuilderRef,
2029 Scope: DIDescriptor,
2033 SizeInBits: c_ulonglong,
2034 AlignInBits: c_ulonglong,
2035 OffsetInBits: c_ulonglong,
2037 Ty: DIType) -> DIDerivedType;
2040 pub unsafe fn LLVMDIBuilderCreateLexicalBlock(
2041 Builder: DIBuilderRef,
2042 Scope: DIDescriptor,
2045 Col: c_uint) -> DILexicalBlock;
2048 pub unsafe fn LLVMDIBuilderCreateLocalVariable(
2049 Builder: DIBuilderRef,
2051 Scope: DIDescriptor,
2056 AlwaysPreserve: bool,
2058 ArgNo: c_uint) -> DIVariable;
2061 pub unsafe fn LLVMDIBuilderCreateArrayType(
2062 Builder: DIBuilderRef,
2064 AlignInBits: c_ulonglong,
2066 Subscripts: DIArray) -> DIType;
2069 pub unsafe fn LLVMDIBuilderCreateVectorType(
2070 Builder: DIBuilderRef,
2072 AlignInBits: c_ulonglong,
2074 Subscripts: DIArray) -> DIType;
2077 pub unsafe fn LLVMDIBuilderGetOrCreateSubrange(
2078 Builder: DIBuilderRef,
2080 Count: c_longlong) -> DISubrange;
2083 pub unsafe fn LLVMDIBuilderGetOrCreateArray(
2084 Builder: DIBuilderRef,
2086 Count: c_uint) -> DIArray;
2089 pub unsafe fn LLVMDIBuilderInsertDeclareAtEnd(
2090 Builder: DIBuilderRef,
2092 VarInfo: DIVariable,
2093 InsertAtEnd: BasicBlockRef) -> ValueRef;
2096 pub unsafe fn LLVMDIBuilderInsertDeclareBefore(
2097 Builder: DIBuilderRef,
2099 VarInfo: DIVariable,
2100 InsertBefore: ValueRef) -> ValueRef;
2103 pub unsafe fn LLVMDIBuilderCreateEnumerator(
2104 Builder: DIBuilderRef,
2106 Val: c_ulonglong) -> ValueRef;
2109 pub unsafe fn LLVMDIBuilderCreateEnumerationType(
2110 Builder: DIBuilderRef,
2115 SizeInBits: c_ulonglong,
2116 AlignInBits: c_ulonglong,
2118 ClassType: ValueRef) -> ValueRef;
2121 pub unsafe fn LLVMDIBuilderCreateUnionType(
2122 Builder: DIBuilderRef,
2127 SizeInBits: c_ulonglong,
2128 AlignInBits: c_ulonglong,
2131 RunTimeLang: c_uint) -> ValueRef;
2135 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
2137 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
2140 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
2142 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
2145 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
2147 llvm::LLVMSetLinkage(Global, Link as c_uint);
2151 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
2153 llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
2156 pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
2158 llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
2161 /* Memory-managed object interface to type handles. */
2163 pub struct TypeNames {
2164 type_names: HashMap<TypeRef, ~str>,
2165 named_types: HashMap<~str, TypeRef>
2169 pub fn new() -> TypeNames {
2171 type_names: HashMap::new(),
2172 named_types: HashMap::new()
2176 pub fn associate_type(&mut self, s: &str, t: &Type) {
2177 assert!(self.type_names.insert(t.to_ref(), s.to_owned()));
2178 assert!(self.named_types.insert(s.to_owned(), t.to_ref()));
2181 pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
2182 match self.type_names.find(&ty.to_ref()) {
2183 Some(a) => Some(a.slice(0, a.len())),
2188 pub fn find_type(&self, s: &str) -> Option<Type> {
2189 self.named_types.find_equiv(&s).map_consume(|x| Type::from_ref(*x))
2192 // We have a depth count, because we seem to make infinite types.
2193 pub fn type_to_str_depth(&self, ty: Type, depth: int) -> ~str {
2194 match self.find_name(&ty) {
2195 option::Some(name) => return name.to_owned(),
2204 let kind = ty.kind();
2210 Double => ~"Double",
2211 X86_FP80 => ~"X86_FP80",
2213 PPC_FP128 => ~"PPC_FP128",
2215 Vector => ~"Vector",
2216 Metadata => ~"Metadata",
2217 X86_MMX => ~"X86_MMAX",
2219 fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
2222 let out_ty = ty.return_type();
2223 let args = ty.func_params();
2225 args.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2226 let out_ty = self.type_to_str_depth(out_ty, depth-1);
2227 fmt!("fn(%s) -> %s", args, out_ty)
2230 let tys = ty.field_types();
2231 let tys = tys.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2235 let el_ty = ty.element_type();
2236 let el_ty = self.type_to_str_depth(el_ty, depth-1);
2237 let len = ty.array_length();
2238 fmt!("[%s x %u]", el_ty, len)
2241 let el_ty = ty.element_type();
2242 let el_ty = self.type_to_str_depth(el_ty, depth-1);
2245 _ => fail!("Unknown Type Kind (%u)", kind as uint)
2250 pub fn type_to_str(&self, ty: Type) -> ~str {
2251 self.type_to_str_depth(ty, 30)
2254 pub fn val_to_str(&self, val: ValueRef) -> ~str {
2256 let ty = Type::from_ref(llvm::LLVMTypeOf(val));
2257 self.type_to_str(ty)
2263 /* Memory-managed interface to target data. */
2265 pub struct target_data_res {
2269 impl Drop for target_data_res {
2272 llvm::LLVMDisposeTargetData(self.TD);
2277 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
2283 pub struct TargetData {
2284 lltd: TargetDataRef,
2285 dtor: @target_data_res
2288 pub fn mk_target_data(string_rep: &str) -> TargetData {
2289 let lltd = do string_rep.as_c_str |buf| {
2290 unsafe { llvm::LLVMCreateTargetData(buf) }
2295 dtor: @target_data_res(lltd)
2299 /* Memory-managed interface to pass managers. */
2301 pub struct pass_manager_res {
2305 impl Drop for pass_manager_res {
2308 llvm::LLVMDisposePassManager(self.PM);
2313 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
2319 pub struct PassManager {
2320 llpm: PassManagerRef,
2321 dtor: @pass_manager_res
2324 pub fn mk_pass_manager() -> PassManager {
2326 let llpm = llvm::LLVMCreatePassManager();
2330 dtor: @pass_manager_res(llpm)
2335 /* Memory-managed interface to object files. */
2337 pub struct object_file_res {
2338 ObjectFile: ObjectFileRef,
2341 impl Drop for object_file_res {
2344 llvm::LLVMDisposeObjectFile(self.ObjectFile);
2349 pub fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
2355 pub struct ObjectFile {
2356 llof: ObjectFileRef,
2357 dtor: @object_file_res
2360 pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2362 let llof = llvm::LLVMCreateObjectFile(llmb);
2363 if llof as int == 0 { return option::None::<ObjectFile>; }
2365 option::Some(ObjectFile {
2367 dtor: @object_file_res(llof)
2372 /* Memory-managed interface to section iterators. */
2374 pub struct section_iter_res {
2375 SI: SectionIteratorRef,
2378 impl Drop for section_iter_res {
2381 llvm::LLVMDisposeSectionIterator(self.SI);
2386 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
2392 pub struct SectionIter {
2393 llsi: SectionIteratorRef,
2394 dtor: @section_iter_res
2397 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2399 let llsi = llvm::LLVMGetSections(llof);
2402 dtor: @section_iter_res(llsi)