about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm/common.rs
diff options
context:
space:
mode:
authorDenis Merigoux <denis.merigoux@gmail.com>2018-08-07 17:14:40 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2018-11-16 14:11:09 +0200
commit34c5dc045f2ee53b3bc8e5cece75e6ece96389e6 (patch)
tree9c536bb2727ff84a356346f37163b395099603ff /src/librustc_codegen_llvm/common.rs
parent83b2152ce40ed4f1340ed541236609511fc7e89c (diff)
downloadrust-34c5dc045f2ee53b3bc8e5cece75e6ece96389e6.tar.gz
rust-34c5dc045f2ee53b3bc8e5cece75e6ece96389e6.zip
Generalized base.rs#call_memcpy and everything that it uses
Generalized operand.rs#nontemporal_store and fixed tidy issues

Generalized operand.rs#nontemporal_store's implem even more
With a BuilderMethod trait implemented by Builder for LLVM

Cleaned builder.rs : no more code duplication, no more ValueTrait

Full traitification of builder.rs
Diffstat (limited to 'src/librustc_codegen_llvm/common.rs')
-rw-r--r--src/librustc_codegen_llvm/common.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs
index c9b464fd8f3..66f14322fc6 100644
--- a/src/librustc_codegen_llvm/common.rs
+++ b/src/librustc_codegen_llvm/common.rs
@@ -23,11 +23,12 @@ use consts;
 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 @@ impl Funclet<'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