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.
13 use core::libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
18 use std::oldmap::HashMap;
20 pub type Opcode = u32;
21 pub type Bool = c_uint;
23 pub const True: Bool = 1 as Bool;
24 pub const False: Bool = 0 as Bool;
26 // Consts for the LLVM CallConv type, pre-cast to uint.
32 X86StdcallCallConv = 64,
33 X86FastcallCallConv = 65,
37 LLVMDefaultVisibility = 0,
39 ProtectedVisibility = 2,
44 AvailableExternallyLinkage = 1,
45 LinkOnceAnyLinkage = 2,
46 LinkOnceODRLinkage = 3,
47 LinkOnceODRAutoHideLinkage = 4,
53 DLLImportLinkage = 10,
54 DLLExportLinkage = 11,
55 ExternalWeakLinkage = 12,
58 LinkerPrivateLinkage = 15,
59 LinkerPrivateWeakLinkage = 16,
65 NoReturnAttribute = 4,
67 StructRetAttribute = 16,
68 NoUnwindAttribute = 32,
69 NoAliasAttribute = 64,
72 ReadNoneAttribute = 512,
73 ReadOnlyAttribute = 1024,
74 NoInlineAttribute = 2048,
75 AlwaysInlineAttribute = 4096,
76 OptimizeForSizeAttribute = 8192,
77 StackProtectAttribute = 16384,
78 StackProtectReqAttribute = 32768,
80 AlignmentAttribute = 2031616,
81 NoCaptureAttribute = 2097152,
82 NoRedZoneAttribute = 4194304,
83 NoImplicitFloatAttribute = 8388608,
84 NakedAttribute = 16777216,
85 InlineHintAttribute = 33554432,
87 StackAttribute = 469762048,
88 ReturnsTwiceAttribute = 536870912,
90 UWTableAttribute = 1073741824,
91 NonLazyBindAttribute = 2147483648,
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 // enum for the LLVM TypeKind type - must stay in sync with the def of
129 // LLVMTypeKind in llvm/include/llvm-c/Core.h
150 pub enum AtomicBinOp {
164 pub enum AtomicOrdering {
168 // Consume = 3, // Not specified yet.
172 SequentiallyConsistent = 7
175 // FIXME: Not used right now, but will be once #2334 is fixed
176 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
191 // Inline Asm Dialect
192 pub enum AsmDialect {
197 // Opaque pointer types
198 pub enum Module_opaque {}
199 pub type ModuleRef = *Module_opaque;
200 pub enum Context_opaque {}
201 pub type ContextRef = *Context_opaque;
202 pub enum Type_opaque {}
203 pub type TypeRef = *Type_opaque;
204 pub enum Value_opaque {}
205 pub type ValueRef = *Value_opaque;
206 pub enum BasicBlock_opaque {}
207 pub type BasicBlockRef = *BasicBlock_opaque;
208 pub enum Builder_opaque {}
209 pub type BuilderRef = *Builder_opaque;
210 pub enum MemoryBuffer_opaque {}
211 pub type MemoryBufferRef = *MemoryBuffer_opaque;
212 pub enum PassManager_opaque {}
213 pub type PassManagerRef = *PassManager_opaque;
214 pub enum PassManagerBuilder_opaque {}
215 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
216 pub enum Use_opaque {}
217 pub type UseRef = *Use_opaque;
218 pub enum TargetData_opaque {}
219 pub type TargetDataRef = *TargetData_opaque;
220 pub enum ObjectFile_opaque {}
221 pub type ObjectFileRef = *ObjectFile_opaque;
222 pub enum SectionIterator_opaque {}
223 pub type SectionIteratorRef = *SectionIterator_opaque;
226 use super::{AsmDialect, AtomicBinOp, AtomicOrdering, BasicBlockRef};
227 use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
228 use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
229 use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
230 use super::{ValueRef};
232 use core::libc::{c_char, c_int, c_longlong, c_uint, c_ulonglong};
234 #[link_args = "-Lrustllvm -lrustllvm"]
235 #[link_name = "rustllvm"]
238 /* Create and destroy contexts. */
239 pub unsafe fn LLVMContextCreate() -> ContextRef;
240 pub unsafe fn LLVMGetGlobalContext() -> ContextRef;
241 pub unsafe fn LLVMContextDispose(C: ContextRef);
242 pub unsafe fn LLVMGetMDKindIDInContext(C: ContextRef,
246 pub unsafe fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
248 /* Create and destroy modules. */
249 pub unsafe fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
252 pub unsafe fn LLVMDisposeModule(M: ModuleRef);
254 /** Data layout. See Module::getDataLayout. */
255 pub unsafe fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
256 pub unsafe fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
258 /** Target triple. See Module::getTargetTriple. */
259 pub unsafe fn LLVMGetTarget(M: ModuleRef) -> *c_char;
260 pub unsafe fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
262 /** See Module::dump. */
263 pub unsafe fn LLVMDumpModule(M: ModuleRef);
265 /** See Module::setModuleInlineAsm. */
266 pub unsafe fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
268 /** See llvm::LLVMTypeKind::getTypeID. */
269 pub unsafe fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
271 /** See llvm::LLVMType::getContext. */
272 pub unsafe fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
274 /* Operations on integer types */
275 pub unsafe fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
276 pub unsafe fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
277 pub unsafe fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
278 pub unsafe fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
279 pub unsafe fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
280 pub unsafe fn LLVMIntTypeInContext(C: ContextRef,
281 NumBits: c_uint) -> TypeRef;
283 pub unsafe fn LLVMInt1Type() -> TypeRef;
284 pub unsafe fn LLVMInt8Type() -> TypeRef;
285 pub unsafe fn LLVMInt16Type() -> TypeRef;
286 pub unsafe fn LLVMInt32Type() -> TypeRef;
287 pub unsafe fn LLVMInt64Type() -> TypeRef;
288 pub unsafe fn LLVMIntType(NumBits: c_uint) -> TypeRef;
289 pub unsafe fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
291 /* Operations on real types */
292 pub unsafe fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
293 pub unsafe fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
294 pub unsafe fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
295 pub unsafe fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
296 pub unsafe fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
298 pub unsafe fn LLVMFloatType() -> TypeRef;
299 pub unsafe fn LLVMDoubleType() -> TypeRef;
300 pub unsafe fn LLVMX86FP80Type() -> TypeRef;
301 pub unsafe fn LLVMFP128Type() -> TypeRef;
302 pub unsafe fn LLVMPPCFP128Type() -> TypeRef;
304 /* Operations on function types */
305 pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
306 ParamTypes: *TypeRef,
310 pub unsafe fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
311 pub unsafe fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
312 pub unsafe fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
313 pub unsafe fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
315 /* Operations on struct types */
316 pub unsafe fn LLVMStructTypeInContext(C: ContextRef,
317 ElementTypes: *TypeRef,
318 ElementCount: c_uint,
319 Packed: Bool) -> TypeRef;
320 pub unsafe fn LLVMStructType(ElementTypes: *TypeRef,
321 ElementCount: c_uint,
324 pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
326 pub unsafe fn LLVMGetStructElementTypes(StructTy: TypeRef,
328 pub unsafe fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
330 /* Operations on array, pointer, and vector types (sequence types) */
331 pub unsafe fn LLVMArrayType(ElementType: TypeRef,
332 ElementCount: c_uint) -> TypeRef;
333 pub unsafe fn LLVMPointerType(ElementType: TypeRef,
334 AddressSpace: c_uint) -> TypeRef;
335 pub unsafe fn LLVMVectorType(ElementType: TypeRef,
336 ElementCount: c_uint) -> TypeRef;
338 pub unsafe fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
339 pub unsafe fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
340 pub unsafe fn LLVMGetPointerAddressSpace(PointerTy: TypeRef)
342 pub unsafe fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
344 /* Operations on other types */
345 pub unsafe fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
346 pub unsafe fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
347 pub unsafe fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
349 pub unsafe fn LLVMVoidType() -> TypeRef;
350 pub unsafe fn LLVMLabelType() -> TypeRef;
351 pub unsafe fn LLVMMetadataType() -> TypeRef;
353 /* Operations on all values */
354 pub unsafe fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
355 pub unsafe fn LLVMGetValueName(Val: ValueRef) -> *c_char;
356 pub unsafe fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
357 pub unsafe fn LLVMDumpValue(Val: ValueRef);
358 pub unsafe fn LLVMReplaceAllUsesWith(OldVal: ValueRef,
360 pub unsafe fn LLVMHasMetadata(Val: ValueRef) -> c_int;
361 pub unsafe fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint)
363 pub unsafe fn LLVMSetMetadata(Val: ValueRef,
367 /* Operations on Uses */
368 pub unsafe fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
369 pub unsafe fn LLVMGetNextUse(U: UseRef) -> UseRef;
370 pub unsafe fn LLVMGetUser(U: UseRef) -> ValueRef;
371 pub unsafe fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
373 /* Operations on Users */
374 pub unsafe fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
375 pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint)
377 pub unsafe fn LLVMSetOperand(Val: ValueRef,
381 /* Operations on constants of any type */
382 pub unsafe fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
384 pub unsafe fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
385 /* only for int/vector */
386 pub unsafe fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
387 pub unsafe fn LLVMIsConstant(Val: ValueRef) -> Bool;
388 pub unsafe fn LLVMIsNull(Val: ValueRef) -> Bool;
389 pub unsafe fn LLVMIsUndef(Val: ValueRef) -> Bool;
390 pub unsafe fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
392 /* Operations on metadata */
393 pub unsafe fn LLVMMDStringInContext(C: ContextRef,
397 pub unsafe fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
398 pub unsafe fn LLVMMDNodeInContext(C: ContextRef,
402 pub unsafe fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
403 pub unsafe fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
406 /* Operations on scalar constants */
407 pub unsafe fn LLVMConstInt(IntTy: TypeRef,
411 pub unsafe fn LLVMConstIntOfString(IntTy: TypeRef,
415 pub unsafe fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
420 pub unsafe fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
421 pub unsafe fn LLVMConstRealOfString(RealTy: TypeRef,
424 pub unsafe fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
428 pub unsafe fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef)
430 pub unsafe fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef)
434 /* Operations on composite constants */
435 pub unsafe fn LLVMConstStringInContext(C: ContextRef,
438 DontNullTerminate: Bool)
440 pub unsafe fn LLVMConstStructInContext(C: ContextRef,
441 ConstantVals: *ValueRef,
443 Packed: Bool) -> ValueRef;
445 pub unsafe fn LLVMConstString(Str: *c_char,
447 DontNullTerminate: Bool)
449 pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
450 ConstantVals: *ValueRef,
453 pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
455 Packed: Bool) -> ValueRef;
456 pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
457 Size: c_uint) -> ValueRef;
459 /* Constant expressions */
460 pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
461 pub unsafe fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
462 pub unsafe fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
463 pub unsafe fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
464 pub unsafe fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
465 pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
466 pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
467 pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
468 RHSConstant: ValueRef)
470 pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
471 RHSConstant: ValueRef)
473 pub unsafe fn LLVMConstNUWAdd(LHSConstant: ValueRef,
474 RHSConstant: ValueRef)
476 pub unsafe fn LLVMConstFAdd(LHSConstant: ValueRef,
477 RHSConstant: ValueRef)
479 pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
480 RHSConstant: ValueRef)
482 pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
483 RHSConstant: ValueRef)
485 pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
486 RHSConstant: ValueRef)
488 pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
489 RHSConstant: ValueRef)
491 pub unsafe fn LLVMConstMul(LHSConstant: ValueRef,
492 RHSConstant: ValueRef)
494 pub unsafe fn LLVMConstNSWMul(LHSConstant: ValueRef,
495 RHSConstant: ValueRef)
497 pub unsafe fn LLVMConstNUWMul(LHSConstant: ValueRef,
498 RHSConstant: ValueRef)
500 pub unsafe fn LLVMConstFMul(LHSConstant: ValueRef,
501 RHSConstant: ValueRef)
503 pub unsafe fn LLVMConstUDiv(LHSConstant: ValueRef,
504 RHSConstant: ValueRef)
506 pub unsafe fn LLVMConstSDiv(LHSConstant: ValueRef,
507 RHSConstant: ValueRef)
509 pub unsafe fn LLVMConstExactSDiv(LHSConstant: ValueRef,
510 RHSConstant: ValueRef)
512 pub unsafe fn LLVMConstFDiv(LHSConstant: ValueRef,
513 RHSConstant: ValueRef)
515 pub unsafe fn LLVMConstURem(LHSConstant: ValueRef,
516 RHSConstant: ValueRef)
518 pub unsafe fn LLVMConstSRem(LHSConstant: ValueRef,
519 RHSConstant: ValueRef)
521 pub unsafe fn LLVMConstFRem(LHSConstant: ValueRef,
522 RHSConstant: ValueRef)
524 pub unsafe fn LLVMConstAnd(LHSConstant: ValueRef,
525 RHSConstant: ValueRef)
527 pub unsafe fn LLVMConstOr(LHSConstant: ValueRef,
528 RHSConstant: ValueRef)
530 pub unsafe fn LLVMConstXor(LHSConstant: ValueRef,
531 RHSConstant: ValueRef)
533 pub unsafe fn LLVMConstShl(LHSConstant: ValueRef,
534 RHSConstant: ValueRef)
536 pub unsafe fn LLVMConstLShr(LHSConstant: ValueRef,
537 RHSConstant: ValueRef) -> ValueRef;
538 pub unsafe fn LLVMConstAShr(LHSConstant: ValueRef,
539 RHSConstant: ValueRef) -> ValueRef;
540 pub unsafe fn LLVMConstGEP(ConstantVal: ValueRef,
541 ConstantIndices: *ValueRef,
542 NumIndices: c_uint) -> ValueRef;
543 pub unsafe fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
544 ConstantIndices: *ValueRef,
547 pub unsafe fn LLVMConstTrunc(ConstantVal: ValueRef,
550 pub unsafe fn LLVMConstSExt(ConstantVal: ValueRef,
553 pub unsafe fn LLVMConstZExt(ConstantVal: ValueRef,
556 pub unsafe fn LLVMConstFPTrunc(ConstantVal: ValueRef,
559 pub unsafe fn LLVMConstFPExt(ConstantVal: ValueRef,
562 pub unsafe fn LLVMConstUIToFP(ConstantVal: ValueRef,
565 pub unsafe fn LLVMConstSIToFP(ConstantVal: ValueRef,
568 pub unsafe fn LLVMConstFPToUI(ConstantVal: ValueRef,
571 pub unsafe fn LLVMConstFPToSI(ConstantVal: ValueRef,
574 pub unsafe fn LLVMConstPtrToInt(ConstantVal: ValueRef,
577 pub unsafe fn LLVMConstIntToPtr(ConstantVal: ValueRef,
580 pub unsafe fn LLVMConstBitCast(ConstantVal: ValueRef,
583 pub unsafe fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef,
586 pub unsafe fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef,
589 pub unsafe fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef,
592 pub unsafe fn LLVMConstPointerCast(ConstantVal: ValueRef,
595 pub unsafe fn LLVMConstIntCast(ConstantVal: ValueRef,
599 pub unsafe fn LLVMConstFPCast(ConstantVal: ValueRef,
602 pub unsafe fn LLVMConstSelect(ConstantCondition: ValueRef,
603 ConstantIfTrue: ValueRef,
604 ConstantIfFalse: ValueRef)
606 pub unsafe fn LLVMConstExtractElement(VectorConstant: ValueRef,
607 IndexConstant: ValueRef) -> ValueRef;
608 pub unsafe fn LLVMConstInsertElement(VectorConstant: ValueRef,
609 ElementValueConstant: ValueRef,
610 IndexConstant: ValueRef) -> ValueRef;
611 pub unsafe fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
612 VectorBConstant: ValueRef,
613 MaskConstant: ValueRef) -> ValueRef;
614 pub unsafe fn LLVMConstExtractValue(AggConstant: ValueRef,
616 NumIdx: c_uint) -> ValueRef;
617 pub unsafe fn LLVMConstInsertValue(AggConstant: ValueRef,
618 ElementValueConstant: ValueRef,
622 pub unsafe fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
623 Constraints: *c_char, HasSideEffects: Bool,
624 IsAlignStack: Bool) -> ValueRef;
625 pub unsafe fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef)
630 /* Operations on global variables, functions, and aliases (globals) */
631 pub unsafe fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
632 pub unsafe fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
633 pub unsafe fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
634 pub unsafe fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
635 pub unsafe fn LLVMGetSection(Global: ValueRef) -> *c_char;
636 pub unsafe fn LLVMSetSection(Global: ValueRef, Section: *c_char);
637 pub unsafe fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
638 pub unsafe fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
639 pub unsafe fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
640 pub unsafe fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
643 /* Operations on global variables */
644 pub unsafe fn LLVMAddGlobal(M: ModuleRef,
648 pub unsafe fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
651 AddressSpace: c_uint)
653 pub unsafe fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char)
655 pub unsafe fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
656 pub unsafe fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
657 pub unsafe fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
658 pub unsafe fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
659 pub unsafe fn LLVMDeleteGlobal(GlobalVar: ValueRef);
660 pub unsafe fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
661 pub unsafe fn LLVMSetInitializer(GlobalVar: ValueRef,
662 ConstantVal: ValueRef);
663 pub unsafe fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
664 pub unsafe fn LLVMSetThreadLocal(GlobalVar: ValueRef,
665 IsThreadLocal: Bool);
666 pub unsafe fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
667 pub unsafe fn LLVMSetGlobalConstant(GlobalVar: ValueRef,
670 /* Operations on aliases */
671 pub unsafe fn LLVMAddAlias(M: ModuleRef,
677 /* Operations on functions */
678 pub unsafe fn LLVMAddFunction(M: ModuleRef,
682 pub unsafe fn LLVMGetNamedFunction(M: ModuleRef,
683 Name: *c_char) -> ValueRef;
684 pub unsafe fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
685 pub unsafe fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
686 pub unsafe fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
687 pub unsafe fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
688 pub unsafe fn LLVMDeleteFunction(Fn: ValueRef);
689 pub unsafe fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
690 FunctionTy: TypeRef) -> ValueRef;
691 pub unsafe fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
692 pub unsafe fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
693 pub unsafe fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
694 pub unsafe fn LLVMGetGC(Fn: ValueRef) -> *c_char;
695 pub unsafe fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
696 pub unsafe fn LLVMAddFunctionAttr(Fn: ValueRef,
698 HighPA: c_ulonglong);
699 pub unsafe fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
700 pub unsafe fn LLVMRemoveFunctionAttr(Fn: ValueRef,
702 HighPA: c_ulonglong);
704 /* Operations on parameters */
705 pub unsafe fn LLVMCountParams(Fn: ValueRef) -> c_uint;
706 pub unsafe fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
707 pub unsafe fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
708 pub unsafe fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
709 pub unsafe fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
710 pub unsafe fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
711 pub unsafe fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
712 pub unsafe fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
713 pub unsafe fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
714 pub unsafe fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
715 pub unsafe fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
716 pub unsafe fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
718 /* Operations on basic blocks */
719 pub unsafe fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
720 pub unsafe fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
721 pub unsafe fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
722 pub unsafe fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
723 pub unsafe fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
724 pub unsafe fn LLVMGetBasicBlocks(Fn: ValueRef,
725 BasicBlocks: *ValueRef);
726 pub unsafe fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
727 pub unsafe fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
728 pub unsafe fn LLVMGetNextBasicBlock(BB: BasicBlockRef)
730 pub unsafe fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef)
732 pub unsafe fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
734 pub unsafe fn LLVMAppendBasicBlockInContext(C: ContextRef,
738 pub unsafe fn LLVMInsertBasicBlockInContext(C: ContextRef,
743 pub unsafe fn LLVMAppendBasicBlock(Fn: ValueRef,
746 pub unsafe fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef,
749 pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
751 /* Operations on instructions */
752 pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef)
754 pub unsafe fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
755 pub unsafe fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
756 pub unsafe fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
757 pub unsafe fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
759 /* Operations on call sites */
760 pub unsafe fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
761 pub unsafe fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
762 pub unsafe fn LLVMAddInstrAttribute(Instr: ValueRef,
765 pub unsafe fn LLVMRemoveInstrAttribute(Instr: ValueRef,
768 pub unsafe fn LLVMSetInstrParamAlignment(Instr: ValueRef,
772 /* Operations on call instructions (only) */
773 pub unsafe fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
774 pub unsafe fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
776 /* Operations on phi nodes */
777 pub unsafe fn LLVMAddIncoming(PhiNode: ValueRef,
778 IncomingValues: *ValueRef,
779 IncomingBlocks: *BasicBlockRef,
781 pub unsafe fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
782 pub unsafe fn LLVMGetIncomingValue(PhiNode: ValueRef,
785 pub unsafe fn LLVMGetIncomingBlock(PhiNode: ValueRef,
786 Index: c_uint) -> BasicBlockRef;
788 /* Instruction builders */
789 pub unsafe fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
790 pub unsafe fn LLVMCreateBuilder() -> BuilderRef;
791 pub unsafe fn LLVMPositionBuilder(Builder: BuilderRef,
792 Block: BasicBlockRef,
794 pub unsafe fn LLVMPositionBuilderBefore(Builder: BuilderRef,
796 pub unsafe fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
797 Block: BasicBlockRef);
798 pub unsafe fn LLVMGetInsertBlock(Builder: BuilderRef)
800 pub unsafe fn LLVMClearInsertionPosition(Builder: BuilderRef);
801 pub unsafe fn LLVMInsertIntoBuilder(Builder: BuilderRef,
803 pub unsafe fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
806 pub unsafe fn LLVMDisposeBuilder(Builder: BuilderRef);
809 pub unsafe fn LLVMSetCurrentDebugLocation(Builder: BuilderRef,
811 pub unsafe fn LLVMGetCurrentDebugLocation(Builder: BuilderRef)
813 pub unsafe fn LLVMSetInstDebugLocation(Builder: BuilderRef,
817 pub unsafe fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
818 pub unsafe fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
819 pub unsafe fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
820 N: c_uint) -> ValueRef;
821 pub unsafe fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef)
823 pub unsafe fn LLVMBuildCondBr(B: BuilderRef,
828 pub unsafe fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef,
829 Else: BasicBlockRef, NumCases: c_uint)
831 pub unsafe fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef,
832 NumDests: c_uint) -> ValueRef;
833 pub unsafe fn LLVMBuildInvoke(B: BuilderRef,
838 Catch: BasicBlockRef,
839 Name: *c_char) -> ValueRef;
840 pub unsafe fn LLVMBuildLandingPad(B: BuilderRef,
846 pub unsafe fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef)
848 pub unsafe fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
850 /* Add a case to the switch instruction */
851 pub unsafe fn LLVMAddCase(Switch: ValueRef,
853 Dest: BasicBlockRef);
855 /* Add a destination to the indirectbr instruction */
856 pub unsafe fn LLVMAddDestination(IndirectBr: ValueRef,
857 Dest: BasicBlockRef);
859 /* Add a clause to the landing pad instruction */
860 pub unsafe fn LLVMAddClause(LandingPad: ValueRef,
861 ClauseVal: ValueRef);
863 /* Set the cleanup on a landing pad instruction */
864 pub unsafe fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
867 pub unsafe fn LLVMBuildAdd(B: BuilderRef,
872 pub unsafe fn LLVMBuildNSWAdd(B: BuilderRef,
877 pub unsafe fn LLVMBuildNUWAdd(B: BuilderRef,
882 pub unsafe fn LLVMBuildFAdd(B: BuilderRef,
887 pub unsafe fn LLVMBuildSub(B: BuilderRef,
892 pub unsafe fn LLVMBuildNSWSub(B: BuilderRef,
897 pub unsafe fn LLVMBuildNUWSub(B: BuilderRef,
902 pub unsafe fn LLVMBuildFSub(B: BuilderRef,
907 pub unsafe fn LLVMBuildMul(B: BuilderRef,
912 pub unsafe fn LLVMBuildNSWMul(B: BuilderRef,
917 pub unsafe fn LLVMBuildNUWMul(B: BuilderRef,
922 pub unsafe fn LLVMBuildFMul(B: BuilderRef,
927 pub unsafe fn LLVMBuildUDiv(B: BuilderRef,
932 pub unsafe fn LLVMBuildSDiv(B: BuilderRef,
937 pub unsafe fn LLVMBuildExactSDiv(B: BuilderRef,
942 pub unsafe fn LLVMBuildFDiv(B: BuilderRef,
947 pub unsafe fn LLVMBuildURem(B: BuilderRef,
952 pub unsafe fn LLVMBuildSRem(B: BuilderRef,
957 pub unsafe fn LLVMBuildFRem(B: BuilderRef,
962 pub unsafe fn LLVMBuildShl(B: BuilderRef,
967 pub unsafe fn LLVMBuildLShr(B: BuilderRef,
972 pub unsafe fn LLVMBuildAShr(B: BuilderRef,
977 pub unsafe fn LLVMBuildAnd(B: BuilderRef,
982 pub unsafe fn LLVMBuildOr(B: BuilderRef,
987 pub unsafe fn LLVMBuildXor(B: BuilderRef,
992 pub unsafe fn LLVMBuildBinOp(B: BuilderRef,
998 pub unsafe fn LLVMBuildNeg(B: BuilderRef,
1002 pub unsafe fn LLVMBuildNSWNeg(B: BuilderRef,
1006 pub unsafe fn LLVMBuildNUWNeg(B: BuilderRef,
1010 pub unsafe fn LLVMBuildFNeg(B: BuilderRef,
1014 pub unsafe fn LLVMBuildNot(B: BuilderRef,
1020 pub unsafe fn LLVMBuildMalloc(B: BuilderRef,
1024 pub unsafe fn LLVMBuildArrayMalloc(B: BuilderRef,
1027 Name: *c_char) -> ValueRef;
1028 pub unsafe fn LLVMBuildAlloca(B: BuilderRef,
1032 pub unsafe fn LLVMBuildArrayAlloca(B: BuilderRef,
1035 Name: *c_char) -> ValueRef;
1036 pub unsafe fn LLVMBuildFree(B: BuilderRef,
1037 PointerVal: ValueRef) -> ValueRef;
1038 pub unsafe fn LLVMBuildLoad(B: BuilderRef,
1039 PointerVal: ValueRef,
1042 pub unsafe fn LLVMBuildStore(B: BuilderRef,
1044 Ptr: ValueRef) -> ValueRef;
1045 pub unsafe fn LLVMBuildGEP(B: BuilderRef,
1051 pub unsafe fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
1052 Indices: *ValueRef, NumIndices: c_uint,
1055 pub unsafe fn LLVMBuildStructGEP(B: BuilderRef,
1060 pub unsafe fn LLVMBuildGlobalString(B: BuilderRef,
1064 pub unsafe fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1070 pub unsafe fn LLVMBuildTrunc(B: BuilderRef,
1073 Name: *c_char) -> ValueRef;
1074 pub unsafe fn LLVMBuildZExt(B: BuilderRef,
1079 pub unsafe fn LLVMBuildSExt(B: BuilderRef,
1084 pub unsafe fn LLVMBuildFPToUI(B: BuilderRef,
1087 Name: *c_char) -> ValueRef;
1088 pub unsafe fn LLVMBuildFPToSI(B: BuilderRef,
1091 Name: *c_char) -> ValueRef;
1092 pub unsafe fn LLVMBuildUIToFP(B: BuilderRef,
1095 Name: *c_char) -> ValueRef;
1096 pub unsafe fn LLVMBuildSIToFP(B: BuilderRef,
1099 Name: *c_char) -> ValueRef;
1100 pub unsafe fn LLVMBuildFPTrunc(B: BuilderRef,
1103 Name: *c_char) -> ValueRef;
1104 pub unsafe fn LLVMBuildFPExt(B: BuilderRef,
1107 Name: *c_char) -> ValueRef;
1108 pub unsafe fn LLVMBuildPtrToInt(B: BuilderRef,
1111 Name: *c_char) -> ValueRef;
1112 pub unsafe fn LLVMBuildIntToPtr(B: BuilderRef,
1115 Name: *c_char) -> ValueRef;
1116 pub unsafe fn LLVMBuildBitCast(B: BuilderRef,
1119 Name: *c_char) -> ValueRef;
1120 pub unsafe fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1125 pub unsafe fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1130 pub unsafe fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1135 pub unsafe fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
1136 DestTy: TypeRef, Name: *c_char) -> ValueRef;
1137 pub unsafe fn LLVMBuildPointerCast(B: BuilderRef,
1142 pub unsafe fn LLVMBuildIntCast(B: BuilderRef,
1145 Name: *c_char) -> ValueRef;
1146 pub unsafe fn LLVMBuildFPCast(B: BuilderRef,
1149 Name: *c_char) -> ValueRef;
1152 pub unsafe fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1153 RHS: ValueRef, Name: *c_char) -> ValueRef;
1154 pub unsafe fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1155 RHS: ValueRef, Name: *c_char) -> ValueRef;
1157 /* Miscellaneous instructions */
1158 pub unsafe fn LLVMBuildPhi(B: BuilderRef,
1162 pub unsafe fn LLVMBuildCall(B: BuilderRef,
1168 pub unsafe fn LLVMBuildSelect(B: BuilderRef,
1174 pub unsafe fn LLVMBuildVAArg(B: BuilderRef,
1179 pub unsafe fn LLVMBuildExtractElement(B: BuilderRef,
1184 pub unsafe fn LLVMBuildInsertElement(B: BuilderRef,
1190 pub unsafe fn LLVMBuildShuffleVector(B: BuilderRef,
1196 pub unsafe fn LLVMBuildExtractValue(B: BuilderRef,
1201 pub unsafe fn LLVMBuildInsertValue(B: BuilderRef,
1208 pub unsafe fn LLVMBuildIsNull(B: BuilderRef,
1212 pub unsafe fn LLVMBuildIsNotNull(B: BuilderRef,
1216 pub unsafe fn LLVMBuildPtrDiff(B: BuilderRef,
1219 Name: *c_char) -> ValueRef;
1221 /* Atomic Operations */
1222 pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef, LHS: ValueRef,
1223 CMP: ValueRef, RHS: ValueRef,
1224 ++Order: AtomicOrdering) -> ValueRef;
1225 pub unsafe fn LLVMBuildAtomicRMW(B: BuilderRef, ++Op: AtomicBinOp,
1226 LHS: ValueRef, RHS: ValueRef,
1227 ++Order: AtomicOrdering) -> ValueRef;
1229 /* Selected entries from the downcasts. */
1230 pub unsafe fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1232 /** Writes a module to the specified path. Returns 0 on success. */
1233 pub unsafe fn LLVMWriteBitcodeToFile(M: ModuleRef,
1234 Path: *c_char) -> c_int;
1236 /** Creates target data from a target layout string. */
1237 pub unsafe fn LLVMCreateTargetData(StringRep: *c_char)
1239 /** Adds the target data to the given pass manager. The pass manager
1240 references the target data only weakly. */
1241 pub unsafe fn LLVMAddTargetData(TD: TargetDataRef,
1242 PM: PassManagerRef);
1243 /** Number of bytes clobbered when doing a Store to *T. */
1244 pub unsafe fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1247 /** Number of bytes clobbered when doing a Store to *T. */
1248 pub unsafe fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1251 /** Distance between successive elements in an array of T.
1252 Includes ABI padding. */
1253 pub unsafe fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef)
1256 /** Returns the preferred alignment of a type. */
1257 pub unsafe fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
1258 Ty: TypeRef) -> c_uint;
1259 /** Returns the minimum alignment of a type. */
1260 pub unsafe fn LLVMABIAlignmentOfType(TD: TargetDataRef,
1261 Ty: TypeRef) -> c_uint;
1263 * Returns the minimum alignment of a type when part of a call frame.
1265 pub unsafe fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
1269 /** Disposes target data. */
1270 pub unsafe fn LLVMDisposeTargetData(TD: TargetDataRef);
1272 /** Creates a pass manager. */
1273 pub unsafe fn LLVMCreatePassManager() -> PassManagerRef;
1274 /** Disposes a pass manager. */
1275 pub unsafe fn LLVMDisposePassManager(PM: PassManagerRef);
1276 /** Runs a pass manager on a module. */
1277 pub unsafe fn LLVMRunPassManager(PM: PassManagerRef,
1278 M: ModuleRef) -> Bool;
1280 /** Adds a verification pass. */
1281 pub unsafe fn LLVMAddVerifierPass(PM: PassManagerRef);
1283 pub unsafe fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1284 pub unsafe fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1285 pub unsafe fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1286 pub unsafe fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1287 pub unsafe fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1288 pub unsafe fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1289 pub unsafe fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1290 pub unsafe fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1291 pub unsafe fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1292 pub unsafe fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1293 pub unsafe fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1294 pub unsafe fn LLVMAddReassociatePass(PM: PassManagerRef);
1295 pub unsafe fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1296 pub unsafe fn LLVMAddLICMPass(PM: PassManagerRef);
1297 pub unsafe fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1298 pub unsafe fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1299 pub unsafe fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1300 pub unsafe fn LLVMAddGVNPass(PM: PassManagerRef);
1301 pub unsafe fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1302 pub unsafe fn LLVMAddSCCPPass(PM: PassManagerRef);
1303 pub unsafe fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1304 pub unsafe fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1305 pub unsafe fn LLVMAddConstantMergePass(PM: PassManagerRef);
1306 pub unsafe fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1307 pub unsafe fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1308 pub unsafe fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1309 pub unsafe fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1310 pub unsafe fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1311 pub unsafe fn LLVMAddCorrelatedValuePropagationPass(PM:
1313 pub unsafe fn LLVMAddPruneEHPass(PM: PassManagerRef);
1314 pub unsafe fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1315 pub unsafe fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1316 pub unsafe fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1317 pub unsafe fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1318 pub unsafe fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1320 pub unsafe fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1321 pub unsafe fn LLVMPassManagerBuilderDispose(PMB:
1322 PassManagerBuilderRef);
1323 pub unsafe fn LLVMPassManagerBuilderSetOptLevel(
1324 PMB: PassManagerBuilderRef, OptimizationLevel: c_uint);
1325 pub unsafe fn LLVMPassManagerBuilderSetSizeLevel(
1326 PMB: PassManagerBuilderRef, Value: Bool);
1327 pub unsafe fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1328 PMB: PassManagerBuilderRef, Value: Bool);
1329 pub unsafe fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1330 PMB: PassManagerBuilderRef, Value: Bool);
1331 pub unsafe fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
1332 (PMB: PassManagerBuilderRef, Value: Bool);
1333 pub unsafe fn LLVMPassManagerBuilderUseInlinerWithThreshold
1334 (PMB: PassManagerBuilderRef, threshold: c_uint);
1335 pub unsafe fn LLVMPassManagerBuilderPopulateModulePassManager
1336 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1338 pub unsafe fn LLVMPassManagerBuilderPopulateFunctionPassManager
1339 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1341 /** Destroys a memory buffer. */
1342 pub unsafe fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1345 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1347 /** Opens an object file. */
1348 pub unsafe fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef)
1350 /** Closes an object file. */
1351 pub unsafe fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1353 /** Enumerates the sections in an object file. */
1354 pub unsafe fn LLVMGetSections(ObjFile: ObjectFileRef)
1355 -> SectionIteratorRef;
1356 /** Destroys a section iterator. */
1357 pub unsafe fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1358 /** Returns true if the section iterator is at the end of the section
1360 pub unsafe fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1361 SI: SectionIteratorRef) -> Bool;
1362 /** Moves the section iterator to point to the next section. */
1363 pub unsafe fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1364 /** Returns the current section name. */
1365 pub unsafe fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1366 /** Returns the current section size. */
1367 pub unsafe fn LLVMGetSectionSize(SI: SectionIteratorRef)
1369 /** Returns the current section contents as a string buffer. */
1370 pub unsafe fn LLVMGetSectionContents(SI: SectionIteratorRef)
1373 /** Reads the given file and returns it as a memory buffer. Use
1374 LLVMDisposeMemoryBuffer() to get rid of it. */
1375 pub unsafe fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1379 pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
1382 // FIXME: When #2334 is fixed,
1383 // change c_uint to FileType
1387 EnableSegmentedStacks: bool)
1390 /** Returns a string describing the last error caused by an LLVMRust*
1392 pub unsafe fn LLVMRustGetLastError() -> *c_char;
1394 /** Prepare the JIT. Returns a memory manager that can load crates. */
1395 pub unsafe fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1397 /** Load a crate into the memory manager. */
1398 pub unsafe fn LLVMRustLoadCrate(MM: *(),
1402 /** Execute the JIT engine. */
1403 pub unsafe fn LLVMRustExecuteJIT(MM: *(),
1407 EnableSegmentedStacks: bool) -> *();
1409 /** Parses the bitcode in the given memory buffer. */
1410 pub unsafe fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef)
1413 /** Parses LLVM asm in the given file */
1414 pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char)
1417 pub unsafe fn LLVMRustAddPrintModulePass(PM: PassManagerRef,
1421 /** Turn on LLVM pass-timing. */
1422 pub unsafe fn LLVMRustEnableTimePasses();
1424 /// Print the pass timings since static dtors aren't picking them up.
1425 pub unsafe fn LLVMRustPrintPassTimings();
1427 pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
1430 pub unsafe fn LLVMStructSetBody(StructTy: TypeRef,
1431 ElementTypes: *TypeRef,
1432 ElementCount: c_uint,
1435 pub unsafe fn LLVMConstNamedStruct(S: TypeRef,
1436 ConstantVals: *ValueRef,
1440 /** Enables LLVM debug output. */
1441 pub unsafe fn LLVMSetDebug(Enabled: c_int);
1443 /** Prepares inline assembly. */
1444 pub unsafe fn LLVMInlineAsm(Ty: TypeRef, AsmString: *c_char,
1445 Constraints: *c_char, SideEffects: Bool,
1446 AlignStack: Bool, Dialect: AsmDialect)
1451 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
1453 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
1456 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
1458 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
1461 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
1463 llvm::LLVMSetLinkage(Global, Link as c_uint);
1467 /* Memory-managed object interface to type handles. */
1469 pub struct TypeNames {
1470 type_names: HashMap<TypeRef, @str>,
1471 named_types: HashMap<@str, TypeRef>
1474 pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
1475 fail_unless!(tn.type_names.insert(t, s));
1476 fail_unless!(tn.named_types.insert(s, t));
1479 pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {
1480 return tn.type_names.find(&t);
1483 pub fn name_has_type(tn: @TypeNames, s: @str) -> Option<TypeRef> {
1484 return tn.named_types.find(&s);
1487 pub fn mk_type_names() -> @TypeNames {
1489 type_names: HashMap(),
1490 named_types: HashMap()
1494 pub fn type_to_str(names: @TypeNames, ty: TypeRef) -> @str {
1495 return type_to_str_inner(names, [], ty);
1498 pub fn type_to_str_inner(names: @TypeNames, +outer0: &[TypeRef], ty: TypeRef)
1501 match type_has_name(names, ty) {
1502 option::Some(n) => return n,
1506 let outer = vec::append_one(outer0.to_vec(), ty);
1508 let kind = llvm::LLVMGetTypeKind(ty);
1510 fn tys_str(names: @TypeNames, outer: &[TypeRef],
1511 tys: ~[TypeRef]) -> @str {
1513 let mut first: bool = true;
1515 if first { first = false; } else { s += ~", "; }
1516 s += type_to_str_inner(names, outer, *t).to_owned();
1518 // [Note at-str] FIXME #2543: Could rewrite this without the copy,
1519 // but need better @str support.
1520 return s.to_managed();
1524 Void => return @"Void",
1525 Half => return @"Half",
1526 Float => return @"Float",
1527 Double => return @"Double",
1528 X86_FP80 => return @"X86_FP80",
1529 FP128 => return @"FP128",
1530 PPC_FP128 => return @"PPC_FP128",
1531 Label => return @"Label",
1533 // See [Note at-str]
1534 return fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty)
1535 as int).to_managed();
1538 let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
1539 let n_args = llvm::LLVMCountParamTypes(ty) as uint;
1540 let args = vec::from_elem(n_args, 0 as TypeRef);
1542 llvm::LLVMGetParamTypes(ty, vec::raw::to_ptr(args));
1544 // See [Note at-str]
1545 return fmt!("fn(%s) -> %s",
1546 tys_str(names, outer, args),
1547 type_to_str_inner(names, outer, out_ty)).to_managed();
1550 let elts = struct_tys(ty);
1551 // See [Note at-str]
1552 return fmt!("{%s}", tys_str(names, outer, elts)).to_managed();
1555 let el_ty = llvm::LLVMGetElementType(ty);
1556 // See [Note at-str]
1557 return fmt!("[%s@ x %u", type_to_str_inner(names, outer, el_ty),
1558 llvm::LLVMGetArrayLength(ty) as uint).to_managed();
1562 for outer0.each |tout| {
1564 if *tout as int == ty as int {
1565 let n = outer0.len() - i;
1566 // See [Note at-str]
1567 return fmt!("*\\%d", n as int).to_managed();
1571 let addrspace = llvm::LLVMGetPointerAddressSpace(ty) as uint;
1575 fmt!("addrspace(%u)", addrspace)
1578 // See [Note at-str]
1579 return fmt!("%s*%s", addrstr, type_to_str_inner(names,
1581 llvm::LLVMGetElementType(ty))).to_managed();
1583 Vector => return @"Vector",
1584 Metadata => return @"Metadata",
1585 X86_MMX => return @"X86_MMAX"
1590 pub fn float_width(llt: TypeRef) -> uint {
1592 return match llvm::LLVMGetTypeKind(llt) as int {
1597 _ => fail!(~"llvm_float_width called on a non-float type")
1602 pub fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] {
1604 let args = vec::from_elem(llvm::LLVMCountParamTypes(fn_ty) as uint,
1606 llvm::LLVMGetParamTypes(fn_ty, vec::raw::to_ptr(args));
1611 pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] {
1613 let n_elts = llvm::LLVMCountStructElementTypes(struct_ty) as uint;
1617 let mut elts = vec::from_elem(n_elts, ptr::null());
1618 llvm::LLVMGetStructElementTypes(
1619 struct_ty, ptr::to_mut_unsafe_ptr(&mut elts[0]));
1625 /* Memory-managed interface to target data. */
1627 pub struct target_data_res {
1631 impl Drop for target_data_res {
1632 fn finalize(&self) {
1634 llvm::LLVMDisposeTargetData(self.TD);
1639 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
1645 pub struct TargetData {
1646 lltd: TargetDataRef,
1647 dtor: @target_data_res
1650 pub fn mk_target_data(string_rep: ~str) -> TargetData {
1652 str::as_c_str(string_rep, |buf| unsafe {
1653 llvm::LLVMCreateTargetData(buf)
1658 dtor: @target_data_res(lltd)
1662 /* Memory-managed interface to pass managers. */
1664 pub struct pass_manager_res {
1668 impl Drop for pass_manager_res {
1669 fn finalize(&self) {
1671 llvm::LLVMDisposePassManager(self.PM);
1676 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
1682 pub struct PassManager {
1683 llpm: PassManagerRef,
1684 dtor: @pass_manager_res
1687 pub fn mk_pass_manager() -> PassManager {
1689 let llpm = llvm::LLVMCreatePassManager();
1693 dtor: @pass_manager_res(llpm)
1698 /* Memory-managed interface to object files. */
1700 pub struct object_file_res {
1701 ObjectFile: ObjectFileRef,
1704 impl Drop for object_file_res {
1705 fn finalize(&self) {
1707 llvm::LLVMDisposeObjectFile(self.ObjectFile);
1712 pub fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
1718 pub struct ObjectFile {
1719 llof: ObjectFileRef,
1720 dtor: @object_file_res
1723 pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1725 let llof = llvm::LLVMCreateObjectFile(llmb);
1726 if llof as int == 0 { return option::None::<ObjectFile>; }
1728 option::Some(ObjectFile {
1730 dtor: @object_file_res(llof)
1735 /* Memory-managed interface to section iterators. */
1737 pub struct section_iter_res {
1738 SI: SectionIteratorRef,
1741 impl Drop for section_iter_res {
1742 fn finalize(&self) {
1744 llvm::LLVMDisposeSectionIterator(self.SI);
1749 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
1755 pub struct SectionIter {
1756 llsi: SectionIteratorRef,
1757 dtor: @section_iter_res
1760 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
1762 let llsi = llvm::LLVMGetSections(llof);
1765 dtor: @section_iter_res(llsi)
1774 // indent-tabs-mode: nil
1775 // c-basic-offset: 4
1776 // buffer-file-coding-system: utf-8-unix