]> git.lizzy.rs Git - rust.git/blob - src/librustc/lib/llvm.rs
Wrap llvm::InlineAsm::AsmDialect
[rust.git] / src / librustc / lib / llvm.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use core::prelude::*;
12
13 use core::libc::{c_char, c_int, c_uint, c_longlong, c_ulonglong};
14 use core::option;
15 use core::ptr;
16 use core::str;
17 use core::vec;
18 use std::oldmap::HashMap;
19
20 pub type Opcode = u32;
21 pub type Bool = c_uint;
22
23 pub const True: Bool = 1 as Bool;
24 pub const False: Bool = 0 as Bool;
25
26 // Consts for the LLVM CallConv type, pre-cast to uint.
27
28 pub enum CallConv {
29     CCallConv = 0,
30     FastCallConv = 8,
31     ColdCallConv = 9,
32     X86StdcallCallConv = 64,
33     X86FastcallCallConv = 65,
34 }
35
36 pub enum Visibility {
37     LLVMDefaultVisibility = 0,
38     HiddenVisibility = 1,
39     ProtectedVisibility = 2,
40 }
41
42 pub enum Linkage {
43     ExternalLinkage = 0,
44     AvailableExternallyLinkage = 1,
45     LinkOnceAnyLinkage = 2,
46     LinkOnceODRLinkage = 3,
47     LinkOnceODRAutoHideLinkage = 4,
48     WeakAnyLinkage = 5,
49     WeakODRLinkage = 6,
50     AppendingLinkage = 7,
51     InternalLinkage = 8,
52     PrivateLinkage = 9,
53     DLLImportLinkage = 10,
54     DLLExportLinkage = 11,
55     ExternalWeakLinkage = 12,
56     GhostLinkage = 13,
57     CommonLinkage = 14,
58     LinkerPrivateLinkage = 15,
59     LinkerPrivateWeakLinkage = 16,
60 }
61
62 pub enum Attribute {
63     ZExtAttribute = 1,
64     SExtAttribute = 2,
65     NoReturnAttribute = 4,
66     InRegAttribute = 8,
67     StructRetAttribute = 16,
68     NoUnwindAttribute = 32,
69     NoAliasAttribute = 64,
70     ByValAttribute = 128,
71     NestAttribute = 256,
72     ReadNoneAttribute = 512,
73     ReadOnlyAttribute = 1024,
74     NoInlineAttribute = 2048,
75     AlwaysInlineAttribute = 4096,
76     OptimizeForSizeAttribute = 8192,
77     StackProtectAttribute = 16384,
78     StackProtectReqAttribute = 32768,
79     // 31 << 16
80     AlignmentAttribute = 2031616,
81     NoCaptureAttribute = 2097152,
82     NoRedZoneAttribute = 4194304,
83     NoImplicitFloatAttribute = 8388608,
84     NakedAttribute = 16777216,
85     InlineHintAttribute = 33554432,
86     // 7 << 26
87     StackAttribute = 469762048,
88     ReturnsTwiceAttribute = 536870912,
89     // 1 << 30
90     UWTableAttribute = 1073741824,
91     NonLazyBindAttribute = 2147483648,
92 }
93
94 // enum for the LLVM IntPredicate type
95 pub enum IntPredicate {
96     IntEQ = 32,
97     IntNE = 33,
98     IntUGT = 34,
99     IntUGE = 35,
100     IntULT = 36,
101     IntULE = 37,
102     IntSGT = 38,
103     IntSGE = 39,
104     IntSLT = 40,
105     IntSLE = 41,
106 }
107
108 // enum for the LLVM RealPredicate type
109 pub enum RealPredicate {
110     RealPredicateFalse = 0,
111     RealOEQ = 1,
112     RealOGT = 2,
113     RealOGE = 3,
114     RealOLT = 4,
115     RealOLE = 5,
116     RealONE = 6,
117     RealORD = 7,
118     RealUNO = 8,
119     RealUEQ = 9,
120     RealUGT = 10,
121     RealUGE = 11,
122     RealULT = 12,
123     RealULE = 13,
124     RealUNE = 14,
125     RealPredicateTrue = 15,
126 }
127
128 // enum for the LLVM TypeKind type - must stay in sync with the def of
129 // LLVMTypeKind in llvm/include/llvm-c/Core.h
130 #[deriving_eq]
131 pub enum TypeKind {
132     Void      = 0,
133     Half      = 1,
134     Float     = 2,
135     Double    = 3,
136     X86_FP80  = 4,
137     FP128     = 5,
138     PPC_FP128 = 6,
139     Label     = 7,
140     Integer   = 8,
141     Function  = 9,
142     Struct    = 10,
143     Array     = 11,
144     Pointer   = 12,
145     Vector    = 13,
146     Metadata  = 14,
147     X86_MMX   = 15
148 }
149
150 pub enum AtomicBinOp {
151     Xchg = 0,
152     Add  = 1,
153     Sub  = 2,
154     And  = 3,
155     Nand = 4,
156     Or   = 5,
157     Xor  = 6,
158     Max  = 7,
159     Min  = 8,
160     UMax = 9,
161     UMin = 10,
162 }
163
164 pub enum AtomicOrdering {
165     NotAtomic = 0,
166     Unordered = 1,
167     Monotonic = 2,
168     // Consume = 3,  // Not specified yet.
169     Acquire = 4,
170     Release = 5,
171     AcquireRelease = 6,
172     SequentiallyConsistent = 7
173 }
174
175 // FIXME: Not used right now, but will be once #2334 is fixed
176 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
177 pub enum FileType {
178     AssemblyFile = 0,
179     ObjectFile = 1
180 }
181
182 pub enum Metadata {
183     MD_dbg = 0,
184     MD_tbaa = 1,
185     MD_prof = 2,
186     MD_fpmath = 3,
187     MD_range = 4,
188     MD_tbaa_struct = 5
189 }
190
191 // Inline Asm Dialect
192 pub enum AsmDialect {
193     AD_ATT   = 0,
194     AD_Intel = 1
195 }
196
197 // Opaque pointer types
198 pub enum Module_opaque {}
199 pub type ModuleRef = *Module_opaque;
200 pub enum Context_opaque {}
201 pub type ContextRef = *Context_opaque;
202 pub enum Type_opaque {}
203 pub type TypeRef = *Type_opaque;
204 pub enum Value_opaque {}
205 pub type ValueRef = *Value_opaque;
206 pub enum BasicBlock_opaque {}
207 pub type BasicBlockRef = *BasicBlock_opaque;
208 pub enum Builder_opaque {}
209 pub type BuilderRef = *Builder_opaque;
210 pub enum MemoryBuffer_opaque {}
211 pub type MemoryBufferRef = *MemoryBuffer_opaque;
212 pub enum PassManager_opaque {}
213 pub type PassManagerRef = *PassManager_opaque;
214 pub enum PassManagerBuilder_opaque {}
215 pub type PassManagerBuilderRef = *PassManagerBuilder_opaque;
216 pub enum Use_opaque {}
217 pub type UseRef = *Use_opaque;
218 pub enum TargetData_opaque {}
219 pub type TargetDataRef = *TargetData_opaque;
220 pub enum ObjectFile_opaque {}
221 pub type ObjectFileRef = *ObjectFile_opaque;
222 pub enum SectionIterator_opaque {}
223 pub type SectionIteratorRef = *SectionIterator_opaque;
224
225 pub mod llvm {
226     use super::{AsmDialect, AtomicBinOp, AtomicOrdering, BasicBlockRef};
227     use super::{Bool, BuilderRef, ContextRef, MemoryBufferRef, ModuleRef};
228     use super::{ObjectFileRef, Opcode, PassManagerRef, PassManagerBuilderRef};
229     use super::{SectionIteratorRef, TargetDataRef, TypeKind, TypeRef, UseRef};
230     use super::{ValueRef};
231
232     use core::libc::{c_char, c_int, c_longlong, c_uint, c_ulonglong};
233
234     #[link_args = "-Lrustllvm -lrustllvm"]
235     #[link_name = "rustllvm"]
236     #[abi = "cdecl"]
237     pub extern {
238         /* Create and destroy contexts. */
239         pub unsafe fn LLVMContextCreate() -> ContextRef;
240         pub unsafe fn LLVMGetGlobalContext() -> ContextRef;
241         pub unsafe fn LLVMContextDispose(C: ContextRef);
242         pub unsafe fn LLVMGetMDKindIDInContext(C: ContextRef,
243                                            Name: *c_char,
244                                            SLen: c_uint)
245                                         -> c_uint;
246         pub unsafe fn LLVMGetMDKindID(Name: *c_char, SLen: c_uint) -> c_uint;
247
248         /* Create and destroy modules. */
249         pub unsafe fn LLVMModuleCreateWithNameInContext(ModuleID: *c_char,
250                                                     C: ContextRef)
251                                                  -> ModuleRef;
252         pub unsafe fn LLVMDisposeModule(M: ModuleRef);
253
254         /** Data layout. See Module::getDataLayout. */
255         pub unsafe fn LLVMGetDataLayout(M: ModuleRef) -> *c_char;
256         pub unsafe fn LLVMSetDataLayout(M: ModuleRef, Triple: *c_char);
257
258         /** Target triple. See Module::getTargetTriple. */
259         pub unsafe fn LLVMGetTarget(M: ModuleRef) -> *c_char;
260         pub unsafe fn LLVMSetTarget(M: ModuleRef, Triple: *c_char);
261
262         /** See Module::dump. */
263         pub unsafe fn LLVMDumpModule(M: ModuleRef);
264
265         /** See Module::setModuleInlineAsm. */
266         pub unsafe fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *c_char);
267
268         /** See llvm::LLVMTypeKind::getTypeID. */
269         pub unsafe fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
270
271         /** See llvm::LLVMType::getContext. */
272         pub unsafe fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
273
274         /* Operations on integer types */
275         pub unsafe fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
276         pub unsafe fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
277         pub unsafe fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
278         pub unsafe fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
279         pub unsafe fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
280         pub unsafe fn LLVMIntTypeInContext(C: ContextRef,
281                                            NumBits: c_uint) -> TypeRef;
282
283         pub unsafe fn LLVMInt1Type() -> TypeRef;
284         pub unsafe fn LLVMInt8Type() -> TypeRef;
285         pub unsafe fn LLVMInt16Type() -> TypeRef;
286         pub unsafe fn LLVMInt32Type() -> TypeRef;
287         pub unsafe fn LLVMInt64Type() -> TypeRef;
288         pub unsafe fn LLVMIntType(NumBits: c_uint) -> TypeRef;
289         pub unsafe fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
290
291         /* Operations on real types */
292         pub unsafe fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
293         pub unsafe fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
294         pub unsafe fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
295         pub unsafe fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
296         pub unsafe fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
297
298         pub unsafe fn LLVMFloatType() -> TypeRef;
299         pub unsafe fn LLVMDoubleType() -> TypeRef;
300         pub unsafe fn LLVMX86FP80Type() -> TypeRef;
301         pub unsafe fn LLVMFP128Type() -> TypeRef;
302         pub unsafe fn LLVMPPCFP128Type() -> TypeRef;
303
304         /* Operations on function types */
305         pub unsafe fn LLVMFunctionType(ReturnType: TypeRef,
306                                        ParamTypes: *TypeRef,
307                                        ParamCount: c_uint,
308                                        IsVarArg: Bool)
309                                     -> TypeRef;
310         pub unsafe fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
311         pub unsafe fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
312         pub unsafe fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
313         pub unsafe fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *TypeRef);
314
315         /* Operations on struct types */
316         pub unsafe fn LLVMStructTypeInContext(C: ContextRef,
317                                               ElementTypes: *TypeRef,
318                                               ElementCount: c_uint,
319                                               Packed: Bool) -> TypeRef;
320         pub unsafe fn LLVMStructType(ElementTypes: *TypeRef,
321                                      ElementCount: c_uint,
322                                      Packed: Bool)
323                                   -> TypeRef;
324         pub unsafe fn LLVMCountStructElementTypes(StructTy: TypeRef)
325                                                -> c_uint;
326         pub unsafe fn LLVMGetStructElementTypes(StructTy: TypeRef,
327                                             Dest: *mut TypeRef);
328         pub unsafe fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
329
330         /* Operations on array, pointer, and vector types (sequence types) */
331         pub unsafe fn LLVMArrayType(ElementType: TypeRef,
332                          ElementCount: c_uint) -> TypeRef;
333         pub unsafe fn LLVMPointerType(ElementType: TypeRef,
334                            AddressSpace: c_uint) -> TypeRef;
335         pub unsafe fn LLVMVectorType(ElementType: TypeRef,
336                           ElementCount: c_uint) -> TypeRef;
337
338         pub unsafe fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
339         pub unsafe fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
340         pub unsafe fn LLVMGetPointerAddressSpace(PointerTy: TypeRef)
341                                               -> c_uint;
342         pub unsafe fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
343
344         /* Operations on other types */
345         pub unsafe fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
346         pub unsafe fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
347         pub unsafe fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
348
349         pub unsafe fn LLVMVoidType() -> TypeRef;
350         pub unsafe fn LLVMLabelType() -> TypeRef;
351         pub unsafe fn LLVMMetadataType() -> TypeRef;
352
353         /* Operations on all values */
354         pub unsafe fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
355         pub unsafe fn LLVMGetValueName(Val: ValueRef) -> *c_char;
356         pub unsafe fn LLVMSetValueName(Val: ValueRef, Name: *c_char);
357         pub unsafe fn LLVMDumpValue(Val: ValueRef);
358         pub unsafe fn LLVMReplaceAllUsesWith(OldVal: ValueRef,
359                                              NewVal: ValueRef);
360         pub unsafe fn LLVMHasMetadata(Val: ValueRef) -> c_int;
361         pub unsafe fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint)
362                                    -> ValueRef;
363         pub unsafe fn LLVMSetMetadata(Val: ValueRef,
364                                       KindID: c_uint,
365                                       Node: ValueRef);
366
367         /* Operations on Uses */
368         pub unsafe fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
369         pub unsafe fn LLVMGetNextUse(U: UseRef) -> UseRef;
370         pub unsafe fn LLVMGetUser(U: UseRef) -> ValueRef;
371         pub unsafe fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
372
373         /* Operations on Users */
374         pub unsafe fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
375         pub unsafe fn LLVMGetOperand(Val: ValueRef, Index: c_uint)
376                                   -> ValueRef;
377         pub unsafe fn LLVMSetOperand(Val: ValueRef,
378                                      Index: c_uint,
379                                      Op: ValueRef);
380
381         /* Operations on constants of any type */
382         pub unsafe fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
383         /* all zeroes */
384         pub unsafe fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
385         /* only for int/vector */
386         pub unsafe fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
387         pub unsafe fn LLVMIsConstant(Val: ValueRef) -> Bool;
388         pub unsafe fn LLVMIsNull(Val: ValueRef) -> Bool;
389         pub unsafe fn LLVMIsUndef(Val: ValueRef) -> Bool;
390         pub unsafe fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
391
392         /* Operations on metadata */
393         pub unsafe fn LLVMMDStringInContext(C: ContextRef,
394                                         Str: *c_char,
395                                         SLen: c_uint)
396                                      -> ValueRef;
397         pub unsafe fn LLVMMDString(Str: *c_char, SLen: c_uint) -> ValueRef;
398         pub unsafe fn LLVMMDNodeInContext(C: ContextRef,
399                                       Vals: *ValueRef,
400                                       Count: c_uint)
401                                    -> ValueRef;
402         pub unsafe fn LLVMMDNode(Vals: *ValueRef, Count: c_uint) -> ValueRef;
403         pub unsafe fn LLVMAddNamedMetadataOperand(M: ModuleRef, Str: *c_char,
404                                        Val: ValueRef);
405
406         /* Operations on scalar constants */
407         pub unsafe fn LLVMConstInt(IntTy: TypeRef,
408                                N: c_ulonglong,
409                                SignExtend: Bool)
410                             -> ValueRef;
411         pub unsafe fn LLVMConstIntOfString(IntTy: TypeRef,
412                                        Text: *c_char,
413                                        Radix: u8)
414                                     -> ValueRef;
415         pub unsafe fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
416                                                   Text: *c_char,
417                                                   SLen: c_uint,
418                                                   Radix: u8)
419                                                -> ValueRef;
420         pub unsafe fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
421         pub unsafe fn LLVMConstRealOfString(RealTy: TypeRef,
422                                         Text: *c_char)
423                                      -> ValueRef;
424         pub unsafe fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
425                                                    Text: *c_char,
426                                                    SLen: c_uint)
427                                                 -> ValueRef;
428         pub unsafe fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef)
429                                             -> c_ulonglong;
430         pub unsafe fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef)
431                                             -> c_longlong;
432
433
434         /* Operations on composite constants */
435         pub unsafe fn LLVMConstStringInContext(C: ContextRef,
436                                            Str: *c_char,
437                                            Length: c_uint,
438                                            DontNullTerminate: Bool)
439                                         -> ValueRef;
440         pub unsafe fn LLVMConstStructInContext(C: ContextRef,
441                                                ConstantVals: *ValueRef,
442                                                Count: c_uint,
443                                                Packed: Bool) -> ValueRef;
444
445         pub unsafe fn LLVMConstString(Str: *c_char,
446                                       Length: c_uint,
447                                       DontNullTerminate: Bool)
448                                    -> ValueRef;
449         pub unsafe fn LLVMConstArray(ElementTy: TypeRef,
450                                      ConstantVals: *ValueRef,
451                                      Length: c_uint)
452                                   -> ValueRef;
453         pub unsafe fn LLVMConstStruct(ConstantVals: *ValueRef,
454                                       Count: c_uint,
455                                       Packed: Bool) -> ValueRef;
456         pub unsafe fn LLVMConstVector(ScalarConstantVals: *ValueRef,
457                                       Size: c_uint) -> ValueRef;
458
459         /* Constant expressions */
460         pub unsafe fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
461         pub unsafe fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
462         pub unsafe fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
463         pub unsafe fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
464         pub unsafe fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
465         pub unsafe fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
466         pub unsafe fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
467         pub unsafe fn LLVMConstAdd(LHSConstant: ValueRef,
468                                    RHSConstant: ValueRef)
469                                 -> ValueRef;
470         pub unsafe fn LLVMConstNSWAdd(LHSConstant: ValueRef,
471                                   RHSConstant: ValueRef)
472                                -> ValueRef;
473         pub unsafe fn LLVMConstNUWAdd(LHSConstant: ValueRef,
474                                   RHSConstant: ValueRef)
475                                -> ValueRef;
476         pub unsafe fn LLVMConstFAdd(LHSConstant: ValueRef,
477                                 RHSConstant: ValueRef)
478                              -> ValueRef;
479         pub unsafe fn LLVMConstSub(LHSConstant: ValueRef,
480                                    RHSConstant: ValueRef)
481                                 -> ValueRef;
482         pub unsafe fn LLVMConstNSWSub(LHSConstant: ValueRef,
483                                       RHSConstant: ValueRef)
484                                    -> ValueRef;
485         pub unsafe fn LLVMConstNUWSub(LHSConstant: ValueRef,
486                                       RHSConstant: ValueRef)
487                                    -> ValueRef;
488         pub unsafe fn LLVMConstFSub(LHSConstant: ValueRef,
489                                     RHSConstant: ValueRef)
490                                  -> ValueRef;
491         pub unsafe fn LLVMConstMul(LHSConstant: ValueRef,
492                                RHSConstant: ValueRef)
493                             -> ValueRef;
494         pub unsafe fn LLVMConstNSWMul(LHSConstant: ValueRef,
495                                   RHSConstant: ValueRef)
496                                -> ValueRef;
497         pub unsafe fn LLVMConstNUWMul(LHSConstant: ValueRef,
498                                   RHSConstant: ValueRef)
499                                -> ValueRef;
500         pub unsafe fn LLVMConstFMul(LHSConstant: ValueRef,
501                                 RHSConstant: ValueRef)
502                              -> ValueRef;
503         pub unsafe fn LLVMConstUDiv(LHSConstant: ValueRef,
504                                 RHSConstant: ValueRef)
505                              -> ValueRef;
506         pub unsafe fn LLVMConstSDiv(LHSConstant: ValueRef,
507                                 RHSConstant: ValueRef)
508                              -> ValueRef;
509         pub unsafe fn LLVMConstExactSDiv(LHSConstant: ValueRef,
510                                      RHSConstant: ValueRef)
511                                   -> ValueRef;
512         pub unsafe fn LLVMConstFDiv(LHSConstant: ValueRef,
513                                 RHSConstant: ValueRef)
514                              -> ValueRef;
515         pub unsafe fn LLVMConstURem(LHSConstant: ValueRef,
516                                 RHSConstant: ValueRef)
517                              -> ValueRef;
518         pub unsafe fn LLVMConstSRem(LHSConstant: ValueRef,
519                                 RHSConstant: ValueRef)
520                              -> ValueRef;
521         pub unsafe fn LLVMConstFRem(LHSConstant: ValueRef,
522                                 RHSConstant: ValueRef)
523                              -> ValueRef;
524         pub unsafe fn LLVMConstAnd(LHSConstant: ValueRef,
525                                RHSConstant: ValueRef)
526                             -> ValueRef;
527         pub unsafe fn LLVMConstOr(LHSConstant: ValueRef,
528                               RHSConstant: ValueRef)
529                            -> ValueRef;
530         pub unsafe fn LLVMConstXor(LHSConstant: ValueRef,
531                                RHSConstant: ValueRef)
532                             -> ValueRef;
533         pub unsafe fn LLVMConstShl(LHSConstant: ValueRef,
534                                RHSConstant: ValueRef)
535                             -> ValueRef;
536         pub unsafe fn LLVMConstLShr(LHSConstant: ValueRef,
537                                     RHSConstant: ValueRef) -> ValueRef;
538         pub unsafe fn LLVMConstAShr(LHSConstant: ValueRef,
539                                     RHSConstant: ValueRef) -> ValueRef;
540         pub unsafe fn LLVMConstGEP(ConstantVal: ValueRef,
541                         ConstantIndices: *ValueRef,
542                         NumIndices: c_uint) -> ValueRef;
543         pub unsafe fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
544                                        ConstantIndices: *ValueRef,
545                                        NumIndices: c_uint)
546                                     -> ValueRef;
547         pub unsafe fn LLVMConstTrunc(ConstantVal: ValueRef,
548                                  ToType: TypeRef)
549                               -> ValueRef;
550         pub unsafe fn LLVMConstSExt(ConstantVal: ValueRef,
551                                 ToType: TypeRef)
552                              -> ValueRef;
553         pub unsafe fn LLVMConstZExt(ConstantVal: ValueRef,
554                                 ToType: TypeRef)
555                              -> ValueRef;
556         pub unsafe fn LLVMConstFPTrunc(ConstantVal: ValueRef,
557                                    ToType: TypeRef)
558                                 -> ValueRef;
559         pub unsafe fn LLVMConstFPExt(ConstantVal: ValueRef,
560                                  ToType: TypeRef)
561                               -> ValueRef;
562         pub unsafe fn LLVMConstUIToFP(ConstantVal: ValueRef,
563                                   ToType: TypeRef)
564                                -> ValueRef;
565         pub unsafe fn LLVMConstSIToFP(ConstantVal: ValueRef,
566                                   ToType: TypeRef)
567                                -> ValueRef;
568         pub unsafe fn LLVMConstFPToUI(ConstantVal: ValueRef,
569                                   ToType: TypeRef)
570                                -> ValueRef;
571         pub unsafe fn LLVMConstFPToSI(ConstantVal: ValueRef,
572                                   ToType: TypeRef)
573                                -> ValueRef;
574         pub unsafe fn LLVMConstPtrToInt(ConstantVal: ValueRef,
575                                     ToType: TypeRef)
576                                  -> ValueRef;
577         pub unsafe fn LLVMConstIntToPtr(ConstantVal: ValueRef,
578                                     ToType: TypeRef)
579                                  -> ValueRef;
580         pub unsafe fn LLVMConstBitCast(ConstantVal: ValueRef,
581                                    ToType: TypeRef)
582                                 -> ValueRef;
583         pub unsafe fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef,
584                                          ToType: TypeRef)
585                                       -> ValueRef;
586         pub unsafe fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef,
587                                          ToType: TypeRef)
588                                       -> ValueRef;
589         pub unsafe fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef,
590                                           ToType: TypeRef)
591                                        -> ValueRef;
592         pub unsafe fn LLVMConstPointerCast(ConstantVal: ValueRef,
593                                        ToType: TypeRef)
594                                     -> ValueRef;
595         pub unsafe fn LLVMConstIntCast(ConstantVal: ValueRef,
596                                        ToType: TypeRef,
597                                        isSigned: Bool)
598                                     -> ValueRef;
599         pub unsafe fn LLVMConstFPCast(ConstantVal: ValueRef,
600                                   ToType: TypeRef)
601                                -> ValueRef;
602         pub unsafe fn LLVMConstSelect(ConstantCondition: ValueRef,
603                                       ConstantIfTrue: ValueRef,
604                                       ConstantIfFalse: ValueRef)
605                                    -> ValueRef;
606         pub unsafe fn LLVMConstExtractElement(VectorConstant: ValueRef,
607                                    IndexConstant: ValueRef) -> ValueRef;
608         pub unsafe fn LLVMConstInsertElement(VectorConstant: ValueRef,
609                                   ElementValueConstant: ValueRef,
610                                   IndexConstant: ValueRef) -> ValueRef;
611         pub unsafe fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
612                                   VectorBConstant: ValueRef,
613                                   MaskConstant: ValueRef) -> ValueRef;
614         pub unsafe fn LLVMConstExtractValue(AggConstant: ValueRef,
615                                             IdxList: *c_uint,
616                                             NumIdx: c_uint) -> ValueRef;
617         pub unsafe fn LLVMConstInsertValue(AggConstant: ValueRef,
618                                            ElementValueConstant: ValueRef,
619                                            IdxList: *c_uint,
620                                            NumIdx: c_uint)
621                                         -> ValueRef;
622         pub unsafe fn LLVMConstInlineAsm(Ty: TypeRef, AsmString: *c_char,
623                               Constraints: *c_char, HasSideEffects: Bool,
624                               IsAlignStack: Bool) -> ValueRef;
625         pub unsafe fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef)
626                                     -> ValueRef;
627
628
629
630         /* Operations on global variables, functions, and aliases (globals) */
631         pub unsafe fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
632         pub unsafe fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
633         pub unsafe fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
634         pub unsafe fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
635         pub unsafe fn LLVMGetSection(Global: ValueRef) -> *c_char;
636         pub unsafe fn LLVMSetSection(Global: ValueRef, Section: *c_char);
637         pub unsafe fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
638         pub unsafe fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
639         pub unsafe fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
640         pub unsafe fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
641
642
643         /* Operations on global variables */
644         pub unsafe fn LLVMAddGlobal(M: ModuleRef,
645                                 Ty: TypeRef,
646                                 Name: *c_char)
647                              -> ValueRef;
648         pub unsafe fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
649                                               Ty: TypeRef,
650                                               Name: *c_char,
651                                               AddressSpace: c_uint)
652                                            -> ValueRef;
653         pub unsafe fn LLVMGetNamedGlobal(M: ModuleRef, Name: *c_char)
654                                       -> ValueRef;
655         pub unsafe fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
656         pub unsafe fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
657         pub unsafe fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
658         pub unsafe fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
659         pub unsafe fn LLVMDeleteGlobal(GlobalVar: ValueRef);
660         pub unsafe fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
661         pub unsafe fn LLVMSetInitializer(GlobalVar: ValueRef,
662                                          ConstantVal: ValueRef);
663         pub unsafe fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
664         pub unsafe fn LLVMSetThreadLocal(GlobalVar: ValueRef,
665                                          IsThreadLocal: Bool);
666         pub unsafe fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
667         pub unsafe fn LLVMSetGlobalConstant(GlobalVar: ValueRef,
668                                             IsConstant: Bool);
669
670         /* Operations on aliases */
671         pub unsafe fn LLVMAddAlias(M: ModuleRef,
672                                    Ty: TypeRef,
673                                    Aliasee: ValueRef,
674                                    Name: *c_char)
675                                 -> ValueRef;
676
677         /* Operations on functions */
678         pub unsafe fn LLVMAddFunction(M: ModuleRef,
679                                   Name: *c_char,
680                                   FunctionTy: TypeRef)
681                                -> ValueRef;
682         pub unsafe fn LLVMGetNamedFunction(M: ModuleRef,
683                                            Name: *c_char) -> ValueRef;
684         pub unsafe fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
685         pub unsafe fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
686         pub unsafe fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
687         pub unsafe fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
688         pub unsafe fn LLVMDeleteFunction(Fn: ValueRef);
689         pub unsafe fn LLVMGetOrInsertFunction(M: ModuleRef, Name: *c_char,
690                                    FunctionTy: TypeRef) -> ValueRef;
691         pub unsafe fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
692         pub unsafe fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
693         pub unsafe fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
694         pub unsafe fn LLVMGetGC(Fn: ValueRef) -> *c_char;
695         pub unsafe fn LLVMSetGC(Fn: ValueRef, Name: *c_char);
696         pub unsafe fn LLVMAddFunctionAttr(Fn: ValueRef,
697                                           PA: c_ulonglong,
698                                           HighPA: c_ulonglong);
699         pub unsafe fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
700         pub unsafe fn LLVMRemoveFunctionAttr(Fn: ValueRef,
701                                              PA: c_ulonglong,
702                                              HighPA: c_ulonglong);
703
704         /* Operations on parameters */
705         pub unsafe fn LLVMCountParams(Fn: ValueRef) -> c_uint;
706         pub unsafe fn LLVMGetParams(Fn: ValueRef, Params: *ValueRef);
707         pub unsafe fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
708         pub unsafe fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
709         pub unsafe fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
710         pub unsafe fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
711         pub unsafe fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
712         pub unsafe fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
713         pub unsafe fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
714         pub unsafe fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
715         pub unsafe fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
716         pub unsafe fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
717
718         /* Operations on basic blocks */
719         pub unsafe fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
720         pub unsafe fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
721         pub unsafe fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
722         pub unsafe fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
723         pub unsafe fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
724         pub unsafe fn LLVMGetBasicBlocks(Fn: ValueRef,
725                                          BasicBlocks: *ValueRef);
726         pub unsafe fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
727         pub unsafe fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
728         pub unsafe fn LLVMGetNextBasicBlock(BB: BasicBlockRef)
729                                          -> BasicBlockRef;
730         pub unsafe fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef)
731                                              -> BasicBlockRef;
732         pub unsafe fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
733
734         pub unsafe fn LLVMAppendBasicBlockInContext(C: ContextRef,
735                                                     Fn: ValueRef,
736                                                     Name: *c_char)
737                                                  -> BasicBlockRef;
738         pub unsafe fn LLVMInsertBasicBlockInContext(C: ContextRef,
739                                                     BB: BasicBlockRef,
740                                                     Name: *c_char)
741                                                  -> BasicBlockRef;
742
743         pub unsafe fn LLVMAppendBasicBlock(Fn: ValueRef,
744                                        Name: *c_char)
745                                     -> BasicBlockRef;
746         pub unsafe fn LLVMInsertBasicBlock(InsertBeforeBB: BasicBlockRef,
747                                        Name: *c_char)
748                                     -> BasicBlockRef;
749         pub unsafe fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
750
751         /* Operations on instructions */
752         pub unsafe fn LLVMGetInstructionParent(Inst: ValueRef)
753                                             -> BasicBlockRef;
754         pub unsafe fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
755         pub unsafe fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
756         pub unsafe fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
757         pub unsafe fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
758
759         /* Operations on call sites */
760         pub unsafe fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
761         pub unsafe fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
762         pub unsafe fn LLVMAddInstrAttribute(Instr: ValueRef,
763                                             index: c_uint,
764                                             IA: c_uint);
765         pub unsafe fn LLVMRemoveInstrAttribute(Instr: ValueRef,
766                                                index: c_uint,
767                                                IA: c_uint);
768         pub unsafe fn LLVMSetInstrParamAlignment(Instr: ValueRef,
769                                                  index: c_uint,
770                                                  align: c_uint);
771
772         /* Operations on call instructions (only) */
773         pub unsafe fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
774         pub unsafe fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
775
776         /* Operations on phi nodes */
777         pub unsafe fn LLVMAddIncoming(PhiNode: ValueRef,
778                                       IncomingValues: *ValueRef,
779                                       IncomingBlocks: *BasicBlockRef,
780                                       Count: c_uint);
781         pub unsafe fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
782         pub unsafe fn LLVMGetIncomingValue(PhiNode: ValueRef,
783                                        Index: c_uint)
784                                     -> ValueRef;
785         pub unsafe fn LLVMGetIncomingBlock(PhiNode: ValueRef,
786                                 Index: c_uint) -> BasicBlockRef;
787
788         /* Instruction builders */
789         pub unsafe fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
790         pub unsafe fn LLVMCreateBuilder() -> BuilderRef;
791         pub unsafe fn LLVMPositionBuilder(Builder: BuilderRef,
792                                           Block: BasicBlockRef,
793                                           Instr: ValueRef);
794         pub unsafe fn LLVMPositionBuilderBefore(Builder: BuilderRef,
795                                                 Instr: ValueRef);
796         pub unsafe fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
797                                                Block: BasicBlockRef);
798         pub unsafe fn LLVMGetInsertBlock(Builder: BuilderRef)
799                                       -> BasicBlockRef;
800         pub unsafe fn LLVMClearInsertionPosition(Builder: BuilderRef);
801         pub unsafe fn LLVMInsertIntoBuilder(Builder: BuilderRef,
802                                             Instr: ValueRef);
803         pub unsafe fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
804                                                 Instr: ValueRef,
805                                                 Name: *c_char);
806         pub unsafe fn LLVMDisposeBuilder(Builder: BuilderRef);
807
808         /* Metadata */
809         pub unsafe fn LLVMSetCurrentDebugLocation(Builder: BuilderRef,
810                                                   L: ValueRef);
811         pub unsafe fn LLVMGetCurrentDebugLocation(Builder: BuilderRef)
812                                                -> ValueRef;
813         pub unsafe fn LLVMSetInstDebugLocation(Builder: BuilderRef,
814                                                Inst: ValueRef);
815
816         /* Terminators */
817         pub unsafe fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
818         pub unsafe fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
819         pub unsafe fn LLVMBuildAggregateRet(B: BuilderRef, RetVals: *ValueRef,
820                                  N: c_uint) -> ValueRef;
821         pub unsafe fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef)
822                                -> ValueRef;
823         pub unsafe fn LLVMBuildCondBr(B: BuilderRef,
824                                   If: ValueRef,
825                                   Then: BasicBlockRef,
826                                   Else: BasicBlockRef)
827                                -> ValueRef;
828         pub unsafe fn LLVMBuildSwitch(B: BuilderRef, V: ValueRef,
829                                       Else: BasicBlockRef, NumCases: c_uint)
830                                    -> ValueRef;
831         pub unsafe fn LLVMBuildIndirectBr(B: BuilderRef, Addr: ValueRef,
832                                NumDests: c_uint) -> ValueRef;
833         pub unsafe fn LLVMBuildInvoke(B: BuilderRef,
834                                       Fn: ValueRef,
835                                       Args: *ValueRef,
836                                       NumArgs: c_uint,
837                                       Then: BasicBlockRef,
838                                       Catch: BasicBlockRef,
839                                       Name: *c_char) -> ValueRef;
840         pub unsafe fn LLVMBuildLandingPad(B: BuilderRef,
841                                       Ty: TypeRef,
842                                       PersFn: ValueRef,
843                                       NumClauses: c_uint,
844                                       Name: *c_char)
845                                    -> ValueRef;
846         pub unsafe fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef)
847                                    -> ValueRef;
848         pub unsafe fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
849
850         /* Add a case to the switch instruction */
851         pub unsafe fn LLVMAddCase(Switch: ValueRef,
852                               OnVal: ValueRef,
853                               Dest: BasicBlockRef);
854
855         /* Add a destination to the indirectbr instruction */
856         pub unsafe fn LLVMAddDestination(IndirectBr: ValueRef,
857                                          Dest: BasicBlockRef);
858
859         /* Add a clause to the landing pad instruction */
860         pub unsafe fn LLVMAddClause(LandingPad: ValueRef,
861                                     ClauseVal: ValueRef);
862
863         /* Set the cleanup on a landing pad instruction */
864         pub unsafe fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
865
866         /* Arithmetic */
867         pub unsafe fn LLVMBuildAdd(B: BuilderRef,
868                                    LHS: ValueRef,
869                                    RHS: ValueRef,
870                                    Name: *c_char)
871                                 -> ValueRef;
872         pub unsafe fn LLVMBuildNSWAdd(B: BuilderRef,
873                                       LHS: ValueRef,
874                                       RHS: ValueRef,
875                                       Name: *c_char)
876                                    -> ValueRef;
877         pub unsafe fn LLVMBuildNUWAdd(B: BuilderRef,
878                                       LHS: ValueRef,
879                                       RHS: ValueRef,
880                                       Name: *c_char)
881                                    -> ValueRef;
882         pub unsafe fn LLVMBuildFAdd(B: BuilderRef,
883                                     LHS: ValueRef,
884                                     RHS: ValueRef,
885                                     Name: *c_char)
886                                  -> ValueRef;
887         pub unsafe fn LLVMBuildSub(B: BuilderRef,
888                                    LHS: ValueRef,
889                                    RHS: ValueRef,
890                                    Name: *c_char)
891                                 -> ValueRef;
892         pub unsafe fn LLVMBuildNSWSub(B: BuilderRef,
893                                       LHS: ValueRef,
894                                       RHS: ValueRef,
895                                       Name: *c_char)
896                                    -> ValueRef;
897         pub unsafe fn LLVMBuildNUWSub(B: BuilderRef,
898                                       LHS: ValueRef,
899                                       RHS: ValueRef,
900                                       Name: *c_char)
901                                    -> ValueRef;
902         pub unsafe fn LLVMBuildFSub(B: BuilderRef,
903                                     LHS: ValueRef,
904                                     RHS: ValueRef,
905                                     Name: *c_char)
906                                  -> ValueRef;
907         pub unsafe fn LLVMBuildMul(B: BuilderRef,
908                                    LHS: ValueRef,
909                                    RHS: ValueRef,
910                                    Name: *c_char)
911                                 -> ValueRef;
912         pub unsafe fn LLVMBuildNSWMul(B: BuilderRef,
913                                       LHS: ValueRef,
914                                       RHS: ValueRef,
915                                       Name: *c_char)
916                                    -> ValueRef;
917         pub unsafe fn LLVMBuildNUWMul(B: BuilderRef,
918                                       LHS: ValueRef,
919                                       RHS: ValueRef,
920                                       Name: *c_char)
921                                    -> ValueRef;
922         pub unsafe fn LLVMBuildFMul(B: BuilderRef,
923                                     LHS: ValueRef,
924                                     RHS: ValueRef,
925                                     Name: *c_char)
926                                  -> ValueRef;
927         pub unsafe fn LLVMBuildUDiv(B: BuilderRef,
928                                     LHS: ValueRef,
929                                     RHS: ValueRef,
930                                     Name: *c_char)
931                                  -> ValueRef;
932         pub unsafe fn LLVMBuildSDiv(B: BuilderRef,
933                                     LHS: ValueRef,
934                                     RHS: ValueRef,
935                                     Name: *c_char)
936                                  -> ValueRef;
937         pub unsafe fn LLVMBuildExactSDiv(B: BuilderRef,
938                                          LHS: ValueRef,
939                                          RHS: ValueRef,
940                                          Name: *c_char)
941                                       -> ValueRef;
942         pub unsafe fn LLVMBuildFDiv(B: BuilderRef,
943                                     LHS: ValueRef,
944                                     RHS: ValueRef,
945                                     Name: *c_char)
946                                  -> ValueRef;
947         pub unsafe fn LLVMBuildURem(B: BuilderRef,
948                                     LHS: ValueRef,
949                                     RHS: ValueRef,
950                                     Name: *c_char)
951                                  -> ValueRef;
952         pub unsafe fn LLVMBuildSRem(B: BuilderRef,
953                                     LHS: ValueRef,
954                                     RHS: ValueRef,
955                                     Name: *c_char)
956                                  -> ValueRef;
957         pub unsafe fn LLVMBuildFRem(B: BuilderRef,
958                                     LHS: ValueRef,
959                                     RHS: ValueRef,
960                                     Name: *c_char)
961                                  -> ValueRef;
962         pub unsafe fn LLVMBuildShl(B: BuilderRef,
963                                    LHS: ValueRef,
964                                    RHS: ValueRef,
965                                    Name: *c_char)
966                                 -> ValueRef;
967         pub unsafe fn LLVMBuildLShr(B: BuilderRef,
968                                     LHS: ValueRef,
969                                     RHS: ValueRef,
970                                     Name: *c_char)
971                                  -> ValueRef;
972         pub unsafe fn LLVMBuildAShr(B: BuilderRef,
973                                     LHS: ValueRef,
974                                     RHS: ValueRef,
975                                     Name: *c_char)
976                                  -> ValueRef;
977         pub unsafe fn LLVMBuildAnd(B: BuilderRef,
978                                    LHS: ValueRef,
979                                    RHS: ValueRef,
980                                    Name: *c_char)
981                                 -> ValueRef;
982         pub unsafe fn LLVMBuildOr(B: BuilderRef,
983                                   LHS: ValueRef,
984                                   RHS: ValueRef,
985                                   Name: *c_char)
986                                -> ValueRef;
987         pub unsafe fn LLVMBuildXor(B: BuilderRef,
988                                    LHS: ValueRef,
989                                    RHS: ValueRef,
990                                    Name: *c_char)
991                                 -> ValueRef;
992         pub unsafe fn LLVMBuildBinOp(B: BuilderRef,
993                                  Op: Opcode,
994                                  LHS: ValueRef,
995                                  RHS: ValueRef,
996                                  Name: *c_char)
997                               -> ValueRef;
998         pub unsafe fn LLVMBuildNeg(B: BuilderRef,
999                                V: ValueRef,
1000                                Name: *c_char)
1001                             -> ValueRef;
1002         pub unsafe fn LLVMBuildNSWNeg(B: BuilderRef,
1003                                   V: ValueRef,
1004                                   Name: *c_char)
1005                                -> ValueRef;
1006         pub unsafe fn LLVMBuildNUWNeg(B: BuilderRef,
1007                                   V: ValueRef,
1008                                   Name: *c_char)
1009                                -> ValueRef;
1010         pub unsafe fn LLVMBuildFNeg(B: BuilderRef,
1011                                 V: ValueRef,
1012                                 Name: *c_char)
1013                              -> ValueRef;
1014         pub unsafe fn LLVMBuildNot(B: BuilderRef,
1015                                V: ValueRef,
1016                                Name: *c_char)
1017                             -> ValueRef;
1018
1019         /* Memory */
1020         pub unsafe fn LLVMBuildMalloc(B: BuilderRef,
1021                                       Ty: TypeRef,
1022                                       Name: *c_char)
1023                                    -> ValueRef;
1024         pub unsafe fn LLVMBuildArrayMalloc(B: BuilderRef,
1025                                            Ty: TypeRef,
1026                                            Val: ValueRef,
1027                                            Name: *c_char) -> ValueRef;
1028         pub unsafe fn LLVMBuildAlloca(B: BuilderRef,
1029                                   Ty: TypeRef,
1030                                   Name: *c_char)
1031                                -> ValueRef;
1032         pub unsafe fn LLVMBuildArrayAlloca(B: BuilderRef,
1033                                            Ty: TypeRef,
1034                                            Val: ValueRef,
1035                                            Name: *c_char) -> ValueRef;
1036         pub unsafe fn LLVMBuildFree(B: BuilderRef,
1037                                     PointerVal: ValueRef) -> ValueRef;
1038         pub unsafe fn LLVMBuildLoad(B: BuilderRef,
1039                                 PointerVal: ValueRef,
1040                                 Name: *c_char)
1041                              -> ValueRef;
1042         pub unsafe fn LLVMBuildStore(B: BuilderRef,
1043                                      Val: ValueRef,
1044                                      Ptr: ValueRef) -> ValueRef;
1045         pub unsafe fn LLVMBuildGEP(B: BuilderRef,
1046                                Pointer: ValueRef,
1047                                Indices: *ValueRef,
1048                                NumIndices: c_uint,
1049                                Name: *c_char)
1050                             -> ValueRef;
1051         pub unsafe fn LLVMBuildInBoundsGEP(B: BuilderRef, Pointer: ValueRef,
1052                                 Indices: *ValueRef, NumIndices: c_uint,
1053                                 Name: *c_char)
1054            -> ValueRef;
1055         pub unsafe fn LLVMBuildStructGEP(B: BuilderRef,
1056                                      Pointer: ValueRef,
1057                                      Idx: c_uint,
1058                                      Name: *c_char)
1059                                   -> ValueRef;
1060         pub unsafe fn LLVMBuildGlobalString(B: BuilderRef,
1061                                         Str: *c_char,
1062                                         Name: *c_char)
1063                                      -> ValueRef;
1064         pub unsafe fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1065                                            Str: *c_char,
1066                                            Name: *c_char)
1067                                         -> ValueRef;
1068
1069         /* Casts */
1070         pub unsafe fn LLVMBuildTrunc(B: BuilderRef,
1071                                      Val: ValueRef,
1072                                      DestTy: TypeRef,
1073                                      Name: *c_char) -> ValueRef;
1074         pub unsafe fn LLVMBuildZExt(B: BuilderRef,
1075                                     Val: ValueRef,
1076                                     DestTy: TypeRef,
1077                                     Name: *c_char)
1078                                  -> ValueRef;
1079         pub unsafe fn LLVMBuildSExt(B: BuilderRef,
1080                                     Val: ValueRef,
1081                                     DestTy: TypeRef,
1082                                     Name: *c_char)
1083                                  -> ValueRef;
1084         pub unsafe fn LLVMBuildFPToUI(B: BuilderRef,
1085                                       Val: ValueRef,
1086                                       DestTy: TypeRef,
1087                                       Name: *c_char) -> ValueRef;
1088         pub unsafe fn LLVMBuildFPToSI(B: BuilderRef,
1089                                       Val: ValueRef,
1090                                       DestTy: TypeRef,
1091                                       Name: *c_char) -> ValueRef;
1092         pub unsafe fn LLVMBuildUIToFP(B: BuilderRef,
1093                                       Val: ValueRef,
1094                                       DestTy: TypeRef,
1095                                       Name: *c_char) -> ValueRef;
1096         pub unsafe fn LLVMBuildSIToFP(B: BuilderRef,
1097                                       Val: ValueRef,
1098                                       DestTy: TypeRef,
1099                                       Name: *c_char) -> ValueRef;
1100         pub unsafe fn LLVMBuildFPTrunc(B: BuilderRef,
1101                                        Val: ValueRef,
1102                                        DestTy: TypeRef,
1103                                        Name: *c_char) -> ValueRef;
1104         pub unsafe fn LLVMBuildFPExt(B: BuilderRef,
1105                                      Val: ValueRef,
1106                                      DestTy: TypeRef,
1107                                      Name: *c_char) -> ValueRef;
1108         pub unsafe fn LLVMBuildPtrToInt(B: BuilderRef,
1109                                         Val: ValueRef,
1110                                         DestTy: TypeRef,
1111                                         Name: *c_char) -> ValueRef;
1112         pub unsafe fn LLVMBuildIntToPtr(B: BuilderRef,
1113                                         Val: ValueRef,
1114                                         DestTy: TypeRef,
1115                                         Name: *c_char) -> ValueRef;
1116         pub unsafe fn LLVMBuildBitCast(B: BuilderRef,
1117                                        Val: ValueRef,
1118                                        DestTy: TypeRef,
1119                                        Name: *c_char) -> ValueRef;
1120         pub unsafe fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1121                                          Val: ValueRef,
1122                                          DestTy: TypeRef,
1123                                          Name: *c_char)
1124                                       -> ValueRef;
1125         pub unsafe fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1126                                          Val: ValueRef,
1127                                          DestTy: TypeRef,
1128                                          Name: *c_char)
1129                                       -> ValueRef;
1130         pub unsafe fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1131                                           Val: ValueRef,
1132                                           DestTy: TypeRef,
1133                                           Name: *c_char)
1134                                        -> ValueRef;
1135         pub unsafe fn LLVMBuildCast(B: BuilderRef, Op: Opcode, Val: ValueRef,
1136                          DestTy: TypeRef, Name: *c_char) -> ValueRef;
1137         pub unsafe fn LLVMBuildPointerCast(B: BuilderRef,
1138                                        Val: ValueRef,
1139                                        DestTy: TypeRef,
1140                                        Name: *c_char)
1141                                     -> ValueRef;
1142         pub unsafe fn LLVMBuildIntCast(B: BuilderRef,
1143                                        Val: ValueRef,
1144                                        DestTy: TypeRef,
1145                                        Name: *c_char) -> ValueRef;
1146         pub unsafe fn LLVMBuildFPCast(B: BuilderRef,
1147                                       Val: ValueRef,
1148                                       DestTy: TypeRef,
1149                                       Name: *c_char) -> ValueRef;
1150
1151         /* Comparisons */
1152         pub unsafe fn LLVMBuildICmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1153                          RHS: ValueRef, Name: *c_char) -> ValueRef;
1154         pub unsafe fn LLVMBuildFCmp(B: BuilderRef, Op: c_uint, LHS: ValueRef,
1155                          RHS: ValueRef, Name: *c_char) -> ValueRef;
1156
1157         /* Miscellaneous instructions */
1158         pub unsafe fn LLVMBuildPhi(B: BuilderRef,
1159                                    Ty: TypeRef,
1160                                    Name: *c_char)
1161                                 -> ValueRef;
1162         pub unsafe fn LLVMBuildCall(B: BuilderRef,
1163                                     Fn: ValueRef,
1164                                     Args: *ValueRef,
1165                                     NumArgs: c_uint,
1166                                     Name: *c_char)
1167                                  -> ValueRef;
1168         pub unsafe fn LLVMBuildSelect(B: BuilderRef,
1169                                       If: ValueRef,
1170                                       Then: ValueRef,
1171                                       Else: ValueRef,
1172                                       Name: *c_char)
1173                                    -> ValueRef;
1174         pub unsafe fn LLVMBuildVAArg(B: BuilderRef,
1175                                      list: ValueRef,
1176                                      Ty: TypeRef,
1177                                      Name: *c_char)
1178                                   -> ValueRef;
1179         pub unsafe fn LLVMBuildExtractElement(B: BuilderRef,
1180                                           VecVal: ValueRef,
1181                                           Index: ValueRef,
1182                                           Name: *c_char)
1183                                        -> ValueRef;
1184         pub unsafe fn LLVMBuildInsertElement(B: BuilderRef,
1185                                          VecVal: ValueRef,
1186                                          EltVal: ValueRef,
1187                                          Index: ValueRef,
1188                                          Name: *c_char)
1189                                       -> ValueRef;
1190         pub unsafe fn LLVMBuildShuffleVector(B: BuilderRef,
1191                                          V1: ValueRef,
1192                                          V2: ValueRef,
1193                                          Mask: ValueRef,
1194                                          Name: *c_char)
1195                                       -> ValueRef;
1196         pub unsafe fn LLVMBuildExtractValue(B: BuilderRef,
1197                                         AggVal: ValueRef,
1198                                         Index: c_uint,
1199                                         Name: *c_char)
1200                                      -> ValueRef;
1201         pub unsafe fn LLVMBuildInsertValue(B: BuilderRef,
1202                                        AggVal: ValueRef,
1203                                        EltVal: ValueRef,
1204                                        Index: c_uint,
1205                                        Name: *c_char)
1206                                     -> ValueRef;
1207
1208         pub unsafe fn LLVMBuildIsNull(B: BuilderRef,
1209                                       Val: ValueRef,
1210                                       Name: *c_char)
1211                                    -> ValueRef;
1212         pub unsafe fn LLVMBuildIsNotNull(B: BuilderRef,
1213                                          Val: ValueRef,
1214                                          Name: *c_char)
1215                                       -> ValueRef;
1216         pub unsafe fn LLVMBuildPtrDiff(B: BuilderRef,
1217                                        LHS: ValueRef,
1218                                        RHS: ValueRef,
1219                                        Name: *c_char) -> ValueRef;
1220
1221         /* Atomic Operations */
1222         pub unsafe fn LLVMBuildAtomicCmpXchg(B: BuilderRef, LHS: ValueRef,
1223                                   CMP: ValueRef, RHS: ValueRef,
1224                                   ++Order: AtomicOrdering) -> ValueRef;
1225         pub unsafe fn LLVMBuildAtomicRMW(B: BuilderRef, ++Op: AtomicBinOp,
1226                               LHS: ValueRef, RHS: ValueRef,
1227                               ++Order: AtomicOrdering) -> ValueRef;
1228
1229         /* Selected entries from the downcasts. */
1230         pub unsafe fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1231
1232         /** Writes a module to the specified path. Returns 0 on success. */
1233         pub unsafe fn LLVMWriteBitcodeToFile(M: ModuleRef,
1234                                              Path: *c_char) -> c_int;
1235
1236         /** Creates target data from a target layout string. */
1237         pub unsafe fn LLVMCreateTargetData(StringRep: *c_char)
1238                                         -> TargetDataRef;
1239         /** Adds the target data to the given pass manager. The pass manager
1240             references the target data only weakly. */
1241         pub unsafe fn LLVMAddTargetData(TD: TargetDataRef,
1242                                         PM: PassManagerRef);
1243         /** Number of bytes clobbered when doing a Store to *T. */
1244         pub unsafe fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1245             -> c_ulonglong;
1246
1247         /** Number of bytes clobbered when doing a Store to *T. */
1248         pub unsafe fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1249             -> c_ulonglong;
1250
1251         /** Distance between successive elements in an array of T.
1252         Includes ABI padding. */
1253         pub unsafe fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef)
1254                                      -> c_uint;
1255
1256         /** Returns the preferred alignment of a type. */
1257         pub unsafe fn LLVMPreferredAlignmentOfType(TD: TargetDataRef,
1258                                         Ty: TypeRef) -> c_uint;
1259         /** Returns the minimum alignment of a type. */
1260         pub unsafe fn LLVMABIAlignmentOfType(TD: TargetDataRef,
1261                                   Ty: TypeRef) -> c_uint;
1262         /**
1263          * Returns the minimum alignment of a type when part of a call frame.
1264          */
1265         pub unsafe fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef,
1266                                                    Ty: TypeRef)
1267                                                 -> c_uint;
1268
1269         /** Disposes target data. */
1270         pub unsafe fn LLVMDisposeTargetData(TD: TargetDataRef);
1271
1272         /** Creates a pass manager. */
1273         pub unsafe fn LLVMCreatePassManager() -> PassManagerRef;
1274         /** Disposes a pass manager. */
1275         pub unsafe fn LLVMDisposePassManager(PM: PassManagerRef);
1276         /** Runs a pass manager on a module. */
1277         pub unsafe fn LLVMRunPassManager(PM: PassManagerRef,
1278                                          M: ModuleRef) -> Bool;
1279
1280         /** Adds a verification pass. */
1281         pub unsafe fn LLVMAddVerifierPass(PM: PassManagerRef);
1282
1283         pub unsafe fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1284         pub unsafe fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1285         pub unsafe fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1286         pub unsafe fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1287         pub unsafe fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1288         pub unsafe fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1289         pub unsafe fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1290         pub unsafe fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1291         pub unsafe fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1292         pub unsafe fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1293         pub unsafe fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1294         pub unsafe fn LLVMAddReassociatePass(PM: PassManagerRef);
1295         pub unsafe fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1296         pub unsafe fn LLVMAddLICMPass(PM: PassManagerRef);
1297         pub unsafe fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1298         pub unsafe fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1299         pub unsafe fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1300         pub unsafe fn LLVMAddGVNPass(PM: PassManagerRef);
1301         pub unsafe fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1302         pub unsafe fn LLVMAddSCCPPass(PM: PassManagerRef);
1303         pub unsafe fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1304         pub unsafe fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1305         pub unsafe fn LLVMAddConstantMergePass(PM: PassManagerRef);
1306         pub unsafe fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1307         pub unsafe fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1308         pub unsafe fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1309         pub unsafe fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1310         pub unsafe fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1311         pub unsafe fn LLVMAddCorrelatedValuePropagationPass(PM:
1312                                                             PassManagerRef);
1313         pub unsafe fn LLVMAddPruneEHPass(PM: PassManagerRef);
1314         pub unsafe fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1315         pub unsafe fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1316         pub unsafe fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1317         pub unsafe fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1318         pub unsafe fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1319
1320         pub unsafe fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1321         pub unsafe fn LLVMPassManagerBuilderDispose(PMB:
1322                                                     PassManagerBuilderRef);
1323         pub unsafe fn LLVMPassManagerBuilderSetOptLevel(
1324             PMB: PassManagerBuilderRef, OptimizationLevel: c_uint);
1325         pub unsafe fn LLVMPassManagerBuilderSetSizeLevel(
1326             PMB: PassManagerBuilderRef, Value: Bool);
1327         pub unsafe fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1328             PMB: PassManagerBuilderRef, Value: Bool);
1329         pub unsafe fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1330             PMB: PassManagerBuilderRef, Value: Bool);
1331         pub unsafe fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls
1332             (PMB: PassManagerBuilderRef, Value: Bool);
1333         pub unsafe fn LLVMPassManagerBuilderUseInlinerWithThreshold
1334             (PMB: PassManagerBuilderRef, threshold: c_uint);
1335         pub unsafe fn LLVMPassManagerBuilderPopulateModulePassManager
1336             (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1337
1338         pub unsafe fn LLVMPassManagerBuilderPopulateFunctionPassManager
1339             (PMB: PassManagerBuilderRef, PM: PassManagerRef);
1340
1341         /** Destroys a memory buffer. */
1342         pub unsafe fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1343
1344
1345         /* Stuff that's in rustllvm/ because it's not upstream yet. */
1346
1347         /** Opens an object file. */
1348         pub unsafe fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef)
1349                                         -> ObjectFileRef;
1350         /** Closes an object file. */
1351         pub unsafe fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1352
1353         /** Enumerates the sections in an object file. */
1354         pub unsafe fn LLVMGetSections(ObjFile: ObjectFileRef)
1355                                    -> SectionIteratorRef;
1356         /** Destroys a section iterator. */
1357         pub unsafe fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1358         /** Returns true if the section iterator is at the end of the section
1359             list: */
1360         pub unsafe fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1361                                       SI: SectionIteratorRef) -> Bool;
1362         /** Moves the section iterator to point to the next section. */
1363         pub unsafe fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1364         /** Returns the current section name. */
1365         pub unsafe fn LLVMGetSectionName(SI: SectionIteratorRef) -> *c_char;
1366         /** Returns the current section size. */
1367         pub unsafe fn LLVMGetSectionSize(SI: SectionIteratorRef)
1368                                       -> c_ulonglong;
1369         /** Returns the current section contents as a string buffer. */
1370         pub unsafe fn LLVMGetSectionContents(SI: SectionIteratorRef)
1371                                           -> *c_char;
1372
1373         /** Reads the given file and returns it as a memory buffer. Use
1374             LLVMDisposeMemoryBuffer() to get rid of it. */
1375         pub unsafe fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1376                 Path: *c_char)
1377              -> MemoryBufferRef;
1378
1379         pub unsafe fn LLVMRustWriteOutputFile(PM: PassManagerRef,
1380                                               M: ModuleRef,
1381                                               Triple: *c_char,
1382                                               // FIXME: When #2334 is fixed,
1383                                               // change c_uint to FileType
1384                                               Output: *c_char,
1385                                               FileType: c_uint,
1386                                               OptLevel: c_int,
1387                                               EnableSegmentedStacks: bool)
1388                                            -> bool;
1389
1390         /** Returns a string describing the last error caused by an LLVMRust*
1391             call. */
1392         pub unsafe fn LLVMRustGetLastError() -> *c_char;
1393
1394         /** Prepare the JIT. Returns a memory manager that can load crates. */
1395         pub unsafe fn LLVMRustPrepareJIT(__morestack: *()) -> *();
1396
1397         /** Load a crate into the memory manager. */
1398         pub unsafe fn LLVMRustLoadCrate(MM: *(),
1399                                         Filename: *c_char)
1400                                      -> bool;
1401
1402         /** Execute the JIT engine. */
1403         pub unsafe fn LLVMRustExecuteJIT(MM: *(),
1404                               PM: PassManagerRef,
1405                               M: ModuleRef,
1406                               OptLevel: c_int,
1407                               EnableSegmentedStacks: bool) -> *();
1408
1409         /** Parses the bitcode in the given memory buffer. */
1410         pub unsafe fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef)
1411                                         -> ModuleRef;
1412
1413         /** Parses LLVM asm in the given file */
1414         pub unsafe fn LLVMRustParseAssemblyFile(Filename: *c_char)
1415                                              -> ModuleRef;
1416
1417         pub unsafe fn LLVMRustAddPrintModulePass(PM: PassManagerRef,
1418                                                  M: ModuleRef,
1419                                                  Output: *c_char);
1420
1421         /** Turn on LLVM pass-timing. */
1422         pub unsafe fn LLVMRustEnableTimePasses();
1423
1424         /// Print the pass timings since static dtors aren't picking them up.
1425         pub unsafe fn LLVMRustPrintPassTimings();
1426
1427         pub unsafe fn LLVMStructCreateNamed(C: ContextRef, Name: *c_char)
1428                                          -> TypeRef;
1429
1430         pub unsafe fn LLVMStructSetBody(StructTy: TypeRef,
1431                                         ElementTypes: *TypeRef,
1432                                         ElementCount: c_uint,
1433                                         Packed: Bool);
1434
1435         pub unsafe fn LLVMConstNamedStruct(S: TypeRef,
1436                                            ConstantVals: *ValueRef,
1437                                            Count: c_uint)
1438                                         -> ValueRef;
1439
1440         /** Enables LLVM debug output. */
1441         pub unsafe fn LLVMSetDebug(Enabled: c_int);
1442
1443         /** Prepares inline assembly. */
1444         pub unsafe fn LLVMInlineAsm(Ty: TypeRef, AsmString: *c_char,
1445                                     Constraints: *c_char, SideEffects: Bool,
1446                                     AlignStack: Bool, Dialect: AsmDialect)
1447                                  -> ValueRef;
1448     }
1449 }
1450
1451 pub fn SetInstructionCallConv(Instr: ValueRef, CC: CallConv) {
1452     unsafe {
1453         llvm::LLVMSetInstructionCallConv(Instr, CC as c_uint);
1454     }
1455 }
1456 pub fn SetFunctionCallConv(Fn: ValueRef, CC: CallConv) {
1457     unsafe {
1458         llvm::LLVMSetFunctionCallConv(Fn, CC as c_uint);
1459     }
1460 }
1461 pub fn SetLinkage(Global: ValueRef, Link: Linkage) {
1462     unsafe {
1463         llvm::LLVMSetLinkage(Global, Link as c_uint);
1464     }
1465 }
1466
1467 /* Memory-managed object interface to type handles. */
1468
1469 pub struct TypeNames {
1470     type_names: HashMap<TypeRef, @str>,
1471     named_types: HashMap<@str, TypeRef>
1472 }
1473
1474 pub fn associate_type(tn: @TypeNames, s: @str, t: TypeRef) {
1475     fail_unless!(tn.type_names.insert(t, s));
1476     fail_unless!(tn.named_types.insert(s, t));
1477 }
1478
1479 pub fn type_has_name(tn: @TypeNames, t: TypeRef) -> Option<@str> {
1480     return tn.type_names.find(&t);
1481 }
1482
1483 pub fn name_has_type(tn: @TypeNames, s: @str) -> Option<TypeRef> {
1484     return tn.named_types.find(&s);
1485 }
1486
1487 pub fn mk_type_names() -> @TypeNames {
1488     @TypeNames {
1489         type_names: HashMap(),
1490         named_types: HashMap()
1491     }
1492 }
1493
1494 pub fn type_to_str(names: @TypeNames, ty: TypeRef) -> @str {
1495     return type_to_str_inner(names, [], ty);
1496 }
1497
1498 pub fn type_to_str_inner(names: @TypeNames, +outer0: &[TypeRef], ty: TypeRef)
1499                       -> @str {
1500     unsafe {
1501         match type_has_name(names, ty) {
1502           option::Some(n) => return n,
1503           _ => {}
1504         }
1505
1506         let outer = vec::append_one(outer0.to_vec(), ty);
1507
1508         let kind = llvm::LLVMGetTypeKind(ty);
1509
1510         fn tys_str(names: @TypeNames, outer: &[TypeRef],
1511                    tys: ~[TypeRef]) -> @str {
1512             let mut s = ~"";
1513             let mut first: bool = true;
1514             for tys.each |t| {
1515                 if first { first = false; } else { s += ~", "; }
1516                 s += type_to_str_inner(names, outer, *t).to_owned();
1517             }
1518             // [Note at-str] FIXME #2543: Could rewrite this without the copy,
1519             // but need better @str support.
1520             return s.to_managed();
1521         }
1522
1523         match kind {
1524           Void => return @"Void",
1525           Half => return @"Half",
1526           Float => return @"Float",
1527           Double => return @"Double",
1528           X86_FP80 => return @"X86_FP80",
1529           FP128 => return @"FP128",
1530           PPC_FP128 => return @"PPC_FP128",
1531           Label => return @"Label",
1532           Integer => {
1533             // See [Note at-str]
1534             return fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty)
1535                         as int).to_managed();
1536           }
1537           Function => {
1538             let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
1539             let n_args = llvm::LLVMCountParamTypes(ty) as uint;
1540             let args = vec::from_elem(n_args, 0 as TypeRef);
1541             unsafe {
1542                 llvm::LLVMGetParamTypes(ty, vec::raw::to_ptr(args));
1543             }
1544             // See [Note at-str]
1545             return fmt!("fn(%s) -> %s",
1546                         tys_str(names, outer, args),
1547                         type_to_str_inner(names, outer, out_ty)).to_managed();
1548           }
1549           Struct => {
1550             let elts = struct_tys(ty);
1551             // See [Note at-str]
1552             return fmt!("{%s}", tys_str(names, outer, elts)).to_managed();
1553           }
1554           Array => {
1555             let el_ty = llvm::LLVMGetElementType(ty);
1556             // See [Note at-str]
1557             return fmt!("[%s@ x %u", type_to_str_inner(names, outer, el_ty),
1558                 llvm::LLVMGetArrayLength(ty) as uint).to_managed();
1559           }
1560           Pointer => {
1561             let mut i = 0;
1562             for outer0.each |tout| {
1563                 i += 1;
1564                 if *tout as int == ty as int {
1565                     let n = outer0.len() - i;
1566                     // See [Note at-str]
1567                     return fmt!("*\\%d", n as int).to_managed();
1568                 }
1569             }
1570             let addrstr = {
1571                 let addrspace = llvm::LLVMGetPointerAddressSpace(ty) as uint;
1572                 if addrspace == 0 {
1573                     ~""
1574                 } else {
1575                     fmt!("addrspace(%u)", addrspace)
1576                 }
1577             };
1578             // See [Note at-str]
1579             return fmt!("%s*%s", addrstr, type_to_str_inner(names,
1580                         outer,
1581                         llvm::LLVMGetElementType(ty))).to_managed();
1582           }
1583           Vector => return @"Vector",
1584           Metadata => return @"Metadata",
1585           X86_MMX => return @"X86_MMAX"
1586         }
1587     }
1588 }
1589
1590 pub fn float_width(llt: TypeRef) -> uint {
1591     unsafe {
1592         return match llvm::LLVMGetTypeKind(llt) as int {
1593               1 => 32u,
1594               2 => 64u,
1595               3 => 80u,
1596               4 | 5 => 128u,
1597               _ => fail!(~"llvm_float_width called on a non-float type")
1598             };
1599     }
1600 }
1601
1602 pub fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] {
1603     unsafe {
1604         let args = vec::from_elem(llvm::LLVMCountParamTypes(fn_ty) as uint,
1605                                  0 as TypeRef);
1606         llvm::LLVMGetParamTypes(fn_ty, vec::raw::to_ptr(args));
1607         return args;
1608     }
1609 }
1610
1611 pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] {
1612     unsafe {
1613         let n_elts = llvm::LLVMCountStructElementTypes(struct_ty) as uint;
1614         if n_elts == 0 {
1615             return ~[];
1616         }
1617         let mut elts = vec::from_elem(n_elts, ptr::null());
1618         llvm::LLVMGetStructElementTypes(
1619             struct_ty, ptr::to_mut_unsafe_ptr(&mut elts[0]));
1620         return elts;
1621     }
1622 }
1623
1624
1625 /* Memory-managed interface to target data. */
1626
1627 pub struct target_data_res {
1628     TD: TargetDataRef,
1629 }
1630
1631 impl Drop for target_data_res {
1632     fn finalize(&self) {
1633         unsafe {
1634             llvm::LLVMDisposeTargetData(self.TD);
1635         }
1636     }
1637 }
1638
1639 pub fn target_data_res(TD: TargetDataRef) -> target_data_res {
1640     target_data_res {
1641         TD: TD
1642     }
1643 }
1644
1645 pub struct TargetData {
1646     lltd: TargetDataRef,
1647     dtor: @target_data_res
1648 }
1649
1650 pub fn mk_target_data(string_rep: ~str) -> TargetData {
1651     let lltd =
1652         str::as_c_str(string_rep, |buf| unsafe {
1653             llvm::LLVMCreateTargetData(buf)
1654         });
1655
1656     TargetData {
1657         lltd: lltd,
1658         dtor: @target_data_res(lltd)
1659     }
1660 }
1661
1662 /* Memory-managed interface to pass managers. */
1663
1664 pub struct pass_manager_res {
1665     PM: PassManagerRef,
1666 }
1667
1668 impl Drop for pass_manager_res {
1669     fn finalize(&self) {
1670         unsafe {
1671             llvm::LLVMDisposePassManager(self.PM);
1672         }
1673     }
1674 }
1675
1676 pub fn pass_manager_res(PM: PassManagerRef) -> pass_manager_res {
1677     pass_manager_res {
1678         PM: PM
1679     }
1680 }
1681
1682 pub struct PassManager {
1683     llpm: PassManagerRef,
1684     dtor: @pass_manager_res
1685 }
1686
1687 pub fn mk_pass_manager() -> PassManager {
1688     unsafe {
1689         let llpm = llvm::LLVMCreatePassManager();
1690
1691         PassManager {
1692             llpm: llpm,
1693             dtor: @pass_manager_res(llpm)
1694         }
1695     }
1696 }
1697
1698 /* Memory-managed interface to object files. */
1699
1700 pub struct object_file_res {
1701     ObjectFile: ObjectFileRef,
1702 }
1703
1704 impl Drop for object_file_res {
1705     fn finalize(&self) {
1706         unsafe {
1707             llvm::LLVMDisposeObjectFile(self.ObjectFile);
1708         }
1709     }
1710 }
1711
1712 pub fn object_file_res(ObjFile: ObjectFileRef) -> object_file_res {
1713     object_file_res {
1714         ObjectFile: ObjFile
1715     }
1716 }
1717
1718 pub struct ObjectFile {
1719     llof: ObjectFileRef,
1720     dtor: @object_file_res
1721 }
1722
1723 pub fn mk_object_file(llmb: MemoryBufferRef) -> Option<ObjectFile> {
1724     unsafe {
1725         let llof = llvm::LLVMCreateObjectFile(llmb);
1726         if llof as int == 0 { return option::None::<ObjectFile>; }
1727
1728         option::Some(ObjectFile {
1729             llof: llof,
1730             dtor: @object_file_res(llof)
1731         })
1732     }
1733 }
1734
1735 /* Memory-managed interface to section iterators. */
1736
1737 pub struct section_iter_res {
1738     SI: SectionIteratorRef,
1739 }
1740
1741 impl Drop for section_iter_res {
1742     fn finalize(&self) {
1743         unsafe {
1744             llvm::LLVMDisposeSectionIterator(self.SI);
1745         }
1746     }
1747 }
1748
1749 pub fn section_iter_res(SI: SectionIteratorRef) -> section_iter_res {
1750     section_iter_res {
1751         SI: SI
1752     }
1753 }
1754
1755 pub struct SectionIter {
1756     llsi: SectionIteratorRef,
1757     dtor: @section_iter_res
1758 }
1759
1760 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
1761     unsafe {
1762         let llsi = llvm::LLVMGetSections(llof);
1763         SectionIter {
1764             llsi: llsi,
1765             dtor: @section_iter_res(llsi)
1766         }
1767     }
1768 }
1769
1770 //
1771 // Local Variables:
1772 // mode: rust
1773 // fill-column: 78;
1774 // indent-tabs-mode: nil
1775 // c-basic-offset: 4
1776 // buffer-file-coding-system: utf-8-unix
1777 // End:
1778 //