1 import std::map::hashmap;
3 import 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,
37 DLLExportLinkage = 10,
38 ExternalWeakLinkage = 11,
41 LinkerPrivateLinkage = 14,
42 LinkerPrivateWeakLinkage = 15,
43 LinkerPrivateWeakDefAutoLinkage = 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
110 // enum for the LLVM TypeKind type - must stay in sync with the def of
111 // LLVMTypeKind in llvm/include/llvm-c/Core.h
131 impl TypeKind : cmp::Eq {
132 pure fn eq(&&other: TypeKind) -> bool {
133 match (self, other) {
134 (Void, Void) => true,
135 (Half, Half) => true,
136 (Float, Float) => true,
137 (Double, Double) => true,
138 (X86_FP80, X86_FP80) => true,
139 (FP128, FP128) => true,
140 (PPC_FP128, PPC_FP128) => true,
141 (Label, Label) => true,
142 (Integer, Integer) => true,
143 (Function, Function) => true,
144 (Struct, Struct) => true,
145 (Array, Array) => true,
146 (Pointer, Pointer) => true,
147 (Vector, Vector) => true,
148 (Metadata, Metadata) => true,
149 (X86_MMX, X86_MMX) => true,
153 (Double, _) => false,
154 (X86_FP80, _) => false,
156 (PPC_FP128, _) => false,
158 (Integer, _) => false,
159 (Function, _) => false,
160 (Struct, _) => false,
162 (Pointer, _) => false,
163 (Vector, _) => false,
164 (Metadata, _) => false,
165 (X86_MMX, _) => false,
184 enum AtomicOrdering {
188 // Consume = 3, // Not specified yet.
192 SequentiallyConsistent = 7
195 // FIXME: Not used right now, but will be once #2334 is fixed
196 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
202 // Opaque pointer types
203 enum Module_opaque {}
204 type ModuleRef = *Module_opaque;
205 enum Context_opaque {}
206 type ContextRef = *Context_opaque;
208 type TypeRef = *Type_opaque;
210 type ValueRef = *Value_opaque;
211 enum BasicBlock_opaque {}
212 type BasicBlockRef = *BasicBlock_opaque;
213 enum Builder_opaque {}
214 type BuilderRef = *Builder_opaque;
215 enum MemoryBuffer_opaque {}
216 type MemoryBufferRef = *MemoryBuffer_opaque;
217 enum PassManager_opaque {}
218 type PassManagerRef = *PassManager_opaque;
219 enum PassManagerBuilder_opaque {}
220 type PassManagerBuilderRef = *PassManagerBuilder_opaque;
222 type UseRef = *Use_opaque;
223 enum TargetData_opaque {}
224 type TargetDataRef = *TargetData_opaque;
225 enum ObjectFile_opaque {}
226 type ObjectFileRef = *ObjectFile_opaque;
227 enum SectionIterator_opaque {}
228 type SectionIteratorRef = *SectionIterator_opaque;
230 #[link_args = "-Lrustllvm"]
231 #[link_name = "rustllvm"]
234 /* Create and destroy contexts. */
235 fn LLVMContextCreate() -> ContextRef;
236 fn LLVMGetGlobalContext() -> ContextRef;
237 fn LLVMContextDispose(C: ContextRef);
238 fn LLVMGetMDKindIDInContext(C: ContextRef, Name: *c_char, SLen: c_uint) ->
240 fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
242 /* Create and destroy modules. */
243 fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char, C: ContextRef) ->
245 fn LLVMDisposeModule(M: ModuleRef);
247 /** Data layout. See Module::getDataLayout. */
248 fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
249 fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
251 /** Target triple. See Module::getTargetTriple. */
252 fn LLVMGetTarget(M: ModuleRef) -> *c_char;
253 fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
255 /** See Module::dump. */
256 fn LLVMDumpModule(M: ModuleRef);
258 /** See Module::setModuleInlineAsm. */
259 fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
261 /** See llvm::LLVMTypeKind::getTypeID. */
262 fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
264 /** See llvm::LLVMType::getContext. */
265 fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
267 /* Operations on integer types */
268 fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
269 fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
270 fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
271 fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
272 fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
273 fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint) -> TypeRef;
275 fn LLVMInt1Type() -> TypeRef;
276 fn LLVMInt8Type() -> TypeRef;
277 fn LLVMInt16Type() -> TypeRef;
278 fn LLVMInt32Type() -> TypeRef;
279 fn LLVMInt64Type() -> TypeRef;
280 fn LLVMIntType(NumBits: c_uint) -> TypeRef;
281 fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
283 /* Operations on real types */
284 fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
285 fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
286 fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
287 fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
288 fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
290 fn LLVMFloatType() -> TypeRef;
291 fn LLVMDoubleType() -> TypeRef;
292 fn LLVMX86FP80Type() -> TypeRef;
293 fn LLVMFP128Type() -> TypeRef;
294 fn LLVMPPCFP128Type() -> TypeRef;
296 /* Operations on function types */
297 fn LLVMFunctionType(ReturnType: TypeRef, ParamTypes: *TypeRef,
298 ParamCount: c_uint, IsVarArg: Bool) -> TypeRef;
299 fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
300 fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
301 fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
302 fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
304 /* Operations on struct types */
305 fn LLVMStructTypeInContext(C: ContextRef, ElementTypes: *TypeRef,
306 ElementCount: c_uint,
307 Packed: Bool) -> TypeRef;
308 fn LLVMStructType(ElementTypes: *TypeRef, ElementCount: c_uint,
309 Packed: Bool) -> TypeRef;
310 fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
311 fn LLVMGetStructElementTypes(StructTy: TypeRef, Dest: *TypeRef);
312 fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
314 /* Operations on array, pointer, and vector types (sequence types) */
315 fn LLVMArrayType(ElementType: TypeRef,
316 ElementCount: c_uint) -> TypeRef;
317 fn LLVMPointerType(ElementType: TypeRef,
318 AddressSpace: c_uint) -> TypeRef;
319 fn LLVMVectorType(ElementType: TypeRef,
320 ElementCount: c_uint) -> TypeRef;
322 fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
323 fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
324 fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
325 fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
327 /* Operations on other types */
328 fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
329 fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
330 fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
332 fn LLVMVoidType() -> TypeRef;
333 fn LLVMLabelType() -> TypeRef;
334 fn LLVMMetadataType() -> TypeRef;
336 /* Operations on all values */
337 fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
338 fn LLVMGetValueName(Val: ValueRef) -> *c_char;
339 fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
340 fn LLVMDumpValue(Val: ValueRef);
341 fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
342 fn LLVMHasMetadata(Val: ValueRef) -> c_int;
343 fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
344 fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
346 /* Operations on Uses */
347 fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
348 fn LLVMGetNextUse(U: UseRef) -> UseRef;
349 fn LLVMGetUser(U: UseRef) -> ValueRef;
350 fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
352 /* Operations on Users */
353 fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
354 fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
356 /* Operations on constants of any type */
357 fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
359 fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
360 /* only for int/vector */
361 fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
362 fn LLVMIsConstant(Val: ValueRef) -> Bool;
363 fn LLVMIsNull(Val: ValueRef) -> Bool;
364 fn LLVMIsUndef(Val: ValueRef) -> Bool;
365 fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
367 /* Operations on metadata */
368 fn LLVMMDStringInContext(C: ContextRef, Str: *c_char, SLen: c_uint) ->
370 fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
371 fn LLVMMDNodeInContext(C: ContextRef, Vals: *ValueRef, Count: c_uint) ->
373 fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
374 fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
377 /* Operations on scalar constants */
378 fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool) ->
380 fn LLVMConstIntOfString(IntTy: TypeRef, Text: *c_char, Radix: u8) ->
382 fn LLVMConstIntOfStringAndSize(IntTy: TypeRef, Text: *c_char,
384 Radix: u8) -> ValueRef;
385 fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
386 fn LLVMConstRealOfString(RealTy: TypeRef, Text: *c_char) -> ValueRef;
387 fn LLVMConstRealOfStringAndSize(RealTy: TypeRef, Text: *c_char,
388 SLen: c_uint) -> ValueRef;
389 fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
390 fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
393 /* Operations on composite constants */
394 fn LLVMConstStringInContext(C: ContextRef, Str: *c_char, Length: c_uint,
395 DontNullTerminate: Bool) -> ValueRef;
396 fn LLVMConstStructInContext(C: ContextRef, ConstantVals: *ValueRef,
397 Count: c_uint, Packed: Bool) -> ValueRef;
399 fn LLVMConstString(Str: *c_char, Length: c_uint,
400 DontNullTerminate: Bool) -> ValueRef;
401 fn LLVMConstArray(ElementTy: TypeRef, ConstantVals: *ValueRef,
402 Length: c_uint) -> ValueRef;
403 fn LLVMConstStruct(ConstantVals: *ValueRef,
404 Count: c_uint, Packed: Bool) -> ValueRef;
405 fn LLVMConstVector(ScalarConstantVals: *ValueRef,
406 Size: c_uint) -> ValueRef;
408 /* Constant expressions */
409 fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
410 fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
411 fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
412 fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
413 fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
414 fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
415 fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
416 fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
417 fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
419 fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
421 fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
423 fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
424 fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
426 fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
428 fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
430 fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
431 fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
433 fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
435 fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
437 fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
439 fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
441 fn LLVMConstExactSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
443 fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
445 fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
447 fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
449 fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
451 fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
452 fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
453 fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
454 fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef) -> ValueRef;
455 fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
457 fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef) ->
459 fn LLVMConstGEP(ConstantVal: ValueRef, ConstantIndices: *uint,
460 NumIndices: c_uint) -> ValueRef;
461 fn LLVMConstInBoundsGEP(ConstantVal: ValueRef, ConstantIndices: *uint,
462 NumIndices: c_uint) -> ValueRef;
463 fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
464 fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
465 fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
466 fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
467 fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
468 fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
469 fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
470 fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
471 fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
472 fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
473 fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
474 fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
475 fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
477 fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
479 fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef) ->
481 fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef) ->
483 fn LLVMConstIntCast(ConstantVal: ValueRef, ToType: TypeRef,
484 isSigned: Bool) -> ValueRef;
485 fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef) -> ValueRef;
486 fn LLVMConstSelect(ConstantCondition: ValueRef, ConstantIfTrue: ValueRef,
487 ConstantIfFalse: ValueRef) -> ValueRef;
488 fn LLVMConstExtractElement(VectorConstant: ValueRef,
489 IndexConstant: ValueRef) -> ValueRef;
490 fn LLVMConstInsertElement(VectorConstant: ValueRef,
491 ElementValueConstant: ValueRef,
492 IndexConstant: ValueRef) -> ValueRef;
493 fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
494 VectorBConstant: ValueRef,
495 MaskConstant: ValueRef) -> ValueRef;
496 fn LLVMConstExtractValue(AggConstant: ValueRef, IdxList: *uint,
497 NumIdx: c_uint) -> ValueRef;
498 fn LLVMConstInsertValue(AggConstant: ValueRef,
499 ElementValueConstant: ValueRef, IdxList: *uint,
500 NumIdx: c_uint) -> ValueRef;
501 fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
502 Constraints: *c_char, HasSideEffects: Bool,
503 IsAlignStack: Bool) -> ValueRef;
504 fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
508 /* Operations on global variables, functions, and aliases (globals) */
509 fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
510 fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
511 fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
512 fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
513 fn LLVMGetSection(Global: ValueRef) -> *c_char;
514 fn LLVMSetSection(Global: ValueRef, Section: *c_char);
515 fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
516 fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
517 fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
518 fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
521 /* Operations on global variables */
522 fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
523 fn LLVMAddGlobalInAddressSpace(M: ModuleRef, Ty: TypeRef, Name: *c_char,
524 AddressSpace: c_uint) -> ValueRef;
525 fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char) -> ValueRef;
526 fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
527 fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
528 fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
529 fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
530 fn LLVMDeleteGlobal(GlobalVar: ValueRef);
531 fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
532 fn LLVMSetInitializer(GlobalVar: ValueRef, ConstantVal: ValueRef);
533 fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
534 fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
535 fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
536 fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
538 /* Operations on aliases */
539 fn LLVMAddAlias(M: ModuleRef, Ty: TypeRef, Aliasee: ValueRef,
540 Name: *c_char) -> ValueRef;
542 /* Operations on functions */
543 fn LLVMAddFunction(M: ModuleRef, Name: *c_char, FunctionTy: TypeRef) ->
545 fn LLVMGetNamedFunction(M: ModuleRef, Name: *c_char) -> ValueRef;
546 fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
547 fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
548 fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
549 fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
550 fn LLVMDeleteFunction(Fn: ValueRef);
551 fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
552 FunctionTy: TypeRef) -> ValueRef;
553 fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
554 fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
555 fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
556 fn LLVMGetGC(Fn: ValueRef) -> *c_char;
557 fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
558 fn LLVMAddFunctionAttr(Fn: ValueRef, PA: c_ulonglong, HighPA:
560 fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
561 fn LLVMRemoveFunctionAttr(Fn: ValueRef, PA: c_ulonglong, HighPA:
564 /* Operations on parameters */
565 fn LLVMCountParams(Fn: ValueRef) -> c_uint;
566 fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
567 fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
568 fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
569 fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
570 fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
571 fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
572 fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
573 fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
574 fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
575 fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
576 fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
578 /* Operations on basic blocks */
579 fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
580 fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
581 fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
582 fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
583 fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
584 fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *ValueRef);
585 fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
586 fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
587 fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
588 fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
589 fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
591 fn LLVMAppendBasicBlockInContext(C: ContextRef, Fn: ValueRef,
592 Name: *c_char) -> BasicBlockRef;
593 fn LLVMInsertBasicBlockInContext(C: ContextRef, BB: BasicBlockRef,
594 Name: *c_char) -> BasicBlockRef;
596 fn LLVMAppendBasicBlock(Fn: ValueRef, Name: *c_char) -> BasicBlockRef;
597 fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef, Name: *c_char) ->
599 fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
601 /* Operations on instructions */
602 fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
603 fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
604 fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
605 fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
606 fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
608 /* Operations on call sites */
609 fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
610 fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
611 fn LLVMAddInstrAttribute(Instr: ValueRef, index: c_uint, IA: c_uint);
612 fn LLVMRemoveInstrAttribute(Instr: ValueRef, index: c_uint,
614 fn LLVMSetInstrParamAlignment(Instr: ValueRef, index: c_uint,
617 /* Operations on call instructions (only) */
618 fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
619 fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
621 /* Operations on phi nodes */
622 fn LLVMAddIncoming(PhiNode: ValueRef, IncomingValues: *ValueRef,
623 IncomingBlocks: *BasicBlockRef, Count: c_uint);
624 fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
625 fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint) -> ValueRef;
626 fn LLVMGetIncomingBlock(PhiNode: ValueRef,
627 Index: c_uint) -> BasicBlockRef;
629 /* Instruction builders */
630 fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
631 fn LLVMCreateBuilder() -> BuilderRef;
632 fn LLVMPositionBuilder(Builder: BuilderRef, Block: BasicBlockRef,
634 fn LLVMPositionBuilderBefore(Builder: BuilderRef, Instr: ValueRef);
635 fn LLVMPositionBuilderAtEnd(Builder: BuilderRef, Block: BasicBlockRef);
636 fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
637 fn LLVMClearInsertionPosition(Builder: BuilderRef);
638 fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
639 fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef, Instr: ValueRef,
641 fn LLVMDisposeBuilder(Builder: BuilderRef);
644 fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
645 fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
646 fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
649 fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
650 fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
651 fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
652 N: c_uint) -> ValueRef;
653 fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
654 fn LLVMBuildCondBr(B: BuilderRef, If: ValueRef, Then: BasicBlockRef,
655 Else: BasicBlockRef) -> ValueRef;
656 fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef, Else: BasicBlockRef,
657 NumCases: c_uint) -> ValueRef;
658 fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef,
659 NumDests: c_uint) -> ValueRef;
660 fn LLVMBuildInvoke(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
661 NumArgs: c_uint, Then: BasicBlockRef,
662 Catch: BasicBlockRef, Name: *c_char) -> ValueRef;
663 fn LLVMBuildLandingPad(B: BuilderRef, Ty: TypeRef, PersFn: ValueRef,
664 NumClauses: c_uint, Name: *c_char) -> ValueRef;
665 fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
666 fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
668 /* Add a case to the switch instruction */
669 fn LLVMAddCase(Switch: ValueRef, OnVal: ValueRef, Dest: BasicBlockRef);
671 /* Add a destination to the indirectbr instruction */
672 fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
674 /* Add a clause to the landing pad instruction */
675 fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
677 /* Set the cleanup on a landing pad instruction */
678 fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
681 fn LLVMBuildAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
682 Name: *c_char) -> ValueRef;
683 fn LLVMBuildNSWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
684 Name: *c_char) -> ValueRef;
685 fn LLVMBuildNUWAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
686 Name: *c_char) -> ValueRef;
687 fn LLVMBuildFAdd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
688 Name: *c_char) -> ValueRef;
689 fn LLVMBuildSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
690 Name: *c_char) -> ValueRef;
691 fn LLVMBuildNSWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
692 Name: *c_char) -> ValueRef;
693 fn LLVMBuildNUWSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
694 Name: *c_char) -> ValueRef;
695 fn LLVMBuildFSub(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
696 Name: *c_char) -> ValueRef;
697 fn LLVMBuildMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
698 Name: *c_char) -> ValueRef;
699 fn LLVMBuildNSWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
700 Name: *c_char) -> ValueRef;
701 fn LLVMBuildNUWMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
702 Name: *c_char) -> ValueRef;
703 fn LLVMBuildFMul(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
704 Name: *c_char) -> ValueRef;
705 fn LLVMBuildUDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
706 Name: *c_char) -> ValueRef;
707 fn LLVMBuildSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
708 Name: *c_char) -> ValueRef;
709 fn LLVMBuildExactSDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
710 Name: *c_char) -> ValueRef;
711 fn LLVMBuildFDiv(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
712 Name: *c_char) -> ValueRef;
713 fn LLVMBuildURem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
714 Name: *c_char) -> ValueRef;
715 fn LLVMBuildSRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
716 Name: *c_char) -> ValueRef;
717 fn LLVMBuildFRem(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
718 Name: *c_char) -> ValueRef;
719 fn LLVMBuildShl(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
720 Name: *c_char) -> ValueRef;
721 fn LLVMBuildLShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
722 Name: *c_char) -> ValueRef;
723 fn LLVMBuildAShr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
724 Name: *c_char) -> ValueRef;
725 fn LLVMBuildAnd(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
726 Name: *c_char) -> ValueRef;
727 fn LLVMBuildOr(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
728 Name: *c_char) -> ValueRef;
729 fn LLVMBuildXor(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
730 Name: *c_char) -> ValueRef;
731 fn LLVMBuildBinOp(B: BuilderRef, Op: Opcode, LHS: ValueRef, RHS: ValueRef,
732 Name: *c_char) -> ValueRef;
733 fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
734 fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
735 fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
736 fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
737 fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *c_char) -> ValueRef;
740 fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
741 fn LLVMBuildArrayMalloc(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
742 Name: *c_char) -> ValueRef;
743 fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
744 fn LLVMBuildArrayAlloca(B: BuilderRef, Ty: TypeRef, Val: ValueRef,
745 Name: *c_char) -> ValueRef;
746 fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
747 fn LLVMBuildLoad(B: BuilderRef, PointerVal: ValueRef, Name: *c_char) ->
749 fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef) ->
751 fn LLVMBuildGEP(B: BuilderRef, Pointer: ValueRef, Indices: *ValueRef,
752 NumIndices: c_uint, Name: *c_char) -> ValueRef;
753 fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
754 Indices: *ValueRef, NumIndices: c_uint,
757 fn LLVMBuildStructGEP(B: BuilderRef, Pointer: ValueRef, Idx: c_uint,
758 Name: *c_char) -> ValueRef;
759 fn LLVMBuildGlobalString(B: BuilderRef, Str: *c_char, Name: *c_char) ->
761 fn LLVMBuildGlobalStringPtr(B: BuilderRef, Str: *c_char, Name: *c_char) ->
765 fn LLVMBuildTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
766 Name: *c_char) -> ValueRef;
767 fn LLVMBuildZExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
768 Name: *c_char) -> ValueRef;
769 fn LLVMBuildSExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
770 Name: *c_char) -> ValueRef;
771 fn LLVMBuildFPToUI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
772 Name: *c_char) -> ValueRef;
773 fn LLVMBuildFPToSI(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
774 Name: *c_char) -> ValueRef;
775 fn LLVMBuildUIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
776 Name: *c_char) -> ValueRef;
777 fn LLVMBuildSIToFP(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
778 Name: *c_char) -> ValueRef;
779 fn LLVMBuildFPTrunc(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
780 Name: *c_char) -> ValueRef;
781 fn LLVMBuildFPExt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
782 Name: *c_char) -> ValueRef;
783 fn LLVMBuildPtrToInt(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
784 Name: *c_char) -> ValueRef;
785 fn LLVMBuildIntToPtr(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
786 Name: *c_char) -> ValueRef;
787 fn LLVMBuildBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
788 Name: *c_char) -> ValueRef;
789 fn LLVMBuildZExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
790 Name: *c_char) -> ValueRef;
791 fn LLVMBuildSExtOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
792 Name: *c_char) -> ValueRef;
793 fn LLVMBuildTruncOrBitCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
794 Name: *c_char) -> ValueRef;
795 fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
796 DestTy: TypeRef, Name: *c_char) -> ValueRef;
797 fn LLVMBuildPointerCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
798 Name: *c_char) -> ValueRef;
799 fn LLVMBuildIntCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
800 Name: *c_char) -> ValueRef;
801 fn LLVMBuildFPCast(B: BuilderRef, Val: ValueRef, DestTy: TypeRef,
802 Name: *c_char) -> ValueRef;
805 fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
806 RHS: ValueRef, Name: *c_char) -> ValueRef;
807 fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
808 RHS: ValueRef, Name: *c_char) -> ValueRef;
810 /* Miscellaneous instructions */
811 fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *c_char) -> ValueRef;
812 fn LLVMBuildCall(B: BuilderRef, Fn: ValueRef, Args: *ValueRef,
813 NumArgs: c_uint, Name: *c_char) -> ValueRef;
814 fn LLVMBuildSelect(B: BuilderRef, If: ValueRef, Then: ValueRef,
815 Else: ValueRef, Name: *c_char) -> ValueRef;
816 fn LLVMBuildVAArg(B: BuilderRef, list: ValueRef, Ty: TypeRef,
819 fn LLVMBuildExtractElement(B: BuilderRef, VecVal: ValueRef,
820 Index: ValueRef, Name: *c_char) -> ValueRef;
821 fn LLVMBuildInsertElement(B: BuilderRef, VecVal: ValueRef,
822 EltVal: ValueRef, Index: ValueRef,
825 fn LLVMBuildShuffleVector(B: BuilderRef, V1: ValueRef, V2: ValueRef,
826 Mask: ValueRef, Name: *c_char) -> ValueRef;
827 fn LLVMBuildExtractValue(B: BuilderRef, AggVal: ValueRef, Index: c_uint,
828 Name: *c_char) -> ValueRef;
829 fn LLVMBuildInsertValue(B: BuilderRef, AggVal: ValueRef, EltVal: ValueRef,
830 Index: c_uint, Name: *c_char) -> ValueRef;
832 fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef,
833 Name: *c_char) -> ValueRef;
834 fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *c_char) ->
836 fn LLVMBuildPtrDiff(B: BuilderRef, LHS: ValueRef, RHS: ValueRef,
837 Name: *c_char) -> ValueRef;
839 /* Atomic Operations */
840 fn LLVMBuildAtomicRMW(B: BuilderRef, ++Op: AtomicBinOp,
841 LHS: ValueRef, RHS: ValueRef,
842 ++Order: AtomicOrdering) -> ValueRef;
844 /* Selected entries from the downcasts. */
845 fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
847 /** Writes a module to the specified path. Returns 0 on success. */
848 fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *c_char) -> c_int;
850 /** Creates target data from a target layout string. */
851 fn LLVMCreateTargetData(StringRep: *c_char) -> TargetDataRef;
852 /** Adds the target data to the given pass manager. The pass manager
853 references the target data only weakly. */
854 fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
855 /** Number of bytes clobbered when doing a Store to *T. */
856 fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
858 /** Number of bytes clobbered when doing a Store to *T. */
859 fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
861 /** Distance between successive elements in an array of T.
862 Includes ABI padding. */
863 fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_uint;
865 /** Returns the preferred alignment of a type. */
866 fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
867 Ty: TypeRef) -> c_uint;
868 /** Returns the minimum alignment of a type. */
869 fn LLVMABIAlignmentOfType(TD: TargetDataRef,
870 Ty: TypeRef) -> c_uint;
871 /** Returns the minimum alignment of a type when part of a call frame. */
872 fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
873 Ty: TypeRef) -> c_uint;
875 /** Disposes target data. */
876 fn LLVMDisposeTargetData(TD: TargetDataRef);
878 /** Creates a pass manager. */
879 fn LLVMCreatePassManager() -> PassManagerRef;
880 /** Disposes a pass manager. */
881 fn LLVMDisposePassManager(PM: PassManagerRef);
882 /** Runs a pass manager on a module. */
883 fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
885 /** Adds a verification pass. */
886 fn LLVMAddVerifierPass(PM: PassManagerRef);
888 fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
889 fn LLVMAddIPSCCPPass(PM: PassManagerRef);
890 fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
891 fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
892 fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
893 fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
894 fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
895 fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
896 fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
897 fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
898 fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
899 fn LLVMAddReassociatePass(PM: PassManagerRef);
900 fn LLVMAddLoopRotatePass(PM: PassManagerRef);
901 fn LLVMAddLICMPass(PM: PassManagerRef);
902 fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
903 fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
904 fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
905 fn LLVMAddGVNPass(PM: PassManagerRef);
906 fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
907 fn LLVMAddSCCPPass(PM: PassManagerRef);
908 fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
909 fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
910 fn LLVMAddConstantMergePass(PM: PassManagerRef);
911 fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
912 fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
913 fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
914 fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
915 fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
916 fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
917 fn LLVMAddPruneEHPass(PM: PassManagerRef);
918 fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
919 fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
920 fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
921 fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
922 fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
924 fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
925 fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
926 fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
927 OptimizationLevel: c_uint);
928 fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
930 fn LLVMPassManagerBuilderSetDisableUnitAtATime(PMB: PassManagerBuilderRef,
932 fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef,
934 fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
935 (PMB: PassManagerBuilderRef, Value: Bool);
936 fn LLVMPassManagerBuilderUseInlinerWithThreshold
937 (PMB: PassManagerBuilderRef, threshold: c_uint);
938 fn LLVMPassManagerBuilderPopulateModulePassManager
939 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
941 fn LLVMPassManagerBuilderPopulateFunctionPassManager
942 (PMB: PassManagerBuilderRef, PM: PassManagerRef);
944 /** Destroys a memory buffer. */
945 fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
948 /* Stuff that's in rustllvm/ because it's not upstream yet. */
950 /** Opens an object file. */
951 fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
952 /** Closes an object file. */
953 fn LLVMDisposeObjectFile(ObjectFile: ObjectFileRef);
955 /** Enumerates the sections in an object file. */
956 fn LLVMGetSections(ObjectFile: ObjectFileRef) -> SectionIteratorRef;
957 /** Destroys a section iterator. */
958 fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
959 /** Returns true if the section iterator is at the end of the section
961 fn LLVMIsSectionIteratorAtEnd(ObjectFile: ObjectFileRef,
962 SI: SectionIteratorRef) -> Bool;
963 /** Moves the section iterator to point to the next section. */
964 fn LLVMMoveToNextSection(SI: SectionIteratorRef);
965 /** Returns the current section name. */
966 fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
967 /** Returns the current section size. */
968 fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
969 /** Returns the current section contents as a string buffer. */
970 fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *c_char;
972 /** Reads the given file and returns it as a memory buffer. Use
973 LLVMDisposeMemoryBuffer() to get rid of it. */
974 fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char) ->
977 fn LLVMRustWriteOutputFile(PM: PassManagerRef, M: ModuleRef,
979 // FIXME: When #2334 is fixed, change
980 // c_uint to FileType
981 Output: *c_char, FileType: c_uint,
983 EnableSegmentedStacks: bool) -> bool;
985 /** Returns a string describing the last error caused by an LLVMRust*
987 fn LLVMRustGetLastError() -> *c_char;
989 /** Parses the bitcode in the given memory buffer. */
990 fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;
992 /** Parses LLVM asm in the given file */
993 fn LLVMRustParseAssemblyFile(Filename: *c_char) -> ModuleRef;
995 fn LLVMRustAddPrintModulePass(PM: PassManagerRef, M: ModuleRef,
998 /** Turn on LLVM pass-timing. */
999 fn LLVMRustEnableTimePasses();
1001 /** Print the pass timings since static dtors aren't picking them up. */
1002 fn LLVMRustPrintPassTimings();
1004 fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char) -> TypeRef;
1006 fn LLVMStructSetBody(StructTy: TypeRef, ElementTypes: *TypeRef,
1007 ElementCount: c_uint, Packed: Bool);
1009 fn LLVMConstNamedStruct(S: TypeRef, ConstantVals: *ValueRef,
1010 Count: c_uint) -> ValueRef;
1012 /** Enables LLVM debug output. */
1013 fn LLVMSetDebug(Enabled: c_int);
1016 fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
1017 llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
1019 fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
1020 llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
1022 fn SetLinkage(Global: ValueRef, Link: Linkage) {
1023 llvm::LLVMSetLinkage(Global, Link as c_uint);
1026 /* Memory-managed object interface to type handles. */
1028 type type_names = @{type_names: std::map::hashmap<TypeRef, ~str>,
1029 named_types: std::map::hashmap<~str, TypeRef>};
1031 fn associate_type(tn: type_names, s: ~str, t: TypeRef) {
1032 assert tn.type_names.insert(t, s);
1033 assert tn.named_types.insert(s, t);
1036 fn type_has_name(tn: type_names, t: TypeRef) -> Option<~str> {
1037 return tn.type_names.find(t);
1040 fn name_has_type(tn: type_names, s: ~str) -> Option<TypeRef> {
1041 return tn.named_types.find(s);
1044 fn mk_type_names() -> type_names {
1045 pure fn hash(t: &TypeRef) -> uint { *t as uint }
1046 pure fn eq(a: &TypeRef, b: &TypeRef) -> bool { *a == *b }
1047 @{type_names: std::map::hashmap(hash, eq),
1048 named_types: std::map::str_hash()}
1051 fn type_to_str(names: type_names, ty: TypeRef) -> ~str {
1052 return type_to_str_inner(names, ~[], ty);
1055 fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) ->
1057 match type_has_name(names, ty) {
1058 option::Some(n) => return n,
1062 let outer = vec::append_one(outer0, ty);
1064 let kind = llvm::LLVMGetTypeKind(ty);
1066 fn tys_str(names: type_names, outer: ~[TypeRef],
1067 tys: ~[TypeRef]) -> ~str {
1068 let mut s: ~str = ~"";
1069 let mut first: bool = true;
1071 if first { first = false; } else { s += ~", "; }
1072 s += type_to_str_inner(names, outer, t);
1078 Void => return ~"Void",
1079 Half => return ~"Half",
1080 Float => return ~"Float",
1081 Double => return ~"Double",
1082 X86_FP80 => return ~"X86_FP80",
1083 FP128 => return ~"FP128",
1084 PPC_FP128 => return ~"PPC_FP128",
1085 Label => return ~"Label",
1087 return ~"i" + int::str(llvm::LLVMGetIntTypeWidth(ty) as int);
1091 let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
1092 let n_args = llvm::LLVMCountParamTypes(ty) as uint;
1093 let args = vec::from_elem(n_args, 0 as TypeRef);
1095 llvm::LLVMGetParamTypes(ty, vec::unsafe::to_ptr(args));
1097 s += tys_str(names, outer, args);
1099 s += type_to_str_inner(names, outer, out_ty);
1103 let mut s: ~str = ~"{";
1104 let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
1105 let elts = vec::from_elem(n_elts, 0 as TypeRef);
1107 llvm::LLVMGetStructElementTypes(ty, vec::unsafe::to_ptr(elts));
1109 s += tys_str(names, outer, elts);
1114 let el_ty = llvm::LLVMGetElementType(ty);
1115 return ~"[" + type_to_str_inner(names, outer, el_ty) + ~" x " +
1116 uint::str(llvm::LLVMGetArrayLength(ty) as uint) + ~"]";
1119 let mut i: uint = 0u;
1120 for outer0.each |tout| {
1122 if tout as int == ty as int {
1123 let n: uint = vec::len::<TypeRef>(outer0) - i;
1124 return ~"*\\" + int::str(n as int);
1128 let addrspace = llvm::LLVMGetPointerAddressSpace(ty) as uint;
1129 if addrspace == 0u {
1132 fmt!("addrspace(%u)", addrspace)
1135 return addrstr + ~"*" +
1136 type_to_str_inner(names, outer, llvm::LLVMGetElementType(ty));
1138 Vector => return ~"Vector",
1139 Metadata => return ~"Metadata",
1140 X86_MMX => return ~"X86_MMAX"
1144 fn float_width(llt: TypeRef) -> uint {
1145 return match llvm::LLVMGetTypeKind(llt) as int {
1150 _ => fail ~"llvm_float_width called on a non-float type"
1154 fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] unsafe {
1155 let args = vec::from_elem(llvm::LLVMCountParamTypes(fn_ty) as uint,
1157 llvm::LLVMGetParamTypes(fn_ty, vec::unsafe::to_ptr(args));
1162 /* Memory-managed interface to target data. */
1164 struct target_data_res {
1165 let TD: TargetDataRef;
1166 new(TD: TargetDataRef) { self.TD = TD; }
1167 drop { llvm::LLVMDisposeTargetData(self.TD); }
1170 type target_data = {lltd: TargetDataRef, dtor: @target_data_res};
1172 fn mk_target_data(string_rep: ~str) -> target_data {
1174 str::as_c_str(string_rep, |buf| llvm::LLVMCreateTargetData(buf) );
1175 return {lltd: lltd, dtor: @target_data_res(lltd)};
1178 /* Memory-managed interface to pass managers. */
1180 struct pass_manager_res {
1181 let PM: PassManagerRef;
1182 new(PM: PassManagerRef) { self.PM = PM; }
1183 drop { llvm::LLVMDisposePassManager(self.PM); }
1186 type pass_manager = {llpm: PassManagerRef, dtor: @pass_manager_res};
1188 fn mk_pass_manager() -> pass_manager {
1189 let llpm = llvm::LLVMCreatePassManager();
1190 return {llpm: llpm, dtor: @pass_manager_res(llpm)};
1193 /* Memory-managed interface to object files. */
1195 struct object_file_res {
1196 let ObjectFile: ObjectFileRef;
1197 new(ObjectFile: ObjectFileRef) { self.ObjectFile = ObjectFile; }
1198 drop { llvm::LLVMDisposeObjectFile(self.ObjectFile); }
1201 type object_file = {llof: ObjectFileRef, dtor: @object_file_res};
1203 fn mk_object_file(llmb: MemoryBufferRef) -> Option<object_file> {
1204 let llof = llvm::LLVMCreateObjectFile(llmb);
1205 if llof as int == 0 { return option::None::<object_file>; }
1206 return option::Some({llof: llof, dtor: @object_file_res(llof)});
1209 /* Memory-managed interface to section iterators. */
1211 struct section_iter_res {
1212 let SI: SectionIteratorRef;
1213 new(SI: SectionIteratorRef) { self.SI = SI; }
1214 drop { llvm::LLVMDisposeSectionIterator(self.SI); }
1217 type section_iter = {llsi: SectionIteratorRef, dtor: @section_iter_res};
1219 fn mk_section_iter(llof: ObjectFileRef) -> section_iter {
1220 let llsi = llvm::LLVMGetSections(llof);
1221 return {llsi: llsi, dtor: @section_iter_res(llsi)};
1228 // indent-tabs-mode: nil
1229 // c-basic-offset: 4
1230 // buffer-file-coding-system: utf-8-unix