]> git.proxmox.com Git - rustc.git/blob - src/librustc_llvm/lib.rs
Imported Upstream version 1.0.0-alpha.2
[rustc.git] / src / librustc_llvm / lib.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(non_upper_case_globals)]
12 #![allow(non_camel_case_types)]
13 #![allow(non_snake_case)]
14 #![allow(dead_code)]
15
16 #![crate_name = "rustc_llvm"]
17 #![unstable(feature = "rustc_private")]
18 #![staged_api]
19 #![crate_type = "dylib"]
20 #![crate_type = "rlib"]
21 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
22 html_favicon_url = "http://www.rust-lang.org/favicon.ico",
23 html_root_url = "http://doc.rust-lang.org/nightly/")]
24
25 #![feature(box_syntax)]
26 #![feature(collections)]
27 #![feature(core)]
28 #![feature(int_uint)]
29 #![feature(libc)]
30 #![feature(link_args)]
31 #![feature(old_path)]
32 #![feature(staged_api)]
33 #![feature(std_misc)]
34
35 extern crate libc;
36 #[macro_use] #[no_link] extern crate rustc_bitflags;
37
38 pub use self::OtherAttribute::*;
39 pub use self::SpecialAttribute::*;
40 pub use self::AttributeSet::*;
41 pub use self::IntPredicate::*;
42 pub use self::RealPredicate::*;
43 pub use self::TypeKind::*;
44 pub use self::AtomicBinOp::*;
45 pub use self::AtomicOrdering::*;
46 pub use self::FileType::*;
47 pub use self::MetadataType::*;
48 pub use self::AsmDialect::*;
49 pub use self::CodeGenOptLevel::*;
50 pub use self::RelocMode::*;
51 pub use self::CodeGenModel::*;
52 pub use self::DiagnosticKind::*;
53 pub use self::CallConv::*;
54 pub use self::Visibility::*;
55 pub use self::DiagnosticSeverity::*;
56 pub use self::Linkage::*;
57
58 use std::ffi::CString;
59 use std::cell::RefCell;
60 use std::{raw, mem};
61 use libc::{c_uint, c_ushort, uint64_t, c_int, size_t, c_char};
62 use libc::{c_longlong, c_ulonglong, c_void};
63 use debuginfo::{DIBuilderRef, DIDescriptor,
64 DIFile, DILexicalBlock, DISubprogram, DIType,
65 DIBasicType, DIDerivedType, DICompositeType, DIScope,
66 DIVariable, DIGlobalVariable, DIArray, DISubrange,
67 DITemplateTypeParameter, DIEnumerator, DINameSpace};
68
69 pub mod archive_ro;
70 pub mod diagnostic;
71
72 pub type Opcode = u32;
73 pub type Bool = c_uint;
74
75 pub const True: Bool = 1 as Bool;
76 pub const False: Bool = 0 as Bool;
77
78 // Consts for the LLVM CallConv type, pre-cast to uint.
79
80 #[derive(Copy, PartialEq)]
81 pub enum CallConv {
82 CCallConv = 0,
83 FastCallConv = 8,
84 ColdCallConv = 9,
85 X86StdcallCallConv = 64,
86 X86FastcallCallConv = 65,
87 X86_64_Win64 = 79,
88 }
89
90 #[derive(Copy)]
91 pub enum Visibility {
92 LLVMDefaultVisibility = 0,
93 HiddenVisibility = 1,
94 ProtectedVisibility = 2,
95 }
96
97 // This enum omits the obsolete (and no-op) linkage types DLLImportLinkage,
98 // DLLExportLinkage, GhostLinkage and LinkOnceODRAutoHideLinkage.
99 // LinkerPrivateLinkage and LinkerPrivateWeakLinkage are not included either;
100 // they've been removed in upstream LLVM commit r203866.
101 #[derive(Copy)]
102 pub enum Linkage {
103 ExternalLinkage = 0,
104 AvailableExternallyLinkage = 1,
105 LinkOnceAnyLinkage = 2,
106 LinkOnceODRLinkage = 3,
107 WeakAnyLinkage = 5,
108 WeakODRLinkage = 6,
109 AppendingLinkage = 7,
110 InternalLinkage = 8,
111 PrivateLinkage = 9,
112 ExternalWeakLinkage = 12,
113 CommonLinkage = 14,
114 }
115
116 #[repr(C)]
117 #[derive(Copy, Debug)]
118 pub enum DiagnosticSeverity {
119 Error,
120 Warning,
121 Remark,
122 Note,
123 }
124
125 bitflags! {
126 flags Attribute : u32 {
127 const ZExtAttribute = 1 << 0,
128 const SExtAttribute = 1 << 1,
129 const NoReturnAttribute = 1 << 2,
130 const InRegAttribute = 1 << 3,
131 const StructRetAttribute = 1 << 4,
132 const NoUnwindAttribute = 1 << 5,
133 const NoAliasAttribute = 1 << 6,
134 const ByValAttribute = 1 << 7,
135 const NestAttribute = 1 << 8,
136 const ReadNoneAttribute = 1 << 9,
137 const ReadOnlyAttribute = 1 << 10,
138 const NoInlineAttribute = 1 << 11,
139 const AlwaysInlineAttribute = 1 << 12,
140 const OptimizeForSizeAttribute = 1 << 13,
141 const StackProtectAttribute = 1 << 14,
142 const StackProtectReqAttribute = 1 << 15,
143 const AlignmentAttribute = 31 << 16,
144 const NoCaptureAttribute = 1 << 21,
145 const NoRedZoneAttribute = 1 << 22,
146 const NoImplicitFloatAttribute = 1 << 23,
147 const NakedAttribute = 1 << 24,
148 const InlineHintAttribute = 1 << 25,
149 const StackAttribute = 7 << 26,
150 const ReturnsTwiceAttribute = 1 << 29,
151 const UWTableAttribute = 1 << 30,
152 const NonLazyBindAttribute = 1 << 31,
153 }
154 }
155
156
157 #[repr(u64)]
158 #[derive(Copy)]
159 pub enum OtherAttribute {
160 // The following are not really exposed in
161 // the LLVM c api so instead to add these
162 // we call a wrapper function in RustWrapper
163 // that uses the C++ api.
164 SanitizeAddressAttribute = 1 << 32,
165 MinSizeAttribute = 1 << 33,
166 NoDuplicateAttribute = 1 << 34,
167 StackProtectStrongAttribute = 1 << 35,
168 SanitizeThreadAttribute = 1 << 36,
169 SanitizeMemoryAttribute = 1 << 37,
170 NoBuiltinAttribute = 1 << 38,
171 ReturnedAttribute = 1 << 39,
172 ColdAttribute = 1 << 40,
173 BuiltinAttribute = 1 << 41,
174 OptimizeNoneAttribute = 1 << 42,
175 InAllocaAttribute = 1 << 43,
176 NonNullAttribute = 1 << 44,
177 }
178
179 #[derive(Copy)]
180 pub enum SpecialAttribute {
181 DereferenceableAttribute(u64)
182 }
183
184 #[repr(C)]
185 #[derive(Copy)]
186 pub enum AttributeSet {
187 ReturnIndex = 0,
188 FunctionIndex = !0
189 }
190
191 pub trait AttrHelper {
192 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef);
193 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef);
194 }
195
196 impl AttrHelper for Attribute {
197 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
198 unsafe {
199 LLVMAddFunctionAttribute(llfn, idx, self.bits() as uint64_t);
200 }
201 }
202
203 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
204 unsafe {
205 LLVMAddCallSiteAttribute(callsite, idx, self.bits() as uint64_t);
206 }
207 }
208 }
209
210 impl AttrHelper for OtherAttribute {
211 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
212 unsafe {
213 LLVMAddFunctionAttribute(llfn, idx, *self as uint64_t);
214 }
215 }
216
217 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
218 unsafe {
219 LLVMAddCallSiteAttribute(callsite, idx, *self as uint64_t);
220 }
221 }
222 }
223
224 impl AttrHelper for SpecialAttribute {
225 fn apply_llfn(&self, idx: c_uint, llfn: ValueRef) {
226 match *self {
227 DereferenceableAttribute(bytes) => unsafe {
228 LLVMAddDereferenceableAttr(llfn, idx, bytes as uint64_t);
229 }
230 }
231 }
232
233 fn apply_callsite(&self, idx: c_uint, callsite: ValueRef) {
234 match *self {
235 DereferenceableAttribute(bytes) => unsafe {
236 LLVMAddDereferenceableCallSiteAttr(callsite, idx, bytes as uint64_t);
237 }
238 }
239 }
240 }
241
242 pub struct AttrBuilder {
243 attrs: Vec<(uint, Box<AttrHelper+'static>)>
244 }
245
246 impl AttrBuilder {
247 pub fn new() -> AttrBuilder {
248 AttrBuilder {
249 attrs: Vec::new()
250 }
251 }
252
253 pub fn arg<'a, T: AttrHelper + 'static>(&'a mut self, idx: uint, a: T) -> &'a mut AttrBuilder {
254 self.attrs.push((idx, box a as Box<AttrHelper+'static>));
255 self
256 }
257
258 pub fn ret<'a, T: AttrHelper + 'static>(&'a mut self, a: T) -> &'a mut AttrBuilder {
259 self.attrs.push((ReturnIndex as uint, box a as Box<AttrHelper+'static>));
260 self
261 }
262
263 pub fn apply_llfn(&self, llfn: ValueRef) {
264 for &(idx, ref attr) in &self.attrs {
265 attr.apply_llfn(idx as c_uint, llfn);
266 }
267 }
268
269 pub fn apply_callsite(&self, callsite: ValueRef) {
270 for &(idx, ref attr) in &self.attrs {
271 attr.apply_callsite(idx as c_uint, callsite);
272 }
273 }
274 }
275
276 // enum for the LLVM IntPredicate type
277 #[derive(Copy)]
278 pub enum IntPredicate {
279 IntEQ = 32,
280 IntNE = 33,
281 IntUGT = 34,
282 IntUGE = 35,
283 IntULT = 36,
284 IntULE = 37,
285 IntSGT = 38,
286 IntSGE = 39,
287 IntSLT = 40,
288 IntSLE = 41,
289 }
290
291 // enum for the LLVM RealPredicate type
292 #[derive(Copy)]
293 pub enum RealPredicate {
294 RealPredicateFalse = 0,
295 RealOEQ = 1,
296 RealOGT = 2,
297 RealOGE = 3,
298 RealOLT = 4,
299 RealOLE = 5,
300 RealONE = 6,
301 RealORD = 7,
302 RealUNO = 8,
303 RealUEQ = 9,
304 RealUGT = 10,
305 RealUGE = 11,
306 RealULT = 12,
307 RealULE = 13,
308 RealUNE = 14,
309 RealPredicateTrue = 15,
310 }
311
312 // The LLVM TypeKind type - must stay in sync with the def of
313 // LLVMTypeKind in llvm/include/llvm-c/Core.h
314 #[derive(Copy, PartialEq, Debug)]
315 #[repr(C)]
316 pub enum TypeKind {
317 Void = 0,
318 Half = 1,
319 Float = 2,
320 Double = 3,
321 X86_FP80 = 4,
322 FP128 = 5,
323 PPC_FP128 = 6,
324 Label = 7,
325 Integer = 8,
326 Function = 9,
327 Struct = 10,
328 Array = 11,
329 Pointer = 12,
330 Vector = 13,
331 Metadata = 14,
332 X86_MMX = 15,
333 }
334
335 #[repr(C)]
336 #[derive(Copy)]
337 pub enum AtomicBinOp {
338 AtomicXchg = 0,
339 AtomicAdd = 1,
340 AtomicSub = 2,
341 AtomicAnd = 3,
342 AtomicNand = 4,
343 AtomicOr = 5,
344 AtomicXor = 6,
345 AtomicMax = 7,
346 AtomicMin = 8,
347 AtomicUMax = 9,
348 AtomicUMin = 10,
349 }
350
351 #[repr(C)]
352 #[derive(Copy)]
353 pub enum AtomicOrdering {
354 NotAtomic = 0,
355 Unordered = 1,
356 Monotonic = 2,
357 // Consume = 3, // Not specified yet.
358 Acquire = 4,
359 Release = 5,
360 AcquireRelease = 6,
361 SequentiallyConsistent = 7
362 }
363
364 // Consts for the LLVMCodeGenFileType type (in include/llvm/c/TargetMachine.h)
365 #[repr(C)]
366 #[derive(Copy)]
367 pub enum FileType {
368 AssemblyFileType = 0,
369 ObjectFileType = 1
370 }
371
372 #[derive(Copy)]
373 pub enum MetadataType {
374 MD_dbg = 0,
375 MD_tbaa = 1,
376 MD_prof = 2,
377 MD_fpmath = 3,
378 MD_range = 4,
379 MD_tbaa_struct = 5,
380 MD_invariant_load = 6,
381 MD_alias_scope = 7,
382 MD_noalias = 8,
383 MD_nontemporal = 9,
384 MD_mem_parallel_loop_access = 10,
385 MD_nonnull = 11,
386 }
387
388 // Inline Asm Dialect
389 #[derive(Copy)]
390 pub enum AsmDialect {
391 AD_ATT = 0,
392 AD_Intel = 1
393 }
394
395 #[derive(Copy, PartialEq, Clone)]
396 #[repr(C)]
397 pub enum CodeGenOptLevel {
398 CodeGenLevelNone = 0,
399 CodeGenLevelLess = 1,
400 CodeGenLevelDefault = 2,
401 CodeGenLevelAggressive = 3,
402 }
403
404 #[derive(Copy, PartialEq)]
405 #[repr(C)]
406 pub enum RelocMode {
407 RelocDefault = 0,
408 RelocStatic = 1,
409 RelocPIC = 2,
410 RelocDynamicNoPic = 3,
411 }
412
413 #[repr(C)]
414 #[derive(Copy)]
415 pub enum CodeGenModel {
416 CodeModelDefault = 0,
417 CodeModelJITDefault = 1,
418 CodeModelSmall = 2,
419 CodeModelKernel = 3,
420 CodeModelMedium = 4,
421 CodeModelLarge = 5,
422 }
423
424 #[repr(C)]
425 #[derive(Copy)]
426 pub enum DiagnosticKind {
427 DK_InlineAsm = 0,
428 DK_StackSize,
429 DK_DebugMetadataVersion,
430 DK_SampleProfile,
431 DK_OptimizationRemark,
432 DK_OptimizationRemarkMissed,
433 DK_OptimizationRemarkAnalysis,
434 DK_OptimizationFailure,
435 }
436
437 // Opaque pointer types
438 #[allow(missing_copy_implementations)]
439 pub enum Module_opaque {}
440 pub type ModuleRef = *mut Module_opaque;
441 #[allow(missing_copy_implementations)]
442 pub enum Context_opaque {}
443 pub type ContextRef = *mut Context_opaque;
444 #[allow(missing_copy_implementations)]
445 pub enum Type_opaque {}
446 pub type TypeRef = *mut Type_opaque;
447 #[allow(missing_copy_implementations)]
448 pub enum Value_opaque {}
449 pub type ValueRef = *mut Value_opaque;
450 #[allow(missing_copy_implementations)]
451 pub enum Metadata_opaque {}
452 pub type MetadataRef = *mut Metadata_opaque;
453 #[allow(missing_copy_implementations)]
454 pub enum BasicBlock_opaque {}
455 pub type BasicBlockRef = *mut BasicBlock_opaque;
456 #[allow(missing_copy_implementations)]
457 pub enum Builder_opaque {}
458 pub type BuilderRef = *mut Builder_opaque;
459 #[allow(missing_copy_implementations)]
460 pub enum ExecutionEngine_opaque {}
461 pub type ExecutionEngineRef = *mut ExecutionEngine_opaque;
462 #[allow(missing_copy_implementations)]
463 pub enum RustJITMemoryManager_opaque {}
464 pub type RustJITMemoryManagerRef = *mut RustJITMemoryManager_opaque;
465 #[allow(missing_copy_implementations)]
466 pub enum MemoryBuffer_opaque {}
467 pub type MemoryBufferRef = *mut MemoryBuffer_opaque;
468 #[allow(missing_copy_implementations)]
469 pub enum PassManager_opaque {}
470 pub type PassManagerRef = *mut PassManager_opaque;
471 #[allow(missing_copy_implementations)]
472 pub enum PassManagerBuilder_opaque {}
473 pub type PassManagerBuilderRef = *mut PassManagerBuilder_opaque;
474 #[allow(missing_copy_implementations)]
475 pub enum Use_opaque {}
476 pub type UseRef = *mut Use_opaque;
477 #[allow(missing_copy_implementations)]
478 pub enum TargetData_opaque {}
479 pub type TargetDataRef = *mut TargetData_opaque;
480 #[allow(missing_copy_implementations)]
481 pub enum ObjectFile_opaque {}
482 pub type ObjectFileRef = *mut ObjectFile_opaque;
483 #[allow(missing_copy_implementations)]
484 pub enum SectionIterator_opaque {}
485 pub type SectionIteratorRef = *mut SectionIterator_opaque;
486 #[allow(missing_copy_implementations)]
487 pub enum Pass_opaque {}
488 pub type PassRef = *mut Pass_opaque;
489 #[allow(missing_copy_implementations)]
490 pub enum TargetMachine_opaque {}
491 pub type TargetMachineRef = *mut TargetMachine_opaque;
492 #[allow(missing_copy_implementations)]
493 pub enum Archive_opaque {}
494 pub type ArchiveRef = *mut Archive_opaque;
495 #[allow(missing_copy_implementations)]
496 pub enum Twine_opaque {}
497 pub type TwineRef = *mut Twine_opaque;
498 #[allow(missing_copy_implementations)]
499 pub enum DiagnosticInfo_opaque {}
500 pub type DiagnosticInfoRef = *mut DiagnosticInfo_opaque;
501 #[allow(missing_copy_implementations)]
502 pub enum DebugLoc_opaque {}
503 pub type DebugLocRef = *mut DebugLoc_opaque;
504 #[allow(missing_copy_implementations)]
505 pub enum SMDiagnostic_opaque {}
506 pub type SMDiagnosticRef = *mut SMDiagnostic_opaque;
507
508 pub type DiagnosticHandler = unsafe extern "C" fn(DiagnosticInfoRef, *mut c_void);
509 pub type InlineAsmDiagHandler = unsafe extern "C" fn(SMDiagnosticRef, *const c_void, c_uint);
510
511 pub mod debuginfo {
512 pub use self::DIDescriptorFlags::*;
513 use super::{MetadataRef};
514
515 #[allow(missing_copy_implementations)]
516 pub enum DIBuilder_opaque {}
517 pub type DIBuilderRef = *mut DIBuilder_opaque;
518
519 pub type DIDescriptor = MetadataRef;
520 pub type DIScope = DIDescriptor;
521 pub type DILocation = DIDescriptor;
522 pub type DIFile = DIScope;
523 pub type DILexicalBlock = DIScope;
524 pub type DISubprogram = DIScope;
525 pub type DINameSpace = DIScope;
526 pub type DIType = DIDescriptor;
527 pub type DIBasicType = DIType;
528 pub type DIDerivedType = DIType;
529 pub type DICompositeType = DIDerivedType;
530 pub type DIVariable = DIDescriptor;
531 pub type DIGlobalVariable = DIDescriptor;
532 pub type DIArray = DIDescriptor;
533 pub type DISubrange = DIDescriptor;
534 pub type DIEnumerator = DIDescriptor;
535 pub type DITemplateTypeParameter = DIDescriptor;
536
537 #[derive(Copy)]
538 pub enum DIDescriptorFlags {
539 FlagPrivate = 1 << 0,
540 FlagProtected = 1 << 1,
541 FlagFwdDecl = 1 << 2,
542 FlagAppleBlock = 1 << 3,
543 FlagBlockByrefStruct = 1 << 4,
544 FlagVirtual = 1 << 5,
545 FlagArtificial = 1 << 6,
546 FlagExplicit = 1 << 7,
547 FlagPrototyped = 1 << 8,
548 FlagObjcClassComplete = 1 << 9,
549 FlagObjectPointer = 1 << 10,
550 FlagVector = 1 << 11,
551 FlagStaticMember = 1 << 12,
552 FlagIndirectVariable = 1 << 13,
553 FlagLValueReference = 1 << 14,
554 FlagRValueReference = 1 << 15
555 }
556 }
557
558
559 // Link to our native llvm bindings (things that we need to use the C++ api
560 // for) and because llvm is written in C++ we need to link against libstdc++
561 //
562 // You'll probably notice that there is an omission of all LLVM libraries
563 // from this location. This is because the set of LLVM libraries that we
564 // link to is mostly defined by LLVM, and the `llvm-config` tool is used to
565 // figure out the exact set of libraries. To do this, the build system
566 // generates an llvmdeps.rs file next to this one which will be
567 // automatically updated whenever LLVM is updated to include an up-to-date
568 // set of the libraries we need to link to LLVM for.
569 #[link(name = "rustllvm", kind = "static")]
570 extern {
571 /* Create and destroy contexts. */
572 pub fn LLVMContextCreate() -> ContextRef;
573 pub fn LLVMContextDispose(C: ContextRef);
574 pub fn LLVMGetMDKindIDInContext(C: ContextRef,
575 Name: *const c_char,
576 SLen: c_uint)
577 -> c_uint;
578
579 /* Create and destroy modules. */
580 pub fn LLVMModuleCreateWithNameInContext(ModuleID: *const c_char,
581 C: ContextRef)
582 -> ModuleRef;
583 pub fn LLVMGetModuleContext(M: ModuleRef) -> ContextRef;
584 pub fn LLVMDisposeModule(M: ModuleRef);
585
586 /// Data layout. See Module::getDataLayout.
587 pub fn LLVMGetDataLayout(M: ModuleRef) -> *const c_char;
588 pub fn LLVMSetDataLayout(M: ModuleRef, Triple: *const c_char);
589
590 /// Target triple. See Module::getTargetTriple.
591 pub fn LLVMGetTarget(M: ModuleRef) -> *const c_char;
592 pub fn LLVMSetTarget(M: ModuleRef, Triple: *const c_char);
593
594 /// See Module::dump.
595 pub fn LLVMDumpModule(M: ModuleRef);
596
597 /// See Module::setModuleInlineAsm.
598 pub fn LLVMSetModuleInlineAsm(M: ModuleRef, Asm: *const c_char);
599
600 /// See llvm::LLVMTypeKind::getTypeID.
601 pub fn LLVMGetTypeKind(Ty: TypeRef) -> TypeKind;
602
603 /// See llvm::LLVMType::getContext.
604 pub fn LLVMGetTypeContext(Ty: TypeRef) -> ContextRef;
605
606 /* Operations on integer types */
607 pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef;
608 pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef;
609 pub fn LLVMInt16TypeInContext(C: ContextRef) -> TypeRef;
610 pub fn LLVMInt32TypeInContext(C: ContextRef) -> TypeRef;
611 pub fn LLVMInt64TypeInContext(C: ContextRef) -> TypeRef;
612 pub fn LLVMIntTypeInContext(C: ContextRef, NumBits: c_uint)
613 -> TypeRef;
614
615 pub fn LLVMGetIntTypeWidth(IntegerTy: TypeRef) -> c_uint;
616
617 /* Operations on real types */
618 pub fn LLVMFloatTypeInContext(C: ContextRef) -> TypeRef;
619 pub fn LLVMDoubleTypeInContext(C: ContextRef) -> TypeRef;
620 pub fn LLVMX86FP80TypeInContext(C: ContextRef) -> TypeRef;
621 pub fn LLVMFP128TypeInContext(C: ContextRef) -> TypeRef;
622 pub fn LLVMPPCFP128TypeInContext(C: ContextRef) -> TypeRef;
623
624 /* Operations on function types */
625 pub fn LLVMFunctionType(ReturnType: TypeRef,
626 ParamTypes: *const TypeRef,
627 ParamCount: c_uint,
628 IsVarArg: Bool)
629 -> TypeRef;
630 pub fn LLVMIsFunctionVarArg(FunctionTy: TypeRef) -> Bool;
631 pub fn LLVMGetReturnType(FunctionTy: TypeRef) -> TypeRef;
632 pub fn LLVMCountParamTypes(FunctionTy: TypeRef) -> c_uint;
633 pub fn LLVMGetParamTypes(FunctionTy: TypeRef, Dest: *mut TypeRef);
634
635 /* Operations on struct types */
636 pub fn LLVMStructTypeInContext(C: ContextRef,
637 ElementTypes: *const TypeRef,
638 ElementCount: c_uint,
639 Packed: Bool)
640 -> TypeRef;
641 pub fn LLVMCountStructElementTypes(StructTy: TypeRef) -> c_uint;
642 pub fn LLVMGetStructElementTypes(StructTy: TypeRef,
643 Dest: *mut TypeRef);
644 pub fn LLVMIsPackedStruct(StructTy: TypeRef) -> Bool;
645
646 /* Operations on array, pointer, and vector types (sequence types) */
647 pub fn LLVMRustArrayType(ElementType: TypeRef, ElementCount: u64) -> TypeRef;
648 pub fn LLVMPointerType(ElementType: TypeRef, AddressSpace: c_uint)
649 -> TypeRef;
650 pub fn LLVMVectorType(ElementType: TypeRef, ElementCount: c_uint)
651 -> TypeRef;
652
653 pub fn LLVMGetElementType(Ty: TypeRef) -> TypeRef;
654 pub fn LLVMGetArrayLength(ArrayTy: TypeRef) -> c_uint;
655 pub fn LLVMGetPointerAddressSpace(PointerTy: TypeRef) -> c_uint;
656 pub fn LLVMGetPointerToGlobal(EE: ExecutionEngineRef, V: ValueRef)
657 -> *const ();
658 pub fn LLVMGetVectorSize(VectorTy: TypeRef) -> c_uint;
659
660 /* Operations on other types */
661 pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
662 pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
663 pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef;
664
665 /* Operations on all values */
666 pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
667 pub fn LLVMGetValueName(Val: ValueRef) -> *const c_char;
668 pub fn LLVMSetValueName(Val: ValueRef, Name: *const c_char);
669 pub fn LLVMDumpValue(Val: ValueRef);
670 pub fn LLVMReplaceAllUsesWith(OldVal: ValueRef, NewVal: ValueRef);
671 pub fn LLVMHasMetadata(Val: ValueRef) -> c_int;
672 pub fn LLVMGetMetadata(Val: ValueRef, KindID: c_uint) -> ValueRef;
673 pub fn LLVMSetMetadata(Val: ValueRef, KindID: c_uint, Node: ValueRef);
674
675 /* Operations on Uses */
676 pub fn LLVMGetFirstUse(Val: ValueRef) -> UseRef;
677 pub fn LLVMGetNextUse(U: UseRef) -> UseRef;
678 pub fn LLVMGetUser(U: UseRef) -> ValueRef;
679 pub fn LLVMGetUsedValue(U: UseRef) -> ValueRef;
680
681 /* Operations on Users */
682 pub fn LLVMGetNumOperands(Val: ValueRef) -> c_int;
683 pub fn LLVMGetOperand(Val: ValueRef, Index: c_uint) -> ValueRef;
684 pub fn LLVMSetOperand(Val: ValueRef, Index: c_uint, Op: ValueRef);
685
686 /* Operations on constants of any type */
687 pub fn LLVMConstNull(Ty: TypeRef) -> ValueRef;
688 /* all zeroes */
689 pub fn LLVMConstAllOnes(Ty: TypeRef) -> ValueRef;
690 pub fn LLVMConstICmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
691 -> ValueRef;
692 pub fn LLVMConstFCmp(Pred: c_ushort, V1: ValueRef, V2: ValueRef)
693 -> ValueRef;
694 /* only for int/vector */
695 pub fn LLVMGetUndef(Ty: TypeRef) -> ValueRef;
696 pub fn LLVMIsConstant(Val: ValueRef) -> Bool;
697 pub fn LLVMIsNull(Val: ValueRef) -> Bool;
698 pub fn LLVMIsUndef(Val: ValueRef) -> Bool;
699 pub fn LLVMConstPointerNull(Ty: TypeRef) -> ValueRef;
700
701 /* Operations on metadata */
702 pub fn LLVMMDStringInContext(C: ContextRef,
703 Str: *const c_char,
704 SLen: c_uint)
705 -> ValueRef;
706 pub fn LLVMMDNodeInContext(C: ContextRef,
707 Vals: *const ValueRef,
708 Count: c_uint)
709 -> ValueRef;
710 pub fn LLVMAddNamedMetadataOperand(M: ModuleRef,
711 Str: *const c_char,
712 Val: ValueRef);
713
714 /* Operations on scalar constants */
715 pub fn LLVMConstInt(IntTy: TypeRef, N: c_ulonglong, SignExtend: Bool)
716 -> ValueRef;
717 pub fn LLVMConstIntOfString(IntTy: TypeRef, Text: *const c_char, Radix: u8)
718 -> ValueRef;
719 pub fn LLVMConstIntOfStringAndSize(IntTy: TypeRef,
720 Text: *const c_char,
721 SLen: c_uint,
722 Radix: u8)
723 -> ValueRef;
724 pub fn LLVMConstReal(RealTy: TypeRef, N: f64) -> ValueRef;
725 pub fn LLVMConstRealOfString(RealTy: TypeRef, Text: *const c_char)
726 -> ValueRef;
727 pub fn LLVMConstRealOfStringAndSize(RealTy: TypeRef,
728 Text: *const c_char,
729 SLen: c_uint)
730 -> ValueRef;
731 pub fn LLVMConstIntGetZExtValue(ConstantVal: ValueRef) -> c_ulonglong;
732 pub fn LLVMConstIntGetSExtValue(ConstantVal: ValueRef) -> c_longlong;
733
734
735 /* Operations on composite constants */
736 pub fn LLVMConstStringInContext(C: ContextRef,
737 Str: *const c_char,
738 Length: c_uint,
739 DontNullTerminate: Bool)
740 -> ValueRef;
741 pub fn LLVMConstStructInContext(C: ContextRef,
742 ConstantVals: *const ValueRef,
743 Count: c_uint,
744 Packed: Bool)
745 -> ValueRef;
746
747 pub fn LLVMConstArray(ElementTy: TypeRef,
748 ConstantVals: *const ValueRef,
749 Length: c_uint)
750 -> ValueRef;
751 pub fn LLVMConstVector(ScalarConstantVals: *const ValueRef, Size: c_uint)
752 -> ValueRef;
753
754 /* Constant expressions */
755 pub fn LLVMAlignOf(Ty: TypeRef) -> ValueRef;
756 pub fn LLVMSizeOf(Ty: TypeRef) -> ValueRef;
757 pub fn LLVMConstNeg(ConstantVal: ValueRef) -> ValueRef;
758 pub fn LLVMConstNSWNeg(ConstantVal: ValueRef) -> ValueRef;
759 pub fn LLVMConstNUWNeg(ConstantVal: ValueRef) -> ValueRef;
760 pub fn LLVMConstFNeg(ConstantVal: ValueRef) -> ValueRef;
761 pub fn LLVMConstNot(ConstantVal: ValueRef) -> ValueRef;
762 pub fn LLVMConstAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
763 -> ValueRef;
764 pub fn LLVMConstNSWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
765 -> ValueRef;
766 pub fn LLVMConstNUWAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
767 -> ValueRef;
768 pub fn LLVMConstFAdd(LHSConstant: ValueRef, RHSConstant: ValueRef)
769 -> ValueRef;
770 pub fn LLVMConstSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
771 -> ValueRef;
772 pub fn LLVMConstNSWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
773 -> ValueRef;
774 pub fn LLVMConstNUWSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
775 -> ValueRef;
776 pub fn LLVMConstFSub(LHSConstant: ValueRef, RHSConstant: ValueRef)
777 -> ValueRef;
778 pub fn LLVMConstMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
779 -> ValueRef;
780 pub fn LLVMConstNSWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
781 -> ValueRef;
782 pub fn LLVMConstNUWMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
783 -> ValueRef;
784 pub fn LLVMConstFMul(LHSConstant: ValueRef, RHSConstant: ValueRef)
785 -> ValueRef;
786 pub fn LLVMConstUDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
787 -> ValueRef;
788 pub fn LLVMConstSDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
789 -> ValueRef;
790 pub fn LLVMConstExactSDiv(LHSConstant: ValueRef,
791 RHSConstant: ValueRef)
792 -> ValueRef;
793 pub fn LLVMConstFDiv(LHSConstant: ValueRef, RHSConstant: ValueRef)
794 -> ValueRef;
795 pub fn LLVMConstURem(LHSConstant: ValueRef, RHSConstant: ValueRef)
796 -> ValueRef;
797 pub fn LLVMConstSRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
798 -> ValueRef;
799 pub fn LLVMConstFRem(LHSConstant: ValueRef, RHSConstant: ValueRef)
800 -> ValueRef;
801 pub fn LLVMConstAnd(LHSConstant: ValueRef, RHSConstant: ValueRef)
802 -> ValueRef;
803 pub fn LLVMConstOr(LHSConstant: ValueRef, RHSConstant: ValueRef)
804 -> ValueRef;
805 pub fn LLVMConstXor(LHSConstant: ValueRef, RHSConstant: ValueRef)
806 -> ValueRef;
807 pub fn LLVMConstShl(LHSConstant: ValueRef, RHSConstant: ValueRef)
808 -> ValueRef;
809 pub fn LLVMConstLShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
810 -> ValueRef;
811 pub fn LLVMConstAShr(LHSConstant: ValueRef, RHSConstant: ValueRef)
812 -> ValueRef;
813 pub fn LLVMConstGEP(ConstantVal: ValueRef,
814 ConstantIndices: *const ValueRef,
815 NumIndices: c_uint)
816 -> ValueRef;
817 pub fn LLVMConstInBoundsGEP(ConstantVal: ValueRef,
818 ConstantIndices: *const ValueRef,
819 NumIndices: c_uint)
820 -> ValueRef;
821 pub fn LLVMConstTrunc(ConstantVal: ValueRef, ToType: TypeRef)
822 -> ValueRef;
823 pub fn LLVMConstSExt(ConstantVal: ValueRef, ToType: TypeRef)
824 -> ValueRef;
825 pub fn LLVMConstZExt(ConstantVal: ValueRef, ToType: TypeRef)
826 -> ValueRef;
827 pub fn LLVMConstFPTrunc(ConstantVal: ValueRef, ToType: TypeRef)
828 -> ValueRef;
829 pub fn LLVMConstFPExt(ConstantVal: ValueRef, ToType: TypeRef)
830 -> ValueRef;
831 pub fn LLVMConstUIToFP(ConstantVal: ValueRef, ToType: TypeRef)
832 -> ValueRef;
833 pub fn LLVMConstSIToFP(ConstantVal: ValueRef, ToType: TypeRef)
834 -> ValueRef;
835 pub fn LLVMConstFPToUI(ConstantVal: ValueRef, ToType: TypeRef)
836 -> ValueRef;
837 pub fn LLVMConstFPToSI(ConstantVal: ValueRef, ToType: TypeRef)
838 -> ValueRef;
839 pub fn LLVMConstPtrToInt(ConstantVal: ValueRef, ToType: TypeRef)
840 -> ValueRef;
841 pub fn LLVMConstIntToPtr(ConstantVal: ValueRef, ToType: TypeRef)
842 -> ValueRef;
843 pub fn LLVMConstBitCast(ConstantVal: ValueRef, ToType: TypeRef)
844 -> ValueRef;
845 pub fn LLVMConstZExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
846 -> ValueRef;
847 pub fn LLVMConstSExtOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
848 -> ValueRef;
849 pub fn LLVMConstTruncOrBitCast(ConstantVal: ValueRef, ToType: TypeRef)
850 -> ValueRef;
851 pub fn LLVMConstPointerCast(ConstantVal: ValueRef, ToType: TypeRef)
852 -> ValueRef;
853 pub fn LLVMConstIntCast(ConstantVal: ValueRef,
854 ToType: TypeRef,
855 isSigned: Bool)
856 -> ValueRef;
857 pub fn LLVMConstFPCast(ConstantVal: ValueRef, ToType: TypeRef)
858 -> ValueRef;
859 pub fn LLVMConstSelect(ConstantCondition: ValueRef,
860 ConstantIfTrue: ValueRef,
861 ConstantIfFalse: ValueRef)
862 -> ValueRef;
863 pub fn LLVMConstExtractElement(VectorConstant: ValueRef,
864 IndexConstant: ValueRef)
865 -> ValueRef;
866 pub fn LLVMConstInsertElement(VectorConstant: ValueRef,
867 ElementValueConstant: ValueRef,
868 IndexConstant: ValueRef)
869 -> ValueRef;
870 pub fn LLVMConstShuffleVector(VectorAConstant: ValueRef,
871 VectorBConstant: ValueRef,
872 MaskConstant: ValueRef)
873 -> ValueRef;
874 pub fn LLVMConstExtractValue(AggConstant: ValueRef,
875 IdxList: *const c_uint,
876 NumIdx: c_uint)
877 -> ValueRef;
878 pub fn LLVMConstInsertValue(AggConstant: ValueRef,
879 ElementValueConstant: ValueRef,
880 IdxList: *const c_uint,
881 NumIdx: c_uint)
882 -> ValueRef;
883 pub fn LLVMConstInlineAsm(Ty: TypeRef,
884 AsmString: *const c_char,
885 Constraints: *const c_char,
886 HasSideEffects: Bool,
887 IsAlignStack: Bool)
888 -> ValueRef;
889 pub fn LLVMBlockAddress(F: ValueRef, BB: BasicBlockRef) -> ValueRef;
890
891
892
893 /* Operations on global variables, functions, and aliases (globals) */
894 pub fn LLVMGetGlobalParent(Global: ValueRef) -> ModuleRef;
895 pub fn LLVMIsDeclaration(Global: ValueRef) -> Bool;
896 pub fn LLVMGetLinkage(Global: ValueRef) -> c_uint;
897 pub fn LLVMSetLinkage(Global: ValueRef, Link: c_uint);
898 pub fn LLVMGetSection(Global: ValueRef) -> *const c_char;
899 pub fn LLVMSetSection(Global: ValueRef, Section: *const c_char);
900 pub fn LLVMGetVisibility(Global: ValueRef) -> c_uint;
901 pub fn LLVMSetVisibility(Global: ValueRef, Viz: c_uint);
902 pub fn LLVMGetAlignment(Global: ValueRef) -> c_uint;
903 pub fn LLVMSetAlignment(Global: ValueRef, Bytes: c_uint);
904
905
906 /* Operations on global variables */
907 pub fn LLVMIsAGlobalVariable(GlobalVar: ValueRef) -> ValueRef;
908 pub fn LLVMAddGlobal(M: ModuleRef, Ty: TypeRef, Name: *const c_char)
909 -> ValueRef;
910 pub fn LLVMAddGlobalInAddressSpace(M: ModuleRef,
911 Ty: TypeRef,
912 Name: *const c_char,
913 AddressSpace: c_uint)
914 -> ValueRef;
915 pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef;
916 pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
917 pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
918 pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
919 pub fn LLVMGetPreviousGlobal(GlobalVar: ValueRef) -> ValueRef;
920 pub fn LLVMDeleteGlobal(GlobalVar: ValueRef);
921 pub fn LLVMGetInitializer(GlobalVar: ValueRef) -> ValueRef;
922 pub fn LLVMSetInitializer(GlobalVar: ValueRef,
923 ConstantVal: ValueRef);
924 pub fn LLVMIsThreadLocal(GlobalVar: ValueRef) -> Bool;
925 pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
926 pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
927 pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
928
929 /* Operations on aliases */
930 pub fn LLVMAddAlias(M: ModuleRef,
931 Ty: TypeRef,
932 Aliasee: ValueRef,
933 Name: *const c_char)
934 -> ValueRef;
935
936 /* Operations on functions */
937 pub fn LLVMAddFunction(M: ModuleRef,
938 Name: *const c_char,
939 FunctionTy: TypeRef)
940 -> ValueRef;
941 pub fn LLVMGetNamedFunction(M: ModuleRef, Name: *const c_char) -> ValueRef;
942 pub fn LLVMGetFirstFunction(M: ModuleRef) -> ValueRef;
943 pub fn LLVMGetLastFunction(M: ModuleRef) -> ValueRef;
944 pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
945 pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
946 pub fn LLVMDeleteFunction(Fn: ValueRef);
947 pub fn LLVMGetOrInsertFunction(M: ModuleRef,
948 Name: *const c_char,
949 FunctionTy: TypeRef)
950 -> ValueRef;
951 pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
952 pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
953 pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
954 pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
955 pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
956 pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
957 pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
958 pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
959 pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
960 pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_ulonglong;
961
962 /* Operations on parameters */
963 pub fn LLVMCountParams(Fn: ValueRef) -> c_uint;
964 pub fn LLVMGetParams(Fn: ValueRef, Params: *const ValueRef);
965 pub fn LLVMGetParam(Fn: ValueRef, Index: c_uint) -> ValueRef;
966 pub fn LLVMGetParamParent(Inst: ValueRef) -> ValueRef;
967 pub fn LLVMGetFirstParam(Fn: ValueRef) -> ValueRef;
968 pub fn LLVMGetLastParam(Fn: ValueRef) -> ValueRef;
969 pub fn LLVMGetNextParam(Arg: ValueRef) -> ValueRef;
970 pub fn LLVMGetPreviousParam(Arg: ValueRef) -> ValueRef;
971 pub fn LLVMAddAttribute(Arg: ValueRef, PA: c_uint);
972 pub fn LLVMRemoveAttribute(Arg: ValueRef, PA: c_uint);
973 pub fn LLVMGetAttribute(Arg: ValueRef) -> c_uint;
974 pub fn LLVMSetParamAlignment(Arg: ValueRef, align: c_uint);
975
976 /* Operations on basic blocks */
977 pub fn LLVMBasicBlockAsValue(BB: BasicBlockRef) -> ValueRef;
978 pub fn LLVMValueIsBasicBlock(Val: ValueRef) -> Bool;
979 pub fn LLVMValueAsBasicBlock(Val: ValueRef) -> BasicBlockRef;
980 pub fn LLVMGetBasicBlockParent(BB: BasicBlockRef) -> ValueRef;
981 pub fn LLVMCountBasicBlocks(Fn: ValueRef) -> c_uint;
982 pub fn LLVMGetBasicBlocks(Fn: ValueRef, BasicBlocks: *const ValueRef);
983 pub fn LLVMGetFirstBasicBlock(Fn: ValueRef) -> BasicBlockRef;
984 pub fn LLVMGetLastBasicBlock(Fn: ValueRef) -> BasicBlockRef;
985 pub fn LLVMGetNextBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
986 pub fn LLVMGetPreviousBasicBlock(BB: BasicBlockRef) -> BasicBlockRef;
987 pub fn LLVMGetEntryBasicBlock(Fn: ValueRef) -> BasicBlockRef;
988
989 pub fn LLVMAppendBasicBlockInContext(C: ContextRef,
990 Fn: ValueRef,
991 Name: *const c_char)
992 -> BasicBlockRef;
993 pub fn LLVMInsertBasicBlockInContext(C: ContextRef,
994 BB: BasicBlockRef,
995 Name: *const c_char)
996 -> BasicBlockRef;
997 pub fn LLVMDeleteBasicBlock(BB: BasicBlockRef);
998
999 pub fn LLVMMoveBasicBlockAfter(BB: BasicBlockRef,
1000 MoveAfter: BasicBlockRef);
1001
1002 pub fn LLVMMoveBasicBlockBefore(BB: BasicBlockRef,
1003 MoveBefore: BasicBlockRef);
1004
1005 /* Operations on instructions */
1006 pub fn LLVMGetInstructionParent(Inst: ValueRef) -> BasicBlockRef;
1007 pub fn LLVMGetFirstInstruction(BB: BasicBlockRef) -> ValueRef;
1008 pub fn LLVMGetLastInstruction(BB: BasicBlockRef) -> ValueRef;
1009 pub fn LLVMGetNextInstruction(Inst: ValueRef) -> ValueRef;
1010 pub fn LLVMGetPreviousInstruction(Inst: ValueRef) -> ValueRef;
1011 pub fn LLVMInstructionEraseFromParent(Inst: ValueRef);
1012
1013 /* Operations on call sites */
1014 pub fn LLVMSetInstructionCallConv(Instr: ValueRef, CC: c_uint);
1015 pub fn LLVMGetInstructionCallConv(Instr: ValueRef) -> c_uint;
1016 pub fn LLVMAddInstrAttribute(Instr: ValueRef,
1017 index: c_uint,
1018 IA: c_uint);
1019 pub fn LLVMRemoveInstrAttribute(Instr: ValueRef,
1020 index: c_uint,
1021 IA: c_uint);
1022 pub fn LLVMSetInstrParamAlignment(Instr: ValueRef,
1023 index: c_uint,
1024 align: c_uint);
1025 pub fn LLVMAddCallSiteAttribute(Instr: ValueRef,
1026 index: c_uint,
1027 Val: uint64_t);
1028 pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef,
1029 index: c_uint,
1030 bytes: uint64_t);
1031
1032 /* Operations on call instructions (only) */
1033 pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
1034 pub fn LLVMSetTailCall(CallInst: ValueRef, IsTailCall: Bool);
1035
1036 /* Operations on load/store instructions (only) */
1037 pub fn LLVMGetVolatile(MemoryAccessInst: ValueRef) -> Bool;
1038 pub fn LLVMSetVolatile(MemoryAccessInst: ValueRef, volatile: Bool);
1039
1040 /* Operations on phi nodes */
1041 pub fn LLVMAddIncoming(PhiNode: ValueRef,
1042 IncomingValues: *const ValueRef,
1043 IncomingBlocks: *const BasicBlockRef,
1044 Count: c_uint);
1045 pub fn LLVMCountIncoming(PhiNode: ValueRef) -> c_uint;
1046 pub fn LLVMGetIncomingValue(PhiNode: ValueRef, Index: c_uint)
1047 -> ValueRef;
1048 pub fn LLVMGetIncomingBlock(PhiNode: ValueRef, Index: c_uint)
1049 -> BasicBlockRef;
1050
1051 /* Instruction builders */
1052 pub fn LLVMCreateBuilderInContext(C: ContextRef) -> BuilderRef;
1053 pub fn LLVMPositionBuilder(Builder: BuilderRef,
1054 Block: BasicBlockRef,
1055 Instr: ValueRef);
1056 pub fn LLVMPositionBuilderBefore(Builder: BuilderRef,
1057 Instr: ValueRef);
1058 pub fn LLVMPositionBuilderAtEnd(Builder: BuilderRef,
1059 Block: BasicBlockRef);
1060 pub fn LLVMGetInsertBlock(Builder: BuilderRef) -> BasicBlockRef;
1061 pub fn LLVMClearInsertionPosition(Builder: BuilderRef);
1062 pub fn LLVMInsertIntoBuilder(Builder: BuilderRef, Instr: ValueRef);
1063 pub fn LLVMInsertIntoBuilderWithName(Builder: BuilderRef,
1064 Instr: ValueRef,
1065 Name: *const c_char);
1066 pub fn LLVMDisposeBuilder(Builder: BuilderRef);
1067
1068 /* Execution engine */
1069 pub fn LLVMRustCreateJITMemoryManager(morestack: *const ())
1070 -> RustJITMemoryManagerRef;
1071 pub fn LLVMBuildExecutionEngine(Mod: ModuleRef,
1072 MM: RustJITMemoryManagerRef) -> ExecutionEngineRef;
1073 pub fn LLVMDisposeExecutionEngine(EE: ExecutionEngineRef);
1074 pub fn LLVMExecutionEngineFinalizeObject(EE: ExecutionEngineRef);
1075 pub fn LLVMRustLoadDynamicLibrary(path: *const c_char) -> Bool;
1076 pub fn LLVMExecutionEngineAddModule(EE: ExecutionEngineRef, M: ModuleRef);
1077 pub fn LLVMExecutionEngineRemoveModule(EE: ExecutionEngineRef, M: ModuleRef)
1078 -> Bool;
1079
1080 /* Metadata */
1081 pub fn LLVMSetCurrentDebugLocation(Builder: BuilderRef, L: ValueRef);
1082 pub fn LLVMGetCurrentDebugLocation(Builder: BuilderRef) -> ValueRef;
1083 pub fn LLVMSetInstDebugLocation(Builder: BuilderRef, Inst: ValueRef);
1084
1085 /* Terminators */
1086 pub fn LLVMBuildRetVoid(B: BuilderRef) -> ValueRef;
1087 pub fn LLVMBuildRet(B: BuilderRef, V: ValueRef) -> ValueRef;
1088 pub fn LLVMBuildAggregateRet(B: BuilderRef,
1089 RetVals: *const ValueRef,
1090 N: c_uint)
1091 -> ValueRef;
1092 pub fn LLVMBuildBr(B: BuilderRef, Dest: BasicBlockRef) -> ValueRef;
1093 pub fn LLVMBuildCondBr(B: BuilderRef,
1094 If: ValueRef,
1095 Then: BasicBlockRef,
1096 Else: BasicBlockRef)
1097 -> ValueRef;
1098 pub fn LLVMBuildSwitch(B: BuilderRef,
1099 V: ValueRef,
1100 Else: BasicBlockRef,
1101 NumCases: c_uint)
1102 -> ValueRef;
1103 pub fn LLVMBuildIndirectBr(B: BuilderRef,
1104 Addr: ValueRef,
1105 NumDests: c_uint)
1106 -> ValueRef;
1107 pub fn LLVMBuildInvoke(B: BuilderRef,
1108 Fn: ValueRef,
1109 Args: *const ValueRef,
1110 NumArgs: c_uint,
1111 Then: BasicBlockRef,
1112 Catch: BasicBlockRef,
1113 Name: *const c_char)
1114 -> ValueRef;
1115 pub fn LLVMBuildLandingPad(B: BuilderRef,
1116 Ty: TypeRef,
1117 PersFn: ValueRef,
1118 NumClauses: c_uint,
1119 Name: *const c_char)
1120 -> ValueRef;
1121 pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef;
1122 pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef;
1123
1124 /* Add a case to the switch instruction */
1125 pub fn LLVMAddCase(Switch: ValueRef,
1126 OnVal: ValueRef,
1127 Dest: BasicBlockRef);
1128
1129 /* Add a destination to the indirectbr instruction */
1130 pub fn LLVMAddDestination(IndirectBr: ValueRef, Dest: BasicBlockRef);
1131
1132 /* Add a clause to the landing pad instruction */
1133 pub fn LLVMAddClause(LandingPad: ValueRef, ClauseVal: ValueRef);
1134
1135 /* Set the cleanup on a landing pad instruction */
1136 pub fn LLVMSetCleanup(LandingPad: ValueRef, Val: Bool);
1137
1138 /* Arithmetic */
1139 pub fn LLVMBuildAdd(B: BuilderRef,
1140 LHS: ValueRef,
1141 RHS: ValueRef,
1142 Name: *const c_char)
1143 -> ValueRef;
1144 pub fn LLVMBuildNSWAdd(B: BuilderRef,
1145 LHS: ValueRef,
1146 RHS: ValueRef,
1147 Name: *const c_char)
1148 -> ValueRef;
1149 pub fn LLVMBuildNUWAdd(B: BuilderRef,
1150 LHS: ValueRef,
1151 RHS: ValueRef,
1152 Name: *const c_char)
1153 -> ValueRef;
1154 pub fn LLVMBuildFAdd(B: BuilderRef,
1155 LHS: ValueRef,
1156 RHS: ValueRef,
1157 Name: *const c_char)
1158 -> ValueRef;
1159 pub fn LLVMBuildSub(B: BuilderRef,
1160 LHS: ValueRef,
1161 RHS: ValueRef,
1162 Name: *const c_char)
1163 -> ValueRef;
1164 pub fn LLVMBuildNSWSub(B: BuilderRef,
1165 LHS: ValueRef,
1166 RHS: ValueRef,
1167 Name: *const c_char)
1168 -> ValueRef;
1169 pub fn LLVMBuildNUWSub(B: BuilderRef,
1170 LHS: ValueRef,
1171 RHS: ValueRef,
1172 Name: *const c_char)
1173 -> ValueRef;
1174 pub fn LLVMBuildFSub(B: BuilderRef,
1175 LHS: ValueRef,
1176 RHS: ValueRef,
1177 Name: *const c_char)
1178 -> ValueRef;
1179 pub fn LLVMBuildMul(B: BuilderRef,
1180 LHS: ValueRef,
1181 RHS: ValueRef,
1182 Name: *const c_char)
1183 -> ValueRef;
1184 pub fn LLVMBuildNSWMul(B: BuilderRef,
1185 LHS: ValueRef,
1186 RHS: ValueRef,
1187 Name: *const c_char)
1188 -> ValueRef;
1189 pub fn LLVMBuildNUWMul(B: BuilderRef,
1190 LHS: ValueRef,
1191 RHS: ValueRef,
1192 Name: *const c_char)
1193 -> ValueRef;
1194 pub fn LLVMBuildFMul(B: BuilderRef,
1195 LHS: ValueRef,
1196 RHS: ValueRef,
1197 Name: *const c_char)
1198 -> ValueRef;
1199 pub fn LLVMBuildUDiv(B: BuilderRef,
1200 LHS: ValueRef,
1201 RHS: ValueRef,
1202 Name: *const c_char)
1203 -> ValueRef;
1204 pub fn LLVMBuildSDiv(B: BuilderRef,
1205 LHS: ValueRef,
1206 RHS: ValueRef,
1207 Name: *const c_char)
1208 -> ValueRef;
1209 pub fn LLVMBuildExactSDiv(B: BuilderRef,
1210 LHS: ValueRef,
1211 RHS: ValueRef,
1212 Name: *const c_char)
1213 -> ValueRef;
1214 pub fn LLVMBuildFDiv(B: BuilderRef,
1215 LHS: ValueRef,
1216 RHS: ValueRef,
1217 Name: *const c_char)
1218 -> ValueRef;
1219 pub fn LLVMBuildURem(B: BuilderRef,
1220 LHS: ValueRef,
1221 RHS: ValueRef,
1222 Name: *const c_char)
1223 -> ValueRef;
1224 pub fn LLVMBuildSRem(B: BuilderRef,
1225 LHS: ValueRef,
1226 RHS: ValueRef,
1227 Name: *const c_char)
1228 -> ValueRef;
1229 pub fn LLVMBuildFRem(B: BuilderRef,
1230 LHS: ValueRef,
1231 RHS: ValueRef,
1232 Name: *const c_char)
1233 -> ValueRef;
1234 pub fn LLVMBuildShl(B: BuilderRef,
1235 LHS: ValueRef,
1236 RHS: ValueRef,
1237 Name: *const c_char)
1238 -> ValueRef;
1239 pub fn LLVMBuildLShr(B: BuilderRef,
1240 LHS: ValueRef,
1241 RHS: ValueRef,
1242 Name: *const c_char)
1243 -> ValueRef;
1244 pub fn LLVMBuildAShr(B: BuilderRef,
1245 LHS: ValueRef,
1246 RHS: ValueRef,
1247 Name: *const c_char)
1248 -> ValueRef;
1249 pub fn LLVMBuildAnd(B: BuilderRef,
1250 LHS: ValueRef,
1251 RHS: ValueRef,
1252 Name: *const c_char)
1253 -> ValueRef;
1254 pub fn LLVMBuildOr(B: BuilderRef,
1255 LHS: ValueRef,
1256 RHS: ValueRef,
1257 Name: *const c_char)
1258 -> ValueRef;
1259 pub fn LLVMBuildXor(B: BuilderRef,
1260 LHS: ValueRef,
1261 RHS: ValueRef,
1262 Name: *const c_char)
1263 -> ValueRef;
1264 pub fn LLVMBuildBinOp(B: BuilderRef,
1265 Op: Opcode,
1266 LHS: ValueRef,
1267 RHS: ValueRef,
1268 Name: *const c_char)
1269 -> ValueRef;
1270 pub fn LLVMBuildNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1271 -> ValueRef;
1272 pub fn LLVMBuildNSWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1273 -> ValueRef;
1274 pub fn LLVMBuildNUWNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1275 -> ValueRef;
1276 pub fn LLVMBuildFNeg(B: BuilderRef, V: ValueRef, Name: *const c_char)
1277 -> ValueRef;
1278 pub fn LLVMBuildNot(B: BuilderRef, V: ValueRef, Name: *const c_char)
1279 -> ValueRef;
1280
1281 /* Memory */
1282 pub fn LLVMBuildMalloc(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1283 -> ValueRef;
1284 pub fn LLVMBuildArrayMalloc(B: BuilderRef,
1285 Ty: TypeRef,
1286 Val: ValueRef,
1287 Name: *const c_char)
1288 -> ValueRef;
1289 pub fn LLVMBuildAlloca(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1290 -> ValueRef;
1291 pub fn LLVMBuildArrayAlloca(B: BuilderRef,
1292 Ty: TypeRef,
1293 Val: ValueRef,
1294 Name: *const c_char)
1295 -> ValueRef;
1296 pub fn LLVMBuildFree(B: BuilderRef, PointerVal: ValueRef) -> ValueRef;
1297 pub fn LLVMBuildLoad(B: BuilderRef,
1298 PointerVal: ValueRef,
1299 Name: *const c_char)
1300 -> ValueRef;
1301
1302 pub fn LLVMBuildStore(B: BuilderRef, Val: ValueRef, Ptr: ValueRef)
1303 -> ValueRef;
1304
1305 pub fn LLVMBuildGEP(B: BuilderRef,
1306 Pointer: ValueRef,
1307 Indices: *const ValueRef,
1308 NumIndices: c_uint,
1309 Name: *const c_char)
1310 -> ValueRef;
1311 pub fn LLVMBuildInBoundsGEP(B: BuilderRef,
1312 Pointer: ValueRef,
1313 Indices: *const ValueRef,
1314 NumIndices: c_uint,
1315 Name: *const c_char)
1316 -> ValueRef;
1317 pub fn LLVMBuildStructGEP(B: BuilderRef,
1318 Pointer: ValueRef,
1319 Idx: c_uint,
1320 Name: *const c_char)
1321 -> ValueRef;
1322 pub fn LLVMBuildGlobalString(B: BuilderRef,
1323 Str: *const c_char,
1324 Name: *const c_char)
1325 -> ValueRef;
1326 pub fn LLVMBuildGlobalStringPtr(B: BuilderRef,
1327 Str: *const c_char,
1328 Name: *const c_char)
1329 -> ValueRef;
1330
1331 /* Casts */
1332 pub fn LLVMBuildTrunc(B: BuilderRef,
1333 Val: ValueRef,
1334 DestTy: TypeRef,
1335 Name: *const c_char)
1336 -> ValueRef;
1337 pub fn LLVMBuildZExt(B: BuilderRef,
1338 Val: ValueRef,
1339 DestTy: TypeRef,
1340 Name: *const c_char)
1341 -> ValueRef;
1342 pub fn LLVMBuildSExt(B: BuilderRef,
1343 Val: ValueRef,
1344 DestTy: TypeRef,
1345 Name: *const c_char)
1346 -> ValueRef;
1347 pub fn LLVMBuildFPToUI(B: BuilderRef,
1348 Val: ValueRef,
1349 DestTy: TypeRef,
1350 Name: *const c_char)
1351 -> ValueRef;
1352 pub fn LLVMBuildFPToSI(B: BuilderRef,
1353 Val: ValueRef,
1354 DestTy: TypeRef,
1355 Name: *const c_char)
1356 -> ValueRef;
1357 pub fn LLVMBuildUIToFP(B: BuilderRef,
1358 Val: ValueRef,
1359 DestTy: TypeRef,
1360 Name: *const c_char)
1361 -> ValueRef;
1362 pub fn LLVMBuildSIToFP(B: BuilderRef,
1363 Val: ValueRef,
1364 DestTy: TypeRef,
1365 Name: *const c_char)
1366 -> ValueRef;
1367 pub fn LLVMBuildFPTrunc(B: BuilderRef,
1368 Val: ValueRef,
1369 DestTy: TypeRef,
1370 Name: *const c_char)
1371 -> ValueRef;
1372 pub fn LLVMBuildFPExt(B: BuilderRef,
1373 Val: ValueRef,
1374 DestTy: TypeRef,
1375 Name: *const c_char)
1376 -> ValueRef;
1377 pub fn LLVMBuildPtrToInt(B: BuilderRef,
1378 Val: ValueRef,
1379 DestTy: TypeRef,
1380 Name: *const c_char)
1381 -> ValueRef;
1382 pub fn LLVMBuildIntToPtr(B: BuilderRef,
1383 Val: ValueRef,
1384 DestTy: TypeRef,
1385 Name: *const c_char)
1386 -> ValueRef;
1387 pub fn LLVMBuildBitCast(B: BuilderRef,
1388 Val: ValueRef,
1389 DestTy: TypeRef,
1390 Name: *const c_char)
1391 -> ValueRef;
1392 pub fn LLVMBuildZExtOrBitCast(B: BuilderRef,
1393 Val: ValueRef,
1394 DestTy: TypeRef,
1395 Name: *const c_char)
1396 -> ValueRef;
1397 pub fn LLVMBuildSExtOrBitCast(B: BuilderRef,
1398 Val: ValueRef,
1399 DestTy: TypeRef,
1400 Name: *const c_char)
1401 -> ValueRef;
1402 pub fn LLVMBuildTruncOrBitCast(B: BuilderRef,
1403 Val: ValueRef,
1404 DestTy: TypeRef,
1405 Name: *const c_char)
1406 -> ValueRef;
1407 pub fn LLVMBuildCast(B: BuilderRef,
1408 Op: Opcode,
1409 Val: ValueRef,
1410 DestTy: TypeRef,
1411 Name: *const c_char) -> ValueRef;
1412 pub fn LLVMBuildPointerCast(B: BuilderRef,
1413 Val: ValueRef,
1414 DestTy: TypeRef,
1415 Name: *const c_char)
1416 -> ValueRef;
1417 pub fn LLVMBuildIntCast(B: BuilderRef,
1418 Val: ValueRef,
1419 DestTy: TypeRef,
1420 Name: *const c_char)
1421 -> ValueRef;
1422 pub fn LLVMBuildFPCast(B: BuilderRef,
1423 Val: ValueRef,
1424 DestTy: TypeRef,
1425 Name: *const c_char)
1426 -> ValueRef;
1427
1428 /* Comparisons */
1429 pub fn LLVMBuildICmp(B: BuilderRef,
1430 Op: c_uint,
1431 LHS: ValueRef,
1432 RHS: ValueRef,
1433 Name: *const c_char)
1434 -> ValueRef;
1435 pub fn LLVMBuildFCmp(B: BuilderRef,
1436 Op: c_uint,
1437 LHS: ValueRef,
1438 RHS: ValueRef,
1439 Name: *const c_char)
1440 -> ValueRef;
1441
1442 /* Miscellaneous instructions */
1443 pub fn LLVMBuildPhi(B: BuilderRef, Ty: TypeRef, Name: *const c_char)
1444 -> ValueRef;
1445 pub fn LLVMBuildCall(B: BuilderRef,
1446 Fn: ValueRef,
1447 Args: *const ValueRef,
1448 NumArgs: c_uint,
1449 Name: *const c_char)
1450 -> ValueRef;
1451 pub fn LLVMBuildSelect(B: BuilderRef,
1452 If: ValueRef,
1453 Then: ValueRef,
1454 Else: ValueRef,
1455 Name: *const c_char)
1456 -> ValueRef;
1457 pub fn LLVMBuildVAArg(B: BuilderRef,
1458 list: ValueRef,
1459 Ty: TypeRef,
1460 Name: *const c_char)
1461 -> ValueRef;
1462 pub fn LLVMBuildExtractElement(B: BuilderRef,
1463 VecVal: ValueRef,
1464 Index: ValueRef,
1465 Name: *const c_char)
1466 -> ValueRef;
1467 pub fn LLVMBuildInsertElement(B: BuilderRef,
1468 VecVal: ValueRef,
1469 EltVal: ValueRef,
1470 Index: ValueRef,
1471 Name: *const c_char)
1472 -> ValueRef;
1473 pub fn LLVMBuildShuffleVector(B: BuilderRef,
1474 V1: ValueRef,
1475 V2: ValueRef,
1476 Mask: ValueRef,
1477 Name: *const c_char)
1478 -> ValueRef;
1479 pub fn LLVMBuildExtractValue(B: BuilderRef,
1480 AggVal: ValueRef,
1481 Index: c_uint,
1482 Name: *const c_char)
1483 -> ValueRef;
1484 pub fn LLVMBuildInsertValue(B: BuilderRef,
1485 AggVal: ValueRef,
1486 EltVal: ValueRef,
1487 Index: c_uint,
1488 Name: *const c_char)
1489 -> ValueRef;
1490
1491 pub fn LLVMBuildIsNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1492 -> ValueRef;
1493 pub fn LLVMBuildIsNotNull(B: BuilderRef, Val: ValueRef, Name: *const c_char)
1494 -> ValueRef;
1495 pub fn LLVMBuildPtrDiff(B: BuilderRef,
1496 LHS: ValueRef,
1497 RHS: ValueRef,
1498 Name: *const c_char)
1499 -> ValueRef;
1500
1501 /* Atomic Operations */
1502 pub fn LLVMBuildAtomicLoad(B: BuilderRef,
1503 PointerVal: ValueRef,
1504 Name: *const c_char,
1505 Order: AtomicOrdering,
1506 Alignment: c_uint)
1507 -> ValueRef;
1508
1509 pub fn LLVMBuildAtomicStore(B: BuilderRef,
1510 Val: ValueRef,
1511 Ptr: ValueRef,
1512 Order: AtomicOrdering,
1513 Alignment: c_uint)
1514 -> ValueRef;
1515
1516 pub fn LLVMBuildAtomicCmpXchg(B: BuilderRef,
1517 LHS: ValueRef,
1518 CMP: ValueRef,
1519 RHS: ValueRef,
1520 Order: AtomicOrdering,
1521 FailureOrder: AtomicOrdering)
1522 -> ValueRef;
1523 pub fn LLVMBuildAtomicRMW(B: BuilderRef,
1524 Op: AtomicBinOp,
1525 LHS: ValueRef,
1526 RHS: ValueRef,
1527 Order: AtomicOrdering,
1528 SingleThreaded: Bool)
1529 -> ValueRef;
1530
1531 pub fn LLVMBuildAtomicFence(B: BuilderRef, Order: AtomicOrdering);
1532
1533
1534 /* Selected entries from the downcasts. */
1535 pub fn LLVMIsATerminatorInst(Inst: ValueRef) -> ValueRef;
1536 pub fn LLVMIsAStoreInst(Inst: ValueRef) -> ValueRef;
1537
1538 /// Writes a module to the specified path. Returns 0 on success.
1539 pub fn LLVMWriteBitcodeToFile(M: ModuleRef, Path: *const c_char) -> c_int;
1540
1541 /// Creates target data from a target layout string.
1542 pub fn LLVMCreateTargetData(StringRep: *const c_char) -> TargetDataRef;
1543 /// Adds the target data to the given pass manager. The pass manager
1544 /// references the target data only weakly.
1545 pub fn LLVMAddTargetData(TD: TargetDataRef, PM: PassManagerRef);
1546 /// Number of bytes clobbered when doing a Store to *T.
1547 pub fn LLVMStoreSizeOfType(TD: TargetDataRef, Ty: TypeRef)
1548 -> c_ulonglong;
1549
1550 /// Number of bytes clobbered when doing a Store to *T.
1551 pub fn LLVMSizeOfTypeInBits(TD: TargetDataRef, Ty: TypeRef)
1552 -> c_ulonglong;
1553
1554 /// Distance between successive elements in an array of T. Includes ABI padding.
1555 pub fn LLVMABISizeOfType(TD: TargetDataRef, Ty: TypeRef) -> c_ulonglong;
1556
1557 /// Returns the preferred alignment of a type.
1558 pub fn LLVMPreferredAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1559 -> c_uint;
1560 /// Returns the minimum alignment of a type.
1561 pub fn LLVMABIAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1562 -> c_uint;
1563
1564 /// Computes the byte offset of the indexed struct element for a
1565 /// target.
1566 pub fn LLVMOffsetOfElement(TD: TargetDataRef,
1567 StructTy: TypeRef,
1568 Element: c_uint)
1569 -> c_ulonglong;
1570
1571 /// Returns the minimum alignment of a type when part of a call frame.
1572 pub fn LLVMCallFrameAlignmentOfType(TD: TargetDataRef, Ty: TypeRef)
1573 -> c_uint;
1574
1575 /// Disposes target data.
1576 pub fn LLVMDisposeTargetData(TD: TargetDataRef);
1577
1578 /// Creates a pass manager.
1579 pub fn LLVMCreatePassManager() -> PassManagerRef;
1580
1581 /// Creates a function-by-function pass manager
1582 pub fn LLVMCreateFunctionPassManagerForModule(M: ModuleRef)
1583 -> PassManagerRef;
1584
1585 /// Disposes a pass manager.
1586 pub fn LLVMDisposePassManager(PM: PassManagerRef);
1587
1588 /// Runs a pass manager on a module.
1589 pub fn LLVMRunPassManager(PM: PassManagerRef, M: ModuleRef) -> Bool;
1590
1591 /// Runs the function passes on the provided function.
1592 pub fn LLVMRunFunctionPassManager(FPM: PassManagerRef, F: ValueRef)
1593 -> Bool;
1594
1595 /// Initializes all the function passes scheduled in the manager
1596 pub fn LLVMInitializeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1597
1598 /// Finalizes all the function passes scheduled in the manager
1599 pub fn LLVMFinalizeFunctionPassManager(FPM: PassManagerRef) -> Bool;
1600
1601 pub fn LLVMInitializePasses();
1602
1603 /// Adds a verification pass.
1604 pub fn LLVMAddVerifierPass(PM: PassManagerRef);
1605
1606 pub fn LLVMAddGlobalOptimizerPass(PM: PassManagerRef);
1607 pub fn LLVMAddIPSCCPPass(PM: PassManagerRef);
1608 pub fn LLVMAddDeadArgEliminationPass(PM: PassManagerRef);
1609 pub fn LLVMAddInstructionCombiningPass(PM: PassManagerRef);
1610 pub fn LLVMAddCFGSimplificationPass(PM: PassManagerRef);
1611 pub fn LLVMAddFunctionInliningPass(PM: PassManagerRef);
1612 pub fn LLVMAddFunctionAttrsPass(PM: PassManagerRef);
1613 pub fn LLVMAddScalarReplAggregatesPass(PM: PassManagerRef);
1614 pub fn LLVMAddScalarReplAggregatesPassSSA(PM: PassManagerRef);
1615 pub fn LLVMAddJumpThreadingPass(PM: PassManagerRef);
1616 pub fn LLVMAddConstantPropagationPass(PM: PassManagerRef);
1617 pub fn LLVMAddReassociatePass(PM: PassManagerRef);
1618 pub fn LLVMAddLoopRotatePass(PM: PassManagerRef);
1619 pub fn LLVMAddLICMPass(PM: PassManagerRef);
1620 pub fn LLVMAddLoopUnswitchPass(PM: PassManagerRef);
1621 pub fn LLVMAddLoopDeletionPass(PM: PassManagerRef);
1622 pub fn LLVMAddLoopUnrollPass(PM: PassManagerRef);
1623 pub fn LLVMAddGVNPass(PM: PassManagerRef);
1624 pub fn LLVMAddMemCpyOptPass(PM: PassManagerRef);
1625 pub fn LLVMAddSCCPPass(PM: PassManagerRef);
1626 pub fn LLVMAddDeadStoreEliminationPass(PM: PassManagerRef);
1627 pub fn LLVMAddStripDeadPrototypesPass(PM: PassManagerRef);
1628 pub fn LLVMAddConstantMergePass(PM: PassManagerRef);
1629 pub fn LLVMAddArgumentPromotionPass(PM: PassManagerRef);
1630 pub fn LLVMAddTailCallEliminationPass(PM: PassManagerRef);
1631 pub fn LLVMAddIndVarSimplifyPass(PM: PassManagerRef);
1632 pub fn LLVMAddAggressiveDCEPass(PM: PassManagerRef);
1633 pub fn LLVMAddGlobalDCEPass(PM: PassManagerRef);
1634 pub fn LLVMAddCorrelatedValuePropagationPass(PM: PassManagerRef);
1635 pub fn LLVMAddPruneEHPass(PM: PassManagerRef);
1636 pub fn LLVMAddSimplifyLibCallsPass(PM: PassManagerRef);
1637 pub fn LLVMAddLoopIdiomPass(PM: PassManagerRef);
1638 pub fn LLVMAddEarlyCSEPass(PM: PassManagerRef);
1639 pub fn LLVMAddTypeBasedAliasAnalysisPass(PM: PassManagerRef);
1640 pub fn LLVMAddBasicAliasAnalysisPass(PM: PassManagerRef);
1641
1642 pub fn LLVMPassManagerBuilderCreate() -> PassManagerBuilderRef;
1643 pub fn LLVMPassManagerBuilderDispose(PMB: PassManagerBuilderRef);
1644 pub fn LLVMPassManagerBuilderSetOptLevel(PMB: PassManagerBuilderRef,
1645 OptimizationLevel: c_uint);
1646 pub fn LLVMPassManagerBuilderSetSizeLevel(PMB: PassManagerBuilderRef,
1647 Value: Bool);
1648 pub fn LLVMPassManagerBuilderSetDisableUnitAtATime(
1649 PMB: PassManagerBuilderRef,
1650 Value: Bool);
1651 pub fn LLVMPassManagerBuilderSetDisableUnrollLoops(
1652 PMB: PassManagerBuilderRef,
1653 Value: Bool);
1654 pub fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls(
1655 PMB: PassManagerBuilderRef,
1656 Value: Bool);
1657 pub fn LLVMPassManagerBuilderUseInlinerWithThreshold(
1658 PMB: PassManagerBuilderRef,
1659 threshold: c_uint);
1660 pub fn LLVMPassManagerBuilderPopulateModulePassManager(
1661 PMB: PassManagerBuilderRef,
1662 PM: PassManagerRef);
1663
1664 pub fn LLVMPassManagerBuilderPopulateFunctionPassManager(
1665 PMB: PassManagerBuilderRef,
1666 PM: PassManagerRef);
1667 pub fn LLVMPassManagerBuilderPopulateLTOPassManager(
1668 PMB: PassManagerBuilderRef,
1669 PM: PassManagerRef,
1670 Internalize: Bool,
1671 RunInliner: Bool);
1672
1673 /// Destroys a memory buffer.
1674 pub fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef);
1675
1676
1677 /* Stuff that's in rustllvm/ because it's not upstream yet. */
1678
1679 /// Opens an object file.
1680 pub fn LLVMCreateObjectFile(MemBuf: MemoryBufferRef) -> ObjectFileRef;
1681 /// Closes an object file.
1682 pub fn LLVMDisposeObjectFile(ObjFile: ObjectFileRef);
1683
1684 /// Enumerates the sections in an object file.
1685 pub fn LLVMGetSections(ObjFile: ObjectFileRef) -> SectionIteratorRef;
1686 /// Destroys a section iterator.
1687 pub fn LLVMDisposeSectionIterator(SI: SectionIteratorRef);
1688 /// Returns true if the section iterator is at the end of the section
1689 /// list:
1690 pub fn LLVMIsSectionIteratorAtEnd(ObjFile: ObjectFileRef,
1691 SI: SectionIteratorRef)
1692 -> Bool;
1693 /// Moves the section iterator to point to the next section.
1694 pub fn LLVMMoveToNextSection(SI: SectionIteratorRef);
1695 /// Returns the current section size.
1696 pub fn LLVMGetSectionSize(SI: SectionIteratorRef) -> c_ulonglong;
1697 /// Returns the current section contents as a string buffer.
1698 pub fn LLVMGetSectionContents(SI: SectionIteratorRef) -> *const c_char;
1699
1700 /// Reads the given file and returns it as a memory buffer. Use
1701 /// LLVMDisposeMemoryBuffer() to get rid of it.
1702 pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *const c_char)
1703 -> MemoryBufferRef;
1704 /// Borrows the contents of the memory buffer (doesn't copy it)
1705 pub fn LLVMCreateMemoryBufferWithMemoryRange(InputData: *const c_char,
1706 InputDataLength: size_t,
1707 BufferName: *const c_char,
1708 RequiresNull: Bool)
1709 -> MemoryBufferRef;
1710 pub fn LLVMCreateMemoryBufferWithMemoryRangeCopy(InputData: *const c_char,
1711 InputDataLength: size_t,
1712 BufferName: *const c_char)
1713 -> MemoryBufferRef;
1714
1715 pub fn LLVMIsMultithreaded() -> Bool;
1716 pub fn LLVMStartMultithreaded() -> Bool;
1717
1718 /// Returns a string describing the last error caused by an LLVMRust* call.
1719 pub fn LLVMRustGetLastError() -> *const c_char;
1720
1721 /// Print the pass timings since static dtors aren't picking them up.
1722 pub fn LLVMRustPrintPassTimings();
1723
1724 pub fn LLVMStructCreateNamed(C: ContextRef, Name: *const c_char) -> TypeRef;
1725
1726 pub fn LLVMStructSetBody(StructTy: TypeRef,
1727 ElementTypes: *const TypeRef,
1728 ElementCount: c_uint,
1729 Packed: Bool);
1730
1731 pub fn LLVMConstNamedStruct(S: TypeRef,
1732 ConstantVals: *const ValueRef,
1733 Count: c_uint)
1734 -> ValueRef;
1735
1736 /// Enables LLVM debug output.
1737 pub fn LLVMSetDebug(Enabled: c_int);
1738
1739 /// Prepares inline assembly.
1740 pub fn LLVMInlineAsm(Ty: TypeRef,
1741 AsmString: *const c_char,
1742 Constraints: *const c_char,
1743 SideEffects: Bool,
1744 AlignStack: Bool,
1745 Dialect: c_uint)
1746 -> ValueRef;
1747
1748 pub static LLVMRustDebugMetadataVersion: u32;
1749
1750 pub fn LLVMRustAddModuleFlag(M: ModuleRef,
1751 name: *const c_char,
1752 value: u32);
1753
1754 pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
1755
1756 pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef);
1757
1758 pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef);
1759
1760 pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
1761 Lang: c_uint,
1762 File: *const c_char,
1763 Dir: *const c_char,
1764 Producer: *const c_char,
1765 isOptimized: bool,
1766 Flags: *const c_char,
1767 RuntimeVer: c_uint,
1768 SplitName: *const c_char)
1769 -> DIDescriptor;
1770
1771 pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef,
1772 Filename: *const c_char,
1773 Directory: *const c_char)
1774 -> DIFile;
1775
1776 pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
1777 File: DIFile,
1778 ParameterTypes: DIArray)
1779 -> DICompositeType;
1780
1781 pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef,
1782 Scope: DIDescriptor,
1783 Name: *const c_char,
1784 LinkageName: *const c_char,
1785 File: DIFile,
1786 LineNo: c_uint,
1787 Ty: DIType,
1788 isLocalToUnit: bool,
1789 isDefinition: bool,
1790 ScopeLine: c_uint,
1791 Flags: c_uint,
1792 isOptimized: bool,
1793 Fn: ValueRef,
1794 TParam: DIArray,
1795 Decl: DIDescriptor)
1796 -> DISubprogram;
1797
1798 pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef,
1799 Name: *const c_char,
1800 SizeInBits: c_ulonglong,
1801 AlignInBits: c_ulonglong,
1802 Encoding: c_uint)
1803 -> DIBasicType;
1804
1805 pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef,
1806 PointeeTy: DIType,
1807 SizeInBits: c_ulonglong,
1808 AlignInBits: c_ulonglong,
1809 Name: *const c_char)
1810 -> DIDerivedType;
1811
1812 pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef,
1813 Scope: DIDescriptor,
1814 Name: *const c_char,
1815 File: DIFile,
1816 LineNumber: c_uint,
1817 SizeInBits: c_ulonglong,
1818 AlignInBits: c_ulonglong,
1819 Flags: c_uint,
1820 DerivedFrom: DIType,
1821 Elements: DIArray,
1822 RunTimeLang: c_uint,
1823 VTableHolder: DIType,
1824 UniqueId: *const c_char)
1825 -> DICompositeType;
1826
1827 pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef,
1828 Scope: DIDescriptor,
1829 Name: *const c_char,
1830 File: DIFile,
1831 LineNo: c_uint,
1832 SizeInBits: c_ulonglong,
1833 AlignInBits: c_ulonglong,
1834 OffsetInBits: c_ulonglong,
1835 Flags: c_uint,
1836 Ty: DIType)
1837 -> DIDerivedType;
1838
1839 pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
1840 Scope: DIScope,
1841 File: DIFile,
1842 Line: c_uint,
1843 Col: c_uint)
1844 -> DILexicalBlock;
1845
1846 pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
1847 Context: DIScope,
1848 Name: *const c_char,
1849 LinkageName: *const c_char,
1850 File: DIFile,
1851 LineNo: c_uint,
1852 Ty: DIType,
1853 isLocalToUnit: bool,
1854 Val: ValueRef,
1855 Decl: DIDescriptor)
1856 -> DIGlobalVariable;
1857
1858 pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef,
1859 Tag: c_uint,
1860 Scope: DIDescriptor,
1861 Name: *const c_char,
1862 File: DIFile,
1863 LineNo: c_uint,
1864 Ty: DIType,
1865 AlwaysPreserve: bool,
1866 Flags: c_uint,
1867 AddrOps: *const i64,
1868 AddrOpsCount: c_uint,
1869 ArgNo: c_uint)
1870 -> DIVariable;
1871
1872 pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef,
1873 Size: c_ulonglong,
1874 AlignInBits: c_ulonglong,
1875 Ty: DIType,
1876 Subscripts: DIArray)
1877 -> DIType;
1878
1879 pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef,
1880 Size: c_ulonglong,
1881 AlignInBits: c_ulonglong,
1882 Ty: DIType,
1883 Subscripts: DIArray)
1884 -> DIType;
1885
1886 pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
1887 Lo: c_longlong,
1888 Count: c_longlong)
1889 -> DISubrange;
1890
1891 pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
1892 Ptr: *const DIDescriptor,
1893 Count: c_uint)
1894 -> DIArray;
1895
1896 pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
1897 Val: ValueRef,
1898 VarInfo: DIVariable,
1899 AddrOps: *const i64,
1900 AddrOpsCount: c_uint,
1901 InsertAtEnd: BasicBlockRef)
1902 -> ValueRef;
1903
1904 pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
1905 Val: ValueRef,
1906 VarInfo: DIVariable,
1907 AddrOps: *const i64,
1908 AddrOpsCount: c_uint,
1909 InsertBefore: ValueRef)
1910 -> ValueRef;
1911
1912 pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef,
1913 Name: *const c_char,
1914 Val: c_ulonglong)
1915 -> DIEnumerator;
1916
1917 pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
1918 Scope: DIScope,
1919 Name: *const c_char,
1920 File: DIFile,
1921 LineNumber: c_uint,
1922 SizeInBits: c_ulonglong,
1923 AlignInBits: c_ulonglong,
1924 Elements: DIArray,
1925 ClassType: DIType)
1926 -> DIType;
1927
1928 pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef,
1929 Scope: DIScope,
1930 Name: *const c_char,
1931 File: DIFile,
1932 LineNumber: c_uint,
1933 SizeInBits: c_ulonglong,
1934 AlignInBits: c_ulonglong,
1935 Flags: c_uint,
1936 Elements: DIArray,
1937 RunTimeLang: c_uint,
1938 UniqueId: *const c_char)
1939 -> DIType;
1940
1941 pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
1942
1943 pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
1944 Scope: DIScope,
1945 Name: *const c_char,
1946 Ty: DIType,
1947 File: DIFile,
1948 LineNo: c_uint,
1949 ColumnNo: c_uint)
1950 -> DITemplateTypeParameter;
1951
1952 pub fn LLVMDIBuilderCreateOpDeref() -> i64;
1953
1954 pub fn LLVMDIBuilderCreateOpPlus() -> i64;
1955
1956 pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
1957 Scope: DIScope,
1958 Name: *const c_char,
1959 File: DIFile,
1960 LineNo: c_uint)
1961 -> DINameSpace;
1962
1963 pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
1964 Line: c_uint,
1965 Column: c_uint,
1966 Scope: DIScope,
1967 InlinedAt: MetadataRef)
1968 -> ValueRef;
1969
1970 pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
1971 CompositeType: DIType,
1972 TypeArray: DIArray);
1973 pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef);
1974 pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef);
1975
1976 pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
1977
1978 pub fn LLVMIsAAllocaInst(value_ref: ValueRef) -> ValueRef;
1979
1980 pub fn LLVMInitializeX86TargetInfo();
1981 pub fn LLVMInitializeX86Target();
1982 pub fn LLVMInitializeX86TargetMC();
1983 pub fn LLVMInitializeX86AsmPrinter();
1984 pub fn LLVMInitializeX86AsmParser();
1985 pub fn LLVMInitializeARMTargetInfo();
1986 pub fn LLVMInitializeARMTarget();
1987 pub fn LLVMInitializeARMTargetMC();
1988 pub fn LLVMInitializeARMAsmPrinter();
1989 pub fn LLVMInitializeARMAsmParser();
1990 pub fn LLVMInitializeAArch64TargetInfo();
1991 pub fn LLVMInitializeAArch64Target();
1992 pub fn LLVMInitializeAArch64TargetMC();
1993 pub fn LLVMInitializeAArch64AsmPrinter();
1994 pub fn LLVMInitializeAArch64AsmParser();
1995 pub fn LLVMInitializeMipsTargetInfo();
1996 pub fn LLVMInitializeMipsTarget();
1997 pub fn LLVMInitializeMipsTargetMC();
1998 pub fn LLVMInitializeMipsAsmPrinter();
1999 pub fn LLVMInitializeMipsAsmParser();
2000 pub fn LLVMInitializePowerPCTargetInfo();
2001 pub fn LLVMInitializePowerPCTarget();
2002 pub fn LLVMInitializePowerPCTargetMC();
2003 pub fn LLVMInitializePowerPCAsmPrinter();
2004 pub fn LLVMInitializePowerPCAsmParser();
2005
2006 pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
2007 pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
2008 CPU: *const c_char,
2009 Features: *const c_char,
2010 Model: CodeGenModel,
2011 Reloc: RelocMode,
2012 Level: CodeGenOptLevel,
2013 EnableSegstk: bool,
2014 UseSoftFP: bool,
2015 NoFramePointerElim: bool,
2016 PositionIndependentExecutable: bool,
2017 FunctionSections: bool,
2018 DataSections: bool) -> TargetMachineRef;
2019 pub fn LLVMRustDisposeTargetMachine(T: TargetMachineRef);
2020 pub fn LLVMRustAddAnalysisPasses(T: TargetMachineRef,
2021 PM: PassManagerRef,
2022 M: ModuleRef);
2023 pub fn LLVMRustAddBuilderLibraryInfo(PMB: PassManagerBuilderRef,
2024 M: ModuleRef,
2025 DisableSimplifyLibCalls: bool);
2026 pub fn LLVMRustAddLibraryInfo(PM: PassManagerRef, M: ModuleRef,
2027 DisableSimplifyLibCalls: bool);
2028 pub fn LLVMRustRunFunctionPassManager(PM: PassManagerRef, M: ModuleRef);
2029 pub fn LLVMRustWriteOutputFile(T: TargetMachineRef,
2030 PM: PassManagerRef,
2031 M: ModuleRef,
2032 Output: *const c_char,
2033 FileType: FileType) -> bool;
2034 pub fn LLVMRustPrintModule(PM: PassManagerRef,
2035 M: ModuleRef,
2036 Output: *const c_char);
2037 pub fn LLVMRustSetLLVMOptions(Argc: c_int, Argv: *const *const c_char);
2038 pub fn LLVMRustPrintPasses();
2039 pub fn LLVMRustSetNormalizedTarget(M: ModuleRef, triple: *const c_char);
2040 pub fn LLVMRustAddAlwaysInlinePass(P: PassManagerBuilderRef,
2041 AddLifetimes: bool);
2042 pub fn LLVMRustLinkInExternalBitcode(M: ModuleRef,
2043 bc: *const c_char,
2044 len: size_t) -> bool;
2045 pub fn LLVMRustRunRestrictionPass(M: ModuleRef,
2046 syms: *const *const c_char,
2047 len: size_t);
2048 pub fn LLVMRustMarkAllFunctionsNounwind(M: ModuleRef);
2049
2050 pub fn LLVMRustOpenArchive(path: *const c_char) -> ArchiveRef;
2051 pub fn LLVMRustArchiveReadSection(AR: ArchiveRef, name: *const c_char,
2052 out_len: *mut size_t) -> *const c_char;
2053 pub fn LLVMRustDestroyArchive(AR: ArchiveRef);
2054
2055 pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef);
2056 pub fn LLVMVersionMajor() -> c_int;
2057 pub fn LLVMVersionMinor() -> c_int;
2058
2059 pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
2060 data: *mut *const c_char) -> c_int;
2061
2062 pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef);
2063
2064 pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
2065 Handler: DiagnosticHandler,
2066 DiagnosticContext: *mut c_void);
2067
2068 pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
2069 pass_name_out: *mut *const c_char,
2070 function_out: *mut ValueRef,
2071 debugloc_out: *mut DebugLocRef,
2072 message_out: *mut TwineRef);
2073 pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
2074 cookie_out: *mut c_uint,
2075 message_out: *mut TwineRef,
2076 instruction_out: *mut ValueRef);
2077
2078 pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef);
2079 pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
2080 pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
2081
2082 pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef);
2083
2084 pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef,
2085 H: InlineAsmDiagHandler,
2086 CX: *mut c_void);
2087
2088 pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
2089 }
2090
2091 pub fn SetInstructionCallConv(instr: ValueRef, cc: CallConv) {
2092 unsafe {
2093 LLVMSetInstructionCallConv(instr, cc as c_uint);
2094 }
2095 }
2096 pub fn SetFunctionCallConv(fn_: ValueRef, cc: CallConv) {
2097 unsafe {
2098 LLVMSetFunctionCallConv(fn_, cc as c_uint);
2099 }
2100 }
2101 pub fn SetLinkage(global: ValueRef, link: Linkage) {
2102 unsafe {
2103 LLVMSetLinkage(global, link as c_uint);
2104 }
2105 }
2106
2107 pub fn SetUnnamedAddr(global: ValueRef, unnamed: bool) {
2108 unsafe {
2109 LLVMSetUnnamedAddr(global, unnamed as Bool);
2110 }
2111 }
2112
2113 pub fn set_thread_local(global: ValueRef, is_thread_local: bool) {
2114 unsafe {
2115 LLVMSetThreadLocal(global, is_thread_local as Bool);
2116 }
2117 }
2118
2119 pub fn ConstICmp(pred: IntPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2120 unsafe {
2121 LLVMConstICmp(pred as c_ushort, v1, v2)
2122 }
2123 }
2124 pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
2125 unsafe {
2126 LLVMConstFCmp(pred as c_ushort, v1, v2)
2127 }
2128 }
2129
2130 pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
2131 unsafe {
2132 LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, attr.bits() as uint64_t)
2133 }
2134 }
2135
2136 /* Memory-managed interface to target data. */
2137
2138 pub struct TargetData {
2139 pub lltd: TargetDataRef
2140 }
2141
2142 impl Drop for TargetData {
2143 fn drop(&mut self) {
2144 unsafe {
2145 LLVMDisposeTargetData(self.lltd);
2146 }
2147 }
2148 }
2149
2150 pub fn mk_target_data(string_rep: &str) -> TargetData {
2151 let string_rep = CString::new(string_rep).unwrap();
2152 TargetData {
2153 lltd: unsafe { LLVMCreateTargetData(string_rep.as_ptr()) }
2154 }
2155 }
2156
2157 /* Memory-managed interface to object files. */
2158
2159 pub struct ObjectFile {
2160 pub llof: ObjectFileRef,
2161 }
2162
2163 impl ObjectFile {
2164 // This will take ownership of llmb
2165 pub fn new(llmb: MemoryBufferRef) -> Option<ObjectFile> {
2166 unsafe {
2167 let llof = LLVMCreateObjectFile(llmb);
2168 if llof as int == 0 {
2169 // LLVMCreateObjectFile took ownership of llmb
2170 return None
2171 }
2172
2173 Some(ObjectFile {
2174 llof: llof,
2175 })
2176 }
2177 }
2178 }
2179
2180 impl Drop for ObjectFile {
2181 fn drop(&mut self) {
2182 unsafe {
2183 LLVMDisposeObjectFile(self.llof);
2184 }
2185 }
2186 }
2187
2188 /* Memory-managed interface to section iterators. */
2189
2190 pub struct SectionIter {
2191 pub llsi: SectionIteratorRef
2192 }
2193
2194 impl Drop for SectionIter {
2195 fn drop(&mut self) {
2196 unsafe {
2197 LLVMDisposeSectionIterator(self.llsi);
2198 }
2199 }
2200 }
2201
2202 pub fn mk_section_iter(llof: ObjectFileRef) -> SectionIter {
2203 unsafe {
2204 SectionIter {
2205 llsi: LLVMGetSections(llof)
2206 }
2207 }
2208 }
2209
2210 /// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
2211 pub fn get_param(llfn: ValueRef, index: c_uint) -> ValueRef {
2212 unsafe {
2213 assert!(index < LLVMCountParams(llfn));
2214 LLVMGetParam(llfn, index)
2215 }
2216 }
2217
2218 #[allow(missing_copy_implementations)]
2219 pub enum RustString_opaque {}
2220 pub type RustStringRef = *mut RustString_opaque;
2221 type RustStringRepr = *mut RefCell<Vec<u8>>;
2222
2223 /// Appending to a Rust string -- used by raw_rust_string_ostream.
2224 #[no_mangle]
2225 pub unsafe extern "C" fn rust_llvm_string_write_impl(sr: RustStringRef,
2226 ptr: *const c_char,
2227 size: size_t) {
2228 let slice: &[u8] = mem::transmute(raw::Slice {
2229 data: ptr as *const u8,
2230 len: size as uint,
2231 });
2232
2233 let sr: RustStringRepr = mem::transmute(sr);
2234 (*sr).borrow_mut().push_all(slice);
2235 }
2236
2237 pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
2238 let mut buf = RefCell::new(Vec::new());
2239 f(&mut buf as RustStringRepr as RustStringRef);
2240 String::from_utf8(buf.into_inner()).ok()
2241 }
2242
2243 pub unsafe fn twine_to_string(tr: TwineRef) -> String {
2244 build_string(|s| LLVMWriteTwineToString(tr, s))
2245 .expect("got a non-UTF8 Twine from LLVM")
2246 }
2247
2248 pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
2249 build_string(|s| LLVMWriteDebugLocToString(c, tr, s))
2250 .expect("got a non-UTF8 DebugLoc from LLVM")
2251 }
2252
2253 // The module containing the native LLVM dependencies, generated by the build system
2254 // Note that this must come after the rustllvm extern declaration so that
2255 // parts of LLVM that rustllvm depends on aren't thrown away by the linker.
2256 // Works to the above fix for #15460 to ensure LLVM dependencies that
2257 // are only used by rustllvm don't get stripped by the linker.
2258 mod llvmdeps {
2259 include! { env!("CFG_LLVM_LINKAGE_FILE") }
2260 }