X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_codegen_llvm%2Ftype_.rs;h=44162ef0a50427ef070b976fc49ce17fbbebcbf0;hb=34c5dc045f2ee53b3bc8e5cece75e6ece96389e6;hp=6fb78fe4aa5a4124c590b755153451f3a4fab0c0;hpb=83b2152ce40ed4f1340ed541236609511fc7e89c;p=rust.git diff --git a/src/librustc_codegen_llvm/type_.rs b/src/librustc_codegen_llvm/type_.rs index 6fb78fe4aa5..44162ef0a50 100644 --- a/src/librustc_codegen_llvm/type_.rs +++ b/src/librustc_codegen_llvm/type_.rs @@ -16,6 +16,7 @@ use llvm::{Bool, False, True, TypeKind}; use context::CodegenCx; +use value::{Value, ValueTrait}; use syntax::ast; use rustc::ty::layout::{self, Align, Size}; @@ -40,107 +41,143 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } impl Type { - pub fn void(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn void( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMVoidTypeInContext(cx.llcx) } } - pub fn metadata(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn metadata( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMRustMetadataTypeInContext(cx.llcx) } } - pub fn i1(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn i1( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMInt1TypeInContext(cx.llcx) } } - pub fn i8(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn i8( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMInt8TypeInContext(cx.llcx) } } - pub fn i8_llcx(llcx: &llvm::Context) -> &Type { + pub fn i8_llcx(llcx: &llvm::Context) -> &Type where Value : ValueTrait { unsafe { llvm::LLVMInt8TypeInContext(llcx) } } - pub fn i16(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn i16( + cx: &CodegenCx<'ll, '_, &'ll Value>) -> &'ll Type where Value : ValueTrait { unsafe { + llvm::LLVMInt16TypeInContext(cx.llcx) } } - pub fn i32(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn i32( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMInt32TypeInContext(cx.llcx) } } - pub fn i64(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn i64( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMInt64TypeInContext(cx.llcx) } } - pub fn i128(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn i128( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMIntTypeInContext(cx.llcx, 128) } } // Creates an integer type with the given number of bits, e.g. i24 - pub fn ix(cx: &CodegenCx<'ll, '_>, num_bits: u64) -> &'ll Type { + pub fn ix( + cx: &CodegenCx<'ll, '_, &'ll Value>, + num_bits: u64 + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMIntTypeInContext(cx.llcx, num_bits as c_uint) } } // Creates an integer type with the given number of bits, e.g. i24 - pub fn ix_llcx(llcx: &llvm::Context, num_bits: u64) -> &Type { + pub fn ix_llcx( + llcx: &llvm::Context, + num_bits: u64 + ) -> &Type where Value : ValueTrait { unsafe { llvm::LLVMIntTypeInContext(llcx, num_bits as c_uint) } } - pub fn f32(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn f32( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMFloatTypeInContext(cx.llcx) } } - pub fn f64(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn f64( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMDoubleTypeInContext(cx.llcx) } } - pub fn bool(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn bool( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { Type::i8(cx) } - pub fn char(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn char( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { Type::i32(cx) } - pub fn i8p(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn i8p( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { Type::i8(cx).ptr_to() } - pub fn i8p_llcx(llcx: &llvm::Context) -> &Type { - Type::i8_llcx(llcx).ptr_to() + pub fn i8p_llcx(llcx: &llvm::Context) -> &Type where Value : ValueTrait { + Type::i8_llcx::(llcx).ptr_to() } - pub fn isize(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn isize( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { cx.isize_ty } - pub fn c_int(cx: &CodegenCx<'ll, '_>) -> &'ll Type { + pub fn c_int( + cx: &CodegenCx<'ll, '_, &'ll Value> + ) -> &'ll Type where Value : ValueTrait { match &cx.tcx.sess.target.target.target_c_int_width[..] { "16" => Type::i16(cx), "32" => Type::i32(cx), @@ -149,7 +186,10 @@ pub fn c_int(cx: &CodegenCx<'ll, '_>) -> &'ll Type { } } - pub fn int_from_ty(cx: &CodegenCx<'ll, '_>, t: ast::IntTy) -> &'ll Type { + pub fn int_from_ty( + cx: &CodegenCx<'ll, '_, &'ll Value>, + t: ast::IntTy + ) -> &'ll Type where Value : ValueTrait { match t { ast::IntTy::Isize => cx.isize_ty, ast::IntTy::I8 => Type::i8(cx), @@ -160,7 +200,10 @@ pub fn int_from_ty(cx: &CodegenCx<'ll, '_>, t: ast::IntTy) -> &'ll Type { } } - pub fn uint_from_ty(cx: &CodegenCx<'ll, '_>, t: ast::UintTy) -> &'ll Type { + pub fn uint_from_ty( + cx: &CodegenCx<'ll, '_, &'ll Value>, + t: ast::UintTy + ) -> &'ll Type where Value : ValueTrait { match t { ast::UintTy::Usize => cx.isize_ty, ast::UintTy::U8 => Type::i8(cx), @@ -171,28 +214,41 @@ pub fn uint_from_ty(cx: &CodegenCx<'ll, '_>, t: ast::UintTy) -> &'ll Type { } } - pub fn float_from_ty(cx: &CodegenCx<'ll, '_>, t: ast::FloatTy) -> &'ll Type { + pub fn float_from_ty( + cx: &CodegenCx<'ll, '_, &'ll Value>, + t: ast::FloatTy + ) -> &'ll Type where Value : ValueTrait { match t { ast::FloatTy::F32 => Type::f32(cx), ast::FloatTy::F64 => Type::f64(cx), } } - pub fn func(args: &[&'ll Type], ret: &'ll Type) -> &'ll Type { + pub fn func( + args: &[&'ll Type], + ret: &'ll Type + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, False) } } - pub fn variadic_func(args: &[&'ll Type], ret: &'ll Type) -> &'ll Type { + pub fn variadic_func( + args: &[&'ll Type], + ret: &'ll Type + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMFunctionType(ret, args.as_ptr(), args.len() as c_uint, True) } } - pub fn struct_(cx: &CodegenCx<'ll, '_>, els: &[&'ll Type], packed: bool) -> &'ll Type { + pub fn struct_( + cx: &CodegenCx<'ll, '_, &'ll Value>, + els: &[&'ll Type], + packed: bool + ) -> &'ll Type where Value : ValueTrait { unsafe { llvm::LLVMStructTypeInContext(cx.llcx, els.as_ptr(), els.len() as c_uint, @@ -208,13 +264,13 @@ pub fn named_struct(cx: &CodegenCx<'ll, '_>, name: &str) -> &'ll Type { } - pub fn array(ty: &Type, len: u64) -> &Type { + pub fn array(ty: &Type, len: u64) -> &Type where Value : ValueTrait { unsafe { llvm::LLVMRustArrayType(ty, len) } } - pub fn vector(ty: &Type, len: u64) -> &Type { + pub fn vector(ty: &Type, len: u64) -> &Type where Value : ValueTrait { unsafe { llvm::LLVMVectorType(ty, len as c_uint) } @@ -307,7 +363,7 @@ pub fn padding_filler(cx: &CodegenCx<'ll, '_>, size: Size, align: Align) -> &'ll let size = size.bytes(); let unit_size = unit.size().bytes(); assert_eq!(size % unit_size, 0); - Type::array(Type::from_integer(cx, unit), size / unit_size) + Type::array::(Type::from_integer(cx, unit), size / unit_size) } pub fn x86_mmx(cx: &CodegenCx<'ll, '_>) -> &'ll Type {