]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_codegen_llvm/common.rs
Generalized base.rs#call_memcpy and everything that it uses
[rust.git] / src / librustc_codegen_llvm / common.rs
index c9b464fd8f3dd48482fa3a307a3f55b0c0bc7856..66f14322fc6725b65c7ca275d9d2a418be4d54d1 100644 (file)
 use declare;
 use type_::Type;
 use type_of::LayoutLlvmExt;
-use value::Value;
+use value::{Value, ValueTrait};
 
 use rustc::ty::{self, Ty, TyCtxt};
 use rustc::ty::layout::{HasDataLayout, LayoutOf};
 use rustc::hir;
+use traits::BuilderMethods;
 
 use libc::{c_uint, c_char};
 
@@ -110,9 +111,9 @@ pub fn bundle(&self) -> &OperandBundleDef<'ll> {
     }
 }
 
-pub fn val_ty(v: &'ll Value) -> &'ll Type {
+pub fn val_ty<Value : ?Sized>(v: &'ll Value) -> &'ll Type where Value : ValueTrait {
     unsafe {
-        llvm::LLVMTypeOf(v)
+        llvm::LLVMTypeOf(v.to_llvm())
     }
 }
 
@@ -123,21 +124,21 @@ pub fn C_null(t: &'ll Type) -> &'ll Value {
     }
 }
 
-pub fn C_undef(t: &'ll Type) -> &'ll Value {
+pub fn C_undef<Value : ?Sized>(t: &'ll Type) -> &'ll Value where Value : ValueTrait {
     unsafe {
-        llvm::LLVMGetUndef(t)
+        Value::of_llvm(llvm::LLVMGetUndef(t))
     }
 }
 
-pub fn C_int(t: &'ll Type, i: i64) -> &'ll Value {
+pub fn C_int<Value : ?Sized>(t: &'ll Type, i: i64) -> &'ll Value where Value : ValueTrait {
     unsafe {
-        llvm::LLVMConstInt(t, i as u64, True)
+        Value::of_llvm(llvm::LLVMConstInt(t, i as u64, True))
     }
 }
 
-pub fn C_uint(t: &'ll Type, i: u64) -> &'ll Value {
+pub fn C_uint<Value : ?Sized>(t: &'ll Type, i: u64) -> &'ll Value where Value : ValueTrait {
     unsafe {
-        llvm::LLVMConstInt(t, i, False)
+        Value::of_llvm(llvm::LLVMConstInt(t, i, False))
     }
 }
 
@@ -148,11 +149,17 @@ pub fn C_uint_big(t: &'ll Type, u: u128) -> &'ll Value {
     }
 }
 
-pub fn C_bool(cx: &CodegenCx<'ll, '_>, val: bool) -> &'ll Value {
+pub fn C_bool<Value : ?Sized>(
+    cx: &CodegenCx<'ll, '_, &'ll Value>,
+    val: bool
+) -> &'ll Value where Value : ValueTrait {
     C_uint(Type::i1(cx), val as u64)
 }
 
-pub fn C_i32(cx: &CodegenCx<'ll, '_>, i: i32) -> &'ll Value {
+pub fn C_i32<Value : ?Sized>(
+    cx: &CodegenCx<'ll, '_, &'ll Value>,
+    i: i32
+) -> &'ll Value where Value : ValueTrait {
     C_int(Type::i32(cx), i as i64)
 }
 
@@ -164,7 +171,10 @@ pub fn C_u64(cx: &CodegenCx<'ll, '_>, i: u64) -> &'ll Value {
     C_uint(Type::i64(cx), i)
 }
 
-pub fn C_usize(cx: &CodegenCx<'ll, '_>, i: u64) -> &'ll Value {
+pub fn C_usize<Value : ?Sized>(
+    cx: &CodegenCx<'ll, '_, &'ll Value>,
+    i: u64
+) -> &'ll Value where Value : ValueTrait {
     let bit_size = cx.data_layout().pointer_size.bits();
     if bit_size < 64 {
         // make sure it doesn't overflow