1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #[allow(non_uppercase_pattern_statics)];
13 use std::c_str::ToCStr;
14 use std::hashmap::HashMap;
15 use std::libc::{c_uint, c_ushort, c_void, free};
16 use std::str::raw::from_c_str;
18 use middle::trans::type_::Type;
20 pub type Opcode = u32;
21 pub type Bool = c_uint;
23 pub static True: Bool = 1 as Bool;
24 pub static False: Bool = 0 as Bool;
26 // Consts for the LLVM CallConv type, pre-cast to uint.
33 X86StdcallCallConv = 64,
34 X86FastcallCallConv = 65,
39 LLVMDefaultVisibility = 0,
41 ProtectedVisibility = 2,
46 AvailableExternallyLinkage = 1,
47 LinkOnceAnyLinkage = 2,
48 LinkOnceODRLinkage = 3,
49 LinkOnceODRAutoHideLinkage = 4,
55 DLLImportLinkage = 10,
56 DLLExportLinkage = 11,
57 ExternalWeakLinkage = 12,
60 LinkerPrivateLinkage = 15,
61 LinkerPrivateWeakLinkage = 16,
66 ZExtAttribute = 1 << 0,
67 SExtAttribute = 1 << 1,
68 NoReturnAttribute = 1 << 2,
69 InRegAttribute = 1 << 3,
70 StructRetAttribute = 1 << 4,
71 NoUnwindAttribute = 1 << 5,
72 NoAliasAttribute = 1 << 6,
73 ByValAttribute = 1 << 7,
74 NestAttribute = 1 << 8,
75 ReadNoneAttribute = 1 << 9,
76 ReadOnlyAttribute = 1 << 10,
77 NoInlineAttribute = 1 << 11,
78 AlwaysInlineAttribute = 1 << 12,
79 OptimizeForSizeAttribute = 1 << 13,
80 StackProtectAttribute = 1 << 14,
81 StackProtectReqAttribute = 1 << 15,
82 AlignmentAttribute = 31 << 16,
83 NoCaptureAttribute = 1 << 21,
84 NoRedZoneAttribute = 1 << 22,
85 NoImplicitFloatAttribute = 1 << 23,
86 NakedAttribute = 1 << 24,
87 InlineHintAttribute = 1 << 25,
88 StackAttribute = 7 << 26,
89 ReturnsTwiceAttribute = 1 << 29,
90 UWTableAttribute = 1 << 30,
91 NonLazyBindAttribute = 1 << 31,
94 // enum for the LLVM IntPredicate type
95 pub enum IntPredicate {
108 // enum for the LLVM RealPredicate type
109 pub enum RealPredicate {
110 RealPredicateFalse = 0,
125 RealPredicateTrue = 15,
128 // The LLVM TypeKind type - must stay in sync with the def of
129 // LLVMTypeKind in llvm/include/llvm-c/Core.h
152 pub enum AtomicBinOp {
167 pub enum AtomicOrdering {
171 // Consume = 3, // Not specified yet.
175 SequentiallyConsistent = 7
178 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
194 // Inline Asm Dialect
195 pub enum AsmDialect {
202 pub enum CodeGenOptLevel {
203 CodeGenLevelNone = 0,
204 CodeGenLevelLess = 1,
205 CodeGenLevelDefault = 2,
206 CodeGenLevelAggressive = 3,
214 RelocDynamicNoPic = 3,
218 pub enum CodeGenModel {
219 CodeModelDefault = 0,
220 CodeModelJITDefault = 1,
227 // Opaque pointer types
228 pub enum Module_opaque {}
229 pub type ModuleRef = *Module_opaque;
230 pub enum Context_opaque {}
231 pub type ContextRef = *Context_opaque;
232 pub enum Type_opaque {}
233 pub type TypeRef = *Type_opaque;
234 pub enum Value_opaque {}
235 pub type ValueRef = *Value_opaque;
236 pub enum BasicBlock_opaque {}
237 pub type BasicBlockRef = *BasicBlock_opaque;
238 pub enum Builder_opaque {}
239 pub type BuilderRef = *Builder_opaque;
240 pub enum ExecutionEngine_opaque {}
241 pub type ExecutionEngineRef = *ExecutionEngine_opaque;
242 pub enum MemoryBuffer_opaque {}
243 pub type MemoryBufferRef = *MemoryBuffer_opaque;
244 pub enum PassManager_opaque {}
245 pub type PassManagerRef = *PassManager_opaque;
246 pub enum PassManagerBuilder_opaque {}
247 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
248 pub enum Use_opaque {}
249 pub type UseRef = *Use_opaque;
250 pub enum TargetData_opaque {}
251 pub type TargetDataRef = *TargetData_opaque;
252 pub enum ObjectFile_opaque {}
253 pub type ObjectFileRef = *ObjectFile_opaque;
254 pub enum SectionIterator_opaque {}
255 pub type SectionIteratorRef = *SectionIterator_opaque;
256 pub enum Pass_opaque {}
257 pub type PassRef = *Pass_opaque;
258 pub enum TargetMachine_opaque {}
259 pub type TargetMachineRef = *TargetMachine_opaque;
262 use super::{ValueRef};
264 pub enum DIBuilder_opaque {}
265 pub type DIBuilderRef = *DIBuilder_opaque;
267 pub type DIDescriptor = ValueRef;
268 pub type DIScope = DIDescriptor;
269 pub type DILocation = DIDescriptor;
270 pub type DIFile = DIScope;
271 pub type DILexicalBlock = DIScope;
272 pub type DISubprogram = DIScope;
273 pub type DIType = DIDescriptor;
274 pub type DIBasicType = DIType;
275 pub type DIDerivedType = DIType;
276 pub type DICompositeType = DIDerivedType;
277 pub type DIVariable = DIDescriptor;
278 pub type DIArray = DIDescriptor;
279 pub type DISubrange = DIDescriptor;
281 pub enum DIDescriptorFlags {
282 FlagPrivate = 1 << 0,
283 FlagProtected = 1 << 1,
284 FlagFwdDecl = 1 << 2,
285 FlagAppleBlock = 1 << 3,
286 FlagBlockByrefStruct = 1 << 4,
287 FlagVirtual = 1 << 5,
288 FlagArtificial = 1 << 6,
289 FlagExplicit = 1 << 7,
290 FlagPrototyped = 1 << 8,
291 FlagObjcClassComplete = 1 << 9,
292 FlagObjectPointer = 1 << 10,
293 FlagVector = 1 << 11,
294 FlagStaticMember = 1 << 12
299 use super::{AtomicBinOp, AtomicOrdering, BasicBlockRef, ExecutionEngineRef};
300 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
301 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
302 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
303 use super::{ValueRef, TargetMachineRef, FileType};
304 use super::{CodeGenModel, RelocMode, CodeGenOptLevel};
305 use super::debuginfo::*;
306 use std::libc::{c_char, c_int, c_longlong, c_ushort, c_uint, c_ulonglong,
309 // Link to our native llvm bindings (things that we need to use the C++ api
310 // for) and because llvm is written in C++ we need to link against libstdc++
312 // You'll probably notice that there is an omission of all LLVM libraries
313 // from this location. This is because the set of LLVM libraries that we
314 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
315 // figure out the exact set of libraries. To do this, the build system
316 // generates an llvmdeps.rs file next to this one which will be
317 // automatically updated whenever LLVM is updated to include an up-to-date
318 // set of the libraries we need to link to LLVM for.
319 #[link(name = "rustllvm", kind = "static")]
320 #[link(name = "stdc++")]
322 /* Create and destroy contexts. */
323 pub fn LLVMContextCreate() -> ContextRef;
324 pub fn LLVMContextDispose(C: ContextRef);
325 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
330 /* Create and destroy modules. */
331 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
334 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
335 pub fn LLVMDisposeModule(M: ModuleRef);
337 /** Data layout. See Module::getDataLayout. */
338 pub fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
339 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
341 /** Target triple. See Module::getTargetTriple. */
342 pub fn LLVMGetTarget(M: ModuleRef) -> *c_char;
343 pub fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
345 /** See Module::dump. */
346 pub fn LLVMDumpModule(M: ModuleRef);
348 /** See Module::setModuleInlineAsm. */
349 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
351 /** See llvm::LLVMTypeKind::getTypeID. */
352 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
354 /** See llvm::LLVMType::getContext. */
355 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
357 /* Operations on integer types */
358 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
359 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
360 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
361 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
362 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
363 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
366 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
368 /* Operations on real types */
369 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
370 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
371 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
372 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
373 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
375 /* Operations on function types */
376 pub fn LLVMFunctionType(ReturnType: TypeRef,
377 ParamTypes: *TypeRef,
381 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
382 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
383 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
384 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
386 /* Operations on struct types */
387 pub fn LLVMStructTypeInContext(C: ContextRef,
388 ElementTypes: *TypeRef,
389 ElementCount: c_uint,
392 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
393 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
395 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
397 /* Operations on array, pointer, and vector types (sequence types) */
398 pub fn LLVMArrayType(ElementType: TypeRef, ElementCount: c_uint)
400 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
402 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
405 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
406 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
407 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
408 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
410 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
412 /* Operations on other types */
413 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
414 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
415 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
417 /* Operations on all values */
418 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
419 pub fn LLVMGetValueName(Val: ValueRef) -> *c_char;
420 pub fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
421 pub fn LLVMDumpValue(Val: ValueRef);
422 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
423 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
424 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
425 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
427 /* Operations on Uses */
428 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
429 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
430 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
431 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
433 /* Operations on Users */
434 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
435 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
436 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
438 /* Operations on constants of any type */
439 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
441 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
442 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
444 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
446 /* only for int/vector */
447 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
448 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
449 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
450 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
451 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
453 /* Operations on metadata */
454 pub fn LLVMMDStringInContext(C: ContextRef,
458 pub fn LLVMMDNodeInContext(C: ContextRef,
462 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
466 /* Operations on scalar constants */
467 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
469 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8)
471 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
476 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
477 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char)
479 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
483 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
484 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
487 /* Operations on composite constants */
488 pub fn LLVMConstStringInContext(C: ContextRef,
491 DontNullTerminate: Bool)
493 pub fn LLVMConstStructInContext(C: ContextRef,
494 ConstantVals: *ValueRef,
499 pub fn LLVMConstArray(ElementTy: TypeRef,
500 ConstantVals: *ValueRef,
503 pub fn LLVMConstVector(ScalarConstantVals: *ValueRef, Size: c_uint)
506 /* Constant expressions */
507 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
508 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
509 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
510 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
511 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
512 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
513 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
514 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
516 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
518 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
520 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
522 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
524 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
526 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
528 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
530 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
532 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
534 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
536 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
538 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
540 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
542 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
543 RHSConstant: ValueRef)
545 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
547 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
549 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
551 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
553 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
555 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
557 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
559 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
561 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
563 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
565 pub fn LLVMConstGEP(ConstantVal: ValueRef,
566 ConstantIndices: *ValueRef,
569 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
570 ConstantIndices: *ValueRef,
573 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
575 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
577 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
579 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
581 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
583 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
585 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
587 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
589 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
591 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
593 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
595 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
597 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
599 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
601 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
603 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
605 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
609 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
611 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
612 ConstantIfTrue: ValueRef,
613 ConstantIfFalse: ValueRef)
615 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
616 IndexConstant: ValueRef)
618 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
619 ElementValueConstant: ValueRef,
620 IndexConstant: ValueRef)
622 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
623 VectorBConstant: ValueRef,
624 MaskConstant: ValueRef)
626 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
630 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
631 ElementValueConstant: ValueRef,
635 pub fn LLVMConstInlineAsm(Ty: TypeRef,
637 Constraints: *c_char,
638 HasSideEffects: Bool,
641 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
645 /* Operations on global variables, functions, and aliases (globals) */
646 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
647 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
648 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
649 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
650 pub fn LLVMGetSection(Global: ValueRef) -> *c_char;
651 pub fn LLVMSetSection(Global: ValueRef, Section: *c_char);
652 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
653 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
654 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
655 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
658 /* Operations on global variables */
659 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char)
661 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
664 AddressSpace: c_uint)
666 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
667 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
668 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
669 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
670 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
671 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
672 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
673 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
674 ConstantVal: ValueRef);
675 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
676 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
677 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
678 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
680 /* Operations on aliases */
681 pub fn LLVMAddAlias(M: ModuleRef,
687 /* Operations on functions */
688 pub fn LLVMAddFunction(M: ModuleRef,
692 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
693 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
694 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
695 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
696 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
697 pub fn LLVMDeleteFunction(Fn: ValueRef);
698 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
702 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
703 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
704 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
705 pub fn LLVMGetGC(Fn: ValueRef) -> *c_char;
706 pub fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
707 pub fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_uint);
708 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, Name: *c_char);
709 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
711 pub fn LLVMAddReturnAttribute(Fn: ValueRef, PA: c_uint);
712 pub fn LLVMRemoveReturnAttribute(Fn: ValueRef, PA: c_uint);
714 pub fn LLVMAddColdAttribute(Fn: ValueRef);
716 pub fn LLVMRemoveFunctionAttr(Fn: ValueRef,
718 HighPA: c_ulonglong);
720 /* Operations on parameters */
721 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
722 pub fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
723 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
724 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
725 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
726 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
727 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
728 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
729 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
730 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
731 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
732 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
734 /* Operations on basic blocks */
735 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
736 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
737 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
738 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
739 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
740 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
741 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
742 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
743 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
744 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
745 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
747 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
751 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
755 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
757 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
758 MoveAfter: BasicBlockRef);
760 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
761 MoveBefore: BasicBlockRef);
763 /* Operations on instructions */
764 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
765 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
766 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
767 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
768 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
769 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
771 /* Operations on call sites */
772 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
773 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
774 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
777 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
780 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
784 /* Operations on call instructions (only) */
785 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
786 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
788 /* Operations on phi nodes */
789 pub fn LLVMAddIncoming(PhiNode: ValueRef,
790 IncomingValues: *ValueRef,
791 IncomingBlocks: *BasicBlockRef,
793 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
794 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
796 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
799 /* Instruction builders */
800 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
801 pub fn LLVMPositionBuilder(Builder: BuilderRef,
802 Block: BasicBlockRef,
804 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
806 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
807 Block: BasicBlockRef);
808 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
809 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
810 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
811 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
814 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
815 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
818 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
819 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
820 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
823 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
824 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
825 pub fn LLVMBuildAggregateRet(B: BuilderRef,
829 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
830 pub fn LLVMBuildCondBr(B: BuilderRef,
835 pub fn LLVMBuildSwitch(B: BuilderRef,
840 pub fn LLVMBuildIndirectBr(B: BuilderRef,
844 pub fn LLVMBuildInvoke(B: BuilderRef,
849 Catch: BasicBlockRef,
852 pub fn LLVMBuildLandingPad(B: BuilderRef,
858 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
859 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
861 /* Add a case to the switch instruction */
862 pub fn LLVMAddCase(Switch: ValueRef,
864 Dest: BasicBlockRef);
866 /* Add a destination to the indirectbr instruction */
867 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
869 /* Add a clause to the landing pad instruction */
870 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
872 /* Set the cleanup on a landing pad instruction */
873 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
876 pub fn LLVMBuildAdd(B: BuilderRef,
881 pub fn LLVMBuildNSWAdd(B: BuilderRef,
886 pub fn LLVMBuildNUWAdd(B: BuilderRef,
891 pub fn LLVMBuildFAdd(B: BuilderRef,
896 pub fn LLVMBuildSub(B: BuilderRef,
901 pub fn LLVMBuildNSWSub(B: BuilderRef,
906 pub fn LLVMBuildNUWSub(B: BuilderRef,
911 pub fn LLVMBuildFSub(B: BuilderRef,
916 pub fn LLVMBuildMul(B: BuilderRef,
921 pub fn LLVMBuildNSWMul(B: BuilderRef,
926 pub fn LLVMBuildNUWMul(B: BuilderRef,
931 pub fn LLVMBuildFMul(B: BuilderRef,
936 pub fn LLVMBuildUDiv(B: BuilderRef,
941 pub fn LLVMBuildSDiv(B: BuilderRef,
946 pub fn LLVMBuildExactSDiv(B: BuilderRef,
951 pub fn LLVMBuildFDiv(B: BuilderRef,
956 pub fn LLVMBuildURem(B: BuilderRef,
961 pub fn LLVMBuildSRem(B: BuilderRef,
966 pub fn LLVMBuildFRem(B: BuilderRef,
971 pub fn LLVMBuildShl(B: BuilderRef,
976 pub fn LLVMBuildLShr(B: BuilderRef,
981 pub fn LLVMBuildAShr(B: BuilderRef,
986 pub fn LLVMBuildAnd(B: BuilderRef,
991 pub fn LLVMBuildOr(B: BuilderRef,
996 pub fn LLVMBuildXor(B: BuilderRef,
1001 pub fn LLVMBuildBinOp(B: BuilderRef,
1007 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1009 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1011 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1013 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char)
1015 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char)
1019 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1021 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1026 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1028 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1033 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1034 pub fn LLVMBuildLoad(B: BuilderRef,
1035 PointerVal: ValueRef,
1039 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1042 pub fn LLVMBuildGEP(B: BuilderRef,
1048 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1054 pub fn LLVMBuildStructGEP(B: BuilderRef,
1059 pub fn LLVMBuildGlobalString(B: BuilderRef,
1063 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1069 pub fn LLVMBuildTrunc(B: BuilderRef,
1074 pub fn LLVMBuildZExt(B: BuilderRef,
1079 pub fn LLVMBuildSExt(B: BuilderRef,
1084 pub fn LLVMBuildFPToUI(B: BuilderRef,
1089 pub fn LLVMBuildFPToSI(B: BuilderRef,
1094 pub fn LLVMBuildUIToFP(B: BuilderRef,
1099 pub fn LLVMBuildSIToFP(B: BuilderRef,
1104 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1109 pub fn LLVMBuildFPExt(B: BuilderRef,
1114 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1119 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1124 pub fn LLVMBuildBitCast(B: BuilderRef,
1129 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1134 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1139 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1144 pub fn LLVMBuildCast(B: BuilderRef,
1148 Name: *c_char) -> ValueRef;
1149 pub fn LLVMBuildPointerCast(B: BuilderRef,
1154 pub fn LLVMBuildIntCast(B: BuilderRef,
1159 pub fn LLVMBuildFPCast(B: BuilderRef,
1166 pub fn LLVMBuildICmp(B: BuilderRef,
1172 pub fn LLVMBuildFCmp(B: BuilderRef,
1179 /* Miscellaneous instructions */
1180 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char)
1182 pub fn LLVMBuildCall(B: BuilderRef,
1188 pub fn LLVMBuildSelect(B: BuilderRef,
1194 pub fn LLVMBuildVAArg(B: BuilderRef,
1199 pub fn LLVMBuildExtractElement(B: BuilderRef,
1204 pub fn LLVMBuildInsertElement(B: BuilderRef,
1210 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1216 pub fn LLVMBuildExtractValue(B: BuilderRef,
1221 pub fn LLVMBuildInsertValue(B: BuilderRef,
1228 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1230 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char)
1232 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1238 /* Atomic Operations */
1239 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1240 PointerVal: ValueRef,
1242 Order: AtomicOrdering,
1246 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1249 Order: AtomicOrdering,
1253 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1257 Order: AtomicOrdering)
1259 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1263 Order: AtomicOrdering,
1264 SingleThreaded: Bool)
1267 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1270 /* Selected entries from the downcasts. */
1271 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1272 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1274 /** Writes a module to the specified path. Returns 0 on success. */
1275 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
1277 /** Creates target data from a target layout string. */
1278 pub fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
1279 /// Adds the target data to the given pass manager. The pass manager
1280 /// references the target data only weakly.
1281 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1282 /** Number of bytes clobbered when doing a Store to *T. */
1283 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1286 /** Number of bytes clobbered when doing a Store to *T. */
1287 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1290 /** Distance between successive elements in an array of T.
1291 Includes ABI padding. */
1292 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
1294 /** Returns the preferred alignment of a type. */
1295 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1297 /** Returns the minimum alignment of a type. */
1298 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1301 /// Computes the byte offset of the indexed struct element for a
1303 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1309 * Returns the minimum alignment of a type when part of a call frame.
1311 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1314 /** Disposes target data. */
1315 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1317 /** Creates a pass manager. */
1318 pub fn LLVMCreatePassManager() -> PassManagerRef;
1320 /** Creates a function-by-function pass manager */
1321 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1324 /** Disposes a pass manager. */
1325 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1327 /** Runs a pass manager on a module. */
1328 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1330 /** Runs the function passes on the provided function. */
1331 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1334 /** Initializes all the function passes scheduled in the manager */
1335 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1337 /** Finalizes all the function passes scheduled in the manager */
1338 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1340 pub fn LLVMInitializePasses();
1342 /** Adds a verification pass. */
1343 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1345 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1346 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1347 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1348 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1349 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1350 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1351 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1352 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1353 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1354 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1355 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1356 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1357 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1358 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1359 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1360 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1361 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1362 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1363 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1364 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1365 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1366 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1367 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1368 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1369 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1370 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1371 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1372 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1373 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1374 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1375 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1376 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1377 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1378 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1379 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1381 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1382 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1383 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1384 OptimizationLevel: c_uint);
1385 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1387 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1388 PMB: PassManagerBuilderRef,
1390 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1391 PMB: PassManagerBuilderRef,
1393 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1394 PMB: PassManagerBuilderRef,
1396 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1397 PMB: PassManagerBuilderRef,
1399 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1400 PMB: PassManagerBuilderRef,
1401 PM: PassManagerRef);
1403 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1404 PMB: PassManagerBuilderRef,
1405 PM: PassManagerRef);
1407 /** Destroys a memory buffer. */
1408 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1411 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1413 /** Opens an object file. */
1414 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1415 /** Closes an object file. */
1416 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1418 /** Enumerates the sections in an object file. */
1419 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1420 /** Destroys a section iterator. */
1421 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1422 /** Returns true if the section iterator is at the end of the section
1424 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1425 SI: SectionIteratorRef)
1427 /** Moves the section iterator to point to the next section. */
1428 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1429 /** Returns the current section name. */
1430 pub fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1431 /** Returns the current section size. */
1432 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1433 /** Returns the current section contents as a string buffer. */
1434 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
1436 /** Reads the given file and returns it as a memory buffer. Use
1437 LLVMDisposeMemoryBuffer() to get rid of it. */
1438 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
1440 /** Borrows the contents of the memory buffer (doesn't copy it) */
1441 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *c_char,
1442 InputDataLength: size_t,
1443 BufferName: *c_char,
1446 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *c_char,
1447 InputDataLength: size_t,
1448 BufferName: *c_char)
1451 /** Returns a string describing the last error caused by an LLVMRust*
1453 pub fn LLVMRustGetLastError() -> *c_char;
1455 /// Print the pass timings since static dtors aren't picking them up.
1456 pub fn LLVMRustPrintPassTimings();
1458 pub fn LLVMRustStartMultithreading() -> bool;
1460 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1462 pub fn LLVMStructSetBody(StructTy: TypeRef,
1463 ElementTypes: *TypeRef,
1464 ElementCount: c_uint,
1467 pub fn LLVMConstNamedStruct(S: TypeRef,
1468 ConstantVals: *ValueRef,
1472 /** Enables LLVM debug output. */
1473 pub fn LLVMSetDebug(Enabled: c_int);
1475 /** Prepares inline assembly. */
1476 pub fn LLVMInlineAsm(Ty: TypeRef,
1478 Constraints: *c_char,
1485 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1487 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1489 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1491 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1499 SplitName: *c_char);
1501 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1506 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1508 ParameterTypes: DIArray)
1511 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1512 Scope: DIDescriptor,
1514 LinkageName: *c_char,
1518 isLocalToUnit: bool,
1528 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1530 SizeInBits: c_ulonglong,
1531 AlignInBits: c_ulonglong,
1535 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1537 SizeInBits: c_ulonglong,
1538 AlignInBits: c_ulonglong,
1542 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1543 Scope: DIDescriptor,
1547 SizeInBits: c_ulonglong,
1548 AlignInBits: c_ulonglong,
1550 DerivedFrom: DIType,
1552 RunTimeLang: c_uint,
1553 VTableHolder: ValueRef,
1557 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1558 Scope: DIDescriptor,
1562 SizeInBits: c_ulonglong,
1563 AlignInBits: c_ulonglong,
1564 OffsetInBits: c_ulonglong,
1569 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1570 Scope: DIDescriptor,
1576 pub fn LLVMDIBuilderCreateLocalVariable(Builder: DIBuilderRef,
1578 Scope: DIDescriptor,
1583 AlwaysPreserve: bool,
1588 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1590 AlignInBits: c_ulonglong,
1592 Subscripts: DIArray)
1595 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1597 AlignInBits: c_ulonglong,
1599 Subscripts: DIArray)
1602 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1607 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1612 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1614 VarInfo: DIVariable,
1615 InsertAtEnd: BasicBlockRef)
1618 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1620 VarInfo: DIVariable,
1621 InsertBefore: ValueRef)
1624 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1629 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1634 SizeInBits: c_ulonglong,
1635 AlignInBits: c_ulonglong,
1637 ClassType: ValueRef)
1640 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1645 SizeInBits: c_ulonglong,
1646 AlignInBits: c_ulonglong,
1649 RunTimeLang: c_uint)
1652 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1654 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1663 pub fn LLVMDIBuilderCreateOpDeref(IntType: TypeRef) -> ValueRef;
1665 pub fn LLVMDIBuilderCreateOpPlus(IntType: TypeRef) -> ValueRef;
1667 pub fn LLVMDIBuilderCreateComplexVariable(Builder: DIBuilderRef,
1675 AddrOpsCount: c_uint,
1679 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1686 pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1687 pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
1689 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1691 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1693 pub fn LLVMInitializeX86TargetInfo();
1694 pub fn LLVMInitializeX86Target();
1695 pub fn LLVMInitializeX86TargetMC();
1696 pub fn LLVMInitializeX86AsmPrinter();
1697 pub fn LLVMInitializeX86AsmParser();
1698 pub fn LLVMInitializeARMTargetInfo();
1699 pub fn LLVMInitializeARMTarget();
1700 pub fn LLVMInitializeARMTargetMC();
1701 pub fn LLVMInitializeARMAsmPrinter();
1702 pub fn LLVMInitializeARMAsmParser();
1703 pub fn LLVMInitializeMipsTargetInfo();
1704 pub fn LLVMInitializeMipsTarget();
1705 pub fn LLVMInitializeMipsTargetMC();
1706 pub fn LLVMInitializeMipsAsmPrinter();
1707 pub fn LLVMInitializeMipsAsmParser();
1709 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *c_char) -> bool;
1710 pub fn LLVMRustCreateTargetMachine(Triple: *c_char,
1713 Model: CodeGenModel,
1715 Level: CodeGenOptLevel,
1717 UseSoftFP: bool) -> TargetMachineRef;
1718 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
1719 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
1722 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
1724 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef);
1725 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
1726 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
1730 FileType: FileType) -> bool;
1731 pub fn LLVMRustPrintModule(PM: PassManagerRef,
1734 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: **c_char);
1735 pub fn LLVMRustPrintPasses();
1736 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *c_char);
1737 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
1738 AddLifetimes: bool);
1742 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
1744 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
1747 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
1749 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
1752 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
1754 llvm::LLVMSetLinkage(Global, Link as c_uint);
1758 pub fn SetUnnamedAddr(Global: ValueRef, Unnamed: bool) {
1760 llvm::LLVMSetUnnamedAddr(Global, Unnamed as Bool);
1764 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
1766 llvm::LLVMSetThreadLocal(global, is_thread_local as Bool);
1770 pub fn ConstICmp(Pred: IntPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1772 llvm::LLVMConstICmp(Pred as c_ushort, V1, V2)
1775 pub fn ConstFCmp(Pred: RealPredicate, V1: ValueRef, V2: ValueRef) -> ValueRef {
1777 llvm::LLVMConstFCmp(Pred as c_ushort, V1, V2)
1781 pub fn SetFunctionAttribute(Fn: ValueRef, attr: Attribute) {
1783 llvm::LLVMAddFunctionAttr(Fn, attr as c_uint)
1786 /* Memory-managed object interface to type handles. */
1788 pub struct TypeNames {
1789 type_names: HashMap<TypeRef, ~str>,
1790 named_types: HashMap<~str, TypeRef>
1794 pub fn new() -> TypeNames {
1796 type_names: HashMap::new(),
1797 named_types: HashMap::new()
1801 pub fn associate_type(&mut self, s: &str, t: &Type) {
1802 assert!(self.type_names.insert(t.to_ref(), s.to_owned()));
1803 assert!(self.named_types.insert(s.to_owned(), t.to_ref()));
1806 pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
1807 match self.type_names.find(&ty.to_ref()) {
1808 Some(a) => Some(a.slice(0, a.len())),
1813 pub fn find_type(&self, s: &str) -> Option<Type> {
1814 self.named_types.find_equiv(&s).map(|x| Type::from_ref(*x))
1817 pub fn type_to_str(&self, ty: Type) -> ~str {
1819 let s = llvm::LLVMTypeToString(ty.to_ref());
1820 let ret = from_c_str(s);
1826 pub fn types_to_str(&self, tys: &[Type]) -> ~str {
1827 let strs = tys.map(|t| self.type_to_str(*t));
1828 format!("[{}]", strs.connect(","))
1831 pub fn val_to_str(&self, val: ValueRef) -> ~str {
1833 let ty = Type::from_ref(llvm::LLVMTypeOf(val));
1834 self.type_to_str(ty)
1839 /* Memory-managed interface to target data. */
1841 pub struct target_data_res {
1845 impl Drop for target_data_res {
1846 fn drop(&mut self) {
1848 llvm::LLVMDisposeTargetData(self.TD);
1853 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
1859 pub struct TargetData {
1860 lltd: TargetDataRef,
1861 dtor: @target_data_res
1864 pub fn mk_target_data(string_rep: &str) -> TargetData {
1865 let lltd = string_rep.with_c_str(|buf| {
1866 unsafe { llvm::LLVMCreateTargetData(buf) }
1871 dtor: @target_data_res(lltd)
1875 /* Memory-managed interface to pass managers. */
1877 pub struct pass_manager_res {
1881 impl Drop for pass_manager_res {
1882 fn drop(&mut self) {
1884 llvm::LLVMDisposePassManager(self.PM);
1889 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
1895 pub struct PassManager {
1896 llpm: PassManagerRef,
1897 dtor: @pass_manager_res
1900 pub fn mk_pass_manager() -> PassManager {
1902 let llpm = llvm::LLVMCreatePassManager();
1906 dtor: @pass_manager_res(llpm)
1911 /* Memory-managed interface to object files. */
1913 pub struct ObjectFile {
1914 llof: ObjectFileRef,
1918 // This will take ownership of llmb
1919 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1921 let llof = llvm::LLVMCreateObjectFile(llmb);
1922 if llof as int == 0 {
1923 llvm::LLVMDisposeMemoryBuffer(llmb);
1934 impl Drop for ObjectFile {
1935 fn drop(&mut self) {
1937 llvm::LLVMDisposeObjectFile(self.llof);
1942 /* Memory-managed interface to section iterators. */
1944 pub struct section_iter_res {
1945 SI: SectionIteratorRef,
1948 impl Drop for section_iter_res {
1949 fn drop(&mut self) {
1951 llvm::LLVMDisposeSectionIterator(self.SI);
1956 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
1962 pub struct SectionIter {
1963 llsi: SectionIteratorRef,
1964 dtor: @section_iter_res
1967 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
1969 let llsi = llvm::LLVMGetSections(llof);
1972 dtor: @section_iter_res(llsi)