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;
18 use middle::trans::type_::Type;
20 pub type Opcode = u32;
21 pub type Bool = c_uint;
23 pub static True: Bool = 1 as Bool;
24 pub static False: Bool = 0 as Bool;
26 // Consts for the LLVM CallConv type, pre-cast to uint.
33 X86StdcallCallConv = 64,
34 X86FastcallCallConv = 65,
39 LLVMDefaultVisibility = 0,
41 ProtectedVisibility = 2,
46 AvailableExternallyLinkage = 1,
47 LinkOnceAnyLinkage = 2,
48 LinkOnceODRLinkage = 3,
49 LinkOnceODRAutoHideLinkage = 4,
55 DLLImportLinkage = 10,
56 DLLExportLinkage = 11,
57 ExternalWeakLinkage = 12,
60 LinkerPrivateLinkage = 15,
61 LinkerPrivateWeakLinkage = 16,
66 ZExtAttribute = 1 << 0,
67 SExtAttribute = 1 << 1,
68 NoReturnAttribute = 1 << 2,
69 InRegAttribute = 1 << 3,
70 StructRetAttribute = 1 << 4,
71 NoUnwindAttribute = 1 << 5,
72 NoAliasAttribute = 1 << 6,
73 ByValAttribute = 1 << 7,
74 NestAttribute = 1 << 8,
75 ReadNoneAttribute = 1 << 9,
76 ReadOnlyAttribute = 1 << 10,
77 NoInlineAttribute = 1 << 11,
78 AlwaysInlineAttribute = 1 << 12,
79 OptimizeForSizeAttribute = 1 << 13,
80 StackProtectAttribute = 1 << 14,
81 StackProtectReqAttribute = 1 << 15,
82 AlignmentAttribute = 31 << 16,
83 NoCaptureAttribute = 1 << 21,
84 NoRedZoneAttribute = 1 << 22,
85 NoImplicitFloatAttribute = 1 << 23,
86 NakedAttribute = 1 << 24,
87 InlineHintAttribute = 1 << 25,
88 StackAttribute = 7 << 26,
89 ReturnsTwiceAttribute = 1 << 29,
90 UWTableAttribute = 1 << 30,
91 NonLazyBindAttribute = 1 << 31,
94 // enum for the LLVM IntPredicate type
95 pub enum IntPredicate {
108 // enum for the LLVM RealPredicate type
109 pub enum RealPredicate {
110 RealPredicateFalse = 0,
125 RealPredicateTrue = 15,
128 // The LLVM TypeKind type - must stay in sync with the def of
129 // LLVMTypeKind in llvm/include/llvm-c/Core.h
152 pub enum AtomicBinOp {
167 pub enum AtomicOrdering {
171 // Consume = 3, // Not specified yet.
175 SequentiallyConsistent = 7
178 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
194 // Inline Asm Dialect
195 pub enum AsmDialect {
202 pub enum CodeGenOptLevel {
203 CodeGenLevelNone = 0,
204 CodeGenLevelLess = 1,
205 CodeGenLevelDefault = 2,
206 CodeGenLevelAggressive = 3,
214 RelocDynamicNoPic = 3,
218 pub enum CodeGenModel {
219 CodeModelDefault = 0,
220 CodeModelJITDefault = 1,
227 // Opaque pointer types
228 pub enum Module_opaque {}
229 pub type ModuleRef = *Module_opaque;
230 pub enum Context_opaque {}
231 pub type ContextRef = *Context_opaque;
232 pub enum Type_opaque {}
233 pub type TypeRef = *Type_opaque;
234 pub enum Value_opaque {}
235 pub type ValueRef = *Value_opaque;
236 pub enum BasicBlock_opaque {}
237 pub type BasicBlockRef = *BasicBlock_opaque;
238 pub enum Builder_opaque {}
239 pub type BuilderRef = *Builder_opaque;
240 pub enum ExecutionEngine_opaque {}
241 pub type ExecutionEngineRef = *ExecutionEngine_opaque;
242 pub enum MemoryBuffer_opaque {}
243 pub type MemoryBufferRef = *MemoryBuffer_opaque;
244 pub enum PassManager_opaque {}
245 pub type PassManagerRef = *PassManager_opaque;
246 pub enum PassManagerBuilder_opaque {}
247 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
248 pub enum Use_opaque {}
249 pub type UseRef = *Use_opaque;
250 pub enum TargetData_opaque {}
251 pub type TargetDataRef = *TargetData_opaque;
252 pub enum ObjectFile_opaque {}
253 pub type ObjectFileRef = *ObjectFile_opaque;
254 pub enum SectionIterator_opaque {}
255 pub type SectionIteratorRef = *SectionIterator_opaque;
256 pub enum Pass_opaque {}
257 pub type PassRef = *Pass_opaque;
258 pub enum TargetMachine_opaque {}
259 pub type TargetMachineRef = *TargetMachine_opaque;
262 use super::{ValueRef};
264 pub enum DIBuilder_opaque {}
265 pub type DIBuilderRef = *DIBuilder_opaque;
267 pub type DIDescriptor = ValueRef;
268 pub type DIScope = DIDescriptor;
269 pub type DILocation = DIDescriptor;
270 pub type DIFile = DIScope;
271 pub type DILexicalBlock = DIScope;
272 pub type DISubprogram = DIScope;
273 pub type DIType = DIDescriptor;
274 pub type DIBasicType = DIType;
275 pub type DIDerivedType = DIType;
276 pub type DICompositeType = DIDerivedType;
277 pub type DIVariable = DIDescriptor;
278 pub type DIArray = DIDescriptor;
279 pub type DISubrange = DIDescriptor;
281 pub enum DIDescriptorFlags {
282 FlagPrivate = 1 << 0,
283 FlagProtected = 1 << 1,
284 FlagFwdDecl = 1 << 2,
285 FlagAppleBlock = 1 << 3,
286 FlagBlockByrefStruct = 1 << 4,
287 FlagVirtual = 1 << 5,
288 FlagArtificial = 1 << 6,
289 FlagExplicit = 1 << 7,
290 FlagPrototyped = 1 << 8,
291 FlagObjcClassComplete = 1 << 9,
292 FlagObjectPointer = 1 << 10,
293 FlagVector = 1 << 11,
294 FlagStaticMember = 1 << 12
299 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
300 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
301 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
302 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
303 use super::{ValueRef, TargetMachineRef, FileType};
304 use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
305 use super::debuginfo::*;
306 use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong,
310 #[link_args = "-lrustllvm"]
312 #[cfg(not(stage0))] // if you're deleting this, put this on the block below
313 #[link(name = "rustllvm")]
317 /* Create and destroy contexts. */
318 pub fn LLVMContextCreate() -> ContextRef;
319 pub fn LLVMContextDispose(C: ContextRef);
320 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
325 /* Create and destroy modules. */
326 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
329 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
330 pub fn LLVMDisposeModule(M: ModuleRef);
332 /** Data layout. See Module::getDataLayout. */
333 pub fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
334 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
336 /** Target triple. See Module::getTargetTriple. */
337 pub fn LLVMGetTarget(M: ModuleRef) -> *c_char;
338 pub fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
340 /** See Module::dump. */
341 pub fn LLVMDumpModule(M: ModuleRef);
343 /** See Module::setModuleInlineAsm. */
344 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
346 /** See llvm::LLVMTypeKind::getTypeID. */
347 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
349 /** See llvm::LLVMType::getContext. */
350 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
352 /* Operations on integer types */
353 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
354 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
355 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
356 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
357 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
358 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
361 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
363 /* Operations on real types */
364 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
365 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
366 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
367 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
368 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
370 /* Operations on function types */
371 pub fn LLVMFunctionType(ReturnType: TypeRef,
372 ParamTypes: *TypeRef,
376 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
377 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
378 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
379 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
381 /* Operations on struct types */
382 pub fn LLVMStructTypeInContext(C: ContextRef,
383 ElementTypes: *TypeRef,
384 ElementCount: c_uint,
387 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
388 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
390 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
392 /* Operations on array, pointer, and vector types (sequence types) */
393 pub fn LLVMArrayType(ElementType: TypeRef, ElementCount: c_uint)
395 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
397 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
400 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
401 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
402 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
403 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
405 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
407 /* Operations on other types */
408 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
409 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
410 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
412 /* Operations on all values */
413 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
414 pub fn LLVMGetValueName(Val: ValueRef) -> *c_char;
415 pub fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
416 pub fn LLVMDumpValue(Val: ValueRef);
417 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
418 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
419 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
420 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
422 /* Operations on Uses */
423 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
424 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
425 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
426 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
428 /* Operations on Users */
429 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
430 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
431 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
433 /* Operations on constants of any type */
434 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
436 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
437 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
439 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
441 /* only for int/vector */
442 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
443 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
444 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
445 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
446 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
448 /* Operations on metadata */
449 pub fn LLVMMDStringInContext(C: ContextRef,
453 pub fn LLVMMDNodeInContext(C: ContextRef,
457 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
461 /* Operations on scalar constants */
462 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
464 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8)
466 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
471 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
472 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char)
474 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
478 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
479 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
482 /* Operations on composite constants */
483 pub fn LLVMConstStringInContext(C: ContextRef,
486 DontNullTerminate: Bool)
488 pub fn LLVMConstStructInContext(C: ContextRef,
489 ConstantVals: *ValueRef,
494 pub fn LLVMConstArray(ElementTy: TypeRef,
495 ConstantVals: *ValueRef,
498 pub fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: c_uint)
501 /* Constant expressions */
502 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
503 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
504 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
505 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
506 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
507 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
508 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
509 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
511 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
513 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
515 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
517 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
519 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
521 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
523 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
525 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
527 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
529 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
531 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
533 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
535 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
537 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
538 RHSConstant: ValueRef)
540 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
542 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
544 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
546 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
548 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
550 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
552 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
554 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
556 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
558 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
560 pub fn LLVMConstGEP(ConstantVal: ValueRef,
561 ConstantIndices: *ValueRef,
564 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
565 ConstantIndices: *ValueRef,
568 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
570 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
572 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
574 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
576 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
578 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
580 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
582 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
584 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
586 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
588 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
590 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
592 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
594 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
596 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
598 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
600 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
604 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
606 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
607 ConstantIfTrue: ValueRef,
608 ConstantIfFalse: ValueRef)
610 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
611 IndexConstant: ValueRef)
613 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
614 ElementValueConstant: ValueRef,
615 IndexConstant: ValueRef)
617 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
618 VectorBConstant: ValueRef,
619 MaskConstant: ValueRef)
621 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
625 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
626 ElementValueConstant: ValueRef,
630 pub fn LLVMConstInlineAsm(Ty: TypeRef,
632 Constraints: *c_char,
633 HasSideEffects: Bool,
636 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
640 /* Operations on global variables, functions, and aliases (globals) */
641 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
642 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
643 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
644 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
645 pub fn LLVMGetSection(Global: ValueRef) -> *c_char;
646 pub fn LLVMSetSection(Global: ValueRef, Section: *c_char);
647 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
648 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
649 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
650 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
653 /* Operations on global variables */
654 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char)
656 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
659 AddressSpace: c_uint)
661 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
662 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
663 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
664 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
665 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
666 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
667 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
668 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
669 ConstantVal: ValueRef);
670 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
671 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
672 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
673 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
675 /* Operations on aliases */
676 pub fn LLVMAddAlias(M: ModuleRef,
682 /* Operations on functions */
683 pub fn LLVMAddFunction(M: ModuleRef,
687 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
688 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
689 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
690 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
691 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
692 pub fn LLVMDeleteFunction(Fn: ValueRef);
693 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
697 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
698 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
699 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
700 pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
701 pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
702 pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
703 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
704 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
706 pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
707 pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
709 pub fn LLVMAddColdAttribute(Fn: ValueRef);
711 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
713 HighPA: c_ulonglong);
715 /* Operations on parameters */
716 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
717 pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
718 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
719 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
720 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
721 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
722 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
723 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
724 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
725 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
726 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
727 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
729 /* Operations on basic blocks */
730 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
731 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
732 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
733 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
734 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
735 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
736 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
737 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
738 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
739 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
740 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
742 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
746 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
750 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
752 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
753 MoveAfter: BasicBlockRef);
755 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
756 MoveBefore: BasicBlockRef);
758 /* Operations on instructions */
759 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
760 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
761 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
762 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
763 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
764 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
766 /* Operations on call sites */
767 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
768 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
769 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
772 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
775 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
779 /* Operations on call instructions (only) */
780 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
781 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
783 /* Operations on phi nodes */
784 pub fn LLVMAddIncoming(PhiNode: ValueRef,
785 IncomingValues: *ValueRef,
786 IncomingBlocks: *BasicBlockRef,
788 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
789 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
791 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
794 /* Instruction builders */
795 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
796 pub fn LLVMPositionBuilder(Builder: BuilderRef,
797 Block: BasicBlockRef,
799 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
801 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
802 Block: BasicBlockRef);
803 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
804 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
805 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
806 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
809 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
810 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
813 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
814 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
815 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
818 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
819 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
820 pub fn LLVMBuildAggregateRet(B: BuilderRef,
824 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
825 pub fn LLVMBuildCondBr(B: BuilderRef,
830 pub fn LLVMBuildSwitch(B: BuilderRef,
835 pub fn LLVMBuildIndirectBr(B: BuilderRef,
839 pub fn LLVMBuildInvoke(B: BuilderRef,
844 Catch: BasicBlockRef,
847 pub fn LLVMBuildLandingPad(B: BuilderRef,
853 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
854 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
856 /* Add a case to the switch instruction */
857 pub fn LLVMAddCase(Switch: ValueRef,
859 Dest: BasicBlockRef);
861 /* Add a destination to the indirectbr instruction */
862 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
864 /* Add a clause to the landing pad instruction */
865 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
867 /* Set the cleanup on a landing pad instruction */
868 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
871 pub fn LLVMBuildAdd(B: BuilderRef,
876 pub fn LLVMBuildNSWAdd(B: BuilderRef,
881 pub fn LLVMBuildNUWAdd(B: BuilderRef,
886 pub fn LLVMBuildFAdd(B: BuilderRef,
891 pub fn LLVMBuildSub(B: BuilderRef,
896 pub fn LLVMBuildNSWSub(B: BuilderRef,
901 pub fn LLVMBuildNUWSub(B: BuilderRef,
906 pub fn LLVMBuildFSub(B: BuilderRef,
911 pub fn LLVMBuildMul(B: BuilderRef,
916 pub fn LLVMBuildNSWMul(B: BuilderRef,
921 pub fn LLVMBuildNUWMul(B: BuilderRef,
926 pub fn LLVMBuildFMul(B: BuilderRef,
931 pub fn LLVMBuildUDiv(B: BuilderRef,
936 pub fn LLVMBuildSDiv(B: BuilderRef,
941 pub fn LLVMBuildExactSDiv(B: BuilderRef,
946 pub fn LLVMBuildFDiv(B: BuilderRef,
951 pub fn LLVMBuildURem(B: BuilderRef,
956 pub fn LLVMBuildSRem(B: BuilderRef,
961 pub fn LLVMBuildFRem(B: BuilderRef,
966 pub fn LLVMBuildShl(B: BuilderRef,
971 pub fn LLVMBuildLShr(B: BuilderRef,
976 pub fn LLVMBuildAShr(B: BuilderRef,
981 pub fn LLVMBuildAnd(B: BuilderRef,
986 pub fn LLVMBuildOr(B: BuilderRef,
991 pub fn LLVMBuildXor(B: BuilderRef,
996 pub fn LLVMBuildBinOp(B: BuilderRef,
1002 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1004 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1006 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1008 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1010 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char)
1014 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1016 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1021 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1023 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1028 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1029 pub fn LLVMBuildLoad(B: BuilderRef,
1030 PointerVal: ValueRef,
1034 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1037 pub fn LLVMBuildGEP(B: BuilderRef,
1043 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1049 pub fn LLVMBuildStructGEP(B: BuilderRef,
1054 pub fn LLVMBuildGlobalString(B: BuilderRef,
1058 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1064 pub fn LLVMBuildTrunc(B: BuilderRef,
1069 pub fn LLVMBuildZExt(B: BuilderRef,
1074 pub fn LLVMBuildSExt(B: BuilderRef,
1079 pub fn LLVMBuildFPToUI(B: BuilderRef,
1084 pub fn LLVMBuildFPToSI(B: BuilderRef,
1089 pub fn LLVMBuildUIToFP(B: BuilderRef,
1094 pub fn LLVMBuildSIToFP(B: BuilderRef,
1099 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1104 pub fn LLVMBuildFPExt(B: BuilderRef,
1109 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1114 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1119 pub fn LLVMBuildBitCast(B: BuilderRef,
1124 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1129 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1134 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1139 pub fn LLVMBuildCast(B: BuilderRef,
1143 Name: *c_char) -> ValueRef;
1144 pub fn LLVMBuildPointerCast(B: BuilderRef,
1149 pub fn LLVMBuildIntCast(B: BuilderRef,
1154 pub fn LLVMBuildFPCast(B: BuilderRef,
1161 pub fn LLVMBuildICmp(B: BuilderRef,
1167 pub fn LLVMBuildFCmp(B: BuilderRef,
1174 /* Miscellaneous instructions */
1175 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1177 pub fn LLVMBuildCall(B: BuilderRef,
1183 pub fn LLVMBuildSelect(B: BuilderRef,
1189 pub fn LLVMBuildVAArg(B: BuilderRef,
1194 pub fn LLVMBuildExtractElement(B: BuilderRef,
1199 pub fn LLVMBuildInsertElement(B: BuilderRef,
1205 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1211 pub fn LLVMBuildExtractValue(B: BuilderRef,
1216 pub fn LLVMBuildInsertValue(B: BuilderRef,
1223 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1225 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1227 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1233 /* Atomic Operations */
1234 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1235 PointerVal: ValueRef,
1237 Order: AtomicOrdering,
1241 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1244 Order: AtomicOrdering,
1248 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1252 Order: AtomicOrdering)
1254 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1258 Order: AtomicOrdering,
1259 SingleThreaded: Bool)
1262 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1265 /* Selected entries from the downcasts. */
1266 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1267 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1269 /** Writes a module to the specified path. Returns 0 on success. */
1270 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
1272 /** Creates target data from a target layout string. */
1273 pub fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
1274 /// Adds the target data to the given pass manager. The pass manager
1275 /// references the target data only weakly.
1276 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1277 /** Number of bytes clobbered when doing a Store to *T. */
1278 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1281 /** Number of bytes clobbered when doing a Store to *T. */
1282 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1285 /** Distance between successive elements in an array of T.
1286 Includes ABI padding. */
1287 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1289 /** Returns the preferred alignment of a type. */
1290 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1292 /** Returns the minimum alignment of a type. */
1293 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1296 /// Computes the byte offset of the indexed struct element for a
1298 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1304 * Returns the minimum alignment of a type when part of a call frame.
1306 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1309 /** Disposes target data. */
1310 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1312 /** Creates a pass manager. */
1313 pub fn LLVMCreatePassManager() -> PassManagerRef;
1315 /** Creates a function-by-function pass manager */
1316 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1319 /** Disposes a pass manager. */
1320 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1322 /** Runs a pass manager on a module. */
1323 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1325 /** Runs the function passes on the provided function. */
1326 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1329 /** Initializes all the function passes scheduled in the manager */
1330 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1332 /** Finalizes all the function passes scheduled in the manager */
1333 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1335 pub fn LLVMInitializePasses();
1337 /** Adds a verification pass. */
1338 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1340 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1341 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1342 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1343 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1344 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1345 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1346 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1347 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1348 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1349 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1350 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1351 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1352 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1353 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1354 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1355 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1356 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1357 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1358 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1359 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1360 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1361 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1362 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1363 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1364 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1365 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1366 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1367 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1368 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1369 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1370 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1371 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1372 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1373 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1374 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1376 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1377 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1378 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1379 OptimizationLevel: c_uint);
1380 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1382 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1383 PMB: PassManagerBuilderRef,
1385 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1386 PMB: PassManagerBuilderRef,
1388 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1389 PMB: PassManagerBuilderRef,
1391 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1392 PMB: PassManagerBuilderRef,
1394 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1395 PMB: PassManagerBuilderRef,
1396 PM: PassManagerRef);
1398 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1399 PMB: PassManagerBuilderRef,
1400 PM: PassManagerRef);
1402 /** Destroys a memory buffer. */
1403 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1406 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1408 /** Opens an object file. */
1409 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1410 /** Closes an object file. */
1411 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1413 /** Enumerates the sections in an object file. */
1414 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1415 /** Destroys a section iterator. */
1416 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1417 /** Returns true if the section iterator is at the end of the section
1419 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1420 SI: SectionIteratorRef)
1422 /** Moves the section iterator to point to the next section. */
1423 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1424 /** Returns the current section name. */
1425 pub fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1426 /** Returns the current section size. */
1427 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1428 /** Returns the current section contents as a string buffer. */
1429 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
1431 /** Reads the given file and returns it as a memory buffer. Use
1432 LLVMDisposeMemoryBuffer() to get rid of it. */
1433 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
1435 /** Borrows the contents of the memory buffer (doesn't copy it) */
1436 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *c_char,
1437 InputDataLength: size_t,
1438 BufferName: *c_char,
1441 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *c_char,
1442 InputDataLength: size_t,
1443 BufferName: *c_char)
1446 /** Returns a string describing the last error caused by an LLVMRust*
1448 pub fn LLVMRustGetLastError() -> *c_char;
1450 /** Prepare the JIT. Returns a memory manager that can load crates. */
1451 pub fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1453 /** Load a crate into the memory manager. */
1454 pub fn LLVMRustLoadCrate(MM: *(), Filename: *c_char) -> bool;
1456 /** Execute the JIT engine. */
1457 pub fn LLVMRustBuildJIT(MM: *(),
1459 EnableSegmentedStacks: bool)
1460 -> ExecutionEngineRef;
1462 /// Print the pass timings since static dtors aren't picking them up.
1463 pub fn LLVMRustPrintPassTimings();
1465 pub fn LLVMRustStartMultithreading() -> bool;
1467 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1469 pub fn LLVMStructSetBody(StructTy: TypeRef,
1470 ElementTypes: *TypeRef,
1471 ElementCount: c_uint,
1474 pub fn LLVMConstNamedStruct(S: TypeRef,
1475 ConstantVals: *ValueRef,
1479 /** Enables LLVM debug output. */
1480 pub fn LLVMSetDebug(Enabled: c_int);
1482 /** Prepares inline assembly. */
1483 pub fn LLVMInlineAsm(Ty: TypeRef,
1485 Constraints: *c_char,
1492 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1494 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1496 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1498 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1506 SplitName: *c_char);
1508 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1513 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1515 ParameterTypes: DIArray)
1518 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1519 Scope: DIDescriptor,
1521 LinkageName: *c_char,
1525 isLocalToUnit: bool,
1535 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1537 SizeInBits: c_ulonglong,
1538 AlignInBits: c_ulonglong,
1542 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1544 SizeInBits: c_ulonglong,
1545 AlignInBits: c_ulonglong,
1549 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1550 Scope: DIDescriptor,
1554 SizeInBits: c_ulonglong,
1555 AlignInBits: c_ulonglong,
1557 DerivedFrom: DIType,
1559 RunTimeLang: c_uint,
1560 VTableHolder: ValueRef,
1564 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1565 Scope: DIDescriptor,
1569 SizeInBits: c_ulonglong,
1570 AlignInBits: c_ulonglong,
1571 OffsetInBits: c_ulonglong,
1576 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1577 Scope: DIDescriptor,
1583 pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
1585 Scope: DIDescriptor,
1590 AlwaysPreserve: bool,
1595 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1597 AlignInBits: c_ulonglong,
1599 Subscripts: DIArray)
1602 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1604 AlignInBits: c_ulonglong,
1606 Subscripts: DIArray)
1609 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1614 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1619 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1621 VarInfo: DIVariable,
1622 InsertAtEnd: BasicBlockRef)
1625 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1627 VarInfo: DIVariable,
1628 InsertBefore: ValueRef)
1631 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1636 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1641 SizeInBits: c_ulonglong,
1642 AlignInBits: c_ulonglong,
1644 ClassType: ValueRef)
1647 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1652 SizeInBits: c_ulonglong,
1653 AlignInBits: c_ulonglong,
1656 RunTimeLang: c_uint)
1659 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1661 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1670 pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
1672 pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
1674 pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
1682 AddrOpsCount: c_uint,
1686 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1693 pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1694 pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
1696 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1698 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1700 pub fn LLVMInitializeX86TargetInfo();
1701 pub fn LLVMInitializeX86Target();
1702 pub fn LLVMInitializeX86TargetMC();
1703 pub fn LLVMInitializeX86AsmPrinter();
1704 pub fn LLVMInitializeX86AsmParser();
1705 pub fn LLVMInitializeARMTargetInfo();
1706 pub fn LLVMInitializeARMTarget();
1707 pub fn LLVMInitializeARMTargetMC();
1708 pub fn LLVMInitializeARMAsmPrinter();
1709 pub fn LLVMInitializeARMAsmParser();
1710 pub fn LLVMInitializeMipsTargetInfo();
1711 pub fn LLVMInitializeMipsTarget();
1712 pub fn LLVMInitializeMipsTargetMC();
1713 pub fn LLVMInitializeMipsAsmPrinter();
1714 pub fn LLVMInitializeMipsAsmParser();
1716 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *c_char) -> bool;
1717 pub fn LLVMRustCreateTargetMachine(Triple: *c_char,
1720 Model: CodeGenModel,
1722 Level: CodeGenOptLevel,
1724 UseSoftFP: bool) -> TargetMachineRef;
1725 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
1726 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
1729 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
1731 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef);
1732 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
1733 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
1737 FileType: FileType) -> bool;
1738 pub fn LLVMRustPrintModule(PM: PassManagerRef,
1741 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: **c_char);
1742 pub fn LLVMRustPrintPasses();
1743 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *c_char);
1744 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
1745 AddLifetimes: bool);
1749 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
1751 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
1754 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
1756 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
1759 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
1761 llvm::LLVMSetLinkage(Global, Link as c_uint);
1765 pub fn SetUnnamedAddr(Global: ValueRef, Unnamed: bool) {
1767 llvm::LLVMSetUnnamedAddr(Global, Unnamed as Bool);
1771 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
1773 llvm::LLVMSetThreadLocal(global, is_thread_local as Bool);
1777 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1779 llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
1782 pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1784 llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
1788 pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
1790 llvm::LLVMAddFunctionAttr(Fn, attr as c_uint)
1793 /* Memory-managed object interface to type handles. */
1795 pub struct TypeNames {
1796 type_names: HashMap<TypeRef, ~str>,
1797 named_types: HashMap<~str, TypeRef>
1801 pub fn new() -> TypeNames {
1803 type_names: HashMap::new(),
1804 named_types: HashMap::new()
1808 pub fn associate_type(&mut self, s: &str, t: &Type) {
1809 assert!(self.type_names.insert(t.to_ref(), s.to_owned()));
1810 assert!(self.named_types.insert(s.to_owned(), t.to_ref()));
1813 pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
1814 match self.type_names.find(&ty.to_ref()) {
1815 Some(a) => Some(a.slice(0, a.len())),
1820 pub fn find_type(&self, s: &str) -> Option<Type> {
1821 self.named_types.find_equiv(&s).map(|x| Type::from_ref(*x))
1824 pub fn type_to_str(&self, ty: Type) -> ~str {
1826 let s = llvm::LLVMTypeToString(ty.to_ref());
1827 let ret = from_c_str(s);
1833 pub fn types_to_str(&self, tys: &[Type]) -> ~str {
1834 let strs = tys.map(|t| self.type_to_str(*t));
1835 format!("[{}]", strs.connect(","))
1838 pub fn val_to_str(&self, val: ValueRef) -> ~str {
1840 let ty = Type::from_ref(llvm::LLVMTypeOf(val));
1841 self.type_to_str(ty)
1846 /* Memory-managed interface to target data. */
1848 pub struct target_data_res {
1852 impl Drop for target_data_res {
1853 fn drop(&mut self) {
1855 llvm::LLVMDisposeTargetData(self.TD);
1860 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
1866 pub struct TargetData {
1867 lltd: TargetDataRef,
1868 dtor: @target_data_res
1871 pub fn mk_target_data(string_rep: &str) -> TargetData {
1872 let lltd = string_rep.with_c_str(|buf| {
1873 unsafe { llvm::LLVMCreateTargetData(buf) }
1878 dtor: @target_data_res(lltd)
1882 /* Memory-managed interface to pass managers. */
1884 pub struct pass_manager_res {
1888 impl Drop for pass_manager_res {
1889 fn drop(&mut self) {
1891 llvm::LLVMDisposePassManager(self.PM);
1896 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
1902 pub struct PassManager {
1903 llpm: PassManagerRef,
1904 dtor: @pass_manager_res
1907 pub fn mk_pass_manager() -> PassManager {
1909 let llpm = llvm::LLVMCreatePassManager();
1913 dtor: @pass_manager_res(llpm)
1918 /* Memory-managed interface to object files. */
1920 pub struct ObjectFile {
1921 llof: ObjectFileRef,
1925 // This will take ownership of llmb
1926 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1928 let llof = llvm::LLVMCreateObjectFile(llmb);
1929 if llof as int == 0 {
1930 llvm::LLVMDisposeMemoryBuffer(llmb);
1941 impl Drop for ObjectFile {
1942 fn drop(&mut self) {
1944 llvm::LLVMDisposeObjectFile(self.llof);
1949 /* Memory-managed interface to section iterators. */
1951 pub struct section_iter_res {
1952 SI: SectionIteratorRef,
1955 impl Drop for section_iter_res {
1956 fn drop(&mut self) {
1958 llvm::LLVMDisposeSectionIterator(self.SI);
1963 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
1969 pub struct SectionIter {
1970 llsi: SectionIteratorRef,
1971 dtor: @section_iter_res
1974 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
1976 let llsi = llvm::LLVMGetSections(llof);
1979 dtor: @section_iter_res(llsi)