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