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 #[allow(non_uppercase_pattern_statics)];
13 use std::c_str::ToCStr;
14 use std::hashmap::HashMap;
15 use std::libc::{c_uint, c_ushort, c_void, free};
16 use std::str::raw::from_c_str;
19 use middle::trans::type_::Type;
21 pub type Opcode = u32;
22 pub type Bool = c_uint;
24 pub static True: Bool = 1 as Bool;
25 pub static False: Bool = 0 as Bool;
27 // Consts for the LLVM CallConv type, pre-cast to uint.
34 X86StdcallCallConv = 64,
35 X86FastcallCallConv = 65,
40 LLVMDefaultVisibility = 0,
42 ProtectedVisibility = 2,
47 AvailableExternallyLinkage = 1,
48 LinkOnceAnyLinkage = 2,
49 LinkOnceODRLinkage = 3,
50 LinkOnceODRAutoHideLinkage = 4,
56 DLLImportLinkage = 10,
57 DLLExportLinkage = 11,
58 ExternalWeakLinkage = 12,
61 LinkerPrivateLinkage = 15,
62 LinkerPrivateWeakLinkage = 16,
67 ZExtAttribute = 1 << 0,
68 SExtAttribute = 1 << 1,
69 NoReturnAttribute = 1 << 2,
70 InRegAttribute = 1 << 3,
71 StructRetAttribute = 1 << 4,
72 NoUnwindAttribute = 1 << 5,
73 NoAliasAttribute = 1 << 6,
74 ByValAttribute = 1 << 7,
75 NestAttribute = 1 << 8,
76 ReadNoneAttribute = 1 << 9,
77 ReadOnlyAttribute = 1 << 10,
78 NoInlineAttribute = 1 << 11,
79 AlwaysInlineAttribute = 1 << 12,
80 OptimizeForSizeAttribute = 1 << 13,
81 StackProtectAttribute = 1 << 14,
82 StackProtectReqAttribute = 1 << 15,
83 AlignmentAttribute = 31 << 16,
84 NoCaptureAttribute = 1 << 21,
85 NoRedZoneAttribute = 1 << 22,
86 NoImplicitFloatAttribute = 1 << 23,
87 NakedAttribute = 1 << 24,
88 InlineHintAttribute = 1 << 25,
89 StackAttribute = 7 << 26,
90 ReturnsTwiceAttribute = 1 << 29,
91 UWTableAttribute = 1 << 30,
92 NonLazyBindAttribute = 1 << 31,
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;
150 pub enum AtomicBinOp {
165 pub enum AtomicOrdering {
169 // Consume = 3, // Not specified yet.
173 SequentiallyConsistent = 7
176 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
192 // Inline Asm Dialect
193 pub enum AsmDialect {
200 pub enum CodeGenOptLevel {
201 CodeGenLevelNone = 0,
202 CodeGenLevelLess = 1,
203 CodeGenLevelDefault = 2,
204 CodeGenLevelAggressive = 3,
212 RelocDynamicNoPic = 3,
216 pub enum CodeGenModel {
217 CodeModelDefault = 0,
218 CodeModelJITDefault = 1,
225 // Opaque pointer types
226 pub enum Module_opaque {}
227 pub type ModuleRef = *Module_opaque;
228 pub enum Context_opaque {}
229 pub type ContextRef = *Context_opaque;
230 pub enum Type_opaque {}
231 pub type TypeRef = *Type_opaque;
232 pub enum Value_opaque {}
233 pub type ValueRef = *Value_opaque;
234 pub enum BasicBlock_opaque {}
235 pub type BasicBlockRef = *BasicBlock_opaque;
236 pub enum Builder_opaque {}
237 pub type BuilderRef = *Builder_opaque;
238 pub enum ExecutionEngine_opaque {}
239 pub type ExecutionEngineRef = *ExecutionEngine_opaque;
240 pub enum MemoryBuffer_opaque {}
241 pub type MemoryBufferRef = *MemoryBuffer_opaque;
242 pub enum PassManager_opaque {}
243 pub type PassManagerRef = *PassManager_opaque;
244 pub enum PassManagerBuilder_opaque {}
245 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
246 pub enum Use_opaque {}
247 pub type UseRef = *Use_opaque;
248 pub enum TargetData_opaque {}
249 pub type TargetDataRef = *TargetData_opaque;
250 pub enum ObjectFile_opaque {}
251 pub type ObjectFileRef = *ObjectFile_opaque;
252 pub enum SectionIterator_opaque {}
253 pub type SectionIteratorRef = *SectionIterator_opaque;
254 pub enum Pass_opaque {}
255 pub type PassRef = *Pass_opaque;
256 pub enum TargetMachine_opaque {}
257 pub type TargetMachineRef = *TargetMachine_opaque;
260 use super::{ValueRef};
262 pub enum DIBuilder_opaque {}
263 pub type DIBuilderRef = *DIBuilder_opaque;
265 pub type DIDescriptor = ValueRef;
266 pub type DIScope = DIDescriptor;
267 pub type DILocation = DIDescriptor;
268 pub type DIFile = DIScope;
269 pub type DILexicalBlock = DIScope;
270 pub type DISubprogram = DIScope;
271 pub type DIType = DIDescriptor;
272 pub type DIBasicType = DIType;
273 pub type DIDerivedType = DIType;
274 pub type DICompositeType = DIDerivedType;
275 pub type DIVariable = DIDescriptor;
276 pub type DIArray = DIDescriptor;
277 pub type DISubrange = DIDescriptor;
279 pub enum DIDescriptorFlags {
280 FlagPrivate = 1 << 0,
281 FlagProtected = 1 << 1,
282 FlagFwdDecl = 1 << 2,
283 FlagAppleBlock = 1 << 3,
284 FlagBlockByrefStruct = 1 << 4,
285 FlagVirtual = 1 << 5,
286 FlagArtificial = 1 << 6,
287 FlagExplicit = 1 << 7,
288 FlagPrototyped = 1 << 8,
289 FlagObjcClassComplete = 1 << 9,
290 FlagObjectPointer = 1 << 10,
291 FlagVector = 1 << 11,
292 FlagStaticMember = 1 << 12
297 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
298 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
299 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
300 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
301 use super::{ValueRef, TargetMachineRef, FileType};
302 use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
303 use super::debuginfo::*;
304 use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong};
306 #[link_args = "-lrustllvm"]
308 /* Create and destroy contexts. */
309 pub fn LLVMContextCreate() -> ContextRef;
310 pub fn LLVMContextDispose(C: ContextRef);
311 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
316 /* Create and destroy modules. */
317 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
320 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
321 pub fn LLVMDisposeModule(M: ModuleRef);
323 /** Data layout. See Module::getDataLayout. */
324 pub fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
325 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
327 /** Target triple. See Module::getTargetTriple. */
328 pub fn LLVMGetTarget(M: ModuleRef) -> *c_char;
329 pub fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
331 /** See Module::dump. */
332 pub fn LLVMDumpModule(M: ModuleRef);
334 /** See Module::setModuleInlineAsm. */
335 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
337 /** See llvm::LLVMTypeKind::getTypeID. */
338 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
340 /** See llvm::LLVMType::getContext. */
341 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
343 /* Operations on integer types */
344 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
345 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
346 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
347 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
348 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
349 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
352 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
354 /* Operations on real types */
355 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
356 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
357 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
358 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
359 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
361 /* Operations on function types */
362 pub fn LLVMFunctionType(ReturnType: TypeRef,
363 ParamTypes: *TypeRef,
367 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
368 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
369 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
370 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
372 /* Operations on struct types */
373 pub fn LLVMStructTypeInContext(C: ContextRef,
374 ElementTypes: *TypeRef,
375 ElementCount: c_uint,
378 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
379 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
381 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
383 /* Operations on array, pointer, and vector types (sequence types) */
384 pub fn LLVMArrayType(ElementType: TypeRef, ElementCount: c_uint)
386 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
388 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
391 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
392 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
393 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
394 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
396 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
398 /* Operations on other types */
399 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
400 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
401 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
403 /* Operations on all values */
404 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
405 pub fn LLVMGetValueName(Val: ValueRef) -> *c_char;
406 pub fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
407 pub fn LLVMDumpValue(Val: ValueRef);
408 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
409 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
410 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
411 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
413 /* Operations on Uses */
414 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
415 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
416 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
417 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
419 /* Operations on Users */
420 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
421 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
422 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
424 /* Operations on constants of any type */
425 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
427 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
428 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
430 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
432 /* only for int/vector */
433 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
434 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
435 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
436 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
437 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
439 /* Operations on metadata */
440 pub fn LLVMMDStringInContext(C: ContextRef,
444 pub fn LLVMMDNodeInContext(C: ContextRef,
448 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
452 /* Operations on scalar constants */
453 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
455 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8)
457 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
462 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
463 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char)
465 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
469 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
470 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
473 /* Operations on composite constants */
474 pub fn LLVMConstStringInContext(C: ContextRef,
477 DontNullTerminate: Bool)
479 pub fn LLVMConstStructInContext(C: ContextRef,
480 ConstantVals: *ValueRef,
485 pub fn LLVMConstArray(ElementTy: TypeRef,
486 ConstantVals: *ValueRef,
489 pub fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: c_uint)
492 /* Constant expressions */
493 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
494 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
495 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
496 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
497 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
498 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
499 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
500 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
502 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
504 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
506 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
508 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
510 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
512 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
514 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
516 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
518 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
520 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
522 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
524 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
526 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
528 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
529 RHSConstant: ValueRef)
531 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
533 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
535 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
537 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
539 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
541 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
543 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
545 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
547 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
549 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
551 pub fn LLVMConstGEP(ConstantVal: ValueRef,
552 ConstantIndices: *ValueRef,
555 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
556 ConstantIndices: *ValueRef,
559 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
561 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
563 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
565 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
567 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
569 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
571 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
573 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
575 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
577 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
579 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
581 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
583 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
585 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
587 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
589 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
591 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
595 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
597 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
598 ConstantIfTrue: ValueRef,
599 ConstantIfFalse: ValueRef)
601 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
602 IndexConstant: ValueRef)
604 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
605 ElementValueConstant: ValueRef,
606 IndexConstant: ValueRef)
608 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
609 VectorBConstant: ValueRef,
610 MaskConstant: ValueRef)
612 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
616 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
617 ElementValueConstant: ValueRef,
621 pub fn LLVMConstInlineAsm(Ty: TypeRef,
623 Constraints: *c_char,
624 HasSideEffects: Bool,
627 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
631 /* Operations on global variables, functions, and aliases (globals) */
632 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
633 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
634 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
635 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
636 pub fn LLVMGetSection(Global: ValueRef) -> *c_char;
637 pub fn LLVMSetSection(Global: ValueRef, Section: *c_char);
638 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
639 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
640 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
641 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
644 /* Operations on global variables */
645 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char)
647 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
650 AddressSpace: c_uint)
652 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
653 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
654 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
655 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
656 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
657 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
658 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
659 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
660 ConstantVal: ValueRef);
661 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
662 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
663 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
664 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
666 /* Operations on aliases */
667 pub fn LLVMAddAlias(M: ModuleRef,
673 /* Operations on functions */
674 pub fn LLVMAddFunction(M: ModuleRef,
678 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
679 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
680 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
681 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
682 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
683 pub fn LLVMDeleteFunction(Fn: ValueRef);
684 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
688 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
689 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
690 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
691 pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
692 pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
693 pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
694 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
695 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
697 pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
698 pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
700 pub fn LLVMAddColdAttribute(Fn: ValueRef);
702 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
704 HighPA: c_ulonglong);
706 /* Operations on parameters */
707 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
708 pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
709 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
710 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
711 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
712 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
713 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
714 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
715 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
716 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
717 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
718 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
720 /* Operations on basic blocks */
721 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
722 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
723 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
724 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
725 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
726 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
727 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
728 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
729 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
730 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
731 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
733 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
737 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
741 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
743 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
744 MoveAfter: BasicBlockRef);
746 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
747 MoveBefore: BasicBlockRef);
749 /* Operations on instructions */
750 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
751 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
752 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
753 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
754 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
755 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
757 /* Operations on call sites */
758 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
759 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
760 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
763 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
766 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
770 /* Operations on call instructions (only) */
771 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
772 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
774 /* Operations on phi nodes */
775 pub fn LLVMAddIncoming(PhiNode: ValueRef,
776 IncomingValues: *ValueRef,
777 IncomingBlocks: *BasicBlockRef,
779 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
780 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
782 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
785 /* Instruction builders */
786 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
787 pub fn LLVMPositionBuilder(Builder: BuilderRef,
788 Block: BasicBlockRef,
790 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
792 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
793 Block: BasicBlockRef);
794 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
795 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
796 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
797 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
800 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
801 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
804 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
805 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
806 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
809 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
810 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
811 pub fn LLVMBuildAggregateRet(B: BuilderRef,
815 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
816 pub fn LLVMBuildCondBr(B: BuilderRef,
821 pub fn LLVMBuildSwitch(B: BuilderRef,
826 pub fn LLVMBuildIndirectBr(B: BuilderRef,
830 pub fn LLVMBuildInvoke(B: BuilderRef,
835 Catch: BasicBlockRef,
838 pub fn LLVMBuildLandingPad(B: BuilderRef,
844 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
845 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
847 /* Add a case to the switch instruction */
848 pub fn LLVMAddCase(Switch: ValueRef,
850 Dest: BasicBlockRef);
852 /* Add a destination to the indirectbr instruction */
853 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
855 /* Add a clause to the landing pad instruction */
856 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
858 /* Set the cleanup on a landing pad instruction */
859 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
862 pub fn LLVMBuildAdd(B: BuilderRef,
867 pub fn LLVMBuildNSWAdd(B: BuilderRef,
872 pub fn LLVMBuildNUWAdd(B: BuilderRef,
877 pub fn LLVMBuildFAdd(B: BuilderRef,
882 pub fn LLVMBuildSub(B: BuilderRef,
887 pub fn LLVMBuildNSWSub(B: BuilderRef,
892 pub fn LLVMBuildNUWSub(B: BuilderRef,
897 pub fn LLVMBuildFSub(B: BuilderRef,
902 pub fn LLVMBuildMul(B: BuilderRef,
907 pub fn LLVMBuildNSWMul(B: BuilderRef,
912 pub fn LLVMBuildNUWMul(B: BuilderRef,
917 pub fn LLVMBuildFMul(B: BuilderRef,
922 pub fn LLVMBuildUDiv(B: BuilderRef,
927 pub fn LLVMBuildSDiv(B: BuilderRef,
932 pub fn LLVMBuildExactSDiv(B: BuilderRef,
937 pub fn LLVMBuildFDiv(B: BuilderRef,
942 pub fn LLVMBuildURem(B: BuilderRef,
947 pub fn LLVMBuildSRem(B: BuilderRef,
952 pub fn LLVMBuildFRem(B: BuilderRef,
957 pub fn LLVMBuildShl(B: BuilderRef,
962 pub fn LLVMBuildLShr(B: BuilderRef,
967 pub fn LLVMBuildAShr(B: BuilderRef,
972 pub fn LLVMBuildAnd(B: BuilderRef,
977 pub fn LLVMBuildOr(B: BuilderRef,
982 pub fn LLVMBuildXor(B: BuilderRef,
987 pub fn LLVMBuildBinOp(B: BuilderRef,
993 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
995 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
997 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
999 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1001 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char)
1005 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1007 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1012 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1014 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1019 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1020 pub fn LLVMBuildLoad(B: BuilderRef,
1021 PointerVal: ValueRef,
1025 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1028 pub fn LLVMBuildGEP(B: BuilderRef,
1034 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1040 pub fn LLVMBuildStructGEP(B: BuilderRef,
1045 pub fn LLVMBuildGlobalString(B: BuilderRef,
1049 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1055 pub fn LLVMBuildTrunc(B: BuilderRef,
1060 pub fn LLVMBuildZExt(B: BuilderRef,
1065 pub fn LLVMBuildSExt(B: BuilderRef,
1070 pub fn LLVMBuildFPToUI(B: BuilderRef,
1075 pub fn LLVMBuildFPToSI(B: BuilderRef,
1080 pub fn LLVMBuildUIToFP(B: BuilderRef,
1085 pub fn LLVMBuildSIToFP(B: BuilderRef,
1090 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1095 pub fn LLVMBuildFPExt(B: BuilderRef,
1100 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1105 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1110 pub fn LLVMBuildBitCast(B: BuilderRef,
1115 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1120 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1125 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1130 pub fn LLVMBuildCast(B: BuilderRef,
1134 Name: *c_char) -> ValueRef;
1135 pub fn LLVMBuildPointerCast(B: BuilderRef,
1140 pub fn LLVMBuildIntCast(B: BuilderRef,
1145 pub fn LLVMBuildFPCast(B: BuilderRef,
1152 pub fn LLVMBuildICmp(B: BuilderRef,
1158 pub fn LLVMBuildFCmp(B: BuilderRef,
1165 /* Miscellaneous instructions */
1166 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1168 pub fn LLVMBuildCall(B: BuilderRef,
1174 pub fn LLVMBuildSelect(B: BuilderRef,
1180 pub fn LLVMBuildVAArg(B: BuilderRef,
1185 pub fn LLVMBuildExtractElement(B: BuilderRef,
1190 pub fn LLVMBuildInsertElement(B: BuilderRef,
1196 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1202 pub fn LLVMBuildExtractValue(B: BuilderRef,
1207 pub fn LLVMBuildInsertValue(B: BuilderRef,
1214 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1216 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1218 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1224 /* Atomic Operations */
1225 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1226 PointerVal: ValueRef,
1228 Order: AtomicOrdering,
1232 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1235 Order: AtomicOrdering,
1239 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1243 Order: AtomicOrdering)
1245 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1249 Order: AtomicOrdering,
1250 SingleThreaded: Bool)
1253 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1256 /* Selected entries from the downcasts. */
1257 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1258 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1260 /** Writes a module to the specified path. Returns 0 on success. */
1261 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
1263 /** Creates target data from a target layout string. */
1264 pub fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
1265 /// Adds the target data to the given pass manager. The pass manager
1266 /// references the target data only weakly.
1267 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1268 /** Number of bytes clobbered when doing a Store to *T. */
1269 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1272 /** Number of bytes clobbered when doing a Store to *T. */
1273 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1276 /** Distance between successive elements in an array of T.
1277 Includes ABI padding. */
1278 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1280 /** Returns the preferred alignment of a type. */
1281 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1283 /** Returns the minimum alignment of a type. */
1284 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1287 /// Computes the byte offset of the indexed struct element for a
1289 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1295 * Returns the minimum alignment of a type when part of a call frame.
1297 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1300 /** Disposes target data. */
1301 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1303 /** Creates a pass manager. */
1304 pub fn LLVMCreatePassManager() -> PassManagerRef;
1306 /** Creates a function-by-function pass manager */
1307 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1310 /** Disposes a pass manager. */
1311 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1313 /** Runs a pass manager on a module. */
1314 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1316 /** Runs the function passes on the provided function. */
1317 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1320 /** Initializes all the function passes scheduled in the manager */
1321 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1323 /** Finalizes all the function passes scheduled in the manager */
1324 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1326 pub fn LLVMInitializePasses();
1328 /** Adds a verification pass. */
1329 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1331 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1332 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1333 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1334 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1335 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1336 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1337 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1338 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1339 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1340 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1341 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1342 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1343 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1344 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1345 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1346 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1347 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1348 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1349 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1350 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1351 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1352 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1353 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1354 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1355 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1356 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1357 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1358 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1359 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1360 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1361 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1362 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1363 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1364 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1365 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1367 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1368 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1369 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1370 OptimizationLevel: c_uint);
1371 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1373 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1374 PMB: PassManagerBuilderRef,
1376 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1377 PMB: PassManagerBuilderRef,
1379 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1380 PMB: PassManagerBuilderRef,
1382 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1383 PMB: PassManagerBuilderRef,
1385 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1386 PMB: PassManagerBuilderRef,
1387 PM: PassManagerRef);
1389 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1390 PMB: PassManagerBuilderRef,
1391 PM: PassManagerRef);
1393 /** Destroys a memory buffer. */
1394 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1397 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1399 /** Opens an object file. */
1400 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1401 /** Closes an object file. */
1402 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1404 /** Enumerates the sections in an object file. */
1405 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1406 /** Destroys a section iterator. */
1407 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1408 /** Returns true if the section iterator is at the end of the section
1410 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1411 SI: SectionIteratorRef)
1413 /** Moves the section iterator to point to the next section. */
1414 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1415 /** Returns the current section name. */
1416 pub fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1417 /** Returns the current section size. */
1418 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1419 /** Returns the current section contents as a string buffer. */
1420 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
1422 /** Reads the given file and returns it as a memory buffer. Use
1423 LLVMDisposeMemoryBuffer() to get rid of it. */
1424 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
1427 /** Returns a string describing the last error caused by an LLVMRust*
1429 pub fn LLVMRustGetLastError() -> *c_char;
1431 /** Prepare the JIT. Returns a memory manager that can load crates. */
1432 pub fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1434 /** Load a crate into the memory manager. */
1435 pub fn LLVMRustLoadCrate(MM: *(), Filename: *c_char) -> bool;
1437 /** Execute the JIT engine. */
1438 pub fn LLVMRustBuildJIT(MM: *(),
1440 EnableSegmentedStacks: bool)
1441 -> ExecutionEngineRef;
1443 /// Print the pass timings since static dtors aren't picking them up.
1444 pub fn LLVMRustPrintPassTimings();
1446 pub fn LLVMRustStartMultithreading() -> bool;
1448 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1450 pub fn LLVMStructSetBody(StructTy: TypeRef,
1451 ElementTypes: *TypeRef,
1452 ElementCount: c_uint,
1455 pub fn LLVMConstNamedStruct(S: TypeRef,
1456 ConstantVals: *ValueRef,
1460 /** Enables LLVM debug output. */
1461 pub fn LLVMSetDebug(Enabled: c_int);
1463 /** Prepares inline assembly. */
1464 pub fn LLVMInlineAsm(Ty: TypeRef,
1466 Constraints: *c_char,
1473 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1475 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1477 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1479 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1487 SplitName: *c_char);
1489 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1494 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1496 ParameterTypes: DIArray)
1499 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1500 Scope: DIDescriptor,
1502 LinkageName: *c_char,
1506 isLocalToUnit: bool,
1516 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1518 SizeInBits: c_ulonglong,
1519 AlignInBits: c_ulonglong,
1523 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1525 SizeInBits: c_ulonglong,
1526 AlignInBits: c_ulonglong,
1530 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1531 Scope: DIDescriptor,
1535 SizeInBits: c_ulonglong,
1536 AlignInBits: c_ulonglong,
1538 DerivedFrom: DIType,
1540 RunTimeLang: c_uint,
1541 VTableHolder: ValueRef,
1545 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1546 Scope: DIDescriptor,
1550 SizeInBits: c_ulonglong,
1551 AlignInBits: c_ulonglong,
1552 OffsetInBits: c_ulonglong,
1557 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1558 Scope: DIDescriptor,
1564 pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
1566 Scope: DIDescriptor,
1571 AlwaysPreserve: bool,
1576 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1578 AlignInBits: c_ulonglong,
1580 Subscripts: DIArray)
1583 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1585 AlignInBits: c_ulonglong,
1587 Subscripts: DIArray)
1590 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1595 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1600 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1602 VarInfo: DIVariable,
1603 InsertAtEnd: BasicBlockRef)
1606 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1608 VarInfo: DIVariable,
1609 InsertBefore: ValueRef)
1612 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1617 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1622 SizeInBits: c_ulonglong,
1623 AlignInBits: c_ulonglong,
1625 ClassType: ValueRef)
1628 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1633 SizeInBits: c_ulonglong,
1634 AlignInBits: c_ulonglong,
1637 RunTimeLang: c_uint)
1640 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1642 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1651 pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
1653 pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
1655 pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
1663 AddrOpsCount: c_uint,
1667 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1674 pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1675 pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
1677 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1679 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1681 pub fn LLVMInitializeX86TargetInfo();
1682 pub fn LLVMInitializeX86Target();
1683 pub fn LLVMInitializeX86TargetMC();
1684 pub fn LLVMInitializeX86AsmPrinter();
1685 pub fn LLVMInitializeX86AsmParser();
1686 pub fn LLVMInitializeARMTargetInfo();
1687 pub fn LLVMInitializeARMTarget();
1688 pub fn LLVMInitializeARMTargetMC();
1689 pub fn LLVMInitializeARMAsmPrinter();
1690 pub fn LLVMInitializeARMAsmParser();
1691 pub fn LLVMInitializeMipsTargetInfo();
1692 pub fn LLVMInitializeMipsTarget();
1693 pub fn LLVMInitializeMipsTargetMC();
1694 pub fn LLVMInitializeMipsAsmPrinter();
1695 pub fn LLVMInitializeMipsAsmParser();
1697 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *c_char) -> bool;
1698 pub fn LLVMRustCreateTargetMachine(Triple: *c_char,
1701 Model: CodeGenModel,
1703 Level: CodeGenOptLevel,
1705 UseSoftFP: bool) -> TargetMachineRef;
1706 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
1707 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
1710 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
1712 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef);
1713 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
1714 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
1718 FileType: FileType) -> bool;
1719 pub fn LLVMRustPrintModule(PM: PassManagerRef,
1722 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: **c_char);
1723 pub fn LLVMRustPrintPasses();
1724 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *c_char);
1725 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
1726 AddLifetimes: bool);
1730 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
1732 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
1735 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
1737 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
1740 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
1742 llvm::LLVMSetLinkage(Global, Link as c_uint);
1746 pub fn SetUnnamedAddr(Global: ValueRef, Unnamed: bool) {
1748 llvm::LLVMSetUnnamedAddr(Global, Unnamed as Bool);
1752 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
1754 llvm::LLVMSetThreadLocal(global, is_thread_local as Bool);
1758 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1760 llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
1763 pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1765 llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
1769 pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
1771 llvm::LLVMAddFunctionAttr(Fn, attr as c_uint)
1774 /* Memory-managed object interface to type handles. */
1776 pub struct TypeNames {
1777 type_names: HashMap<TypeRef, ~str>,
1778 named_types: HashMap<~str, TypeRef>
1782 pub fn new() -> TypeNames {
1784 type_names: HashMap::new(),
1785 named_types: HashMap::new()
1789 pub fn associate_type(&mut self, s: &str, t: &Type) {
1790 assert!(self.type_names.insert(t.to_ref(), s.to_owned()));
1791 assert!(self.named_types.insert(s.to_owned(), t.to_ref()));
1794 pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
1795 match self.type_names.find(&ty.to_ref()) {
1796 Some(a) => Some(a.slice(0, a.len())),
1801 pub fn find_type(&self, s: &str) -> Option<Type> {
1802 self.named_types.find_equiv(&s).map(|x| Type::from_ref(*x))
1805 pub fn type_to_str(&self, ty: Type) -> ~str {
1807 let s = llvm::LLVMTypeToString(ty.to_ref());
1808 let ret = from_c_str(s);
1814 pub fn types_to_str(&self, tys: &[Type]) -> ~str {
1815 let strs = tys.map(|t| self.type_to_str(*t));
1816 format!("[{}]", strs.connect(","))
1819 pub fn val_to_str(&self, val: ValueRef) -> ~str {
1821 let ty = Type::from_ref(llvm::LLVMTypeOf(val));
1822 self.type_to_str(ty)
1827 /* Memory-managed interface to target data. */
1829 pub struct target_data_res {
1833 impl Drop for target_data_res {
1834 fn drop(&mut self) {
1836 llvm::LLVMDisposeTargetData(self.TD);
1841 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
1847 pub struct TargetData {
1848 lltd: TargetDataRef,
1849 dtor: @target_data_res
1852 pub fn mk_target_data(string_rep: &str) -> TargetData {
1853 let lltd = do string_rep.with_c_str |buf| {
1854 unsafe { llvm::LLVMCreateTargetData(buf) }
1859 dtor: @target_data_res(lltd)
1863 /* Memory-managed interface to pass managers. */
1865 pub struct pass_manager_res {
1869 impl Drop for pass_manager_res {
1870 fn drop(&mut self) {
1872 llvm::LLVMDisposePassManager(self.PM);
1877 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
1883 pub struct PassManager {
1884 llpm: PassManagerRef,
1885 dtor: @pass_manager_res
1888 pub fn mk_pass_manager() -> PassManager {
1890 let llpm = llvm::LLVMCreatePassManager();
1894 dtor: @pass_manager_res(llpm)
1899 /* Memory-managed interface to object files. */
1901 pub struct object_file_res {
1902 ObjectFile: ObjectFileRef,
1905 impl Drop for object_file_res {
1906 fn drop(&mut self) {
1908 llvm::LLVMDisposeObjectFile(self.ObjectFile);
1913 pub fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
1919 pub struct ObjectFile {
1920 llof: ObjectFileRef,
1921 dtor: @object_file_res
1924 pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1926 let llof = llvm::LLVMCreateObjectFile(llmb);
1927 if llof as int == 0 { return option::None::<ObjectFile>; }
1929 option::Some(ObjectFile {
1931 dtor: @object_file_res(llof)
1936 /* Memory-managed interface to section iterators. */
1938 pub struct section_iter_res {
1939 SI: SectionIteratorRef,
1942 impl Drop for section_iter_res {
1943 fn drop(&mut self) {
1945 llvm::LLVMDisposeSectionIterator(self.SI);
1950 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
1956 pub struct SectionIter {
1957 llsi: SectionIteratorRef,
1958 dtor: @section_iter_res
1961 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
1963 let llsi = llvm::LLVMGetSections(llof);
1966 dtor: @section_iter_res(llsi)