1 // Copyright 2012-2014 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)]
12 #![allow(non_camel_case_types)]
13 #![allow(non_snake_case_functions)]
16 use std::c_str::ToCStr;
17 use std::cell::RefCell;
18 use std::collections::HashMap;
19 use libc::{c_uint, c_ushort, c_void, free, uint64_t};
20 use std::str::raw::from_c_str;
22 use middle::trans::type_::Type;
24 pub type Opcode = u32;
25 pub type Bool = c_uint;
27 pub static True: Bool = 1 as Bool;
28 pub static False: Bool = 0 as Bool;
30 // Consts for the LLVM CallConv type, pre-cast to uint.
32 #[deriving(PartialEq)]
37 X86StdcallCallConv = 64,
38 X86FastcallCallConv = 65,
43 LLVMDefaultVisibility = 0,
45 ProtectedVisibility = 2,
48 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
49 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
50 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
51 // they've been removed in upstream LLVM commit r203866.
54 AvailableExternallyLinkage = 1,
55 LinkOnceAnyLinkage = 2,
56 LinkOnceODRLinkage = 3,
62 ExternalWeakLinkage = 12,
68 ZExtAttribute = 1 << 0,
69 SExtAttribute = 1 << 1,
70 NoReturnAttribute = 1 << 2,
71 InRegAttribute = 1 << 3,
72 StructRetAttribute = 1 << 4,
73 NoUnwindAttribute = 1 << 5,
74 NoAliasAttribute = 1 << 6,
75 ByValAttribute = 1 << 7,
76 NestAttribute = 1 << 8,
77 ReadNoneAttribute = 1 << 9,
78 ReadOnlyAttribute = 1 << 10,
79 NoInlineAttribute = 1 << 11,
80 AlwaysInlineAttribute = 1 << 12,
81 OptimizeForSizeAttribute = 1 << 13,
82 StackProtectAttribute = 1 << 14,
83 StackProtectReqAttribute = 1 << 15,
84 AlignmentAttribute = 31 << 16,
85 NoCaptureAttribute = 1 << 21,
86 NoRedZoneAttribute = 1 << 22,
87 NoImplicitFloatAttribute = 1 << 23,
88 NakedAttribute = 1 << 24,
89 InlineHintAttribute = 1 << 25,
90 StackAttribute = 7 << 26,
91 ReturnsTwiceAttribute = 1 << 29,
92 UWTableAttribute = 1 << 30,
93 NonLazyBindAttribute = 1 << 31,
97 pub enum OtherAttribute {
98 // The following are not really exposed in
99 // the LLVM c api so instead to add these
100 // we call a wrapper function in RustWrapper
101 // that uses the C++ api.
102 SanitizeAddressAttribute = 1 << 32,
103 MinSizeAttribute = 1 << 33,
104 NoDuplicateAttribute = 1 << 34,
105 StackProtectStrongAttribute = 1 << 35,
106 SanitizeThreadAttribute = 1 << 36,
107 SanitizeMemoryAttribute = 1 << 37,
108 NoBuiltinAttribute = 1 << 38,
109 ReturnedAttribute = 1 << 39,
110 ColdAttribute = 1 << 40,
111 BuiltinAttribute = 1 << 41,
112 OptimizeNoneAttribute = 1 << 42,
113 InAllocaAttribute = 1 << 43,
114 NonNullAttribute = 1 << 44,
118 pub enum AttributeSet {
123 // enum for the LLVM IntPredicate type
124 pub enum IntPredicate {
137 // enum for the LLVM RealPredicate type
138 pub enum RealPredicate {
139 RealPredicateFalse = 0,
154 RealPredicateTrue = 15,
157 // The LLVM TypeKind type - must stay in sync with the def of
158 // LLVMTypeKind in llvm/include/llvm-c/Core.h
159 #[deriving(PartialEq)]
181 pub enum AtomicBinOp {
196 pub enum AtomicOrdering {
200 // Consume = 3, // Not specified yet.
204 SequentiallyConsistent = 7
207 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
223 // Inline Asm Dialect
224 pub enum AsmDialect {
229 #[deriving(PartialEq)]
231 pub enum CodeGenOptLevel {
232 CodeGenLevelNone = 0,
233 CodeGenLevelLess = 1,
234 CodeGenLevelDefault = 2,
235 CodeGenLevelAggressive = 3,
243 RelocDynamicNoPic = 3,
247 pub enum CodeGenModel {
248 CodeModelDefault = 0,
249 CodeModelJITDefault = 1,
256 // Opaque pointer types
257 pub enum Module_opaque {}
258 pub type ModuleRef = *Module_opaque;
259 pub enum Context_opaque {}
260 pub type ContextRef = *Context_opaque;
261 pub enum Type_opaque {}
262 pub type TypeRef = *Type_opaque;
263 pub enum Value_opaque {}
264 pub type ValueRef = *Value_opaque;
265 pub enum BasicBlock_opaque {}
266 pub type BasicBlockRef = *BasicBlock_opaque;
267 pub enum Builder_opaque {}
268 pub type BuilderRef = *Builder_opaque;
269 pub enum ExecutionEngine_opaque {}
270 pub type ExecutionEngineRef = *ExecutionEngine_opaque;
271 pub enum MemoryBuffer_opaque {}
272 pub type MemoryBufferRef = *MemoryBuffer_opaque;
273 pub enum PassManager_opaque {}
274 pub type PassManagerRef = *PassManager_opaque;
275 pub enum PassManagerBuilder_opaque {}
276 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
277 pub enum Use_opaque {}
278 pub type UseRef = *Use_opaque;
279 pub enum TargetData_opaque {}
280 pub type TargetDataRef = *TargetData_opaque;
281 pub enum ObjectFile_opaque {}
282 pub type ObjectFileRef = *ObjectFile_opaque;
283 pub enum SectionIterator_opaque {}
284 pub type SectionIteratorRef = *SectionIterator_opaque;
285 pub enum Pass_opaque {}
286 pub type PassRef = *Pass_opaque;
287 pub enum TargetMachine_opaque {}
288 pub type TargetMachineRef = *TargetMachine_opaque;
289 pub enum Archive_opaque {}
290 pub type ArchiveRef = *Archive_opaque;
293 use super::{ValueRef};
295 pub enum DIBuilder_opaque {}
296 pub type DIBuilderRef = *DIBuilder_opaque;
298 pub type DIDescriptor = ValueRef;
299 pub type DIScope = DIDescriptor;
300 pub type DILocation = DIDescriptor;
301 pub type DIFile = DIScope;
302 pub type DILexicalBlock = DIScope;
303 pub type DISubprogram = DIScope;
304 pub type DIType = DIDescriptor;
305 pub type DIBasicType = DIType;
306 pub type DIDerivedType = DIType;
307 pub type DICompositeType = DIDerivedType;
308 pub type DIVariable = DIDescriptor;
309 pub type DIGlobalVariable = DIDescriptor;
310 pub type DIArray = DIDescriptor;
311 pub type DISubrange = DIDescriptor;
313 pub enum DIDescriptorFlags {
314 FlagPrivate = 1 << 0,
315 FlagProtected = 1 << 1,
316 FlagFwdDecl = 1 << 2,
317 FlagAppleBlock = 1 << 3,
318 FlagBlockByrefStruct = 1 << 4,
319 FlagVirtual = 1 << 5,
320 FlagArtificial = 1 << 6,
321 FlagExplicit = 1 << 7,
322 FlagPrototyped = 1 << 8,
323 FlagObjcClassComplete = 1 << 9,
324 FlagObjectPointer = 1 << 10,
325 FlagVector = 1 << 11,
326 FlagStaticMember = 1 << 12
331 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
332 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
333 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
334 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
335 use super::{ValueRef, TargetMachineRef, FileType, ArchiveRef};
336 use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
337 use super::debuginfo::*;
338 use libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong,
341 // Link to our native llvm bindings (things that we need to use the C++ api
342 // for) and because llvm is written in C++ we need to link against libstdc++
344 // You'll probably notice that there is an omission of all LLVM libraries
345 // from this location. This is because the set of LLVM libraries that we
346 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
347 // figure out the exact set of libraries. To do this, the build system
348 // generates an llvmdeps.rs file next to this one which will be
349 // automatically updated whenever LLVM is updated to include an up-to-date
350 // set of the libraries we need to link to LLVM for.
351 #[link(name = "rustllvm", kind = "static")]
353 /* Create and destroy contexts. */
354 pub fn LLVMContextCreate() -> ContextRef;
355 pub fn LLVMContextDispose(C: ContextRef);
356 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
361 /* Create and destroy modules. */
362 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
365 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
366 pub fn LLVMDisposeModule(M: ModuleRef);
368 /** Data layout. See Module::getDataLayout. */
369 pub fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
370 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
372 /** Target triple. See Module::getTargetTriple. */
373 pub fn LLVMGetTarget(M: ModuleRef) -> *c_char;
374 pub fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
376 /** See Module::dump. */
377 pub fn LLVMDumpModule(M: ModuleRef);
379 /** See Module::setModuleInlineAsm. */
380 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
382 /** See llvm::LLVMTypeKind::getTypeID. */
383 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
385 /** See llvm::LLVMType::getContext. */
386 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
388 /* Operations on integer types */
389 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
390 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
391 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
392 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
393 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
394 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
397 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
399 /* Operations on real types */
400 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
401 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
402 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
403 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
404 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
406 /* Operations on function types */
407 pub fn LLVMFunctionType(ReturnType: TypeRef,
408 ParamTypes: *TypeRef,
412 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
413 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
414 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
415 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
417 /* Operations on struct types */
418 pub fn LLVMStructTypeInContext(C: ContextRef,
419 ElementTypes: *TypeRef,
420 ElementCount: c_uint,
423 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
424 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
426 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
428 /* Operations on array, pointer, and vector types (sequence types) */
429 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
430 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
432 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
435 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
436 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
437 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
438 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
440 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
442 /* Operations on other types */
443 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
444 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
445 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
447 /* Operations on all values */
448 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
449 pub fn LLVMGetValueName(Val: ValueRef) -> *c_char;
450 pub fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
451 pub fn LLVMDumpValue(Val: ValueRef);
452 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
453 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
454 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
455 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
457 /* Operations on Uses */
458 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
459 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
460 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
461 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
463 /* Operations on Users */
464 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
465 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
466 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
468 /* Operations on constants of any type */
469 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
471 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
472 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
474 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
476 /* only for int/vector */
477 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
478 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
479 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
480 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
481 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
483 /* Operations on metadata */
484 pub fn LLVMMDStringInContext(C: ContextRef,
488 pub fn LLVMMDNodeInContext(C: ContextRef,
492 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
496 /* Operations on scalar constants */
497 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
499 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8)
501 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
506 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
507 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char)
509 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
513 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
514 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
517 /* Operations on composite constants */
518 pub fn LLVMConstStringInContext(C: ContextRef,
521 DontNullTerminate: Bool)
523 pub fn LLVMConstStructInContext(C: ContextRef,
524 ConstantVals: *ValueRef,
529 pub fn LLVMConstArray(ElementTy: TypeRef,
530 ConstantVals: *ValueRef,
533 pub fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: c_uint)
536 /* Constant expressions */
537 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
538 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
539 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
540 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
541 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
542 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
543 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
544 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
546 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
548 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
550 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
552 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
554 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
556 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
558 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
560 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
562 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
564 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
566 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
568 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
570 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
572 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
573 RHSConstant: ValueRef)
575 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
577 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
579 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
581 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
583 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
585 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
587 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
589 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
591 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
593 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
595 pub fn LLVMConstGEP(ConstantVal: ValueRef,
596 ConstantIndices: *ValueRef,
599 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
600 ConstantIndices: *ValueRef,
603 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
605 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
607 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
609 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
611 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
613 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
615 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
617 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
619 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
621 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
623 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
625 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
627 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
629 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
631 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
633 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
635 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
639 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
641 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
642 ConstantIfTrue: ValueRef,
643 ConstantIfFalse: ValueRef)
645 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
646 IndexConstant: ValueRef)
648 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
649 ElementValueConstant: ValueRef,
650 IndexConstant: ValueRef)
652 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
653 VectorBConstant: ValueRef,
654 MaskConstant: ValueRef)
656 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
660 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
661 ElementValueConstant: ValueRef,
665 pub fn LLVMConstInlineAsm(Ty: TypeRef,
667 Constraints: *c_char,
668 HasSideEffects: Bool,
671 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
675 /* Operations on global variables, functions, and aliases (globals) */
676 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
677 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
678 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
679 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
680 pub fn LLVMGetSection(Global: ValueRef) -> *c_char;
681 pub fn LLVMSetSection(Global: ValueRef, Section: *c_char);
682 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
683 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
684 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
685 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
688 /* Operations on global variables */
689 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char)
691 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
694 AddressSpace: c_uint)
696 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
697 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
698 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
699 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
700 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
701 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
702 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
703 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
704 ConstantVal: ValueRef);
705 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
706 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
707 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
708 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
710 /* Operations on aliases */
711 pub fn LLVMAddAlias(M: ModuleRef,
717 /* Operations on functions */
718 pub fn LLVMAddFunction(M: ModuleRef,
722 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
723 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
724 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
725 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
726 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
727 pub fn LLVMDeleteFunction(Fn: ValueRef);
728 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
732 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
733 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
734 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
735 pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
736 pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
737 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
738 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *c_char);
739 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *c_char);
740 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
742 /* Operations on parameters */
743 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
744 pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
745 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
746 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
747 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
748 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
749 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
750 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
751 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
752 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
753 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
754 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
756 /* Operations on basic blocks */
757 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
758 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
759 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
760 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
761 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
762 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
763 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
764 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
765 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
766 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
767 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
769 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
773 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
777 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
779 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
780 MoveAfter: BasicBlockRef);
782 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
783 MoveBefore: BasicBlockRef);
785 /* Operations on instructions */
786 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
787 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
788 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
789 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
790 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
791 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
793 /* Operations on call sites */
794 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
795 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
796 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
799 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
802 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
805 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
809 /* Operations on call instructions (only) */
810 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
811 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
813 /* Operations on load/store instructions (only) */
814 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
815 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
817 /* Operations on phi nodes */
818 pub fn LLVMAddIncoming(PhiNode: ValueRef,
819 IncomingValues: *ValueRef,
820 IncomingBlocks: *BasicBlockRef,
822 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
823 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
825 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
828 /* Instruction builders */
829 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
830 pub fn LLVMPositionBuilder(Builder: BuilderRef,
831 Block: BasicBlockRef,
833 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
835 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
836 Block: BasicBlockRef);
837 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
838 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
839 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
840 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
843 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
844 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
847 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
848 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
849 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
852 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
853 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
854 pub fn LLVMBuildAggregateRet(B: BuilderRef,
858 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
859 pub fn LLVMBuildCondBr(B: BuilderRef,
864 pub fn LLVMBuildSwitch(B: BuilderRef,
869 pub fn LLVMBuildIndirectBr(B: BuilderRef,
873 pub fn LLVMBuildInvoke(B: BuilderRef,
878 Catch: BasicBlockRef,
881 pub fn LLVMBuildLandingPad(B: BuilderRef,
887 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
888 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
890 /* Add a case to the switch instruction */
891 pub fn LLVMAddCase(Switch: ValueRef,
893 Dest: BasicBlockRef);
895 /* Add a destination to the indirectbr instruction */
896 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
898 /* Add a clause to the landing pad instruction */
899 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
901 /* Set the cleanup on a landing pad instruction */
902 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
905 pub fn LLVMBuildAdd(B: BuilderRef,
910 pub fn LLVMBuildNSWAdd(B: BuilderRef,
915 pub fn LLVMBuildNUWAdd(B: BuilderRef,
920 pub fn LLVMBuildFAdd(B: BuilderRef,
925 pub fn LLVMBuildSub(B: BuilderRef,
930 pub fn LLVMBuildNSWSub(B: BuilderRef,
935 pub fn LLVMBuildNUWSub(B: BuilderRef,
940 pub fn LLVMBuildFSub(B: BuilderRef,
945 pub fn LLVMBuildMul(B: BuilderRef,
950 pub fn LLVMBuildNSWMul(B: BuilderRef,
955 pub fn LLVMBuildNUWMul(B: BuilderRef,
960 pub fn LLVMBuildFMul(B: BuilderRef,
965 pub fn LLVMBuildUDiv(B: BuilderRef,
970 pub fn LLVMBuildSDiv(B: BuilderRef,
975 pub fn LLVMBuildExactSDiv(B: BuilderRef,
980 pub fn LLVMBuildFDiv(B: BuilderRef,
985 pub fn LLVMBuildURem(B: BuilderRef,
990 pub fn LLVMBuildSRem(B: BuilderRef,
995 pub fn LLVMBuildFRem(B: BuilderRef,
1000 pub fn LLVMBuildShl(B: BuilderRef,
1005 pub fn LLVMBuildLShr(B: BuilderRef,
1010 pub fn LLVMBuildAShr(B: BuilderRef,
1015 pub fn LLVMBuildAnd(B: BuilderRef,
1020 pub fn LLVMBuildOr(B: BuilderRef,
1025 pub fn LLVMBuildXor(B: BuilderRef,
1030 pub fn LLVMBuildBinOp(B: BuilderRef,
1036 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1038 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1040 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1042 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1044 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char)
1048 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1050 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1055 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1057 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1062 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1063 pub fn LLVMBuildLoad(B: BuilderRef,
1064 PointerVal: ValueRef,
1068 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1071 pub fn LLVMBuildGEP(B: BuilderRef,
1077 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1083 pub fn LLVMBuildStructGEP(B: BuilderRef,
1088 pub fn LLVMBuildGlobalString(B: BuilderRef,
1092 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1098 pub fn LLVMBuildTrunc(B: BuilderRef,
1103 pub fn LLVMBuildZExt(B: BuilderRef,
1108 pub fn LLVMBuildSExt(B: BuilderRef,
1113 pub fn LLVMBuildFPToUI(B: BuilderRef,
1118 pub fn LLVMBuildFPToSI(B: BuilderRef,
1123 pub fn LLVMBuildUIToFP(B: BuilderRef,
1128 pub fn LLVMBuildSIToFP(B: BuilderRef,
1133 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1138 pub fn LLVMBuildFPExt(B: BuilderRef,
1143 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1148 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1153 pub fn LLVMBuildBitCast(B: BuilderRef,
1158 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1163 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1168 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1173 pub fn LLVMBuildCast(B: BuilderRef,
1177 Name: *c_char) -> ValueRef;
1178 pub fn LLVMBuildPointerCast(B: BuilderRef,
1183 pub fn LLVMBuildIntCast(B: BuilderRef,
1188 pub fn LLVMBuildFPCast(B: BuilderRef,
1195 pub fn LLVMBuildICmp(B: BuilderRef,
1201 pub fn LLVMBuildFCmp(B: BuilderRef,
1208 /* Miscellaneous instructions */
1209 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1211 pub fn LLVMBuildCall(B: BuilderRef,
1217 pub fn LLVMBuildSelect(B: BuilderRef,
1223 pub fn LLVMBuildVAArg(B: BuilderRef,
1228 pub fn LLVMBuildExtractElement(B: BuilderRef,
1233 pub fn LLVMBuildInsertElement(B: BuilderRef,
1239 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1245 pub fn LLVMBuildExtractValue(B: BuilderRef,
1250 pub fn LLVMBuildInsertValue(B: BuilderRef,
1257 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1259 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1261 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1267 /* Atomic Operations */
1268 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1269 PointerVal: ValueRef,
1271 Order: AtomicOrdering,
1275 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1278 Order: AtomicOrdering,
1282 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1286 Order: AtomicOrdering,
1287 FailureOrder: AtomicOrdering)
1289 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1293 Order: AtomicOrdering,
1294 SingleThreaded: Bool)
1297 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1300 /* Selected entries from the downcasts. */
1301 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1302 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1304 /** Writes a module to the specified path. Returns 0 on success. */
1305 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
1307 /** Creates target data from a target layout string. */
1308 pub fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
1309 /// Adds the target data to the given pass manager. The pass manager
1310 /// references the target data only weakly.
1311 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1312 /** Number of bytes clobbered when doing a Store to *T. */
1313 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1316 /** Number of bytes clobbered when doing a Store to *T. */
1317 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1320 /** Distance between successive elements in an array of T.
1321 Includes ABI padding. */
1322 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1324 /** Returns the preferred alignment of a type. */
1325 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1327 /** Returns the minimum alignment of a type. */
1328 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1331 /// Computes the byte offset of the indexed struct element for a
1333 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1339 * Returns the minimum alignment of a type when part of a call frame.
1341 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1344 /** Disposes target data. */
1345 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1347 /** Creates a pass manager. */
1348 pub fn LLVMCreatePassManager() -> PassManagerRef;
1350 /** Creates a function-by-function pass manager */
1351 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1354 /** Disposes a pass manager. */
1355 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1357 /** Runs a pass manager on a module. */
1358 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1360 /** Runs the function passes on the provided function. */
1361 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1364 /** Initializes all the function passes scheduled in the manager */
1365 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1367 /** Finalizes all the function passes scheduled in the manager */
1368 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1370 pub fn LLVMInitializePasses();
1372 /** Adds a verification pass. */
1373 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1375 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1376 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1377 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1378 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1379 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1380 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1381 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1382 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1383 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1384 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1385 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1386 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1387 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1388 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1389 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1390 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1391 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1392 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1393 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1394 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1395 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1396 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1397 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1398 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1399 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1400 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1401 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1402 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1403 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1404 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1405 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1406 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1407 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1408 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1409 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1411 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1412 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1413 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1414 OptimizationLevel: c_uint);
1415 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1417 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1418 PMB: PassManagerBuilderRef,
1420 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1421 PMB: PassManagerBuilderRef,
1423 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1424 PMB: PassManagerBuilderRef,
1426 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1427 PMB: PassManagerBuilderRef,
1429 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1430 PMB: PassManagerBuilderRef,
1431 PM: PassManagerRef);
1433 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1434 PMB: PassManagerBuilderRef,
1435 PM: PassManagerRef);
1436 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1437 PMB: PassManagerBuilderRef,
1442 /** Destroys a memory buffer. */
1443 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1446 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1448 /** Opens an object file. */
1449 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1450 /** Closes an object file. */
1451 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1453 /** Enumerates the sections in an object file. */
1454 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1455 /** Destroys a section iterator. */
1456 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1457 /** Returns true if the section iterator is at the end of the section
1459 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1460 SI: SectionIteratorRef)
1462 /** Moves the section iterator to point to the next section. */
1463 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1464 /** Returns the current section size. */
1465 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1466 /** Returns the current section contents as a string buffer. */
1467 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
1469 /** Reads the given file and returns it as a memory buffer. Use
1470 LLVMDisposeMemoryBuffer() to get rid of it. */
1471 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
1473 /** Borrows the contents of the memory buffer (doesn't copy it) */
1474 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *c_char,
1475 InputDataLength: size_t,
1476 BufferName: *c_char,
1479 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *c_char,
1480 InputDataLength: size_t,
1481 BufferName: *c_char)
1484 pub fn LLVMIsMultithreaded() -> Bool;
1485 pub fn LLVMStartMultithreaded() -> Bool;
1487 /** Returns a string describing the last error caused by an LLVMRust*
1489 pub fn LLVMRustGetLastError() -> *c_char;
1491 /// Print the pass timings since static dtors aren't picking them up.
1492 pub fn LLVMRustPrintPassTimings();
1494 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1496 pub fn LLVMStructSetBody(StructTy: TypeRef,
1497 ElementTypes: *TypeRef,
1498 ElementCount: c_uint,
1501 pub fn LLVMConstNamedStruct(S: TypeRef,
1502 ConstantVals: *ValueRef,
1506 /** Enables LLVM debug output. */
1507 pub fn LLVMSetDebug(Enabled: c_int);
1509 /** Prepares inline assembly. */
1510 pub fn LLVMInlineAsm(Ty: TypeRef,
1512 Constraints: *c_char,
1518 pub static LLVMRustDebugMetadataVersion: u32;
1520 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1524 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1526 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1528 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1530 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1538 SplitName: *c_char);
1540 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1545 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1547 ParameterTypes: DIArray)
1550 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1551 Scope: DIDescriptor,
1553 LinkageName: *c_char,
1557 isLocalToUnit: bool,
1567 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1569 SizeInBits: c_ulonglong,
1570 AlignInBits: c_ulonglong,
1574 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1576 SizeInBits: c_ulonglong,
1577 AlignInBits: c_ulonglong,
1581 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1582 Scope: DIDescriptor,
1586 SizeInBits: c_ulonglong,
1587 AlignInBits: c_ulonglong,
1589 DerivedFrom: DIType,
1591 RunTimeLang: c_uint,
1592 VTableHolder: ValueRef,
1596 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1597 Scope: DIDescriptor,
1601 SizeInBits: c_ulonglong,
1602 AlignInBits: c_ulonglong,
1603 OffsetInBits: c_ulonglong,
1608 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1609 Scope: DIDescriptor,
1613 Discriminator: c_uint)
1616 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1617 Context: DIDescriptor,
1619 LinkageName: *c_char,
1623 isLocalToUnit: bool,
1626 -> DIGlobalVariable;
1628 pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
1630 Scope: DIDescriptor,
1635 AlwaysPreserve: bool,
1640 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1642 AlignInBits: c_ulonglong,
1644 Subscripts: DIArray)
1647 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1649 AlignInBits: c_ulonglong,
1651 Subscripts: DIArray)
1654 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1659 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1664 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1666 VarInfo: DIVariable,
1667 InsertAtEnd: BasicBlockRef)
1670 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1672 VarInfo: DIVariable,
1673 InsertBefore: ValueRef)
1676 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1681 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1686 SizeInBits: c_ulonglong,
1687 AlignInBits: c_ulonglong,
1689 ClassType: ValueRef)
1692 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1697 SizeInBits: c_ulonglong,
1698 AlignInBits: c_ulonglong,
1701 RunTimeLang: c_uint,
1705 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1707 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1716 pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
1718 pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
1720 pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
1728 AddrOpsCount: c_uint,
1732 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1739 pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1740 pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
1741 pub fn LLVMValueToString(value_ref: ValueRef) -> *c_char;
1743 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1745 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1747 pub fn LLVMInitializeX86TargetInfo();
1748 pub fn LLVMInitializeX86Target();
1749 pub fn LLVMInitializeX86TargetMC();
1750 pub fn LLVMInitializeX86AsmPrinter();
1751 pub fn LLVMInitializeX86AsmParser();
1752 pub fn LLVMInitializeARMTargetInfo();
1753 pub fn LLVMInitializeARMTarget();
1754 pub fn LLVMInitializeARMTargetMC();
1755 pub fn LLVMInitializeARMAsmPrinter();
1756 pub fn LLVMInitializeARMAsmParser();
1757 pub fn LLVMInitializeMipsTargetInfo();
1758 pub fn LLVMInitializeMipsTarget();
1759 pub fn LLVMInitializeMipsTargetMC();
1760 pub fn LLVMInitializeMipsAsmPrinter();
1761 pub fn LLVMInitializeMipsAsmParser();
1763 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *c_char) -> bool;
1764 pub fn LLVMRustCreateTargetMachine(Triple: *c_char,
1767 Model: CodeGenModel,
1769 Level: CodeGenOptLevel,
1772 NoFramePointerElim: bool,
1773 FunctionSections: bool,
1774 DataSections: bool) -> TargetMachineRef;
1775 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
1776 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
1779 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
1781 DisableSimplifyLibCalls: bool);
1782 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
1783 DisableSimplifyLibCalls: bool);
1784 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
1785 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
1789 FileType: FileType) -> bool;
1790 pub fn LLVMRustPrintModule(PM: PassManagerRef,
1793 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: **c_char);
1794 pub fn LLVMRustPrintPasses();
1795 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *c_char);
1796 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
1797 AddLifetimes: bool);
1798 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
1800 len: size_t) -> bool;
1801 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
1804 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
1806 pub fn LLVMRustOpenArchive(path: *c_char) -> ArchiveRef;
1807 pub fn LLVMRustArchiveReadSection(AR: ArchiveRef, name: *c_char,
1808 out_len: *mut size_t) -> *c_char;
1809 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
1811 pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef);
1812 pub fn LLVMVersionMajor() -> c_int;
1813 pub fn LLVMVersionMinor() -> c_int;
1815 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
1816 data: *mut *c_char) -> c_int;
1820 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
1822 llvm::LLVMSetInstructionCallConv(instr, cc as c_uint);
1825 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
1827 llvm::LLVMSetFunctionCallConv(fn_, cc as c_uint);
1830 pub fn SetLinkage(global: ValueRef, link: Linkage) {
1832 llvm::LLVMSetLinkage(global, link as c_uint);
1836 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
1838 llvm::LLVMSetUnnamedAddr(global, unnamed as Bool);
1842 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
1844 llvm::LLVMSetThreadLocal(global, is_thread_local as Bool);
1848 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
1850 llvm::LLVMConstICmp(pred as c_ushort, v1, v2)
1853 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
1855 llvm::LLVMConstFCmp(pred as c_ushort, v1, v2)
1859 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
1861 llvm::LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr as uint64_t)
1864 /* Memory-managed object interface to type handles. */
1866 pub struct TypeNames {
1867 named_types: RefCell<HashMap<String, TypeRef>>,
1871 pub fn new() -> TypeNames {
1873 named_types: RefCell::new(HashMap::new())
1877 pub fn associate_type(&self, s: &str, t: &Type) {
1878 assert!(self.named_types.borrow_mut().insert(s.to_string(),
1882 pub fn find_type(&self, s: &str) -> Option<Type> {
1883 self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x))
1886 pub fn type_to_str(&self, ty: Type) -> String {
1888 let s = llvm::LLVMTypeToString(ty.to_ref());
1889 let ret = from_c_str(s);
1890 free(s as *mut c_void);
1895 pub fn types_to_str(&self, tys: &[Type]) -> String {
1896 let strs: Vec<String> = tys.iter().map(|t| self.type_to_str(*t)).collect();
1897 format!("[{}]", strs.connect(",").to_string())
1900 pub fn val_to_str(&self, val: ValueRef) -> String {
1902 let s = llvm::LLVMValueToString(val);
1903 let ret = from_c_str(s);
1904 free(s as *mut c_void);
1910 /* Memory-managed interface to target data. */
1912 pub struct TargetData {
1913 pub lltd: TargetDataRef
1916 impl Drop for TargetData {
1917 fn drop(&mut self) {
1919 llvm::LLVMDisposeTargetData(self.lltd);
1924 pub fn mk_target_data(string_rep: &str) -> TargetData {
1926 lltd: string_rep.with_c_str(|buf| {
1927 unsafe { llvm::LLVMCreateTargetData(buf) }
1932 /* Memory-managed interface to object files. */
1934 pub struct ObjectFile {
1935 pub llof: ObjectFileRef,
1939 // This will take ownership of llmb
1940 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1942 let llof = llvm::LLVMCreateObjectFile(llmb);
1943 if llof as int == 0 {
1944 // LLVMCreateObjectFile took ownership of llmb
1955 impl Drop for ObjectFile {
1956 fn drop(&mut self) {
1958 llvm::LLVMDisposeObjectFile(self.llof);
1963 /* Memory-managed interface to section iterators. */
1965 pub struct SectionIter {
1966 pub llsi: SectionIteratorRef
1969 impl Drop for SectionIter {
1970 fn drop(&mut self) {
1972 llvm::LLVMDisposeSectionIterator(self.llsi);
1977 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
1980 llsi: llvm::LLVMGetSections(llof)