Skip to content

Commit

Permalink
Finish up Type refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
James Miller committed Jun 22, 2013
1 parent 57a7537 commit 81cf72c
Show file tree
Hide file tree
Showing 30 changed files with 517 additions and 886 deletions.
8 changes: 4 additions & 4 deletions src/librustc/back/upcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ pub struct Upcalls {

macro_rules! upcall (
(fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
let fn_ty = Type::func([ $($arg),* ], $ret);
let fn_ty = Type::func([ $($arg),* ], &$ret);
base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty)
});
(nothrow fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
let fn_ty = Type::func([ $($arg),* ], $ret);
let fn_ty = Type::func([ $($arg),* ], &$ret);
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
base::set_no_unwind(decl);
decl
});
(nothrow fn $name:ident -> $ret:expr) => ({
let fn_ty = Type::func([], $ret);
let fn_ty = Type::func([], &$ret);
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
base::set_no_unwind(decl);
decl
})
)

pub fn declare_upcalls(targ_cfg: @session::config, llmod: ModuleRef) -> @Upcalls {
let opaque_ptr = Type::i8().to_ptr();
let opaque_ptr = Type::i8().ptr_to();
let int_ty = Type::int(targ_cfg.arch);

@Upcalls {
Expand Down
47 changes: 12 additions & 35 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ impl TypeNames {
}

pub fn find_name<'r>(&'r self, ty: &Type) -> Option<&'r str> {
match self.type_names.find(ty.to_ref()) {
match self.type_names.find(&ty.to_ref()) {
Some(a) => Some(a.slice(0, a.len())),
None => None
}
Expand All @@ -2151,14 +2151,14 @@ impl TypeNames {
self.named_types.find_equiv(&s).map_consume(|x| Type::from_ref(*x))
}

pub fn type_to_str(&self, ty: TypeRef) -> ~str {
pub fn type_to_str(&self, ty: Type) -> ~str {
match self.find_name(&ty) {
option::Some(name) => return name.to_owned(),
None => ()
}

unsafe {
let kind = llvm::LLVMGetTypeKind(ty);
let kind = ty.kind();

match kind {
Void => ~"Void",
Expand All @@ -2172,31 +2172,28 @@ impl TypeNames {
Metadata => ~"Metadata",
X86_MMX => ~"X86_MMAX",
Integer => {
fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty) as int)
fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
}
Function => {
let out_ty = llvm::LLVMGetReturnType(ty);
let n_args = llvm::LLVMCountParamTypes(ty) as uint;
let args = vec::from_elem(n_args, 0 as TypeRef);
llvm::LLVMGetParamTypes(ty, vec::raw::to_ptr(args));

let out_ty = ty.return_type();
let args = ty.func_params();
let args = args.map(|&ty| self.type_to_str(ty)).connect(", ");
let out_ty = self.type_to_str(out_ty);
fmt!("fn(%s) -> %s", args, out_ty)
}
Struct => {
let tys = struct_tys(ty);
let tys = ty.field_types();
let tys = tys.map(|&ty| self.type_to_str(ty)).connect(", ");
fmt!("{%s}", tys)
}
Array => {
let el_ty = llvm::LLVMGetElementType(ty);
let el_ty = ty.element_type();
let el_ty = self.type_to_str(el_ty);
let len = llvm::LLVMGetArrayLength(ty) as uint;
let len = ty.array_length();
fmt!("[%s x %u]", el_ty, len)
}
Pointer => {
let el_ty = llvm::LLVMGetElementType(ty);
let el_ty = ty.element_type();
let el_ty = self.type_to_str(el_ty);
fmt!("*%s", el_ty)
}
Expand All @@ -2207,32 +2204,12 @@ impl TypeNames {

pub fn val_to_str(&self, val: ValueRef) -> ~str {
unsafe {
self.type_to_str(llvm::LLVMTypeOf(val))
let ty = Type::from_ref(llvm::LLVMTypeOf(val));
self.type_to_str(ty)
}
}
}

pub fn float_width(llt: TypeRef) -> uint {
unsafe {
return match llvm::LLVMGetTypeKind(llt) as int {
1 => 32u,
2 => 64u,
3 => 80u,
4 | 5 => 128u,
_ => fail!("llvm_float_width called on a non-float type")
};
}
}

pub fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] {
unsafe {
let args = vec::from_elem(llvm::LLVMCountParamTypes(fn_ty) as uint,
0 as TypeRef);
llvm::LLVMGetParamTypes(fn_ty, vec::raw::to_ptr(args));
return args;
}
}


/* Memory-managed interface to target data. */

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ pub fn extract_vec_elems(bcx: block,
Sub(bcx, count,
C_int(bcx.ccx(), (elem_count - i) as int))])
}
_ => unsafe { llvm::LLVMGetUndef(vt.llunit_ty) }
_ => unsafe { llvm::LLVMGetUndef(vt.llunit_ty.to_ref()) }
}
};
if slice.is_some() {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/middle/trans/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ use middle::ty;
use syntax::ast;
use util::ppaux::ty_to_str;

use middle::trans::type_::Type;


/// Representations.
pub enum Repr {
Expand Down Expand Up @@ -260,10 +262,8 @@ fn generic_fields_of(cx: &mut CrateContext, r: &Repr, sizing: bool) -> ~[Type] {
let most_aligned = most_aligned.get();
let padding = largest_size - most_aligned.size;

assert!(padding >= 0);

struct_llfields(cx, most_aligned, sizing)
+ [Type::array(Type::i8(), padding /*bad*/as uint)]
+ [Type::array(&Type::i8(), padding)]
}
}
}
Expand Down Expand Up @@ -439,7 +439,7 @@ pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
// The unit-like case might have a nonzero number of unit-like fields.
// (e.g., Result or Either with () as one side.)
let ty = type_of::type_of(bcx.ccx(), nullfields[ix]);
assert_eq!(machine::llsize_of_alloc(bcx.ccx(), llty), 0);
assert_eq!(machine::llsize_of_alloc(bcx.ccx(), ty), 0);
// The contents of memory at this pointer can't matter, but use
// the value that's "reasonable" in case of pointer comparison.
PointerCast(bcx, val, ty.ptr_to())
Expand All @@ -457,7 +457,7 @@ fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
type_of::type_of(ccx, ty)
};
let real_ty = Type::struct_(fields, st.packed);
PointerCast(bcx, val, real_llty.to_ptr().to_ref())
PointerCast(bcx, val, real_ty.ptr_to())
} else {
val
};
Expand Down Expand Up @@ -572,7 +572,7 @@ fn build_const_struct(ccx: &mut CrateContext, st: &Struct, vals: &[ValueRef])
}

fn padding(size: u64) -> ValueRef {
C_undef(Type::array(Type::i8(), size).to_ref())
C_undef(Type::array(&Type::i8(), size))
}

// XXX this utility routine should be somewhere more general
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/trans/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use middle::trans::callee;
use middle::trans::common::*;
use middle::ty;

use middle::trans::type_::Type;

use core::str;
use syntax::ast;

Expand Down
Loading

0 comments on commit 81cf72c

Please sign in to comment.