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)]
15 use std::c_str::ToCStr;
16 use std::cell::RefCell;
17 use collections::HashMap;
18 use libc::{c_uint, c_ushort, c_void, free};
19 use std::str::raw::from_c_str;
21 use middle::trans::type_::Type;
23 pub type Opcode = u32;
24 pub type Bool = c_uint;
26 pub static True: Bool = 1 as Bool;
27 pub static False: Bool = 0 as Bool;
29 // Consts for the LLVM CallConv type, pre-cast to uint.
36 X86StdcallCallConv = 64,
37 X86FastcallCallConv = 65,
42 LLVMDefaultVisibility = 0,
44 ProtectedVisibility = 2,
47 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
48 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
49 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
50 // they've been removed in upstream LLVM commit r203866.
53 AvailableExternallyLinkage = 1,
54 LinkOnceAnyLinkage = 2,
55 LinkOnceODRLinkage = 3,
61 ExternalWeakLinkage = 12,
67 ZExtAttribute = 1 << 0,
68 SExtAttribute = 1 << 1,
69 NoReturnAttribute = 1 << 2,
70 InRegAttribute = 1 << 3,
71 StructRetAttribute = 1 << 4,
72 NoUnwindAttribute = 1 << 5,
73 NoAliasAttribute = 1 << 6,
74 ByValAttribute = 1 << 7,
75 NestAttribute = 1 << 8,
76 ReadNoneAttribute = 1 << 9,
77 ReadOnlyAttribute = 1 << 10,
78 NoInlineAttribute = 1 << 11,
79 AlwaysInlineAttribute = 1 << 12,
80 OptimizeForSizeAttribute = 1 << 13,
81 StackProtectAttribute = 1 << 14,
82 StackProtectReqAttribute = 1 << 15,
83 AlignmentAttribute = 31 << 16,
84 NoCaptureAttribute = 1 << 21,
85 NoRedZoneAttribute = 1 << 22,
86 NoImplicitFloatAttribute = 1 << 23,
87 NakedAttribute = 1 << 24,
88 InlineHintAttribute = 1 << 25,
89 StackAttribute = 7 << 26,
90 ReturnsTwiceAttribute = 1 << 29,
91 UWTableAttribute = 1 << 30,
92 NonLazyBindAttribute = 1 << 31,
95 // enum for the LLVM IntPredicate type
96 pub enum IntPredicate {
109 // enum for the LLVM RealPredicate type
110 pub enum RealPredicate {
111 RealPredicateFalse = 0,
126 RealPredicateTrue = 15,
129 // The LLVM TypeKind type - must stay in sync with the def of
130 // LLVMTypeKind in llvm/include/llvm-c/Core.h
153 pub enum AtomicBinOp {
168 pub enum AtomicOrdering {
172 // Consume = 3, // Not specified yet.
176 SequentiallyConsistent = 7
179 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
195 // Inline Asm Dialect
196 pub enum AsmDialect {
203 pub enum CodeGenOptLevel {
204 CodeGenLevelNone = 0,
205 CodeGenLevelLess = 1,
206 CodeGenLevelDefault = 2,
207 CodeGenLevelAggressive = 3,
215 RelocDynamicNoPic = 3,
219 pub enum CodeGenModel {
220 CodeModelDefault = 0,
221 CodeModelJITDefault = 1,
228 // Opaque pointer types
229 pub enum Module_opaque {}
230 pub type ModuleRef = *Module_opaque;
231 pub enum Context_opaque {}
232 pub type ContextRef = *Context_opaque;
233 pub enum Type_opaque {}
234 pub type TypeRef = *Type_opaque;
235 pub enum Value_opaque {}
236 pub type ValueRef = *Value_opaque;
237 pub enum BasicBlock_opaque {}
238 pub type BasicBlockRef = *BasicBlock_opaque;
239 pub enum Builder_opaque {}
240 pub type BuilderRef = *Builder_opaque;
241 pub enum ExecutionEngine_opaque {}
242 pub type ExecutionEngineRef = *ExecutionEngine_opaque;
243 pub enum MemoryBuffer_opaque {}
244 pub type MemoryBufferRef = *MemoryBuffer_opaque;
245 pub enum PassManager_opaque {}
246 pub type PassManagerRef = *PassManager_opaque;
247 pub enum PassManagerBuilder_opaque {}
248 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
249 pub enum Use_opaque {}
250 pub type UseRef = *Use_opaque;
251 pub enum TargetData_opaque {}
252 pub type TargetDataRef = *TargetData_opaque;
253 pub enum ObjectFile_opaque {}
254 pub type ObjectFileRef = *ObjectFile_opaque;
255 pub enum SectionIterator_opaque {}
256 pub type SectionIteratorRef = *SectionIterator_opaque;
257 pub enum Pass_opaque {}
258 pub type PassRef = *Pass_opaque;
259 pub enum TargetMachine_opaque {}
260 pub type TargetMachineRef = *TargetMachine_opaque;
261 pub enum Archive_opaque {}
262 pub type ArchiveRef = *Archive_opaque;
265 use super::{ValueRef};
267 pub enum DIBuilder_opaque {}
268 pub type DIBuilderRef = *DIBuilder_opaque;
270 pub type DIDescriptor = ValueRef;
271 pub type DIScope = DIDescriptor;
272 pub type DILocation = DIDescriptor;
273 pub type DIFile = DIScope;
274 pub type DILexicalBlock = DIScope;
275 pub type DISubprogram = DIScope;
276 pub type DIType = DIDescriptor;
277 pub type DIBasicType = DIType;
278 pub type DIDerivedType = DIType;
279 pub type DICompositeType = DIDerivedType;
280 pub type DIVariable = DIDescriptor;
281 pub type DIGlobalVariable = DIDescriptor;
282 pub type DIArray = DIDescriptor;
283 pub type DISubrange = DIDescriptor;
285 pub enum DIDescriptorFlags {
286 FlagPrivate = 1 << 0,
287 FlagProtected = 1 << 1,
288 FlagFwdDecl = 1 << 2,
289 FlagAppleBlock = 1 << 3,
290 FlagBlockByrefStruct = 1 << 4,
291 FlagVirtual = 1 << 5,
292 FlagArtificial = 1 << 6,
293 FlagExplicit = 1 << 7,
294 FlagPrototyped = 1 << 8,
295 FlagObjcClassComplete = 1 << 9,
296 FlagObjectPointer = 1 << 10,
297 FlagVector = 1 << 11,
298 FlagStaticMember = 1 << 12
303 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
304 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
305 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
306 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
307 use super::{ValueRef, TargetMachineRef, FileType, ArchiveRef};
308 use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
309 use super::debuginfo::*;
310 use libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong,
313 // Link to our native llvm bindings (things that we need to use the C++ api
314 // for) and because llvm is written in C++ we need to link against libstdc++
316 // You'll probably notice that there is an omission of all LLVM libraries
317 // from this location. This is because the set of LLVM libraries that we
318 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
319 // figure out the exact set of libraries. To do this, the build system
320 // generates an llvmdeps.rs file next to this one which will be
321 // automatically updated whenever LLVM is updated to include an up-to-date
322 // set of the libraries we need to link to LLVM for.
323 #[link(name = "rustllvm", kind = "static")]
325 /* Create and destroy contexts. */
326 pub fn LLVMContextCreate() -> ContextRef;
327 pub fn LLVMContextDispose(C: ContextRef);
328 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
333 /* Create and destroy modules. */
334 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
337 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
338 pub fn LLVMDisposeModule(M: ModuleRef);
340 /** Data layout. See Module::getDataLayout. */
341 pub fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
342 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
344 /** Target triple. See Module::getTargetTriple. */
345 pub fn LLVMGetTarget(M: ModuleRef) -> *c_char;
346 pub fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
348 /** See Module::dump. */
349 pub fn LLVMDumpModule(M: ModuleRef);
351 /** See Module::setModuleInlineAsm. */
352 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
354 /** See llvm::LLVMTypeKind::getTypeID. */
355 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
357 /** See llvm::LLVMType::getContext. */
358 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
360 /* Operations on integer types */
361 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
362 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
363 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
364 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
365 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
366 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
369 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
371 /* Operations on real types */
372 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
373 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
374 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
375 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
376 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
378 /* Operations on function types */
379 pub fn LLVMFunctionType(ReturnType: TypeRef,
380 ParamTypes: *TypeRef,
384 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
385 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
386 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
387 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
389 /* Operations on struct types */
390 pub fn LLVMStructTypeInContext(C: ContextRef,
391 ElementTypes: *TypeRef,
392 ElementCount: c_uint,
395 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
396 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
398 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
400 /* Operations on array, pointer, and vector types (sequence types) */
401 pub fn LLVMArrayType(ElementType: TypeRef, ElementCount: c_uint)
403 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
405 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
408 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
409 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
410 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
411 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
413 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
415 /* Operations on other types */
416 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
417 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
418 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
420 /* Operations on all values */
421 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
422 pub fn LLVMGetValueName(Val: ValueRef) -> *c_char;
423 pub fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
424 pub fn LLVMDumpValue(Val: ValueRef);
425 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
426 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
427 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
428 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
430 /* Operations on Uses */
431 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
432 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
433 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
434 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
436 /* Operations on Users */
437 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
438 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
439 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
441 /* Operations on constants of any type */
442 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
444 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
445 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
447 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
449 /* only for int/vector */
450 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
451 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
452 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
453 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
454 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
456 /* Operations on metadata */
457 pub fn LLVMMDStringInContext(C: ContextRef,
461 pub fn LLVMMDNodeInContext(C: ContextRef,
465 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
469 /* Operations on scalar constants */
470 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
472 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8)
474 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
479 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
480 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char)
482 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
486 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
487 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
490 /* Operations on composite constants */
491 pub fn LLVMConstStringInContext(C: ContextRef,
494 DontNullTerminate: Bool)
496 pub fn LLVMConstStructInContext(C: ContextRef,
497 ConstantVals: *ValueRef,
502 pub fn LLVMConstArray(ElementTy: TypeRef,
503 ConstantVals: *ValueRef,
506 pub fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: c_uint)
509 /* Constant expressions */
510 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
511 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
512 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
513 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
514 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
515 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
516 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
517 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
519 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
521 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
523 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
525 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
527 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
529 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
531 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
533 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
535 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
537 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
539 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
541 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
543 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
545 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
546 RHSConstant: ValueRef)
548 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
550 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
552 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
554 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
556 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
558 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
560 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
562 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
564 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
566 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
568 pub fn LLVMConstGEP(ConstantVal: ValueRef,
569 ConstantIndices: *ValueRef,
572 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
573 ConstantIndices: *ValueRef,
576 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
578 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
580 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
582 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
584 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
586 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
588 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
590 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
592 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
594 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
596 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
598 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
600 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
602 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
604 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
606 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
608 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
612 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
614 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
615 ConstantIfTrue: ValueRef,
616 ConstantIfFalse: ValueRef)
618 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
619 IndexConstant: ValueRef)
621 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
622 ElementValueConstant: ValueRef,
623 IndexConstant: ValueRef)
625 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
626 VectorBConstant: ValueRef,
627 MaskConstant: ValueRef)
629 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
633 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
634 ElementValueConstant: ValueRef,
638 pub fn LLVMConstInlineAsm(Ty: TypeRef,
640 Constraints: *c_char,
641 HasSideEffects: Bool,
644 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
648 /* Operations on global variables, functions, and aliases (globals) */
649 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
650 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
651 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
652 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
653 pub fn LLVMGetSection(Global: ValueRef) -> *c_char;
654 pub fn LLVMSetSection(Global: ValueRef, Section: *c_char);
655 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
656 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
657 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
658 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
661 /* Operations on global variables */
662 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char)
664 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
667 AddressSpace: c_uint)
669 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
670 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
671 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
672 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
673 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
674 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
675 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
676 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
677 ConstantVal: ValueRef);
678 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
679 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
680 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
681 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
683 /* Operations on aliases */
684 pub fn LLVMAddAlias(M: ModuleRef,
690 /* Operations on functions */
691 pub fn LLVMAddFunction(M: ModuleRef,
695 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
696 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
697 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
698 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
699 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
700 pub fn LLVMDeleteFunction(Fn: ValueRef);
701 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
705 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
706 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
707 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
708 pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
709 pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
710 pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
711 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
712 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
714 pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
715 pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
717 pub fn LLVMAddColdAttribute(Fn: ValueRef);
719 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
721 HighPA: c_ulonglong);
723 /* Operations on parameters */
724 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
725 pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
726 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
727 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
728 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
729 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
730 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
731 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
732 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
733 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
734 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
735 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
737 /* Operations on basic blocks */
738 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
739 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
740 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
741 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
742 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
743 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
744 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
745 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
746 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
747 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
748 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
750 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
754 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
758 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
760 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
761 MoveAfter: BasicBlockRef);
763 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
764 MoveBefore: BasicBlockRef);
766 /* Operations on instructions */
767 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
768 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
769 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
770 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
771 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
772 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
774 /* Operations on call sites */
775 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
776 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
777 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
780 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
783 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
787 /* Operations on call instructions (only) */
788 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
789 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
791 /* Operations on load/store instructions (only) */
792 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
793 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
795 /* Operations on phi nodes */
796 pub fn LLVMAddIncoming(PhiNode: ValueRef,
797 IncomingValues: *ValueRef,
798 IncomingBlocks: *BasicBlockRef,
800 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
801 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
803 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
806 /* Instruction builders */
807 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
808 pub fn LLVMPositionBuilder(Builder: BuilderRef,
809 Block: BasicBlockRef,
811 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
813 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
814 Block: BasicBlockRef);
815 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
816 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
817 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
818 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
821 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
822 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
825 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
826 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
827 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
830 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
831 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
832 pub fn LLVMBuildAggregateRet(B: BuilderRef,
836 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
837 pub fn LLVMBuildCondBr(B: BuilderRef,
842 pub fn LLVMBuildSwitch(B: BuilderRef,
847 pub fn LLVMBuildIndirectBr(B: BuilderRef,
851 pub fn LLVMBuildInvoke(B: BuilderRef,
856 Catch: BasicBlockRef,
859 pub fn LLVMBuildLandingPad(B: BuilderRef,
865 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
866 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
868 /* Add a case to the switch instruction */
869 pub fn LLVMAddCase(Switch: ValueRef,
871 Dest: BasicBlockRef);
873 /* Add a destination to the indirectbr instruction */
874 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
876 /* Add a clause to the landing pad instruction */
877 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
879 /* Set the cleanup on a landing pad instruction */
880 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
883 pub fn LLVMBuildAdd(B: BuilderRef,
888 pub fn LLVMBuildNSWAdd(B: BuilderRef,
893 pub fn LLVMBuildNUWAdd(B: BuilderRef,
898 pub fn LLVMBuildFAdd(B: BuilderRef,
903 pub fn LLVMBuildSub(B: BuilderRef,
908 pub fn LLVMBuildNSWSub(B: BuilderRef,
913 pub fn LLVMBuildNUWSub(B: BuilderRef,
918 pub fn LLVMBuildFSub(B: BuilderRef,
923 pub fn LLVMBuildMul(B: BuilderRef,
928 pub fn LLVMBuildNSWMul(B: BuilderRef,
933 pub fn LLVMBuildNUWMul(B: BuilderRef,
938 pub fn LLVMBuildFMul(B: BuilderRef,
943 pub fn LLVMBuildUDiv(B: BuilderRef,
948 pub fn LLVMBuildSDiv(B: BuilderRef,
953 pub fn LLVMBuildExactSDiv(B: BuilderRef,
958 pub fn LLVMBuildFDiv(B: BuilderRef,
963 pub fn LLVMBuildURem(B: BuilderRef,
968 pub fn LLVMBuildSRem(B: BuilderRef,
973 pub fn LLVMBuildFRem(B: BuilderRef,
978 pub fn LLVMBuildShl(B: BuilderRef,
983 pub fn LLVMBuildLShr(B: BuilderRef,
988 pub fn LLVMBuildAShr(B: BuilderRef,
993 pub fn LLVMBuildAnd(B: BuilderRef,
998 pub fn LLVMBuildOr(B: BuilderRef,
1003 pub fn LLVMBuildXor(B: BuilderRef,
1008 pub fn LLVMBuildBinOp(B: BuilderRef,
1014 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1016 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1018 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1020 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1022 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char)
1026 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1028 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1033 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1035 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1040 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1041 pub fn LLVMBuildLoad(B: BuilderRef,
1042 PointerVal: ValueRef,
1046 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1049 pub fn LLVMBuildGEP(B: BuilderRef,
1055 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1061 pub fn LLVMBuildStructGEP(B: BuilderRef,
1066 pub fn LLVMBuildGlobalString(B: BuilderRef,
1070 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1076 pub fn LLVMBuildTrunc(B: BuilderRef,
1081 pub fn LLVMBuildZExt(B: BuilderRef,
1086 pub fn LLVMBuildSExt(B: BuilderRef,
1091 pub fn LLVMBuildFPToUI(B: BuilderRef,
1096 pub fn LLVMBuildFPToSI(B: BuilderRef,
1101 pub fn LLVMBuildUIToFP(B: BuilderRef,
1106 pub fn LLVMBuildSIToFP(B: BuilderRef,
1111 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1116 pub fn LLVMBuildFPExt(B: BuilderRef,
1121 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1126 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1131 pub fn LLVMBuildBitCast(B: BuilderRef,
1136 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1141 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1146 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1151 pub fn LLVMBuildCast(B: BuilderRef,
1155 Name: *c_char) -> ValueRef;
1156 pub fn LLVMBuildPointerCast(B: BuilderRef,
1161 pub fn LLVMBuildIntCast(B: BuilderRef,
1166 pub fn LLVMBuildFPCast(B: BuilderRef,
1173 pub fn LLVMBuildICmp(B: BuilderRef,
1179 pub fn LLVMBuildFCmp(B: BuilderRef,
1186 /* Miscellaneous instructions */
1187 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1189 pub fn LLVMBuildCall(B: BuilderRef,
1195 pub fn LLVMBuildSelect(B: BuilderRef,
1201 pub fn LLVMBuildVAArg(B: BuilderRef,
1206 pub fn LLVMBuildExtractElement(B: BuilderRef,
1211 pub fn LLVMBuildInsertElement(B: BuilderRef,
1217 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1223 pub fn LLVMBuildExtractValue(B: BuilderRef,
1228 pub fn LLVMBuildInsertValue(B: BuilderRef,
1235 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1237 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1239 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1245 /* Atomic Operations */
1246 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1247 PointerVal: ValueRef,
1249 Order: AtomicOrdering,
1253 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1256 Order: AtomicOrdering,
1260 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1264 Order: AtomicOrdering,
1265 FailureOrder: AtomicOrdering)
1267 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1271 Order: AtomicOrdering,
1272 SingleThreaded: Bool)
1275 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1278 /* Selected entries from the downcasts. */
1279 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1280 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1282 /** Writes a module to the specified path. Returns 0 on success. */
1283 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
1285 /** Creates target data from a target layout string. */
1286 pub fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
1287 /// Adds the target data to the given pass manager. The pass manager
1288 /// references the target data only weakly.
1289 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1290 /** Number of bytes clobbered when doing a Store to *T. */
1291 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1294 /** Number of bytes clobbered when doing a Store to *T. */
1295 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1298 /** Distance between successive elements in an array of T.
1299 Includes ABI padding. */
1300 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1302 /** Returns the preferred alignment of a type. */
1303 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1305 /** Returns the minimum alignment of a type. */
1306 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1309 /// Computes the byte offset of the indexed struct element for a
1311 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1317 * Returns the minimum alignment of a type when part of a call frame.
1319 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1322 /** Disposes target data. */
1323 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1325 /** Creates a pass manager. */
1326 pub fn LLVMCreatePassManager() -> PassManagerRef;
1328 /** Creates a function-by-function pass manager */
1329 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1332 /** Disposes a pass manager. */
1333 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1335 /** Runs a pass manager on a module. */
1336 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1338 /** Runs the function passes on the provided function. */
1339 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1342 /** Initializes all the function passes scheduled in the manager */
1343 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1345 /** Finalizes all the function passes scheduled in the manager */
1346 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1348 pub fn LLVMInitializePasses();
1350 /** Adds a verification pass. */
1351 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1353 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1354 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1355 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1356 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1357 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1358 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1359 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1360 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1361 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1362 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1363 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1364 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1365 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1366 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1367 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1368 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1369 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1370 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1371 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1372 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1373 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1374 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1375 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1376 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1377 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1378 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1379 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1380 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1381 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1382 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1383 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1384 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1385 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1386 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1387 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1389 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1390 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1391 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1392 OptimizationLevel: c_uint);
1393 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1395 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1396 PMB: PassManagerBuilderRef,
1398 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1399 PMB: PassManagerBuilderRef,
1401 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1402 PMB: PassManagerBuilderRef,
1404 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1405 PMB: PassManagerBuilderRef,
1407 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1408 PMB: PassManagerBuilderRef,
1409 PM: PassManagerRef);
1411 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1412 PMB: PassManagerBuilderRef,
1413 PM: PassManagerRef);
1414 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1415 PMB: PassManagerBuilderRef,
1420 /** Destroys a memory buffer. */
1421 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1424 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1426 /** Opens an object file. */
1427 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1428 /** Closes an object file. */
1429 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1431 /** Enumerates the sections in an object file. */
1432 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1433 /** Destroys a section iterator. */
1434 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1435 /** Returns true if the section iterator is at the end of the section
1437 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1438 SI: SectionIteratorRef)
1440 /** Moves the section iterator to point to the next section. */
1441 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1442 /** Returns the current section size. */
1443 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1444 /** Returns the current section contents as a string buffer. */
1445 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
1447 /** Reads the given file and returns it as a memory buffer. Use
1448 LLVMDisposeMemoryBuffer() to get rid of it. */
1449 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
1451 /** Borrows the contents of the memory buffer (doesn't copy it) */
1452 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *c_char,
1453 InputDataLength: size_t,
1454 BufferName: *c_char,
1457 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *c_char,
1458 InputDataLength: size_t,
1459 BufferName: *c_char)
1462 pub fn LLVMIsMultithreaded() -> Bool;
1463 pub fn LLVMStartMultithreaded() -> Bool;
1465 /** Returns a string describing the last error caused by an LLVMRust*
1467 pub fn LLVMRustGetLastError() -> *c_char;
1469 /// Print the pass timings since static dtors aren't picking them up.
1470 pub fn LLVMRustPrintPassTimings();
1472 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1474 pub fn LLVMStructSetBody(StructTy: TypeRef,
1475 ElementTypes: *TypeRef,
1476 ElementCount: c_uint,
1479 pub fn LLVMConstNamedStruct(S: TypeRef,
1480 ConstantVals: *ValueRef,
1484 /** Enables LLVM debug output. */
1485 pub fn LLVMSetDebug(Enabled: c_int);
1487 /** Prepares inline assembly. */
1488 pub fn LLVMInlineAsm(Ty: TypeRef,
1490 Constraints: *c_char,
1496 pub static LLVMRustDebugMetadataVersion: u32;
1498 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1502 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1504 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1506 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1508 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1516 SplitName: *c_char);
1518 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1523 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1525 ParameterTypes: DIArray)
1528 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1529 Scope: DIDescriptor,
1531 LinkageName: *c_char,
1535 isLocalToUnit: bool,
1545 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1547 SizeInBits: c_ulonglong,
1548 AlignInBits: c_ulonglong,
1552 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1554 SizeInBits: c_ulonglong,
1555 AlignInBits: c_ulonglong,
1559 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1560 Scope: DIDescriptor,
1564 SizeInBits: c_ulonglong,
1565 AlignInBits: c_ulonglong,
1567 DerivedFrom: DIType,
1569 RunTimeLang: c_uint,
1570 VTableHolder: ValueRef,
1574 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1575 Scope: DIDescriptor,
1579 SizeInBits: c_ulonglong,
1580 AlignInBits: c_ulonglong,
1581 OffsetInBits: c_ulonglong,
1586 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1587 Scope: DIDescriptor,
1591 Discriminator: c_uint)
1594 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1595 Context: DIDescriptor,
1597 LinkageName: *c_char,
1601 isLocalToUnit: bool,
1604 -> DIGlobalVariable;
1606 pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
1608 Scope: DIDescriptor,
1613 AlwaysPreserve: bool,
1618 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1620 AlignInBits: c_ulonglong,
1622 Subscripts: DIArray)
1625 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1627 AlignInBits: c_ulonglong,
1629 Subscripts: DIArray)
1632 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1637 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1642 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1644 VarInfo: DIVariable,
1645 InsertAtEnd: BasicBlockRef)
1648 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1650 VarInfo: DIVariable,
1651 InsertBefore: ValueRef)
1654 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1659 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1664 SizeInBits: c_ulonglong,
1665 AlignInBits: c_ulonglong,
1667 ClassType: ValueRef)
1670 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1675 SizeInBits: c_ulonglong,
1676 AlignInBits: c_ulonglong,
1679 RunTimeLang: c_uint,
1683 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1685 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1694 pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
1696 pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
1698 pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
1706 AddrOpsCount: c_uint,
1710 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1717 pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1718 pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
1719 pub fn LLVMValueToString(value_ref: ValueRef) -> *c_char;
1721 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1723 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1725 pub fn LLVMInitializeX86TargetInfo();
1726 pub fn LLVMInitializeX86Target();
1727 pub fn LLVMInitializeX86TargetMC();
1728 pub fn LLVMInitializeX86AsmPrinter();
1729 pub fn LLVMInitializeX86AsmParser();
1730 pub fn LLVMInitializeARMTargetInfo();
1731 pub fn LLVMInitializeARMTarget();
1732 pub fn LLVMInitializeARMTargetMC();
1733 pub fn LLVMInitializeARMAsmPrinter();
1734 pub fn LLVMInitializeARMAsmParser();
1735 pub fn LLVMInitializeMipsTargetInfo();
1736 pub fn LLVMInitializeMipsTarget();
1737 pub fn LLVMInitializeMipsTargetMC();
1738 pub fn LLVMInitializeMipsAsmPrinter();
1739 pub fn LLVMInitializeMipsAsmParser();
1741 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *c_char) -> bool;
1742 pub fn LLVMRustCreateTargetMachine(Triple: *c_char,
1745 Model: CodeGenModel,
1747 Level: CodeGenOptLevel,
1750 NoFramePointerElim: bool) -> TargetMachineRef;
1751 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
1752 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
1755 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
1757 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef);
1758 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
1759 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
1763 FileType: FileType) -> bool;
1764 pub fn LLVMRustPrintModule(PM: PassManagerRef,
1767 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: **c_char);
1768 pub fn LLVMRustPrintPasses();
1769 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *c_char);
1770 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
1771 AddLifetimes: bool);
1772 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
1774 len: size_t) -> bool;
1775 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
1778 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
1780 pub fn LLVMRustOpenArchive(path: *c_char) -> ArchiveRef;
1781 pub fn LLVMRustArchiveReadSection(AR: ArchiveRef, name: *c_char,
1782 out_len: *mut size_t) -> *c_char;
1783 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
1785 pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef);
1786 pub fn LLVMVersionMinor() -> c_int;
1788 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
1789 data: *mut *c_char) -> c_int;
1793 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
1795 llvm::LLVMSetInstructionCallConv(instr, cc as c_uint);
1798 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
1800 llvm::LLVMSetFunctionCallConv(fn_, cc as c_uint);
1803 pub fn SetLinkage(global: ValueRef, link: Linkage) {
1805 llvm::LLVMSetLinkage(global, link as c_uint);
1809 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
1811 llvm::LLVMSetUnnamedAddr(global, unnamed as Bool);
1815 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
1817 llvm::LLVMSetThreadLocal(global, is_thread_local as Bool);
1821 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
1823 llvm::LLVMConstICmp(pred as c_ushort, v1, v2)
1826 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
1828 llvm::LLVMConstFCmp(pred as c_ushort, v1, v2)
1832 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
1834 llvm::LLVMAddFunctionAttr(fn_, attr as c_uint)
1837 /* Memory-managed object interface to type handles. */
1839 pub struct TypeNames {
1840 named_types: RefCell<HashMap<~str, TypeRef>>,
1844 pub fn new() -> TypeNames {
1846 named_types: RefCell::new(HashMap::new())
1850 pub fn associate_type(&self, s: &str, t: &Type) {
1851 assert!(self.named_types.borrow_mut().insert(s.to_owned(), t.to_ref()));
1854 pub fn find_type(&self, s: &str) -> Option<Type> {
1855 self.named_types.borrow().find_equiv(&s).map(|x| Type::from_ref(*x))
1858 pub fn type_to_str(&self, ty: Type) -> ~str {
1860 let s = llvm::LLVMTypeToString(ty.to_ref());
1861 let ret = from_c_str(s);
1862 free(s as *mut c_void);
1867 pub fn types_to_str(&self, tys: &[Type]) -> ~str {
1868 let strs: Vec<~str> = tys.iter().map(|t| self.type_to_str(*t)).collect();
1869 format!("[{}]", strs.connect(","))
1872 pub fn val_to_str(&self, val: ValueRef) -> ~str {
1874 let s = llvm::LLVMValueToString(val);
1875 let ret = from_c_str(s);
1876 free(s as *mut c_void);
1882 /* Memory-managed interface to target data. */
1884 pub struct target_data_res {
1885 pub td: TargetDataRef,
1888 impl Drop for target_data_res {
1889 fn drop(&mut self) {
1891 llvm::LLVMDisposeTargetData(self.td);
1896 pub fn target_data_res(td: TargetDataRef) -> target_data_res {
1902 pub struct TargetData {
1903 pub lltd: TargetDataRef,
1904 dtor: @target_data_res
1907 pub fn mk_target_data(string_rep: &str) -> TargetData {
1908 let lltd = string_rep.with_c_str(|buf| {
1909 unsafe { llvm::LLVMCreateTargetData(buf) }
1914 dtor: @target_data_res(lltd)
1918 /* Memory-managed interface to object files. */
1920 pub struct ObjectFile {
1921 pub llof: ObjectFileRef,
1925 // This will take ownership of llmb
1926 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1928 let llof = llvm::LLVMCreateObjectFile(llmb);
1929 if llof as int == 0 {
1930 // LLVMCreateObjectFile took ownership of llmb
1941 impl Drop for ObjectFile {
1942 fn drop(&mut self) {
1944 llvm::LLVMDisposeObjectFile(self.llof);
1949 /* Memory-managed interface to section iterators. */
1951 pub struct section_iter_res {
1952 pub si: SectionIteratorRef,
1955 impl Drop for section_iter_res {
1956 fn drop(&mut self) {
1958 llvm::LLVMDisposeSectionIterator(self.si);
1963 pub fn section_iter_res(si: SectionIteratorRef) -> section_iter_res {
1969 pub struct SectionIter {
1970 pub llsi: SectionIteratorRef,
1971 dtor: @section_iter_res
1974 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
1976 let llsi = llvm::LLVMGetSections(llof);
1979 dtor: @section_iter_res(llsi)