rust/src/librustc/lib/llvm.rs

1308 lines
52 KiB
Rust
Raw Normal View History

// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use core::prelude::*;
use core::cast;
use core::cmp;
use core::int;
use core::io;
use core::libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
use core::option;
use core::ptr;
use core::str;
use core::uint;
use core::vec;
2012-09-10 15:38:28 -07:00
use std::map::HashMap;
type Opcode = u32;
type Bool = c_uint;
const True: Bool = 1 as Bool;
const False: Bool = 0 as Bool;
2010-07-12 17:47:40 -07:00
// Consts for the LLVM CallConv type, pre-cast to uint.
enum CallConv {
CCallConv = 0,
FastCallConv = 8,
ColdCallConv = 9,
X86StdcallCallConv = 64,
X86FastcallCallConv = 65,
}
enum Visibility {
LLVMDefaultVisibility = 0,
HiddenVisibility = 1,
ProtectedVisibility = 2,
}
enum Linkage {
ExternalLinkage = 0,
AvailableExternallyLinkage = 1,
LinkOnceAnyLinkage = 2,
LinkOnceODRLinkage = 3,
LinkOnceODRAutoHideLinkage = 4,
WeakAnyLinkage = 5,
WeakODRLinkage = 6,
AppendingLinkage = 7,
InternalLinkage = 8,
PrivateLinkage = 9,
DLLImportLinkage = 10,
DLLExportLinkage = 11,
ExternalWeakLinkage = 12,
GhostLinkage = 13,
CommonLinkage = 14,
LinkerPrivateLinkage = 15,
LinkerPrivateWeakLinkage = 16,
}
2011-07-27 14:19:39 +02:00
enum Attribute {
ZExtAttribute = 1,
SExtAttribute = 2,
NoReturnAttribute = 4,
InRegAttribute = 8,
StructRetAttribute = 16,
NoUnwindAttribute = 32,
NoAliasAttribute = 64,
ByValAttribute = 128,
NestAttribute = 256,
ReadNoneAttribute = 512,
ReadOnlyAttribute = 1024,
NoInlineAttribute = 2048,
AlwaysInlineAttribute = 4096,
OptimizeForSizeAttribute = 8192,
StackProtectAttribute = 16384,
StackProtectReqAttribute = 32768,
// 31 << 16
AlignmentAttribute = 2031616,
NoCaptureAttribute = 2097152,
NoRedZoneAttribute = 4194304,
NoImplicitFloatAttribute = 8388608,
NakedAttribute = 16777216,
InlineHintAttribute = 33554432,
// 7 << 26
StackAttribute = 469762048,
ReturnsTwiceAttribute = 536870912,
// 1 << 30
UWTableAttribute = 1073741824,
NonLazyBindAttribute = 2147483648,
}
2011-07-27 14:19:39 +02:00
// enum for the LLVM IntPredicate type
enum IntPredicate {
IntEQ = 32,
IntNE = 33,
IntUGT = 34,
IntUGE = 35,
IntULT = 36,
IntULE = 37,
IntSGT = 38,
IntSGE = 39,
IntSLT = 40,
IntSLE = 41,
}
// enum for the LLVM RealPredicate type
enum RealPredicate {
RealPredicateFalse = 0,
RealOEQ = 1,
RealOGT = 2,
RealOGE = 3,
RealOLT = 4,
RealOLE = 5,
RealONE = 6,
RealORD = 7,
RealUNO = 8,
RealUEQ = 9,
RealUGT = 10,
RealUGE = 11,
RealULT = 12,
RealULE = 13,
RealUNE = 14,
RealPredicateTrue = 15,
}
// enum for the LLVM TypeKind type - must stay in sync with the def of
// LLVMTypeKind in llvm/include/llvm-c/Core.h
enum TypeKind {
Void = 0,
Half = 1,
Float = 2,
Double = 3,
X86_FP80 = 4,
FP128 = 5,
PPC_FP128 = 6,
Label = 7,
Integer = 8,
Function = 9,
Struct = 10,
Array = 11,
Pointer = 12,
Vector = 13,
Metadata = 14,
X86_MMX = 15
}
impl TypeKind : cmp::Eq {
pure fn eq(&self, other: &TypeKind) -> bool {
match ((*self), (*other)) {
(Void, Void) => true,
(Half, Half) => true,
(Float, Float) => true,
(Double, Double) => true,
(X86_FP80, X86_FP80) => true,
(FP128, FP128) => true,
(PPC_FP128, PPC_FP128) => true,
(Label, Label) => true,
(Integer, Integer) => true,
(Function, Function) => true,
(Struct, Struct) => true,
(Array, Array) => true,
(Pointer, Pointer) => true,
(Vector, Vector) => true,
(Metadata, Metadata) => true,
(X86_MMX, X86_MMX) => true,
(Void, _) => false,
(Half, _) => false,
(Float, _) => false,
(Double, _) => false,
(X86_FP80, _) => false,
(FP128, _) => false,
(PPC_FP128, _) => false,
(Label, _) => false,
(Integer, _) => false,
(Function, _) => false,
(Struct, _) => false,
(Array, _) => false,
(Pointer, _) => false,
(Vector, _) => false,
(Metadata, _) => false,
(X86_MMX, _) => false,
}
}
pure fn ne(&self, other: &TypeKind) -> bool { !(*self).eq(other) }
}
2012-08-27 16:26:35 -07:00
enum AtomicBinOp {
Xchg = 0,
Add = 1,
Sub = 2,
And = 3,
Nand = 4,
Or = 5,
Xor = 6,
Max = 7,
Min = 8,
UMax = 9,
UMin = 10,
}
enum AtomicOrdering {
NotAtomic = 0,
Unordered = 1,
Monotonic = 2,
// Consume = 3, // Not specified yet.
Acquire = 4,
Release = 5,
AcquireRelease = 6,
SequentiallyConsistent = 7
}
// FIXME: Not used right now, but will be once #2334 is fixed
// Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
enum FileType {
AssemblyFile = 0,
ObjectFile = 1
}
// Opaque pointer types
enum Module_opaque {}
type ModuleRef = *Module_opaque;
enum Context_opaque {}
type ContextRef = *Context_opaque;
enum Type_opaque {}
type TypeRef = *Type_opaque;
enum Value_opaque {}
type ValueRef = *Value_opaque;
enum BasicBlock_opaque {}
type BasicBlockRef = *BasicBlock_opaque;
enum Builder_opaque {}
type BuilderRef = *Builder_opaque;
enum MemoryBuffer_opaque {}
type MemoryBufferRef = *MemoryBuffer_opaque;
enum PassManager_opaque {}
type PassManagerRef = *PassManager_opaque;
enum PassManagerBuilder_opaque {}
type PassManagerBuilderRef = *PassManagerBuilder_opaque;
enum Use_opaque {}
type UseRef = *Use_opaque;
enum TargetData_opaque {}
type TargetDataRef = *TargetData_opaque;
enum ObjectFile_opaque {}
type ObjectFileRef = *ObjectFile_opaque;
enum SectionIterator_opaque {}
type SectionIteratorRef = *SectionIterator_opaque;
#[link_args = "-Lrustllvm"]
#[link_name = "rustllvm"]
#[abi = "cdecl"]
extern mod llvm {
#[legacy_exports];
/* Create and destroy contexts. */
fn LLVMContextCreate() -> ContextRef;
fn LLVMGetGlobalContext() -> ContextRef;
2011-07-27 14:19:39 +02:00
fn LLVMContextDispose(C: ContextRef);
fn LLVMGetMDKindIDInContext(C: ContextRef, Name: *c_char, SLen: c_uint) ->
c_uint;
fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
/* Create and destroy modules. */
fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char, C: ContextRef) ->
2011-07-27 14:19:39 +02:00
ModuleRef;
fn LLVMDisposeModule(M: ModuleRef);
/** Data layout. See Module::getDataLayout. */
fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
/** Target triple. See Module::getTargetTriple. */
fn LLVMGetTarget(M: ModuleRef) -> *c_char;
fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
/** See Module::dump. */
2011-07-27 14:19:39 +02:00
fn LLVMDumpModule(M: ModuleRef);
/** See Module::setModuleInlineAsm. */
fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
/** See llvm::LLVMTypeKind::getTypeID. */
fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
/** See llvm::LLVMType::getContext. */
2011-07-27 14:19:39 +02:00
fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
/* Operations on integer types */
2011-07-27 14:19:39 +02:00
fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint) -> TypeRef;
fn LLVMInt1Type() -> TypeRef;
fn LLVMInt8Type() -> TypeRef;
fn LLVMInt16Type() -> TypeRef;
fn LLVMInt32Type() -> TypeRef;
fn LLVMInt64Type() -> TypeRef;
fn LLVMIntType(NumBits: c_uint) -> TypeRef;
fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
/* Operations on real types */
2011-07-27 14:19:39 +02:00
fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
fn LLVMFloatType() -> TypeRef;
fn LLVMDoubleType() -> TypeRef;
fn LLVMX86FP80Type() -> TypeRef;
fn LLVMFP128Type() -> TypeRef;
fn LLVMPPCFP128Type() -> TypeRef;
/* Operations on function types */
2011-07-27 14:19:39 +02:00
fn LLVMFunctionType(ReturnType: TypeRef, ParamTypes: *TypeRef,
ParamCount: c_uint, IsVarArg: Bool) -> TypeRef;
2011-07-27 14:19:39 +02:00
fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
2011-07-27 14:19:39 +02:00
fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
/* Operations on struct types */
2011-07-27 14:19:39 +02:00
fn LLVMStructTypeInContext(C: ContextRef, ElementTypes: *TypeRef,
ElementCount: c_uint,
Packed: Bool) -> TypeRef;
fn LLVMStructType(ElementTypes: *TypeRef, ElementCount: c_uint,
2011-07-27 14:19:39 +02:00
Packed: Bool) -> TypeRef;
fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
fn LLVMGetStructElementTypes(StructTy: TypeRef, Dest: *mut TypeRef);
2011-07-27 14:19:39 +02:00
fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
/* Operations on array, pointer, and vector types (sequence types) */
fn LLVMArrayType(ElementType: TypeRef,
ElementCount: c_uint) -> TypeRef;
fn LLVMPointerType(ElementType: TypeRef,
AddressSpace: c_uint) -> TypeRef;
fn LLVMVectorType(ElementType: TypeRef,
ElementCount: c_uint) -> TypeRef;
2011-07-27 14:19:39 +02:00
fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
/* Operations on other types */
2011-07-27 14:19:39 +02:00
fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
fn LLVMVoidType() -> TypeRef;
fn LLVMLabelType() -> TypeRef;
fn LLVMMetadataType() -> TypeRef;
/* Operations on all values */
2011-07-27 14:19:39 +02:00
fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
fn LLVMGetValueName(Val: ValueRef) -> *c_char;
fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
2011-07-27 14:19:39 +02:00
fn LLVMDumpValue(Val: ValueRef);
fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
fn LLVMHasMetadata(Val: ValueRef) -> c_int;
fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
/* Operations on Uses */
2011-07-27 14:19:39 +02:00
fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
fn LLVMGetNextUse(U: UseRef) -> UseRef;
fn LLVMGetUser(U: UseRef) -> ValueRef;
fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
/* Operations on Users */
fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
/* Operations on constants of any type */
2011-07-27 14:19:39 +02:00
fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
/* all zeroes */
2011-07-27 14:19:39 +02:00
fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
/* only for int/vector */
2011-07-27 14:19:39 +02:00
fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
fn LLVMIsConstant(Val: ValueRef) -> Bool;
fn LLVMIsNull(Val: ValueRef) -> Bool;
fn LLVMIsUndef(Val: ValueRef) -> Bool;
fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
/* Operations on metadata */
fn LLVMMDStringInContext(C: ContextRef, Str: *c_char, SLen: c_uint) ->
2011-07-27 14:19:39 +02:00
ValueRef;
fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
fn LLVMMDNodeInContext(C: ContextRef, Vals: *ValueRef, Count: c_uint) ->
2011-07-27 14:19:39 +02:00
ValueRef;
fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
Val: ValueRef);
/* Operations on scalar constants */
fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) ->
2011-07-27 14:19:39 +02:00
ValueRef;
fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8) ->
2011-07-27 14:19:39 +02:00
ValueRef;
fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: *c_char,
SLen: c_uint,
2011-07-27 14:19:39 +02:00
Radix: u8) -> ValueRef;
fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char) -> ValueRef;
fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, Text: *c_char,
SLen: c_uint) -> ValueRef;
fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
/* Operations on composite constants */
fn LLVMConstStringInContext(C: ContextRef, Str: *c_char, Length: c_uint,
2011-07-27 14:19:39 +02:00
DontNullTerminate: Bool) -> ValueRef;
fn LLVMConstStructInContext(C: ContextRef, ConstantVals: *ValueRef,
Count: c_uint, Packed: Bool) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMConstString(Str: *c_char, Length: c_uint,
DontNullTerminate: Bool) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
Length: c_uint) -> ValueRef;
fn LLVMConstStruct(ConstantVals: *ValueRef,
Count: c_uint, Packed: Bool) -> ValueRef;
fn LLVMConstVector(ScalarConstantVals: *ValueRef,
Size: c_uint) -> ValueRef;
/* Constant expressions */
2011-07-27 14:19:39 +02:00
fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstExactSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
ValueRef;
fn LLVMConstGEP(ConstantVal: ValueRef,
ConstantIndices: *ValueRef,
NumIndices: c_uint) -> ValueRef;
fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
ConstantIndices: *ValueRef,
NumIndices: c_uint) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
ValueRef;
fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
ValueRef;
fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
ValueRef;
fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef) ->
ValueRef;
fn LLVMConstIntCast(ConstantVal: ValueRef, ToType: TypeRef,
isSigned: Bool) -> ValueRef;
fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
fn LLVMConstSelect(ConstantCondition: ValueRef, ConstantIfTrue: ValueRef,
ConstantIfFalse: ValueRef) -> ValueRef;
fn LLVMConstExtractElement(VectorConstant: ValueRef,
IndexConstant: ValueRef) -> ValueRef;
fn LLVMConstInsertElement(VectorConstant: ValueRef,
ElementValueConstant: ValueRef,
IndexConstant: ValueRef) -> ValueRef;
fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
VectorBConstant: ValueRef,
MaskConstant: ValueRef) -> ValueRef;
fn LLVMConstExtractValue(AggConstant: ValueRef, IdxList: *c_uint,
NumIdx: c_uint) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMConstInsertValue(AggConstant: ValueRef,
ElementValueConstant: ValueRef, IdxList: *c_uint,
NumIdx: c_uint) -> ValueRef;
fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
Constraints: *c_char, HasSideEffects: Bool,
IsAlignStack: Bool) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
/* Operations on global variables, functions, and aliases (globals) */
2011-07-27 14:19:39 +02:00
fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
fn LLVMGetSection(Global: ValueRef) -> *c_char;
fn LLVMSetSection(Global: ValueRef, Section: *c_char);
fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
/* Operations on global variables */
fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
fn LLVMAddGlobalInAddressSpace(M: ModuleRef, Ty: TypeRef, Name: *c_char,
AddressSpace: c_uint) -> ValueRef;
fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
fn LLVMDeleteGlobal(GlobalVar: ValueRef);
fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
fn LLVMSetInitializer(GlobalVar: ValueRef, ConstantVal: ValueRef);
fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
/* Operations on aliases */
fn LLVMAddAlias(M: ModuleRef, Ty: TypeRef, Aliasee: ValueRef,
Name: *c_char) -> ValueRef;
/* Operations on functions */
fn LLVMAddFunction(M: ModuleRef, Name: *c_char, FunctionTy: TypeRef) ->
2011-07-27 14:19:39 +02:00
ValueRef;
fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
fn LLVMDeleteFunction(Fn: ValueRef);
fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
FunctionTy: TypeRef) -> ValueRef;
fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
fn LLVMGetGC(Fn: ValueRef) -> *c_char;
fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_ulonglong, HighPA:
c_ulonglong);
fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
fn LLVMRemoveFunctionAttr(Fn: ValueRef, PA: c_ulonglong, HighPA:
c_ulonglong);
/* Operations on parameters */
fn LLVMCountParams(Fn: ValueRef) -> c_uint;
2011-07-27 14:19:39 +02:00
fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
/* Operations on basic blocks */
2011-07-27 14:19:39 +02:00
fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
2011-07-27 14:19:39 +02:00
fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef,
Name: *c_char) -> BasicBlockRef;
2011-07-27 14:19:39 +02:00
fn LLVMInsertBasicBlockInContext(C: ContextRef, BB: BasicBlockRef,
Name: *c_char) -> BasicBlockRef;
2011-07-27 14:19:39 +02:00
fn LLVMAppendBasicBlock(Fn: ValueRef, Name: *c_char) -> BasicBlockRef;
fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef, Name: *c_char) ->
2011-07-27 14:19:39 +02:00
BasicBlockRef;
fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
/* Operations on instructions */
2011-07-27 14:19:39 +02:00
fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
/* Operations on call sites */
fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
fn LLVMAddInstrAttribute(Instr: ValueRef, index: c_uint, IA: c_uint);
fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: c_uint,
IA: c_uint);
fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: c_uint,
align: c_uint);
/* Operations on call instructions (only) */
2011-07-27 14:19:39 +02:00
fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
/* Operations on phi nodes */
2011-07-27 14:19:39 +02:00
fn LLVMAddIncoming(PhiNode: ValueRef, IncomingValues: *ValueRef,
IncomingBlocks: *BasicBlockRef, Count: c_uint);
fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint) -> ValueRef;
fn LLVMGetIncomingBlock(PhiNode: ValueRef,
Index: c_uint) -> BasicBlockRef;
/* Instruction builders */
2011-07-27 14:19:39 +02:00
fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
fn LLVMCreateBuilder() -> BuilderRef;
2011-07-27 14:19:39 +02:00
fn LLVMPositionBuilder(Builder: BuilderRef, Block: BasicBlockRef,
Instr: ValueRef);
fn LLVMPositionBuilderBefore(Builder: BuilderRef, Instr: ValueRef);
fn LLVMPositionBuilderAtEnd(Builder: BuilderRef, Block: BasicBlockRef);
fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
fn LLVMClearInsertionPosition(Builder: BuilderRef);
fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef, Instr: ValueRef,
Name: *c_char);
2011-07-27 14:19:39 +02:00
fn LLVMDisposeBuilder(Builder: BuilderRef);
/* Metadata */
2011-07-27 14:19:39 +02:00
fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
/* Terminators */
2011-07-27 14:19:39 +02:00
fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
N: c_uint) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
fn LLVMBuildCondBr(B: BuilderRef, If: ValueRef, Then: BasicBlockRef,
Else: BasicBlockRef) -> ValueRef;
fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef, Else: BasicBlockRef,
NumCases: c_uint) -> ValueRef;
fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef,
NumDests: c_uint) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildInvoke(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
NumArgs: c_uint, Then: BasicBlockRef,
Catch: BasicBlockRef, Name: *c_char) -> ValueRef;
fn LLVMBuildLandingPad(B: BuilderRef, Ty: TypeRef, PersFn: ValueRef,
NumClauses: c_uint, Name: *c_char) -> ValueRef;
fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
/* Add a case to the switch instruction */
2011-07-27 14:19:39 +02:00
fn LLVMAddCase(Switch: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef);
/* Add a destination to the indirectbr instruction */
2011-07-27 14:19:39 +02:00
fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
/* Add a clause to the landing pad instruction */
fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
/* Set the cleanup on a landing pad instruction */
fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
/* Arithmetic */
fn LLVMBuildAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildNSWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildNUWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildFAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildNSWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildNUWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildFSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildNSWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildNUWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildFMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildUDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildExactSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildFDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildURem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildSRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildFRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildShl(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildLShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildAShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildAnd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildOr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildXor(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildBinOp(B: BuilderRef, Op: Opcode, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
/* Memory */
fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildArrayMalloc(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildArrayAlloca(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
fn LLVMBuildLoad(B: BuilderRef, PointerVal: ValueRef, Name: *c_char) ->
2011-07-27 14:19:39 +02:00
ValueRef;
fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef) ->
ValueRef;
fn LLVMBuildGEP(B: BuilderRef, Pointer: ValueRef, Indices: *ValueRef,
NumIndices: c_uint, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
Indices: *ValueRef, NumIndices: c_uint,
Name: *c_char)
2011-07-27 14:19:39 +02:00
-> ValueRef;
fn LLVMBuildStructGEP(B: BuilderRef, Pointer: ValueRef, Idx: c_uint,
Name: *c_char) -> ValueRef;
fn LLVMBuildGlobalString(B: BuilderRef, Str: *c_char, Name: *c_char) ->
2011-07-27 14:19:39 +02:00
ValueRef;
fn LLVMBuildGlobalStringPtr(B: BuilderRef, Str: *c_char, Name: *c_char) ->
2011-07-27 14:19:39 +02:00
ValueRef;
/* Casts */
2011-07-27 14:19:39 +02:00
fn LLVMBuildTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildZExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildSExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildFPToUI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildFPToSI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildUIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildSIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildFPTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildFPExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildPtrToInt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildIntToPtr(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildZExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildSExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildTruncOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
DestTy: TypeRef, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildPointerCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildIntCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildFPCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
Name: *c_char) -> ValueRef;
/* Comparisons */
fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
RHS: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
RHS: ValueRef, Name: *c_char) -> ValueRef;
/* Miscellaneous instructions */
fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildCall(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
NumArgs: c_uint, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildSelect(B: BuilderRef, If: ValueRef, Then: ValueRef,
Else: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildVAArg(B: BuilderRef, list: ValueRef, Ty: TypeRef,
Name: *c_char)
2011-07-27 14:19:39 +02:00
-> ValueRef;
fn LLVMBuildExtractElement(B: BuilderRef, VecVal: ValueRef,
Index: ValueRef, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildInsertElement(B: BuilderRef, VecVal: ValueRef,
EltVal: ValueRef, Index: ValueRef,
Name: *c_char)
2011-07-27 14:19:39 +02:00
-> ValueRef;
fn LLVMBuildShuffleVector(B: BuilderRef, V1: ValueRef, V2: ValueRef,
Mask: ValueRef, Name: *c_char) -> ValueRef;
fn LLVMBuildExtractValue(B: BuilderRef, AggVal: ValueRef, Index: c_uint,
Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildInsertValue(B: BuilderRef, AggVal: ValueRef, EltVal: ValueRef,
Index: c_uint, Name: *c_char) -> ValueRef;
2011-07-27 14:19:39 +02:00
fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef,
Name: *c_char) -> ValueRef;
fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char) ->
2011-07-27 14:19:39 +02:00
ValueRef;
fn LLVMBuildPtrDiff(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
Name: *c_char) -> ValueRef;
/* Atomic Operations */
fn LLVMBuildAtomicCmpXchg(B: BuilderRef, LHS: ValueRef,
CMP: ValueRef, RHS: ValueRef,
++Order: AtomicOrdering) -> ValueRef;
fn LLVMBuildAtomicRMW(B: BuilderRef, ++Op: AtomicBinOp,
LHS: ValueRef, RHS: ValueRef,
++Order: AtomicOrdering) -> ValueRef;
/* Selected entries from the downcasts. */
2011-07-27 14:19:39 +02:00
fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
/** Writes a module to the specified path. Returns 0 on success. */
fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
/** Creates target data from a target layout string. */
fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
/** Adds the target data to the given pass manager. The pass manager
references the target data only weakly. */
2011-07-27 14:19:39 +02:00
fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
/** Number of bytes clobbered when doing a Store to *T. */
fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
/** Number of bytes clobbered when doing a Store to *T. */
fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
/** Distance between successive elements in an array of T.
Includes ABI padding. */
fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
/** Returns the preferred alignment of a type. */
fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
Ty: TypeRef) -> c_uint;
/** Returns the minimum alignment of a type. */
fn LLVMABIAlignmentOfType(TD: TargetDataRef,
Ty: TypeRef) -> c_uint;
/** Returns the minimum alignment of a type when part of a call frame. */
fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
Ty: TypeRef) -> c_uint;
/** Disposes target data. */
2011-07-27 14:19:39 +02:00
fn LLVMDisposeTargetData(TD: TargetDataRef);
/** Creates a pass manager. */
fn LLVMCreatePassManager() -> PassManagerRef;
/** Disposes a pass manager. */
2011-07-27 14:19:39 +02:00
fn LLVMDisposePassManager(PM: PassManagerRef);
/** Runs a pass manager on a module. */
2011-07-27 14:19:39 +02:00
fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
/** Adds a verification pass. */
2011-07-27 14:19:39 +02:00
fn LLVMAddVerifierPass(PM: PassManagerRef);
fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
fn LLVMAddIPSCCPPass(PM: PassManagerRef);
fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
fn LLVMAddReassociatePass(PM: PassManagerRef);
fn LLVMAddLoopRotatePass(PM: PassManagerRef);
fn LLVMAddLICMPass(PM: PassManagerRef);
fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
fn LLVMAddGVNPass(PM: PassManagerRef);
fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
fn LLVMAddSCCPPass(PM: PassManagerRef);
fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
fn LLVMAddConstantMergePass(PM: PassManagerRef);
fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
fn LLVMAddPruneEHPass(PM: PassManagerRef);
fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
OptimizationLevel: c_uint);
fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
Value: Bool);
fn LLVMPassManagerBuilderSetDisableUnitAtATime(PMB: PassManagerBuilderRef,
Value: Bool);
fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef,
Value: Bool);
fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
2011-09-12 12:39:38 +02:00
(PMB: PassManagerBuilderRef, Value: Bool);
fn LLVMPassManagerBuilderUseInlinerWithThreshold
(PMB: PassManagerBuilderRef, threshold: c_uint);
2011-09-12 12:39:38 +02:00
fn LLVMPassManagerBuilderPopulateModulePassManager
(PMB: PassManagerBuilderRef, PM: PassManagerRef);
2011-09-12 12:39:38 +02:00
fn LLVMPassManagerBuilderPopulateFunctionPassManager
(PMB: PassManagerBuilderRef, PM: PassManagerRef);
/** Destroys a memory buffer. */
2011-07-27 14:19:39 +02:00
fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
/* Stuff that's in rustllvm/ because it's not upstream yet. */
/** Opens an object file. */
2011-07-27 14:19:39 +02:00
fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
/** Closes an object file. */
fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
/** Enumerates the sections in an object file. */
fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
/** Destroys a section iterator. */
2011-07-27 14:19:39 +02:00
fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
/** Returns true if the section iterator is at the end of the section
list: */
fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
2011-07-27 14:19:39 +02:00
SI: SectionIteratorRef) -> Bool;
/** Moves the section iterator to point to the next section. */
2011-07-27 14:19:39 +02:00
fn LLVMMoveToNextSection(SI: SectionIteratorRef);
/** Returns the current section name. */
fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
/** Returns the current section size. */
fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
/** Returns the current section contents as a string buffer. */
fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
/** Reads the given file and returns it as a memory buffer. Use
LLVMDisposeMemoryBuffer() to get rid of it. */
fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char) ->
2011-07-27 14:19:39 +02:00
MemoryBufferRef;
fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef,
Triple: *c_char,
// FIXME: When #2334 is fixed, change
// c_uint to FileType
Output: *c_char, FileType: c_uint,
OptLevel: c_int,
EnableSegmentedStacks: bool) -> bool;
/** Returns a string describing the last error caused by an LLVMRust*
call. */
fn LLVMRustGetLastError() -> *c_char;
/** Prepare the JIT. Returns a memory manager that can load crates. */
fn LLVMRustPrepareJIT(__morestack: *()) -> *();
/** Load a crate into the memory manager. */
fn LLVMRustLoadCrate(MM: *(),
Filename: *c_char) -> bool;
/** Execute the JIT engine. */
fn LLVMRustExecuteJIT(MM: *(),
PM: PassManagerRef,
M: ModuleRef,
OptLevel: c_int,
EnableSegmentedStacks: bool) -> *();
2012-08-25 14:54:30 +10:00
/** Parses the bitcode in the given memory buffer. */
2011-07-27 14:19:39 +02:00
fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
/** Parses LLVM asm in the given file */
fn LLVMRustParseAssemblyFile(Filename: *c_char) -> ModuleRef;
fn LLVMRustAddPrintModulePass(PM: PassManagerRef, M: ModuleRef,
Output: *c_char);
2011-05-10 16:10:08 -07:00
/** Turn on LLVM pass-timing. */
fn LLVMRustEnableTimePasses();
/** Print the pass timings since static dtors aren't picking them up. */
fn LLVMRustPrintPassTimings();
fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
2011-07-27 14:19:39 +02:00
fn LLVMStructSetBody(StructTy: TypeRef, ElementTypes: *TypeRef,
ElementCount: c_uint, Packed: Bool);
fn LLVMConstNamedStruct(S: TypeRef, ConstantVals: *ValueRef,
Count: c_uint) -> ValueRef;
/** Enables LLVM debug output. */
fn LLVMSetDebug(Enabled: c_int);
}
fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
}
fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
}
fn SetLinkage(Global: ValueRef, Link: Linkage) {
llvm::LLVMSetLinkage(Global, Link as c_uint);
}
/* Memory-managed object interface to type handles. */
type type_names = @{type_names: HashMap<TypeRef, ~str>,
named_types: HashMap<~str, TypeRef>};
fn associate_type(tn: type_names, +s: ~str, t: TypeRef) {
// XXX: Bad copy, use @str instead?
assert tn.type_names.insert(t, copy s);
assert tn.named_types.insert(s, t);
}
2012-08-20 12:23:37 -07:00
fn type_has_name(tn: type_names, t: TypeRef) -> Option<~str> {
2012-08-01 17:30:05 -07:00
return tn.type_names.find(t);
}
fn name_has_type(tn: type_names, +s: ~str) -> Option<TypeRef> {
2012-08-01 17:30:05 -07:00
return tn.named_types.find(s);
}
fn mk_type_names() -> type_names {
@{type_names: HashMap(),
named_types: HashMap()}
}
fn type_to_str(names: type_names, ty: TypeRef) -> ~str {
2012-08-01 17:30:05 -07:00
return type_to_str_inner(names, ~[], ty);
2010-12-23 17:05:27 -08:00
}
fn type_to_str_inner(names: type_names, +outer0: ~[TypeRef], ty: TypeRef) ->
~str {
2012-08-06 12:34:08 -07:00
match type_has_name(names, ty) {
option::Some(ref n) => return (/*bad*/copy *n),
2012-08-03 19:59:04 -07:00
_ => {}
}
2010-12-23 17:05:27 -08:00
// XXX: Bad copy.
let outer = vec::append_one(copy outer0, ty);
2010-12-23 17:05:27 -08:00
let kind = llvm::LLVMGetTypeKind(ty);
fn tys_str(names: type_names, outer: ~[TypeRef],
tys: ~[TypeRef]) -> ~str {
let mut s: ~str = ~"";
let mut first: bool = true;
2012-06-30 16:19:07 -07:00
for tys.each |t| {
if first { first = false; } else { s += ~", "; }
s += type_to_str_inner(names, outer, *t);
}
2012-08-01 17:30:05 -07:00
return s;
}
2012-08-06 12:34:08 -07:00
match kind {
2012-08-03 19:59:04 -07:00
Void => return ~"Void",
Half => return ~"Half",
Float => return ~"Float",
Double => return ~"Double",
X86_FP80 => return ~"X86_FP80",
FP128 => return ~"FP128",
PPC_FP128 => return ~"PPC_FP128",
Label => return ~"Label",
Integer => {
2012-08-01 17:30:05 -07:00
return ~"i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
2011-07-27 14:19:39 +02:00
}
2012-08-03 19:59:04 -07:00
Function => {
let mut s = ~"fn(";
2011-07-27 14:19:39 +02:00
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
let n_args = llvm::LLVMCountParamTypes(ty) as uint;
let args = vec::from_elem(n_args, 0 as TypeRef);
unsafe {
2012-09-12 17:45:23 -07:00
llvm::LLVMGetParamTypes(ty, vec::raw::to_ptr(args));
}
2011-07-27 14:19:39 +02:00
s += tys_str(names, outer, args);
s += ~") -> ";
2011-07-27 14:19:39 +02:00
s += type_to_str_inner(names, outer, out_ty);
2012-08-01 17:30:05 -07:00
return s;
2011-07-27 14:19:39 +02:00
}
2012-08-03 19:59:04 -07:00
Struct => {
let mut s: ~str = ~"{";
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
let mut elts = vec::from_elem(n_elts, 0 as TypeRef);
llvm::LLVMGetStructElementTypes(ty,
ptr::to_mut_unsafe_ptr(&mut elts[0]));
2011-07-27 14:19:39 +02:00
s += tys_str(names, outer, elts);
s += ~"}";
2012-08-01 17:30:05 -07:00
return s;
2011-07-27 14:19:39 +02:00
}
2012-08-03 19:59:04 -07:00
Array => {
2011-07-27 14:19:39 +02:00
let el_ty = llvm::LLVMGetElementType(ty);
2012-08-01 17:30:05 -07:00
return ~"[" + type_to_str_inner(names, outer, el_ty) + ~" x " +
uint::str(llvm::LLVMGetArrayLength(ty) as uint) + ~"]";
2011-07-27 14:19:39 +02:00
}
2012-08-03 19:59:04 -07:00
Pointer => {
let mut i: uint = 0u;
2012-06-30 16:19:07 -07:00
for outer0.each |tout| {
2011-07-27 14:19:39 +02:00
i += 1u;
if *tout as int == ty as int {
let n: uint = vec::len::<TypeRef>(outer0) - i;
2012-08-01 17:30:05 -07:00
return ~"*\\" + int::str(n as int);
2010-12-23 17:05:27 -08:00
}
}
2012-05-07 14:27:43 -07:00
let addrstr = {
let addrspace = llvm::LLVMGetPointerAddressSpace(ty) as uint;
if addrspace == 0u {
~""
2012-05-07 14:27:43 -07:00
} else {
2012-08-22 17:24:52 -07:00
fmt!("addrspace(%u)", addrspace)
2012-05-07 14:27:43 -07:00
}
};
2012-08-01 17:30:05 -07:00
return addrstr + ~"*" +
2011-07-27 14:19:39 +02:00
type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
}
2012-08-03 19:59:04 -07:00
Vector => return ~"Vector",
Metadata => return ~"Metadata",
X86_MMX => return ~"X86_MMAX"
}
}
2011-10-11 22:08:36 -07:00
fn float_width(llt: TypeRef) -> uint {
2012-08-06 12:34:08 -07:00
return match llvm::LLVMGetTypeKind(llt) as int {
2012-08-03 19:59:04 -07:00
1 => 32u,
2 => 64u,
3 => 80u,
4 | 5 => 128u,
_ => fail ~"llvm_float_width called on a non-float type"
2011-07-27 14:19:39 +02:00
};
}
fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] unsafe {
2012-03-12 15:52:30 -07:00
let args = vec::from_elem(llvm::LLVMCountParamTypes(fn_ty) as uint,
0 as TypeRef);
2012-09-12 17:45:23 -07:00
llvm::LLVMGetParamTypes(fn_ty, vec::raw::to_ptr(args));
2012-08-01 17:30:05 -07:00
return args;
}
fn struct_element_types(struct_ty: TypeRef) -> ~[TypeRef] {
unsafe {
let count = llvm::LLVMCountStructElementTypes(struct_ty);
let mut buf: ~[TypeRef] =
vec::from_elem(count as uint,
cast::transmute::<uint,TypeRef>(0));
llvm::LLVMGetStructElementTypes(struct_ty,
ptr::to_mut_unsafe_ptr(&mut buf[0]));
return move buf;
}
}
/* Memory-managed interface to target data. */
2012-08-15 18:46:55 -07:00
struct target_data_res {
2012-09-06 19:40:15 -07:00
TD: TargetDataRef,
drop { llvm::LLVMDisposeTargetData(self.TD); }
}
2012-09-05 15:58:43 -07:00
fn target_data_res(TD: TargetDataRef) -> target_data_res {
target_data_res {
TD: TD
}
}
type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
fn mk_target_data(string_rep: ~str) -> target_data {
2011-09-02 15:34:58 -07:00
let lltd =
2012-06-30 16:19:07 -07:00
str::as_c_str(string_rep, |buf| llvm::LLVMCreateTargetData(buf) );
2012-08-01 17:30:05 -07:00
return {lltd: lltd, dtor: @target_data_res(lltd)};
}
/* Memory-managed interface to pass managers. */
2012-08-15 18:46:55 -07:00
struct pass_manager_res {
2012-09-06 19:40:15 -07:00
PM: PassManagerRef,
drop { llvm::LLVMDisposePassManager(self.PM); }
}
2012-09-05 15:58:43 -07:00
fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
pass_manager_res {
PM: PM
}
}
type pass_manager = {llpm: PassManagerRef, dtor: @pass_manager_res};
2011-10-11 22:08:36 -07:00
fn mk_pass_manager() -> pass_manager {
2011-07-27 14:19:39 +02:00
let llpm = llvm::LLVMCreatePassManager();
2012-08-01 17:30:05 -07:00
return {llpm: llpm, dtor: @pass_manager_res(llpm)};
}
/* Memory-managed interface to object files. */
2012-08-15 18:46:55 -07:00
struct object_file_res {
2012-09-06 19:40:15 -07:00
ObjectFile: ObjectFileRef,
drop { llvm::LLVMDisposeObjectFile(self.ObjectFile); }
}
fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
2012-09-05 15:58:43 -07:00
object_file_res {
ObjectFile: ObjFile
2012-09-05 15:58:43 -07:00
}
}
type object_file = {llof: ObjectFileRef, dtor: @object_file_res};
2012-08-20 12:23:37 -07:00
fn mk_object_file(llmb: MemoryBufferRef) -> Option<object_file> {
2011-07-27 14:19:39 +02:00
let llof = llvm::LLVMCreateObjectFile(llmb);
2012-08-20 12:23:37 -07:00
if llof as int == 0 { return option::None::<object_file>; }
return option::Some({llof: llof, dtor: @object_file_res(llof)});
}
/* Memory-managed interface to section iterators. */
2012-08-15 18:46:55 -07:00
struct section_iter_res {
2012-09-06 19:40:15 -07:00
SI: SectionIteratorRef,
drop { llvm::LLVMDisposeSectionIterator(self.SI); }
}
2012-09-05 15:58:43 -07:00
fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
section_iter_res {
SI: SI
}
}
type section_iter = {llsi: SectionIteratorRef, dtor: @section_iter_res};
2011-10-11 22:08:36 -07:00
fn mk_section_iter(llof: ObjectFileRef) -> section_iter {
2011-07-27 14:19:39 +02:00
let llsi = llvm::LLVMGetSections(llof);
2012-08-01 17:30:05 -07:00
return {llsi: llsi, dtor: @section_iter_res(llsi)};
}
//
// Local Variables:
// mode: rust
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//