3 use libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
7 const True: Bool = 1 as Bool;
8 const False: Bool = 0 as Bool;
10 // Consts for the LLVM CallConv type, pre-cast to uint.
16 X86StdcallCallConv = 64,
17 X86FastcallCallConv = 65,
21 LLVMDefaultVisibility = 0,
23 ProtectedVisibility = 2,
28 AvailableExternallyLinkage = 1,
29 LinkOnceAnyLinkage = 2,
30 LinkOnceODRLinkage = 3,
31 LinkOnceODRAutoHideLinkage = 4,
37 DLLImportLinkage = 10,
38 DLLExportLinkage = 11,
39 ExternalWeakLinkage = 12,
42 LinkerPrivateLinkage = 15,
43 LinkerPrivateWeakLinkage = 16,
49 NoReturnAttribute = 4,
51 StructRetAttribute = 16,
52 NoUnwindAttribute = 32,
53 NoAliasAttribute = 64,
56 ReadNoneAttribute = 512,
57 ReadOnlyAttribute = 1024,
58 NoInlineAttribute = 2048,
59 AlwaysInlineAttribute = 4096,
60 OptimizeForSizeAttribute = 8192,
61 StackProtectAttribute = 16384,
62 StackProtectReqAttribute = 32768,
64 AlignmentAttribute = 2031616,
65 NoCaptureAttribute = 2097152,
66 NoRedZoneAttribute = 4194304,
67 NoImplicitFloatAttribute = 8388608,
68 NakedAttribute = 16777216,
69 InlineHintAttribute = 33554432,
71 StackAttribute = 469762048,
72 ReturnsTwiceAttribute = 536870912,
74 UWTableAttribute = 1073741824,
75 NonLazyBindAttribute = 2147483648,
78 // enum for the LLVM IntPredicate type
92 // enum for the LLVM RealPredicate type
94 RealPredicateFalse = 0,
109 RealPredicateTrue = 15,
112 // enum for the LLVM TypeKind type - must stay in sync with the def of
113 // LLVMTypeKind in llvm/include/llvm-c/Core.h
133 impl TypeKind : cmp::Eq {
134 pure fn eq(other: &TypeKind) -> bool {
135 match (self, (*other)) {
136 (Void, Void) => true,
137 (Half, Half) => true,
138 (Float, Float) => true,
139 (Double, Double) => true,
140 (X86_FP80, X86_FP80) => true,
141 (FP128, FP128) => true,
142 (PPC_FP128, PPC_FP128) => true,
143 (Label, Label) => true,
144 (Integer, Integer) => true,
145 (Function, Function) => true,
146 (Struct, Struct) => true,
147 (Array, Array) => true,
148 (Pointer, Pointer) => true,
149 (Vector, Vector) => true,
150 (Metadata, Metadata) => true,
151 (X86_MMX, X86_MMX) => true,
155 (Double, _) => false,
156 (X86_FP80, _) => false,
158 (PPC_FP128, _) => false,
160 (Integer, _) => false,
161 (Function, _) => false,
162 (Struct, _) => false,
164 (Pointer, _) => false,
165 (Vector, _) => false,
166 (Metadata, _) => false,
167 (X86_MMX, _) => false,
170 pure fn ne(other: &TypeKind) -> bool { !self.eq(other) }
187 enum AtomicOrdering {
191 // Consume = 3, // Not specified yet.
195 SequentiallyConsistent = 7
198 // FIXME: Not used right now, but will be once #2334 is fixed
199 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
205 // Opaque pointer types
206 enum Module_opaque {}
207 type ModuleRef = *Module_opaque;
208 enum Context_opaque {}
209 type ContextRef = *Context_opaque;
211 type TypeRef = *Type_opaque;
213 type ValueRef = *Value_opaque;
214 enum BasicBlock_opaque {}
215 type BasicBlockRef = *BasicBlock_opaque;
216 enum Builder_opaque {}
217 type BuilderRef = *Builder_opaque;
218 enum MemoryBuffer_opaque {}
219 type MemoryBufferRef = *MemoryBuffer_opaque;
220 enum PassManager_opaque {}
221 type PassManagerRef = *PassManager_opaque;
222 enum PassManagerBuilder_opaque {}
223 type PassManagerBuilderRef = *PassManagerBuilder_opaque;
225 type UseRef = *Use_opaque;
226 enum TargetData_opaque {}
227 type TargetDataRef = *TargetData_opaque;
228 enum ObjectFile_opaque {}
229 type ObjectFileRef = *ObjectFile_opaque;
230 enum SectionIterator_opaque {}
231 type SectionIteratorRef = *SectionIterator_opaque;
233 #[link_args = "-Lrustllvm"]
234 #[link_name = "rustllvm"]
238 /* Create and destroy contexts. */
239 fn LLVMContextCreate() -> ContextRef;
240 fn LLVMGetGlobalContext() -> ContextRef;
241 fn LLVMContextDispose(C: ContextRef);
242 fn LLVMGetMDKindIDInContext(C: ContextRef, Name: *c_char, SLen: c_uint) ->
244 fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
246 /* Create and destroy modules. */
247 fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char, C: ContextRef) ->
249 fn LLVMDisposeModule(M: ModuleRef);
251 /** Data layout. See Module::getDataLayout. */
252 fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
253 fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
255 /** Target triple. See Module::getTargetTriple. */
256 fn LLVMGetTarget(M: ModuleRef) -> *c_char;
257 fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
259 /** See Module::dump. */
260 fn LLVMDumpModule(M: ModuleRef);
262 /** See Module::setModuleInlineAsm. */
263 fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
265 /** See llvm::LLVMTypeKind::getTypeID. */
266 fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
268 /** See llvm::LLVMType::getContext. */
269 fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
271 /* Operations on integer types */
272 fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
273 fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
274 fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
275 fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
276 fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
277 fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint) -> TypeRef;
279 fn LLVMInt1Type() -> TypeRef;
280 fn LLVMInt8Type() -> TypeRef;
281 fn LLVMInt16Type() -> TypeRef;
282 fn LLVMInt32Type() -> TypeRef;
283 fn LLVMInt64Type() -> TypeRef;
284 fn LLVMIntType(NumBits: c_uint) -> TypeRef;
285 fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
287 /* Operations on real types */
288 fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
289 fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
290 fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
291 fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
292 fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
294 fn LLVMFloatType() -> TypeRef;
295 fn LLVMDoubleType() -> TypeRef;
296 fn LLVMX86FP80Type() -> TypeRef;
297 fn LLVMFP128Type() -> TypeRef;
298 fn LLVMPPCFP128Type() -> TypeRef;
300 /* Operations on function types */
301 fn LLVMFunctionType(ReturnType: TypeRef, ParamTypes: *TypeRef,
302 ParamCount: c_uint, IsVarArg: Bool) -> TypeRef;
303 fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
304 fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
305 fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
306 fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
308 /* Operations on struct types */
309 fn LLVMStructTypeInContext(C: ContextRef, ElementTypes: *TypeRef,
310 ElementCount: c_uint,
311 Packed: Bool) -> TypeRef;
312 fn LLVMStructType(ElementTypes: *TypeRef, ElementCount: c_uint,
313 Packed: Bool) -> TypeRef;
314 fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
315 fn LLVMGetStructElementTypes(StructTy: TypeRef, Dest: *TypeRef);
316 fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
318 /* Operations on array, pointer, and vector types (sequence types) */
319 fn LLVMArrayType(ElementType: TypeRef,
320 ElementCount: c_uint) -> TypeRef;
321 fn LLVMPointerType(ElementType: TypeRef,
322 AddressSpace: c_uint) -> TypeRef;
323 fn LLVMVectorType(ElementType: TypeRef,
324 ElementCount: c_uint) -> TypeRef;
326 fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
327 fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
328 fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
329 fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
331 /* Operations on other types */
332 fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
333 fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
334 fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
336 fn LLVMVoidType() -> TypeRef;
337 fn LLVMLabelType() -> TypeRef;
338 fn LLVMMetadataType() -> TypeRef;
340 /* Operations on all values */
341 fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
342 fn LLVMGetValueName(Val: ValueRef) -> *c_char;
343 fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
344 fn LLVMDumpValue(Val: ValueRef);
345 fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
346 fn LLVMHasMetadata(Val: ValueRef) -> c_int;
347 fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
348 fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
350 /* Operations on Uses */
351 fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
352 fn LLVMGetNextUse(U: UseRef) -> UseRef;
353 fn LLVMGetUser(U: UseRef) -> ValueRef;
354 fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
356 /* Operations on Users */
357 fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
358 fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
360 /* Operations on constants of any type */
361 fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
363 fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
364 /* only for int/vector */
365 fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
366 fn LLVMIsConstant(Val: ValueRef) -> Bool;
367 fn LLVMIsNull(Val: ValueRef) -> Bool;
368 fn LLVMIsUndef(Val: ValueRef) -> Bool;
369 fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
371 /* Operations on metadata */
372 fn LLVMMDStringInContext(C: ContextRef, Str: *c_char, SLen: c_uint) ->
374 fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
375 fn LLVMMDNodeInContext(C: ContextRef, Vals: *ValueRef, Count: c_uint) ->
377 fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
378 fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
381 /* Operations on scalar constants */
382 fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) ->
384 fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8) ->
386 fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: *c_char,
388 Radix: u8) -> ValueRef;
389 fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
390 fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char) -> ValueRef;
391 fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, Text: *c_char,
392 SLen: c_uint) -> ValueRef;
393 fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
394 fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
397 /* Operations on composite constants */
398 fn LLVMConstStringInContext(C: ContextRef, Str: *c_char, Length: c_uint,
399 DontNullTerminate: Bool) -> ValueRef;
400 fn LLVMConstStructInContext(C: ContextRef, ConstantVals: *ValueRef,
401 Count: c_uint, Packed: Bool) -> ValueRef;
403 fn LLVMConstString(Str: *c_char, Length: c_uint,
404 DontNullTerminate: Bool) -> ValueRef;
405 fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
406 Length: c_uint) -> ValueRef;
407 fn LLVMConstStruct(ConstantVals: *ValueRef,
408 Count: c_uint, Packed: Bool) -> ValueRef;
409 fn LLVMConstVector(ScalarConstantVals: *ValueRef,
410 Size: c_uint) -> ValueRef;
412 /* Constant expressions */
413 fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
414 fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
415 fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
416 fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
417 fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
418 fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
419 fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
420 fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
421 fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
423 fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
425 fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
427 fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
428 fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
430 fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
432 fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
434 fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
435 fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
437 fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
439 fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
441 fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
443 fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
445 fn LLVMConstExactSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
447 fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
449 fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
451 fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
453 fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
455 fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
456 fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
457 fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
458 fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
459 fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
461 fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
463 fn LLVMConstGEP(ConstantVal: ValueRef,
464 ConstantIndices: *ValueRef,
465 NumIndices: c_uint) -> ValueRef;
466 fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
467 ConstantIndices: *ValueRef,
468 NumIndices: c_uint) -> ValueRef;
469 fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
470 fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
471 fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
472 fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
473 fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
474 fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
475 fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
476 fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
477 fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
478 fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
479 fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
480 fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
481 fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
483 fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
485 fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
487 fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef) ->
489 fn LLVMConstIntCast(ConstantVal: ValueRef, ToType: TypeRef,
490 isSigned: Bool) -> ValueRef;
491 fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
492 fn LLVMConstSelect(ConstantCondition: ValueRef, ConstantIfTrue: ValueRef,
493 ConstantIfFalse: ValueRef) -> ValueRef;
494 fn LLVMConstExtractElement(VectorConstant: ValueRef,
495 IndexConstant: ValueRef) -> ValueRef;
496 fn LLVMConstInsertElement(VectorConstant: ValueRef,
497 ElementValueConstant: ValueRef,
498 IndexConstant: ValueRef) -> ValueRef;
499 fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
500 VectorBConstant: ValueRef,
501 MaskConstant: ValueRef) -> ValueRef;
502 fn LLVMConstExtractValue(AggConstant: ValueRef, IdxList: *c_uint,
503 NumIdx: c_uint) -> ValueRef;
504 fn LLVMConstInsertValue(AggConstant: ValueRef,
505 ElementValueConstant: ValueRef, IdxList: *c_uint,
506 NumIdx: c_uint) -> ValueRef;
507 fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
508 Constraints: *c_char, HasSideEffects: Bool,
509 IsAlignStack: Bool) -> ValueRef;
510 fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
514 /* Operations on global variables, functions, and aliases (globals) */
515 fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
516 fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
517 fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
518 fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
519 fn LLVMGetSection(Global: ValueRef) -> *c_char;
520 fn LLVMSetSection(Global: ValueRef, Section: *c_char);
521 fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
522 fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
523 fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
524 fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
527 /* Operations on global variables */
528 fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
529 fn LLVMAddGlobalInAddressSpace(M: ModuleRef, Ty: TypeRef, Name: *c_char,
530 AddressSpace: c_uint) -> ValueRef;
531 fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
532 fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
533 fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
534 fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
535 fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
536 fn LLVMDeleteGlobal(GlobalVar: ValueRef);
537 fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
538 fn LLVMSetInitializer(GlobalVar: ValueRef, ConstantVal: ValueRef);
539 fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
540 fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
541 fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
542 fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
544 /* Operations on aliases */
545 fn LLVMAddAlias(M: ModuleRef, Ty: TypeRef, Aliasee: ValueRef,
546 Name: *c_char) -> ValueRef;
548 /* Operations on functions */
549 fn LLVMAddFunction(M: ModuleRef, Name: *c_char, FunctionTy: TypeRef) ->
551 fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
552 fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
553 fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
554 fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
555 fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
556 fn LLVMDeleteFunction(Fn: ValueRef);
557 fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
558 FunctionTy: TypeRef) -> ValueRef;
559 fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
560 fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
561 fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
562 fn LLVMGetGC(Fn: ValueRef) -> *c_char;
563 fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
564 fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_ulonglong, HighPA:
566 fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
567 fn LLVMRemoveFunctionAttr(Fn: ValueRef, PA: c_ulonglong, HighPA:
570 /* Operations on parameters */
571 fn LLVMCountParams(Fn: ValueRef) -> c_uint;
572 fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
573 fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
574 fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
575 fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
576 fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
577 fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
578 fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
579 fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
580 fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
581 fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
582 fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
584 /* Operations on basic blocks */
585 fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
586 fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
587 fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
588 fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
589 fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
590 fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
591 fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
592 fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
593 fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
594 fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
595 fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
597 fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef,
598 Name: *c_char) -> BasicBlockRef;
599 fn LLVMInsertBasicBlockInContext(C: ContextRef, BB: BasicBlockRef,
600 Name: *c_char) -> BasicBlockRef;
602 fn LLVMAppendBasicBlock(Fn: ValueRef, Name: *c_char) -> BasicBlockRef;
603 fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef, Name: *c_char) ->
605 fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
607 /* Operations on instructions */
608 fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
609 fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
610 fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
611 fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
612 fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
614 /* Operations on call sites */
615 fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
616 fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
617 fn LLVMAddInstrAttribute(Instr: ValueRef, index: c_uint, IA: c_uint);
618 fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: c_uint,
620 fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: c_uint,
623 /* Operations on call instructions (only) */
624 fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
625 fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
627 /* Operations on phi nodes */
628 fn LLVMAddIncoming(PhiNode: ValueRef, IncomingValues: *ValueRef,
629 IncomingBlocks: *BasicBlockRef, Count: c_uint);
630 fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
631 fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint) -> ValueRef;
632 fn LLVMGetIncomingBlock(PhiNode: ValueRef,
633 Index: c_uint) -> BasicBlockRef;
635 /* Instruction builders */
636 fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
637 fn LLVMCreateBuilder() -> BuilderRef;
638 fn LLVMPositionBuilder(Builder: BuilderRef, Block: BasicBlockRef,
640 fn LLVMPositionBuilderBefore(Builder: BuilderRef, Instr: ValueRef);
641 fn LLVMPositionBuilderAtEnd(Builder: BuilderRef, Block: BasicBlockRef);
642 fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
643 fn LLVMClearInsertionPosition(Builder: BuilderRef);
644 fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
645 fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef, Instr: ValueRef,
647 fn LLVMDisposeBuilder(Builder: BuilderRef);
650 fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
651 fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
652 fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
655 fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
656 fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
657 fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
658 N: c_uint) -> ValueRef;
659 fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
660 fn LLVMBuildCondBr(B: BuilderRef, If: ValueRef, Then: BasicBlockRef,
661 Else: BasicBlockRef) -> ValueRef;
662 fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef, Else: BasicBlockRef,
663 NumCases: c_uint) -> ValueRef;
664 fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef,
665 NumDests: c_uint) -> ValueRef;
666 fn LLVMBuildInvoke(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
667 NumArgs: c_uint, Then: BasicBlockRef,
668 Catch: BasicBlockRef, Name: *c_char) -> ValueRef;
669 fn LLVMBuildLandingPad(B: BuilderRef, Ty: TypeRef, PersFn: ValueRef,
670 NumClauses: c_uint, Name: *c_char) -> ValueRef;
671 fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
672 fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
674 /* Add a case to the switch instruction */
675 fn LLVMAddCase(Switch: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef);
677 /* Add a destination to the indirectbr instruction */
678 fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
680 /* Add a clause to the landing pad instruction */
681 fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
683 /* Set the cleanup on a landing pad instruction */
684 fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
687 fn LLVMBuildAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
688 Name: *c_char) -> ValueRef;
689 fn LLVMBuildNSWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
690 Name: *c_char) -> ValueRef;
691 fn LLVMBuildNUWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
692 Name: *c_char) -> ValueRef;
693 fn LLVMBuildFAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
694 Name: *c_char) -> ValueRef;
695 fn LLVMBuildSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
696 Name: *c_char) -> ValueRef;
697 fn LLVMBuildNSWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
698 Name: *c_char) -> ValueRef;
699 fn LLVMBuildNUWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
700 Name: *c_char) -> ValueRef;
701 fn LLVMBuildFSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
702 Name: *c_char) -> ValueRef;
703 fn LLVMBuildMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
704 Name: *c_char) -> ValueRef;
705 fn LLVMBuildNSWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
706 Name: *c_char) -> ValueRef;
707 fn LLVMBuildNUWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
708 Name: *c_char) -> ValueRef;
709 fn LLVMBuildFMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
710 Name: *c_char) -> ValueRef;
711 fn LLVMBuildUDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
712 Name: *c_char) -> ValueRef;
713 fn LLVMBuildSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
714 Name: *c_char) -> ValueRef;
715 fn LLVMBuildExactSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
716 Name: *c_char) -> ValueRef;
717 fn LLVMBuildFDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
718 Name: *c_char) -> ValueRef;
719 fn LLVMBuildURem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
720 Name: *c_char) -> ValueRef;
721 fn LLVMBuildSRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
722 Name: *c_char) -> ValueRef;
723 fn LLVMBuildFRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
724 Name: *c_char) -> ValueRef;
725 fn LLVMBuildShl(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
726 Name: *c_char) -> ValueRef;
727 fn LLVMBuildLShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
728 Name: *c_char) -> ValueRef;
729 fn LLVMBuildAShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
730 Name: *c_char) -> ValueRef;
731 fn LLVMBuildAnd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
732 Name: *c_char) -> ValueRef;
733 fn LLVMBuildOr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
734 Name: *c_char) -> ValueRef;
735 fn LLVMBuildXor(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
736 Name: *c_char) -> ValueRef;
737 fn LLVMBuildBinOp(B: BuilderRef, Op: Opcode, LHS: ValueRef, RHS: ValueRef,
738 Name: *c_char) -> ValueRef;
739 fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
740 fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
741 fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
742 fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
743 fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
746 fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
747 fn LLVMBuildArrayMalloc(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
748 Name: *c_char) -> ValueRef;
749 fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
750 fn LLVMBuildArrayAlloca(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
751 Name: *c_char) -> ValueRef;
752 fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
753 fn LLVMBuildLoad(B: BuilderRef, PointerVal: ValueRef, Name: *c_char) ->
755 fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef) ->
757 fn LLVMBuildGEP(B: BuilderRef, Pointer: ValueRef, Indices: *ValueRef,
758 NumIndices: c_uint, Name: *c_char) -> ValueRef;
759 fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
760 Indices: *ValueRef, NumIndices: c_uint,
763 fn LLVMBuildStructGEP(B: BuilderRef, Pointer: ValueRef, Idx: c_uint,
764 Name: *c_char) -> ValueRef;
765 fn LLVMBuildGlobalString(B: BuilderRef, Str: *c_char, Name: *c_char) ->
767 fn LLVMBuildGlobalStringPtr(B: BuilderRef, Str: *c_char, Name: *c_char) ->
771 fn LLVMBuildTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
772 Name: *c_char) -> ValueRef;
773 fn LLVMBuildZExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
774 Name: *c_char) -> ValueRef;
775 fn LLVMBuildSExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
776 Name: *c_char) -> ValueRef;
777 fn LLVMBuildFPToUI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
778 Name: *c_char) -> ValueRef;
779 fn LLVMBuildFPToSI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
780 Name: *c_char) -> ValueRef;
781 fn LLVMBuildUIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
782 Name: *c_char) -> ValueRef;
783 fn LLVMBuildSIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
784 Name: *c_char) -> ValueRef;
785 fn LLVMBuildFPTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
786 Name: *c_char) -> ValueRef;
787 fn LLVMBuildFPExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
788 Name: *c_char) -> ValueRef;
789 fn LLVMBuildPtrToInt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
790 Name: *c_char) -> ValueRef;
791 fn LLVMBuildIntToPtr(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
792 Name: *c_char) -> ValueRef;
793 fn LLVMBuildBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
794 Name: *c_char) -> ValueRef;
795 fn LLVMBuildZExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
796 Name: *c_char) -> ValueRef;
797 fn LLVMBuildSExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
798 Name: *c_char) -> ValueRef;
799 fn LLVMBuildTruncOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
800 Name: *c_char) -> ValueRef;
801 fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
802 DestTy: TypeRef, Name: *c_char) -> ValueRef;
803 fn LLVMBuildPointerCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
804 Name: *c_char) -> ValueRef;
805 fn LLVMBuildIntCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
806 Name: *c_char) -> ValueRef;
807 fn LLVMBuildFPCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
808 Name: *c_char) -> ValueRef;
811 fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
812 RHS: ValueRef, Name: *c_char) -> ValueRef;
813 fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
814 RHS: ValueRef, Name: *c_char) -> ValueRef;
816 /* Miscellaneous instructions */
817 fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
818 fn LLVMBuildCall(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
819 NumArgs: c_uint, Name: *c_char) -> ValueRef;
820 fn LLVMBuildSelect(B: BuilderRef, If: ValueRef, Then: ValueRef,
821 Else: ValueRef, Name: *c_char) -> ValueRef;
822 fn LLVMBuildVAArg(B: BuilderRef, list: ValueRef, Ty: TypeRef,
825 fn LLVMBuildExtractElement(B: BuilderRef, VecVal: ValueRef,
826 Index: ValueRef, Name: *c_char) -> ValueRef;
827 fn LLVMBuildInsertElement(B: BuilderRef, VecVal: ValueRef,
828 EltVal: ValueRef, Index: ValueRef,
831 fn LLVMBuildShuffleVector(B: BuilderRef, V1: ValueRef, V2: ValueRef,
832 Mask: ValueRef, Name: *c_char) -> ValueRef;
833 fn LLVMBuildExtractValue(B: BuilderRef, AggVal: ValueRef, Index: c_uint,
834 Name: *c_char) -> ValueRef;
835 fn LLVMBuildInsertValue(B: BuilderRef, AggVal: ValueRef, EltVal: ValueRef,
836 Index: c_uint, Name: *c_char) -> ValueRef;
838 fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef,
839 Name: *c_char) -> ValueRef;
840 fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char) ->
842 fn LLVMBuildPtrDiff(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
843 Name: *c_char) -> ValueRef;
845 /* Atomic Operations */
846 fn LLVMBuildAtomicCmpXchg(B: BuilderRef, LHS: ValueRef,
847 CMP: ValueRef, RHS: ValueRef,
848 ++Order: AtomicOrdering) -> ValueRef;
849 fn LLVMBuildAtomicRMW(B: BuilderRef, ++Op: AtomicBinOp,
850 LHS: ValueRef, RHS: ValueRef,
851 ++Order: AtomicOrdering) -> ValueRef;
853 /* Selected entries from the downcasts. */
854 fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
856 /** Writes a module to the specified path. Returns 0 on success. */
857 fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
859 /** Creates target data from a target layout string. */
860 fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
861 /** Adds the target data to the given pass manager. The pass manager
862 references the target data only weakly. */
863 fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
864 /** Number of bytes clobbered when doing a Store to *T. */
865 fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
867 /** Number of bytes clobbered when doing a Store to *T. */
868 fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
870 /** Distance between successive elements in an array of T.
871 Includes ABI padding. */
872 fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
874 /** Returns the preferred alignment of a type. */
875 fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
876 Ty: TypeRef) -> c_uint;
877 /** Returns the minimum alignment of a type. */
878 fn LLVMABIAlignmentOfType(TD: TargetDataRef,
879 Ty: TypeRef) -> c_uint;
880 /** Returns the minimum alignment of a type when part of a call frame. */
881 fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
882 Ty: TypeRef) -> c_uint;
884 /** Disposes target data. */
885 fn LLVMDisposeTargetData(TD: TargetDataRef);
887 /** Creates a pass manager. */
888 fn LLVMCreatePassManager() -> PassManagerRef;
889 /** Disposes a pass manager. */
890 fn LLVMDisposePassManager(PM: PassManagerRef);
891 /** Runs a pass manager on a module. */
892 fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
894 /** Adds a verification pass. */
895 fn LLVMAddVerifierPass(PM: PassManagerRef);
897 fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
898 fn LLVMAddIPSCCPPass(PM: PassManagerRef);
899 fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
900 fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
901 fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
902 fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
903 fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
904 fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
905 fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
906 fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
907 fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
908 fn LLVMAddReassociatePass(PM: PassManagerRef);
909 fn LLVMAddLoopRotatePass(PM: PassManagerRef);
910 fn LLVMAddLICMPass(PM: PassManagerRef);
911 fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
912 fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
913 fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
914 fn LLVMAddGVNPass(PM: PassManagerRef);
915 fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
916 fn LLVMAddSCCPPass(PM: PassManagerRef);
917 fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
918 fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
919 fn LLVMAddConstantMergePass(PM: PassManagerRef);
920 fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
921 fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
922 fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
923 fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
924 fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
925 fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
926 fn LLVMAddPruneEHPass(PM: PassManagerRef);
927 fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
928 fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
929 fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
930 fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
931 fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
933 fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
934 fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
935 fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
936 OptimizationLevel: c_uint);
937 fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
939 fn LLVMPassManagerBuilderSetDisableUnitAtATime(PMB: PassManagerBuilderRef,
941 fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef,
943 fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
944 (PMB: PassManagerBuilderRef, Value: Bool);
945 fn LLVMPassManagerBuilderUseInlinerWithThreshold
946 (PMB: PassManagerBuilderRef, threshold: c_uint);
947 fn LLVMPassManagerBuilderPopulateModulePassManager
948 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
950 fn LLVMPassManagerBuilderPopulateFunctionPassManager
951 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
953 /** Destroys a memory buffer. */
954 fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
957 /* Stuff that's in rustllvm/ because it's not upstream yet. */
959 /** Opens an object file. */
960 fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
961 /** Closes an object file. */
962 fn LLVMDisposeObjectFile(ObjectFile: ObjectFileRef);
964 /** Enumerates the sections in an object file. */
965 fn LLVMGetSections(ObjectFile: ObjectFileRef) -> SectionIteratorRef;
966 /** Destroys a section iterator. */
967 fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
968 /** Returns true if the section iterator is at the end of the section
970 fn LLVMIsSectionIteratorAtEnd(ObjectFile: ObjectFileRef,
971 SI: SectionIteratorRef) -> Bool;
972 /** Moves the section iterator to point to the next section. */
973 fn LLVMMoveToNextSection(SI: SectionIteratorRef);
974 /** Returns the current section name. */
975 fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
976 /** Returns the current section size. */
977 fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
978 /** Returns the current section contents as a string buffer. */
979 fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
981 /** Reads the given file and returns it as a memory buffer. Use
982 LLVMDisposeMemoryBuffer() to get rid of it. */
983 fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char) ->
986 fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef,
988 // FIXME: When #2334 is fixed, change
989 // c_uint to FileType
990 Output: *c_char, FileType: c_uint,
992 EnableSegmentedStacks: bool) -> bool;
994 /** Returns a string describing the last error caused by an LLVMRust*
996 fn LLVMRustGetLastError() -> *c_char;
998 /** Prepare the JIT. Returns a memory manager that can load crates. */
999 fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1001 /** Load a crate into the memory manager. */
1002 fn LLVMRustLoadCrate(MM: *(),
1003 Filename: *c_char) -> bool;
1005 /** Execute the JIT engine. */
1006 fn LLVMRustExecuteJIT(MM: *(),
1010 EnableSegmentedStacks: bool) -> *();
1012 /** Parses the bitcode in the given memory buffer. */
1013 fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
1015 /** Parses LLVM asm in the given file */
1016 fn LLVMRustParseAssemblyFile(Filename: *c_char) -> ModuleRef;
1018 fn LLVMRustAddPrintModulePass(PM: PassManagerRef, M: ModuleRef,
1021 /** Turn on LLVM pass-timing. */
1022 fn LLVMRustEnableTimePasses();
1024 /** Print the pass timings since static dtors aren't picking them up. */
1025 fn LLVMRustPrintPassTimings();
1027 fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1029 fn LLVMStructSetBody(StructTy: TypeRef, ElementTypes: *TypeRef,
1030 ElementCount: c_uint, Packed: Bool);
1032 fn LLVMConstNamedStruct(S: TypeRef, ConstantVals: *ValueRef,
1033 Count: c_uint) -> ValueRef;
1035 /** Enables LLVM debug output. */
1036 fn LLVMSetDebug(Enabled: c_int);
1039 fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
1040 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
1042 fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
1043 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
1045 fn SetLinkage(Global: ValueRef, Link: Linkage) {
1046 llvm::LLVMSetLinkage(Global, Link as c_uint);
1049 /* Memory-managed object interface to type handles. */
1051 type type_names = @{type_names: std::map::HashMap<TypeRef, ~str>,
1052 named_types: std::map::HashMap<~str, TypeRef>};
1054 fn associate_type(tn: type_names, s: ~str, t: TypeRef) {
1055 assert tn.type_names.insert(t, s);
1056 assert tn.named_types.insert(s, t);
1059 fn type_has_name(tn: type_names, t: TypeRef) -> Option<~str> {
1060 return tn.type_names.find(t);
1063 fn name_has_type(tn: type_names, s: ~str) -> Option<TypeRef> {
1064 return tn.named_types.find(s);
1067 fn mk_type_names() -> type_names {
1068 @{type_names: std::map::HashMap(),
1069 named_types: std::map::HashMap()}
1072 fn type_to_str(names: type_names, ty: TypeRef) -> ~str {
1073 return type_to_str_inner(names, ~[], ty);
1076 fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) ->
1078 match type_has_name(names, ty) {
1079 option::Some(n) => return n,
1083 let outer = vec::append_one(outer0, ty);
1085 let kind = llvm::LLVMGetTypeKind(ty);
1087 fn tys_str(names: type_names, outer: ~[TypeRef],
1088 tys: ~[TypeRef]) -> ~str {
1089 let mut s: ~str = ~"";
1090 let mut first: bool = true;
1092 if first { first = false; } else { s += ~", "; }
1093 s += type_to_str_inner(names, outer, *t);
1099 Void => return ~"Void",
1100 Half => return ~"Half",
1101 Float => return ~"Float",
1102 Double => return ~"Double",
1103 X86_FP80 => return ~"X86_FP80",
1104 FP128 => return ~"FP128",
1105 PPC_FP128 => return ~"PPC_FP128",
1106 Label => return ~"Label",
1108 return ~"i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
1112 let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
1113 let n_args = llvm::LLVMCountParamTypes(ty) as uint;
1114 let args = vec::from_elem(n_args, 0 as TypeRef);
1116 llvm::LLVMGetParamTypes(ty, vec::raw::to_ptr(args));
1118 s += tys_str(names, outer, args);
1120 s += type_to_str_inner(names, outer, out_ty);
1124 let mut s: ~str = ~"{";
1125 let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
1126 let elts = vec::from_elem(n_elts, 0 as TypeRef);
1128 llvm::LLVMGetStructElementTypes(ty, vec::raw::to_ptr(elts));
1130 s += tys_str(names, outer, elts);
1135 let el_ty = llvm::LLVMGetElementType(ty);
1136 return ~"[" + type_to_str_inner(names, outer, el_ty) + ~" x " +
1137 uint::str(llvm::LLVMGetArrayLength(ty) as uint) + ~"]";
1140 let mut i: uint = 0u;
1141 for outer0.each |tout| {
1143 if *tout as int == ty as int {
1144 let n: uint = vec::len::<TypeRef>(outer0) - i;
1145 return ~"*\\" + int::str(n as int);
1149 let addrspace = llvm::LLVMGetPointerAddressSpace(ty) as uint;
1150 if addrspace == 0u {
1153 fmt!("addrspace(%u)", addrspace)
1156 return addrstr + ~"*" +
1157 type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
1159 Vector => return ~"Vector",
1160 Metadata => return ~"Metadata",
1161 X86_MMX => return ~"X86_MMAX"
1165 fn float_width(llt: TypeRef) -> uint {
1166 return match llvm::LLVMGetTypeKind(llt) as int {
1171 _ => fail ~"llvm_float_width called on a non-float type"
1175 fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] unsafe {
1176 let args = vec::from_elem(llvm::LLVMCountParamTypes(fn_ty) as uint,
1178 llvm::LLVMGetParamTypes(fn_ty, vec::raw::to_ptr(args));
1183 /* Memory-managed interface to target data. */
1185 struct target_data_res {
1187 drop { llvm::LLVMDisposeTargetData(self.TD); }
1190 fn target_data_res(TD: TargetDataRef) -> target_data_res {
1196 type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
1198 fn mk_target_data(string_rep: ~str) -> target_data {
1200 str::as_c_str(string_rep, |buf| llvm::LLVMCreateTargetData(buf) );
1201 return {lltd: lltd, dtor: @target_data_res(lltd)};
1204 /* Memory-managed interface to pass managers. */
1206 struct pass_manager_res {
1208 drop { llvm::LLVMDisposePassManager(self.PM); }
1211 fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
1217 type pass_manager = {llpm: PassManagerRef, dtor: @pass_manager_res};
1219 fn mk_pass_manager() -> pass_manager {
1220 let llpm = llvm::LLVMCreatePassManager();
1221 return {llpm: llpm, dtor: @pass_manager_res(llpm)};
1224 /* Memory-managed interface to object files. */
1226 struct object_file_res {
1227 ObjectFile: ObjectFileRef,
1228 drop { llvm::LLVMDisposeObjectFile(self.ObjectFile); }
1231 fn object_file_res(ObjectFile: ObjectFileRef) -> object_file_res{
1233 ObjectFile: ObjectFile
1237 type object_file = {llof: ObjectFileRef, dtor: @object_file_res};
1239 fn mk_object_file(llmb: MemoryBufferRef) -> Option<object_file> {
1240 let llof = llvm::LLVMCreateObjectFile(llmb);
1241 if llof as int == 0 { return option::None::<object_file>; }
1242 return option::Some({llof: llof, dtor: @object_file_res(llof)});
1245 /* Memory-managed interface to section iterators. */
1247 struct section_iter_res {
1248 SI: SectionIteratorRef,
1249 drop { llvm::LLVMDisposeSectionIterator(self.SI); }
1252 fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
1258 type section_iter = {llsi: SectionIteratorRef, dtor: @section_iter_res};
1260 fn mk_section_iter(llof: ObjectFileRef) -> section_iter {
1261 let llsi = llvm::LLVMGetSections(llof);
1262 return {llsi: llsi, dtor: @section_iter_res(llsi)};
1269 // indent-tabs-mode: nil
1270 // c-basic-offset: 4
1271 // buffer-file-coding-system: utf-8-unix