lib.rs 99.7 KB
Newer Older
A
Akos Kiss 已提交
1
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

A
Aaron Turon 已提交
11
#![allow(non_upper_case_globals)]
12
#![allow(non_camel_case_types)]
13
#![allow(non_snake_case)]
C
Corey Richardson 已提交
14
#![allow(dead_code)]
15

16
#![crate_name = "rustc_llvm"]
17
#![unstable(feature = "rustc_private", issue = "27812")]
18 19
#![crate_type = "dylib"]
#![crate_type = "rlib"]
20
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
A
Alex Crichton 已提交
21
       html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
22
       html_root_url = "https://doc.rust-lang.org/nightly/")]
23
#![cfg_attr(not(stage0), deny(warnings))]
24

T
Fallout  
Tamir Duberstein 已提交
25
#![feature(associated_consts)]
26
#![feature(box_syntax)]
27
#![feature(libc)]
A
Alex Crichton 已提交
28 29
#![feature(link_args)]
#![feature(staged_api)]
A
Alex Crichton 已提交
30
#![feature(linked_from)]
31
#![feature(concat_idents)]
32 33

extern crate libc;
34
#[macro_use] #[no_link] extern crate rustc_bitflags;
35

S
Steven Fackler 已提交
36 37 38 39 40 41
pub use self::AttributeSet::*;
pub use self::IntPredicate::*;
pub use self::RealPredicate::*;
pub use self::TypeKind::*;
pub use self::AtomicBinOp::*;
pub use self::AtomicOrdering::*;
42
pub use self::SynchronizationScope::*;
S
Steven Fackler 已提交
43 44
pub use self::MetadataType::*;
pub use self::AsmDialect::*;
45
pub use self::CodeGenOptSize::*;
S
Steven Fackler 已提交
46 47 48 49
pub use self::DiagnosticKind::*;
pub use self::CallConv::*;
pub use self::Visibility::*;
pub use self::DiagnosticSeverity::*;
S
Steven Fackler 已提交
50
pub use self::Linkage::*;
51
pub use self::DLLStorageClassTypes::*;
S
Steven Fackler 已提交
52

J
Jake Goulding 已提交
53
use std::str::FromStr;
A
Alex Crichton 已提交
54
use std::ffi::{CString, CStr};
55
use std::cell::RefCell;
56
use std::slice;
57
use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
58
use libc::{c_longlong, c_ulonglong, c_void};
59 60
use debuginfo::{DIBuilderRef, DIDescriptor,
                DIFile, DILexicalBlock, DISubprogram, DIType,
61 62 63
                DIBasicType, DIDerivedType, DICompositeType, DIScope,
                DIVariable, DIGlobalVariable, DIArray, DISubrange,
                DITemplateTypeParameter, DIEnumerator, DINameSpace};
64

65
pub mod archive_ro;
66
pub mod diagnostic;
67

68 69
pub type Opcode = u32;
pub type Bool = c_uint;
70

71 72
pub const True: Bool = 1 as Bool;
pub const False: Bool = 0 as Bool;
G
Graydon Hoare 已提交
73

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#[repr(C)]
#[derive(Copy, Clone, PartialEq)]
pub enum LLVMRustResult {
    Success = 0,
    Failure = 1
}

impl LLVMRustResult {
    pub fn into_result(self) -> Result<(), ()> {
        match self {
            LLVMRustResult::Success => Ok(()),
            LLVMRustResult::Failure => Err(()),
        }
    }
}

90
// Consts for the LLVM CallConv type, pre-cast to usize.
91

N
Niko Matsakis 已提交
92
#[derive(Copy, Clone, PartialEq)]
93
#[repr(C)]
94
pub enum CallConv {
95 96 97 98 99
    CCallConv = 0,
    FastCallConv = 8,
    ColdCallConv = 9,
    X86StdcallCallConv = 64,
    X86FastcallCallConv = 65,
E
Eric Holk 已提交
100
    X86_64_Win64 = 79,
101
    X86_VectorCall = 80
102
}
103

N
Niko Matsakis 已提交
104
#[derive(Copy, Clone)]
105
#[repr(C)]
106
pub enum Visibility {
107 108 109 110 111
    LLVMDefaultVisibility = 0,
    HiddenVisibility = 1,
    ProtectedVisibility = 2,
}

112 113 114 115
// This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
// DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
// LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
// they've been removed in upstream LLVM commit r203866.
116
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
117
#[repr(C)]
118
pub enum Linkage {
119 120 121 122
    ExternalLinkage = 0,
    AvailableExternallyLinkage = 1,
    LinkOnceAnyLinkage = 2,
    LinkOnceODRLinkage = 3,
123 124 125 126 127 128 129
    WeakAnyLinkage = 5,
    WeakODRLinkage = 6,
    AppendingLinkage = 7,
    InternalLinkage = 8,
    PrivateLinkage = 9,
    ExternalWeakLinkage = 12,
    CommonLinkage = 14,
130
}
M
Marijn Haverbeke 已提交
131

132
#[repr(C)]
N
Niko Matsakis 已提交
133
#[derive(Copy, Clone, Debug)]
134 135 136 137 138 139 140
pub enum DiagnosticSeverity {
    Error,
    Warning,
    Remark,
    Note,
}

141 142 143 144 145 146 147 148 149

#[repr(C)]
#[derive(Copy, Clone)]
pub enum DLLStorageClassTypes {
    DefaultStorageClass = 0,
    DLLImportStorageClass = 1,
    DLLExportStorageClass = 2,
}

A
Ahmed Charles 已提交
150
bitflags! {
151
    #[derive(Default, Debug)]
152
    flags Attribute : u64 {
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
        const ZExt            = 1 << 0,
        const SExt            = 1 << 1,
        const NoReturn        = 1 << 2,
        const InReg           = 1 << 3,
        const StructRet       = 1 << 4,
        const NoUnwind        = 1 << 5,
        const NoAlias         = 1 << 6,
        const ByVal           = 1 << 7,
        const Nest            = 1 << 8,
        const ReadNone        = 1 << 9,
        const ReadOnly        = 1 << 10,
        const NoInline        = 1 << 11,
        const AlwaysInline    = 1 << 12,
        const OptimizeForSize = 1 << 13,
        const StackProtect    = 1 << 14,
        const StackProtectReq = 1 << 15,
        const NoCapture       = 1 << 21,
        const NoRedZone       = 1 << 22,
        const NoImplicitFloat = 1 << 23,
        const Naked           = 1 << 24,
        const InlineHint      = 1 << 25,
        const ReturnsTwice    = 1 << 29,
        const UWTable         = 1 << 30,
        const NonLazyBind     = 1 << 31,
M
Marijn Haverbeke 已提交
177

178 179 180 181 182
        // Some of these are missing from the LLVM C API, the rest are
        // present, but commented out, and preceded by the following warning:
        // FIXME: These attributes are currently not included in the C API as
        // a temporary measure until the API/ABI impact to the C API is understood
        // and the path forward agreed upon.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
        const SanitizeAddress = 1 << 32,
        const MinSize         = 1 << 33,
        const NoDuplicate     = 1 << 34,
        const StackProtectStrong = 1 << 35,
        const SanitizeThread  = 1 << 36,
        const SanitizeMemory  = 1 << 37,
        const NoBuiltin       = 1 << 38,
        const Returned        = 1 << 39,
        const Cold            = 1 << 40,
        const Builtin         = 1 << 41,
        const OptimizeNone    = 1 << 42,
        const InAlloca        = 1 << 43,
        const NonNull         = 1 << 44,
        const JumpTable       = 1 << 45,
        const Convergent      = 1 << 46,
        const SafeStack       = 1 << 47,
        const NoRecurse       = 1 << 48,
        const InaccessibleMemOnly         = 1 << 49,
        const InaccessibleMemOrArgMemOnly = 1 << 50,
202
    }
203 204
}

205
#[derive(Copy, Clone, Default, Debug)]
206 207 208
pub struct Attributes {
    regular: Attribute,
    dereferenceable_bytes: u64
209 210
}

211 212 213 214 215
impl Attributes {
    pub fn set(&mut self, attr: Attribute) -> &mut Self {
        self.regular = self.regular | attr;
        self
    }
216

217 218 219 220
    pub fn unset(&mut self, attr: Attribute) -> &mut Self {
        self.regular = self.regular - attr;
        self
    }
221

222 223 224
    pub fn set_dereferenceable(&mut self, bytes: u64) -> &mut Self {
        self.dereferenceable_bytes = bytes;
        self
225 226
    }

227 228 229
    pub fn unset_dereferenceable(&mut self) -> &mut Self {
        self.dereferenceable_bytes = 0;
        self
230 231
    }

232
    pub fn apply_llfn(&self, idx: usize, llfn: ValueRef) {
233
        unsafe {
234
            LLVMAddFunctionAttribute(llfn, idx as c_uint, self.regular.bits());
235
            if self.dereferenceable_bytes != 0 {
236
                LLVMAddDereferenceableAttr(llfn, idx as c_uint,
237
                                           self.dereferenceable_bytes);
238 239 240 241
            }
        }
    }

242
    pub fn apply_callsite(&self, idx: usize, callsite: ValueRef) {
243
        unsafe {
244
            LLVMRustAddCallSiteAttribute(callsite, idx as c_uint, self.regular.bits());
245
            if self.dereferenceable_bytes != 0 {
246
                LLVMAddDereferenceableCallSiteAttr(callsite, idx as c_uint,
247
                                                   self.dereferenceable_bytes);
248 249 250 251 252
            }
        }
    }
}

253 254 255 256 257 258 259
#[repr(C)]
#[derive(Copy, Clone)]
pub enum AttributeSet {
    ReturnIndex = 0,
    FunctionIndex = !0
}

260
// enum for the LLVM IntPredicate type
N
Niko Matsakis 已提交
261
#[derive(Copy, Clone)]
262
pub enum IntPredicate {
263 264 265 266 267 268 269 270 271 272 273
    IntEQ = 32,
    IntNE = 33,
    IntUGT = 34,
    IntUGE = 35,
    IntULT = 36,
    IntULE = 37,
    IntSGT = 38,
    IntSGE = 39,
    IntSLT = 40,
    IntSLE = 41,
}
274

275
// enum for the LLVM RealPredicate type
N
Niko Matsakis 已提交
276
#[derive(Copy, Clone)]
277
pub enum RealPredicate {
278
    RealPredicateFalse = 0,
279 280 281 282 283 284 285 286 287 288 289 290 291 292
    RealOEQ = 1,
    RealOGT = 2,
    RealOGE = 3,
    RealOLT = 4,
    RealOLE = 5,
    RealONE = 6,
    RealORD = 7,
    RealUNO = 8,
    RealUEQ = 9,
    RealUGT = 10,
    RealUGE = 11,
    RealULT = 12,
    RealULE = 13,
    RealUNE = 14,
293
    RealPredicateTrue = 15,
294 295
}

296
// The LLVM TypeKind type - must stay in sync with the def of
297
// LLVMTypeKind in llvm/include/llvm-c/Core.h
N
Niko Matsakis 已提交
298
#[derive(Copy, Clone, PartialEq, Debug)]
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
#[repr(C)]
pub enum TypeKind {
    Void      = 0,
    Half      = 1,
    Float     = 2,
    Double    = 3,
    X86_FP80  = 4,
    FP128     = 5,
    PPC_FP128 = 6,
    Label     = 7,
    Integer   = 8,
    Function  = 9,
    Struct    = 10,
    Array     = 11,
    Pointer   = 12,
    Vector    = 13,
    Metadata  = 14,
    X86_MMX   = 15,
}

319
#[repr(C)]
N
Niko Matsakis 已提交
320
#[derive(Copy, Clone)]
321
pub enum AtomicBinOp {
A
Alex Crichton 已提交
322 323 324 325 326 327 328 329 330 331 332
    AtomicXchg = 0,
    AtomicAdd  = 1,
    AtomicSub  = 2,
    AtomicAnd  = 3,
    AtomicNand = 4,
    AtomicOr   = 5,
    AtomicXor  = 6,
    AtomicMax  = 7,
    AtomicMin  = 8,
    AtomicUMax = 9,
    AtomicUMin = 10,
E
Eric Holk 已提交
333 334
}

335
#[repr(C)]
N
Niko Matsakis 已提交
336
#[derive(Copy, Clone)]
337
pub enum AtomicOrdering {
E
Eric Holk 已提交
338 339 340 341 342 343 344 345 346 347
    NotAtomic = 0,
    Unordered = 1,
    Monotonic = 2,
    // Consume = 3,  // Not specified yet.
    Acquire = 4,
    Release = 5,
    AcquireRelease = 6,
    SequentiallyConsistent = 7
}

348 349 350 351 352 353 354
#[repr(C)]
#[derive(Copy, Clone)]
pub enum SynchronizationScope {
    SingleThread = 0,
    CrossThread = 1
}

355
#[repr(C)]
N
Niko Matsakis 已提交
356
#[derive(Copy, Clone)]
357
pub enum FileType {
358 359 360
    Other,
    AssemblyFile,
    ObjectFile,
361 362
}

N
Niko Matsakis 已提交
363
#[derive(Copy, Clone)]
364
pub enum MetadataType {
365 366 367 368 369
    MD_dbg = 0,
    MD_tbaa = 1,
    MD_prof = 2,
    MD_fpmath = 3,
    MD_range = 4,
370 371 372 373 374 375 376
    MD_tbaa_struct = 5,
    MD_invariant_load = 6,
    MD_alias_scope = 7,
    MD_noalias = 8,
    MD_nontemporal = 9,
    MD_mem_parallel_loop_access = 10,
    MD_nonnull = 11,
377 378
}

L
Luqman Aden 已提交
379
// Inline Asm Dialect
N
Niko Matsakis 已提交
380
#[derive(Copy, Clone)]
L
Luqman Aden 已提交
381 382 383 384 385
pub enum AsmDialect {
    AD_ATT   = 0,
    AD_Intel = 1
}

N
Niko Matsakis 已提交
386
#[derive(Copy, Clone, PartialEq)]
387
#[repr(C)]
388
pub enum CodeGenOptLevel {
389 390 391 392 393
    Other,
    None,
    Less,
    Default,
    Aggressive,
394 395
}

396 397 398 399 400 401 402 403
#[derive(Copy, Clone, PartialEq)]
#[repr(C)]
pub enum CodeGenOptSize {
    CodeGenOptSizeNone = 0,
    CodeGenOptSizeDefault = 1,
    CodeGenOptSizeAggressive = 2,
}

N
Niko Matsakis 已提交
404
#[derive(Copy, Clone, PartialEq)]
405
#[repr(C)]
406
pub enum RelocMode {
407 408 409 410
    Default = 0,
    Static = 1,
    PIC = 2,
    DynamicNoPic = 3,
411 412
}

413
#[repr(C)]
N
Niko Matsakis 已提交
414
#[derive(Copy, Clone)]
415 416 417 418 419 420 421 422
pub enum CodeModel {
    Other,
    Default,
    JITDefault,
    Small,
    Kernel,
    Medium,
    Large,
423 424
}

425
#[repr(C)]
N
Niko Matsakis 已提交
426
#[derive(Copy, Clone)]
427 428 429 430 431 432 433 434 435 436 437
pub enum DiagnosticKind {
    DK_InlineAsm = 0,
    DK_StackSize,
    DK_DebugMetadataVersion,
    DK_SampleProfile,
    DK_OptimizationRemark,
    DK_OptimizationRemarkMissed,
    DK_OptimizationRemarkAnalysis,
    DK_OptimizationFailure,
}

A
Alex Crichton 已提交
438 439 440
#[repr(C)]
#[derive(Copy, Clone)]
pub enum ArchiveKind {
441
    Other,
A
Alex Crichton 已提交
442 443 444 445 446 447
    K_GNU,
    K_MIPS64,
    K_BSD,
    K_COFF,
}

J
Jake Goulding 已提交
448 449 450 451 452 453 454 455 456 457 458 459 460 461
impl FromStr for ArchiveKind {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "gnu" => Ok(ArchiveKind::K_GNU),
            "mips64" => Ok(ArchiveKind::K_MIPS64),
            "bsd" => Ok(ArchiveKind::K_BSD),
            "coff" => Ok(ArchiveKind::K_COFF),
            _ => Err(()),
        }
    }
}

462 463 464
/// Represents the different LLVM passes Rust supports
#[derive(Copy, Clone, PartialEq, Debug)]
#[repr(C)]
465 466
pub enum PassKind {
    Other,
467 468 469 470
    Function,
    Module,
}

471
// Opaque pointer types
472
#[allow(missing_copy_implementations)]
473
pub enum Module_opaque {}
474
pub type ModuleRef = *mut Module_opaque;
475
#[allow(missing_copy_implementations)]
476
pub enum Context_opaque {}
477
pub type ContextRef = *mut Context_opaque;
478
#[allow(missing_copy_implementations)]
479
pub enum Type_opaque {}
480
pub type TypeRef = *mut Type_opaque;
481
#[allow(missing_copy_implementations)]
482
pub enum Value_opaque {}
483
pub type ValueRef = *mut Value_opaque;
484
#[allow(missing_copy_implementations)]
485 486
pub enum Metadata_opaque {}
pub type MetadataRef = *mut Metadata_opaque;
487
#[allow(missing_copy_implementations)]
488
pub enum BasicBlock_opaque {}
489
pub type BasicBlockRef = *mut BasicBlock_opaque;
490
#[allow(missing_copy_implementations)]
491
pub enum Builder_opaque {}
492
pub type BuilderRef = *mut Builder_opaque;
493
#[allow(missing_copy_implementations)]
494
pub enum ExecutionEngine_opaque {}
495
pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
496
#[allow(missing_copy_implementations)]
497
pub enum MemoryBuffer_opaque {}
498
pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
499
#[allow(missing_copy_implementations)]
500
pub enum PassManager_opaque {}
501
pub type PassManagerRef = *mut PassManager_opaque;
502
#[allow(missing_copy_implementations)]
503
pub enum PassManagerBuilder_opaque {}
504
pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
505
#[allow(missing_copy_implementations)]
506
pub enum Use_opaque {}
507
pub type UseRef = *mut Use_opaque;
508
#[allow(missing_copy_implementations)]
509
pub enum TargetData_opaque {}
510
pub type TargetDataRef = *mut TargetData_opaque;
511
#[allow(missing_copy_implementations)]
512
pub enum ObjectFile_opaque {}
513
pub type ObjectFileRef = *mut ObjectFile_opaque;
514
#[allow(missing_copy_implementations)]
515
pub enum SectionIterator_opaque {}
516
pub type SectionIteratorRef = *mut SectionIterator_opaque;
517
#[allow(missing_copy_implementations)]
518
pub enum Pass_opaque {}
519
pub type PassRef = *mut Pass_opaque;
520
#[allow(missing_copy_implementations)]
521
pub enum TargetMachine_opaque {}
522
pub type TargetMachineRef = *mut TargetMachine_opaque;
523
pub enum Archive_opaque {}
524
pub type ArchiveRef = *mut Archive_opaque;
525 526 527 528
pub enum ArchiveIterator_opaque {}
pub type ArchiveIteratorRef = *mut ArchiveIterator_opaque;
pub enum ArchiveChild_opaque {}
pub type ArchiveChildRef = *mut ArchiveChild_opaque;
529
#[allow(missing_copy_implementations)]
530 531
pub enum Twine_opaque {}
pub type TwineRef = *mut Twine_opaque;
532
#[allow(missing_copy_implementations)]
533 534
pub enum DiagnosticInfo_opaque {}
pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
535
#[allow(missing_copy_implementations)]
536 537
pub enum DebugLoc_opaque {}
pub type DebugLocRef = *mut DebugLoc_opaque;
538
#[allow(missing_copy_implementations)]
539 540
pub enum SMDiagnostic_opaque {}
pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
541 542 543
#[allow(missing_copy_implementations)]
pub enum RustArchiveMember_opaque {}
pub type RustArchiveMemberRef = *mut RustArchiveMember_opaque;
544 545 546
#[allow(missing_copy_implementations)]
pub enum OperandBundleDef_opaque {}
pub type OperandBundleDefRef = *mut OperandBundleDef_opaque;
547 548

pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
549
pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
550

V
Vadim Chugunov 已提交
551
pub mod debuginfo {
S
Steven Fackler 已提交
552
    pub use self::DIDescriptorFlags::*;
553
    use super::{MetadataRef};
554

555
    #[allow(missing_copy_implementations)]
V
Vadim Chugunov 已提交
556
    pub enum DIBuilder_opaque {}
557
    pub type DIBuilderRef = *mut DIBuilder_opaque;
558

559
    pub type DIDescriptor = MetadataRef;
V
Vadim Chugunov 已提交
560 561 562 563 564
    pub type DIScope = DIDescriptor;
    pub type DILocation = DIDescriptor;
    pub type DIFile = DIScope;
    pub type DILexicalBlock = DIScope;
    pub type DISubprogram = DIScope;
565
    pub type DINameSpace = DIScope;
V
Vadim Chugunov 已提交
566 567 568 569 570
    pub type DIType = DIDescriptor;
    pub type DIBasicType = DIType;
    pub type DIDerivedType = DIType;
    pub type DICompositeType = DIDerivedType;
    pub type DIVariable = DIDescriptor;
571
    pub type DIGlobalVariable = DIDescriptor;
V
Vadim Chugunov 已提交
572 573
    pub type DIArray = DIDescriptor;
    pub type DISubrange = DIDescriptor;
574 575
    pub type DIEnumerator = DIDescriptor;
    pub type DITemplateTypeParameter = DIDescriptor;
V
Vadim Chugunov 已提交
576

N
Niko Matsakis 已提交
577
    #[derive(Copy, Clone)]
V
Vadim Chugunov 已提交
578 579 580 581 582 583 584 585 586 587 588 589 590
    pub enum DIDescriptorFlags {
      FlagPrivate            = 1 << 0,
      FlagProtected          = 1 << 1,
      FlagFwdDecl            = 1 << 2,
      FlagAppleBlock         = 1 << 3,
      FlagBlockByrefStruct   = 1 << 4,
      FlagVirtual            = 1 << 5,
      FlagArtificial         = 1 << 6,
      FlagExplicit           = 1 << 7,
      FlagPrototyped         = 1 << 8,
      FlagObjcClassComplete  = 1 << 9,
      FlagObjectPointer      = 1 << 10,
      FlagVector             = 1 << 11,
591 592 593 594
      FlagStaticMember       = 1 << 12,
      FlagIndirectVariable   = 1 << 13,
      FlagLValueReference    = 1 << 14,
      FlagRValueReference    = 1 << 15
V
Vadim Chugunov 已提交
595 596 597
    }
}

598

599 600 601 602 603 604 605 606 607 608 609
// Link to our native llvm bindings (things that we need to use the C++ api
// for) and because llvm is written in C++ we need to link against libstdc++
//
// You'll probably notice that there is an omission of all LLVM libraries
// from this location. This is because the set of LLVM libraries that we
// link to is mostly defined by LLVM, and the `llvm-config` tool is used to
// figure out the exact set of libraries. To do this, the build system
// generates an llvmdeps.rs file next to this one which will be
// automatically updated whenever LLVM is updated to include an up-to-date
// set of the libraries we need to link to LLVM for.
#[link(name = "rustllvm", kind = "static")]
610 611 612
#[cfg(not(cargobuild))]
extern {}

A
Alex Crichton 已提交
613
#[linked_from = "rustllvm"] // not quite true but good enough
614 615 616 617 618 619 620 621 622 623 624 625 626 627
extern {
    /* Create and destroy contexts. */
    pub fn LLVMContextCreate() -> ContextRef;
    pub fn LLVMContextDispose(C: ContextRef);
    pub fn LLVMGetMDKindIDInContext(C: ContextRef,
                                    Name: *const c_char,
                                    SLen: c_uint)
                                    -> c_uint;

    /* Create and destroy modules. */
    pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
                                             C: ContextRef)
                                             -> ModuleRef;
    pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
628
    pub fn LLVMCloneModule(M: ModuleRef) -> ModuleRef;
629 630
    pub fn LLVMDisposeModule(M: ModuleRef);

S
Steve Klabnik 已提交
631
    /// Data layout. See Module::getDataLayout.
632 633 634
    pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
    pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);

S
Steve Klabnik 已提交
635
    /// Target triple. See Module::getTargetTriple.
636 637 638
    pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
    pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);

S
Steve Klabnik 已提交
639
    /// See Module::dump.
640 641
    pub fn LLVMDumpModule(M: ModuleRef);

S
Steve Klabnik 已提交
642
    /// See Module::setModuleInlineAsm.
643 644
    pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);

S
Steve Klabnik 已提交
645
    /// See llvm::LLVMTypeKind::getTypeID.
646 647
    pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;

S
Steve Klabnik 已提交
648
    /// See llvm::LLVMType::getContext.
649 650 651 652 653 654 655 656 657
    pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;

    /* Operations on integer types */
    pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
658
                                -> TypeRef;
659

660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
    pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;

    /* Operations on real types */
    pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;

    /* Operations on function types */
    pub fn LLVMFunctionType(ReturnType: TypeRef,
                            ParamTypes: *const TypeRef,
                            ParamCount: c_uint,
                            IsVarArg: Bool)
                            -> TypeRef;
    pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
    pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
    pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
A
Ariel Ben-Yehuda 已提交
678
    pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701

    /* Operations on struct types */
    pub fn LLVMStructTypeInContext(C: ContextRef,
                                   ElementTypes: *const TypeRef,
                                   ElementCount: c_uint,
                                   Packed: Bool)
                                   -> TypeRef;
    pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
    pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
                                     Dest: *mut TypeRef);
    pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;

    /* Operations on array, pointer, and vector types (sequence types) */
    pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
    pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
                           -> TypeRef;
    pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
                          -> TypeRef;

    pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
    pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
    pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
    pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
E
Eli Friedman 已提交
702
                                  -> *const c_void;
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
    pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;

    /* Operations on other types */
    pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
    pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;

    /* Operations on all values */
    pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
    pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
    pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
    pub fn LLVMDumpValue(Val: ValueRef);
    pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
    pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
    pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
    pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);

    /* Operations on Uses */
    pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
    pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
    pub fn LLVMGetUser(U: UseRef) -> ValueRef;
    pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;

    /* Operations on Users */
    pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
    pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
    pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);

    /* Operations on constants of any type */
    pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
    /* all zeroes */
    pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
    pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
                         -> ValueRef;
739
    /* only for isize/vector */
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
    pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
    pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
    pub fn LLVMIsNull(Val: ValueRef) -> Bool;
    pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
    pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;

    /* Operations on metadata */
    pub fn LLVMMDStringInContext(C: ContextRef,
                                 Str: *const c_char,
                                 SLen: c_uint)
                                 -> ValueRef;
    pub fn LLVMMDNodeInContext(C: ContextRef,
                               Vals: *const ValueRef,
                               Count: c_uint)
                               -> ValueRef;
    pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
                                       Str: *const c_char,
                                       Val: ValueRef);

    /* Operations on scalar constants */
    pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
                        -> ValueRef;
    pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
                                -> ValueRef;
    pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
                                       Text: *const c_char,
                                       SLen: c_uint,
                                       Radix: u8)
                                       -> ValueRef;
    pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
    pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
                                 -> ValueRef;
    pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
                                        Text: *const c_char,
                                        SLen: c_uint)
                                        -> ValueRef;
    pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
    pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
778 779


780 781 782 783 784 785 786 787 788 789 790
    /* Operations on composite constants */
    pub fn LLVMConstStringInContext(C: ContextRef,
                                    Str: *const c_char,
                                    Length: c_uint,
                                    DontNullTerminate: Bool)
                                    -> ValueRef;
    pub fn LLVMConstStructInContext(C: ContextRef,
                                    ConstantVals: *const ValueRef,
                                    Count: c_uint,
                                    Packed: Bool)
                                    -> ValueRef;
791

792 793 794 795 796 797
    pub fn LLVMConstArray(ElementTy: TypeRef,
                          ConstantVals: *const ValueRef,
                          Length: c_uint)
                          -> ValueRef;
    pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
                           -> ValueRef;
798

799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
    /* Constant expressions */
    pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
    pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
    pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
    pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
    pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
    pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
    pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
    pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
                        -> ValueRef;
    pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
                           -> ValueRef;
    pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
                           -> ValueRef;
    pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
                        -> ValueRef;
    pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
                           -> ValueRef;
    pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
                           -> ValueRef;
    pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
                        -> ValueRef;
    pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
                           -> ValueRef;
    pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
                           -> ValueRef;
    pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
                              RHSConstant: ValueRef)
                              -> ValueRef;
    pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
                        -> ValueRef;
    pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
                       -> ValueRef;
    pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
                        -> ValueRef;
    pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
                        -> ValueRef;
    pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
                         -> ValueRef;
    pub fn LLVMConstGEP(ConstantVal: ValueRef,
                        ConstantIndices: *const ValueRef,
                        NumIndices: c_uint)
                        -> ValueRef;
    pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
                                ConstantIndices: *const ValueRef,
                                NumIndices: c_uint)
                                -> ValueRef;
    pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
                          -> ValueRef;
    pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
                         -> ValueRef;
    pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
                         -> ValueRef;
    pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
873
                            -> ValueRef;
874 875 876 877 878 879 880 881 882 883 884
    pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
                          -> ValueRef;
    pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
                           -> ValueRef;
    pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
                           -> ValueRef;
    pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
                           -> ValueRef;
    pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
                           -> ValueRef;
    pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
885
                             -> ValueRef;
886
    pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
887
                             -> ValueRef;
888
    pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
889
                            -> ValueRef;
890
    pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
891
                                  -> ValueRef;
892 893 894 895 896 897 898 899 900
    pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
                                  -> ValueRef;
    pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
                                   -> ValueRef;
    pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
                                -> ValueRef;
    pub fn LLVMConstIntCast(ConstantVal: ValueRef,
                            ToType: TypeRef,
                            isSigned: Bool)
901
                            -> ValueRef;
902
    pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
903
                           -> ValueRef;
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
    pub fn LLVMConstSelect(ConstantCondition: ValueRef,
                           ConstantIfTrue: ValueRef,
                           ConstantIfFalse: ValueRef)
                           -> ValueRef;
    pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
                                   IndexConstant: ValueRef)
                                   -> ValueRef;
    pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
                                  ElementValueConstant: ValueRef,
                                  IndexConstant: ValueRef)
                                  -> ValueRef;
    pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
                                  VectorBConstant: ValueRef,
                                  MaskConstant: ValueRef)
                                  -> ValueRef;
    pub fn LLVMConstExtractValue(AggConstant: ValueRef,
                                 IdxList: *const c_uint,
                                 NumIdx: c_uint)
922
                                 -> ValueRef;
923 924 925 926
    pub fn LLVMConstInsertValue(AggConstant: ValueRef,
                                ElementValueConstant: ValueRef,
                                IdxList: *const c_uint,
                                NumIdx: c_uint)
927
                                -> ValueRef;
928 929 930 931 932 933 934
    pub fn LLVMConstInlineAsm(Ty: TypeRef,
                              AsmString: *const c_char,
                              Constraints: *const c_char,
                              HasSideEffects: Bool,
                              IsAlignStack: Bool)
                              -> ValueRef;
    pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
935 936


937

938 939 940 941 942 943 944 945 946 947 948
    /* Operations on global variables, functions, and aliases (globals) */
    pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
    pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
    pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
    pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
    pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
    pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
    pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
    pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
    pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
    pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
M
Marijn Haverbeke 已提交
949

950

951
    /* Operations on global variables */
952
    pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
953 954 955 956
    pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
                                       Ty: TypeRef,
957
                                       Name: *const c_char,
958
                                       AddressSpace: c_uint)
959
                                       -> ValueRef;
960
    pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
961
    pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef;
962 963 964 965 966 967 968 969 970 971 972 973
    pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
    pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
    pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
    pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
    pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
    pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
    pub fn LLVMSetInitializer(GlobalVar: ValueRef,
                              ConstantVal: ValueRef);
    pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
    pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
    pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
    pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
974
    pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996

    /* Operations on aliases */
    pub fn LLVMAddAlias(M: ModuleRef,
                        Ty: TypeRef,
                        Aliasee: ValueRef,
                        Name: *const c_char)
                        -> ValueRef;

    /* Operations on functions */
    pub fn LLVMAddFunction(M: ModuleRef,
                           Name: *const c_char,
                           FunctionTy: TypeRef)
                           -> ValueRef;
    pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
    pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
    pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
    pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
    pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
    pub fn LLVMDeleteFunction(Fn: ValueRef);
    pub fn LLVMGetOrInsertFunction(M: ModuleRef,
                                   Name: *const c_char,
                                   FunctionTy: TypeRef)
997
                                   -> ValueRef;
998 999 1000 1001 1002
    pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
    pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
    pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
    pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
    pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
1003
    pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
1004 1005
    pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
    pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
A
Alex Crichton 已提交
1006 1007 1008
    pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
                                          Name: *const c_char,
                                          Value: *const c_char);
1009
    pub fn LLVMRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: uint64_t);
1010
    pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
1011 1012
    pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_uint;
    pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_uint);
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076

    /* Operations on parameters */
    pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
    pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
    pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
    pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
    pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
    pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
    pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
    pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
    pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
    pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
    pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
    pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);

    /* Operations on basic blocks */
    pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
    pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
    pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
    pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
    pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
    pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
    pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
    pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
    pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
    pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
    pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;

    pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
                                         Fn: ValueRef,
                                         Name: *const c_char)
                                         -> BasicBlockRef;
    pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
                                         BB: BasicBlockRef,
                                         Name: *const c_char)
                                         -> BasicBlockRef;
    pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);

    pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
                                   MoveAfter: BasicBlockRef);

    pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
                                    MoveBefore: BasicBlockRef);

    /* Operations on instructions */
    pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
    pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
    pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
    pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
    pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
    pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);

    /* Operations on call sites */
    pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
    pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
    pub fn LLVMAddInstrAttribute(Instr: ValueRef,
                                 index: c_uint,
                                 IA: c_uint);
    pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
                                    index: c_uint,
                                    IA: c_uint);
    pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
                                      index: c_uint,
                                      align: c_uint);
1077
    pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef,
1078 1079
                                    index: c_uint,
                                    Val: uint64_t);
1080 1081 1082
    pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
                                              index: c_uint,
                                              bytes: uint64_t);
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118

    /* Operations on call instructions (only) */
    pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
    pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);

    /* Operations on load/store instructions (only) */
    pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
    pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);

    /* Operations on phi nodes */
    pub fn LLVMAddIncoming(PhiNode: ValueRef,
                           IncomingValues: *const ValueRef,
                           IncomingBlocks: *const BasicBlockRef,
                           Count: c_uint);
    pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
    pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
                                -> ValueRef;
    pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
                                -> BasicBlockRef;

    /* Instruction builders */
    pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
    pub fn LLVMPositionBuilder(Builder: BuilderRef,
                               Block: BasicBlockRef,
                               Instr: ValueRef);
    pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
                                     Instr: ValueRef);
    pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
                                    Block: BasicBlockRef);
    pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
    pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
    pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
    pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
                                         Instr: ValueRef,
                                         Name: *const c_char);
    pub fn LLVMDisposeBuilder(Builder: BuilderRef);
M
Murarth 已提交
1119

1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145
    /* Metadata */
    pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
    pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
    pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);

    /* Terminators */
    pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
    pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
    pub fn LLVMBuildAggregateRet(B: BuilderRef,
                                 RetVals: *const ValueRef,
                                 N: c_uint)
                                 -> ValueRef;
    pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
    pub fn LLVMBuildCondBr(B: BuilderRef,
                           If: ValueRef,
                           Then: BasicBlockRef,
                           Else: BasicBlockRef)
                           -> ValueRef;
    pub fn LLVMBuildSwitch(B: BuilderRef,
                           V: ValueRef,
                           Else: BasicBlockRef,
                           NumCases: c_uint)
                           -> ValueRef;
    pub fn LLVMBuildIndirectBr(B: BuilderRef,
                               Addr: ValueRef,
                               NumDests: c_uint)
1146
                               -> ValueRef;
1147 1148 1149 1150 1151 1152 1153 1154 1155
    pub fn LLVMRustBuildInvoke(B: BuilderRef,
                               Fn: ValueRef,
                               Args: *const ValueRef,
                               NumArgs: c_uint,
                               Then: BasicBlockRef,
                               Catch: BasicBlockRef,
                               Bundle: OperandBundleDefRef,
                               Name: *const c_char)
                               -> ValueRef;
1156 1157 1158 1159 1160 1161 1162
    pub fn LLVMRustBuildLandingPad(B: BuilderRef,
                                   Ty: TypeRef,
                                   PersFn: ValueRef,
                                   NumClauses: c_uint,
                                   Name: *const c_char,
                                   F: ValueRef)
                                   -> ValueRef;
1163 1164 1165
    pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
    pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;

1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
    pub fn LLVMRustBuildCleanupPad(B: BuilderRef,
                                   ParentPad: ValueRef,
                                   ArgCnt: c_uint,
                                   Args: *const ValueRef,
                                   Name: *const c_char) -> ValueRef;
    pub fn LLVMRustBuildCleanupRet(B: BuilderRef,
                                   CleanupPad: ValueRef,
                                   UnwindBB: BasicBlockRef) -> ValueRef;
    pub fn LLVMRustBuildCatchPad(B: BuilderRef,
                                 ParentPad: ValueRef,
                                 ArgCnt: c_uint,
                                 Args: *const ValueRef,
                                 Name: *const c_char) -> ValueRef;
    pub fn LLVMRustBuildCatchRet(B: BuilderRef,
                                 Pad: ValueRef,
                                 BB: BasicBlockRef) -> ValueRef;
    pub fn LLVMRustBuildCatchSwitch(Builder: BuilderRef,
                                    ParentPad: ValueRef,
                                    BB: BasicBlockRef,
                                    NumHandlers: c_uint,
                                    Name: *const c_char) -> ValueRef;
    pub fn LLVMRustAddHandler(CatchSwitch: ValueRef,
                              Handler: BasicBlockRef);
    pub fn LLVMRustSetPersonalityFn(B: BuilderRef, Pers: ValueRef);

1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
    /* Add a case to the switch instruction */
    pub fn LLVMAddCase(Switch: ValueRef,
                       OnVal: ValueRef,
                       Dest: BasicBlockRef);

    /* Add a destination to the indirectbr instruction */
    pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);

    /* Add a clause to the landing pad instruction */
    pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);

    /* Set the cleanup on a landing pad instruction */
    pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);

    /* Arithmetic */
    pub fn LLVMBuildAdd(B: BuilderRef,
                        LHS: ValueRef,
                        RHS: ValueRef,
                        Name: *const c_char)
                        -> ValueRef;
    pub fn LLVMBuildNSWAdd(B: BuilderRef,
1212 1213
                           LHS: ValueRef,
                           RHS: ValueRef,
1214
                           Name: *const c_char)
1215
                           -> ValueRef;
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
    pub fn LLVMBuildNUWAdd(B: BuilderRef,
                           LHS: ValueRef,
                           RHS: ValueRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildFAdd(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildSub(B: BuilderRef,
                        LHS: ValueRef,
                        RHS: ValueRef,
                        Name: *const c_char)
                        -> ValueRef;
    pub fn LLVMBuildNSWSub(B: BuilderRef,
                           LHS: ValueRef,
                           RHS: ValueRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildNUWSub(B: BuilderRef,
                           LHS: ValueRef,
                           RHS: ValueRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildFSub(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildMul(B: BuilderRef,
                        LHS: ValueRef,
                        RHS: ValueRef,
                        Name: *const c_char)
                        -> ValueRef;
    pub fn LLVMBuildNSWMul(B: BuilderRef,
                           LHS: ValueRef,
                           RHS: ValueRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildNUWMul(B: BuilderRef,
                           LHS: ValueRef,
                           RHS: ValueRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildFMul(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildUDiv(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildSDiv(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildExactSDiv(B: BuilderRef,
1277 1278
                              LHS: ValueRef,
                              RHS: ValueRef,
1279
                              Name: *const c_char)
1280
                              -> ValueRef;
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346
    pub fn LLVMBuildFDiv(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildURem(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildSRem(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildFRem(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildShl(B: BuilderRef,
                        LHS: ValueRef,
                        RHS: ValueRef,
                        Name: *const c_char)
                        -> ValueRef;
    pub fn LLVMBuildLShr(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildAShr(B: BuilderRef,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildAnd(B: BuilderRef,
                        LHS: ValueRef,
                        RHS: ValueRef,
                        Name: *const c_char)
                        -> ValueRef;
    pub fn LLVMBuildOr(B: BuilderRef,
                       LHS: ValueRef,
                       RHS: ValueRef,
                       Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildXor(B: BuilderRef,
                        LHS: ValueRef,
                        RHS: ValueRef,
                        Name: *const c_char)
                        -> ValueRef;
    pub fn LLVMBuildBinOp(B: BuilderRef,
                          Op: Opcode,
                          LHS: ValueRef,
                          RHS: ValueRef,
                          Name: *const c_char)
                          -> ValueRef;
    pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
                        -> ValueRef;
    pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
                        -> ValueRef;
1347
    pub fn LLVMRustSetHasUnsafeAlgebra(Instr: ValueRef);
1348

1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
    /* Memory */
    pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
    pub fn LLVMBuildLoad(B: BuilderRef,
                         PointerVal: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;

    pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
                          -> ValueRef;

    pub fn LLVMBuildGEP(B: BuilderRef,
                        Pointer: ValueRef,
                        Indices: *const ValueRef,
                        NumIndices: c_uint,
                        Name: *const c_char)
                        -> ValueRef;
    pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
                                Pointer: ValueRef,
                                Indices: *const ValueRef,
                                NumIndices: c_uint,
                                Name: *const c_char)
                                -> ValueRef;
    pub fn LLVMBuildStructGEP(B: BuilderRef,
                              Pointer: ValueRef,
                              Idx: c_uint,
                              Name: *const c_char)
                              -> ValueRef;
    pub fn LLVMBuildGlobalString(B: BuilderRef,
                                 Str: *const c_char,
                                 Name: *const c_char)
                                 -> ValueRef;
    pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
                                    Str: *const c_char,
1384
                                    Name: *const c_char)
1385
                                    -> ValueRef;
1386

1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425
    /* Casts */
    pub fn LLVMBuildTrunc(B: BuilderRef,
                          Val: ValueRef,
                          DestTy: TypeRef,
                          Name: *const c_char)
                          -> ValueRef;
    pub fn LLVMBuildZExt(B: BuilderRef,
                         Val: ValueRef,
                         DestTy: TypeRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildSExt(B: BuilderRef,
                         Val: ValueRef,
                         DestTy: TypeRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildFPToUI(B: BuilderRef,
                           Val: ValueRef,
                           DestTy: TypeRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildFPToSI(B: BuilderRef,
                           Val: ValueRef,
                           DestTy: TypeRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildUIToFP(B: BuilderRef,
                           Val: ValueRef,
                           DestTy: TypeRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildSIToFP(B: BuilderRef,
                           Val: ValueRef,
                           DestTy: TypeRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildFPTrunc(B: BuilderRef,
                            Val: ValueRef,
                            DestTy: TypeRef,
1426
                            Name: *const c_char)
1427
                            -> ValueRef;
1428 1429 1430 1431 1432 1433
    pub fn LLVMBuildFPExt(B: BuilderRef,
                          Val: ValueRef,
                          DestTy: TypeRef,
                          Name: *const c_char)
                          -> ValueRef;
    pub fn LLVMBuildPtrToInt(B: BuilderRef,
1434 1435
                             Val: ValueRef,
                             DestTy: TypeRef,
1436
                             Name: *const c_char)
1437
                             -> ValueRef;
1438
    pub fn LLVMBuildIntToPtr(B: BuilderRef,
1439 1440
                             Val: ValueRef,
                             DestTy: TypeRef,
1441
                             Name: *const c_char)
1442
                             -> ValueRef;
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468
    pub fn LLVMBuildBitCast(B: BuilderRef,
                            Val: ValueRef,
                            DestTy: TypeRef,
                            Name: *const c_char)
                            -> ValueRef;
    pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
                                  Val: ValueRef,
                                  DestTy: TypeRef,
                                  Name: *const c_char)
                                  -> ValueRef;
    pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
                                  Val: ValueRef,
                                  DestTy: TypeRef,
                                  Name: *const c_char)
                                  -> ValueRef;
    pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
                                   Val: ValueRef,
                                   DestTy: TypeRef,
                                   Name: *const c_char)
                                   -> ValueRef;
    pub fn LLVMBuildCast(B: BuilderRef,
                         Op: Opcode,
                         Val: ValueRef,
                         DestTy: TypeRef,
                         Name: *const c_char) -> ValueRef;
    pub fn LLVMBuildPointerCast(B: BuilderRef,
1469 1470
                                Val: ValueRef,
                                DestTy: TypeRef,
1471
                                Name: *const c_char)
1472
                                -> ValueRef;
1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
    pub fn LLVMBuildIntCast(B: BuilderRef,
                            Val: ValueRef,
                            DestTy: TypeRef,
                            Name: *const c_char)
                            -> ValueRef;
    pub fn LLVMBuildFPCast(B: BuilderRef,
                           Val: ValueRef,
                           DestTy: TypeRef,
                           Name: *const c_char)
                           -> ValueRef;

    /* Comparisons */
    pub fn LLVMBuildICmp(B: BuilderRef,
                         Op: c_uint,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;
    pub fn LLVMBuildFCmp(B: BuilderRef,
                         Op: c_uint,
                         LHS: ValueRef,
                         RHS: ValueRef,
                         Name: *const c_char)
                         -> ValueRef;

    /* Miscellaneous instructions */
    pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
                        -> ValueRef;
1501 1502 1503 1504 1505 1506 1507
    pub fn LLVMRustBuildCall(B: BuilderRef,
                             Fn: ValueRef,
                             Args: *const ValueRef,
                             NumArgs: c_uint,
                             Bundle: OperandBundleDefRef,
                             Name: *const c_char)
                             -> ValueRef;
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
    pub fn LLVMBuildSelect(B: BuilderRef,
                           If: ValueRef,
                           Then: ValueRef,
                           Else: ValueRef,
                           Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildVAArg(B: BuilderRef,
                          list: ValueRef,
                          Ty: TypeRef,
                          Name: *const c_char)
                          -> ValueRef;
    pub fn LLVMBuildExtractElement(B: BuilderRef,
                                   VecVal: ValueRef,
                                   Index: ValueRef,
                                   Name: *const c_char)
                                   -> ValueRef;
    pub fn LLVMBuildInsertElement(B: BuilderRef,
                                  VecVal: ValueRef,
                                  EltVal: ValueRef,
                                  Index: ValueRef,
                                  Name: *const c_char)
                                  -> ValueRef;
    pub fn LLVMBuildShuffleVector(B: BuilderRef,
                                  V1: ValueRef,
                                  V2: ValueRef,
                                  Mask: ValueRef,
                                  Name: *const c_char)
                                  -> ValueRef;
    pub fn LLVMBuildExtractValue(B: BuilderRef,
                                 AggVal: ValueRef,
                                 Index: c_uint,
1539
                                 Name: *const c_char)
1540
                                 -> ValueRef;
1541 1542 1543 1544
    pub fn LLVMBuildInsertValue(B: BuilderRef,
                                AggVal: ValueRef,
                                EltVal: ValueRef,
                                Index: c_uint,
1545
                                Name: *const c_char)
1546
                                -> ValueRef;
1547

1548 1549 1550
    pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
                           -> ValueRef;
    pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1551
                              -> ValueRef;
1552 1553 1554 1555 1556
    pub fn LLVMBuildPtrDiff(B: BuilderRef,
                            LHS: ValueRef,
                            RHS: ValueRef,
                            Name: *const c_char)
                            -> ValueRef;
1557

1558 1559 1560 1561 1562 1563
    /* Atomic Operations */
    pub fn LLVMBuildAtomicLoad(B: BuilderRef,
                               PointerVal: ValueRef,
                               Name: *const c_char,
                               Order: AtomicOrdering,
                               Alignment: c_uint)
1564
                               -> ValueRef;
1565

1566 1567 1568 1569 1570 1571
    pub fn LLVMBuildAtomicStore(B: BuilderRef,
                                Val: ValueRef,
                                Ptr: ValueRef,
                                Order: AtomicOrdering,
                                Alignment: c_uint)
                                -> ValueRef;
M
Tidy  
Matthijs Hofstra 已提交
1572

1573
    pub fn LLVMRustBuildAtomicCmpXchg(B: BuilderRef,
1574
                                  LHS: ValueRef,
1575
                                  CMP: ValueRef,
1576
                                  RHS: ValueRef,
1577
                                  Order: AtomicOrdering,
1578 1579
                                  FailureOrder: AtomicOrdering,
                                  Weak: Bool)
1580
                                  -> ValueRef;
1581 1582 1583 1584 1585 1586 1587
    pub fn LLVMBuildAtomicRMW(B: BuilderRef,
                              Op: AtomicBinOp,
                              LHS: ValueRef,
                              RHS: ValueRef,
                              Order: AtomicOrdering,
                              SingleThreaded: Bool)
                              -> ValueRef;
1588

1589 1590 1591
    pub fn LLVMBuildAtomicFence(B: BuilderRef,
                                Order: AtomicOrdering,
                                Scope: SynchronizationScope);
1592

1593

1594 1595 1596
    /* Selected entries from the downcasts. */
    pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
    pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1597

S
Steve Klabnik 已提交
1598
    /// Writes a module to the specified path. Returns 0 on success.
1599
    pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1600

S
Steve Klabnik 已提交
1601
    /// Creates target data from a target layout string.
1602
    pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
S
Steve Klabnik 已提交
1603
    /// Number of bytes clobbered when doing a Store to *T.
1604 1605
    pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
                               -> c_ulonglong;
1606

S
Steve Klabnik 已提交
1607
    /// Number of bytes clobbered when doing a Store to *T.
1608 1609
    pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
                                -> c_ulonglong;
1610

S
Steve Klabnik 已提交
1611
    /// Distance between successive elements in an array of T. Includes ABI padding.
1612
    pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1613

S
Steve Klabnik 已提交
1614
    /// Returns the preferred alignment of a type.
1615 1616
    pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
                                        -> c_uint;
S
Steve Klabnik 已提交
1617
    /// Returns the minimum alignment of a type.
1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
    pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
                                  -> c_uint;

    /// Computes the byte offset of the indexed struct element for a
    /// target.
    pub fn LLVMOffsetOfElement(TD: TargetDataRef,
                               StructTy: TypeRef,
                               Element: c_uint)
                               -> c_ulonglong;

S
Steve Klabnik 已提交
1628
    /// Returns the minimum alignment of a type when part of a call frame.
1629 1630
    pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
                                        -> c_uint;
L
Luqman Aden 已提交
1631

S
Steve Klabnik 已提交
1632
    /// Disposes target data.
1633 1634
    pub fn LLVMDisposeTargetData(TD: TargetDataRef);

S
Steve Klabnik 已提交
1635
    /// Creates a pass manager.
1636 1637
    pub fn LLVMCreatePassManager() -> PassManagerRef;

S
Steve Klabnik 已提交
1638
    /// Creates a function-by-function pass manager
1639 1640 1641
    pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
                                                  -> PassManagerRef;

S
Steve Klabnik 已提交
1642
    /// Disposes a pass manager.
1643 1644
    pub fn LLVMDisposePassManager(PM: PassManagerRef);

S
Steve Klabnik 已提交
1645
    /// Runs a pass manager on a module.
1646 1647
    pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;

S
Steve Klabnik 已提交
1648
    /// Runs the function passes on the provided function.
1649 1650 1651
    pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
                                      -> Bool;

S
Steve Klabnik 已提交
1652
    /// Initializes all the function passes scheduled in the manager
1653 1654
    pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;

S
Steve Klabnik 已提交
1655
    /// Finalizes all the function passes scheduled in the manager
1656 1657 1658 1659
    pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;

    pub fn LLVMInitializePasses();

S
Steve Klabnik 已提交
1660
    /// Adds a verification pass.
1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
    pub fn LLVMAddVerifierPass(PM: PassManagerRef);

    pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
    pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
    pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
    pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
    pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
    pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
    pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
    pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
    pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
    pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
    pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
    pub fn LLVMAddReassociatePass(PM: PassManagerRef);
    pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
    pub fn LLVMAddLICMPass(PM: PassManagerRef);
    pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
    pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
    pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
    pub fn LLVMAddGVNPass(PM: PassManagerRef);
    pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
    pub fn LLVMAddSCCPPass(PM: PassManagerRef);
    pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
    pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
    pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
    pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
    pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
    pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
    pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
    pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
    pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
    pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
    pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
    pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
    pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
    pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
    pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);

    pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
    pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
    pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
                                             OptimizationLevel: c_uint);
    pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
                                              Value: Bool);
    pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
        PMB: PassManagerBuilderRef,
        Value: Bool);
    pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
        PMB: PassManagerBuilderRef,
        Value: Bool);
    pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
        PMB: PassManagerBuilderRef,
        Value: Bool);
    pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
        PMB: PassManagerBuilderRef,
        threshold: c_uint);
    pub fn LLVMPassManagerBuilderPopulateModulePassManager(
        PMB: PassManagerBuilderRef,
        PM: PassManagerRef);

    pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
        PMB: PassManagerBuilderRef,
        PM: PassManagerRef);
    pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
        PMB: PassManagerBuilderRef,
        PM: PassManagerRef,
        Internalize: Bool,
        RunInliner: Bool);

S
Steve Klabnik 已提交
1730
    /// Destroys a memory buffer.
1731 1732 1733 1734 1735
    pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);


    /* Stuff that's in rustllvm/ because it's not upstream yet. */

S
Steve Klabnik 已提交
1736
    /// Opens an object file.
1737
    pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
S
Steve Klabnik 已提交
1738
    /// Closes an object file.
1739 1740
    pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);

S
Steve Klabnik 已提交
1741
    /// Enumerates the sections in an object file.
1742
    pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
S
Steve Klabnik 已提交
1743
    /// Destroys a section iterator.
1744
    pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
S
Steve Klabnik 已提交
1745 1746
    /// Returns true if the section iterator is at the end of the section
    /// list:
1747 1748 1749
    pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
                                      SI: SectionIteratorRef)
                                      -> Bool;
S
Steve Klabnik 已提交
1750
    /// Moves the section iterator to point to the next section.
1751
    pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
S
Steve Klabnik 已提交
1752
    /// Returns the current section size.
1753
    pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
S
Steve Klabnik 已提交
1754
    /// Returns the current section contents as a string buffer.
1755 1756
    pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;

S
Steve Klabnik 已提交
1757 1758
    /// Reads the given file and returns it as a memory buffer. Use
    /// LLVMDisposeMemoryBuffer() to get rid of it.
1759 1760
    pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
                                                        -> MemoryBufferRef;
S
Steve Klabnik 已提交
1761
    /// Borrows the contents of the memory buffer (doesn't copy it)
1762 1763 1764 1765 1766 1767 1768 1769 1770
    pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
                                                 InputDataLength: size_t,
                                                 BufferName: *const c_char,
                                                 RequiresNull: Bool)
                                                 -> MemoryBufferRef;
    pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
                                                     InputDataLength: size_t,
                                                     BufferName: *const c_char)
                                                     -> MemoryBufferRef;
1771

1772 1773
    pub fn LLVMIsMultithreaded() -> Bool;
    pub fn LLVMStartMultithreaded() -> Bool;
1774

S
Steve Klabnik 已提交
1775
    /// Returns a string describing the last error caused by an LLVMRust* call.
1776
    pub fn LLVMRustGetLastError() -> *const c_char;
V
Vadim Chugunov 已提交
1777

1778 1779
    /// Print the pass timings since static dtors aren't picking them up.
    pub fn LLVMRustPrintPassTimings();
V
Vadim Chugunov 已提交
1780

1781
    pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
V
Vadim Chugunov 已提交
1782

1783 1784 1785 1786
    pub fn LLVMStructSetBody(StructTy: TypeRef,
                             ElementTypes: *const TypeRef,
                             ElementCount: c_uint,
                             Packed: Bool);
V
Vadim Chugunov 已提交
1787

1788 1789 1790 1791
    pub fn LLVMConstNamedStruct(S: TypeRef,
                                ConstantVals: *const ValueRef,
                                Count: c_uint)
                                -> ValueRef;
1792

S
Steve Klabnik 已提交
1793
    /// Enables LLVM debug output.
1794
    pub fn LLVMSetDebug(Enabled: c_int);
1795

S
Steve Klabnik 已提交
1796
    /// Prepares inline assembly.
1797 1798 1799 1800 1801 1802 1803
    pub fn LLVMInlineAsm(Ty: TypeRef,
                         AsmString: *const c_char,
                         Constraints: *const c_char,
                         SideEffects: Bool,
                         AlignStack: Bool,
                         Dialect: c_uint)
                         -> ValueRef;
V
Vadim Chugunov 已提交
1804

1805
    pub fn LLVMRustDebugMetadataVersion() -> u32;
1806 1807
    pub fn LLVMVersionMajor() -> u32;
    pub fn LLVMVersionMinor() -> u32;
1808

1809 1810 1811
    pub fn LLVMRustAddModuleFlag(M: ModuleRef,
                                 name: *const c_char,
                                 value: u32);
1812

1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826
    pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;

    pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);

    pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);

    pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
                                          Lang: c_uint,
                                          File: *const c_char,
                                          Dir: *const c_char,
                                          Producer: *const c_char,
                                          isOptimized: bool,
                                          Flags: *const c_char,
                                          RuntimeVer: c_uint,
1827 1828
                                          SplitName: *const c_char)
                                          -> DIDescriptor;
1829 1830 1831 1832 1833 1834 1835

    pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
                                   Filename: *const c_char,
                                   Directory: *const c_char)
                                   -> DIFile;

    pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1836
                                             File: DIFile,
1837
                                             ParameterTypes: DIArray)
1838 1839
                                             -> DICompositeType;

1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852
    pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
                                       Scope: DIDescriptor,
                                       Name: *const c_char,
                                       LinkageName: *const c_char,
                                       File: DIFile,
                                       LineNo: c_uint,
                                       Ty: DIType,
                                       isLocalToUnit: bool,
                                       isDefinition: bool,
                                       ScopeLine: c_uint,
                                       Flags: c_uint,
                                       isOptimized: bool,
                                       Fn: ValueRef,
1853 1854
                                       TParam: DIArray,
                                       Decl: DIDescriptor)
1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
                                       -> DISubprogram;

    pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
                                        Name: *const c_char,
                                        SizeInBits: c_ulonglong,
                                        AlignInBits: c_ulonglong,
                                        Encoding: c_uint)
                                        -> DIBasicType;

    pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
                                          PointeeTy: DIType,
                                          SizeInBits: c_ulonglong,
                                          AlignInBits: c_ulonglong,
                                          Name: *const c_char)
                                          -> DIDerivedType;

    pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
                                         Scope: DIDescriptor,
                                         Name: *const c_char,
                                         File: DIFile,
                                         LineNumber: c_uint,
                                         SizeInBits: c_ulonglong,
                                         AlignInBits: c_ulonglong,
                                         Flags: c_uint,
                                         DerivedFrom: DIType,
                                         Elements: DIArray,
                                         RunTimeLang: c_uint,
1882
                                         VTableHolder: DIType,
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898
                                         UniqueId: *const c_char)
                                         -> DICompositeType;

    pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
                                         Scope: DIDescriptor,
                                         Name: *const c_char,
                                         File: DIFile,
                                         LineNo: c_uint,
                                         SizeInBits: c_ulonglong,
                                         AlignInBits: c_ulonglong,
                                         OffsetInBits: c_ulonglong,
                                         Flags: c_uint,
                                         Ty: DIType)
                                         -> DIDerivedType;

    pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1899
                                           Scope: DIScope,
1900 1901
                                           File: DIFile,
                                           Line: c_uint,
L
Luqman Aden 已提交
1902
                                           Col: c_uint)
1903 1904 1905
                                           -> DILexicalBlock;

    pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1906
                                             Context: DIScope,
1907
                                             Name: *const c_char,
1908
                                             LinkageName: *const c_char,
1909 1910 1911
                                             File: DIFile,
                                             LineNo: c_uint,
                                             Ty: DIType,
1912 1913
                                             isLocalToUnit: bool,
                                             Val: ValueRef,
1914
                                             Decl: DIDescriptor)
1915 1916
                                             -> DIGlobalVariable;

1917
    pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1918 1919
                                            Tag: c_uint,
                                            Scope: DIDescriptor,
1920
                                            Name: *const c_char,
1921 1922 1923 1924
                                            File: DIFile,
                                            LineNo: c_uint,
                                            Ty: DIType,
                                            AlwaysPreserve: bool,
1925
                                            Flags: c_uint,
1926 1927
                                            AddrOps: *const i64,
                                            AddrOpsCount: c_uint,
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957
                                            ArgNo: c_uint)
                                            -> DIVariable;

    pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
                                        Size: c_ulonglong,
                                        AlignInBits: c_ulonglong,
                                        Ty: DIType,
                                        Subscripts: DIArray)
                                        -> DIType;

    pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
                                         Size: c_ulonglong,
                                         AlignInBits: c_ulonglong,
                                         Ty: DIType,
                                         Subscripts: DIArray)
                                         -> DIType;

    pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
                                            Lo: c_longlong,
                                            Count: c_longlong)
                                            -> DISubrange;

    pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
                                         Ptr: *const DIDescriptor,
                                         Count: c_uint)
                                         -> DIArray;

    pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
                                           Val: ValueRef,
                                           VarInfo: DIVariable,
1958 1959
                                           AddrOps: *const i64,
                                           AddrOpsCount: c_uint,
A
Alex Crichton 已提交
1960
                                           DL: ValueRef,
1961 1962
                                           InsertAtEnd: BasicBlockRef)
                                           -> ValueRef;
1963

1964 1965 1966
    pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
                                            Val: ValueRef,
                                            VarInfo: DIVariable,
1967 1968
                                            AddrOps: *const i64,
                                            AddrOpsCount: c_uint,
A
Alex Crichton 已提交
1969
                                            DL: ValueRef,
1970
                                            InsertBefore: ValueRef)
1971 1972
                                            -> ValueRef;

1973 1974 1975
    pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
                                         Name: *const c_char,
                                         Val: c_ulonglong)
1976
                                         -> DIEnumerator;
1977 1978

    pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1979
                                              Scope: DIScope,
1980
                                              Name: *const c_char,
1981
                                              File: DIFile,
1982 1983 1984
                                              LineNumber: c_uint,
                                              SizeInBits: c_ulonglong,
                                              AlignInBits: c_ulonglong,
1985 1986 1987
                                              Elements: DIArray,
                                              ClassType: DIType)
                                              -> DIType;
1988 1989

    pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1990
                                        Scope: DIScope,
1991
                                        Name: *const c_char,
1992
                                        File: DIFile,
1993 1994 1995 1996
                                        LineNumber: c_uint,
                                        SizeInBits: c_ulonglong,
                                        AlignInBits: c_ulonglong,
                                        Flags: c_uint,
1997
                                        Elements: DIArray,
1998 1999
                                        RunTimeLang: c_uint,
                                        UniqueId: *const c_char)
2000
                                        -> DIType;
2001 2002 2003 2004

    pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);

    pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
2005
                                                    Scope: DIScope,
2006
                                                    Name: *const c_char,
2007 2008
                                                    Ty: DIType,
                                                    File: DIFile,
2009 2010
                                                    LineNo: c_uint,
                                                    ColumnNo: c_uint)
2011
                                                    -> DITemplateTypeParameter;
2012

2013
    pub fn LLVMDIBuilderCreateOpDeref() -> i64;
2014

2015
    pub fn LLVMDIBuilderCreateOpPlus() -> i64;
2016 2017

    pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
2018
                                        Scope: DIScope,
2019
                                        Name: *const c_char,
2020
                                        File: DIFile,
2021
                                        LineNo: c_uint)
2022 2023 2024 2025 2026 2027 2028 2029
                                        -> DINameSpace;

    pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
                                            Line: c_uint,
                                            Column: c_uint,
                                            Scope: DIScope,
                                            InlinedAt: MetadataRef)
                                            -> ValueRef;
2030

2031 2032 2033
    pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
                                           CompositeType: DIType,
                                           TypeArray: DIArray);
2034 2035
    pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
    pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
2036 2037 2038 2039

    pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;

    pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
2040
    pub fn LLVMIsAConstantInt(value_ref: ValueRef) -> ValueRef;
2041

2042
    pub fn LLVMRustPassKind(Pass: PassRef) -> PassKind;
2043 2044 2045
    pub fn LLVMRustFindAndCreatePass(Pass: *const c_char) -> PassRef;
    pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: PassRef);

2046 2047 2048
    pub fn LLVMRustHasFeature(T: TargetMachineRef,
                              s: *const c_char) -> bool;

2049 2050 2051
    pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
                                       CPU: *const c_char,
                                       Features: *const c_char,
2052
                                       Model: CodeModel,
2053 2054 2055
                                       Reloc: RelocMode,
                                       Level: CodeGenOptLevel,
                                       UseSoftFP: bool,
2056
                                       PositionIndependentExecutable: bool,
2057 2058 2059 2060 2061 2062 2063 2064 2065
                                       FunctionSections: bool,
                                       DataSections: bool) -> TargetMachineRef;
    pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
    pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
                                     PM: PassManagerRef,
                                     M: ModuleRef);
    pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
                                         M: ModuleRef,
                                         DisableSimplifyLibCalls: bool);
A
Alex Crichton 已提交
2066 2067 2068 2069 2070
    pub fn LLVMRustConfigurePassManagerBuilder(PMB: PassManagerBuilderRef,
                                               OptLevel: CodeGenOptLevel,
                                               MergeFunctions: bool,
                                               SLPVectorize: bool,
                                               LoopVectorize: bool);
2071 2072 2073 2074 2075
    pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
                                  DisableSimplifyLibCalls: bool);
    pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
    pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
                                   PM: PassManagerRef,
2076
                                   M: ModuleRef,
2077
                                   Output: *const c_char,
2078 2079
                                   FileType: FileType)
                                   -> LLVMRustResult;
2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096
    pub fn LLVMRustPrintModule(PM: PassManagerRef,
                               M: ModuleRef,
                               Output: *const c_char);
    pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
    pub fn LLVMRustPrintPasses();
    pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
    pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
                                       AddLifetimes: bool);
    pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
                                         bc: *const c_char,
                                         len: size_t) -> bool;
    pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
                                      syms: *const *const c_char,
                                      len: size_t);
    pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);

    pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2097
    pub fn LLVMRustArchiveIteratorNew(AR: ArchiveRef) -> ArchiveIteratorRef;
2098
    pub fn LLVMRustArchiveIteratorNext(AIR: ArchiveIteratorRef) -> ArchiveChildRef;
2099 2100 2101 2102
    pub fn LLVMRustArchiveChildName(ACR: ArchiveChildRef,
                                    size: *mut size_t) -> *const c_char;
    pub fn LLVMRustArchiveChildData(ACR: ArchiveChildRef,
                                    size: *mut size_t) -> *const c_char;
2103
    pub fn LLVMRustArchiveChildFree(ACR: ArchiveChildRef);
2104
    pub fn LLVMRustArchiveIteratorFree(AIR: ArchiveIteratorRef);
2105 2106
    pub fn LLVMRustDestroyArchive(AR: ArchiveRef);

2107 2108
    pub fn LLVMRustSetDLLStorageClass(V: ValueRef,
                                      C: DLLStorageClassTypes);
2109 2110 2111

    pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
                                  data: *mut *const c_char) -> c_int;
2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123

    pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);

    pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
                                           Handler: DiagnosticHandler,
                                           DiagnosticContext: *mut c_void);

    pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
                                            pass_name_out: *mut *const c_char,
                                            function_out: *mut ValueRef,
                                            debugloc_out: *mut DebugLocRef,
                                            message_out: *mut TwineRef);
2124 2125 2126 2127
    pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
                                            cookie_out: *mut c_uint,
                                            message_out: *mut TwineRef,
                                            instruction_out: *mut ValueRef);
2128 2129 2130 2131 2132 2133

    pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
    pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
    pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;

    pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2134 2135 2136 2137 2138 2139

    pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
                                             H: InlineAsmDiagHandler,
                                             CX: *mut c_void);

    pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2140 2141 2142 2143

    pub fn LLVMRustWriteArchive(Dst: *const c_char,
                                NumMembers: size_t,
                                Members: *const RustArchiveMemberRef,
A
Alex Crichton 已提交
2144
                                WriteSymbtab: bool,
2145 2146
                                Kind: ArchiveKind) ->
                                LLVMRustResult;
2147 2148 2149 2150
    pub fn LLVMRustArchiveMemberNew(Filename: *const c_char,
                                    Name: *const c_char,
                                    Child: ArchiveChildRef) -> RustArchiveMemberRef;
    pub fn LLVMRustArchiveMemberFree(Member: RustArchiveMemberRef);
2151 2152 2153 2154

    pub fn LLVMRustSetDataLayoutFromTargetMachine(M: ModuleRef,
                                                  TM: TargetMachineRef);
    pub fn LLVMRustGetModuleDataLayout(M: ModuleRef) -> TargetDataRef;
2155 2156 2157 2158 2159 2160

    pub fn LLVMRustBuildOperandBundleDef(Name: *const c_char,
                                         Inputs: *const ValueRef,
                                         NumInputs: c_uint)
                                         -> OperandBundleDefRef;
    pub fn LLVMRustFreeOperandBundleDef(Bundle: OperandBundleDefRef);
2161 2162

    pub fn LLVMRustPositionBuilderAtStart(B: BuilderRef, BB: BasicBlockRef);
2163 2164 2165

    pub fn LLVMRustSetComdat(M: ModuleRef, V: ValueRef, Name: *const c_char);
    pub fn LLVMRustUnsetComdat(V: ValueRef);
2166
    pub fn LLVMRustSetModulePIELevel(M: ModuleRef);
2167
}
2168

A
Alex Crichton 已提交
2169 2170 2171 2172 2173 2174
// LLVM requires symbols from this library, but apparently they're not printed
// during llvm-config?
#[cfg(windows)]
#[link(name = "ole32")]
extern {}

2175
pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2176
    unsafe {
2177
        LLVMSetInstructionCallConv(instr, cc as c_uint);
2178
    }
2179
}
2180
pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2181
    unsafe {
2182
        LLVMSetFunctionCallConv(fn_, cc as c_uint);
2183
    }
2184
}
2185
pub fn SetLinkage(global: ValueRef, link: Linkage) {
2186
    unsafe {
2187
        LLVMSetLinkage(global, link as c_uint);
2188
    }
2189 2190
}

2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208
// Externally visible symbols that might appear in multiple translation units need to appear in
// their own comdat section so that the duplicates can be discarded at link time. This can for
// example happen for generics when using multiple codegen units. This function simply uses the
// value's name as the comdat value to make sure that it is in a 1-to-1 relationship to the
// function.
// For more details on COMDAT sections see e.g. http://www.airs.com/blog/archives/52
pub fn SetUniqueComdat(llmod: ModuleRef, val: ValueRef) {
    unsafe {
        LLVMRustSetComdat(llmod, val, LLVMGetValueName(val));
    }
}

pub fn UnsetComdat(val: ValueRef) {
    unsafe {
        LLVMRustUnsetComdat(val);
    }
}

2209 2210 2211 2212 2213 2214
pub fn SetDLLStorageClass(global: ValueRef, class: DLLStorageClassTypes) {
    unsafe {
        LLVMRustSetDLLStorageClass(global, class);
    }
}

2215
pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2216
    unsafe {
2217
        LLVMSetUnnamedAddr(global, unnamed as Bool);
2218 2219 2220
    }
}

D
Daniel Micay 已提交
2221 2222
pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
    unsafe {
2223
        LLVMSetThreadLocal(global, is_thread_local as Bool);
D
Daniel Micay 已提交
2224 2225 2226
    }
}

2227
pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
C
Corey Richardson 已提交
2228
    unsafe {
2229
        LLVMConstICmp(pred as c_ushort, v1, v2)
C
Corey Richardson 已提交
2230 2231
    }
}
2232
pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
C
Corey Richardson 已提交
2233
    unsafe {
2234
        LLVMConstFCmp(pred as c_ushort, v1, v2)
C
Corey Richardson 已提交
2235 2236
    }
}
2237

2238
pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2239
    unsafe {
2240 2241
        LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint,
                                 attr.bits() as uint64_t)
2242
    }
2243
}
2244

2245 2246 2247 2248 2249 2250 2251
pub fn RemoveFunctionAttributes(fn_: ValueRef, attr: Attribute) {
    unsafe {
        LLVMRemoveFunctionAttributes(fn_, FunctionIndex as c_uint,
                                           attr.bits() as uint64_t)
    }
}

2252 2253
/* Memory-managed interface to target data. */

E
Eduard Burtescu 已提交
2254 2255
pub struct TargetData {
    pub lltd: TargetDataRef
2256 2257
}

E
Eduard Burtescu 已提交
2258
impl Drop for TargetData {
D
Daniel Micay 已提交
2259
    fn drop(&mut self) {
2260
        unsafe {
2261
            LLVMDisposeTargetData(self.lltd);
2262 2263
        }
    }
2264 2265
}

2266
pub fn mk_target_data(string_rep: &str) -> TargetData {
2267
    let string_rep = CString::new(string_rep).unwrap();
2268
    TargetData {
A
Alex Crichton 已提交
2269
        lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2270
    }
2271 2272
}

2273 2274
/* Memory-managed interface to object files. */

2275
pub struct ObjectFile {
2276
    pub llof: ObjectFileRef,
2277 2278
}

2279 2280 2281
impl ObjectFile {
    // This will take ownership of llmb
    pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2282
        unsafe {
2283
            let llof = LLVMCreateObjectFile(llmb);
2284
            if llof as isize == 0 {
2285
                // LLVMCreateObjectFile took ownership of llmb
2286 2287 2288 2289 2290 2291
                return None
            }

            Some(ObjectFile {
                llof: llof,
            })
2292 2293
        }
    }
2294 2295
}

2296 2297 2298
impl Drop for ObjectFile {
    fn drop(&mut self) {
        unsafe {
2299
            LLVMDisposeObjectFile(self.llof);
2300
        }
2301
    }
2302 2303 2304 2305
}

/* Memory-managed interface to section iterators. */

E
Eduard Burtescu 已提交
2306 2307
pub struct SectionIter {
    pub llsi: SectionIteratorRef
2308 2309
}

E
Eduard Burtescu 已提交
2310
impl Drop for SectionIter {
D
Daniel Micay 已提交
2311
    fn drop(&mut self) {
2312
        unsafe {
2313
            LLVMDisposeSectionIterator(self.llsi);
2314 2315
        }
    }
2316 2317
}

2318
pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2319
    unsafe {
2320
        SectionIter {
2321
            llsi: LLVMGetSections(llof)
2322
        }
2323
    }
2324
}
2325

2326 2327 2328 2329 2330 2331 2332 2333
/// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
    unsafe {
        assert!(index < LLVMCountParams(llfn));
        LLVMGetParam(llfn, index)
    }
}

2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345
pub fn get_params(llfn: ValueRef) -> Vec<ValueRef> {
    unsafe {
        let num_params = LLVMCountParams(llfn);
        let mut params = Vec::with_capacity(num_params as usize);
        for idx in 0..num_params {
            params.push(LLVMGetParam(llfn, idx));
        }

        params
    }
}

2346
#[allow(missing_copy_implementations)]
2347 2348 2349 2350 2351 2352 2353 2354 2355
pub enum RustString_opaque {}
pub type RustStringRef = *mut RustString_opaque;
type RustStringRepr = *mut RefCell<Vec<u8>>;

/// Appending to a Rust string -- used by raw_rust_string_ostream.
#[no_mangle]
pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
                                                     ptr: *const c_char,
                                                     size: size_t) {
2356
    let slice = slice::from_raw_parts(ptr as *const u8, size as usize);
2357

2358
    let sr = sr as RustStringRepr;
2359
    (*sr).borrow_mut().extend_from_slice(slice);
2360 2361
}

2362
pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2363 2364
    let mut buf = RefCell::new(Vec::new());
    f(&mut buf as RustStringRepr as RustStringRef);
2365
    String::from_utf8(buf.into_inner()).ok()
2366 2367
}

2368 2369 2370 2371 2372 2373 2374 2375 2376 2377
pub unsafe fn twine_to_string(tr: TwineRef) -> String {
    build_string(|s| LLVMWriteTwineToString(tr, s))
        .expect("got a non-UTF8 Twine from LLVM")
}

pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
    build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
        .expect("got a non-UTF8 DebugLoc from LLVM")
}

2378 2379
pub fn initialize_available_targets() {
    macro_rules! init_target(
2380
        ($cfg:meta, $($method:ident),*) => { {
2381 2382
            #[cfg($cfg)]
            fn init() {
2383 2384 2385
                extern {
                    $(fn $method();)*
                }
2386
                unsafe {
2387
                    $($method();)*
2388 2389 2390 2391 2392 2393 2394
                }
            }
            #[cfg(not($cfg))]
            fn init() { }
            init();
        } }
    );
2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428
    init_target!(llvm_component = "x86",
                 LLVMInitializeX86TargetInfo,
                 LLVMInitializeX86Target,
                 LLVMInitializeX86TargetMC,
                 LLVMInitializeX86AsmPrinter,
                 LLVMInitializeX86AsmParser);
    init_target!(llvm_component = "arm",
                 LLVMInitializeARMTargetInfo,
                 LLVMInitializeARMTarget,
                 LLVMInitializeARMTargetMC,
                 LLVMInitializeARMAsmPrinter,
                 LLVMInitializeARMAsmParser);
    init_target!(llvm_component = "aarch64",
                 LLVMInitializeAArch64TargetInfo,
                 LLVMInitializeAArch64Target,
                 LLVMInitializeAArch64TargetMC,
                 LLVMInitializeAArch64AsmPrinter,
                 LLVMInitializeAArch64AsmParser);
    init_target!(llvm_component = "mips",
                 LLVMInitializeMipsTargetInfo,
                 LLVMInitializeMipsTarget,
                 LLVMInitializeMipsTargetMC,
                 LLVMInitializeMipsAsmPrinter,
                 LLVMInitializeMipsAsmParser);
    init_target!(llvm_component = "powerpc",
                 LLVMInitializePowerPCTargetInfo,
                 LLVMInitializePowerPCTarget,
                 LLVMInitializePowerPCTargetMC,
                 LLVMInitializePowerPCAsmPrinter,
                 LLVMInitializePowerPCAsmParser);
    init_target!(llvm_component = "pnacl",
                 LLVMInitializePNaClTargetInfo,
                 LLVMInitializePNaClTarget,
                 LLVMInitializePNaClTargetMC);
2429 2430
}

A
Alex Crichton 已提交
2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444
pub fn last_error() -> Option<String> {
    unsafe {
        let cstr = LLVMRustGetLastError();
        if cstr.is_null() {
            None
        } else {
            let err = CStr::from_ptr(cstr).to_bytes();
            let err = String::from_utf8_lossy(err).to_string();
            libc::free(cstr as *mut _);
            Some(err)
        }
    }
}

2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472
pub struct OperandBundleDef {
    inner: OperandBundleDefRef,
}

impl OperandBundleDef {
    pub fn new(name: &str, vals: &[ValueRef]) -> OperandBundleDef {
        let name = CString::new(name).unwrap();
        let def = unsafe {
            LLVMRustBuildOperandBundleDef(name.as_ptr(),
                                          vals.as_ptr(),
                                          vals.len() as c_uint)
        };
        OperandBundleDef { inner: def }
    }

    pub fn raw(&self) -> OperandBundleDefRef {
        self.inner
    }
}

impl Drop for OperandBundleDef {
    fn drop(&mut self) {
        unsafe {
            LLVMRustFreeOperandBundleDef(self.inner);
        }
    }
}

2473 2474 2475 2476 2477
// The module containing the native LLVM dependencies, generated by the build system
// Note that this must come after the rustllvm extern declaration so that
// parts of LLVM that rustllvm depends on aren't thrown away by the linker.
// Works to the above fix for #15460 to ensure LLVM dependencies that
// are only used by rustllvm don't get stripped by the linker.
2478
#[cfg(not(cargobuild))]
2479
mod llvmdeps {
2480
    include! { env!("CFG_LLVM_LINKAGE_FILE") }
2481
}