]> git.lizzy.rs Git - rust.git/blob - src/librustc_codegen_llvm/llvm/ffi.rs
Rollup merge of #58273 - taiki-e:rename-dependency, r=matthewjasper
[rust.git] / src / librustc_codegen_llvm / llvm / ffi.rs
1 use super::debuginfo::{
2     DIBuilder, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
3     DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
4     DIGlobalVariableExpression, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
5     DINameSpace, DIFlags, DISPFlags, DebugEmissionKind,
6 };
7
8 use libc::{c_uint, c_int, size_t, c_char};
9 use libc::{c_ulonglong, c_void};
10
11 use std::marker::PhantomData;
12 use syntax;
13 use rustc_codegen_ssa;
14
15 use super::RustString;
16
17 pub type Bool = c_uint;
18
19 pub const True: Bool = 1 as Bool;
20 pub const False: Bool = 0 as Bool;
21
22 #[derive(Copy, Clone, PartialEq)]
23 #[repr(C)]
24 #[allow(dead_code)] // Variants constructed by C++.
25 pub enum LLVMRustResult {
26     Success,
27     Failure,
28 }
29 // Consts for the LLVM CallConv type, pre-cast to usize.
30
31 /// LLVM CallingConv::ID. Should we wrap this?
32 #[derive(Copy, Clone, PartialEq, Debug)]
33 #[repr(C)]
34 pub enum CallConv {
35     CCallConv = 0,
36     FastCallConv = 8,
37     ColdCallConv = 9,
38     X86StdcallCallConv = 64,
39     X86FastcallCallConv = 65,
40     ArmAapcsCallConv = 67,
41     Msp430Intr = 69,
42     X86_ThisCall = 70,
43     PtxKernel = 71,
44     X86_64_SysV = 78,
45     X86_64_Win64 = 79,
46     X86_VectorCall = 80,
47     X86_Intr = 83,
48     AmdGpuKernel = 91,
49 }
50
51 /// LLVMRustLinkage
52 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
53 #[repr(C)]
54 pub enum Linkage {
55     ExternalLinkage = 0,
56     AvailableExternallyLinkage = 1,
57     LinkOnceAnyLinkage = 2,
58     LinkOnceODRLinkage = 3,
59     WeakAnyLinkage = 4,
60     WeakODRLinkage = 5,
61     AppendingLinkage = 6,
62     InternalLinkage = 7,
63     PrivateLinkage = 8,
64     ExternalWeakLinkage = 9,
65     CommonLinkage = 10,
66 }
67
68 // LLVMRustVisibility
69 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
70 #[repr(C)]
71 pub enum Visibility {
72     Default = 0,
73     Hidden = 1,
74     Protected = 2,
75 }
76
77 /// LLVMDLLStorageClass
78 #[derive(Copy, Clone)]
79 #[repr(C)]
80 pub enum DLLStorageClass {
81     #[allow(dead_code)]
82     Default = 0,
83     DllImport = 1, // Function to be imported from DLL.
84     #[allow(dead_code)]
85     DllExport = 2, // Function to be accessible from DLL.
86 }
87
88 /// Matches LLVMRustAttribute in rustllvm.h
89 /// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
90 /// though it is not ABI compatible (since it's a C++ enum)
91 #[repr(C)]
92 #[derive(Copy, Clone, Debug)]
93 pub enum Attribute {
94     AlwaysInline    = 0,
95     ByVal           = 1,
96     Cold            = 2,
97     InlineHint      = 3,
98     MinSize         = 4,
99     Naked           = 5,
100     NoAlias         = 6,
101     NoCapture       = 7,
102     NoInline        = 8,
103     NonNull         = 9,
104     NoRedZone       = 10,
105     NoReturn        = 11,
106     NoUnwind        = 12,
107     OptimizeForSize = 13,
108     ReadOnly        = 14,
109     SExt            = 15,
110     StructRet       = 16,
111     UWTable         = 17,
112     ZExt            = 18,
113     InReg           = 19,
114     SanitizeThread  = 20,
115     SanitizeAddress = 21,
116     SanitizeMemory  = 22,
117     NonLazyBind     = 23,
118     OptimizeNone    = 24,
119 }
120
121 /// LLVMIntPredicate
122 #[derive(Copy, Clone)]
123 #[repr(C)]
124 pub enum IntPredicate {
125     IntEQ = 32,
126     IntNE = 33,
127     IntUGT = 34,
128     IntUGE = 35,
129     IntULT = 36,
130     IntULE = 37,
131     IntSGT = 38,
132     IntSGE = 39,
133     IntSLT = 40,
134     IntSLE = 41,
135 }
136
137 impl IntPredicate {
138     pub fn from_generic(intpre: rustc_codegen_ssa::common::IntPredicate) -> Self {
139         match intpre {
140             rustc_codegen_ssa::common::IntPredicate::IntEQ => IntPredicate::IntEQ,
141             rustc_codegen_ssa::common::IntPredicate::IntNE => IntPredicate::IntNE,
142             rustc_codegen_ssa::common::IntPredicate::IntUGT => IntPredicate::IntUGT,
143             rustc_codegen_ssa::common::IntPredicate::IntUGE => IntPredicate::IntUGE,
144             rustc_codegen_ssa::common::IntPredicate::IntULT => IntPredicate::IntULT,
145             rustc_codegen_ssa::common::IntPredicate::IntULE => IntPredicate::IntULE,
146             rustc_codegen_ssa::common::IntPredicate::IntSGT => IntPredicate::IntSGT,
147             rustc_codegen_ssa::common::IntPredicate::IntSGE => IntPredicate::IntSGE,
148             rustc_codegen_ssa::common::IntPredicate::IntSLT => IntPredicate::IntSLT,
149             rustc_codegen_ssa::common::IntPredicate::IntSLE => IntPredicate::IntSLE,
150         }
151     }
152 }
153
154 /// LLVMRealPredicate
155 #[derive(Copy, Clone)]
156 #[repr(C)]
157 pub enum RealPredicate {
158     RealPredicateFalse = 0,
159     RealOEQ = 1,
160     RealOGT = 2,
161     RealOGE = 3,
162     RealOLT = 4,
163     RealOLE = 5,
164     RealONE = 6,
165     RealORD = 7,
166     RealUNO = 8,
167     RealUEQ = 9,
168     RealUGT = 10,
169     RealUGE = 11,
170     RealULT = 12,
171     RealULE = 13,
172     RealUNE = 14,
173     RealPredicateTrue = 15,
174 }
175
176 impl RealPredicate {
177     pub fn from_generic(realpred: rustc_codegen_ssa::common::RealPredicate) -> Self {
178         match realpred {
179             rustc_codegen_ssa::common::RealPredicate::RealPredicateFalse =>
180                 RealPredicate::RealPredicateFalse,
181             rustc_codegen_ssa::common::RealPredicate::RealOEQ => RealPredicate::RealOEQ,
182             rustc_codegen_ssa::common::RealPredicate::RealOGT => RealPredicate::RealOGT,
183             rustc_codegen_ssa::common::RealPredicate::RealOGE => RealPredicate::RealOGE,
184             rustc_codegen_ssa::common::RealPredicate::RealOLT => RealPredicate::RealOLT,
185             rustc_codegen_ssa::common::RealPredicate::RealOLE => RealPredicate::RealOLE,
186             rustc_codegen_ssa::common::RealPredicate::RealONE => RealPredicate::RealONE,
187             rustc_codegen_ssa::common::RealPredicate::RealORD => RealPredicate::RealORD,
188             rustc_codegen_ssa::common::RealPredicate::RealUNO => RealPredicate::RealUNO,
189             rustc_codegen_ssa::common::RealPredicate::RealUEQ => RealPredicate::RealUEQ,
190             rustc_codegen_ssa::common::RealPredicate::RealUGT => RealPredicate::RealUGT,
191             rustc_codegen_ssa::common::RealPredicate::RealUGE => RealPredicate::RealUGE,
192             rustc_codegen_ssa::common::RealPredicate::RealULT => RealPredicate::RealULT,
193             rustc_codegen_ssa::common::RealPredicate::RealULE => RealPredicate::RealULE,
194             rustc_codegen_ssa::common::RealPredicate::RealUNE => RealPredicate::RealUNE,
195             rustc_codegen_ssa::common::RealPredicate::RealPredicateTrue =>
196                 RealPredicate::RealPredicateTrue
197         }
198     }
199 }
200
201 /// LLVMTypeKind
202 #[derive(Copy, Clone, PartialEq, Debug)]
203 #[repr(C)]
204 pub enum TypeKind {
205     Void = 0,
206     Half = 1,
207     Float = 2,
208     Double = 3,
209     X86_FP80 = 4,
210     FP128 = 5,
211     PPC_FP128 = 6,
212     Label = 7,
213     Integer = 8,
214     Function = 9,
215     Struct = 10,
216     Array = 11,
217     Pointer = 12,
218     Vector = 13,
219     Metadata = 14,
220     X86_MMX = 15,
221     Token = 16,
222 }
223
224 impl TypeKind {
225     pub fn to_generic(self) -> rustc_codegen_ssa::common::TypeKind {
226         match self {
227             TypeKind::Void => rustc_codegen_ssa::common::TypeKind::Void,
228             TypeKind::Half => rustc_codegen_ssa::common::TypeKind::Half,
229             TypeKind::Float => rustc_codegen_ssa::common::TypeKind::Float,
230             TypeKind::Double => rustc_codegen_ssa::common::TypeKind::Double,
231             TypeKind::X86_FP80 => rustc_codegen_ssa::common::TypeKind::X86_FP80,
232             TypeKind::FP128 => rustc_codegen_ssa::common::TypeKind::FP128,
233             TypeKind::PPC_FP128 => rustc_codegen_ssa::common::TypeKind::PPC_FP128,
234             TypeKind::Label => rustc_codegen_ssa::common::TypeKind::Label,
235             TypeKind::Integer => rustc_codegen_ssa::common::TypeKind::Integer,
236             TypeKind::Function => rustc_codegen_ssa::common::TypeKind::Function,
237             TypeKind::Struct => rustc_codegen_ssa::common::TypeKind::Struct,
238             TypeKind::Array => rustc_codegen_ssa::common::TypeKind::Array,
239             TypeKind::Pointer => rustc_codegen_ssa::common::TypeKind::Pointer,
240             TypeKind::Vector => rustc_codegen_ssa::common::TypeKind::Vector,
241             TypeKind::Metadata => rustc_codegen_ssa::common::TypeKind::Metadata,
242             TypeKind::X86_MMX => rustc_codegen_ssa::common::TypeKind::X86_MMX,
243             TypeKind::Token => rustc_codegen_ssa::common::TypeKind::Token,
244         }
245     }
246 }
247
248 /// LLVMAtomicRmwBinOp
249 #[derive(Copy, Clone)]
250 #[repr(C)]
251 pub enum AtomicRmwBinOp {
252     AtomicXchg = 0,
253     AtomicAdd = 1,
254     AtomicSub = 2,
255     AtomicAnd = 3,
256     AtomicNand = 4,
257     AtomicOr = 5,
258     AtomicXor = 6,
259     AtomicMax = 7,
260     AtomicMin = 8,
261     AtomicUMax = 9,
262     AtomicUMin = 10,
263 }
264
265 impl AtomicRmwBinOp {
266     pub fn from_generic(op: rustc_codegen_ssa::common::AtomicRmwBinOp) -> Self {
267         match op {
268             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXchg => AtomicRmwBinOp::AtomicXchg,
269             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAdd => AtomicRmwBinOp::AtomicAdd,
270             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicSub => AtomicRmwBinOp::AtomicSub,
271             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicAnd => AtomicRmwBinOp::AtomicAnd,
272             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicNand => AtomicRmwBinOp::AtomicNand,
273             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicOr => AtomicRmwBinOp::AtomicOr,
274             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicXor => AtomicRmwBinOp::AtomicXor,
275             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMax => AtomicRmwBinOp::AtomicMax,
276             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicMin => AtomicRmwBinOp::AtomicMin,
277             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMax => AtomicRmwBinOp::AtomicUMax,
278             rustc_codegen_ssa::common::AtomicRmwBinOp::AtomicUMin => AtomicRmwBinOp::AtomicUMin
279         }
280     }
281 }
282
283 /// LLVMAtomicOrdering
284 #[derive(Copy, Clone)]
285 #[repr(C)]
286 pub enum AtomicOrdering {
287     #[allow(dead_code)]
288     NotAtomic = 0,
289     Unordered = 1,
290     Monotonic = 2,
291     // Consume = 3,  // Not specified yet.
292     Acquire = 4,
293     Release = 5,
294     AcquireRelease = 6,
295     SequentiallyConsistent = 7,
296 }
297
298 impl AtomicOrdering {
299     pub fn from_generic(ao: rustc_codegen_ssa::common::AtomicOrdering) -> Self {
300         match ao {
301             rustc_codegen_ssa::common::AtomicOrdering::NotAtomic => AtomicOrdering::NotAtomic,
302             rustc_codegen_ssa::common::AtomicOrdering::Unordered => AtomicOrdering::Unordered,
303             rustc_codegen_ssa::common::AtomicOrdering::Monotonic => AtomicOrdering::Monotonic,
304             rustc_codegen_ssa::common::AtomicOrdering::Acquire => AtomicOrdering::Acquire,
305             rustc_codegen_ssa::common::AtomicOrdering::Release => AtomicOrdering::Release,
306             rustc_codegen_ssa::common::AtomicOrdering::AcquireRelease =>
307                 AtomicOrdering::AcquireRelease,
308             rustc_codegen_ssa::common::AtomicOrdering::SequentiallyConsistent =>
309                 AtomicOrdering::SequentiallyConsistent
310         }
311     }
312 }
313
314
315 /// LLVMRustSynchronizationScope
316 #[derive(Copy, Clone)]
317 #[repr(C)]
318 pub enum SynchronizationScope {
319     // FIXME: figure out if this variant is needed at all.
320     #[allow(dead_code)]
321     Other,
322     SingleThread,
323     CrossThread,
324 }
325
326 impl SynchronizationScope {
327     pub fn from_generic(sc: rustc_codegen_ssa::common::SynchronizationScope) -> Self {
328         match sc {
329             rustc_codegen_ssa::common::SynchronizationScope::Other => SynchronizationScope::Other,
330             rustc_codegen_ssa::common::SynchronizationScope::SingleThread =>
331                 SynchronizationScope::SingleThread,
332             rustc_codegen_ssa::common::SynchronizationScope::CrossThread =>
333                 SynchronizationScope::CrossThread,
334         }
335     }
336 }
337
338 /// LLVMRustFileType
339 #[derive(Copy, Clone)]
340 #[repr(C)]
341 pub enum FileType {
342     // FIXME: figure out if this variant is needed at all.
343     #[allow(dead_code)]
344     Other,
345     AssemblyFile,
346     ObjectFile,
347 }
348
349 /// LLVMMetadataType
350 #[derive(Copy, Clone)]
351 #[repr(C)]
352 pub enum MetadataType {
353     MD_dbg = 0,
354     MD_tbaa = 1,
355     MD_prof = 2,
356     MD_fpmath = 3,
357     MD_range = 4,
358     MD_tbaa_struct = 5,
359     MD_invariant_load = 6,
360     MD_alias_scope = 7,
361     MD_noalias = 8,
362     MD_nontemporal = 9,
363     MD_mem_parallel_loop_access = 10,
364     MD_nonnull = 11,
365 }
366
367 /// LLVMRustAsmDialect
368 #[derive(Copy, Clone)]
369 #[repr(C)]
370 pub enum AsmDialect {
371     // FIXME: figure out if this variant is needed at all.
372     #[allow(dead_code)]
373     Other,
374     Att,
375     Intel,
376 }
377
378 impl AsmDialect {
379     pub fn from_generic(asm: syntax::ast::AsmDialect) -> Self {
380         match asm {
381             syntax::ast::AsmDialect::Att => AsmDialect::Att,
382             syntax::ast::AsmDialect::Intel => AsmDialect::Intel
383         }
384     }
385 }
386
387 /// LLVMRustCodeGenOptLevel
388 #[derive(Copy, Clone, PartialEq)]
389 #[repr(C)]
390 pub enum CodeGenOptLevel {
391     // FIXME: figure out if this variant is needed at all.
392     #[allow(dead_code)]
393     Other,
394     None,
395     Less,
396     Default,
397     Aggressive,
398 }
399
400 /// LLVMRelocMode
401 #[derive(Copy, Clone, PartialEq)]
402 #[repr(C)]
403 pub enum RelocMode {
404     Default,
405     Static,
406     PIC,
407     DynamicNoPic,
408     ROPI,
409     RWPI,
410     ROPI_RWPI,
411 }
412
413 /// LLVMRustCodeModel
414 #[derive(Copy, Clone)]
415 #[repr(C)]
416 pub enum CodeModel {
417     // FIXME: figure out if this variant is needed at all.
418     #[allow(dead_code)]
419     Other,
420     Small,
421     Kernel,
422     Medium,
423     Large,
424     None,
425 }
426
427 /// LLVMRustDiagnosticKind
428 #[derive(Copy, Clone)]
429 #[repr(C)]
430 #[allow(dead_code)] // Variants constructed by C++.
431 pub enum DiagnosticKind {
432     Other,
433     InlineAsm,
434     StackSize,
435     DebugMetadataVersion,
436     SampleProfile,
437     OptimizationRemark,
438     OptimizationRemarkMissed,
439     OptimizationRemarkAnalysis,
440     OptimizationRemarkAnalysisFPCommute,
441     OptimizationRemarkAnalysisAliasing,
442     OptimizationRemarkOther,
443     OptimizationFailure,
444     PGOProfile,
445     Linker,
446 }
447
448 /// LLVMRustArchiveKind
449 #[derive(Copy, Clone)]
450 #[repr(C)]
451 pub enum ArchiveKind {
452     // FIXME: figure out if this variant is needed at all.
453     #[allow(dead_code)]
454     Other,
455     K_GNU,
456     K_BSD,
457     K_COFF,
458 }
459
460 /// LLVMRustPassKind
461 #[derive(Copy, Clone, PartialEq, Debug)]
462 #[repr(C)]
463 #[allow(dead_code)] // Variants constructed by C++.
464 pub enum PassKind {
465     Other,
466     Function,
467     Module,
468 }
469
470 /// LLVMRustThinLTOData
471 extern { pub type ThinLTOData; }
472
473 /// LLVMRustThinLTOBuffer
474 extern { pub type ThinLTOBuffer; }
475
476 // LLVMRustModuleNameCallback
477 pub type ThinLTOModuleNameCallback =
478     unsafe extern "C" fn(*mut c_void, *const c_char, *const c_char);
479
480 /// LLVMRustThinLTOModule
481 #[repr(C)]
482 pub struct ThinLTOModule {
483     pub identifier: *const c_char,
484     pub data: *const u8,
485     pub len: usize,
486 }
487
488 /// LLVMThreadLocalMode
489 #[derive(Copy, Clone)]
490 #[repr(C)]
491 pub enum ThreadLocalMode {
492   NotThreadLocal,
493   GeneralDynamic,
494   LocalDynamic,
495   InitialExec,
496   LocalExec
497 }
498
499 extern { type Opaque; }
500 #[repr(C)]
501 struct InvariantOpaque<'a> {
502     _marker: PhantomData<&'a mut &'a ()>,
503     _opaque: Opaque,
504 }
505
506 // Opaque pointer types
507 extern { pub type Module; }
508 extern { pub type Context; }
509 extern { pub type Type; }
510 extern { pub type Value; }
511 extern { pub type Metadata; }
512 extern { pub type BasicBlock; }
513 #[repr(C)]
514 pub struct Builder<'a>(InvariantOpaque<'a>);
515 extern { pub type MemoryBuffer; }
516 #[repr(C)]
517 pub struct PassManager<'a>(InvariantOpaque<'a>);
518 extern { pub type PassManagerBuilder; }
519 extern { pub type ObjectFile; }
520 #[repr(C)]
521 pub struct SectionIterator<'a>(InvariantOpaque<'a>);
522 extern { pub type Pass; }
523 extern { pub type TargetMachine; }
524 extern { pub type Archive; }
525 #[repr(C)]
526 pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
527 #[repr(C)]
528 pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
529 extern { pub type Twine; }
530 extern { pub type DiagnosticInfo; }
531 extern { pub type SMDiagnostic; }
532 #[repr(C)]
533 pub struct RustArchiveMember<'a>(InvariantOpaque<'a>);
534 #[repr(C)]
535 pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
536 #[repr(C)]
537 pub struct Linker<'a>(InvariantOpaque<'a>);
538
539 pub type DiagnosticHandler = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
540 pub type InlineAsmDiagHandler = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
541
542
543 pub mod debuginfo {
544     use super::{InvariantOpaque, Metadata};
545
546     #[repr(C)]
547     pub struct DIBuilder<'a>(InvariantOpaque<'a>);
548
549     pub type DIDescriptor = Metadata;
550     pub type DIScope = DIDescriptor;
551     pub type DIFile = DIScope;
552     pub type DILexicalBlock = DIScope;
553     pub type DISubprogram = DIScope;
554     pub type DINameSpace = DIScope;
555     pub type DIType = DIDescriptor;
556     pub type DIBasicType = DIType;
557     pub type DIDerivedType = DIType;
558     pub type DICompositeType = DIDerivedType;
559     pub type DIVariable = DIDescriptor;
560     pub type DIGlobalVariableExpression = DIDescriptor;
561     pub type DIArray = DIDescriptor;
562     pub type DISubrange = DIDescriptor;
563     pub type DIEnumerator = DIDescriptor;
564     pub type DITemplateTypeParameter = DIDescriptor;
565
566     // These values **must** match with LLVMRustDIFlags!!
567     bitflags! {
568         #[repr(C)]
569         #[derive(Default)]
570         pub struct DIFlags: ::libc::uint32_t {
571             const FlagZero                = 0;
572             const FlagPrivate             = 1;
573             const FlagProtected           = 2;
574             const FlagPublic              = 3;
575             const FlagFwdDecl             = (1 << 2);
576             const FlagAppleBlock          = (1 << 3);
577             const FlagBlockByrefStruct    = (1 << 4);
578             const FlagVirtual             = (1 << 5);
579             const FlagArtificial          = (1 << 6);
580             const FlagExplicit            = (1 << 7);
581             const FlagPrototyped          = (1 << 8);
582             const FlagObjcClassComplete   = (1 << 9);
583             const FlagObjectPointer       = (1 << 10);
584             const FlagVector              = (1 << 11);
585             const FlagStaticMember        = (1 << 12);
586             const FlagLValueReference     = (1 << 13);
587             const FlagRValueReference     = (1 << 14);
588             const FlagExternalTypeRef     = (1 << 15);
589             const FlagIntroducedVirtual   = (1 << 18);
590             const FlagBitField            = (1 << 19);
591             const FlagNoReturn            = (1 << 20);
592             const FlagMainSubprogram      = (1 << 21);
593         }
594     }
595
596     // These values **must** match with LLVMRustDISPFlags!!
597     bitflags! {
598         #[repr(C)]
599         #[derive(Default)]
600         pub struct DISPFlags: ::libc::uint32_t {
601             const SPFlagZero              = 0;
602             const SPFlagVirtual           = 1;
603             const SPFlagPureVirtual       = 2;
604             const SPFlagLocalToUnit       = (1 << 2);
605             const SPFlagDefinition        = (1 << 3);
606             const SPFlagOptimized         = (1 << 4);
607         }
608     }
609
610     /// LLVMRustDebugEmissionKind
611     #[derive(Copy, Clone)]
612     #[repr(C)]
613     pub enum DebugEmissionKind {
614         NoDebug,
615         FullDebug,
616         LineTablesOnly,
617     }
618
619     impl DebugEmissionKind {
620         pub fn from_generic(kind: rustc::session::config::DebugInfo) -> Self {
621             use rustc::session::config::DebugInfo;
622             match kind {
623                 DebugInfo::None => DebugEmissionKind::NoDebug,
624                 DebugInfo::Limited => DebugEmissionKind::LineTablesOnly,
625                 DebugInfo::Full => DebugEmissionKind::FullDebug,
626             }
627         }
628     }
629 }
630
631 extern { pub type ModuleBuffer; }
632
633 extern "C" {
634     pub fn LLVMRustInstallFatalErrorHandler();
635
636     // Create and destroy contexts.
637     pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> &'static mut Context;
638     pub fn LLVMContextDispose(C: &'static mut Context);
639     pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint;
640
641     // Create modules.
642     pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char, C: &Context) -> &Module;
643     pub fn LLVMGetModuleContext(M: &Module) -> &Context;
644     pub fn LLVMCloneModule(M: &Module) -> &Module;
645
646     /// Data layout. See Module::getDataLayout.
647     pub fn LLVMGetDataLayout(M: &Module) -> *const c_char;
648     pub fn LLVMSetDataLayout(M: &Module, Triple: *const c_char);
649
650     /// See Module::setModuleInlineAsm.
651     pub fn LLVMSetModuleInlineAsm(M: &Module, Asm: *const c_char);
652     pub fn LLVMRustAppendModuleInlineAsm(M: &Module, Asm: *const c_char);
653
654     /// See llvm::LLVMTypeKind::getTypeID.
655     pub fn LLVMRustGetTypeKind(Ty: &Type) -> TypeKind;
656
657     // Operations on integer types
658     pub fn LLVMInt1TypeInContext(C: &Context) -> &Type;
659     pub fn LLVMInt8TypeInContext(C: &Context) -> &Type;
660     pub fn LLVMInt16TypeInContext(C: &Context) -> &Type;
661     pub fn LLVMInt32TypeInContext(C: &Context) -> &Type;
662     pub fn LLVMInt64TypeInContext(C: &Context) -> &Type;
663     pub fn LLVMIntTypeInContext(C: &Context, NumBits: c_uint) -> &Type;
664
665     pub fn LLVMGetIntTypeWidth(IntegerTy: &Type) -> c_uint;
666
667     // Operations on real types
668     pub fn LLVMFloatTypeInContext(C: &Context) -> &Type;
669     pub fn LLVMDoubleTypeInContext(C: &Context) -> &Type;
670
671     // Operations on function types
672     pub fn LLVMFunctionType(ReturnType: &'a Type,
673                             ParamTypes: *const &'a Type,
674                             ParamCount: c_uint,
675                             IsVarArg: Bool)
676                             -> &'a Type;
677     pub fn LLVMCountParamTypes(FunctionTy: &Type) -> c_uint;
678     pub fn LLVMGetParamTypes(FunctionTy: &'a Type, Dest: *mut &'a Type);
679
680     // Operations on struct types
681     pub fn LLVMStructTypeInContext(C: &'a Context,
682                                    ElementTypes: *const &'a Type,
683                                    ElementCount: c_uint,
684                                    Packed: Bool)
685                                    -> &'a Type;
686
687     // Operations on array, pointer, and vector types (sequence types)
688     pub fn LLVMRustArrayType(ElementType: &Type, ElementCount: u64) -> &Type;
689     pub fn LLVMPointerType(ElementType: &Type, AddressSpace: c_uint) -> &Type;
690     pub fn LLVMVectorType(ElementType: &Type, ElementCount: c_uint) -> &Type;
691
692     pub fn LLVMGetElementType(Ty: &Type) -> &Type;
693     pub fn LLVMGetVectorSize(VectorTy: &Type) -> c_uint;
694
695     // Operations on other types
696     pub fn LLVMVoidTypeInContext(C: &Context) -> &Type;
697     pub fn LLVMX86MMXTypeInContext(C: &Context) -> &Type;
698     pub fn LLVMRustMetadataTypeInContext(C: &Context) -> &Type;
699
700     // Operations on all values
701     pub fn LLVMTypeOf(Val: &Value) -> &Type;
702     pub fn LLVMGetValueName(Val: &Value) -> *const c_char;
703     pub fn LLVMSetValueName(Val: &Value, Name: *const c_char);
704     pub fn LLVMReplaceAllUsesWith(OldVal: &'a Value, NewVal: &'a Value);
705     pub fn LLVMSetMetadata(Val: &'a Value, KindID: c_uint, Node: &'a Value);
706
707     // Operations on constants of any type
708     pub fn LLVMConstNull(Ty: &Type) -> &Value;
709     pub fn LLVMGetUndef(Ty: &Type) -> &Value;
710
711     // Operations on metadata
712     pub fn LLVMMDStringInContext(C: &Context, Str: *const c_char, SLen: c_uint) -> &Value;
713     pub fn LLVMMDNodeInContext(C: &'a Context, Vals: *const &'a Value, Count: c_uint) -> &'a Value;
714     pub fn LLVMAddNamedMetadataOperand(M: &'a Module, Name: *const c_char, Val: &'a Value);
715
716     // Operations on scalar constants
717     pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
718     pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
719     pub fn LLVMConstIntGetZExtValue(ConstantVal: &Value) -> c_ulonglong;
720     pub fn LLVMRustConstInt128Get(ConstantVal: &Value, SExt: bool,
721                                   high: &mut u64, low: &mut u64) -> bool;
722     pub fn LLVMConstRealGetDouble (ConstantVal: &Value, losesInfo: &mut Bool) -> f64;
723
724
725     // Operations on composite constants
726     pub fn LLVMConstStringInContext(C: &Context,
727                                     Str: *const c_char,
728                                     Length: c_uint,
729                                     DontNullTerminate: Bool)
730                                     -> &Value;
731     pub fn LLVMConstStructInContext(C: &'a Context,
732                                     ConstantVals: *const &'a Value,
733                                     Count: c_uint,
734                                     Packed: Bool)
735                                     -> &'a Value;
736
737     pub fn LLVMConstArray(ElementTy: &'a Type,
738                           ConstantVals: *const &'a Value,
739                           Length: c_uint)
740                           -> &'a Value;
741     pub fn LLVMConstVector(ScalarConstantVals: *const &Value, Size: c_uint) -> &Value;
742
743     // Constant expressions
744     pub fn LLVMConstInBoundsGEP(
745         ConstantVal: &'a Value,
746         ConstantIndices: *const &'a Value,
747         NumIndices: c_uint,
748     ) -> &'a Value;
749     pub fn LLVMConstZExt(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
750     pub fn LLVMConstPtrToInt(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
751     pub fn LLVMConstIntToPtr(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
752     pub fn LLVMConstBitCast(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
753     pub fn LLVMConstPointerCast(ConstantVal: &'a Value, ToType: &'a Type) -> &'a Value;
754     pub fn LLVMConstExtractValue(AggConstant: &Value,
755                                  IdxList: *const c_uint,
756                                  NumIdx: c_uint)
757                                  -> &Value;
758
759     // Operations on global variables, functions, and aliases (globals)
760     pub fn LLVMIsDeclaration(Global: &Value) -> Bool;
761     pub fn LLVMRustGetLinkage(Global: &Value) -> Linkage;
762     pub fn LLVMRustSetLinkage(Global: &Value, RustLinkage: Linkage);
763     pub fn LLVMSetSection(Global: &Value, Section: *const c_char);
764     pub fn LLVMRustGetVisibility(Global: &Value) -> Visibility;
765     pub fn LLVMRustSetVisibility(Global: &Value, Viz: Visibility);
766     pub fn LLVMGetAlignment(Global: &Value) -> c_uint;
767     pub fn LLVMSetAlignment(Global: &Value, Bytes: c_uint);
768     pub fn LLVMSetDLLStorageClass(V: &Value, C: DLLStorageClass);
769
770
771     // Operations on global variables
772     pub fn LLVMIsAGlobalVariable(GlobalVar: &Value) -> Option<&Value>;
773     pub fn LLVMAddGlobal(M: &'a Module, Ty: &'a Type, Name: *const c_char) -> &'a Value;
774     pub fn LLVMGetNamedGlobal(M: &Module, Name: *const c_char) -> Option<&Value>;
775     pub fn LLVMRustGetOrInsertGlobal(M: &'a Module, Name: *const c_char, T: &'a Type) -> &'a Value;
776     pub fn LLVMRustInsertPrivateGlobal(M: &'a Module, T: &'a Type) -> &'a Value;
777     pub fn LLVMGetFirstGlobal(M: &Module) -> Option<&Value>;
778     pub fn LLVMGetNextGlobal(GlobalVar: &Value) -> Option<&Value>;
779     pub fn LLVMDeleteGlobal(GlobalVar: &Value);
780     pub fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;
781     pub fn LLVMSetInitializer(GlobalVar: &'a Value, ConstantVal: &'a Value);
782     pub fn LLVMSetThreadLocal(GlobalVar: &Value, IsThreadLocal: Bool);
783     pub fn LLVMSetThreadLocalMode(GlobalVar: &Value, Mode: ThreadLocalMode);
784     pub fn LLVMIsGlobalConstant(GlobalVar: &Value) -> Bool;
785     pub fn LLVMSetGlobalConstant(GlobalVar: &Value, IsConstant: Bool);
786     pub fn LLVMRustGetNamedValue(M: &Module, Name: *const c_char) -> Option<&Value>;
787     pub fn LLVMSetTailCall(CallInst: &Value, IsTailCall: Bool);
788
789     // Operations on functions
790     pub fn LLVMRustGetOrInsertFunction(M: &'a Module,
791                                        Name: *const c_char,
792                                        FunctionTy: &'a Type)
793                                        -> &'a Value;
794     pub fn LLVMSetFunctionCallConv(Fn: &Value, CC: c_uint);
795     pub fn LLVMRustAddAlignmentAttr(Fn: &Value, index: c_uint, bytes: u32);
796     pub fn LLVMRustAddDereferenceableAttr(Fn: &Value, index: c_uint, bytes: u64);
797     pub fn LLVMRustAddDereferenceableOrNullAttr(Fn: &Value, index: c_uint, bytes: u64);
798     pub fn LLVMRustAddFunctionAttribute(Fn: &Value, index: c_uint, attr: Attribute);
799     pub fn LLVMRustAddFunctionAttrStringValue(Fn: &Value,
800                                               index: c_uint,
801                                               Name: *const c_char,
802                                               Value: *const c_char);
803     pub fn LLVMRustRemoveFunctionAttributes(Fn: &Value, index: c_uint, attr: Attribute);
804
805     // Operations on parameters
806     pub fn LLVMCountParams(Fn: &Value) -> c_uint;
807     pub fn LLVMGetParam(Fn: &Value, Index: c_uint) -> &Value;
808
809     // Operations on basic blocks
810     pub fn LLVMGetBasicBlockParent(BB: &BasicBlock) -> &Value;
811     pub fn LLVMAppendBasicBlockInContext(C: &'a Context,
812                                          Fn: &'a Value,
813                                          Name: *const c_char)
814                                          -> &'a BasicBlock;
815     pub fn LLVMDeleteBasicBlock(BB: &BasicBlock);
816
817     // Operations on instructions
818     pub fn LLVMGetFirstBasicBlock(Fn: &Value) -> &BasicBlock;
819
820     // Operations on call sites
821     pub fn LLVMSetInstructionCallConv(Instr: &Value, CC: c_uint);
822     pub fn LLVMRustAddCallSiteAttribute(Instr: &Value, index: c_uint, attr: Attribute);
823     pub fn LLVMRustAddAlignmentCallSiteAttr(Instr: &Value, index: c_uint, bytes: u32);
824     pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: &Value, index: c_uint, bytes: u64);
825     pub fn LLVMRustAddDereferenceableOrNullCallSiteAttr(Instr: &Value,
826                                                         index: c_uint,
827                                                         bytes: u64);
828
829     // Operations on load/store instructions (only)
830     pub fn LLVMSetVolatile(MemoryAccessInst: &Value, volatile: Bool);
831
832     // Operations on phi nodes
833     pub fn LLVMAddIncoming(PhiNode: &'a Value,
834                            IncomingValues: *const &'a Value,
835                            IncomingBlocks: *const &'a BasicBlock,
836                            Count: c_uint);
837
838     // Instruction builders
839     pub fn LLVMCreateBuilderInContext(C: &'a Context) -> &'a mut Builder<'a>;
840     pub fn LLVMPositionBuilderAtEnd(Builder: &Builder<'a>, Block: &'a BasicBlock);
841     pub fn LLVMGetInsertBlock(Builder: &Builder<'a>) -> &'a BasicBlock;
842     pub fn LLVMDisposeBuilder(Builder: &'a mut Builder<'a>);
843
844     // Metadata
845     pub fn LLVMSetCurrentDebugLocation(Builder: &Builder<'a>, L: Option<&'a Value>);
846     pub fn LLVMGetCurrentDebugLocation(Builder: &Builder<'a>) -> &'a Value;
847     pub fn LLVMSetInstDebugLocation(Builder: &Builder<'a>, Inst: &'a Value);
848
849     // Terminators
850     pub fn LLVMBuildRetVoid(B: &Builder<'a>) -> &'a Value;
851     pub fn LLVMBuildRet(B: &Builder<'a>, V: &'a Value) -> &'a Value;
852     pub fn LLVMBuildBr(B: &Builder<'a>, Dest: &'a BasicBlock) -> &'a Value;
853     pub fn LLVMBuildCondBr(B: &Builder<'a>,
854                            If: &'a Value,
855                            Then: &'a BasicBlock,
856                            Else: &'a BasicBlock)
857                            -> &'a Value;
858     pub fn LLVMBuildSwitch(B: &Builder<'a>,
859                            V: &'a Value,
860                            Else: &'a BasicBlock,
861                            NumCases: c_uint)
862                            -> &'a Value;
863     pub fn LLVMRustBuildInvoke(B: &Builder<'a>,
864                                Fn: &'a Value,
865                                Args: *const &'a Value,
866                                NumArgs: c_uint,
867                                Then: &'a BasicBlock,
868                                Catch: &'a BasicBlock,
869                                Bundle: Option<&OperandBundleDef<'a>>,
870                                Name: *const c_char)
871                                -> &'a Value;
872     pub fn LLVMBuildLandingPad(B: &Builder<'a>,
873                                Ty: &'a Type,
874                                PersFn: &'a Value,
875                                NumClauses: c_uint,
876                                Name: *const c_char)
877                                -> &'a Value;
878     pub fn LLVMBuildResume(B: &Builder<'a>, Exn: &'a Value) -> &'a Value;
879     pub fn LLVMBuildUnreachable(B: &Builder<'a>) -> &'a Value;
880
881     pub fn LLVMRustBuildCleanupPad(B: &Builder<'a>,
882                                    ParentPad: Option<&'a Value>,
883                                    ArgCnt: c_uint,
884                                    Args: *const &'a Value,
885                                    Name: *const c_char)
886                                    -> Option<&'a Value>;
887     pub fn LLVMRustBuildCleanupRet(B: &Builder<'a>,
888                                    CleanupPad: &'a Value,
889                                    UnwindBB: Option<&'a BasicBlock>)
890                                    -> Option<&'a Value>;
891     pub fn LLVMRustBuildCatchPad(B: &Builder<'a>,
892                                  ParentPad: &'a Value,
893                                  ArgCnt: c_uint,
894                                  Args: *const &'a Value,
895                                  Name: *const c_char)
896                                  -> Option<&'a Value>;
897     pub fn LLVMRustBuildCatchRet(
898         B: &Builder<'a>,
899         Pad: &'a Value,
900         BB: &'a BasicBlock,
901     ) -> Option<&'a Value>;
902     pub fn LLVMRustBuildCatchSwitch(Builder: &Builder<'a>,
903                                     ParentPad: Option<&'a Value>,
904                                     BB: Option<&'a BasicBlock>,
905                                     NumHandlers: c_uint,
906                                     Name: *const c_char)
907                                     -> Option<&'a Value>;
908     pub fn LLVMRustAddHandler(CatchSwitch: &'a Value, Handler: &'a BasicBlock);
909     pub fn LLVMSetPersonalityFn(Func: &'a Value, Pers: &'a Value);
910
911     // Add a case to the switch instruction
912     pub fn LLVMAddCase(Switch: &'a Value, OnVal: &'a Value, Dest: &'a BasicBlock);
913
914     // Add a clause to the landing pad instruction
915     pub fn LLVMAddClause(LandingPad: &'a Value, ClauseVal: &'a Value);
916
917     // Set the cleanup on a landing pad instruction
918     pub fn LLVMSetCleanup(LandingPad: &Value, Val: Bool);
919
920     // Arithmetic
921     pub fn LLVMBuildAdd(B: &Builder<'a>,
922                         LHS: &'a Value,
923                         RHS: &'a Value,
924                         Name: *const c_char)
925                         -> &'a Value;
926     pub fn LLVMBuildFAdd(B: &Builder<'a>,
927                          LHS: &'a Value,
928                          RHS: &'a Value,
929                          Name: *const c_char)
930                          -> &'a Value;
931     pub fn LLVMBuildSub(B: &Builder<'a>,
932                         LHS: &'a Value,
933                         RHS: &'a Value,
934                         Name: *const c_char)
935                         -> &'a Value;
936     pub fn LLVMBuildFSub(B: &Builder<'a>,
937                          LHS: &'a Value,
938                          RHS: &'a Value,
939                          Name: *const c_char)
940                          -> &'a Value;
941     pub fn LLVMBuildMul(B: &Builder<'a>,
942                         LHS: &'a Value,
943                         RHS: &'a Value,
944                         Name: *const c_char)
945                         -> &'a Value;
946     pub fn LLVMBuildFMul(B: &Builder<'a>,
947                          LHS: &'a Value,
948                          RHS: &'a Value,
949                          Name: *const c_char)
950                          -> &'a Value;
951     pub fn LLVMBuildUDiv(B: &Builder<'a>,
952                          LHS: &'a Value,
953                          RHS: &'a Value,
954                          Name: *const c_char)
955                          -> &'a Value;
956     pub fn LLVMBuildExactUDiv(B: &Builder<'a>,
957                               LHS: &'a Value,
958                               RHS: &'a Value,
959                               Name: *const c_char)
960                               -> &'a Value;
961     pub fn LLVMBuildSDiv(B: &Builder<'a>,
962                          LHS: &'a Value,
963                          RHS: &'a Value,
964                          Name: *const c_char)
965                          -> &'a Value;
966     pub fn LLVMBuildExactSDiv(B: &Builder<'a>,
967                               LHS: &'a Value,
968                               RHS: &'a Value,
969                               Name: *const c_char)
970                               -> &'a Value;
971     pub fn LLVMBuildFDiv(B: &Builder<'a>,
972                          LHS: &'a Value,
973                          RHS: &'a Value,
974                          Name: *const c_char)
975                          -> &'a Value;
976     pub fn LLVMBuildURem(B: &Builder<'a>,
977                          LHS: &'a Value,
978                          RHS: &'a Value,
979                          Name: *const c_char)
980                          -> &'a Value;
981     pub fn LLVMBuildSRem(B: &Builder<'a>,
982                          LHS: &'a Value,
983                          RHS: &'a Value,
984                          Name: *const c_char)
985                          -> &'a Value;
986     pub fn LLVMBuildFRem(B: &Builder<'a>,
987                          LHS: &'a Value,
988                          RHS: &'a Value,
989                          Name: *const c_char)
990                          -> &'a Value;
991     pub fn LLVMBuildShl(B: &Builder<'a>,
992                         LHS: &'a Value,
993                         RHS: &'a Value,
994                         Name: *const c_char)
995                         -> &'a Value;
996     pub fn LLVMBuildLShr(B: &Builder<'a>,
997                          LHS: &'a Value,
998                          RHS: &'a Value,
999                          Name: *const c_char)
1000                          -> &'a Value;
1001     pub fn LLVMBuildAShr(B: &Builder<'a>,
1002                          LHS: &'a Value,
1003                          RHS: &'a Value,
1004                          Name: *const c_char)
1005                          -> &'a Value;
1006     pub fn LLVMBuildAnd(B: &Builder<'a>,
1007                         LHS: &'a Value,
1008                         RHS: &'a Value,
1009                         Name: *const c_char)
1010                         -> &'a Value;
1011     pub fn LLVMBuildOr(B: &Builder<'a>,
1012                        LHS: &'a Value,
1013                        RHS: &'a Value,
1014                        Name: *const c_char)
1015                        -> &'a Value;
1016     pub fn LLVMBuildXor(B: &Builder<'a>,
1017                         LHS: &'a Value,
1018                         RHS: &'a Value,
1019                         Name: *const c_char)
1020                         -> &'a Value;
1021     pub fn LLVMBuildNeg(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1022     pub fn LLVMBuildFNeg(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1023     pub fn LLVMBuildNot(B: &Builder<'a>, V: &'a Value, Name: *const c_char) -> &'a Value;
1024     pub fn LLVMRustSetHasUnsafeAlgebra(Instr: &Value);
1025
1026     // Memory
1027     pub fn LLVMBuildAlloca(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1028     pub fn LLVMBuildArrayAlloca(B: &Builder<'a>,
1029                                 Ty: &'a Type,
1030                                 Val: &'a Value,
1031                                 Name: *const c_char)
1032                                 -> &'a Value;
1033     pub fn LLVMBuildLoad(B: &Builder<'a>, PointerVal: &'a Value, Name: *const c_char) -> &'a Value;
1034
1035     pub fn LLVMBuildStore(B: &Builder<'a>, Val: &'a Value, Ptr: &'a Value) -> &'a Value;
1036
1037     pub fn LLVMBuildGEP(B: &Builder<'a>,
1038                         Pointer: &'a Value,
1039                         Indices: *const &'a Value,
1040                         NumIndices: c_uint,
1041                         Name: *const c_char)
1042                         -> &'a Value;
1043     pub fn LLVMBuildInBoundsGEP(B: &Builder<'a>,
1044                                 Pointer: &'a Value,
1045                                 Indices: *const &'a Value,
1046                                 NumIndices: c_uint,
1047                                 Name: *const c_char)
1048                                 -> &'a Value;
1049     pub fn LLVMBuildStructGEP(B: &Builder<'a>,
1050                               Pointer: &'a Value,
1051                               Idx: c_uint,
1052                               Name: *const c_char)
1053                               -> &'a Value;
1054
1055     // Casts
1056     pub fn LLVMBuildTrunc(B: &Builder<'a>,
1057                           Val: &'a Value,
1058                           DestTy: &'a Type,
1059                           Name: *const c_char)
1060                           -> &'a Value;
1061     pub fn LLVMBuildZExt(B: &Builder<'a>,
1062                          Val: &'a Value,
1063                          DestTy: &'a Type,
1064                          Name: *const c_char)
1065                          -> &'a Value;
1066     pub fn LLVMBuildSExt(B: &Builder<'a>,
1067                          Val: &'a Value,
1068                          DestTy: &'a Type,
1069                          Name: *const c_char)
1070                          -> &'a Value;
1071     pub fn LLVMBuildFPToUI(B: &Builder<'a>,
1072                            Val: &'a Value,
1073                            DestTy: &'a Type,
1074                            Name: *const c_char)
1075                            -> &'a Value;
1076     pub fn LLVMBuildFPToSI(B: &Builder<'a>,
1077                            Val: &'a Value,
1078                            DestTy: &'a Type,
1079                            Name: *const c_char)
1080                            -> &'a Value;
1081     pub fn LLVMBuildUIToFP(B: &Builder<'a>,
1082                            Val: &'a Value,
1083                            DestTy: &'a Type,
1084                            Name: *const c_char)
1085                            -> &'a Value;
1086     pub fn LLVMBuildSIToFP(B: &Builder<'a>,
1087                            Val: &'a Value,
1088                            DestTy: &'a Type,
1089                            Name: *const c_char)
1090                            -> &'a Value;
1091     pub fn LLVMBuildFPTrunc(B: &Builder<'a>,
1092                             Val: &'a Value,
1093                             DestTy: &'a Type,
1094                             Name: *const c_char)
1095                             -> &'a Value;
1096     pub fn LLVMBuildFPExt(B: &Builder<'a>,
1097                           Val: &'a Value,
1098                           DestTy: &'a Type,
1099                           Name: *const c_char)
1100                           -> &'a Value;
1101     pub fn LLVMBuildPtrToInt(B: &Builder<'a>,
1102                              Val: &'a Value,
1103                              DestTy: &'a Type,
1104                              Name: *const c_char)
1105                              -> &'a Value;
1106     pub fn LLVMBuildIntToPtr(B: &Builder<'a>,
1107                              Val: &'a Value,
1108                              DestTy: &'a Type,
1109                              Name: *const c_char)
1110                              -> &'a Value;
1111     pub fn LLVMBuildBitCast(B: &Builder<'a>,
1112                             Val: &'a Value,
1113                             DestTy: &'a Type,
1114                             Name: *const c_char)
1115                             -> &'a Value;
1116     pub fn LLVMBuildPointerCast(B: &Builder<'a>,
1117                                 Val: &'a Value,
1118                                 DestTy: &'a Type,
1119                                 Name: *const c_char)
1120                                 -> &'a Value;
1121     pub fn LLVMRustBuildIntCast(B: &Builder<'a>,
1122                                 Val: &'a Value,
1123                                 DestTy: &'a Type,
1124                                 IsSized: bool)
1125                                 -> &'a Value;
1126
1127     // Comparisons
1128     pub fn LLVMBuildICmp(B: &Builder<'a>,
1129                          Op: c_uint,
1130                          LHS: &'a Value,
1131                          RHS: &'a Value,
1132                          Name: *const c_char)
1133                          -> &'a Value;
1134     pub fn LLVMBuildFCmp(B: &Builder<'a>,
1135                          Op: c_uint,
1136                          LHS: &'a Value,
1137                          RHS: &'a Value,
1138                          Name: *const c_char)
1139                          -> &'a Value;
1140
1141     // Miscellaneous instructions
1142     pub fn LLVMBuildPhi(B: &Builder<'a>, Ty: &'a Type, Name: *const c_char) -> &'a Value;
1143     pub fn LLVMRustBuildCall(B: &Builder<'a>,
1144                              Fn: &'a Value,
1145                              Args: *const &'a Value,
1146                              NumArgs: c_uint,
1147                              Bundle: Option<&OperandBundleDef<'a>>,
1148                              Name: *const c_char)
1149                              -> &'a Value;
1150     pub fn LLVMRustBuildMemCpy(B: &Builder<'a>,
1151                                Dst: &'a Value,
1152                                DstAlign: c_uint,
1153                                Src: &'a Value,
1154                                SrcAlign: c_uint,
1155                                Size: &'a Value,
1156                                IsVolatile: bool)
1157                                -> &'a Value;
1158     pub fn LLVMRustBuildMemMove(B: &Builder<'a>,
1159                                 Dst: &'a Value,
1160                                 DstAlign: c_uint,
1161                                 Src: &'a Value,
1162                                 SrcAlign: c_uint,
1163                                 Size: &'a Value,
1164                                 IsVolatile: bool)
1165                                 -> &'a Value;
1166     pub fn LLVMBuildSelect(B: &Builder<'a>,
1167                            If: &'a Value,
1168                            Then: &'a Value,
1169                            Else: &'a Value,
1170                            Name: *const c_char)
1171                            -> &'a Value;
1172     pub fn LLVMBuildVAArg(B: &Builder<'a>,
1173                           list: &'a Value,
1174                           Ty: &'a Type,
1175                           Name: *const c_char)
1176                           -> &'a Value;
1177     pub fn LLVMBuildExtractElement(B: &Builder<'a>,
1178                                    VecVal: &'a Value,
1179                                    Index: &'a Value,
1180                                    Name: *const c_char)
1181                                    -> &'a Value;
1182     pub fn LLVMBuildInsertElement(B: &Builder<'a>,
1183                                   VecVal: &'a Value,
1184                                   EltVal: &'a Value,
1185                                   Index: &'a Value,
1186                                   Name: *const c_char)
1187                                   -> &'a Value;
1188     pub fn LLVMBuildShuffleVector(B: &Builder<'a>,
1189                                   V1: &'a Value,
1190                                   V2: &'a Value,
1191                                   Mask: &'a Value,
1192                                   Name: *const c_char)
1193                                   -> &'a Value;
1194     pub fn LLVMBuildExtractValue(B: &Builder<'a>,
1195                                  AggVal: &'a Value,
1196                                  Index: c_uint,
1197                                  Name: *const c_char)
1198                                  -> &'a Value;
1199     pub fn LLVMBuildInsertValue(B: &Builder<'a>,
1200                                 AggVal: &'a Value,
1201                                 EltVal: &'a Value,
1202                                 Index: c_uint,
1203                                 Name: *const c_char)
1204                                 -> &'a Value;
1205
1206     pub fn LLVMRustBuildVectorReduceFAdd(B: &Builder<'a>,
1207                                          Acc: &'a Value,
1208                                          Src: &'a Value)
1209                                          -> &'a Value;
1210     pub fn LLVMRustBuildVectorReduceFMul(B: &Builder<'a>,
1211                                          Acc: &'a Value,
1212                                          Src: &'a Value)
1213                                          -> &'a Value;
1214     pub fn LLVMRustBuildVectorReduceAdd(B: &Builder<'a>,
1215                                         Src: &'a Value)
1216                                         -> &'a Value;
1217     pub fn LLVMRustBuildVectorReduceMul(B: &Builder<'a>,
1218                                         Src: &'a Value)
1219                                         -> &'a Value;
1220     pub fn LLVMRustBuildVectorReduceAnd(B: &Builder<'a>,
1221                                         Src: &'a Value)
1222                                         -> &'a Value;
1223     pub fn LLVMRustBuildVectorReduceOr(B: &Builder<'a>,
1224                                        Src: &'a Value)
1225                                        -> &'a Value;
1226     pub fn LLVMRustBuildVectorReduceXor(B: &Builder<'a>,
1227                                         Src: &'a Value)
1228                                         -> &'a Value;
1229     pub fn LLVMRustBuildVectorReduceMin(B: &Builder<'a>,
1230                                         Src: &'a Value,
1231                                         IsSigned: bool)
1232                                         -> &'a Value;
1233     pub fn LLVMRustBuildVectorReduceMax(B: &Builder<'a>,
1234                                         Src: &'a Value,
1235                                         IsSigned: bool)
1236                                         -> &'a Value;
1237     pub fn LLVMRustBuildVectorReduceFMin(B: &Builder<'a>,
1238                                          Src: &'a Value,
1239                                          IsNaN: bool)
1240                                          -> &'a Value;
1241     pub fn LLVMRustBuildVectorReduceFMax(B: &Builder<'a>,
1242                                          Src: &'a Value,
1243                                          IsNaN: bool)
1244                                          -> &'a Value;
1245
1246     pub fn LLVMRustBuildMinNum(
1247         B: &Builder<'a>,
1248         LHS: &'a Value,
1249         LHS: &'a Value,
1250     ) -> &'a Value;
1251     pub fn LLVMRustBuildMaxNum(
1252         B: &Builder<'a>,
1253         LHS: &'a Value,
1254         LHS: &'a Value,
1255     ) -> &'a Value;
1256
1257     // Atomic Operations
1258     pub fn LLVMRustBuildAtomicLoad(B: &Builder<'a>,
1259                                    PointerVal: &'a Value,
1260                                    Name: *const c_char,
1261                                    Order: AtomicOrdering)
1262                                    -> &'a Value;
1263
1264     pub fn LLVMRustBuildAtomicStore(B: &Builder<'a>,
1265                                     Val: &'a Value,
1266                                     Ptr: &'a Value,
1267                                     Order: AtomicOrdering)
1268                                     -> &'a Value;
1269
1270     pub fn LLVMRustBuildAtomicCmpXchg(B: &Builder<'a>,
1271                                       LHS: &'a Value,
1272                                       CMP: &'a Value,
1273                                       RHS: &'a Value,
1274                                       Order: AtomicOrdering,
1275                                       FailureOrder: AtomicOrdering,
1276                                       Weak: Bool)
1277                                       -> &'a Value;
1278
1279     pub fn LLVMBuildAtomicRMW(B: &Builder<'a>,
1280                               Op: AtomicRmwBinOp,
1281                               LHS: &'a Value,
1282                               RHS: &'a Value,
1283                               Order: AtomicOrdering,
1284                               SingleThreaded: Bool)
1285                               -> &'a Value;
1286
1287     pub fn LLVMRustBuildAtomicFence(B: &Builder,
1288                                     Order: AtomicOrdering,
1289                                     Scope: SynchronizationScope);
1290
1291     /// Writes a module to the specified path. Returns 0 on success.
1292     pub fn LLVMWriteBitcodeToFile(M: &Module, Path: *const c_char) -> c_int;
1293
1294     /// Creates a pass manager.
1295     pub fn LLVMCreatePassManager() -> &'a mut PassManager<'a>;
1296
1297     /// Creates a function-by-function pass manager
1298     pub fn LLVMCreateFunctionPassManagerForModule(M: &'a Module) -> &'a mut PassManager<'a>;
1299
1300     /// Disposes a pass manager.
1301     pub fn LLVMDisposePassManager(PM: &'a mut PassManager<'a>);
1302
1303     /// Runs a pass manager on a module.
1304     pub fn LLVMRunPassManager(PM: &PassManager<'a>, M: &'a Module) -> Bool;
1305
1306     pub fn LLVMInitializePasses();
1307
1308     pub fn LLVMPassManagerBuilderCreate() -> &'static mut PassManagerBuilder;
1309     pub fn LLVMPassManagerBuilderDispose(PMB: &'static mut PassManagerBuilder);
1310     pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: &PassManagerBuilder, Value: Bool);
1311     pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: &PassManagerBuilder, Value: Bool);
1312     pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(PMB: &PassManagerBuilder,
1313                                                          threshold: c_uint);
1314     pub fn LLVMPassManagerBuilderPopulateModulePassManager(PMB: &PassManagerBuilder,
1315                                                            PM: &PassManager);
1316
1317     pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(PMB: &PassManagerBuilder,
1318                                                              PM: &PassManager);
1319     pub fn LLVMPassManagerBuilderPopulateLTOPassManager(PMB: &PassManagerBuilder,
1320                                                         PM: &PassManager,
1321                                                         Internalize: Bool,
1322                                                         RunInliner: Bool);
1323     pub fn LLVMRustPassManagerBuilderPopulateThinLTOPassManager(
1324         PMB: &PassManagerBuilder,
1325         PM: &PassManager);
1326
1327     // Stuff that's in rustllvm/ because it's not upstream yet.
1328
1329     /// Opens an object file.
1330     pub fn LLVMCreateObjectFile(
1331         MemBuf: &'static mut MemoryBuffer,
1332     ) -> Option<&'static mut ObjectFile>;
1333     /// Closes an object file.
1334     pub fn LLVMDisposeObjectFile(ObjFile: &'static mut ObjectFile);
1335
1336     /// Enumerates the sections in an object file.
1337     pub fn LLVMGetSections(ObjFile: &'a ObjectFile) -> &'a mut SectionIterator<'a>;
1338     /// Destroys a section iterator.
1339     pub fn LLVMDisposeSectionIterator(SI: &'a mut SectionIterator<'a>);
1340     /// Returns `true` if the section iterator is at the end of the section
1341     /// list:
1342     pub fn LLVMIsSectionIteratorAtEnd(ObjFile: &'a ObjectFile, SI: &SectionIterator<'a>) -> Bool;
1343     /// Moves the section iterator to point to the next section.
1344     pub fn LLVMMoveToNextSection(SI: &SectionIterator);
1345     /// Returns the current section size.
1346     pub fn LLVMGetSectionSize(SI: &SectionIterator) -> c_ulonglong;
1347     /// Returns the current section contents as a string buffer.
1348     pub fn LLVMGetSectionContents(SI: &SectionIterator) -> *const c_char;
1349
1350     /// Reads the given file and returns it as a memory buffer. Use
1351     /// LLVMDisposeMemoryBuffer() to get rid of it.
1352     pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(
1353         Path: *const c_char,
1354     ) -> Option<&'static mut MemoryBuffer>;
1355
1356     pub fn LLVMStartMultithreaded() -> Bool;
1357
1358     /// Returns a string describing the last error caused by an LLVMRust* call.
1359     pub fn LLVMRustGetLastError() -> *const c_char;
1360
1361     /// Print the pass timings since static dtors aren't picking them up.
1362     pub fn LLVMRustPrintPassTimings();
1363
1364     pub fn LLVMStructCreateNamed(C: &Context, Name: *const c_char) -> &Type;
1365
1366     pub fn LLVMStructSetBody(StructTy: &'a Type,
1367                              ElementTypes: *const &'a Type,
1368                              ElementCount: c_uint,
1369                              Packed: Bool);
1370
1371     /// Prepares inline assembly.
1372     pub fn LLVMRustInlineAsm(Ty: &Type,
1373                              AsmString: *const c_char,
1374                              Constraints: *const c_char,
1375                              SideEffects: Bool,
1376                              AlignStack: Bool,
1377                              Dialect: AsmDialect)
1378                              -> &Value;
1379     pub fn LLVMRustInlineAsmVerify(Ty: &Type,
1380                                    Constraints: *const c_char)
1381                                    -> bool;
1382
1383     pub fn LLVMRustDebugMetadataVersion() -> u32;
1384     pub fn LLVMRustVersionMajor() -> u32;
1385     pub fn LLVMRustVersionMinor() -> u32;
1386     pub fn LLVMRustIsRustLLVM() -> bool;
1387
1388     pub fn LLVMRustAddModuleFlag(M: &Module, name: *const c_char, value: u32);
1389
1390     pub fn LLVMRustMetadataAsValue(C: &'a Context, MD: &'a Metadata) -> &'a Value;
1391
1392     pub fn LLVMRustDIBuilderCreate(M: &'a Module) -> &'a mut DIBuilder<'a>;
1393
1394     pub fn LLVMRustDIBuilderDispose(Builder: &'a mut DIBuilder<'a>);
1395
1396     pub fn LLVMRustDIBuilderFinalize(Builder: &DIBuilder);
1397
1398     pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: &DIBuilder<'a>,
1399                                               Lang: c_uint,
1400                                               File: &'a DIFile,
1401                                               Producer: *const c_char,
1402                                               isOptimized: bool,
1403                                               Flags: *const c_char,
1404                                               RuntimeVer: c_uint,
1405                                               SplitName: *const c_char,
1406                                               kind: DebugEmissionKind)
1407                                               -> &'a DIDescriptor;
1408
1409     pub fn LLVMRustDIBuilderCreateFile(Builder: &DIBuilder<'a>,
1410                                        Filename: *const c_char,
1411                                        Directory: *const c_char)
1412                                        -> &'a DIFile;
1413
1414     pub fn LLVMRustDIBuilderCreateSubroutineType(Builder: &DIBuilder<'a>,
1415                                                  File: &'a DIFile,
1416                                                  ParameterTypes: &'a DIArray)
1417                                                  -> &'a DICompositeType;
1418
1419     pub fn LLVMRustDIBuilderCreateFunction(Builder: &DIBuilder<'a>,
1420                                            Scope: &'a DIDescriptor,
1421                                            Name: *const c_char,
1422                                            LinkageName: *const c_char,
1423                                            File: &'a DIFile,
1424                                            LineNo: c_uint,
1425                                            Ty: &'a DIType,
1426                                            ScopeLine: c_uint,
1427                                            Flags: DIFlags,
1428                                            SPFlags: DISPFlags,
1429                                            Fn: &'a Value,
1430                                            TParam: &'a DIArray,
1431                                            Decl: Option<&'a DIDescriptor>)
1432                                            -> &'a DISubprogram;
1433
1434     pub fn LLVMRustDIBuilderCreateBasicType(Builder: &DIBuilder<'a>,
1435                                             Name: *const c_char,
1436                                             SizeInBits: u64,
1437                                             AlignInBits: u32,
1438                                             Encoding: c_uint)
1439                                             -> &'a DIBasicType;
1440
1441     pub fn LLVMRustDIBuilderCreatePointerType(Builder: &DIBuilder<'a>,
1442                                               PointeeTy: &'a DIType,
1443                                               SizeInBits: u64,
1444                                               AlignInBits: u32,
1445                                               Name: *const c_char)
1446                                               -> &'a DIDerivedType;
1447
1448     pub fn LLVMRustDIBuilderCreateStructType(Builder: &DIBuilder<'a>,
1449                                              Scope: Option<&'a DIDescriptor>,
1450                                              Name: *const c_char,
1451                                              File: &'a DIFile,
1452                                              LineNumber: c_uint,
1453                                              SizeInBits: u64,
1454                                              AlignInBits: u32,
1455                                              Flags: DIFlags,
1456                                              DerivedFrom: Option<&'a DIType>,
1457                                              Elements: &'a DIArray,
1458                                              RunTimeLang: c_uint,
1459                                              VTableHolder: Option<&'a DIType>,
1460                                              UniqueId: *const c_char)
1461                                              -> &'a DICompositeType;
1462
1463     pub fn LLVMRustDIBuilderCreateMemberType(Builder: &DIBuilder<'a>,
1464                                              Scope: &'a DIDescriptor,
1465                                              Name: *const c_char,
1466                                              File: &'a DIFile,
1467                                              LineNo: c_uint,
1468                                              SizeInBits: u64,
1469                                              AlignInBits: u32,
1470                                              OffsetInBits: u64,
1471                                              Flags: DIFlags,
1472                                              Ty: &'a DIType)
1473                                              -> &'a DIDerivedType;
1474
1475     pub fn LLVMRustDIBuilderCreateVariantMemberType(Builder: &DIBuilder<'a>,
1476                                                     Scope: &'a DIScope,
1477                                                     Name: *const c_char,
1478                                                     File: &'a DIFile,
1479                                                     LineNumber: c_uint,
1480                                                     SizeInBits: u64,
1481                                                     AlignInBits: u32,
1482                                                     OffsetInBits: u64,
1483                                                     Discriminant: Option<&'a Value>,
1484                                                     Flags: DIFlags,
1485                                                     Ty: &'a DIType)
1486                                                     -> &'a DIType;
1487
1488     pub fn LLVMRustDIBuilderCreateLexicalBlock(Builder: &DIBuilder<'a>,
1489                                                Scope: &'a DIScope,
1490                                                File: &'a DIFile,
1491                                                Line: c_uint,
1492                                                Col: c_uint)
1493                                                -> &'a DILexicalBlock;
1494
1495     pub fn LLVMRustDIBuilderCreateLexicalBlockFile(Builder: &DIBuilder<'a>,
1496                                                    Scope: &'a DIScope,
1497                                                    File: &'a DIFile)
1498                                                    -> &'a DILexicalBlock;
1499
1500     pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: &DIBuilder<'a>,
1501                                                  Context: Option<&'a DIScope>,
1502                                                  Name: *const c_char,
1503                                                  LinkageName: *const c_char,
1504                                                  File: &'a DIFile,
1505                                                  LineNo: c_uint,
1506                                                  Ty: &'a DIType,
1507                                                  isLocalToUnit: bool,
1508                                                  Val: &'a Value,
1509                                                  Decl: Option<&'a DIDescriptor>,
1510                                                  AlignInBits: u32)
1511                                                  -> &'a DIGlobalVariableExpression;
1512
1513     pub fn LLVMRustDIBuilderCreateVariable(Builder: &DIBuilder<'a>,
1514                                            Tag: c_uint,
1515                                            Scope: &'a DIDescriptor,
1516                                            Name: *const c_char,
1517                                            File: &'a DIFile,
1518                                            LineNo: c_uint,
1519                                            Ty: &'a DIType,
1520                                            AlwaysPreserve: bool,
1521                                            Flags: DIFlags,
1522                                            ArgNo: c_uint,
1523                                            AlignInBits: u32)
1524                                            -> &'a DIVariable;
1525
1526     pub fn LLVMRustDIBuilderCreateArrayType(Builder: &DIBuilder<'a>,
1527                                             Size: u64,
1528                                             AlignInBits: u32,
1529                                             Ty: &'a DIType,
1530                                             Subscripts: &'a DIArray)
1531                                             -> &'a DIType;
1532
1533     pub fn LLVMRustDIBuilderGetOrCreateSubrange(Builder: &DIBuilder<'a>,
1534                                                 Lo: i64,
1535                                                 Count: i64)
1536                                                 -> &'a DISubrange;
1537
1538     pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: &DIBuilder<'a>,
1539                                              Ptr: *const Option<&'a DIDescriptor>,
1540                                              Count: c_uint)
1541                                              -> &'a DIArray;
1542
1543     pub fn LLVMRustDIBuilderInsertDeclareAtEnd(Builder: &DIBuilder<'a>,
1544                                                Val: &'a Value,
1545                                                VarInfo: &'a DIVariable,
1546                                                AddrOps: *const i64,
1547                                                AddrOpsCount: c_uint,
1548                                                DL: &'a Value,
1549                                                InsertAtEnd: &'a BasicBlock)
1550                                                -> &'a Value;
1551
1552     pub fn LLVMRustDIBuilderCreateEnumerator(Builder: &DIBuilder<'a>,
1553                                              Name: *const c_char,
1554                                              Val: u64)
1555                                              -> &'a DIEnumerator;
1556
1557     pub fn LLVMRustDIBuilderCreateEnumerationType(Builder: &DIBuilder<'a>,
1558                                                   Scope: &'a DIScope,
1559                                                   Name: *const c_char,
1560                                                   File: &'a DIFile,
1561                                                   LineNumber: c_uint,
1562                                                   SizeInBits: u64,
1563                                                   AlignInBits: u32,
1564                                                   Elements: &'a DIArray,
1565                                                   ClassType: &'a DIType,
1566                                                   IsScoped: bool)
1567                                                   -> &'a DIType;
1568
1569     pub fn LLVMRustDIBuilderCreateUnionType(Builder: &DIBuilder<'a>,
1570                                             Scope: &'a DIScope,
1571                                             Name: *const c_char,
1572                                             File: &'a DIFile,
1573                                             LineNumber: c_uint,
1574                                             SizeInBits: u64,
1575                                             AlignInBits: u32,
1576                                             Flags: DIFlags,
1577                                             Elements: Option<&'a DIArray>,
1578                                             RunTimeLang: c_uint,
1579                                             UniqueId: *const c_char)
1580                                             -> &'a DIType;
1581
1582     pub fn LLVMRustDIBuilderCreateVariantPart(Builder: &DIBuilder<'a>,
1583                                               Scope: &'a DIScope,
1584                                               Name: *const c_char,
1585                                               File: &'a DIFile,
1586                                               LineNo: c_uint,
1587                                               SizeInBits: u64,
1588                                               AlignInBits: u32,
1589                                               Flags: DIFlags,
1590                                               Discriminator: Option<&'a DIDerivedType>,
1591                                               Elements: &'a DIArray,
1592                                               UniqueId: *const c_char)
1593                                               -> &'a DIDerivedType;
1594
1595     pub fn LLVMSetUnnamedAddr(GlobalVar: &Value, UnnamedAddr: Bool);
1596
1597     pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: &DIBuilder<'a>,
1598                                                         Scope: Option<&'a DIScope>,
1599                                                         Name: *const c_char,
1600                                                         Ty: &'a DIType,
1601                                                         File: &'a DIFile,
1602                                                         LineNo: c_uint,
1603                                                         ColumnNo: c_uint)
1604                                                         -> &'a DITemplateTypeParameter;
1605
1606
1607     pub fn LLVMRustDIBuilderCreateNameSpace(Builder: &DIBuilder<'a>,
1608                                             Scope: Option<&'a DIScope>,
1609                                             Name: *const c_char,
1610                                             File: &'a DIFile,
1611                                             LineNo: c_uint)
1612                                             -> &'a DINameSpace;
1613
1614     pub fn LLVMRustDICompositeTypeReplaceArrays(Builder: &DIBuilder<'a>,
1615                                                 CompositeType: &'a DIType,
1616                                                 Elements: Option<&'a DIArray>,
1617                                                 Params: Option<&'a DIArray>);
1618
1619
1620     pub fn LLVMRustDIBuilderCreateDebugLocation(Context: &'a Context,
1621                                                 Line: c_uint,
1622                                                 Column: c_uint,
1623                                                 Scope: &'a DIScope,
1624                                                 InlinedAt: Option<&'a Metadata>)
1625                                                 -> &'a Value;
1626     pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
1627     pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
1628
1629     #[allow(improper_ctypes)]
1630     pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);
1631     #[allow(improper_ctypes)]
1632     pub fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
1633
1634     pub fn LLVMIsAConstantInt(value_ref: &Value) -> Option<&Value>;
1635     pub fn LLVMIsAConstantFP(value_ref: &Value) -> Option<&Value>;
1636
1637     pub fn LLVMRustPassKind(Pass: &Pass) -> PassKind;
1638     pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> Option<&'static mut Pass>;
1639     pub fn LLVMRustAddPass(PM: &PassManager, Pass: &'static mut Pass);
1640
1641     pub fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
1642
1643     pub fn LLVMRustPrintTargetCPUs(T: &TargetMachine);
1644     pub fn LLVMRustPrintTargetFeatures(T: &TargetMachine);
1645
1646     pub fn LLVMRustGetHostCPUName(len: *mut usize) -> *const c_char;
1647     pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
1648                                        CPU: *const c_char,
1649                                        Features: *const c_char,
1650                                        Model: CodeModel,
1651                                        Reloc: RelocMode,
1652                                        Level: CodeGenOptLevel,
1653                                        UseSoftFP: bool,
1654                                        PositionIndependentExecutable: bool,
1655                                        FunctionSections: bool,
1656                                        DataSections: bool,
1657                                        TrapUnreachable: bool,
1658                                        Singlethread: bool,
1659                                        AsmComments: bool,
1660                                        EmitStackSizeSection: bool)
1661                                        -> Option<&'static mut TargetMachine>;
1662     pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
1663     pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);
1664     pub fn LLVMRustAddBuilderLibraryInfo(PMB: &'a PassManagerBuilder,
1665                                          M: &'a Module,
1666                                          DisableSimplifyLibCalls: bool);
1667     pub fn LLVMRustConfigurePassManagerBuilder(PMB: &PassManagerBuilder,
1668                                                OptLevel: CodeGenOptLevel,
1669                                                MergeFunctions: bool,
1670                                                SLPVectorize: bool,
1671                                                LoopVectorize: bool,
1672                                                PrepareForThinLTO: bool,
1673                                                PGOGenPath: *const c_char,
1674                                                PGOUsePath: *const c_char);
1675     pub fn LLVMRustAddLibraryInfo(PM: &PassManager<'a>,
1676                                   M: &'a Module,
1677                                   DisableSimplifyLibCalls: bool);
1678     pub fn LLVMRustRunFunctionPassManager(PM: &PassManager<'a>, M: &'a Module);
1679     pub fn LLVMRustWriteOutputFile(T: &'a TargetMachine,
1680                                    PM: &PassManager<'a>,
1681                                    M: &'a Module,
1682                                    Output: *const c_char,
1683                                    FileType: FileType)
1684                                    -> LLVMRustResult;
1685     pub fn LLVMRustPrintModule(PM: &PassManager<'a>,
1686                                M: &'a Module,
1687                                Output: *const c_char,
1688                                Demangle: extern fn(*const c_char,
1689                                                    size_t,
1690                                                    *mut c_char,
1691                                                    size_t) -> size_t);
1692     pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
1693     pub fn LLVMRustPrintPasses();
1694     pub fn LLVMRustSetNormalizedTarget(M: &Module, triple: *const c_char);
1695     pub fn LLVMRustAddAlwaysInlinePass(P: &PassManagerBuilder, AddLifetimes: bool);
1696     pub fn LLVMRustRunRestrictionPass(M: &Module, syms: *const *const c_char, len: size_t);
1697     pub fn LLVMRustMarkAllFunctionsNounwind(M: &Module);
1698
1699     pub fn LLVMRustOpenArchive(path: *const c_char) -> Option<&'static mut Archive>;
1700     pub fn LLVMRustArchiveIteratorNew(AR: &'a Archive) -> &'a mut ArchiveIterator<'a>;
1701     pub fn LLVMRustArchiveIteratorNext(
1702         AIR: &ArchiveIterator<'a>,
1703     ) -> Option<&'a mut ArchiveChild<'a>>;
1704     pub fn LLVMRustArchiveChildName(ACR: &ArchiveChild, size: &mut size_t) -> *const c_char;
1705     pub fn LLVMRustArchiveChildData(ACR: &ArchiveChild, size: &mut size_t) -> *const c_char;
1706     pub fn LLVMRustArchiveChildFree(ACR: &'a mut ArchiveChild<'a>);
1707     pub fn LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>);
1708     pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);
1709
1710     pub fn LLVMRustGetSectionName(SI: &SectionIterator, data: &mut *const c_char) -> size_t;
1711
1712     #[allow(improper_ctypes)]
1713     pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
1714
1715     pub fn LLVMContextSetDiagnosticHandler(C: &Context,
1716                                            Handler: DiagnosticHandler,
1717                                            DiagnosticContext: *mut c_void);
1718
1719     #[allow(improper_ctypes)]
1720     pub fn LLVMRustUnpackOptimizationDiagnostic(DI: &'a DiagnosticInfo,
1721                                                 pass_name_out: &RustString,
1722                                                 function_out: &mut Option<&'a Value>,
1723                                                 loc_line_out: &mut c_uint,
1724                                                 loc_column_out: &mut c_uint,
1725                                                 loc_filename_out: &RustString,
1726                                                 message_out: &RustString);
1727
1728     pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: &'a DiagnosticInfo,
1729                                              cookie_out: &mut c_uint,
1730                                              message_out: &mut Option<&'a Twine>,
1731                                              instruction_out: &mut Option<&'a Value>);
1732
1733     #[allow(improper_ctypes)]
1734     pub fn LLVMRustWriteDiagnosticInfoToString(DI: &DiagnosticInfo, s: &RustString);
1735     pub fn LLVMRustGetDiagInfoKind(DI: &DiagnosticInfo) -> DiagnosticKind;
1736
1737     pub fn LLVMRustSetInlineAsmDiagnosticHandler(C: &Context,
1738                                                  H: InlineAsmDiagHandler,
1739                                                  CX: *mut c_void);
1740
1741     #[allow(improper_ctypes)]
1742     pub fn LLVMRustWriteSMDiagnosticToString(d: &SMDiagnostic, s: &RustString);
1743
1744     pub fn LLVMRustWriteArchive(Dst: *const c_char,
1745                                 NumMembers: size_t,
1746                                 Members: *const &RustArchiveMember,
1747                                 WriteSymbtab: bool,
1748                                 Kind: ArchiveKind)
1749                                 -> LLVMRustResult;
1750     pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
1751                                     Name: *const c_char,
1752                                     Child: Option<&ArchiveChild<'a>>)
1753                                     -> &'a mut RustArchiveMember<'a>;
1754     pub fn LLVMRustArchiveMemberFree(Member: &'a mut RustArchiveMember<'a>);
1755
1756     pub fn LLVMRustSetDataLayoutFromTargetMachine(M: &'a Module, TM: &'a TargetMachine);
1757
1758     pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
1759                                          Inputs: *const &'a Value,
1760                                          NumInputs: c_uint)
1761                                          -> &'a mut OperandBundleDef<'a>;
1762     pub fn LLVMRustFreeOperandBundleDef(Bundle: &'a mut OperandBundleDef<'a>);
1763
1764     pub fn LLVMRustPositionBuilderAtStart(B: &Builder<'a>, BB: &'a BasicBlock);
1765
1766     pub fn LLVMRustSetComdat(M: &'a Module, V: &'a Value, Name: *const c_char);
1767     pub fn LLVMRustUnsetComdat(V: &Value);
1768     pub fn LLVMRustSetModulePIELevel(M: &Module);
1769     pub fn LLVMRustModuleBufferCreate(M: &Module) -> &'static mut ModuleBuffer;
1770     pub fn LLVMRustModuleBufferPtr(p: &ModuleBuffer) -> *const u8;
1771     pub fn LLVMRustModuleBufferLen(p: &ModuleBuffer) -> usize;
1772     pub fn LLVMRustModuleBufferFree(p: &'static mut ModuleBuffer);
1773     pub fn LLVMRustModuleCost(M: &Module) -> u64;
1774
1775     pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer;
1776     pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer);
1777     pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char;
1778     pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t;
1779     pub fn LLVMRustCreateThinLTOData(
1780         Modules: *const ThinLTOModule,
1781         NumModules: c_uint,
1782         PreservedSymbols: *const *const c_char,
1783         PreservedSymbolsLen: c_uint,
1784     ) -> Option<&'static mut ThinLTOData>;
1785     pub fn LLVMRustPrepareThinLTORename(
1786         Data: &ThinLTOData,
1787         Module: &Module,
1788     ) -> bool;
1789     pub fn LLVMRustPrepareThinLTOResolveWeak(
1790         Data: &ThinLTOData,
1791         Module: &Module,
1792     ) -> bool;
1793     pub fn LLVMRustPrepareThinLTOInternalize(
1794         Data: &ThinLTOData,
1795         Module: &Module,
1796     ) -> bool;
1797     pub fn LLVMRustPrepareThinLTOImport(
1798         Data: &ThinLTOData,
1799         Module: &Module,
1800     ) -> bool;
1801     pub fn LLVMRustGetThinLTOModuleImports(
1802         Data: *const ThinLTOData,
1803         ModuleNameCallback: ThinLTOModuleNameCallback,
1804         CallbackPayload: *mut c_void,
1805     );
1806     pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
1807     pub fn LLVMRustParseBitcodeForThinLTO(
1808         Context: &Context,
1809         Data: *const u8,
1810         len: usize,
1811         Identifier: *const c_char,
1812     ) -> Option<&Module>;
1813     pub fn LLVMRustThinLTOGetDICompileUnit(M: &Module,
1814                                            CU1: &mut *mut c_void,
1815                                            CU2: &mut *mut c_void);
1816     pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
1817
1818     pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
1819     pub fn LLVMRustLinkerAdd(linker: &Linker,
1820                              bytecode: *const c_char,
1821                              bytecode_len: usize) -> bool;
1822     pub fn LLVMRustLinkerFree(linker: &'a mut Linker<'a>);
1823 }