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
This commit is contained in:
Denis Merigoux 2018-08-07 17:14:40 +02:00 committed by Eduard-Mihai Burtescu
parent 83b2152ce4
commit 34c5dc045f
28 changed files with 793 additions and 314 deletions

View file

@ -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