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)];
12 #[allow(non_camel_case_types)];
14 use std::c_str::ToCStr;
15 use std::cell::RefCell;
16 use collections::HashMap;
17 use std::libc::{c_uint, c_ushort, c_void, free};
18 use std::str::raw::from_c_str;
20 use middle::trans::type_::Type;
22 pub type Opcode = u32;
23 pub type Bool = c_uint;
25 pub static True: Bool = 1 as Bool;
26 pub static False: Bool = 0 as Bool;
28 // Consts for the LLVM CallConv type, pre-cast to uint.
35 X86StdcallCallConv = 64,
36 X86FastcallCallConv = 65,
41 LLVMDefaultVisibility = 0,
43 ProtectedVisibility = 2,
46 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
47 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
48 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
49 // they've been removed in upstream LLVM commit r203866.
52 AvailableExternallyLinkage = 1,
53 LinkOnceAnyLinkage = 2,
54 LinkOnceODRLinkage = 3,
60 ExternalWeakLinkage = 12,
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;
260 pub enum Archive_opaque {}
261 pub type ArchiveRef = *Archive_opaque;
264 use super::{ValueRef};
266 pub enum DIBuilder_opaque {}
267 pub type DIBuilderRef = *DIBuilder_opaque;
269 pub type DIDescriptor = ValueRef;
270 pub type DIScope = DIDescriptor;
271 pub type DILocation = DIDescriptor;
272 pub type DIFile = DIScope;
273 pub type DILexicalBlock = DIScope;
274 pub type DISubprogram = DIScope;
275 pub type DIType = DIDescriptor;
276 pub type DIBasicType = DIType;
277 pub type DIDerivedType = DIType;
278 pub type DICompositeType = DIDerivedType;
279 pub type DIVariable = DIDescriptor;
280 pub type DIArray = DIDescriptor;
281 pub type DISubrange = DIDescriptor;
283 pub enum DIDescriptorFlags {
284 FlagPrivate = 1 << 0,
285 FlagProtected = 1 << 1,
286 FlagFwdDecl = 1 << 2,
287 FlagAppleBlock = 1 << 3,
288 FlagBlockByrefStruct = 1 << 4,
289 FlagVirtual = 1 << 5,
290 FlagArtificial = 1 << 6,
291 FlagExplicit = 1 << 7,
292 FlagPrototyped = 1 << 8,
293 FlagObjcClassComplete = 1 << 9,
294 FlagObjectPointer = 1 << 10,
295 FlagVector = 1 << 11,
296 FlagStaticMember = 1 << 12
301 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
302 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
303 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
304 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
305 use super::{ValueRef, TargetMachineRef, FileType, ArchiveRef};
306 use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
307 use super::debuginfo::*;
308 use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong,
311 // Link to our native llvm bindings (things that we need to use the C++ api
312 // for) and because llvm is written in C++ we need to link against libstdc++
314 // You'll probably notice that there is an omission of all LLVM libraries
315 // from this location. This is because the set of LLVM libraries that we
316 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
317 // figure out the exact set of libraries. To do this, the build system
318 // generates an llvmdeps.rs file next to this one which will be
319 // automatically updated whenever LLVM is updated to include an up-to-date
320 // set of the libraries we need to link to LLVM for.
321 #[link(name = "rustllvm", kind = "static")]
323 /* Create and destroy contexts. */
324 pub fn LLVMContextCreate() -> ContextRef;
325 pub fn LLVMContextDispose(C: ContextRef);
326 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
331 /* Create and destroy modules. */
332 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
335 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
336 pub fn LLVMDisposeModule(M: ModuleRef);
338 /** Data layout. See Module::getDataLayout. */
339 pub fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
340 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
342 /** Target triple. See Module::getTargetTriple. */
343 pub fn LLVMGetTarget(M: ModuleRef) -> *c_char;
344 pub fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
346 /** See Module::dump. */
347 pub fn LLVMDumpModule(M: ModuleRef);
349 /** See Module::setModuleInlineAsm. */
350 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
352 /** See llvm::LLVMTypeKind::getTypeID. */
353 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
355 /** See llvm::LLVMType::getContext. */
356 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
358 /* Operations on integer types */
359 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
360 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
361 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
362 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
363 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
364 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
367 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
369 /* Operations on real types */
370 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
371 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
372 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
373 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
374 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
376 /* Operations on function types */
377 pub fn LLVMFunctionType(ReturnType: TypeRef,
378 ParamTypes: *TypeRef,
382 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
383 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
384 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
385 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
387 /* Operations on struct types */
388 pub fn LLVMStructTypeInContext(C: ContextRef,
389 ElementTypes: *TypeRef,
390 ElementCount: c_uint,
393 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
394 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
396 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
398 /* Operations on array, pointer, and vector types (sequence types) */
399 pub fn LLVMArrayType(ElementType: TypeRef, ElementCount: c_uint)
401 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
403 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
406 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
407 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
408 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
409 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
411 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
413 /* Operations on other types */
414 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
415 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
416 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
418 /* Operations on all values */
419 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
420 pub fn LLVMGetValueName(Val: ValueRef) -> *c_char;
421 pub fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
422 pub fn LLVMDumpValue(Val: ValueRef);
423 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
424 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
425 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
426 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
428 /* Operations on Uses */
429 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
430 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
431 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
432 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
434 /* Operations on Users */
435 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
436 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
437 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
439 /* Operations on constants of any type */
440 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
442 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
443 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
445 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
447 /* only for int/vector */
448 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
449 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
450 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
451 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
452 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
454 /* Operations on metadata */
455 pub fn LLVMMDStringInContext(C: ContextRef,
459 pub fn LLVMMDNodeInContext(C: ContextRef,
463 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
467 /* Operations on scalar constants */
468 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
470 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8)
472 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
477 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
478 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char)
480 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
484 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
485 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
488 /* Operations on composite constants */
489 pub fn LLVMConstStringInContext(C: ContextRef,
492 DontNullTerminate: Bool)
494 pub fn LLVMConstStructInContext(C: ContextRef,
495 ConstantVals: *ValueRef,
500 pub fn LLVMConstArray(ElementTy: TypeRef,
501 ConstantVals: *ValueRef,
504 pub fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: c_uint)
507 /* Constant expressions */
508 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
509 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
510 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
511 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
512 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
513 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
514 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
515 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
517 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
519 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
521 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
523 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
525 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
527 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
529 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
531 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
533 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
535 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
537 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
539 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
541 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
543 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
544 RHSConstant: ValueRef)
546 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
548 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
550 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
552 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
554 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
556 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
558 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
560 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
562 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
564 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
566 pub fn LLVMConstGEP(ConstantVal: ValueRef,
567 ConstantIndices: *ValueRef,
570 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
571 ConstantIndices: *ValueRef,
574 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
576 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
578 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
580 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
582 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
584 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
586 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
588 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
590 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
592 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
594 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
596 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
598 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
600 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
602 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
604 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
606 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
610 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
612 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
613 ConstantIfTrue: ValueRef,
614 ConstantIfFalse: ValueRef)
616 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
617 IndexConstant: ValueRef)
619 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
620 ElementValueConstant: ValueRef,
621 IndexConstant: ValueRef)
623 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
624 VectorBConstant: ValueRef,
625 MaskConstant: ValueRef)
627 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
631 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
632 ElementValueConstant: ValueRef,
636 pub fn LLVMConstInlineAsm(Ty: TypeRef,
638 Constraints: *c_char,
639 HasSideEffects: Bool,
642 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
646 /* Operations on global variables, functions, and aliases (globals) */
647 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
648 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
649 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
650 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
651 pub fn LLVMGetSection(Global: ValueRef) -> *c_char;
652 pub fn LLVMSetSection(Global: ValueRef, Section: *c_char);
653 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
654 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
655 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
656 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
659 /* Operations on global variables */
660 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char)
662 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
665 AddressSpace: c_uint)
667 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
668 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
669 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
670 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
671 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
672 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
673 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
674 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
675 ConstantVal: ValueRef);
676 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
677 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
678 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
679 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
681 /* Operations on aliases */
682 pub fn LLVMAddAlias(M: ModuleRef,
688 /* Operations on functions */
689 pub fn LLVMAddFunction(M: ModuleRef,
693 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
694 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
695 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
696 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
697 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
698 pub fn LLVMDeleteFunction(Fn: ValueRef);
699 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
703 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
704 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
705 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
706 pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
707 pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
708 pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
709 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
710 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
712 pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
713 pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
715 pub fn LLVMAddColdAttribute(Fn: ValueRef);
717 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
719 HighPA: c_ulonglong);
721 /* Operations on parameters */
722 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
723 pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
724 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
725 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
726 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
727 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
728 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
729 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
730 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
731 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
732 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
733 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
735 /* Operations on basic blocks */
736 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
737 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
738 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
739 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
740 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
741 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
742 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
743 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
744 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
745 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
746 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
748 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
752 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
756 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
758 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
759 MoveAfter: BasicBlockRef);
761 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
762 MoveBefore: BasicBlockRef);
764 /* Operations on instructions */
765 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
766 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
767 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
768 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
769 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
770 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
772 /* Operations on call sites */
773 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
774 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
775 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
778 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
781 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
785 /* Operations on call instructions (only) */
786 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
787 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
789 /* Operations on load/store instructions (only) */
790 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
791 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
793 /* Operations on phi nodes */
794 pub fn LLVMAddIncoming(PhiNode: ValueRef,
795 IncomingValues: *ValueRef,
796 IncomingBlocks: *BasicBlockRef,
798 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
799 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
801 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
804 /* Instruction builders */
805 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
806 pub fn LLVMPositionBuilder(Builder: BuilderRef,
807 Block: BasicBlockRef,
809 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
811 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
812 Block: BasicBlockRef);
813 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
814 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
815 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
816 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
819 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
820 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
823 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
824 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
825 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
828 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
829 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
830 pub fn LLVMBuildAggregateRet(B: BuilderRef,
834 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
835 pub fn LLVMBuildCondBr(B: BuilderRef,
840 pub fn LLVMBuildSwitch(B: BuilderRef,
845 pub fn LLVMBuildIndirectBr(B: BuilderRef,
849 pub fn LLVMBuildInvoke(B: BuilderRef,
854 Catch: BasicBlockRef,
857 pub fn LLVMBuildLandingPad(B: BuilderRef,
863 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
864 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
866 /* Add a case to the switch instruction */
867 pub fn LLVMAddCase(Switch: ValueRef,
869 Dest: BasicBlockRef);
871 /* Add a destination to the indirectbr instruction */
872 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
874 /* Add a clause to the landing pad instruction */
875 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
877 /* Set the cleanup on a landing pad instruction */
878 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
881 pub fn LLVMBuildAdd(B: BuilderRef,
886 pub fn LLVMBuildNSWAdd(B: BuilderRef,
891 pub fn LLVMBuildNUWAdd(B: BuilderRef,
896 pub fn LLVMBuildFAdd(B: BuilderRef,
901 pub fn LLVMBuildSub(B: BuilderRef,
906 pub fn LLVMBuildNSWSub(B: BuilderRef,
911 pub fn LLVMBuildNUWSub(B: BuilderRef,
916 pub fn LLVMBuildFSub(B: BuilderRef,
921 pub fn LLVMBuildMul(B: BuilderRef,
926 pub fn LLVMBuildNSWMul(B: BuilderRef,
931 pub fn LLVMBuildNUWMul(B: BuilderRef,
936 pub fn LLVMBuildFMul(B: BuilderRef,
941 pub fn LLVMBuildUDiv(B: BuilderRef,
946 pub fn LLVMBuildSDiv(B: BuilderRef,
951 pub fn LLVMBuildExactSDiv(B: BuilderRef,
956 pub fn LLVMBuildFDiv(B: BuilderRef,
961 pub fn LLVMBuildURem(B: BuilderRef,
966 pub fn LLVMBuildSRem(B: BuilderRef,
971 pub fn LLVMBuildFRem(B: BuilderRef,
976 pub fn LLVMBuildShl(B: BuilderRef,
981 pub fn LLVMBuildLShr(B: BuilderRef,
986 pub fn LLVMBuildAShr(B: BuilderRef,
991 pub fn LLVMBuildAnd(B: BuilderRef,
996 pub fn LLVMBuildOr(B: BuilderRef,
1001 pub fn LLVMBuildXor(B: BuilderRef,
1006 pub fn LLVMBuildBinOp(B: BuilderRef,
1012 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1014 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1016 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1018 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1020 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char)
1024 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1026 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1031 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1033 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1038 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1039 pub fn LLVMBuildLoad(B: BuilderRef,
1040 PointerVal: ValueRef,
1044 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1047 pub fn LLVMBuildGEP(B: BuilderRef,
1053 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1059 pub fn LLVMBuildStructGEP(B: BuilderRef,
1064 pub fn LLVMBuildGlobalString(B: BuilderRef,
1068 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1074 pub fn LLVMBuildTrunc(B: BuilderRef,
1079 pub fn LLVMBuildZExt(B: BuilderRef,
1084 pub fn LLVMBuildSExt(B: BuilderRef,
1089 pub fn LLVMBuildFPToUI(B: BuilderRef,
1094 pub fn LLVMBuildFPToSI(B: BuilderRef,
1099 pub fn LLVMBuildUIToFP(B: BuilderRef,
1104 pub fn LLVMBuildSIToFP(B: BuilderRef,
1109 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1114 pub fn LLVMBuildFPExt(B: BuilderRef,
1119 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1124 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1129 pub fn LLVMBuildBitCast(B: BuilderRef,
1134 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1139 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1144 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1149 pub fn LLVMBuildCast(B: BuilderRef,
1153 Name: *c_char) -> ValueRef;
1154 pub fn LLVMBuildPointerCast(B: BuilderRef,
1159 pub fn LLVMBuildIntCast(B: BuilderRef,
1164 pub fn LLVMBuildFPCast(B: BuilderRef,
1171 pub fn LLVMBuildICmp(B: BuilderRef,
1177 pub fn LLVMBuildFCmp(B: BuilderRef,
1184 /* Miscellaneous instructions */
1185 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1187 pub fn LLVMBuildCall(B: BuilderRef,
1193 pub fn LLVMBuildSelect(B: BuilderRef,
1199 pub fn LLVMBuildVAArg(B: BuilderRef,
1204 pub fn LLVMBuildExtractElement(B: BuilderRef,
1209 pub fn LLVMBuildInsertElement(B: BuilderRef,
1215 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1221 pub fn LLVMBuildExtractValue(B: BuilderRef,
1226 pub fn LLVMBuildInsertValue(B: BuilderRef,
1233 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1235 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1237 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1243 /* Atomic Operations */
1244 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1245 PointerVal: ValueRef,
1247 Order: AtomicOrdering,
1251 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1254 Order: AtomicOrdering,
1258 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1262 Order: AtomicOrdering)
1264 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1268 Order: AtomicOrdering,
1269 SingleThreaded: Bool)
1272 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1275 /* Selected entries from the downcasts. */
1276 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1277 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1279 /** Writes a module to the specified path. Returns 0 on success. */
1280 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
1282 /** Creates target data from a target layout string. */
1283 pub fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
1284 /// Adds the target data to the given pass manager. The pass manager
1285 /// references the target data only weakly.
1286 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1287 /** Number of bytes clobbered when doing a Store to *T. */
1288 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1291 /** Number of bytes clobbered when doing a Store to *T. */
1292 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1295 /** Distance between successive elements in an array of T.
1296 Includes ABI padding. */
1297 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1299 /** Returns the preferred alignment of a type. */
1300 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1302 /** Returns the minimum alignment of a type. */
1303 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1306 /// Computes the byte offset of the indexed struct element for a
1308 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1314 * Returns the minimum alignment of a type when part of a call frame.
1316 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1319 /** Disposes target data. */
1320 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1322 /** Creates a pass manager. */
1323 pub fn LLVMCreatePassManager() -> PassManagerRef;
1325 /** Creates a function-by-function pass manager */
1326 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1329 /** Disposes a pass manager. */
1330 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1332 /** Runs a pass manager on a module. */
1333 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1335 /** Runs the function passes on the provided function. */
1336 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1339 /** Initializes all the function passes scheduled in the manager */
1340 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1342 /** Finalizes all the function passes scheduled in the manager */
1343 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1345 pub fn LLVMInitializePasses();
1347 /** Adds a verification pass. */
1348 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1350 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1351 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1352 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1353 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1354 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1355 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1356 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1357 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1358 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1359 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1360 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1361 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1362 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1363 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1364 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1365 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1366 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1367 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1368 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1369 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1370 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1371 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1372 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1373 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1374 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1375 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1376 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1377 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1378 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1379 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1380 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1381 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1382 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1383 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1384 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1386 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1387 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1388 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1389 OptimizationLevel: c_uint);
1390 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1392 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1393 PMB: PassManagerBuilderRef,
1395 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1396 PMB: PassManagerBuilderRef,
1398 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1399 PMB: PassManagerBuilderRef,
1401 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1402 PMB: PassManagerBuilderRef,
1404 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1405 PMB: PassManagerBuilderRef,
1406 PM: PassManagerRef);
1408 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1409 PMB: PassManagerBuilderRef,
1410 PM: PassManagerRef);
1411 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1412 PMB: PassManagerBuilderRef,
1417 /** Destroys a memory buffer. */
1418 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1421 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1423 /** Opens an object file. */
1424 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1425 /** Closes an object file. */
1426 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1428 /** Enumerates the sections in an object file. */
1429 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1430 /** Destroys a section iterator. */
1431 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1432 /** Returns true if the section iterator is at the end of the section
1434 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1435 SI: SectionIteratorRef)
1437 /** Moves the section iterator to point to the next section. */
1438 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1439 /** Returns the current section name. */
1440 pub fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1441 /** Returns the current section size. */
1442 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1443 /** Returns the current section contents as a string buffer. */
1444 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
1446 /** Reads the given file and returns it as a memory buffer. Use
1447 LLVMDisposeMemoryBuffer() to get rid of it. */
1448 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
1450 /** Borrows the contents of the memory buffer (doesn't copy it) */
1451 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *c_char,
1452 InputDataLength: size_t,
1453 BufferName: *c_char,
1456 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *c_char,
1457 InputDataLength: size_t,
1458 BufferName: *c_char)
1461 pub fn LLVMIsMultithreaded() -> Bool;
1462 pub fn LLVMStartMultithreaded() -> Bool;
1464 /** Returns a string describing the last error caused by an LLVMRust*
1466 pub fn LLVMRustGetLastError() -> *c_char;
1468 /// Print the pass timings since static dtors aren't picking them up.
1469 pub fn LLVMRustPrintPassTimings();
1471 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1473 pub fn LLVMStructSetBody(StructTy: TypeRef,
1474 ElementTypes: *TypeRef,
1475 ElementCount: c_uint,
1478 pub fn LLVMConstNamedStruct(S: TypeRef,
1479 ConstantVals: *ValueRef,
1483 /** Enables LLVM debug output. */
1484 pub fn LLVMSetDebug(Enabled: c_int);
1486 /** Prepares inline assembly. */
1487 pub fn LLVMInlineAsm(Ty: TypeRef,
1489 Constraints: *c_char,
1495 pub static LLVMRustDebugMetadataVersion: u32;
1497 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1501 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1503 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1505 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1507 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1515 SplitName: *c_char);
1517 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1522 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1524 ParameterTypes: DIArray)
1527 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1528 Scope: DIDescriptor,
1530 LinkageName: *c_char,
1534 isLocalToUnit: bool,
1544 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1546 SizeInBits: c_ulonglong,
1547 AlignInBits: c_ulonglong,
1551 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1553 SizeInBits: c_ulonglong,
1554 AlignInBits: c_ulonglong,
1558 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1559 Scope: DIDescriptor,
1563 SizeInBits: c_ulonglong,
1564 AlignInBits: c_ulonglong,
1566 DerivedFrom: DIType,
1568 RunTimeLang: c_uint,
1569 VTableHolder: ValueRef,
1573 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1574 Scope: DIDescriptor,
1578 SizeInBits: c_ulonglong,
1579 AlignInBits: c_ulonglong,
1580 OffsetInBits: c_ulonglong,
1585 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1586 Scope: DIDescriptor,
1592 pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
1594 Scope: DIDescriptor,
1599 AlwaysPreserve: bool,
1604 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1606 AlignInBits: c_ulonglong,
1608 Subscripts: DIArray)
1611 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1613 AlignInBits: c_ulonglong,
1615 Subscripts: DIArray)
1618 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1623 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1628 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1630 VarInfo: DIVariable,
1631 InsertAtEnd: BasicBlockRef)
1634 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1636 VarInfo: DIVariable,
1637 InsertBefore: ValueRef)
1640 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1645 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1650 SizeInBits: c_ulonglong,
1651 AlignInBits: c_ulonglong,
1653 ClassType: ValueRef)
1656 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1661 SizeInBits: c_ulonglong,
1662 AlignInBits: c_ulonglong,
1665 RunTimeLang: c_uint,
1669 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1671 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1680 pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
1682 pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
1684 pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
1692 AddrOpsCount: c_uint,
1696 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1703 pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1704 pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
1705 pub fn LLVMValueToString(value_ref: ValueRef) -> *c_char;
1707 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1709 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1711 pub fn LLVMInitializeX86TargetInfo();
1712 pub fn LLVMInitializeX86Target();
1713 pub fn LLVMInitializeX86TargetMC();
1714 pub fn LLVMInitializeX86AsmPrinter();
1715 pub fn LLVMInitializeX86AsmParser();
1716 pub fn LLVMInitializeARMTargetInfo();
1717 pub fn LLVMInitializeARMTarget();
1718 pub fn LLVMInitializeARMTargetMC();
1719 pub fn LLVMInitializeARMAsmPrinter();
1720 pub fn LLVMInitializeARMAsmParser();
1721 pub fn LLVMInitializeMipsTargetInfo();
1722 pub fn LLVMInitializeMipsTarget();
1723 pub fn LLVMInitializeMipsTargetMC();
1724 pub fn LLVMInitializeMipsAsmPrinter();
1725 pub fn LLVMInitializeMipsAsmParser();
1727 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *c_char) -> bool;
1728 pub fn LLVMRustCreateTargetMachine(Triple: *c_char,
1731 Model: CodeGenModel,
1733 Level: CodeGenOptLevel,
1736 NoFramePointerElim: bool) -> TargetMachineRef;
1737 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
1738 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
1741 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
1743 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef);
1744 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
1745 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
1749 FileType: FileType) -> bool;
1750 pub fn LLVMRustPrintModule(PM: PassManagerRef,
1753 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: **c_char);
1754 pub fn LLVMRustPrintPasses();
1755 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *c_char);
1756 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
1757 AddLifetimes: bool);
1758 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
1760 len: size_t) -> bool;
1761 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
1764 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
1766 pub fn LLVMRustOpenArchive(path: *c_char) -> ArchiveRef;
1767 pub fn LLVMRustArchiveReadSection(AR: ArchiveRef, name: *c_char,
1768 out_len: *mut size_t) -> *c_char;
1769 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
1771 pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef);
1772 pub fn LLVMVersionMinor() -> c_int;
1776 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
1778 llvm::LLVMSetInstructionCallConv(instr, cc as c_uint);
1781 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
1783 llvm::LLVMSetFunctionCallConv(fn_, cc as c_uint);
1786 pub fn SetLinkage(global: ValueRef, link: Linkage) {
1788 llvm::LLVMSetLinkage(global, link as c_uint);
1792 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
1794 llvm::LLVMSetUnnamedAddr(global, unnamed as Bool);
1798 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
1800 llvm::LLVMSetThreadLocal(global, is_thread_local as Bool);
1804 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
1806 llvm::LLVMConstICmp(pred as c_ushort, v1, v2)
1809 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
1811 llvm::LLVMConstFCmp(pred as c_ushort, v1, v2)
1815 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
1817 llvm::LLVMAddFunctionAttr(fn_, attr as c_uint)
1820 /* Memory-managed object interface to type handles. */
1822 pub struct TypeNames {
1823 named_types: RefCell<HashMap<~str, TypeRef>>,
1827 pub fn new() -> TypeNames {
1829 named_types: RefCell::new(HashMap::new())
1833 pub fn associate_type(&self, s: &str, t: &Type) {
1834 let mut named_types = self.named_types.borrow_mut();
1835 assert!(named_types.get().insert(s.to_owned(), t.to_ref()));
1838 pub fn find_type(&self, s: &str) -> Option<Type> {
1839 let named_types = self.named_types.borrow();
1840 named_types.get().find_equiv(&s).map(|x| Type::from_ref(*x))
1843 pub fn type_to_str(&self, ty: Type) -> ~str {
1845 let s = llvm::LLVMTypeToString(ty.to_ref());
1846 let ret = from_c_str(s);
1847 free(s as *mut c_void);
1852 pub fn types_to_str(&self, tys: &[Type]) -> ~str {
1853 let strs = tys.map(|t| self.type_to_str(*t));
1854 format!("[{}]", strs.connect(","))
1857 pub fn val_to_str(&self, val: ValueRef) -> ~str {
1859 let s = llvm::LLVMValueToString(val);
1860 let ret = from_c_str(s);
1861 free(s as *mut c_void);
1867 /* Memory-managed interface to target data. */
1869 pub struct target_data_res {
1873 impl Drop for target_data_res {
1874 fn drop(&mut self) {
1876 llvm::LLVMDisposeTargetData(self.td);
1881 pub fn target_data_res(td: TargetDataRef) -> target_data_res {
1887 pub struct TargetData {
1888 lltd: TargetDataRef,
1889 dtor: @target_data_res
1892 pub fn mk_target_data(string_rep: &str) -> TargetData {
1893 let lltd = string_rep.with_c_str(|buf| {
1894 unsafe { llvm::LLVMCreateTargetData(buf) }
1899 dtor: @target_data_res(lltd)
1903 /* Memory-managed interface to pass managers. */
1905 pub struct pass_manager_res {
1909 impl Drop for pass_manager_res {
1910 fn drop(&mut self) {
1912 llvm::LLVMDisposePassManager(self.pm);
1917 pub fn pass_manager_res(pm: PassManagerRef) -> pass_manager_res {
1923 pub struct PassManager {
1924 llpm: PassManagerRef,
1925 dtor: @pass_manager_res
1928 pub fn mk_pass_manager() -> PassManager {
1930 let llpm = llvm::LLVMCreatePassManager();
1934 dtor: @pass_manager_res(llpm)
1939 /* Memory-managed interface to object files. */
1941 pub struct ObjectFile {
1942 llof: ObjectFileRef,
1946 // This will take ownership of llmb
1947 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1949 let llof = llvm::LLVMCreateObjectFile(llmb);
1950 if llof as int == 0 {
1951 // LLVMCreateObjectFile took ownership of llmb
1962 impl Drop for ObjectFile {
1963 fn drop(&mut self) {
1965 llvm::LLVMDisposeObjectFile(self.llof);
1970 /* Memory-managed interface to section iterators. */
1972 pub struct section_iter_res {
1973 si: SectionIteratorRef,
1976 impl Drop for section_iter_res {
1977 fn drop(&mut self) {
1979 llvm::LLVMDisposeSectionIterator(self.si);
1984 pub fn section_iter_res(si: SectionIteratorRef) -> section_iter_res {
1990 pub struct SectionIter {
1991 llsi: SectionIteratorRef,
1992 dtor: @section_iter_res
1995 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
1997 let llsi = llvm::LLVMGetSections(llof);
2000 dtor: @section_iter_res(llsi)