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.
11 use core::hashmap::HashMap;
12 use core::libc::c_uint;
14 pub type Opcode = u32;
15 pub type Bool = c_uint;
17 pub static True: Bool = 1 as Bool;
18 pub static False: Bool = 0 as Bool;
20 // Consts for the LLVM CallConv type, pre-cast to uint.
26 X86StdcallCallConv = 64,
27 X86FastcallCallConv = 65,
31 LLVMDefaultVisibility = 0,
33 ProtectedVisibility = 2,
38 AvailableExternallyLinkage = 1,
39 LinkOnceAnyLinkage = 2,
40 LinkOnceODRLinkage = 3,
41 LinkOnceODRAutoHideLinkage = 4,
47 DLLImportLinkage = 10,
48 DLLExportLinkage = 11,
49 ExternalWeakLinkage = 12,
52 LinkerPrivateLinkage = 15,
53 LinkerPrivateWeakLinkage = 16,
59 NoReturnAttribute = 4,
61 StructRetAttribute = 16,
62 NoUnwindAttribute = 32,
63 NoAliasAttribute = 64,
66 ReadNoneAttribute = 512,
67 ReadOnlyAttribute = 1024,
68 NoInlineAttribute = 2048,
69 AlwaysInlineAttribute = 4096,
70 OptimizeForSizeAttribute = 8192,
71 StackProtectAttribute = 16384,
72 StackProtectReqAttribute = 32768,
74 AlignmentAttribute = 2031616,
75 NoCaptureAttribute = 2097152,
76 NoRedZoneAttribute = 4194304,
77 NoImplicitFloatAttribute = 8388608,
78 NakedAttribute = 16777216,
79 InlineHintAttribute = 33554432,
81 StackAttribute = 469762048,
82 ReturnsTwiceAttribute = 536870912,
84 UWTableAttribute = 1073741824,
85 NonLazyBindAttribute = 2147483648,
88 // enum for the LLVM IntPredicate type
89 pub enum IntPredicate {
102 // enum for the LLVM RealPredicate type
103 pub enum RealPredicate {
104 RealPredicateFalse = 0,
119 RealPredicateTrue = 15,
122 // The LLVM TypeKind type - must stay in sync with the def of
123 // LLVMTypeKind in llvm/include/llvm-c/Core.h
124 pub type TypeKind = u32;
125 pub static Void: TypeKind = 0;
126 pub static Half: TypeKind = 1;
127 pub static Float: TypeKind = 2;
128 pub static Double: TypeKind = 3;
129 pub static X86_FP80: TypeKind = 4;
130 pub static FP128: TypeKind = 5;
131 pub static PPC_FP128: TypeKind = 6;
132 pub static Label: TypeKind = 7;
133 pub static Integer: TypeKind = 8;
134 pub static Function: TypeKind = 9;
135 pub static Struct: TypeKind = 10;
136 pub static Array: TypeKind = 11;
137 pub static Pointer: TypeKind = 12;
138 pub static Vector: TypeKind = 13;
139 pub static Metadata: TypeKind = 14;
140 pub static X86_MMX: TypeKind = 15;
142 pub enum AtomicBinOp {
156 pub enum AtomicOrdering {
160 // Consume = 3, // Not specified yet.
164 SequentiallyConsistent = 7
167 // FIXME: Not used right now, but will be once #2334 is fixed
168 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
183 // Inline Asm Dialect
184 pub enum AsmDialect {
189 // Opaque pointer types
190 pub enum Module_opaque {}
191 pub type ModuleRef = *Module_opaque;
192 pub enum Context_opaque {}
193 pub type ContextRef = *Context_opaque;
194 pub enum Type_opaque {}
195 pub type TypeRef = *Type_opaque;
196 pub enum Value_opaque {}
197 pub type ValueRef = *Value_opaque;
198 pub enum BasicBlock_opaque {}
199 pub type BasicBlockRef = *BasicBlock_opaque;
200 pub enum Builder_opaque {}
201 pub type BuilderRef = *Builder_opaque;
202 pub enum MemoryBuffer_opaque {}
203 pub type MemoryBufferRef = *MemoryBuffer_opaque;
204 pub enum PassManager_opaque {}
205 pub type PassManagerRef = *PassManager_opaque;
206 pub enum PassManagerBuilder_opaque {}
207 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
208 pub enum Use_opaque {}
209 pub type UseRef = *Use_opaque;
210 pub enum TargetData_opaque {}
211 pub type TargetDataRef = *TargetData_opaque;
212 pub enum ObjectFile_opaque {}
213 pub type ObjectFileRef = *ObjectFile_opaque;
214 pub enum SectionIterator_opaque {}
215 pub type SectionIteratorRef = *SectionIterator_opaque;
218 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef};
219 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
220 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
221 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
222 use super::{ValueRef};
224 use core::libc::{c_char, c_int, c_longlong, c_uint, c_ulonglong};
226 #[link_args = "-Lrustllvm -lrustllvm"]
227 #[link_name = "rustllvm"]
230 /* Create and destroy contexts. */
232 pub unsafe fn LLVMContextCreate() -> ContextRef;
234 pub unsafe fn LLVMGetGlobalContext() -> ContextRef;
236 pub unsafe fn LLVMContextDispose(C: ContextRef);
238 pub unsafe fn LLVMGetMDKindIDInContext(C: ContextRef,
243 pub unsafe fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
245 /* Create and destroy modules. */
247 pub unsafe fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
251 pub unsafe fn LLVMDisposeModule(M: ModuleRef);
253 /** Data layout. See Module::getDataLayout. */
255 pub unsafe fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
257 pub unsafe fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
259 /** Target triple. See Module::getTargetTriple. */
261 pub unsafe fn LLVMGetTarget(M: ModuleRef) -> *c_char;
263 pub unsafe fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
265 /** See Module::dump. */
267 pub unsafe fn LLVMDumpModule(M: ModuleRef);
269 /** See Module::setModuleInlineAsm. */
271 pub unsafe fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
273 /** See llvm::LLVMTypeKind::getTypeID. */
274 pub unsafe fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
276 /** See llvm::LLVMType::getContext. */
278 pub unsafe fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
280 /* Operations on integer types */
282 pub unsafe fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
284 pub unsafe fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
286 pub unsafe fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
288 pub unsafe fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
290 pub unsafe fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
292 pub unsafe fn LLVMIntTypeInContext(C: ContextRef,
293 NumBits: c_uint) -> TypeRef;
296 pub unsafe fn LLVMInt1Type() -> TypeRef;
298 pub unsafe fn LLVMInt8Type() -> TypeRef;
300 pub unsafe fn LLVMInt16Type() -> TypeRef;
302 pub unsafe fn LLVMInt32Type() -> TypeRef;
304 pub unsafe fn LLVMInt64Type() -> TypeRef;
306 pub unsafe fn LLVMIntType(NumBits: c_uint) -> TypeRef;
308 pub unsafe fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
310 /* Operations on real types */
312 pub unsafe fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
314 pub unsafe fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
316 pub unsafe fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
318 pub unsafe fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
320 pub unsafe fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
323 pub unsafe fn LLVMFloatType() -> TypeRef;
325 pub unsafe fn LLVMDoubleType() -> TypeRef;
327 pub unsafe fn LLVMX86FP80Type() -> TypeRef;
329 pub unsafe fn LLVMFP128Type() -> TypeRef;
331 pub unsafe fn LLVMPPCFP128Type() -> TypeRef;
333 /* Operations on function types */
335 pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
336 ParamTypes: *TypeRef,
341 pub unsafe fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
343 pub unsafe fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
345 pub unsafe fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
347 pub unsafe fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
349 /* Operations on struct types */
351 pub unsafe fn LLVMStructTypeInContext(C: ContextRef,
352 ElementTypes: *TypeRef,
353 ElementCount: c_uint,
354 Packed: Bool) -> TypeRef;
356 pub unsafe fn LLVMStructType(ElementTypes: *TypeRef,
357 ElementCount: c_uint,
361 pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
364 pub unsafe fn LLVMGetStructElementTypes(StructTy: TypeRef,
367 pub unsafe fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
369 /* Operations on array, pointer, and vector types (sequence types) */
371 pub unsafe fn LLVMArrayType(ElementType: TypeRef,
372 ElementCount: c_uint) -> TypeRef;
374 pub unsafe fn LLVMPointerType(ElementType: TypeRef,
375 AddressSpace: c_uint) -> TypeRef;
377 pub unsafe fn LLVMVectorType(ElementType: TypeRef,
378 ElementCount: c_uint) -> TypeRef;
381 pub unsafe fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
383 pub unsafe fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
385 pub unsafe fn LLVMGetPointerAddressSpace(PointerTy: TypeRef)
388 pub unsafe fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
390 /* Operations on other types */
392 pub unsafe fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
394 pub unsafe fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
396 pub unsafe fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
399 pub unsafe fn LLVMVoidType() -> TypeRef;
401 pub unsafe fn LLVMLabelType() -> TypeRef;
403 pub unsafe fn LLVMMetadataType() -> TypeRef;
405 /* Operations on all values */
407 pub unsafe fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
409 pub unsafe fn LLVMGetValueName(Val: ValueRef) -> *c_char;
411 pub unsafe fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
413 pub unsafe fn LLVMDumpValue(Val: ValueRef);
415 pub unsafe fn LLVMReplaceAllUsesWith(OldVal: ValueRef,
418 pub unsafe fn LLVMHasMetadata(Val: ValueRef) -> c_int;
420 pub unsafe fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint)
423 pub unsafe fn LLVMSetMetadata(Val: ValueRef,
427 /* Operations on Uses */
429 pub unsafe fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
431 pub unsafe fn LLVMGetNextUse(U: UseRef) -> UseRef;
433 pub unsafe fn LLVMGetUser(U: UseRef) -> ValueRef;
435 pub unsafe fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
437 /* Operations on Users */
439 pub unsafe fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
441 pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint)
444 pub unsafe fn LLVMSetOperand(Val: ValueRef,
448 /* Operations on constants of any type */
450 pub unsafe fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
453 pub unsafe fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
454 /* only for int/vector */
456 pub unsafe fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
458 pub unsafe fn LLVMIsConstant(Val: ValueRef) -> Bool;
460 pub unsafe fn LLVMIsNull(Val: ValueRef) -> Bool;
462 pub unsafe fn LLVMIsUndef(Val: ValueRef) -> Bool;
464 pub unsafe fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
466 /* Operations on metadata */
468 pub unsafe fn LLVMMDStringInContext(C: ContextRef,
473 pub unsafe fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
475 pub unsafe fn LLVMMDNodeInContext(C: ContextRef,
480 pub unsafe fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
482 pub unsafe fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
485 /* Operations on scalar constants */
487 pub unsafe fn LLVMConstInt(IntTy: TypeRef,
492 pub unsafe fn LLVMConstIntOfString(IntTy: TypeRef,
497 pub unsafe fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
503 pub unsafe fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
505 pub unsafe fn LLVMConstRealOfString(RealTy: TypeRef,
509 pub unsafe fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
514 pub unsafe fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef)
517 pub unsafe fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef)
521 /* Operations on composite constants */
523 pub unsafe fn LLVMConstStringInContext(C: ContextRef,
526 DontNullTerminate: Bool)
529 pub unsafe fn LLVMConstStructInContext(C: ContextRef,
530 ConstantVals: *ValueRef,
532 Packed: Bool) -> ValueRef;
535 pub unsafe fn LLVMConstString(Str: *c_char,
537 DontNullTerminate: Bool)
540 pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
541 ConstantVals: *ValueRef,
545 pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
547 Packed: Bool) -> ValueRef;
549 pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
550 Size: c_uint) -> ValueRef;
552 /* Constant expressions */
554 pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
556 pub unsafe fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
558 pub unsafe fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
560 pub unsafe fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
562 pub unsafe fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
564 pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
566 pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
568 pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
569 RHSConstant: ValueRef)
572 pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
573 RHSConstant: ValueRef)
576 pub unsafe fn LLVMConstNUWAdd(LHSConstant: ValueRef,
577 RHSConstant: ValueRef)
580 pub unsafe fn LLVMConstFAdd(LHSConstant: ValueRef,
581 RHSConstant: ValueRef)
584 pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
585 RHSConstant: ValueRef)
588 pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
589 RHSConstant: ValueRef)
592 pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
593 RHSConstant: ValueRef)
596 pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
597 RHSConstant: ValueRef)
600 pub unsafe fn LLVMConstMul(LHSConstant: ValueRef,
601 RHSConstant: ValueRef)
604 pub unsafe fn LLVMConstNSWMul(LHSConstant: ValueRef,
605 RHSConstant: ValueRef)
608 pub unsafe fn LLVMConstNUWMul(LHSConstant: ValueRef,
609 RHSConstant: ValueRef)
612 pub unsafe fn LLVMConstFMul(LHSConstant: ValueRef,
613 RHSConstant: ValueRef)
616 pub unsafe fn LLVMConstUDiv(LHSConstant: ValueRef,
617 RHSConstant: ValueRef)
620 pub unsafe fn LLVMConstSDiv(LHSConstant: ValueRef,
621 RHSConstant: ValueRef)
624 pub unsafe fn LLVMConstExactSDiv(LHSConstant: ValueRef,
625 RHSConstant: ValueRef)
628 pub unsafe fn LLVMConstFDiv(LHSConstant: ValueRef,
629 RHSConstant: ValueRef)
632 pub unsafe fn LLVMConstURem(LHSConstant: ValueRef,
633 RHSConstant: ValueRef)
636 pub unsafe fn LLVMConstSRem(LHSConstant: ValueRef,
637 RHSConstant: ValueRef)
640 pub unsafe fn LLVMConstFRem(LHSConstant: ValueRef,
641 RHSConstant: ValueRef)
644 pub unsafe fn LLVMConstAnd(LHSConstant: ValueRef,
645 RHSConstant: ValueRef)
648 pub unsafe fn LLVMConstOr(LHSConstant: ValueRef,
649 RHSConstant: ValueRef)
652 pub unsafe fn LLVMConstXor(LHSConstant: ValueRef,
653 RHSConstant: ValueRef)
656 pub unsafe fn LLVMConstShl(LHSConstant: ValueRef,
657 RHSConstant: ValueRef)
660 pub unsafe fn LLVMConstLShr(LHSConstant: ValueRef,
661 RHSConstant: ValueRef) -> ValueRef;
663 pub unsafe fn LLVMConstAShr(LHSConstant: ValueRef,
664 RHSConstant: ValueRef) -> ValueRef;
666 pub unsafe fn LLVMConstGEP(ConstantVal: ValueRef,
667 ConstantIndices: *ValueRef,
668 NumIndices: c_uint) -> ValueRef;
670 pub unsafe fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
671 ConstantIndices: *ValueRef,
675 pub unsafe fn LLVMConstTrunc(ConstantVal: ValueRef,
679 pub unsafe fn LLVMConstSExt(ConstantVal: ValueRef,
683 pub unsafe fn LLVMConstZExt(ConstantVal: ValueRef,
687 pub unsafe fn LLVMConstFPTrunc(ConstantVal: ValueRef,
691 pub unsafe fn LLVMConstFPExt(ConstantVal: ValueRef,
695 pub unsafe fn LLVMConstUIToFP(ConstantVal: ValueRef,
699 pub unsafe fn LLVMConstSIToFP(ConstantVal: ValueRef,
703 pub unsafe fn LLVMConstFPToUI(ConstantVal: ValueRef,
707 pub unsafe fn LLVMConstFPToSI(ConstantVal: ValueRef,
711 pub unsafe fn LLVMConstPtrToInt(ConstantVal: ValueRef,
715 pub unsafe fn LLVMConstIntToPtr(ConstantVal: ValueRef,
719 pub unsafe fn LLVMConstBitCast(ConstantVal: ValueRef,
723 pub unsafe fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef,
727 pub unsafe fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef,
731 pub unsafe fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef,
735 pub unsafe fn LLVMConstPointerCast(ConstantVal: ValueRef,
739 pub unsafe fn LLVMConstIntCast(ConstantVal: ValueRef,
744 pub unsafe fn LLVMConstFPCast(ConstantVal: ValueRef,
748 pub unsafe fn LLVMConstSelect(ConstantCondition: ValueRef,
749 ConstantIfTrue: ValueRef,
750 ConstantIfFalse: ValueRef)
753 pub unsafe fn LLVMConstExtractElement(VectorConstant: ValueRef,
754 IndexConstant: ValueRef) -> ValueRef;
756 pub unsafe fn LLVMConstInsertElement(VectorConstant: ValueRef,
757 ElementValueConstant: ValueRef,
758 IndexConstant: ValueRef) -> ValueRef;
760 pub unsafe fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
761 VectorBConstant: ValueRef,
762 MaskConstant: ValueRef) -> ValueRef;
764 pub unsafe fn LLVMConstExtractValue(AggConstant: ValueRef,
766 NumIdx: c_uint) -> ValueRef;
768 pub unsafe fn LLVMConstInsertValue(AggConstant: ValueRef,
769 ElementValueConstant: ValueRef,
774 pub unsafe fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
775 Constraints: *c_char, HasSideEffects: Bool,
776 IsAlignStack: Bool) -> ValueRef;
778 pub unsafe fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef)
783 /* Operations on global variables, functions, and aliases (globals) */
785 pub unsafe fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
787 pub unsafe fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
789 pub unsafe fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
791 pub unsafe fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
793 pub unsafe fn LLVMGetSection(Global: ValueRef) -> *c_char;
795 pub unsafe fn LLVMSetSection(Global: ValueRef, Section: *c_char);
797 pub unsafe fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
799 pub unsafe fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
801 pub unsafe fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
803 pub unsafe fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
806 /* Operations on global variables */
808 pub unsafe fn LLVMAddGlobal(M: ModuleRef,
813 pub unsafe fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
816 AddressSpace: c_uint)
819 pub unsafe fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char)
822 pub unsafe fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
824 pub unsafe fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
826 pub unsafe fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
828 pub unsafe fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
830 pub unsafe fn LLVMDeleteGlobal(GlobalVar: ValueRef);
832 pub unsafe fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
834 pub unsafe fn LLVMSetInitializer(GlobalVar: ValueRef,
835 ConstantVal: ValueRef);
837 pub unsafe fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
839 pub unsafe fn LLVMSetThreadLocal(GlobalVar: ValueRef,
840 IsThreadLocal: Bool);
842 pub unsafe fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
844 pub unsafe fn LLVMSetGlobalConstant(GlobalVar: ValueRef,
847 /* Operations on aliases */
849 pub unsafe fn LLVMAddAlias(M: ModuleRef,
855 /* Operations on functions */
857 pub unsafe fn LLVMAddFunction(M: ModuleRef,
862 pub unsafe fn LLVMGetNamedFunction(M: ModuleRef,
863 Name: *c_char) -> ValueRef;
865 pub unsafe fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
867 pub unsafe fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
869 pub unsafe fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
871 pub unsafe fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
873 pub unsafe fn LLVMDeleteFunction(Fn: ValueRef);
875 pub unsafe fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
876 FunctionTy: TypeRef) -> ValueRef;
878 pub unsafe fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
880 pub unsafe fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
882 pub unsafe fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
884 pub unsafe fn LLVMGetGC(Fn: ValueRef) -> *c_char;
886 pub unsafe fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
888 pub unsafe fn LLVMAddFunctionAttr(Fn: ValueRef,
892 pub unsafe fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
894 pub unsafe fn LLVMRemoveFunctionAttr(Fn: ValueRef,
896 HighPA: c_ulonglong);
898 /* Operations on parameters */
900 pub unsafe fn LLVMCountParams(Fn: ValueRef) -> c_uint;
902 pub unsafe fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
904 pub unsafe fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
906 pub unsafe fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
908 pub unsafe fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
910 pub unsafe fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
912 pub unsafe fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
914 pub unsafe fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
916 pub unsafe fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
918 pub unsafe fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
920 pub unsafe fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
922 pub unsafe fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
924 /* Operations on basic blocks */
926 pub unsafe fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
928 pub unsafe fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
930 pub unsafe fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
932 pub unsafe fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
934 pub unsafe fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
936 pub unsafe fn LLVMGetBasicBlocks(Fn: ValueRef,
937 BasicBlocks: *ValueRef);
939 pub unsafe fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
941 pub unsafe fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
943 pub unsafe fn LLVMGetNextBasicBlock(BB: BasicBlockRef)
946 pub unsafe fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef)
949 pub unsafe fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
952 pub unsafe fn LLVMAppendBasicBlockInContext(C: ContextRef,
957 pub unsafe fn LLVMInsertBasicBlockInContext(C: ContextRef,
963 pub unsafe fn LLVMAppendBasicBlock(Fn: ValueRef,
967 pub unsafe fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef,
971 pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
973 /* Operations on instructions */
975 pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef)
978 pub unsafe fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
980 pub unsafe fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
982 pub unsafe fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
984 pub unsafe fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
986 /* Operations on call sites */
988 pub unsafe fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
990 pub unsafe fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
992 pub unsafe fn LLVMAddInstrAttribute(Instr: ValueRef,
996 pub unsafe fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1000 pub unsafe fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1004 /* Operations on call instructions (only) */
1006 pub unsafe fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1008 pub unsafe fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1010 /* Operations on phi nodes */
1012 pub unsafe fn LLVMAddIncoming(PhiNode: ValueRef,
1013 IncomingValues: *ValueRef,
1014 IncomingBlocks: *BasicBlockRef,
1017 pub unsafe fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1019 pub unsafe fn LLVMGetIncomingValue(PhiNode: ValueRef,
1023 pub unsafe fn LLVMGetIncomingBlock(PhiNode: ValueRef,
1024 Index: c_uint) -> BasicBlockRef;
1026 /* Instruction builders */
1028 pub unsafe fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1030 pub unsafe fn LLVMCreateBuilder() -> BuilderRef;
1032 pub unsafe fn LLVMPositionBuilder(Builder: BuilderRef,
1033 Block: BasicBlockRef,
1036 pub unsafe fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1039 pub unsafe fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1040 Block: BasicBlockRef);
1042 pub unsafe fn LLVMGetInsertBlock(Builder: BuilderRef)
1045 pub unsafe fn LLVMClearInsertionPosition(Builder: BuilderRef);
1047 pub unsafe fn LLVMInsertIntoBuilder(Builder: BuilderRef,
1050 pub unsafe fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1054 pub unsafe fn LLVMDisposeBuilder(Builder: BuilderRef);
1058 pub unsafe fn LLVMSetCurrentDebugLocation(Builder: BuilderRef,
1061 pub unsafe fn LLVMGetCurrentDebugLocation(Builder: BuilderRef)
1064 pub unsafe fn LLVMSetInstDebugLocation(Builder: BuilderRef,
1069 pub unsafe fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1071 pub unsafe fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1073 pub unsafe fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
1074 N: c_uint) -> ValueRef;
1076 pub unsafe fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef)
1079 pub unsafe fn LLVMBuildCondBr(B: BuilderRef,
1081 Then: BasicBlockRef,
1082 Else: BasicBlockRef)
1085 pub unsafe fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef,
1086 Else: BasicBlockRef, NumCases: c_uint)
1089 pub unsafe fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef,
1090 NumDests: c_uint) -> ValueRef;
1092 pub unsafe fn LLVMBuildInvoke(B: BuilderRef,
1096 Then: BasicBlockRef,
1097 Catch: BasicBlockRef,
1098 Name: *c_char) -> ValueRef;
1100 pub unsafe fn LLVMBuildLandingPad(B: BuilderRef,
1107 pub unsafe fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef)
1110 pub unsafe fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1112 /* Add a case to the switch instruction */
1114 pub unsafe fn LLVMAddCase(Switch: ValueRef,
1116 Dest: BasicBlockRef);
1118 /* Add a destination to the indirectbr instruction */
1120 pub unsafe fn LLVMAddDestination(IndirectBr: ValueRef,
1121 Dest: BasicBlockRef);
1123 /* Add a clause to the landing pad instruction */
1125 pub unsafe fn LLVMAddClause(LandingPad: ValueRef,
1126 ClauseVal: ValueRef);
1128 /* Set the cleanup on a landing pad instruction */
1130 pub unsafe fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1134 pub unsafe fn LLVMBuildAdd(B: BuilderRef,
1140 pub unsafe fn LLVMBuildNSWAdd(B: BuilderRef,
1146 pub unsafe fn LLVMBuildNUWAdd(B: BuilderRef,
1152 pub unsafe fn LLVMBuildFAdd(B: BuilderRef,
1158 pub unsafe fn LLVMBuildSub(B: BuilderRef,
1164 pub unsafe fn LLVMBuildNSWSub(B: BuilderRef,
1170 pub unsafe fn LLVMBuildNUWSub(B: BuilderRef,
1176 pub unsafe fn LLVMBuildFSub(B: BuilderRef,
1182 pub unsafe fn LLVMBuildMul(B: BuilderRef,
1188 pub unsafe fn LLVMBuildNSWMul(B: BuilderRef,
1194 pub unsafe fn LLVMBuildNUWMul(B: BuilderRef,
1200 pub unsafe fn LLVMBuildFMul(B: BuilderRef,
1206 pub unsafe fn LLVMBuildUDiv(B: BuilderRef,
1212 pub unsafe fn LLVMBuildSDiv(B: BuilderRef,
1218 pub unsafe fn LLVMBuildExactSDiv(B: BuilderRef,
1224 pub unsafe fn LLVMBuildFDiv(B: BuilderRef,
1230 pub unsafe fn LLVMBuildURem(B: BuilderRef,
1236 pub unsafe fn LLVMBuildSRem(B: BuilderRef,
1242 pub unsafe fn LLVMBuildFRem(B: BuilderRef,
1248 pub unsafe fn LLVMBuildShl(B: BuilderRef,
1254 pub unsafe fn LLVMBuildLShr(B: BuilderRef,
1260 pub unsafe fn LLVMBuildAShr(B: BuilderRef,
1266 pub unsafe fn LLVMBuildAnd(B: BuilderRef,
1272 pub unsafe fn LLVMBuildOr(B: BuilderRef,
1278 pub unsafe fn LLVMBuildXor(B: BuilderRef,
1284 pub unsafe fn LLVMBuildBinOp(B: BuilderRef,
1291 pub unsafe fn LLVMBuildNeg(B: BuilderRef,
1296 pub unsafe fn LLVMBuildNSWNeg(B: BuilderRef,
1301 pub unsafe fn LLVMBuildNUWNeg(B: BuilderRef,
1306 pub unsafe fn LLVMBuildFNeg(B: BuilderRef,
1311 pub unsafe fn LLVMBuildNot(B: BuilderRef,
1318 pub unsafe fn LLVMBuildMalloc(B: BuilderRef,
1323 pub unsafe fn LLVMBuildArrayMalloc(B: BuilderRef,
1326 Name: *c_char) -> ValueRef;
1328 pub unsafe fn LLVMBuildAlloca(B: BuilderRef,
1333 pub unsafe fn LLVMBuildArrayAlloca(B: BuilderRef,
1336 Name: *c_char) -> ValueRef;
1338 pub unsafe fn LLVMBuildFree(B: BuilderRef,
1339 PointerVal: ValueRef) -> ValueRef;
1341 pub unsafe fn LLVMBuildLoad(B: BuilderRef,
1342 PointerVal: ValueRef,
1346 pub unsafe fn LLVMBuildStore(B: BuilderRef,
1348 Ptr: ValueRef) -> ValueRef;
1350 pub unsafe fn LLVMBuildGEP(B: BuilderRef,
1357 pub unsafe fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
1358 Indices: *ValueRef, NumIndices: c_uint,
1362 pub unsafe fn LLVMBuildStructGEP(B: BuilderRef,
1368 pub unsafe fn LLVMBuildGlobalString(B: BuilderRef,
1373 pub unsafe fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1380 pub unsafe fn LLVMBuildTrunc(B: BuilderRef,
1383 Name: *c_char) -> ValueRef;
1385 pub unsafe fn LLVMBuildZExt(B: BuilderRef,
1391 pub unsafe fn LLVMBuildSExt(B: BuilderRef,
1397 pub unsafe fn LLVMBuildFPToUI(B: BuilderRef,
1400 Name: *c_char) -> ValueRef;
1402 pub unsafe fn LLVMBuildFPToSI(B: BuilderRef,
1405 Name: *c_char) -> ValueRef;
1407 pub unsafe fn LLVMBuildUIToFP(B: BuilderRef,
1410 Name: *c_char) -> ValueRef;
1412 pub unsafe fn LLVMBuildSIToFP(B: BuilderRef,
1415 Name: *c_char) -> ValueRef;
1417 pub unsafe fn LLVMBuildFPTrunc(B: BuilderRef,
1420 Name: *c_char) -> ValueRef;
1422 pub unsafe fn LLVMBuildFPExt(B: BuilderRef,
1425 Name: *c_char) -> ValueRef;
1427 pub unsafe fn LLVMBuildPtrToInt(B: BuilderRef,
1430 Name: *c_char) -> ValueRef;
1432 pub unsafe fn LLVMBuildIntToPtr(B: BuilderRef,
1435 Name: *c_char) -> ValueRef;
1437 pub unsafe fn LLVMBuildBitCast(B: BuilderRef,
1440 Name: *c_char) -> ValueRef;
1442 pub unsafe fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1448 pub unsafe fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1454 pub unsafe fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1460 pub unsafe fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
1461 DestTy: TypeRef, Name: *c_char) -> ValueRef;
1463 pub unsafe fn LLVMBuildPointerCast(B: BuilderRef,
1469 pub unsafe fn LLVMBuildIntCast(B: BuilderRef,
1472 Name: *c_char) -> ValueRef;
1474 pub unsafe fn LLVMBuildFPCast(B: BuilderRef,
1477 Name: *c_char) -> ValueRef;
1481 pub unsafe fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1482 RHS: ValueRef, Name: *c_char) -> ValueRef;
1484 pub unsafe fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1485 RHS: ValueRef, Name: *c_char) -> ValueRef;
1487 /* Miscellaneous instructions */
1489 pub unsafe fn LLVMBuildPhi(B: BuilderRef,
1494 pub unsafe fn LLVMBuildCall(B: BuilderRef,
1501 pub unsafe fn LLVMBuildSelect(B: BuilderRef,
1508 pub unsafe fn LLVMBuildVAArg(B: BuilderRef,
1514 pub unsafe fn LLVMBuildExtractElement(B: BuilderRef,
1520 pub unsafe fn LLVMBuildInsertElement(B: BuilderRef,
1527 pub unsafe fn LLVMBuildShuffleVector(B: BuilderRef,
1534 pub unsafe fn LLVMBuildExtractValue(B: BuilderRef,
1540 pub unsafe fn LLVMBuildInsertValue(B: BuilderRef,
1548 pub unsafe fn LLVMBuildIsNull(B: BuilderRef,
1553 pub unsafe fn LLVMBuildIsNotNull(B: BuilderRef,
1558 pub unsafe fn LLVMBuildPtrDiff(B: BuilderRef,
1561 Name: *c_char) -> ValueRef;
1563 /* Atomic Operations */
1564 pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef, LHS: ValueRef,
1565 CMP: ValueRef, RHS: ValueRef,
1566 ++Order: AtomicOrdering) -> ValueRef;
1567 pub unsafe fn LLVMBuildAtomicRMW(B: BuilderRef, ++Op: AtomicBinOp,
1568 LHS: ValueRef, RHS: ValueRef,
1569 ++Order: AtomicOrdering) -> ValueRef;
1571 /* Selected entries from the downcasts. */
1573 pub unsafe fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1575 /** Writes a module to the specified path. Returns 0 on success. */
1577 pub unsafe fn LLVMWriteBitcodeToFile(M: ModuleRef,
1578 Path: *c_char) -> c_int;
1580 /** Creates target data from a target layout string. */
1582 pub unsafe fn LLVMCreateTargetData(StringRep: *c_char)
1584 /** Adds the target data to the given pass manager. The pass manager
1585 references the target data only weakly. */
1587 pub unsafe fn LLVMAddTargetData(TD: TargetDataRef,
1588 PM: PassManagerRef);
1589 /** Number of bytes clobbered when doing a Store to *T. */
1591 pub unsafe fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1594 /** Number of bytes clobbered when doing a Store to *T. */
1596 pub unsafe fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1599 /** Distance between successive elements in an array of T.
1600 Includes ABI padding. */
1602 pub unsafe fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef)
1605 /** Returns the preferred alignment of a type. */
1607 pub unsafe fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
1608 Ty: TypeRef) -> c_uint;
1609 /** Returns the minimum alignment of a type. */
1611 pub unsafe fn LLVMABIAlignmentOfType(TD: TargetDataRef,
1612 Ty: TypeRef) -> c_uint;
1614 * Returns the minimum alignment of a type when part of a call frame.
1617 pub unsafe fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
1621 /** Disposes target data. */
1623 pub unsafe fn LLVMDisposeTargetData(TD: TargetDataRef);
1625 /** Creates a pass manager. */
1627 pub unsafe fn LLVMCreatePassManager() -> PassManagerRef;
1628 /** Disposes a pass manager. */
1630 pub unsafe fn LLVMDisposePassManager(PM: PassManagerRef);
1631 /** Runs a pass manager on a module. */
1633 pub unsafe fn LLVMRunPassManager(PM: PassManagerRef,
1634 M: ModuleRef) -> Bool;
1636 /** Adds a verification pass. */
1638 pub unsafe fn LLVMAddVerifierPass(PM: PassManagerRef);
1641 pub unsafe fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1643 pub unsafe fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1645 pub unsafe fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1647 pub unsafe fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1649 pub unsafe fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1651 pub unsafe fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1653 pub unsafe fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1655 pub unsafe fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1657 pub unsafe fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1659 pub unsafe fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1661 pub unsafe fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1663 pub unsafe fn LLVMAddReassociatePass(PM: PassManagerRef);
1665 pub unsafe fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1667 pub unsafe fn LLVMAddLICMPass(PM: PassManagerRef);
1669 pub unsafe fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1671 pub unsafe fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1673 pub unsafe fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1675 pub unsafe fn LLVMAddGVNPass(PM: PassManagerRef);
1677 pub unsafe fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1679 pub unsafe fn LLVMAddSCCPPass(PM: PassManagerRef);
1681 pub unsafe fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1683 pub unsafe fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1685 pub unsafe fn LLVMAddConstantMergePass(PM: PassManagerRef);
1687 pub unsafe fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1689 pub unsafe fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1691 pub unsafe fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1693 pub unsafe fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1695 pub unsafe fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1697 pub unsafe fn LLVMAddCorrelatedValuePropagationPass(PM:
1700 pub unsafe fn LLVMAddPruneEHPass(PM: PassManagerRef);
1702 pub unsafe fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1704 pub unsafe fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1706 pub unsafe fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1708 pub unsafe fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1710 pub unsafe fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1713 pub unsafe fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1715 pub unsafe fn LLVMPassManagerBuilderDispose(PMB:
1716 PassManagerBuilderRef);
1718 pub unsafe fn LLVMPassManagerBuilderSetOptLevel(
1719 PMB: PassManagerBuilderRef, OptimizationLevel: c_uint);
1721 pub unsafe fn LLVMPassManagerBuilderSetSizeLevel(
1722 PMB: PassManagerBuilderRef, Value: Bool);
1724 pub unsafe fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1725 PMB: PassManagerBuilderRef, Value: Bool);
1727 pub unsafe fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1728 PMB: PassManagerBuilderRef, Value: Bool);
1730 pub unsafe fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
1731 (PMB: PassManagerBuilderRef, Value: Bool);
1733 pub unsafe fn LLVMPassManagerBuilderUseInlinerWithThreshold
1734 (PMB: PassManagerBuilderRef, threshold: c_uint);
1736 pub unsafe fn LLVMPassManagerBuilderPopulateModulePassManager
1737 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1740 pub unsafe fn LLVMPassManagerBuilderPopulateFunctionPassManager
1741 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1743 /** Destroys a memory buffer. */
1745 pub unsafe fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1748 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1750 /** Opens an object file. */
1752 pub unsafe fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef)
1754 /** Closes an object file. */
1756 pub unsafe fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1758 /** Enumerates the sections in an object file. */
1760 pub unsafe fn LLVMGetSections(ObjFile: ObjectFileRef)
1761 -> SectionIteratorRef;
1762 /** Destroys a section iterator. */
1764 pub unsafe fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1765 /** Returns true if the section iterator is at the end of the section
1768 pub unsafe fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1769 SI: SectionIteratorRef) -> Bool;
1770 /** Moves the section iterator to point to the next section. */
1772 pub unsafe fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1773 /** Returns the current section name. */
1775 pub unsafe fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1776 /** Returns the current section size. */
1778 pub unsafe fn LLVMGetSectionSize(SI: SectionIteratorRef)
1780 /** Returns the current section contents as a string buffer. */
1782 pub unsafe fn LLVMGetSectionContents(SI: SectionIteratorRef)
1785 /** Reads the given file and returns it as a memory buffer. Use
1786 LLVMDisposeMemoryBuffer() to get rid of it. */
1788 pub unsafe fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1793 pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
1798 // FIXME: When #2334 is fixed,
1799 // change c_uint to FileType
1802 EnableSegmentedStacks: bool)
1805 /** Returns a string describing the last error caused by an LLVMRust*
1808 pub unsafe fn LLVMRustGetLastError() -> *c_char;
1810 /** Prepare the JIT. Returns a memory manager that can load crates. */
1812 pub unsafe fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1814 /** Load a crate into the memory manager. */
1816 pub unsafe fn LLVMRustLoadCrate(MM: *(),
1820 /** Execute the JIT engine. */
1822 pub unsafe fn LLVMRustExecuteJIT(MM: *(),
1826 EnableSegmentedStacks: bool) -> *();
1828 /** Parses the bitcode in the given memory buffer. */
1830 pub unsafe fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef)
1833 /** Parses LLVM asm in the given file */
1835 pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char)
1839 pub unsafe fn LLVMRustAddPrintModulePass(PM: PassManagerRef,
1843 /** Turn on LLVM pass-timing. */
1845 pub unsafe fn LLVMRustEnableTimePasses();
1847 /// Print the pass timings since static dtors aren't picking them up.
1849 pub unsafe fn LLVMRustPrintPassTimings();
1852 pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
1856 pub unsafe fn LLVMStructSetBody(StructTy: TypeRef,
1857 ElementTypes: *TypeRef,
1858 ElementCount: c_uint,
1862 pub unsafe fn LLVMConstNamedStruct(S: TypeRef,
1863 ConstantVals: *ValueRef,
1867 /** Enables LLVM debug output. */
1869 pub unsafe fn LLVMSetDebug(Enabled: c_int);
1871 /** Prepares inline assembly. */
1873 pub unsafe fn LLVMInlineAsm(Ty: TypeRef, AsmString: *c_char,
1874 Constraints: *c_char, SideEffects: Bool,
1875 AlignStack: Bool, Dialect: c_uint)
1880 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
1882 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
1885 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
1887 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
1890 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
1892 llvm::LLVMSetLinkage(Global, Link as c_uint);
1896 /* Memory-managed object interface to type handles. */
1898 pub struct TypeNames {
1899 type_names: @mut HashMap<TypeRef, @str>,
1900 named_types: @mut HashMap<@str, TypeRef>
1903 pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
1904 assert!(tn.type_names.insert(t, s));
1905 assert!(tn.named_types.insert(s, t));
1908 pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {
1909 return tn.type_names.find(&t).map_consume(|x| *x);
1912 pub fn name_has_type(tn: @TypeNames, s: @str) -> Option<TypeRef> {
1913 return tn.named_types.find(&s).map_consume(|x| *x);
1916 pub fn mk_type_names() -> @TypeNames {
1918 type_names: @mut HashMap::new(),
1919 named_types: @mut HashMap::new()
1923 pub fn type_to_str(names: @TypeNames, ty: TypeRef) -> @str {
1924 return type_to_str_inner(names, [], ty);
1927 pub fn type_to_str_inner(names: @TypeNames, outer0: &[TypeRef], ty: TypeRef)
1930 match type_has_name(names, ty) {
1931 option::Some(n) => return n,
1935 let outer = vec::append_one(outer0.to_vec(), ty);
1937 let kind = llvm::LLVMGetTypeKind(ty);
1939 fn tys_str(names: @TypeNames, outer: &[TypeRef],
1940 tys: ~[TypeRef]) -> @str {
1942 let mut first: bool = true;
1944 if first { first = false; } else { s += ~", "; }
1945 s += type_to_str_inner(names, outer, *t).to_owned();
1947 // [Note at-str] FIXME #2543: Could rewrite this without the copy,
1948 // but need better @str support.
1949 return s.to_managed();
1953 Void => return @"Void",
1954 Half => return @"Half",
1955 Float => return @"Float",
1956 Double => return @"Double",
1957 X86_FP80 => return @"X86_FP80",
1958 FP128 => return @"FP128",
1959 PPC_FP128 => return @"PPC_FP128",
1960 Label => return @"Label",
1962 // See [Note at-str]
1963 return fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty)
1964 as int).to_managed();
1967 let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
1968 let n_args = llvm::LLVMCountParamTypes(ty) as uint;
1969 let args = vec::from_elem(n_args, 0 as TypeRef);
1971 llvm::LLVMGetParamTypes(ty, vec::raw::to_ptr(args));
1973 // See [Note at-str]
1974 return fmt!("fn(%s) -> %s",
1975 tys_str(names, outer, args),
1976 type_to_str_inner(names, outer, out_ty)).to_managed();
1979 let elts = struct_tys(ty);
1980 // See [Note at-str]
1981 return fmt!("{%s}", tys_str(names, outer, elts)).to_managed();
1984 let el_ty = llvm::LLVMGetElementType(ty);
1985 // See [Note at-str]
1986 return fmt!("[%s@ x %u", type_to_str_inner(names, outer, el_ty),
1987 llvm::LLVMGetArrayLength(ty) as uint).to_managed();
1991 for outer0.each |tout| {
1993 if *tout as int == ty as int {
1994 let n = outer0.len() - i;
1995 // See [Note at-str]
1996 return fmt!("*\\%d", n as int).to_managed();
2000 let addrspace = llvm::LLVMGetPointerAddressSpace(ty) as uint;
2004 fmt!("addrspace(%u)", addrspace)
2007 // See [Note at-str]
2008 return fmt!("%s*%s", addrstr, type_to_str_inner(names,
2010 llvm::LLVMGetElementType(ty))).to_managed();
2012 Vector => return @"Vector",
2013 Metadata => return @"Metadata",
2014 X86_MMX => return @"X86_MMAX",
2020 pub fn float_width(llt: TypeRef) -> uint {
2022 return match llvm::LLVMGetTypeKind(llt) as int {
2027 _ => fail!(~"llvm_float_width called on a non-float type")
2032 pub fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] {
2034 let args = vec::from_elem(llvm::LLVMCountParamTypes(fn_ty) as uint,
2036 llvm::LLVMGetParamTypes(fn_ty, vec::raw::to_ptr(args));
2041 pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] {
2043 let n_elts = llvm::LLVMCountStructElementTypes(struct_ty) as uint;
2047 let mut elts = vec::from_elem(n_elts, ptr::null());
2048 llvm::LLVMGetStructElementTypes(
2049 struct_ty, ptr::to_mut_unsafe_ptr(&mut elts[0]));
2055 /* Memory-managed interface to target data. */
2057 pub struct target_data_res {
2061 impl Drop for target_data_res {
2062 fn finalize(&self) {
2064 llvm::LLVMDisposeTargetData(self.TD);
2069 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
2075 pub struct TargetData {
2076 lltd: TargetDataRef,
2077 dtor: @target_data_res
2080 pub fn mk_target_data(string_rep: &str) -> TargetData {
2082 str::as_c_str(string_rep, |buf| unsafe {
2083 llvm::LLVMCreateTargetData(buf)
2088 dtor: @target_data_res(lltd)
2092 /* Memory-managed interface to pass managers. */
2094 pub struct pass_manager_res {
2098 impl Drop for pass_manager_res {
2099 fn finalize(&self) {
2101 llvm::LLVMDisposePassManager(self.PM);
2106 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
2112 pub struct PassManager {
2113 llpm: PassManagerRef,
2114 dtor: @pass_manager_res
2117 pub fn mk_pass_manager() -> PassManager {
2119 let llpm = llvm::LLVMCreatePassManager();
2123 dtor: @pass_manager_res(llpm)
2128 /* Memory-managed interface to object files. */
2130 pub struct object_file_res {
2131 ObjectFile: ObjectFileRef,
2134 impl Drop for object_file_res {
2135 fn finalize(&self) {
2137 llvm::LLVMDisposeObjectFile(self.ObjectFile);
2142 pub fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
2148 pub struct ObjectFile {
2149 llof: ObjectFileRef,
2150 dtor: @object_file_res
2153 pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2155 let llof = llvm::LLVMCreateObjectFile(llmb);
2156 if llof as int == 0 { return option::None::<ObjectFile>; }
2158 option::Some(ObjectFile {
2160 dtor: @object_file_res(llof)
2165 /* Memory-managed interface to section iterators. */
2167 pub struct section_iter_res {
2168 SI: SectionIteratorRef,
2171 impl Drop for section_iter_res {
2172 fn finalize(&self) {
2174 llvm::LLVMDisposeSectionIterator(self.SI);
2179 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
2185 pub struct SectionIter {
2186 llsi: SectionIteratorRef,
2187 dtor: @section_iter_res
2190 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2192 let llsi = llvm::LLVMGetSections(llof);
2195 dtor: @section_iter_res(llsi)
2204 // indent-tabs-mode: nil
2205 // c-basic-offset: 4
2206 // buffer-file-coding-system: utf-8-unix