1
Fork 0

begin auditing the C++ types in RustWrapper

This commit is contained in:
Ariel Ben-Yehuda 2016-08-02 02:35:09 +03:00 committed by Ariel Ben-Yehuda
parent 696691e3c4
commit d091ef802f
20 changed files with 757 additions and 588 deletions

View file

@ -186,7 +186,7 @@ pub fn run_compiler_with_file_loader<'a, L>(args: &[String],
let sopts = config::build_session_options(&matches); let sopts = config::build_session_options(&matches);
if sopts.debugging_opts.debug_llvm { if sopts.debugging_opts.debug_llvm {
unsafe { llvm::LLVMSetDebug(1); } unsafe { llvm::LLVMRustSetDebug(1); }
} }
let descriptions = diagnostics_registry(); let descriptions = diagnostics_registry();

View file

@ -23,15 +23,21 @@ pub enum OptimizationDiagnosticKind {
OptimizationRemark, OptimizationRemark,
OptimizationMissed, OptimizationMissed,
OptimizationAnalysis, OptimizationAnalysis,
OptimizationAnalysisFPCommute,
OptimizationAnalysisAliasing,
OptimizationFailure, OptimizationFailure,
OptimizationRemarkOther,
} }
impl OptimizationDiagnosticKind { impl OptimizationDiagnosticKind {
pub fn describe(self) -> &'static str { pub fn describe(self) -> &'static str {
match self { match self {
OptimizationRemark => "remark", OptimizationRemark |
OptimizationRemarkOther => "remark",
OptimizationMissed => "missed", OptimizationMissed => "missed",
OptimizationAnalysis => "analysis", OptimizationAnalysis => "analysis",
OptimizationAnalysisFPCommute => "floating-point",
OptimizationAnalysisAliasing => "aliasing",
OptimizationFailure => "failure", OptimizationFailure => "failure",
} }
} }
@ -58,11 +64,11 @@ impl OptimizationDiagnostic {
message: ptr::null_mut(), message: ptr::null_mut(),
}; };
super::LLVMUnpackOptimizationDiagnostic(di, super::LLVMRustUnpackOptimizationDiagnostic(di,
&mut opt.pass_name, &mut opt.pass_name,
&mut opt.function, &mut opt.function,
&mut opt.debug_loc, &mut opt.debug_loc,
&mut opt.message); &mut opt.message);
opt opt
} }
@ -84,10 +90,10 @@ impl InlineAsmDiagnostic {
instruction: ptr::null_mut(), instruction: ptr::null_mut(),
}; };
super::LLVMUnpackInlineAsmDiagnostic(di, super::LLVMRustUnpackInlineAsmDiagnostic(di,
&mut opt.cookie, &mut opt.cookie,
&mut opt.message, &mut opt.message,
&mut opt.instruction); &mut opt.instruction);
opt opt
} }
@ -103,24 +109,39 @@ pub enum Diagnostic {
impl Diagnostic { impl Diagnostic {
pub unsafe fn unpack(di: DiagnosticInfoRef) -> Diagnostic { pub unsafe fn unpack(di: DiagnosticInfoRef) -> Diagnostic {
let kind = super::LLVMGetDiagInfoKind(di); use super::DiagnosticKind as Dk;
let kind = super::LLVMRustGetDiagInfoKind(di);
match kind { match kind {
super::DK_InlineAsm => InlineAsm(InlineAsmDiagnostic::unpack(di)), Dk::InlineAsm => InlineAsm(InlineAsmDiagnostic::unpack(di)),
super::DK_OptimizationRemark => { Dk::OptimizationRemark => {
Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di)) Optimization(OptimizationDiagnostic::unpack(OptimizationRemark, di))
} }
Dk::OptimizationRemarkOther => {
super::DK_OptimizationRemarkMissed => { Optimization(OptimizationDiagnostic::unpack(OptimizationRemarkOther, di))
}
Dk::OptimizationRemarkMissed => {
Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di)) Optimization(OptimizationDiagnostic::unpack(OptimizationMissed, di))
} }
super::DK_OptimizationRemarkAnalysis => { Dk::OptimizationRemarkAnalysis => {
Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di)) Optimization(OptimizationDiagnostic::unpack(OptimizationAnalysis, di))
} }
super::DK_OptimizationFailure => {
Dk::OptimizationRemarkAnalysisFPCommute => {
Optimization(OptimizationDiagnostic::unpack(
OptimizationAnalysisFPCommute, di))
}
Dk::OptimizationRemarkAnalysisAliasing => {
Optimization(OptimizationDiagnostic::unpack(
OptimizationAnalysisAliasing, di))
}
Dk::OptimizationFailure => {
Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di)) Optimization(OptimizationDiagnostic::unpack(OptimizationFailure, di))
} }

View file

@ -38,8 +38,6 @@ pub use self::IntPredicate::*;
pub use self::RealPredicate::*; pub use self::RealPredicate::*;
pub use self::TypeKind::*; pub use self::TypeKind::*;
pub use self::AtomicBinOp::*; pub use self::AtomicBinOp::*;
pub use self::AtomicOrdering::*;
pub use self::SynchronizationScope::*;
pub use self::MetadataType::*; pub use self::MetadataType::*;
pub use self::AsmDialect::*; pub use self::AsmDialect::*;
pub use self::CodeGenOptSize::*; pub use self::CodeGenOptSize::*;
@ -48,7 +46,6 @@ pub use self::CallConv::*;
pub use self::Visibility::*; pub use self::Visibility::*;
pub use self::DiagnosticSeverity::*; pub use self::DiagnosticSeverity::*;
pub use self::Linkage::*; pub use self::Linkage::*;
pub use self::DLLStorageClassTypes::*;
use std::str::FromStr; use std::str::FromStr;
use std::ffi::{CString, CStr}; use std::ffi::{CString, CStr};
@ -132,19 +129,20 @@ pub enum Linkage {
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum DiagnosticSeverity { pub enum DiagnosticSeverity {
Error, Error = 0,
Warning, Warning = 1,
Remark, Remark = 2,
Note, Note = 3,
} }
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum DLLStorageClassTypes { pub enum DLLStorageClassTypes {
DefaultStorageClass = 0, Other,
DLLImportStorageClass = 1, Default,
DLLExportStorageClass = 2, DllImport,
DllExport,
} }
bitflags! { bitflags! {
@ -231,10 +229,10 @@ impl Attributes {
pub fn apply_llfn(&self, idx: usize, llfn: ValueRef) { pub fn apply_llfn(&self, idx: usize, llfn: ValueRef) {
unsafe { unsafe {
LLVMAddFunctionAttribute(llfn, idx as c_uint, self.regular.bits()); LLVMRustAddFunctionAttribute(llfn, idx as c_uint, self.regular.bits());
if self.dereferenceable_bytes != 0 { if self.dereferenceable_bytes != 0 {
LLVMAddDereferenceableAttr(llfn, idx as c_uint, LLVMRustAddDereferenceableAttr(llfn, idx as c_uint,
self.dereferenceable_bytes); self.dereferenceable_bytes);
} }
} }
} }
@ -243,8 +241,8 @@ impl Attributes {
unsafe { unsafe {
LLVMRustAddCallSiteAttribute(callsite, idx as c_uint, self.regular.bits()); LLVMRustAddCallSiteAttribute(callsite, idx as c_uint, self.regular.bits());
if self.dereferenceable_bytes != 0 { if self.dereferenceable_bytes != 0 {
LLVMAddDereferenceableCallSiteAttr(callsite, idx as c_uint, LLVMRustAddDereferenceableCallSiteAttr(callsite, idx as c_uint,
self.dereferenceable_bytes); self.dereferenceable_bytes);
} }
} }
} }
@ -348,8 +346,9 @@ pub enum AtomicOrdering {
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum SynchronizationScope { pub enum SynchronizationScope {
SingleThread = 0, Other,
CrossThread = 1 SingleThread,
CrossThread,
} }
#[repr(C)] #[repr(C)]
@ -425,14 +424,18 @@ pub enum CodeModel {
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum DiagnosticKind { pub enum DiagnosticKind {
DK_InlineAsm = 0, Other,
DK_StackSize, InlineAsm,
DK_DebugMetadataVersion, StackSize,
DK_SampleProfile, DebugMetadataVersion,
DK_OptimizationRemark, SampleProfile,
DK_OptimizationRemarkMissed, OptimizationRemark,
DK_OptimizationRemarkAnalysis, OptimizationRemarkMissed,
DK_OptimizationFailure, OptimizationRemarkAnalysis,
OptimizationRemarkAnalysisFPCommute,
OptimizationRemarkAnalysisAliasing,
OptimizationRemarkOther,
OptimizationFailure,
} }
#[repr(C)] #[repr(C)]
@ -705,7 +708,7 @@ extern {
/* Operations on other types */ /* Operations on other types */
pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef; pub fn LLVMVoidTypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef; pub fn LLVMLabelTypeInContext(C: ContextRef) -> TypeRef;
pub fn LLVMMetadataTypeInContext(C: ContextRef) -> TypeRef; pub fn LLVMRustMetadataTypeInContext(C: ContextRef) -> TypeRef;
/* Operations on all values */ /* Operations on all values */
pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef; pub fn LLVMTypeOf(Val: ValueRef) -> TypeRef;
@ -957,8 +960,13 @@ extern {
Name: *const c_char, Name: *const c_char,
AddressSpace: c_uint) AddressSpace: c_uint)
-> ValueRef; -> ValueRef;
pub fn LLVMGetNamedGlobal(M: ModuleRef, Name: *const c_char) -> ValueRef; pub fn LLVMGetNamedGlobal(M: ModuleRef,
pub fn LLVMGetOrInsertGlobal(M: ModuleRef, Name: *const c_char, T: TypeRef) -> ValueRef; Name: *const c_char)
-> ValueRef;
pub fn LLVMRustGetOrInsertGlobal(M: ModuleRef,
Name: *const c_char,
T: TypeRef)
-> ValueRef;
pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef; pub fn LLVMGetFirstGlobal(M: ModuleRef) -> ValueRef;
pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef; pub fn LLVMGetLastGlobal(M: ModuleRef) -> ValueRef;
pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef; pub fn LLVMGetNextGlobal(GlobalVar: ValueRef) -> ValueRef;
@ -971,7 +979,7 @@ extern {
pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool); pub fn LLVMSetThreadLocal(GlobalVar: ValueRef, IsThreadLocal: Bool);
pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool; pub fn LLVMIsGlobalConstant(GlobalVar: ValueRef) -> Bool;
pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool); pub fn LLVMSetGlobalConstant(GlobalVar: ValueRef, IsConstant: Bool);
pub fn LLVMGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef; pub fn LLVMRustGetNamedValue(M: ModuleRef, Name: *const c_char) -> ValueRef;
/* Operations on aliases */ /* Operations on aliases */
pub fn LLVMAddAlias(M: ModuleRef, pub fn LLVMAddAlias(M: ModuleRef,
@ -991,23 +999,27 @@ extern {
pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef; pub fn LLVMGetNextFunction(Fn: ValueRef) -> ValueRef;
pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef; pub fn LLVMGetPreviousFunction(Fn: ValueRef) -> ValueRef;
pub fn LLVMDeleteFunction(Fn: ValueRef); pub fn LLVMDeleteFunction(Fn: ValueRef);
pub fn LLVMGetOrInsertFunction(M: ModuleRef, pub fn LLVMRustGetOrInsertFunction(M: ModuleRef,
Name: *const c_char, Name: *const c_char,
FunctionTy: TypeRef) FunctionTy: TypeRef)
-> ValueRef; -> ValueRef;
pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint; pub fn LLVMGetIntrinsicID(Fn: ValueRef) -> c_uint;
pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint; pub fn LLVMGetFunctionCallConv(Fn: ValueRef) -> c_uint;
pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint); pub fn LLVMSetFunctionCallConv(Fn: ValueRef, CC: c_uint);
pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char; pub fn LLVMGetGC(Fn: ValueRef) -> *const c_char;
pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char); pub fn LLVMSetGC(Fn: ValueRef, Name: *const c_char);
pub fn LLVMAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t); pub fn LLVMRustAddDereferenceableAttr(Fn: ValueRef, index: c_uint, bytes: uint64_t);
pub fn LLVMAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t); pub fn LLVMRustAddFunctionAttribute(Fn: ValueRef, index: c_uint, PA: uint64_t);
pub fn LLVMAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char); pub fn LLVMRustAddFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char);
pub fn LLVMAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint, pub fn LLVMRustAddFunctionAttrStringValue(Fn: ValueRef, index: c_uint,
Name: *const c_char, Name: *const c_char,
Value: *const c_char); Value: *const c_char);
pub fn LLVMRemoveFunctionAttributes(Fn: ValueRef, index: c_uint, attr: uint64_t); pub fn LLVMRustRemoveFunctionAttributes(Fn: ValueRef,
pub fn LLVMRemoveFunctionAttrString(Fn: ValueRef, index: c_uint, Name: *const c_char); index: c_uint,
attr: uint64_t);
pub fn LLVMRustRemoveFunctionAttrString(Fn: ValueRef,
index: c_uint,
Name: *const c_char);
pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_uint; pub fn LLVMGetFunctionAttr(Fn: ValueRef) -> c_uint;
pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_uint); pub fn LLVMRemoveFunctionAttr(Fn: ValueRef, val: c_uint);
@ -1077,9 +1089,9 @@ extern {
pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef, pub fn LLVMRustAddCallSiteAttribute(Instr: ValueRef,
index: c_uint, index: c_uint,
Val: uint64_t); Val: uint64_t);
pub fn LLVMAddDereferenceableCallSiteAttr(Instr: ValueRef, pub fn LLVMRustAddDereferenceableCallSiteAttr(Instr: ValueRef,
index: c_uint, index: c_uint,
bytes: uint64_t); bytes: uint64_t);
/* Operations on call instructions (only) */ /* Operations on call instructions (only) */
pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool; pub fn LLVMIsTailCall(CallInst: ValueRef) -> Bool;
@ -1556,28 +1568,29 @@ extern {
-> ValueRef; -> ValueRef;
/* Atomic Operations */ /* Atomic Operations */
pub fn LLVMBuildAtomicLoad(B: BuilderRef, pub fn LLVMRustBuildAtomicLoad(B: BuilderRef,
PointerVal: ValueRef, PointerVal: ValueRef,
Name: *const c_char, Name: *const c_char,
Order: AtomicOrdering, Order: AtomicOrdering,
Alignment: c_uint) Alignment: c_uint)
-> ValueRef; -> ValueRef;
pub fn LLVMBuildAtomicStore(B: BuilderRef, pub fn LLVMRustBuildAtomicStore(B: BuilderRef,
Val: ValueRef, Val: ValueRef,
Ptr: ValueRef, Ptr: ValueRef,
Order: AtomicOrdering, Order: AtomicOrdering,
Alignment: c_uint) Alignment: c_uint)
-> ValueRef; -> ValueRef;
pub fn LLVMRustBuildAtomicCmpXchg(B: BuilderRef, pub fn LLVMRustBuildAtomicCmpXchg(B: BuilderRef,
LHS: ValueRef, LHS: ValueRef,
CMP: ValueRef, CMP: ValueRef,
RHS: ValueRef, RHS: ValueRef,
Order: AtomicOrdering, Order: AtomicOrdering,
FailureOrder: AtomicOrdering, FailureOrder: AtomicOrdering,
Weak: Bool) Weak: Bool)
-> ValueRef; -> ValueRef;
pub fn LLVMBuildAtomicRMW(B: BuilderRef, pub fn LLVMBuildAtomicRMW(B: BuilderRef,
Op: AtomicBinOp, Op: AtomicBinOp,
LHS: ValueRef, LHS: ValueRef,
@ -1586,9 +1599,9 @@ extern {
SingleThreaded: Bool) SingleThreaded: Bool)
-> ValueRef; -> ValueRef;
pub fn LLVMBuildAtomicFence(B: BuilderRef, pub fn LLVMRustBuildAtomicFence(B: BuilderRef,
Order: AtomicOrdering, Order: AtomicOrdering,
Scope: SynchronizationScope); Scope: SynchronizationScope);
/* Selected entries from the downcasts. */ /* Selected entries from the downcasts. */
@ -1791,248 +1804,248 @@ extern {
-> ValueRef; -> ValueRef;
/// Enables LLVM debug output. /// Enables LLVM debug output.
pub fn LLVMSetDebug(Enabled: c_int); pub fn LLVMRustSetDebug(Enabled: c_int);
/// Prepares inline assembly. /// Prepares inline assembly.
pub fn LLVMInlineAsm(Ty: TypeRef, pub fn LLVMRustInlineAsm(Ty: TypeRef,
AsmString: *const c_char, AsmString: *const c_char,
Constraints: *const c_char, Constraints: *const c_char,
SideEffects: Bool, SideEffects: Bool,
AlignStack: Bool, AlignStack: Bool,
Dialect: c_uint) Dialect: c_uint)
-> ValueRef; -> ValueRef;
pub fn LLVMRustDebugMetadataVersion() -> u32; pub fn LLVMRustDebugMetadataVersion() -> u32;
pub fn LLVMVersionMajor() -> u32; pub fn LLVMRustVersionMajor() -> u32;
pub fn LLVMVersionMinor() -> u32; pub fn LLVMRustVersionMinor() -> u32;
pub fn LLVMRustAddModuleFlag(M: ModuleRef, pub fn LLVMRustAddModuleFlag(M: ModuleRef,
name: *const c_char, name: *const c_char,
value: u32); value: u32);
pub fn LLVMDIBuilderCreate(M: ModuleRef) -> DIBuilderRef; pub fn LLVMRustDIBuilderCreate(M: ModuleRef) -> DIBuilderRef;
pub fn LLVMDIBuilderDispose(Builder: DIBuilderRef); pub fn LLVMRustDIBuilderDispose(Builder: DIBuilderRef);
pub fn LLVMDIBuilderFinalize(Builder: DIBuilderRef); pub fn LLVMRustDIBuilderFinalize(Builder: DIBuilderRef);
pub fn LLVMDIBuilderCreateCompileUnit(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateCompileUnit(Builder: DIBuilderRef,
Lang: c_uint, Lang: c_uint,
File: *const c_char, File: *const c_char,
Dir: *const c_char, Dir: *const c_char,
Producer: *const c_char, Producer: *const c_char,
isOptimized: bool, isOptimized: bool,
Flags: *const c_char, Flags: *const c_char,
RuntimeVer: c_uint, RuntimeVer: c_uint,
SplitName: *const c_char) SplitName: *const c_char)
-> DIDescriptor; -> DIDescriptor;
pub fn LLVMDIBuilderCreateFile(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateFile(Builder: DIBuilderRef,
Filename: *const c_char, Filename: *const c_char,
Directory: *const c_char) Directory: *const c_char)
-> DIFile; -> DIFile;
pub fn LLVMDIBuilderCreateSubroutineType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateSubroutineType(Builder: DIBuilderRef,
File: DIFile, File: DIFile,
ParameterTypes: DIArray) ParameterTypes: DIArray)
-> DICompositeType; -> DICompositeType;
pub fn LLVMDIBuilderCreateFunction(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateFunction(Builder: DIBuilderRef,
Scope: DIDescriptor, Scope: DIDescriptor,
Name: *const c_char, Name: *const c_char,
LinkageName: *const c_char, LinkageName: *const c_char,
File: DIFile, File: DIFile,
LineNo: c_uint, LineNo: c_uint,
Ty: DIType, Ty: DIType,
isLocalToUnit: bool, isLocalToUnit: bool,
isDefinition: bool, isDefinition: bool,
ScopeLine: c_uint, ScopeLine: c_uint,
Flags: c_uint, Flags: c_uint,
isOptimized: bool, isOptimized: bool,
Fn: ValueRef, Fn: ValueRef,
TParam: DIArray, TParam: DIArray,
Decl: DIDescriptor) Decl: DIDescriptor)
-> DISubprogram; -> DISubprogram;
pub fn LLVMDIBuilderCreateBasicType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateBasicType(Builder: DIBuilderRef,
Name: *const c_char, Name: *const c_char,
SizeInBits: c_ulonglong, SizeInBits: u64,
AlignInBits: c_ulonglong, AlignInBits: u64,
Encoding: c_uint) Encoding: c_uint)
-> DIBasicType; -> DIBasicType;
pub fn LLVMDIBuilderCreatePointerType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreatePointerType(Builder: DIBuilderRef,
PointeeTy: DIType, PointeeTy: DIType,
SizeInBits: c_ulonglong, SizeInBits: u64,
AlignInBits: c_ulonglong, AlignInBits: u64,
Name: *const c_char) Name: *const c_char)
-> DIDerivedType; -> DIDerivedType;
pub fn LLVMDIBuilderCreateStructType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateStructType(Builder: DIBuilderRef,
Scope: DIDescriptor, Scope: DIDescriptor,
Name: *const c_char, Name: *const c_char,
File: DIFile, File: DIFile,
LineNumber: c_uint, LineNumber: c_uint,
SizeInBits: c_ulonglong, SizeInBits: u64,
AlignInBits: c_ulonglong, AlignInBits: u64,
Flags: c_uint, Flags: c_uint,
DerivedFrom: DIType, DerivedFrom: DIType,
Elements: DIArray, Elements: DIArray,
RunTimeLang: c_uint, RunTimeLang: c_uint,
VTableHolder: DIType, VTableHolder: DIType,
UniqueId: *const c_char) UniqueId: *const c_char)
-> DICompositeType; -> DICompositeType;
pub fn LLVMDIBuilderCreateMemberType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateMemberType(Builder: DIBuilderRef,
Scope: DIDescriptor, Scope: DIDescriptor,
Name: *const c_char,
File: DIFile,
LineNo: c_uint,
SizeInBits: c_ulonglong,
AlignInBits: c_ulonglong,
OffsetInBits: c_ulonglong,
Flags: c_uint,
Ty: DIType)
-> DIDerivedType;
pub fn LLVMDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
Scope: DIScope,
File: DIFile,
Line: c_uint,
Col: c_uint)
-> DILexicalBlock;
pub fn LLVMDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
Context: DIScope,
Name: *const c_char, Name: *const c_char,
LinkageName: *const c_char,
File: DIFile, File: DIFile,
LineNo: c_uint, LineNo: c_uint,
Ty: DIType, SizeInBits: u64,
isLocalToUnit: bool, AlignInBits: u64,
Val: ValueRef, OffsetInBits: u64,
Decl: DIDescriptor) Flags: c_uint,
-> DIGlobalVariable; Ty: DIType)
-> DIDerivedType;
pub fn LLVMDIBuilderCreateVariable(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateLexicalBlock(Builder: DIBuilderRef,
Tag: c_uint, Scope: DIScope,
Scope: DIDescriptor, File: DIFile,
Name: *const c_char, Line: c_uint,
File: DIFile, Col: c_uint)
LineNo: c_uint, -> DILexicalBlock;
Ty: DIType,
AlwaysPreserve: bool,
Flags: c_uint,
AddrOps: *const i64,
AddrOpsCount: c_uint,
ArgNo: c_uint)
-> DIVariable;
pub fn LLVMDIBuilderCreateArrayType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateStaticVariable(Builder: DIBuilderRef,
Size: c_ulonglong, Context: DIScope,
AlignInBits: c_ulonglong, Name: *const c_char,
Ty: DIType, LinkageName: *const c_char,
Subscripts: DIArray) File: DIFile,
-> DIType; LineNo: c_uint,
Ty: DIType,
isLocalToUnit: bool,
Val: ValueRef,
Decl: DIDescriptor)
-> DIGlobalVariable;
pub fn LLVMDIBuilderCreateVectorType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateVariable(Builder: DIBuilderRef,
Size: c_ulonglong, Tag: c_uint,
AlignInBits: c_ulonglong, Scope: DIDescriptor,
Ty: DIType, Name: *const c_char,
Subscripts: DIArray) File: DIFile,
-> DIType; LineNo: c_uint,
Ty: DIType,
pub fn LLVMDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef, AlwaysPreserve: bool,
Lo: c_longlong, Flags: c_uint,
Count: c_longlong)
-> DISubrange;
pub fn LLVMDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
Ptr: *const DIDescriptor,
Count: c_uint)
-> DIArray;
pub fn LLVMDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
Val: ValueRef,
VarInfo: DIVariable,
AddrOps: *const i64, AddrOps: *const i64,
AddrOpsCount: c_uint, AddrOpsCount: c_uint,
DL: ValueRef, ArgNo: c_uint)
InsertAtEnd: BasicBlockRef) -> DIVariable;
-> ValueRef;
pub fn LLVMDIBuilderInsertDeclareBefore(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateArrayType(Builder: DIBuilderRef,
Val: ValueRef, Size: u64,
VarInfo: DIVariable, AlignInBits: u64,
AddrOps: *const i64, Ty: DIType,
AddrOpsCount: c_uint, Subscripts: DIArray)
DL: ValueRef, -> DIType;
InsertBefore: ValueRef)
-> ValueRef;
pub fn LLVMDIBuilderCreateEnumerator(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateVectorType(Builder: DIBuilderRef,
Name: *const c_char, Size: u64,
Val: c_ulonglong) AlignInBits: u64,
-> DIEnumerator; Ty: DIType,
Subscripts: DIArray)
-> DIType;
pub fn LLVMDIBuilderCreateEnumerationType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderGetOrCreateSubrange(Builder: DIBuilderRef,
Scope: DIScope, Lo: i64,
Name: *const c_char, Count: i64)
File: DIFile, -> DISubrange;
LineNumber: c_uint,
SizeInBits: c_ulonglong,
AlignInBits: c_ulonglong,
Elements: DIArray,
ClassType: DIType)
-> DIType;
pub fn LLVMDIBuilderCreateUnionType(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderGetOrCreateArray(Builder: DIBuilderRef,
Scope: DIScope, Ptr: *const DIDescriptor,
Name: *const c_char, Count: c_uint)
File: DIFile, -> DIArray;
LineNumber: c_uint,
SizeInBits: c_ulonglong, pub fn LLVMRustDIBuilderInsertDeclareAtEnd(Builder: DIBuilderRef,
AlignInBits: c_ulonglong, Val: ValueRef,
Flags: c_uint, VarInfo: DIVariable,
Elements: DIArray, AddrOps: *const i64,
RunTimeLang: c_uint, AddrOpsCount: c_uint,
UniqueId: *const c_char) DL: ValueRef,
-> DIType; InsertAtEnd: BasicBlockRef)
-> ValueRef;
pub fn LLVMRustDIBuilderInsertDeclareBefore(Builder: DIBuilderRef,
Val: ValueRef,
VarInfo: DIVariable,
AddrOps: *const i64,
AddrOpsCount: c_uint,
DL: ValueRef,
InsertBefore: ValueRef)
-> ValueRef;
pub fn LLVMRustDIBuilderCreateEnumerator(Builder: DIBuilderRef,
Name: *const c_char,
Val: u64)
-> DIEnumerator;
pub fn LLVMRustDIBuilderCreateEnumerationType(Builder: DIBuilderRef,
Scope: DIScope,
Name: *const c_char,
File: DIFile,
LineNumber: c_uint,
SizeInBits: u64,
AlignInBits: u64,
Elements: DIArray,
ClassType: DIType)
-> DIType;
pub fn LLVMRustDIBuilderCreateUnionType(Builder: DIBuilderRef,
Scope: DIScope,
Name: *const c_char,
File: DIFile,
LineNumber: c_uint,
SizeInBits: u64,
AlignInBits: u64,
Flags: c_uint,
Elements: DIArray,
RunTimeLang: c_uint,
UniqueId: *const c_char)
-> DIType;
pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool); pub fn LLVMSetUnnamedAddr(GlobalVar: ValueRef, UnnamedAddr: Bool);
pub fn LLVMDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef, pub fn LLVMRustDIBuilderCreateTemplateTypeParameter(Builder: DIBuilderRef,
Scope: DIScope, Scope: DIScope,
Name: *const c_char, Name: *const c_char,
Ty: DIType, Ty: DIType,
File: DIFile, File: DIFile,
LineNo: c_uint, LineNo: c_uint,
ColumnNo: c_uint) ColumnNo: c_uint)
-> DITemplateTypeParameter; -> DITemplateTypeParameter;
pub fn LLVMDIBuilderCreateOpDeref() -> i64;
pub fn LLVMDIBuilderCreateOpPlus() -> i64; pub fn LLVMRustDIBuilderCreateNameSpace(Builder: DIBuilderRef,
pub fn LLVMDIBuilderCreateNameSpace(Builder: DIBuilderRef,
Scope: DIScope,
Name: *const c_char,
File: DIFile,
LineNo: c_uint)
-> DINameSpace;
pub fn LLVMDIBuilderCreateDebugLocation(Context: ContextRef,
Line: c_uint,
Column: c_uint,
Scope: DIScope, Scope: DIScope,
InlinedAt: MetadataRef) Name: *const c_char,
-> ValueRef; File: DIFile,
LineNo: c_uint)
-> DINameSpace;
pub fn LLVMRustDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
CompositeType: DIType,
TypeArray: DIArray);
pub fn LLVMDICompositeTypeSetTypeArray(Builder: DIBuilderRef,
CompositeType: DIType, pub fn LLVMRustDIBuilderCreateDebugLocation(Context: ContextRef,
TypeArray: DIArray); Line: c_uint,
pub fn LLVMWriteTypeToString(Type: TypeRef, s: RustStringRef); Column: c_uint,
pub fn LLVMWriteValueToString(value_ref: ValueRef, s: RustStringRef); Scope: DIScope,
InlinedAt: MetadataRef)
-> ValueRef;
pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
pub fn LLVMRustDIBuilderCreateOpPlus() -> i64;
pub fn LLVMRustWriteTypeToString(Type: TypeRef, s: RustStringRef);
pub fn LLVMRustWriteValueToString(value_ref: ValueRef, s: RustStringRef);
pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef; pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
@ -2108,35 +2121,38 @@ extern {
C: DLLStorageClassTypes); C: DLLStorageClassTypes);
pub fn LLVMRustGetSectionName(SI: SectionIteratorRef, pub fn LLVMRustGetSectionName(SI: SectionIteratorRef,
data: *mut *const c_char) -> c_int; data: *mut *const c_char) -> size_t;
pub fn LLVMWriteTwineToString(T: TwineRef, s: RustStringRef); pub fn LLVMRustWriteTwineToString(T: TwineRef, s: RustStringRef);
pub fn LLVMContextSetDiagnosticHandler(C: ContextRef, pub fn LLVMContextSetDiagnosticHandler(C: ContextRef,
Handler: DiagnosticHandler, Handler: DiagnosticHandler,
DiagnosticContext: *mut c_void); DiagnosticContext: *mut c_void);
pub fn LLVMUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef, pub fn LLVMRustUnpackOptimizationDiagnostic(DI: DiagnosticInfoRef,
pass_name_out: *mut *const c_char, pass_name_out: *mut *const c_char,
function_out: *mut ValueRef, function_out: *mut ValueRef,
debugloc_out: *mut DebugLocRef, debugloc_out: *mut DebugLocRef,
message_out: *mut TwineRef); message_out: *mut TwineRef);
pub fn LLVMUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef, pub fn LLVMRustUnpackInlineAsmDiagnostic(DI: DiagnosticInfoRef,
cookie_out: *mut c_uint, cookie_out: *mut c_uint,
message_out: *mut TwineRef, message_out: *mut TwineRef,
instruction_out: *mut ValueRef); instruction_out: *mut ValueRef);
pub fn LLVMWriteDiagnosticInfoToString(DI: DiagnosticInfoRef, s: RustStringRef); pub fn LLVMRustWriteDiagnosticInfoToString(DI: DiagnosticInfoRef,
s: RustStringRef);
pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity; pub fn LLVMGetDiagInfoSeverity(DI: DiagnosticInfoRef) -> DiagnosticSeverity;
pub fn LLVMGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind; pub fn LLVMRustGetDiagInfoKind(DI: DiagnosticInfoRef) -> DiagnosticKind;
pub fn LLVMWriteDebugLocToString(C: ContextRef, DL: DebugLocRef, s: RustStringRef); pub fn LLVMRustWriteDebugLocToString(C: ContextRef,
DL: DebugLocRef,
s: RustStringRef);
pub fn LLVMSetInlineAsmDiagnosticHandler(C: ContextRef, pub fn LLVMRustSetInlineAsmDiagnosticHandler(C: ContextRef,
H: InlineAsmDiagHandler, H: InlineAsmDiagHandler,
CX: *mut c_void); CX: *mut c_void);
pub fn LLVMWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef); pub fn LLVMRustWriteSMDiagnosticToString(d: SMDiagnosticRef, s: RustStringRef);
pub fn LLVMRustWriteArchive(Dst: *const c_char, pub fn LLVMRustWriteArchive(Dst: *const c_char,
NumMembers: size_t, NumMembers: size_t,
@ -2237,15 +2253,15 @@ pub fn ConstFCmp(pred: RealPredicate, v1: ValueRef, v2: ValueRef) -> ValueRef {
pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) { pub fn SetFunctionAttribute(fn_: ValueRef, attr: Attribute) {
unsafe { unsafe {
LLVMAddFunctionAttribute(fn_, FunctionIndex as c_uint, LLVMRustAddFunctionAttribute(fn_, FunctionIndex as c_uint,
attr.bits() as uint64_t) attr.bits() as uint64_t)
} }
} }
pub fn RemoveFunctionAttributes(fn_: ValueRef, attr: Attribute) { pub fn RemoveFunctionAttributes(fn_: ValueRef, attr: Attribute) {
unsafe { unsafe {
LLVMRemoveFunctionAttributes(fn_, FunctionIndex as c_uint, LLVMRustRemoveFunctionAttributes(fn_, FunctionIndex as c_uint,
attr.bits() as uint64_t) attr.bits() as uint64_t)
} }
} }
@ -2366,12 +2382,12 @@ pub fn build_string<F>(f: F) -> Option<String> where F: FnOnce(RustStringRef){
} }
pub unsafe fn twine_to_string(tr: TwineRef) -> String { pub unsafe fn twine_to_string(tr: TwineRef) -> String {
build_string(|s| LLVMWriteTwineToString(tr, s)) build_string(|s| LLVMRustWriteTwineToString(tr, s))
.expect("got a non-UTF8 Twine from LLVM") .expect("got a non-UTF8 Twine from LLVM")
} }
pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String { pub unsafe fn debug_loc_to_string(c: ContextRef, tr: DebugLocRef) -> String {
build_string(|s| LLVMWriteDebugLocToString(c, tr, s)) build_string(|s| LLVMRustWriteDebugLocToString(c, tr, s))
.expect("got a non-UTF8 DebugLoc from LLVM") .expect("got a non-UTF8 DebugLoc from LLVM")
} }

View file

@ -80,10 +80,10 @@ pub fn set_frame_pointer_elimination(ccx: &CrateContext, llfn: ValueRef) {
unsafe { unsafe {
let attr = "no-frame-pointer-elim\0".as_ptr() as *const _; let attr = "no-frame-pointer-elim\0".as_ptr() as *const _;
let val = "true\0".as_ptr() as *const _; let val = "true\0".as_ptr() as *const _;
llvm::LLVMAddFunctionAttrStringValue(llfn, llvm::LLVMRustAddFunctionAttrStringValue(llfn,
llvm::FunctionIndex as c_uint, llvm::FunctionIndex as c_uint,
attr, attr,
val); val);
} }
} }
} }

View file

@ -365,7 +365,7 @@ unsafe extern "C" fn inline_asm_handler(diag: SMDiagnosticRef,
cookie: c_uint) { cookie: c_uint) {
let HandlerFreeVars { cgcx, .. } = *(user as *const HandlerFreeVars); let HandlerFreeVars { cgcx, .. } = *(user as *const HandlerFreeVars);
let msg = llvm::build_string(|s| llvm::LLVMWriteSMDiagnosticToString(diag, s)) let msg = llvm::build_string(|s| llvm::LLVMRustWriteSMDiagnosticToString(diag, s))
.expect("non-UTF8 SMDiagnostic"); .expect("non-UTF8 SMDiagnostic");
report_inline_asm(cgcx, &msg[..], cookie); report_inline_asm(cgcx, &msg[..], cookie);
@ -421,7 +421,7 @@ unsafe fn optimize_and_codegen(cgcx: &CodegenContext,
}; };
let fv = &fv as *const HandlerFreeVars as *mut c_void; let fv = &fv as *const HandlerFreeVars as *mut c_void;
llvm::LLVMSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, fv); llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, fv);
llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, fv); llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, fv);
let module_name = Some(&mtrans.name[..]); let module_name = Some(&mtrans.name[..]);

View file

@ -2348,7 +2348,8 @@ fn internalize_symbols<'a, 'tcx>(sess: &Session,
if !is_referenced_somewhere && !is_reachable && !has_fixed_linkage { if !is_referenced_somewhere && !is_reachable && !has_fixed_linkage {
llvm::SetLinkage(val, llvm::InternalLinkage); llvm::SetLinkage(val, llvm::InternalLinkage);
llvm::SetDLLStorageClass(val, llvm::DefaultStorageClass); llvm::SetDLLStorageClass(val,
llvm::DLLStorageClassTypes::Default);
llvm::UnsetComdat(val); llvm::UnsetComdat(val);
} }
} }

View file

@ -503,8 +503,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
unsafe { unsafe {
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr)); let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
let align = llalign_of_pref(self.ccx, ty.element_type()); let align = llalign_of_pref(self.ccx, ty.element_type());
llvm::LLVMBuildAtomicLoad(self.llbuilder, ptr, noname(), order, llvm::LLVMRustBuildAtomicLoad(self.llbuilder, ptr, noname(), order,
align as c_uint) align as c_uint)
} }
} }
@ -565,7 +565,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
unsafe { unsafe {
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr)); let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
let align = llalign_of_pref(self.ccx, ty.element_type()); let align = llalign_of_pref(self.ccx, ty.element_type());
llvm::LLVMBuildAtomicStore(self.llbuilder, val, ptr, order, align as c_uint); llvm::LLVMRustBuildAtomicStore(self.llbuilder, val, ptr, order, align as c_uint);
} }
} }
@ -840,7 +840,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
debug!("Asm Output Type: {:?}", output); debug!("Asm Output Type: {:?}", output);
let fty = Type::func(&argtys[..], &output); let fty = Type::func(&argtys[..], &output);
unsafe { unsafe {
let v = llvm::LLVMInlineAsm( let v = llvm::LLVMRustInlineAsm(
fty.to_ref(), asm, cons, volatile, alignstack, dia as c_uint); fty.to_ref(), asm, cons, volatile, alignstack, dia as c_uint);
self.call(v, inputs, None) self.call(v, inputs, None)
} }
@ -1097,7 +1097,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope) { pub fn atomic_fence(&self, order: AtomicOrdering, scope: SynchronizationScope) {
unsafe { unsafe {
llvm::LLVMBuildAtomicFence(self.llbuilder, order, scope); llvm::LLVMRustBuildAtomicFence(self.llbuilder, order, scope);
} }
} }
} }

View file

@ -1126,7 +1126,7 @@ pub fn get_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, def_id: DefId)
} }
} }
if ccx.use_dll_storage_attrs() { if ccx.use_dll_storage_attrs() {
llvm::SetDLLStorageClass(g, llvm::DLLImportStorageClass); llvm::SetDLLStorageClass(g, llvm::DLLStorageClassTypes::DllImport);
} }
g g
}; };
@ -1182,7 +1182,7 @@ pub fn trans_static(ccx: &CrateContext,
let name_str_ref = CStr::from_ptr(llvm::LLVMGetValueName(datum.val)); let name_str_ref = CStr::from_ptr(llvm::LLVMGetValueName(datum.val));
let name_string = CString::new(name_str_ref.to_bytes()).unwrap(); let name_string = CString::new(name_str_ref.to_bytes()).unwrap();
llvm::LLVMSetValueName(datum.val, empty_string.as_ptr()); llvm::LLVMSetValueName(datum.val, empty_string.as_ptr());
let new_g = llvm::LLVMGetOrInsertGlobal( let new_g = llvm::LLVMRustGetOrInsertGlobal(
ccx.llmod(), name_string.as_ptr(), val_llty.to_ref()); ccx.llmod(), name_string.as_ptr(), val_llty.to_ref());
// To avoid breaking any invariants, we leave around the old // To avoid breaking any invariants, we leave around the old
// global for the moment; we'll replace all references to it // global for the moment; we'll replace all references to it

View file

@ -133,7 +133,7 @@ fn make_mir_scope(ccx: &CrateContext,
let loc = span_start(ccx, scope_data.span); let loc = span_start(ccx, scope_data.span);
scopes[scope] = unsafe { scopes[scope] = unsafe {
let file_metadata = file_metadata(ccx, &loc.file.name, &loc.file.abs_path); let file_metadata = file_metadata(ccx, &loc.file.name, &loc.file.abs_path);
llvm::LLVMDIBuilderCreateLexicalBlock( llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(ccx), DIB(ccx),
parent_scope, parent_scope,
file_metadata, file_metadata,
@ -156,7 +156,7 @@ fn with_new_scope<F>(cx: &CrateContext,
let parent_scope = scope_stack.last().unwrap().scope_metadata; let parent_scope = scope_stack.last().unwrap().scope_metadata;
let scope_metadata = unsafe { let scope_metadata = unsafe {
llvm::LLVMDIBuilderCreateLexicalBlock( llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(cx), DIB(cx),
parent_scope, parent_scope,
file_metadata, file_metadata,
@ -272,7 +272,7 @@ fn walk_pattern(cx: &CrateContext,
let parent_scope = scope_stack.last().unwrap().scope_metadata; let parent_scope = scope_stack.last().unwrap().scope_metadata;
let scope_metadata = unsafe { let scope_metadata = unsafe {
llvm::LLVMDIBuilderCreateLexicalBlock( llvm::LLVMRustDIBuilderCreateLexicalBlock(
DIB(cx), DIB(cx),
parent_scope, parent_scope,
file_metadata, file_metadata,

View file

@ -504,12 +504,12 @@ fn fixed_vec_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
}; };
let subrange = unsafe { let subrange = unsafe {
llvm::LLVMDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound) llvm::LLVMRustDIBuilderGetOrCreateSubrange(DIB(cx), 0, upper_bound)
}; };
let subscripts = create_DIArray(DIB(cx), &[subrange]); let subscripts = create_DIArray(DIB(cx), &[subrange]);
let metadata = unsafe { let metadata = unsafe {
llvm::LLVMDIBuilderCreateArrayType( llvm::LLVMRustDIBuilderCreateArrayType(
DIB(cx), DIB(cx),
bytes_to_bits(array_size_in_bytes), bytes_to_bits(array_size_in_bytes),
bytes_to_bits(element_type_align), bytes_to_bits(element_type_align),
@ -612,7 +612,7 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
return MetadataCreationResult::new( return MetadataCreationResult::new(
unsafe { unsafe {
llvm::LLVMDIBuilderCreateSubroutineType( llvm::LLVMRustDIBuilderCreateSubroutineType(
DIB(cx), DIB(cx),
unknown_file_metadata(cx), unknown_file_metadata(cx),
create_DIArray(DIB(cx), &signature_metadata[..])) create_DIArray(DIB(cx), &signature_metadata[..]))
@ -885,8 +885,8 @@ fn file_metadata_(cx: &CrateContext, key: &str, file_name: &str, work_dir: &str)
let file_name = CString::new(file_name).unwrap(); let file_name = CString::new(file_name).unwrap();
let work_dir = CString::new(work_dir).unwrap(); let work_dir = CString::new(work_dir).unwrap();
let file_metadata = unsafe { let file_metadata = unsafe {
llvm::LLVMDIBuilderCreateFile(DIB(cx), file_name.as_ptr(), llvm::LLVMRustDIBuilderCreateFile(DIB(cx), file_name.as_ptr(),
work_dir.as_ptr()) work_dir.as_ptr())
}; };
let mut created_files = debug_context(cx).created_files.borrow_mut(); let mut created_files = debug_context(cx).created_files.borrow_mut();
@ -916,7 +916,7 @@ pub fn scope_metadata(fcx: &FunctionContext,
pub fn diverging_type_metadata(cx: &CrateContext) -> DIType { pub fn diverging_type_metadata(cx: &CrateContext) -> DIType {
unsafe { unsafe {
llvm::LLVMDIBuilderCreateBasicType( llvm::LLVMRustDIBuilderCreateBasicType(
DIB(cx), DIB(cx),
"!\0".as_ptr() as *const _, "!\0".as_ptr() as *const _,
bytes_to_bits(0), bytes_to_bits(0),
@ -951,7 +951,7 @@ fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let (size, align) = size_and_align_of(cx, llvm_type); let (size, align) = size_and_align_of(cx, llvm_type);
let name = CString::new(name).unwrap(); let name = CString::new(name).unwrap();
let ty_metadata = unsafe { let ty_metadata = unsafe {
llvm::LLVMDIBuilderCreateBasicType( llvm::LLVMRustDIBuilderCreateBasicType(
DIB(cx), DIB(cx),
name.as_ptr(), name.as_ptr(),
bytes_to_bits(size), bytes_to_bits(size),
@ -971,7 +971,7 @@ fn pointer_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let name = compute_debuginfo_type_name(cx, pointer_type, false); let name = compute_debuginfo_type_name(cx, pointer_type, false);
let name = CString::new(name).unwrap(); let name = CString::new(name).unwrap();
let ptr_metadata = unsafe { let ptr_metadata = unsafe {
llvm::LLVMDIBuilderCreatePointerType( llvm::LLVMRustDIBuilderCreatePointerType(
DIB(cx), DIB(cx),
pointee_type_metadata, pointee_type_metadata,
bytes_to_bits(pointer_size), bytes_to_bits(pointer_size),
@ -1017,7 +1017,7 @@ pub fn compile_unit_metadata(scc: &SharedCrateContext,
let flags = "\0"; let flags = "\0";
let split_name = "\0"; let split_name = "\0";
return unsafe { return unsafe {
llvm::LLVMDIBuilderCreateCompileUnit( llvm::LLVMRustDIBuilderCreateCompileUnit(
debug_context.builder, debug_context.builder,
DW_LANG_RUST, DW_LANG_RUST,
compile_unit_name, compile_unit_name,
@ -1596,7 +1596,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let token = v.name.as_str(); let token = v.name.as_str();
let name = CString::new(token.as_bytes()).unwrap(); let name = CString::new(token.as_bytes()).unwrap();
unsafe { unsafe {
llvm::LLVMDIBuilderCreateEnumerator( llvm::LLVMRustDIBuilderCreateEnumerator(
DIB(cx), DIB(cx),
name.as_ptr(), name.as_ptr(),
v.disr_val.to_u64_unchecked()) v.disr_val.to_u64_unchecked())
@ -1623,7 +1623,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let name = CString::new(discriminant_name.as_bytes()).unwrap(); let name = CString::new(discriminant_name.as_bytes()).unwrap();
let discriminant_type_metadata = unsafe { let discriminant_type_metadata = unsafe {
llvm::LLVMDIBuilderCreateEnumerationType( llvm::LLVMRustDIBuilderCreateEnumerationType(
DIB(cx), DIB(cx),
containing_scope, containing_scope,
name.as_ptr(), name.as_ptr(),
@ -1667,7 +1667,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let enum_name = CString::new(enum_name).unwrap(); let enum_name = CString::new(enum_name).unwrap();
let unique_type_id_str = CString::new(unique_type_id_str.as_bytes()).unwrap(); let unique_type_id_str = CString::new(unique_type_id_str.as_bytes()).unwrap();
let enum_metadata = unsafe { let enum_metadata = unsafe {
llvm::LLVMDIBuilderCreateUnionType( llvm::LLVMRustDIBuilderCreateUnionType(
DIB(cx), DIB(cx),
containing_scope, containing_scope,
enum_name.as_ptr(), enum_name.as_ptr(),
@ -1769,7 +1769,7 @@ fn set_members_of_composite_type(cx: &CrateContext,
let member_name = member_description.name.as_bytes(); let member_name = member_description.name.as_bytes();
let member_name = CString::new(member_name).unwrap(); let member_name = CString::new(member_name).unwrap();
unsafe { unsafe {
llvm::LLVMDIBuilderCreateMemberType( llvm::LLVMRustDIBuilderCreateMemberType(
DIB(cx), DIB(cx),
composite_type_metadata, composite_type_metadata,
member_name.as_ptr(), member_name.as_ptr(),
@ -1786,13 +1786,14 @@ fn set_members_of_composite_type(cx: &CrateContext,
unsafe { unsafe {
let type_array = create_DIArray(DIB(cx), &member_metadata[..]); let type_array = create_DIArray(DIB(cx), &member_metadata[..]);
llvm::LLVMDICompositeTypeSetTypeArray(DIB(cx), composite_type_metadata, type_array); llvm::LLVMRustDICompositeTypeSetTypeArray(
DIB(cx), composite_type_metadata, type_array);
} }
} }
// A convenience wrapper around LLVMDIBuilderCreateStructType(). Does not do any // A convenience wrapper around LLVMRustDIBuilderCreateStructType(). Does not do
// caching, does not add any fields to the struct. This can be done later with // any caching, does not add any fields to the struct. This can be done later
// set_members_of_composite_type(). // with set_members_of_composite_type().
fn create_struct_stub(cx: &CrateContext, fn create_struct_stub(cx: &CrateContext,
struct_llvm_type: Type, struct_llvm_type: Type,
struct_type_name: &str, struct_type_name: &str,
@ -1807,12 +1808,12 @@ fn create_struct_stub(cx: &CrateContext,
let name = CString::new(struct_type_name).unwrap(); let name = CString::new(struct_type_name).unwrap();
let unique_type_id = CString::new(unique_type_id_str.as_bytes()).unwrap(); let unique_type_id = CString::new(unique_type_id_str.as_bytes()).unwrap();
let metadata_stub = unsafe { let metadata_stub = unsafe {
// LLVMDIBuilderCreateStructType() wants an empty array. A null // LLVMRustDIBuilderCreateStructType() wants an empty array. A null
// pointer will lead to hard to trace and debug LLVM assertions // pointer will lead to hard to trace and debug LLVM assertions
// later on in llvm/lib/IR/Value.cpp. // later on in llvm/lib/IR/Value.cpp.
let empty_array = create_DIArray(DIB(cx), &[]); let empty_array = create_DIArray(DIB(cx), &[]);
llvm::LLVMDIBuilderCreateStructType( llvm::LLVMRustDIBuilderCreateStructType(
DIB(cx), DIB(cx),
containing_scope, containing_scope,
name.as_ptr(), name.as_ptr(),
@ -1868,16 +1869,16 @@ pub fn create_global_var_metadata(cx: &CrateContext,
let var_name = CString::new(var_name).unwrap(); let var_name = CString::new(var_name).unwrap();
let linkage_name = CString::new(linkage_name).unwrap(); let linkage_name = CString::new(linkage_name).unwrap();
unsafe { unsafe {
llvm::LLVMDIBuilderCreateStaticVariable(DIB(cx), llvm::LLVMRustDIBuilderCreateStaticVariable(DIB(cx),
var_scope, var_scope,
var_name.as_ptr(), var_name.as_ptr(),
linkage_name.as_ptr(), linkage_name.as_ptr(),
file_metadata, file_metadata,
line_number, line_number,
type_metadata, type_metadata,
is_local_to_unit, is_local_to_unit,
global, global,
ptr::null_mut()); ptr::null_mut());
} }
} }
@ -1980,10 +1981,10 @@ pub fn create_captured_var_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
env_index); env_index);
let address_operations = unsafe { let address_operations = unsafe {
[llvm::LLVMDIBuilderCreateOpDeref(), [llvm::LLVMRustDIBuilderCreateOpDeref(),
llvm::LLVMDIBuilderCreateOpPlus(), llvm::LLVMRustDIBuilderCreateOpPlus(),
byte_offset_of_var_in_env as i64, byte_offset_of_var_in_env as i64,
llvm::LLVMDIBuilderCreateOpDeref()] llvm::LLVMRustDIBuilderCreateOpDeref()]
}; };
let address_op_count = if captured_by_ref { let address_op_count = if captured_by_ref {
@ -2021,7 +2022,7 @@ pub fn create_match_binding_metadata<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
let scope_metadata = scope_metadata(bcx.fcx, binding.id, binding.span); let scope_metadata = scope_metadata(bcx.fcx, binding.id, binding.span);
let aops = unsafe { let aops = unsafe {
[llvm::LLVMDIBuilderCreateOpDeref()] [llvm::LLVMRustDIBuilderCreateOpDeref()]
}; };
// Regardless of the actual type (`T`) we're always passed the stack slot // Regardless of the actual type (`T`) we're always passed the stack slot
// (alloca) for the binding. For ByRef bindings that's a `T*` but for ByMove // (alloca) for the binding. For ByRef bindings that's a `T*` but for ByMove

View file

@ -88,7 +88,7 @@ pub struct CrateDebugContext<'tcx> {
impl<'tcx> CrateDebugContext<'tcx> { impl<'tcx> CrateDebugContext<'tcx> {
pub fn new(llmod: ModuleRef) -> CrateDebugContext<'tcx> { pub fn new(llmod: ModuleRef) -> CrateDebugContext<'tcx> {
debug!("CrateDebugContext::new"); debug!("CrateDebugContext::new");
let builder = unsafe { llvm::LLVMDIBuilderCreate(llmod) }; let builder = unsafe { llvm::LLVMRustDIBuilderCreate(llmod) };
// DIBuilder inherits context from the module, so we'd better use the same one // DIBuilder inherits context from the module, so we'd better use the same one
let llcontext = unsafe { llvm::LLVMGetModuleContext(llmod) }; let llcontext = unsafe { llvm::LLVMGetModuleContext(llmod) };
return CrateDebugContext { return CrateDebugContext {
@ -178,8 +178,8 @@ pub fn finalize(cx: &CrateContext) {
} }
unsafe { unsafe {
llvm::LLVMDIBuilderFinalize(DIB(cx)); llvm::LLVMRustDIBuilderFinalize(DIB(cx));
llvm::LLVMDIBuilderDispose(DIB(cx)); llvm::LLVMRustDIBuilderDispose(DIB(cx));
// Debuginfo generation in LLVM by default uses a higher // Debuginfo generation in LLVM by default uses a higher
// version of dwarf than OS X currently understands. We can // version of dwarf than OS X currently understands. We can
// instruct LLVM to emit an older version of dwarf, however, // instruct LLVM to emit an older version of dwarf, however,
@ -250,7 +250,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let function_type_metadata = unsafe { let function_type_metadata = unsafe {
let fn_signature = get_function_signature(cx, sig, abi); let fn_signature = get_function_signature(cx, sig, abi);
llvm::LLVMDIBuilderCreateSubroutineType(DIB(cx), file_metadata, fn_signature) llvm::LLVMRustDIBuilderCreateSubroutineType(DIB(cx), file_metadata, fn_signature)
}; };
// Find the enclosing function, in case this is a closure. // Find the enclosing function, in case this is a closure.
@ -284,7 +284,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let linkage_name = CString::new(linkage_name).unwrap(); let linkage_name = CString::new(linkage_name).unwrap();
let fn_metadata = unsafe { let fn_metadata = unsafe {
llvm::LLVMDIBuilderCreateFunction( llvm::LLVMRustDIBuilderCreateFunction(
DIB(cx), DIB(cx),
containing_scope, containing_scope,
function_name.as_ptr(), function_name.as_ptr(),
@ -388,7 +388,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP); let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
let name = CString::new(param.name.as_str().as_bytes()).unwrap(); let name = CString::new(param.name.as_str().as_bytes()).unwrap();
unsafe { unsafe {
llvm::LLVMDIBuilderCreateTemplateTypeParameter( llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
DIB(cx), DIB(cx),
ptr::null_mut(), ptr::null_mut(),
name.as_ptr(), name.as_ptr(),
@ -492,7 +492,7 @@ pub fn declare_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
(DirectVariable { alloca }, address_operations) | (DirectVariable { alloca }, address_operations) |
(IndirectVariable {alloca, address_operations}, _) => { (IndirectVariable {alloca, address_operations}, _) => {
let metadata = unsafe { let metadata = unsafe {
llvm::LLVMDIBuilderCreateVariable( llvm::LLVMRustDIBuilderCreateVariable(
DIB(cx), DIB(cx),
dwarf_tag, dwarf_tag,
scope_metadata, scope_metadata,
@ -510,7 +510,7 @@ pub fn declare_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
InternalDebugLocation::new(scope_metadata, loc.line, loc.col.to_usize())); InternalDebugLocation::new(scope_metadata, loc.line, loc.col.to_usize()));
unsafe { unsafe {
let debug_loc = llvm::LLVMGetCurrentDebugLocation(cx.raw_builder()); let debug_loc = llvm::LLVMGetCurrentDebugLocation(cx.raw_builder());
let instr = llvm::LLVMDIBuilderInsertDeclareAtEnd( let instr = llvm::LLVMRustDIBuilderInsertDeclareAtEnd(
DIB(cx), DIB(cx),
alloca, alloca,
metadata, metadata,

View file

@ -78,7 +78,7 @@ pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {
}; };
let scope = unsafe { let scope = unsafe {
llvm::LLVMDIBuilderCreateNameSpace( llvm::LLVMRustDIBuilderCreateNameSpace(
DIB(ccx), DIB(ccx),
parent_scope, parent_scope,
namespace_name.as_ptr(), namespace_name.as_ptr(),

View file

@ -206,7 +206,7 @@ pub fn set_debug_location(cx: &CrateContext,
debug!("setting debug location to {} {}", line, col); debug!("setting debug location to {} {}", line, col);
unsafe { unsafe {
llvm::LLVMDIBuilderCreateDebugLocation( llvm::LLVMRustDIBuilderCreateDebugLocation(
debug_context(cx).llcontext, debug_context(cx).llcontext,
line as c_uint, line as c_uint,
col as c_uint, col as c_uint,

View file

@ -40,7 +40,7 @@ pub fn is_node_local_to_unit(cx: &CrateContext, node_id: ast::NodeId) -> bool
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray { pub fn create_DIArray(builder: DIBuilderRef, arr: &[DIDescriptor]) -> DIArray {
return unsafe { return unsafe {
llvm::LLVMDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32) llvm::LLVMRustDIBuilderGetOrCreateArray(builder, arr.as_ptr(), arr.len() as u32)
}; };
} }

View file

@ -40,7 +40,7 @@ pub fn declare_global(ccx: &CrateContext, name: &str, ty: Type) -> llvm::ValueRe
bug!("name {:?} contains an interior null byte", name) bug!("name {:?} contains an interior null byte", name)
}); });
unsafe { unsafe {
llvm::LLVMGetOrInsertGlobal(ccx.llmod(), namebuf.as_ptr(), ty.to_ref()) llvm::LLVMRustGetOrInsertGlobal(ccx.llmod(), namebuf.as_ptr(), ty.to_ref())
} }
} }
@ -55,7 +55,7 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
bug!("name {:?} contains an interior null byte", name) bug!("name {:?} contains an interior null byte", name)
}); });
let llfn = unsafe { let llfn = unsafe {
llvm::LLVMGetOrInsertFunction(ccx.llmod(), namebuf.as_ptr(), ty.to_ref()) llvm::LLVMRustGetOrInsertFunction(ccx.llmod(), namebuf.as_ptr(), ty.to_ref())
}; };
llvm::SetFunctionCallConv(llfn, callconv); llvm::SetFunctionCallConv(llfn, callconv);
@ -173,7 +173,7 @@ pub fn get_declared_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
let namebuf = CString::new(name).unwrap_or_else(|_|{ let namebuf = CString::new(name).unwrap_or_else(|_|{
bug!("name {:?} contains an interior null byte", name) bug!("name {:?} contains an interior null byte", name)
}); });
let val = unsafe { llvm::LLVMGetNamedValue(ccx.llmod(), namebuf.as_ptr()) }; let val = unsafe { llvm::LLVMRustGetNamedValue(ccx.llmod(), namebuf.as_ptr()) };
if val.is_null() { if val.is_null() {
debug!("get_declared_value: {:?} value is null", name); debug!("get_declared_value: {:?} value is null", name);
None None

View file

@ -640,28 +640,30 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
// This requires that atomic intrinsics follow a specific naming pattern: // This requires that atomic intrinsics follow a specific naming pattern:
// "atomic_<operation>[_<ordering>]", and no ordering means SeqCst // "atomic_<operation>[_<ordering>]", and no ordering means SeqCst
(_, name) if name.starts_with("atomic_") => { (_, name) if name.starts_with("atomic_") => {
use llvm::AtomicOrdering::*;
let split: Vec<&str> = name.split('_').collect(); let split: Vec<&str> = name.split('_').collect();
let is_cxchg = split[1] == "cxchg" || split[1] == "cxchgweak"; let is_cxchg = split[1] == "cxchg" || split[1] == "cxchgweak";
let (order, failorder) = match split.len() { let (order, failorder) = match split.len() {
2 => (llvm::SequentiallyConsistent, llvm::SequentiallyConsistent), 2 => (SequentiallyConsistent, SequentiallyConsistent),
3 => match split[2] { 3 => match split[2] {
"unordered" => (llvm::Unordered, llvm::Unordered), "unordered" => (Unordered, Unordered),
"relaxed" => (llvm::Monotonic, llvm::Monotonic), "relaxed" => (Monotonic, Monotonic),
"acq" => (llvm::Acquire, llvm::Acquire), "acq" => (Acquire, Acquire),
"rel" => (llvm::Release, llvm::Monotonic), "rel" => (Release, Monotonic),
"acqrel" => (llvm::AcquireRelease, llvm::Acquire), "acqrel" => (AcquireRelease, Acquire),
"failrelaxed" if is_cxchg => "failrelaxed" if is_cxchg =>
(llvm::SequentiallyConsistent, llvm::Monotonic), (SequentiallyConsistent, Monotonic),
"failacq" if is_cxchg => "failacq" if is_cxchg =>
(llvm::SequentiallyConsistent, llvm::Acquire), (SequentiallyConsistent, Acquire),
_ => ccx.sess().fatal("unknown ordering in atomic intrinsic") _ => ccx.sess().fatal("unknown ordering in atomic intrinsic")
}, },
4 => match (split[2], split[3]) { 4 => match (split[2], split[3]) {
("acq", "failrelaxed") if is_cxchg => ("acq", "failrelaxed") if is_cxchg =>
(llvm::Acquire, llvm::Monotonic), (Acquire, Monotonic),
("acqrel", "failrelaxed") if is_cxchg => ("acqrel", "failrelaxed") if is_cxchg =>
(llvm::AcquireRelease, llvm::Monotonic), (AcquireRelease, Monotonic),
_ => ccx.sess().fatal("unknown ordering in atomic intrinsic") _ => ccx.sess().fatal("unknown ordering in atomic intrinsic")
}, },
_ => ccx.sess().fatal("Atomic intrinsic not in correct format"), _ => ccx.sess().fatal("Atomic intrinsic not in correct format"),
@ -714,12 +716,12 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
} }
"fence" => { "fence" => {
AtomicFence(bcx, order, llvm::CrossThread); AtomicFence(bcx, order, llvm::SynchronizationScope::CrossThread);
C_nil(ccx) C_nil(ccx)
} }
"singlethreadfence" => { "singlethreadfence" => {
AtomicFence(bcx, order, llvm::SingleThread); AtomicFence(bcx, order, llvm::SynchronizationScope::SingleThread);
C_nil(ccx) C_nil(ccx)
} }

View file

@ -324,8 +324,8 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
machine::llelement_offset(bcx.ccx(), lltuplety, i); machine::llelement_offset(bcx.ccx(), lltuplety, i);
let ops = unsafe { let ops = unsafe {
[llvm::LLVMDIBuilderCreateOpDeref(), [llvm::LLVMRustDIBuilderCreateOpDeref(),
llvm::LLVMDIBuilderCreateOpPlus(), llvm::LLVMRustDIBuilderCreateOpPlus(),
byte_offset_of_var_in_tuple as i64] byte_offset_of_var_in_tuple as i64]
}; };
@ -450,10 +450,10 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
machine::llelement_offset(bcx.ccx(), llclosurety, i); machine::llelement_offset(bcx.ccx(), llclosurety, i);
let ops = unsafe { let ops = unsafe {
[llvm::LLVMDIBuilderCreateOpDeref(), [llvm::LLVMRustDIBuilderCreateOpDeref(),
llvm::LLVMDIBuilderCreateOpPlus(), llvm::LLVMRustDIBuilderCreateOpPlus(),
byte_offset_of_var_in_env as i64, byte_offset_of_var_in_env as i64,
llvm::LLVMDIBuilderCreateOpDeref()] llvm::LLVMRustDIBuilderCreateOpDeref()]
}; };
// The environment and the capture can each be indirect. // The environment and the capture can each be indirect.

View file

@ -36,7 +36,7 @@ pub struct Type {
impl fmt::Debug for Type { impl fmt::Debug for Type {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&llvm::build_string(|s| unsafe { f.write_str(&llvm::build_string(|s| unsafe {
llvm::LLVMWriteTypeToString(self.to_ref(), s); llvm::LLVMRustWriteTypeToString(self.to_ref(), s);
}).expect("non-UTF8 type description from LLVM")) }).expect("non-UTF8 type description from LLVM"))
} }
} }
@ -72,7 +72,7 @@ impl Type {
} }
pub fn metadata(ccx: &CrateContext) -> Type { pub fn metadata(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMMetadataTypeInContext(ccx.llcx())) ty!(llvm::LLVMRustMetadataTypeInContext(ccx.llcx()))
} }
pub fn i1(ccx: &CrateContext) -> Type { pub fn i1(ccx: &CrateContext) -> Type {

View file

@ -23,7 +23,7 @@ pub struct Value(pub ValueRef);
impl fmt::Debug for Value { impl fmt::Debug for Value {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&llvm::build_string(|s| unsafe { f.write_str(&llvm::build_string(|s| unsafe {
llvm::LLVMWriteValueToString(self.0, s); llvm::LLVMRustWriteValueToString(self.0, s);
}).expect("nun-UTF8 value description from LLVM")) }).expect("nun-UTF8 value description from LLVM"))
} }
} }

View file

@ -13,6 +13,7 @@
#include "llvm/Object/ObjectFile.h" #include "llvm/Object/ObjectFile.h"
#include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/CallSite.h" #include "llvm/IR/CallSite.h"
@ -27,6 +28,30 @@ using namespace llvm;
using namespace llvm::sys; using namespace llvm::sys;
using namespace llvm::object; using namespace llvm::object;
// LLVMAtomicOrdering is already an enum - don't create another
// one.
static AtomicOrdering from_rust(LLVMAtomicOrdering Ordering) {
switch (Ordering) {
case LLVMAtomicOrderingNotAtomic:
return AtomicOrdering::NotAtomic;
case LLVMAtomicOrderingUnordered:
return AtomicOrdering::Unordered;
case LLVMAtomicOrderingMonotonic:
return AtomicOrdering::Monotonic;
case LLVMAtomicOrderingAcquire:
return AtomicOrdering::Acquire;
case LLVMAtomicOrderingRelease:
return AtomicOrdering::Release;
case LLVMAtomicOrderingAcquireRelease:
return AtomicOrdering::AcquireRelease;
case LLVMAtomicOrderingSequentiallyConsistent:
return AtomicOrdering::SequentiallyConsistent;
}
llvm_unreachable("Invalid LLVMAtomicOrdering value!");
}
static char *LastError; static char *LastError;
extern "C" LLVMMemoryBufferRef extern "C" LLVMMemoryBufferRef
@ -57,45 +82,30 @@ LLVMRustSetNormalizedTarget(LLVMModuleRef M, const char *triple) {
unwrap(M)->setTargetTriple(Triple::normalize(triple)); unwrap(M)->setTargetTriple(Triple::normalize(triple));
} }
extern "C" LLVMValueRef LLVMRustConstSmallInt(LLVMTypeRef IntTy, unsigned N,
LLVMBool SignExtend) {
return LLVMConstInt(IntTy, (unsigned long long)N, SignExtend);
}
extern "C" LLVMValueRef LLVMRustConstInt(LLVMTypeRef IntTy,
unsigned N_hi,
unsigned N_lo,
LLVMBool SignExtend) {
unsigned long long N = N_hi;
N <<= 32;
N |= N_lo;
return LLVMConstInt(IntTy, N, SignExtend);
}
extern "C" void LLVMRustPrintPassTimings() { extern "C" void LLVMRustPrintPassTimings() {
raw_fd_ostream OS (2, false); // stderr. raw_fd_ostream OS (2, false); // stderr.
TimerGroup::printAll(OS); TimerGroup::printAll(OS);
} }
extern "C" LLVMValueRef LLVMGetNamedValue(LLVMModuleRef M, extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M,
const char* Name) { const char* Name) {
return wrap(unwrap(M)->getNamedValue(Name)); return wrap(unwrap(M)->getNamedValue(Name));
} }
extern "C" LLVMValueRef LLVMGetOrInsertFunction(LLVMModuleRef M, extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
const char* Name, const char* Name,
LLVMTypeRef FunctionTy) { LLVMTypeRef FunctionTy) {
return wrap(unwrap(M)->getOrInsertFunction(Name, return wrap(unwrap(M)->getOrInsertFunction(Name,
unwrap<FunctionType>(FunctionTy))); unwrap<FunctionType>(FunctionTy)));
} }
extern "C" LLVMValueRef LLVMGetOrInsertGlobal(LLVMModuleRef M, extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M,
const char* Name, const char* Name,
LLVMTypeRef Ty) { LLVMTypeRef Ty) {
return wrap(unwrap(M)->getOrInsertGlobal(Name, unwrap(Ty))); return wrap(unwrap(M)->getOrInsertGlobal(Name, unwrap(Ty)));
} }
extern "C" LLVMTypeRef LLVMMetadataTypeInContext(LLVMContextRef C) { extern "C" LLVMTypeRef LLVMRustMetadataTypeInContext(LLVMContextRef C) {
return wrap(Type::getMetadataTy(*unwrap(C))); return wrap(Type::getMetadataTy(*unwrap(C)));
} }
@ -110,7 +120,10 @@ extern "C" void LLVMRustAddCallSiteAttribute(LLVMValueRef Instr, unsigned index,
} }
extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned idx, uint64_t b) { extern "C" void LLVMRustAddDereferenceableCallSiteAttr(LLVMValueRef Instr,
unsigned idx,
uint64_t b)
{
CallSite Call = CallSite(unwrap<Instruction>(Instr)); CallSite Call = CallSite(unwrap<Instruction>(Instr));
AttrBuilder B; AttrBuilder B;
B.addDereferenceableAttr(b); B.addDereferenceableAttr(b);
@ -120,38 +133,50 @@ extern "C" void LLVMAddDereferenceableCallSiteAttr(LLVMValueRef Instr, unsigned
idx, B))); idx, B)));
} }
extern "C" void LLVMAddFunctionAttribute(LLVMValueRef Fn, unsigned index, extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn,
uint64_t Val) { unsigned index,
uint64_t Val)
{
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addRawValue(Val); B.addRawValue(Val);
A->addAttributes(index, AttributeSet::get(A->getContext(), index, B)); A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
} }
extern "C" void LLVMAddDereferenceableAttr(LLVMValueRef Fn, unsigned index, uint64_t bytes) { extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn,
unsigned index,
uint64_t bytes)
{
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addDereferenceableAttr(bytes); B.addDereferenceableAttr(bytes);
A->addAttributes(index, AttributeSet::get(A->getContext(), index, B)); A->addAttributes(index, AttributeSet::get(A->getContext(), index, B));
} }
extern "C" void LLVMAddFunctionAttrString(LLVMValueRef Fn, unsigned index, const char *Name) { extern "C" void LLVMRustAddFunctionAttrString(LLVMValueRef Fn,
unsigned index,
const char *Name)
{
Function *F = unwrap<Function>(Fn); Function *F = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addAttribute(Name); B.addAttribute(Name);
F->addAttributes(index, AttributeSet::get(F->getContext(), index, B)); F->addAttributes(index, AttributeSet::get(F->getContext(), index, B));
} }
extern "C" void LLVMAddFunctionAttrStringValue(LLVMValueRef Fn, unsigned index, extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn,
const char *Name, unsigned index,
const char *Value) { const char *Name,
const char *Value) {
Function *F = unwrap<Function>(Fn); Function *F = unwrap<Function>(Fn);
AttrBuilder B; AttrBuilder B;
B.addAttribute(Name, Value); B.addAttribute(Name, Value);
F->addAttributes(index, AttributeSet::get(F->getContext(), index, B)); F->addAttributes(index, AttributeSet::get(F->getContext(), index, B));
} }
extern "C" void LLVMRemoveFunctionAttributes(LLVMValueRef Fn, unsigned index, uint64_t Val) { extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
unsigned index,
uint64_t Val)
{
Function *A = unwrap<Function>(Fn); Function *A = unwrap<Function>(Fn);
const AttributeSet PAL = A->getAttributes(); const AttributeSet PAL = A->getAttributes();
AttrBuilder B(Val); AttrBuilder B(Val);
@ -161,7 +186,10 @@ extern "C" void LLVMRemoveFunctionAttributes(LLVMValueRef Fn, unsigned index, ui
A->setAttributes(PALnew); A->setAttributes(PALnew);
} }
extern "C" void LLVMRemoveFunctionAttrString(LLVMValueRef fn, unsigned index, const char *Name) { extern "C" void LLVMRustRemoveFunctionAttrString(LLVMValueRef fn,
unsigned index,
const char *Name)
{
Function *f = unwrap<Function>(fn); Function *f = unwrap<Function>(fn);
LLVMContext &C = f->getContext(); LLVMContext &C = f->getContext();
AttrBuilder B; AttrBuilder B;
@ -181,24 +209,24 @@ extern "C" void LLVMRustSetHasUnsafeAlgebra(LLVMValueRef V) {
} }
} }
extern "C" LLVMValueRef LLVMBuildAtomicLoad(LLVMBuilderRef B, extern "C" LLVMValueRef LLVMRustBuildAtomicLoad(LLVMBuilderRef B,
LLVMValueRef source, LLVMValueRef source,
const char* Name, const char* Name,
AtomicOrdering order, LLVMAtomicOrdering order,
unsigned alignment) { unsigned alignment) {
LoadInst* li = new LoadInst(unwrap(source),0); LoadInst* li = new LoadInst(unwrap(source),0);
li->setAtomic(order); li->setAtomic(from_rust(order));
li->setAlignment(alignment); li->setAlignment(alignment);
return wrap(unwrap(B)->Insert(li, Name)); return wrap(unwrap(B)->Insert(li, Name));
} }
extern "C" LLVMValueRef LLVMBuildAtomicStore(LLVMBuilderRef B, extern "C" LLVMValueRef LLVMRustBuildAtomicStore(LLVMBuilderRef B,
LLVMValueRef val, LLVMValueRef val,
LLVMValueRef target, LLVMValueRef target,
AtomicOrdering order, LLVMAtomicOrdering order,
unsigned alignment) { unsigned alignment) {
StoreInst* si = new StoreInst(unwrap(val),unwrap(target)); StoreInst* si = new StoreInst(unwrap(val),unwrap(target));
si->setAtomic(order); si->setAtomic(from_rust(order));
si->setAlignment(alignment); si->setAlignment(alignment);
return wrap(unwrap(B)->Insert(si)); return wrap(unwrap(B)->Insert(si));
} }
@ -207,54 +235,77 @@ extern "C" LLVMValueRef LLVMRustBuildAtomicCmpXchg(LLVMBuilderRef B,
LLVMValueRef target, LLVMValueRef target,
LLVMValueRef old, LLVMValueRef old,
LLVMValueRef source, LLVMValueRef source,
AtomicOrdering order, LLVMAtomicOrdering order,
AtomicOrdering failure_order, LLVMAtomicOrdering failure_order,
LLVMBool weak) { LLVMBool weak) {
AtomicCmpXchgInst* acxi = unwrap(B)->CreateAtomicCmpXchg(unwrap(target), AtomicCmpXchgInst* acxi = unwrap(B)->CreateAtomicCmpXchg(
unwrap(old), unwrap(target),
unwrap(source), unwrap(old),
order, unwrap(source),
failure_order); from_rust(order),
from_rust(failure_order));
acxi->setWeak(weak); acxi->setWeak(weak);
return wrap(acxi); return wrap(acxi);
} }
extern "C" LLVMValueRef LLVMBuildAtomicFence(LLVMBuilderRef B,
AtomicOrdering order, enum class LLVMRustSynchronizationScope {
SynchronizationScope scope) { Other,
return wrap(unwrap(B)->CreateFence(order, scope)); SingleThread,
CrossThread,
};
static SynchronizationScope
from_rust(LLVMRustSynchronizationScope scope)
{
switch (scope) {
case LLVMRustSynchronizationScope::SingleThread:
return SingleThread;
case LLVMRustSynchronizationScope::CrossThread:
return CrossThread;
default:
abort();
}
} }
extern "C" void LLVMSetDebug(int Enabled) { extern "C" LLVMValueRef LLVMRustBuildAtomicFence(
LLVMBuilderRef B,
LLVMAtomicOrdering order,
LLVMRustSynchronizationScope scope)
{
return wrap(unwrap(B)->CreateFence(from_rust(order), from_rust(scope)));
}
extern "C" void LLVMRustSetDebug(int Enabled) {
#ifndef NDEBUG #ifndef NDEBUG
DebugFlag = Enabled; DebugFlag = Enabled;
#endif #endif
} }
extern "C" LLVMValueRef LLVMInlineAsm(LLVMTypeRef Ty, extern "C" LLVMValueRef LLVMRustInlineAsm(LLVMTypeRef Ty,
char *AsmString, char *AsmString,
char *Constraints, char *Constraints,
LLVMBool HasSideEffects, LLVMBool HasSideEffects,
LLVMBool IsAlignStack, LLVMBool IsAlignStack,
unsigned Dialect) { unsigned Dialect) {
return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), AsmString, return wrap(InlineAsm::get(unwrap<FunctionType>(Ty), AsmString,
Constraints, HasSideEffects, Constraints, HasSideEffects,
IsAlignStack, (InlineAsm::AsmDialect) Dialect)); IsAlignStack, (InlineAsm::AsmDialect) Dialect));
} }
typedef DIBuilder* DIBuilderRef; typedef DIBuilder* LLVMRustDIBuilderRef;
typedef struct LLVMOpaqueMetadata *LLVMMetadataRef; typedef struct LLVMOpaqueMetadata *LLVMRustMetadataRef;
namespace llvm { namespace llvm {
DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMMetadataRef) DEFINE_ISA_CONVERSION_FUNCTIONS(Metadata, LLVMRustMetadataRef)
inline Metadata **unwrap(LLVMMetadataRef *Vals) { inline Metadata **unwrap(LLVMRustMetadataRef *Vals) {
return reinterpret_cast<Metadata**>(Vals); return reinterpret_cast<Metadata**>(Vals);
} }
} }
template<typename DIT> template<typename DIT>
DIT* unwrapDIptr(LLVMMetadataRef ref) { DIT* unwrapDIptr(LLVMRustMetadataRef ref) {
return (DIT*) (ref ? unwrap<MDNode>(ref) : NULL); return (DIT*) (ref ? unwrap<MDNode>(ref) : NULL);
} }
@ -266,11 +317,11 @@ extern "C" uint32_t LLVMRustDebugMetadataVersion() {
return DEBUG_METADATA_VERSION; return DEBUG_METADATA_VERSION;
} }
extern "C" uint32_t LLVMVersionMinor() { extern "C" uint32_t LLVMRustVersionMinor() {
return LLVM_VERSION_MINOR; return LLVM_VERSION_MINOR;
} }
extern "C" uint32_t LLVMVersionMajor() { extern "C" uint32_t LLVMRustVersionMajor() {
return LLVM_VERSION_MAJOR; return LLVM_VERSION_MAJOR;
} }
@ -280,20 +331,20 @@ extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
unwrap(M)->addModuleFlag(Module::Warning, name, value); unwrap(M)->addModuleFlag(Module::Warning, name, value);
} }
extern "C" DIBuilderRef LLVMDIBuilderCreate(LLVMModuleRef M) { extern "C" LLVMRustDIBuilderRef LLVMRustDIBuilderCreate(LLVMModuleRef M) {
return new DIBuilder(*unwrap(M)); return new DIBuilder(*unwrap(M));
} }
extern "C" void LLVMDIBuilderDispose(DIBuilderRef Builder) { extern "C" void LLVMRustDIBuilderDispose(LLVMRustDIBuilderRef Builder) {
delete Builder; delete Builder;
} }
extern "C" void LLVMDIBuilderFinalize(DIBuilderRef Builder) { extern "C" void LLVMRustDIBuilderFinalize(LLVMRustDIBuilderRef Builder) {
Builder->finalize(); Builder->finalize();
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateCompileUnit( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateCompileUnit(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
unsigned Lang, unsigned Lang,
const char* File, const char* File,
const char* Dir, const char* Dir,
@ -312,17 +363,17 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
SplitName)); SplitName));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateFile( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFile(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
const char* Filename, const char* Filename,
const char* Directory) { const char* Directory) {
return wrap(Builder->createFile(Filename, Directory)); return wrap(Builder->createFile(Filename, Directory));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateSubroutineType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateSubroutineType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef File, LLVMRustMetadataRef File,
LLVMMetadataRef ParameterTypes) { LLVMRustMetadataRef ParameterTypes) {
return wrap(Builder->createSubroutineType( return wrap(Builder->createSubroutineType(
#if LLVM_VERSION_MINOR == 7 #if LLVM_VERSION_MINOR == 7
unwrapDI<DIFile>(File), unwrapDI<DIFile>(File),
@ -330,22 +381,22 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(
DITypeRefArray(unwrap<MDTuple>(ParameterTypes)))); DITypeRefArray(unwrap<MDTuple>(ParameterTypes))));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateFunction(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
const char* Name, const char* Name,
const char* LinkageName, const char* LinkageName,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNo, unsigned LineNo,
LLVMMetadataRef Ty, LLVMRustMetadataRef Ty,
bool isLocalToUnit, bool isLocalToUnit,
bool isDefinition, bool isDefinition,
unsigned ScopeLine, unsigned ScopeLine,
unsigned Flags, unsigned Flags,
bool isOptimized, bool isOptimized,
LLVMValueRef Fn, LLVMValueRef Fn,
LLVMMetadataRef TParam, LLVMRustMetadataRef TParam,
LLVMMetadataRef Decl) { LLVMRustMetadataRef Decl) {
#if LLVM_VERSION_MINOR >= 8 #if LLVM_VERSION_MINOR >= 8
DITemplateParameterArray TParams = DITemplateParameterArray TParams =
DITemplateParameterArray(unwrap<MDTuple>(TParam)); DITemplateParameterArray(unwrap<MDTuple>(TParam));
@ -370,8 +421,8 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateFunction(
#endif #endif
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateBasicType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateBasicType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
const char* Name, const char* Name,
uint64_t SizeInBits, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t AlignInBits,
@ -381,9 +432,9 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateBasicType(
AlignInBits, Encoding)); AlignInBits, Encoding));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreatePointerType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreatePointerType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef PointeeTy, LLVMRustMetadataRef PointeeTy,
uint64_t SizeInBits, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t AlignInBits,
const char* Name) { const char* Name) {
@ -391,19 +442,19 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreatePointerType(
unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, Name)); unwrapDI<DIType>(PointeeTy), SizeInBits, AlignInBits, Name));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateStructType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStructType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
const char* Name, const char* Name,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNumber, unsigned LineNumber,
uint64_t SizeInBits, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t AlignInBits,
unsigned Flags, unsigned Flags,
LLVMMetadataRef DerivedFrom, LLVMRustMetadataRef DerivedFrom,
LLVMMetadataRef Elements, LLVMRustMetadataRef Elements,
unsigned RunTimeLang, unsigned RunTimeLang,
LLVMMetadataRef VTableHolder, LLVMRustMetadataRef VTableHolder,
const char *UniqueId) { const char *UniqueId) {
return wrap(Builder->createStructType( return wrap(Builder->createStructType(
unwrapDI<DIDescriptor>(Scope), unwrapDI<DIDescriptor>(Scope),
@ -421,17 +472,17 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStructType(
)); ));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateMemberType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateMemberType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
const char* Name, const char* Name,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNo, unsigned LineNo,
uint64_t SizeInBits, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t AlignInBits,
uint64_t OffsetInBits, uint64_t OffsetInBits,
unsigned Flags, unsigned Flags,
LLVMMetadataRef Ty) { LLVMRustMetadataRef Ty) {
return wrap(Builder->createMemberType( return wrap(Builder->createMemberType(
unwrapDI<DIDescriptor>(Scope), Name, unwrapDI<DIDescriptor>(Scope), Name,
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIFile>(File), LineNo,
@ -439,10 +490,10 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateMemberType(
unwrapDI<DIType>(Ty))); unwrapDI<DIType>(Ty)));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateLexicalBlock(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned Line, unsigned Line,
unsigned Col) { unsigned Col) {
return wrap(Builder->createLexicalBlock( return wrap(Builder->createLexicalBlock(
@ -451,17 +502,17 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
)); ));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateStaticVariable( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Context, LLVMRustMetadataRef Context,
const char* Name, const char* Name,
const char* LinkageName, const char* LinkageName,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNo, unsigned LineNo,
LLVMMetadataRef Ty, LLVMRustMetadataRef Ty,
bool isLocalToUnit, bool isLocalToUnit,
LLVMValueRef Val, LLVMValueRef Val,
LLVMMetadataRef Decl = NULL) { LLVMRustMetadataRef Decl = NULL) {
return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context), return wrap(Builder->createGlobalVariable(unwrapDI<DIDescriptor>(Context),
Name, Name,
LinkageName, LinkageName,
@ -473,14 +524,14 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateStaticVariable(
unwrapDIptr<MDNode>(Decl))); unwrapDIptr<MDNode>(Decl)));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVariable(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
unsigned Tag, unsigned Tag,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
const char* Name, const char* Name,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNo, unsigned LineNo,
LLVMMetadataRef Ty, LLVMRustMetadataRef Ty,
bool AlwaysPreserve, bool AlwaysPreserve,
unsigned Flags, unsigned Flags,
int64_t* AddrOps, int64_t* AddrOps,
@ -509,50 +560,50 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateVariable(
#endif #endif
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateArrayType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateArrayType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
uint64_t Size, uint64_t Size,
uint64_t AlignInBits, uint64_t AlignInBits,
LLVMMetadataRef Ty, LLVMRustMetadataRef Ty,
LLVMMetadataRef Subscripts) { LLVMRustMetadataRef Subscripts) {
return wrap(Builder->createArrayType(Size, AlignInBits, return wrap(Builder->createArrayType(Size, AlignInBits,
unwrapDI<DIType>(Ty), unwrapDI<DIType>(Ty),
DINodeArray(unwrapDI<MDTuple>(Subscripts)) DINodeArray(unwrapDI<MDTuple>(Subscripts))
)); ));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateVectorType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateVectorType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
uint64_t Size, uint64_t Size,
uint64_t AlignInBits, uint64_t AlignInBits,
LLVMMetadataRef Ty, LLVMRustMetadataRef Ty,
LLVMMetadataRef Subscripts) { LLVMRustMetadataRef Subscripts) {
return wrap(Builder->createVectorType(Size, AlignInBits, return wrap(Builder->createVectorType(Size, AlignInBits,
unwrapDI<DIType>(Ty), unwrapDI<DIType>(Ty),
DINodeArray(unwrapDI<MDTuple>(Subscripts)) DINodeArray(unwrapDI<MDTuple>(Subscripts))
)); ));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderGetOrCreateSubrange(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
int64_t Lo, int64_t Lo,
int64_t Count) { int64_t Count) {
return wrap(Builder->getOrCreateSubrange(Lo, Count)); return wrap(Builder->getOrCreateSubrange(Lo, Count));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderGetOrCreateArray( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderGetOrCreateArray(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef* Ptr, LLVMRustMetadataRef* Ptr,
unsigned Count) { unsigned Count) {
Metadata **DataValue = unwrap(Ptr); Metadata **DataValue = unwrap(Ptr);
return wrap(Builder->getOrCreateArray( return wrap(Builder->getOrCreateArray(
ArrayRef<Metadata*>(DataValue, Count)).get()); ArrayRef<Metadata*>(DataValue, Count)).get());
} }
extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd( extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMValueRef Val, LLVMValueRef Val,
LLVMMetadataRef VarInfo, LLVMRustMetadataRef VarInfo,
int64_t* AddrOps, int64_t* AddrOps,
unsigned AddrOpsCount, unsigned AddrOpsCount,
LLVMValueRef DL, LLVMValueRef DL,
@ -566,10 +617,10 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
unwrap(InsertAtEnd))); unwrap(InsertAtEnd)));
} }
extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareBefore( extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareBefore(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMValueRef Val, LLVMValueRef Val,
LLVMMetadataRef VarInfo, LLVMRustMetadataRef VarInfo,
int64_t* AddrOps, int64_t* AddrOps,
unsigned AddrOpsCount, unsigned AddrOpsCount,
LLVMValueRef DL, LLVMValueRef DL,
@ -583,24 +634,24 @@ extern "C" LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
unwrap<Instruction>(InsertBefore))); unwrap<Instruction>(InsertBefore)));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateEnumerator( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerator(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
const char* Name, const char* Name,
uint64_t Val) uint64_t Val)
{ {
return wrap(Builder->createEnumerator(Name, Val)); return wrap(Builder->createEnumerator(Name, Val));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateEnumerationType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateEnumerationType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
const char* Name, const char* Name,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNumber, unsigned LineNumber,
uint64_t SizeInBits, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t AlignInBits,
LLVMMetadataRef Elements, LLVMRustMetadataRef Elements,
LLVMMetadataRef ClassType) LLVMRustMetadataRef ClassType)
{ {
return wrap(Builder->createEnumerationType( return wrap(Builder->createEnumerationType(
unwrapDI<DIDescriptor>(Scope), unwrapDI<DIDescriptor>(Scope),
@ -613,16 +664,16 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
unwrapDI<DIType>(ClassType))); unwrapDI<DIType>(ClassType)));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateUnionType( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateUnionType(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
const char* Name, const char* Name,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNumber, unsigned LineNumber,
uint64_t SizeInBits, uint64_t SizeInBits,
uint64_t AlignInBits, uint64_t AlignInBits,
unsigned Flags, unsigned Flags,
LLVMMetadataRef Elements, LLVMRustMetadataRef Elements,
unsigned RunTimeLang, unsigned RunTimeLang,
const char* UniqueId) const char* UniqueId)
{ {
@ -640,12 +691,12 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateUnionType(
)); ));
} }
extern "C" LLVMMetadataRef LLVMDIBuilderCreateTemplateTypeParameter( extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateTemplateTypeParameter(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
const char* Name, const char* Name,
LLVMMetadataRef Ty, LLVMRustMetadataRef Ty,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNo, unsigned LineNo,
unsigned ColumnNo) unsigned ColumnNo)
{ {
@ -656,21 +707,11 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateTemplateTypeParameter(
)); ));
} }
extern "C" int64_t LLVMDIBuilderCreateOpDeref() extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateNameSpace(
{ LLVMRustDIBuilderRef Builder,
return dwarf::DW_OP_deref; LLVMRustMetadataRef Scope,
}
extern "C" int64_t LLVMDIBuilderCreateOpPlus()
{
return dwarf::DW_OP_plus;
}
extern "C" LLVMMetadataRef LLVMDIBuilderCreateNameSpace(
DIBuilderRef Builder,
LLVMMetadataRef Scope,
const char* Name, const char* Name,
LLVMMetadataRef File, LLVMRustMetadataRef File,
unsigned LineNo) unsigned LineNo)
{ {
return wrap(Builder->createNameSpace( return wrap(Builder->createNameSpace(
@ -680,22 +721,22 @@ extern "C" LLVMMetadataRef LLVMDIBuilderCreateNameSpace(
LineNo)); LineNo));
} }
extern "C" void LLVMDICompositeTypeSetTypeArray( extern "C" void LLVMRustDICompositeTypeSetTypeArray(
DIBuilderRef Builder, LLVMRustDIBuilderRef Builder,
LLVMMetadataRef CompositeType, LLVMRustMetadataRef CompositeType,
LLVMMetadataRef TypeArray) LLVMRustMetadataRef TypeArray)
{ {
DICompositeType *tmp = unwrapDI<DICompositeType>(CompositeType); DICompositeType *tmp = unwrapDI<DICompositeType>(CompositeType);
Builder->replaceArrays(tmp, DINodeArray(unwrap<MDTuple>(TypeArray))); Builder->replaceArrays(tmp, DINodeArray(unwrap<MDTuple>(TypeArray)));
} }
extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation( extern "C" LLVMValueRef LLVMRustDIBuilderCreateDebugLocation(
LLVMContextRef Context, LLVMContextRef Context,
unsigned Line, unsigned Line,
unsigned Column, unsigned Column,
LLVMMetadataRef Scope, LLVMRustMetadataRef Scope,
LLVMMetadataRef InlinedAt) { LLVMRustMetadataRef InlinedAt)
{
LLVMContext& context = *unwrap(Context); LLVMContext& context = *unwrap(Context);
DebugLoc debug_loc = DebugLoc::get(Line, DebugLoc debug_loc = DebugLoc::get(Line,
@ -706,12 +747,22 @@ extern "C" LLVMValueRef LLVMDIBuilderCreateDebugLocation(
return wrap(MetadataAsValue::get(context, debug_loc.getAsMDNode())); return wrap(MetadataAsValue::get(context, debug_loc.getAsMDNode()));
} }
extern "C" void LLVMWriteTypeToString(LLVMTypeRef Type, RustStringRef str) { extern "C" int64_t LLVMRustDIBuilderCreateOpDeref()
{
return dwarf::DW_OP_deref;
}
extern "C" int64_t LLVMRustDIBuilderCreateOpPlus()
{
return dwarf::DW_OP_plus;
}
extern "C" void LLVMRustWriteTypeToString(LLVMTypeRef Type, RustStringRef str) {
raw_rust_string_ostream os(str); raw_rust_string_ostream os(str);
unwrap<llvm::Type>(Type)->print(os); unwrap<llvm::Type>(Type)->print(os);
} }
extern "C" void LLVMWriteValueToString(LLVMValueRef Value, RustStringRef str) { extern "C" void LLVMRustWriteValueToString(LLVMValueRef Value, RustStringRef str) {
raw_rust_string_ostream os(str); raw_rust_string_ostream os(str);
os << "("; os << "(";
unwrap<llvm::Value>(Value)->getType()->print(os); unwrap<llvm::Value>(Value)->getType()->print(os);
@ -746,11 +797,33 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
return true; return true;
} }
enum class LLVMRustDLLStorageClassTypes {
Other,
Default,
DllImport,
DllExport,
};
static GlobalValue::DLLStorageClassTypes
from_rust(LLVMRustDLLStorageClassTypes Class)
{
switch (Class) {
case LLVMRustDLLStorageClassTypes::Default:
return GlobalValue::DefaultStorageClass;
case LLVMRustDLLStorageClassTypes::DllImport:
return GlobalValue::DLLImportStorageClass;
case LLVMRustDLLStorageClassTypes::DllExport:
return GlobalValue::DLLExportStorageClass;
default:
abort();
}
}
extern "C" void extern "C" void
LLVMRustSetDLLStorageClass(LLVMValueRef Value, LLVMRustSetDLLStorageClass(LLVMValueRef Value,
GlobalValue::DLLStorageClassTypes Class) { LLVMRustDLLStorageClassTypes Class) {
GlobalValue *V = unwrap<GlobalValue>(Value); GlobalValue *V = unwrap<GlobalValue>(Value);
V->setDLLStorageClass(Class); V->setDLLStorageClass(from_rust(Class));
} }
// Note that the two following functions look quite similar to the // Note that the two following functions look quite similar to the
@ -768,7 +841,7 @@ inline section_iterator *unwrap(LLVMSectionIteratorRef SI) {
return reinterpret_cast<section_iterator*>(SI); return reinterpret_cast<section_iterator*>(SI);
} }
extern "C" int extern "C" size_t
LLVMRustGetSectionName(LLVMSectionIteratorRef SI, const char **ptr) { LLVMRustGetSectionName(LLVMSectionIteratorRef SI, const char **ptr) {
StringRef ret; StringRef ret;
if (std::error_code ec = (*unwrap(SI))->getName(ret)) if (std::error_code ec = (*unwrap(SI))->getName(ret))
@ -787,13 +860,13 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Twine, LLVMTwineRef)
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DebugLoc, LLVMDebugLocRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(DebugLoc, LLVMDebugLocRef)
extern "C" void extern "C" void
LLVMWriteTwineToString(LLVMTwineRef T, RustStringRef str) { LLVMRustWriteTwineToString(LLVMTwineRef T, RustStringRef str) {
raw_rust_string_ostream os(str); raw_rust_string_ostream os(str);
unwrap(T)->print(os); unwrap(T)->print(os);
} }
extern "C" void extern "C" void
LLVMUnpackOptimizationDiagnostic( LLVMRustUnpackOptimizationDiagnostic(
LLVMDiagnosticInfoRef di, LLVMDiagnosticInfoRef di,
const char **pass_name_out, const char **pass_name_out,
LLVMValueRef *function_out, LLVMValueRef *function_out,
@ -811,7 +884,7 @@ LLVMUnpackOptimizationDiagnostic(
} }
extern "C" void extern "C" void
LLVMUnpackInlineAsmDiagnostic( LLVMRustUnpackInlineAsmDiagnostic(
LLVMDiagnosticInfoRef di, LLVMDiagnosticInfoRef di,
unsigned *cookie_out, unsigned *cookie_out,
LLVMTwineRef *message_out, LLVMTwineRef *message_out,
@ -826,17 +899,68 @@ LLVMUnpackInlineAsmDiagnostic(
*instruction_out = wrap(ia->getInstruction()); *instruction_out = wrap(ia->getInstruction());
} }
extern "C" void LLVMWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef di, RustStringRef str) { extern "C" void LLVMRustWriteDiagnosticInfoToString(LLVMDiagnosticInfoRef di, RustStringRef str) {
raw_rust_string_ostream os(str); raw_rust_string_ostream os(str);
DiagnosticPrinterRawOStream dp(os); DiagnosticPrinterRawOStream dp(os);
unwrap(di)->print(dp); unwrap(di)->print(dp);
} }
extern "C" int LLVMGetDiagInfoKind(LLVMDiagnosticInfoRef di) { enum class LLVMRustDiagnosticKind {
return unwrap(di)->getKind(); Other,
InlineAsm,
StackSize,
DebugMetadataVersion,
SampleProfile,
OptimizationRemark,
OptimizationRemarkMissed,
OptimizationRemarkAnalysis,
OptimizationRemarkAnalysisFPCommute,
OptimizationRemarkAnalysisAliasing,
OptimizationRemarkOther,
OptimizationFailure,
};
static LLVMRustDiagnosticKind
to_rust(DiagnosticKind kind)
{
switch (kind) {
case DK_InlineAsm:
return LLVMRustDiagnosticKind::InlineAsm;
case DK_StackSize:
return LLVMRustDiagnosticKind::StackSize;
case DK_DebugMetadataVersion:
return LLVMRustDiagnosticKind::DebugMetadataVersion;
case DK_SampleProfile:
return LLVMRustDiagnosticKind::SampleProfile;
case DK_OptimizationRemark:
return LLVMRustDiagnosticKind::OptimizationRemark;
case DK_OptimizationRemarkMissed:
return LLVMRustDiagnosticKind::OptimizationRemarkMissed;
case DK_OptimizationRemarkAnalysis:
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysis;
#if LLVM_VERSION_MINOR >= 8
case DK_OptimizationRemarkAnalysisFPCommute:
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisFPCommute;
case DK_OptimizationRemarkAnalysisAliasing:
return LLVMRustDiagnosticKind::OptimizationRemarkAnalysisAliasing;
#endif
default:
#if LLVM_VERSION_MINOR >= 9
return (kind >= DK_FirstRemark && kind <= DK_LastRemark) ?
LLVMRustDiagnosticKind::OptimizationRemarkOther :
LLVMRustDiagnosticKind::Other;
#else
return LLVMRustDiagnosticKind::Other;
#endif
}
} }
extern "C" void LLVMWriteDebugLocToString(
extern "C" LLVMRustDiagnosticKind LLVMRustGetDiagInfoKind(LLVMDiagnosticInfoRef di) {
return to_rust((DiagnosticKind) unwrap(di)->getKind());
}
extern "C" void LLVMRustWriteDebugLocToString(
LLVMContextRef C, LLVMContextRef C,
LLVMDebugLocRef dl, LLVMDebugLocRef dl,
RustStringRef str) RustStringRef str)
@ -847,7 +971,8 @@ extern "C" void LLVMWriteDebugLocToString(
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SMDiagnostic, LLVMSMDiagnosticRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(SMDiagnostic, LLVMSMDiagnosticRef)
extern "C" void LLVMSetInlineAsmDiagnosticHandler( // FIXME(type-audit): assume this function-pointer type does not change
extern "C" void LLVMRustSetInlineAsmDiagnosticHandler(
LLVMContextRef C, LLVMContextRef C,
LLVMContext::InlineAsmDiagHandlerTy H, LLVMContext::InlineAsmDiagHandlerTy H,
void *CX) void *CX)
@ -855,7 +980,8 @@ extern "C" void LLVMSetInlineAsmDiagnosticHandler(
unwrap(C)->setInlineAsmDiagnosticHandler(H, CX); unwrap(C)->setInlineAsmDiagnosticHandler(H, CX);
} }
extern "C" void LLVMWriteSMDiagnosticToString(LLVMSMDiagnosticRef d, RustStringRef str) { extern "C" void LLVMRustWriteSMDiagnosticToString(LLVMSMDiagnosticRef d,
RustStringRef str) {
raw_rust_string_ostream os(str); raw_rust_string_ostream os(str);
unwrap(d)->print("", os); unwrap(d)->print("", os);
} }
@ -902,6 +1028,8 @@ LLVMRustBuildCleanupRet(LLVMBuilderRef Builder,
#endif #endif
} }
// FIXME: to here.
extern "C" LLVMValueRef extern "C" LLVMValueRef
LLVMRustBuildCatchPad(LLVMBuilderRef Builder, LLVMRustBuildCatchPad(LLVMBuilderRef Builder,
LLVMValueRef ParentPad, LLVMValueRef ParentPad,