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 std::c_str::ToCStr;
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,
62 ZExtAttribute = 1 << 0,
63 SExtAttribute = 1 << 1,
64 NoReturnAttribute = 1 << 2,
65 InRegAttribute = 1 << 3,
66 StructRetAttribute = 1 << 4,
67 NoUnwindAttribute = 1 << 5,
68 NoAliasAttribute = 1 << 6,
69 ByValAttribute = 1 << 7,
70 NestAttribute = 1 << 8,
71 ReadNoneAttribute = 1 << 9,
72 ReadOnlyAttribute = 1 << 10,
73 NoInlineAttribute = 1 << 11,
74 AlwaysInlineAttribute = 1 << 12,
75 OptimizeForSizeAttribute = 1 << 13,
76 StackProtectAttribute = 1 << 14,
77 StackProtectReqAttribute = 1 << 15,
78 AlignmentAttribute = 31 << 16,
79 NoCaptureAttribute = 1 << 21,
80 NoRedZoneAttribute = 1 << 22,
81 NoImplicitFloatAttribute = 1 << 23,
82 NakedAttribute = 1 << 24,
83 InlineHintAttribute = 1 << 25,
84 StackAttribute = 7 << 26,
85 ReturnsTwiceAttribute = 1 << 29,
86 UWTableAttribute = 1 << 30,
87 NonLazyBindAttribute = 1 << 31,
89 // Not added to LLVM yet, so may need to stay updated if LLVM changes.
90 // FIXME(#8199): if this changes, be sure to change the relevant constant
92 // FixedStackSegment = 1 << 41,
95 // enum for the LLVM IntPredicate type
96 pub enum IntPredicate {
109 // enum for the LLVM RealPredicate type
110 pub enum RealPredicate {
111 RealPredicateFalse = 0,
126 RealPredicateTrue = 15,
129 // The LLVM TypeKind type - must stay in sync with the def of
130 // LLVMTypeKind in llvm/include/llvm-c/Core.h
131 pub type TypeKind = u32;
132 pub static Void: TypeKind = 0;
133 pub static Half: TypeKind = 1;
134 pub static Float: TypeKind = 2;
135 pub static Double: TypeKind = 3;
136 pub static X86_FP80: TypeKind = 4;
137 pub static FP128: TypeKind = 5;
138 pub static PPC_FP128: TypeKind = 6;
139 pub static Label: TypeKind = 7;
140 pub static Integer: TypeKind = 8;
141 pub static Function: TypeKind = 9;
142 pub static Struct: TypeKind = 10;
143 pub static Array: TypeKind = 11;
144 pub static Pointer: TypeKind = 12;
145 pub static Vector: TypeKind = 13;
146 pub static Metadata: TypeKind = 14;
147 pub static X86_MMX: TypeKind = 15;
149 pub enum AtomicBinOp {
163 pub enum AtomicOrdering {
167 // Consume = 3, // Not specified yet.
171 SequentiallyConsistent = 7
174 // FIXME: Not used right now, but will be once #2334 is fixed
175 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
190 // Inline Asm Dialect
191 pub enum AsmDialect {
196 // Opaque pointer types
197 pub enum Module_opaque {}
198 pub type ModuleRef = *Module_opaque;
199 pub enum Context_opaque {}
200 pub type ContextRef = *Context_opaque;
201 pub enum Type_opaque {}
202 pub type TypeRef = *Type_opaque;
203 pub enum Value_opaque {}
204 pub type ValueRef = *Value_opaque;
205 pub enum BasicBlock_opaque {}
206 pub type BasicBlockRef = *BasicBlock_opaque;
207 pub enum Builder_opaque {}
208 pub type BuilderRef = *Builder_opaque;
209 pub enum ExecutionEngine_opaque {}
210 pub type ExecutionEngineRef = *ExecutionEngine_opaque;
211 pub enum MemoryBuffer_opaque {}
212 pub type MemoryBufferRef = *MemoryBuffer_opaque;
213 pub enum PassManager_opaque {}
214 pub type PassManagerRef = *PassManager_opaque;
215 pub enum PassManagerBuilder_opaque {}
216 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
217 pub enum Use_opaque {}
218 pub type UseRef = *Use_opaque;
219 pub enum TargetData_opaque {}
220 pub type TargetDataRef = *TargetData_opaque;
221 pub enum ObjectFile_opaque {}
222 pub type ObjectFileRef = *ObjectFile_opaque;
223 pub enum SectionIterator_opaque {}
224 pub type SectionIteratorRef = *SectionIterator_opaque;
225 pub enum Pass_opaque {}
226 pub type PassRef = *Pass_opaque;
229 use super::{ValueRef};
231 pub enum DIBuilder_opaque {}
232 pub type DIBuilderRef = *DIBuilder_opaque;
234 pub type DIDescriptor = ValueRef;
235 pub type DIScope = DIDescriptor;
236 pub type DILocation = DIDescriptor;
237 pub type DIFile = DIScope;
238 pub type DILexicalBlock = DIScope;
239 pub type DISubprogram = DIScope;
240 pub type DIType = DIDescriptor;
241 pub type DIBasicType = DIType;
242 pub type DIDerivedType = DIType;
243 pub type DICompositeType = DIDerivedType;
244 pub type DIVariable = DIDescriptor;
245 pub type DIArray = DIDescriptor;
246 pub type DISubrange = DIDescriptor;
248 pub enum DIDescriptorFlags {
249 FlagPrivate = 1 << 0,
250 FlagProtected = 1 << 1,
251 FlagFwdDecl = 1 << 2,
252 FlagAppleBlock = 1 << 3,
253 FlagBlockByrefStruct = 1 << 4,
254 FlagVirtual = 1 << 5,
255 FlagArtificial = 1 << 6,
256 FlagExplicit = 1 << 7,
257 FlagPrototyped = 1 << 8,
258 FlagObjcClassComplete = 1 << 9,
259 FlagObjectPointer = 1 << 10,
260 FlagVector = 1 << 11,
261 FlagStaticMember = 1 << 12
266 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
267 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
268 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
269 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
270 use super::{ValueRef, PassRef};
271 use super::debuginfo::*;
272 use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};
274 #[link_args = "-Lrustllvm -lrustllvm"]
275 #[link_name = "rustllvm"]
278 /* Create and destroy contexts. */
280 pub fn LLVMContextCreate() -> ContextRef;
282 pub fn LLVMContextDispose(C: ContextRef);
284 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
289 /* Create and destroy modules. */
291 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
295 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
297 pub fn LLVMDisposeModule(M: ModuleRef);
299 /** Data layout. See Module::getDataLayout. */
301 pub fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
303 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
305 /** Target triple. See Module::getTargetTriple. */
307 pub fn LLVMGetTarget(M: ModuleRef) -> *c_char;
309 pub fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
311 /** See Module::dump. */
313 pub fn LLVMDumpModule(M: ModuleRef);
315 /** See Module::setModuleInlineAsm. */
317 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
319 /** See llvm::LLVMTypeKind::getTypeID. */
320 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
322 /** See llvm::LLVMType::getContext. */
324 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
326 /* Operations on integer types */
328 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
330 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
332 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
334 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
336 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
338 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
342 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
344 /* Operations on real types */
346 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
348 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
350 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
352 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
354 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
356 /* Operations on function types */
358 pub fn LLVMFunctionType(ReturnType: TypeRef,
359 ParamTypes: *TypeRef,
364 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
366 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
368 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
370 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
372 /* Operations on struct types */
374 pub fn LLVMStructTypeInContext(C: ContextRef,
375 ElementTypes: *TypeRef,
376 ElementCount: c_uint,
380 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
382 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
385 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
387 /* Operations on array, pointer, and vector types (sequence types) */
389 pub fn LLVMArrayType(ElementType: TypeRef, ElementCount: c_uint)
392 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
395 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
399 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
401 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
403 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
405 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
408 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
410 /* Operations on other types */
412 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
414 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
416 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
418 /* Operations on all values */
420 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
422 pub fn LLVMGetValueName(Val: ValueRef) -> *c_char;
424 pub fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
426 pub fn LLVMDumpValue(Val: ValueRef);
428 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
430 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
432 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
434 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
436 /* Operations on Uses */
438 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
440 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
442 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
444 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
446 /* Operations on Users */
448 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
450 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
452 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
454 /* Operations on constants of any type */
456 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
459 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
461 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
464 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
466 /* only for int/vector */
468 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
470 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
472 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
474 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
476 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
478 /* Operations on metadata */
480 pub fn LLVMMDStringInContext(C: ContextRef,
485 pub fn LLVMMDNodeInContext(C: ContextRef,
490 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
494 /* Operations on scalar constants */
496 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
499 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8)
502 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
508 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
510 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char)
513 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
518 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
520 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
523 /* Operations on composite constants */
525 pub fn LLVMConstStringInContext(C: ContextRef,
528 DontNullTerminate: Bool)
531 pub fn LLVMConstStructInContext(C: ContextRef,
532 ConstantVals: *ValueRef,
538 pub fn LLVMConstArray(ElementTy: TypeRef,
539 ConstantVals: *ValueRef,
543 pub fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: c_uint)
546 /* Constant expressions */
548 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
550 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
552 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
554 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
556 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
558 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
560 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
562 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
565 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
568 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
571 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
574 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
577 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
580 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
583 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
586 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
589 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
592 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
595 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
598 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
601 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
604 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
605 RHSConstant: ValueRef)
608 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
611 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
614 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
617 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
620 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
623 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
626 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
629 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
632 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
635 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
638 pub fn LLVMConstGEP(ConstantVal: ValueRef,
639 ConstantIndices: *ValueRef,
643 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
644 ConstantIndices: *ValueRef,
648 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
651 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
654 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
657 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
660 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
663 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
666 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
669 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
672 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
675 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
678 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
681 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
684 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
687 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
690 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
693 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
696 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
701 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
704 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
705 ConstantIfTrue: ValueRef,
706 ConstantIfFalse: ValueRef)
709 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
710 IndexConstant: ValueRef)
713 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
714 ElementValueConstant: ValueRef,
715 IndexConstant: ValueRef)
718 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
719 VectorBConstant: ValueRef,
720 MaskConstant: ValueRef)
723 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
728 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
729 ElementValueConstant: ValueRef,
734 pub fn LLVMConstInlineAsm(Ty: TypeRef,
736 Constraints: *c_char,
737 HasSideEffects: Bool,
741 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
745 /* Operations on global variables, functions, and aliases (globals) */
747 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
749 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
751 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
753 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
755 pub fn LLVMGetSection(Global: ValueRef) -> *c_char;
757 pub fn LLVMSetSection(Global: ValueRef, Section: *c_char);
759 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
761 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
763 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
765 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
768 /* Operations on global variables */
770 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char)
773 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
776 AddressSpace: c_uint)
779 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
781 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
783 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
785 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
787 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
789 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
791 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
793 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
794 ConstantVal: ValueRef);
796 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
798 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
800 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
802 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
804 /* Operations on aliases */
806 pub fn LLVMAddAlias(M: ModuleRef,
812 /* Operations on functions */
814 pub fn LLVMAddFunction(M: ModuleRef,
819 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
821 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
823 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
825 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
827 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
829 pub fn LLVMDeleteFunction(Fn: ValueRef);
831 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
836 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
838 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
840 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
842 pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
844 pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
846 pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint, HighPA: c_uint);
848 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
850 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
852 HighPA: c_ulonglong);
854 /* Operations on parameters */
856 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
858 pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
860 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
862 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
864 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
866 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
868 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
870 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
872 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
874 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
876 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
878 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
880 /* Operations on basic blocks */
882 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
884 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
886 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
888 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
890 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
892 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
894 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
896 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
898 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
900 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
902 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
905 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
910 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
915 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
918 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
919 MoveAfter: BasicBlockRef);
922 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
923 MoveBefore: BasicBlockRef);
925 /* Operations on instructions */
927 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
929 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
931 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
933 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
935 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
937 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
939 /* Operations on call sites */
941 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
943 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
945 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
949 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
953 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
957 /* Operations on call instructions (only) */
959 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
961 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
963 /* Operations on phi nodes */
965 pub fn LLVMAddIncoming(PhiNode: ValueRef,
966 IncomingValues: *ValueRef,
967 IncomingBlocks: *BasicBlockRef,
970 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
972 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
975 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
978 /* Instruction builders */
980 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
982 pub fn LLVMPositionBuilder(Builder: BuilderRef,
983 Block: BasicBlockRef,
986 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
989 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
990 Block: BasicBlockRef);
992 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
994 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
996 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
998 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1002 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1004 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1008 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1010 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1012 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1016 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1018 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1020 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1025 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1027 pub fn LLVMBuildCondBr(B: BuilderRef,
1029 Then: BasicBlockRef,
1030 Else: BasicBlockRef)
1033 pub fn LLVMBuildSwitch(B: BuilderRef,
1035 Else: BasicBlockRef,
1039 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1044 pub fn LLVMBuildInvoke(B: BuilderRef,
1048 Then: BasicBlockRef,
1049 Catch: BasicBlockRef,
1053 pub fn LLVMBuildLandingPad(B: BuilderRef,
1060 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1062 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1064 /* Add a case to the switch instruction */
1066 pub fn LLVMAddCase(Switch: ValueRef,
1068 Dest: BasicBlockRef);
1070 /* Add a destination to the indirectbr instruction */
1072 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1074 /* Add a clause to the landing pad instruction */
1076 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1078 /* Set the cleanup on a landing pad instruction */
1080 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1084 pub fn LLVMBuildAdd(B: BuilderRef,
1090 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1096 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1102 pub fn LLVMBuildFAdd(B: BuilderRef,
1108 pub fn LLVMBuildSub(B: BuilderRef,
1114 pub fn LLVMBuildNSWSub(B: BuilderRef,
1120 pub fn LLVMBuildNUWSub(B: BuilderRef,
1126 pub fn LLVMBuildFSub(B: BuilderRef,
1132 pub fn LLVMBuildMul(B: BuilderRef,
1138 pub fn LLVMBuildNSWMul(B: BuilderRef,
1144 pub fn LLVMBuildNUWMul(B: BuilderRef,
1150 pub fn LLVMBuildFMul(B: BuilderRef,
1156 pub fn LLVMBuildUDiv(B: BuilderRef,
1162 pub fn LLVMBuildSDiv(B: BuilderRef,
1168 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1174 pub fn LLVMBuildFDiv(B: BuilderRef,
1180 pub fn LLVMBuildURem(B: BuilderRef,
1186 pub fn LLVMBuildSRem(B: BuilderRef,
1192 pub fn LLVMBuildFRem(B: BuilderRef,
1198 pub fn LLVMBuildShl(B: BuilderRef,
1204 pub fn LLVMBuildLShr(B: BuilderRef,
1210 pub fn LLVMBuildAShr(B: BuilderRef,
1216 pub fn LLVMBuildAnd(B: BuilderRef,
1222 pub fn LLVMBuildOr(B: BuilderRef,
1228 pub fn LLVMBuildXor(B: BuilderRef,
1234 pub fn LLVMBuildBinOp(B: BuilderRef,
1241 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1244 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1247 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1250 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1253 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char)
1258 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1261 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1267 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1270 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1276 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1278 pub fn LLVMBuildLoad(B: BuilderRef,
1279 PointerVal: ValueRef,
1284 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1288 pub fn LLVMBuildGEP(B: BuilderRef,
1295 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1302 pub fn LLVMBuildStructGEP(B: BuilderRef,
1308 pub fn LLVMBuildGlobalString(B: BuilderRef,
1313 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1320 pub fn LLVMBuildTrunc(B: BuilderRef,
1326 pub fn LLVMBuildZExt(B: BuilderRef,
1332 pub fn LLVMBuildSExt(B: BuilderRef,
1338 pub fn LLVMBuildFPToUI(B: BuilderRef,
1344 pub fn LLVMBuildFPToSI(B: BuilderRef,
1350 pub fn LLVMBuildUIToFP(B: BuilderRef,
1356 pub fn LLVMBuildSIToFP(B: BuilderRef,
1362 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1368 pub fn LLVMBuildFPExt(B: BuilderRef,
1374 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1380 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1386 pub fn LLVMBuildBitCast(B: BuilderRef,
1392 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1398 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1404 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1410 pub fn LLVMBuildCast(B: BuilderRef,
1414 Name: *c_char) -> ValueRef;
1416 pub fn LLVMBuildPointerCast(B: BuilderRef,
1422 pub fn LLVMBuildIntCast(B: BuilderRef,
1428 pub fn LLVMBuildFPCast(B: BuilderRef,
1436 pub fn LLVMBuildICmp(B: BuilderRef,
1443 pub fn LLVMBuildFCmp(B: BuilderRef,
1450 /* Miscellaneous instructions */
1452 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1455 pub fn LLVMBuildCall(B: BuilderRef,
1462 pub fn LLVMBuildSelect(B: BuilderRef,
1469 pub fn LLVMBuildVAArg(B: BuilderRef,
1475 pub fn LLVMBuildExtractElement(B: BuilderRef,
1481 pub fn LLVMBuildInsertElement(B: BuilderRef,
1488 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1495 pub fn LLVMBuildExtractValue(B: BuilderRef,
1501 pub fn LLVMBuildInsertValue(B: BuilderRef,
1509 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1512 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1515 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1521 /* Atomic Operations */
1522 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1523 PointerVal: ValueRef,
1525 Order: AtomicOrdering,
1529 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1532 Order: AtomicOrdering,
1536 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1540 Order: AtomicOrdering)
1542 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1546 Order: AtomicOrdering,
1547 SingleThreaded: Bool)
1550 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1553 /* Selected entries from the downcasts. */
1555 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1557 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1559 /** Writes a module to the specified path. Returns 0 on success. */
1561 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
1563 /** Creates target data from a target layout string. */
1565 pub fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
1566 /// Adds the target data to the given pass manager. The pass manager
1567 /// references the target data only weakly.
1569 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1570 /** Number of bytes clobbered when doing a Store to *T. */
1572 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1575 /** Number of bytes clobbered when doing a Store to *T. */
1577 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1580 /** Distance between successive elements in an array of T.
1581 Includes ABI padding. */
1583 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1585 /** Returns the preferred alignment of a type. */
1587 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1589 /** Returns the minimum alignment of a type. */
1591 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1594 /// Computes the byte offset of the indexed struct element for a
1597 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1603 * Returns the minimum alignment of a type when part of a call frame.
1606 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1609 /** Disposes target data. */
1611 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1613 /** Creates a pass manager. */
1615 pub fn LLVMCreatePassManager() -> PassManagerRef;
1616 /** Creates a function-by-function pass manager */
1618 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1621 /** Disposes a pass manager. */
1623 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1625 /** Runs a pass manager on a module. */
1627 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1629 /** Runs the function passes on the provided function. */
1631 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1634 /** Initializes all the function passes scheduled in the manager */
1636 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1638 /** Finalizes all the function passes scheduled in the manager */
1640 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1643 pub fn LLVMInitializePasses();
1646 pub fn LLVMAddPass(PM: PassManagerRef, P: PassRef);
1649 pub fn LLVMCreatePass(PassName: *c_char) -> PassRef;
1652 pub fn LLVMDestroyPass(P: PassRef);
1654 /** Adds a verification pass. */
1656 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1659 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1661 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1663 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1665 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1667 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1669 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1671 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1673 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1675 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1677 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1679 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1681 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1683 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1685 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1687 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1689 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1691 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1693 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1695 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1697 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1699 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1701 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1703 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1705 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1707 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1709 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1711 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1713 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1715 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1717 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1719 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1721 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1723 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1725 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1727 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1730 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1732 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1734 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1735 OptimizationLevel: c_uint);
1737 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1740 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1741 PMB: PassManagerBuilderRef,
1744 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1745 PMB: PassManagerBuilderRef,
1748 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1749 PMB: PassManagerBuilderRef,
1752 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1753 PMB: PassManagerBuilderRef,
1756 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1757 PMB: PassManagerBuilderRef,
1758 PM: PassManagerRef);
1761 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1762 PMB: PassManagerBuilderRef,
1763 PM: PassManagerRef);
1765 /** Destroys a memory buffer. */
1767 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1770 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1772 /** Opens an object file. */
1774 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1775 /** Closes an object file. */
1777 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1779 /** Enumerates the sections in an object file. */
1781 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1782 /** Destroys a section iterator. */
1784 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1785 /** Returns true if the section iterator is at the end of the section
1788 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1789 SI: SectionIteratorRef)
1791 /** Moves the section iterator to point to the next section. */
1793 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1794 /** Returns the current section name. */
1796 pub fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1797 /** Returns the current section size. */
1799 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1800 /** Returns the current section contents as a string buffer. */
1802 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
1804 /** Reads the given file and returns it as a memory buffer. Use
1805 LLVMDisposeMemoryBuffer() to get rid of it. */
1807 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
1811 pub fn LLVMRustWriteOutputFile(PM: PassManagerRef,
1816 // FIXME: When #2334 is fixed,
1817 // change c_uint to FileType
1820 EnableSegmentedStacks: bool)
1823 /** Returns a string describing the last error caused by an LLVMRust*
1826 pub fn LLVMRustGetLastError() -> *c_char;
1828 /** Prepare the JIT. Returns a memory manager that can load crates. */
1830 pub fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1832 /** Load a crate into the memory manager. */
1834 pub fn LLVMRustLoadCrate(MM: *(), Filename: *c_char) -> bool;
1836 /** Execute the JIT engine. */
1838 pub fn LLVMRustBuildJIT(MM: *(),
1840 EnableSegmentedStacks: bool)
1841 -> ExecutionEngineRef;
1843 /** Parses the bitcode in the given memory buffer. */
1845 pub fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
1847 /** Parses LLVM asm in the given file */
1849 pub fn LLVMRustParseAssemblyFile(Filename: *c_char, C: ContextRef)
1853 pub fn LLVMRustAddPrintModulePass(PM: PassManagerRef,
1857 /** Turn on LLVM pass-timing. */
1859 pub fn LLVMRustEnableTimePasses();
1861 /// Print the pass timings since static dtors aren't picking them up.
1863 pub fn LLVMRustPrintPassTimings();
1866 pub fn LLVMRustStartMultithreading() -> bool;
1869 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1872 pub fn LLVMStructSetBody(StructTy: TypeRef,
1873 ElementTypes: *TypeRef,
1874 ElementCount: c_uint,
1878 pub fn LLVMConstNamedStruct(S: TypeRef,
1879 ConstantVals: *ValueRef,
1883 /** Enables LLVM debug output. */
1885 pub fn LLVMSetDebug(Enabled: c_int);
1887 /** Prepares inline assembly. */
1889 pub fn LLVMInlineAsm(Ty: TypeRef,
1891 Constraints: *c_char,
1899 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1902 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1905 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1908 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1916 SplitName: *c_char);
1919 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1925 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1927 ParameterTypes: DIArray)
1931 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1932 Scope: DIDescriptor,
1934 LinkageName: *c_char,
1938 isLocalToUnit: bool,
1949 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1951 SizeInBits: c_ulonglong,
1952 AlignInBits: c_ulonglong,
1957 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1959 SizeInBits: c_ulonglong,
1960 AlignInBits: c_ulonglong,
1965 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1966 Scope: DIDescriptor,
1970 SizeInBits: c_ulonglong,
1971 AlignInBits: c_ulonglong,
1973 DerivedFrom: DIType,
1975 RunTimeLang: c_uint,
1976 VTableHolder: ValueRef)
1980 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1981 Scope: DIDescriptor,
1985 SizeInBits: c_ulonglong,
1986 AlignInBits: c_ulonglong,
1987 OffsetInBits: c_ulonglong,
1993 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1994 Scope: DIDescriptor,
2001 pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
2003 Scope: DIDescriptor,
2008 AlwaysPreserve: bool,
2014 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
2016 AlignInBits: c_ulonglong,
2018 Subscripts: DIArray)
2022 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
2024 AlignInBits: c_ulonglong,
2026 Subscripts: DIArray)
2030 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
2036 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
2042 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
2044 VarInfo: DIVariable,
2045 InsertAtEnd: BasicBlockRef)
2049 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
2051 VarInfo: DIVariable,
2052 InsertBefore: ValueRef)
2056 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
2062 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
2067 SizeInBits: c_ulonglong,
2068 AlignInBits: c_ulonglong,
2070 ClassType: ValueRef)
2074 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
2079 SizeInBits: c_ulonglong,
2080 AlignInBits: c_ulonglong,
2083 RunTimeLang: c_uint)
2088 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
2090 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
2093 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
2095 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
2098 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
2100 llvm::LLVMSetLinkage(Global, Link as c_uint);
2104 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
2106 llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
2109 pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
2111 llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
2115 pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
2117 let attr = attr as u64;
2118 let lower = attr & 0xffffffff;
2119 let upper = (attr >> 32) & 0xffffffff;
2120 llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2124 // FIXME(#8199): this shouldn't require this hackery. On i686
2125 // (FixedStackSegment as u64) will return 0 instead of 1 << 41.
2126 // Furthermore, if we use a match of any sort then an LLVM
2127 // assertion is generated!
2128 pub fn SetFixedStackSegmentAttribute(Fn: ValueRef) {
2130 let attr = 1u64 << 41;
2131 let lower = attr & 0xffffffff;
2132 let upper = (attr >> 32) & 0xffffffff;
2133 llvm::LLVMAddFunctionAttr(Fn, lower as c_uint, upper as c_uint);
2136 /* Memory-managed object interface to type handles. */
2138 pub struct TypeNames {
2139 type_names: HashMap<TypeRef, ~str>,
2140 named_types: HashMap<~str, TypeRef>
2144 pub fn new() -> TypeNames {
2146 type_names: HashMap::new(),
2147 named_types: HashMap::new()
2151 pub fn associate_type(&mut self, s: &str, t: &Type) {
2152 assert!(self.type_names.insert(t.to_ref(), s.to_owned()));
2153 assert!(self.named_types.insert(s.to_owned(), t.to_ref()));
2156 pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
2157 match self.type_names.find(&ty.to_ref()) {
2158 Some(a) => Some(a.slice(0, a.len())),
2163 pub fn find_type(&self, s: &str) -> Option<Type> {
2164 self.named_types.find_equiv(&s).map_move(|x| Type::from_ref(*x))
2167 // We have a depth count, because we seem to make infinite types.
2168 pub fn type_to_str_depth(&self, ty: Type, depth: int) -> ~str {
2169 match self.find_name(&ty) {
2170 option::Some(name) => return name.to_owned(),
2179 let kind = ty.kind();
2185 Double => ~"Double",
2186 X86_FP80 => ~"X86_FP80",
2188 PPC_FP128 => ~"PPC_FP128",
2190 Vector => ~"Vector",
2191 Metadata => ~"Metadata",
2192 X86_MMX => ~"X86_MMAX",
2194 fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
2197 let out_ty = ty.return_type();
2198 let args = ty.func_params();
2200 args.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2201 let out_ty = self.type_to_str_depth(out_ty, depth-1);
2202 fmt!("fn(%s) -> %s", args, out_ty)
2205 let tys = ty.field_types();
2206 let tys = tys.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
2210 let el_ty = ty.element_type();
2211 let el_ty = self.type_to_str_depth(el_ty, depth-1);
2212 let len = ty.array_length();
2213 fmt!("[%s x %u]", el_ty, len)
2216 let el_ty = ty.element_type();
2217 let el_ty = self.type_to_str_depth(el_ty, depth-1);
2220 _ => fail!("Unknown Type Kind (%u)", kind as uint)
2225 pub fn type_to_str(&self, ty: Type) -> ~str {
2226 self.type_to_str_depth(ty, 30)
2229 pub fn val_to_str(&self, val: ValueRef) -> ~str {
2231 let ty = Type::from_ref(llvm::LLVMTypeOf(val));
2232 self.type_to_str(ty)
2238 /* Memory-managed interface to target data. */
2240 pub struct target_data_res {
2244 impl Drop for target_data_res {
2247 llvm::LLVMDisposeTargetData(self.TD);
2252 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
2258 pub struct TargetData {
2259 lltd: TargetDataRef,
2260 dtor: @target_data_res
2263 pub fn mk_target_data(string_rep: &str) -> TargetData {
2264 let lltd = do string_rep.to_c_str().with_ref |buf| {
2265 unsafe { llvm::LLVMCreateTargetData(buf) }
2270 dtor: @target_data_res(lltd)
2274 /* Memory-managed interface to pass managers. */
2276 pub struct pass_manager_res {
2280 impl Drop for pass_manager_res {
2283 llvm::LLVMDisposePassManager(self.PM);
2288 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
2294 pub struct PassManager {
2295 llpm: PassManagerRef,
2296 dtor: @pass_manager_res
2299 pub fn mk_pass_manager() -> PassManager {
2301 let llpm = llvm::LLVMCreatePassManager();
2305 dtor: @pass_manager_res(llpm)
2310 /* Memory-managed interface to object files. */
2312 pub struct object_file_res {
2313 ObjectFile: ObjectFileRef,
2316 impl Drop for object_file_res {
2319 llvm::LLVMDisposeObjectFile(self.ObjectFile);
2324 pub fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
2330 pub struct ObjectFile {
2331 llof: ObjectFileRef,
2332 dtor: @object_file_res
2335 pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2337 let llof = llvm::LLVMCreateObjectFile(llmb);
2338 if llof as int == 0 { return option::None::<ObjectFile>; }
2340 option::Some(ObjectFile {
2342 dtor: @object_file_res(llof)
2347 /* Memory-managed interface to section iterators. */
2349 pub struct section_iter_res {
2350 SI: SectionIteratorRef,
2353 impl Drop for section_iter_res {
2356 llvm::LLVMDisposeSectionIterator(self.SI);
2361 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
2367 pub struct SectionIter {
2368 llsi: SectionIteratorRef,
2369 dtor: @section_iter_res
2372 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2374 let llsi = llvm::LLVMGetSections(llof);
2377 dtor: @section_iter_res(llsi)