Skip to content

Commit 81cf72c

Browse files
author
James Miller
committed
Finish up Type refactoring
1 parent 57a7537 commit 81cf72c

30 files changed

+517
-886
lines changed

src/librustc/back/upcall.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ pub struct Upcalls {
2424

2525
macro_rules! upcall (
2626
(fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
27-
let fn_ty = Type::func([ $($arg),* ], $ret);
27+
let fn_ty = Type::func([ $($arg),* ], &$ret);
2828
base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty)
2929
});
3030
(nothrow fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
31-
let fn_ty = Type::func([ $($arg),* ], $ret);
31+
let fn_ty = Type::func([ $($arg),* ], &$ret);
3232
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
3333
base::set_no_unwind(decl);
3434
decl
3535
});
3636
(nothrow fn $name:ident -> $ret:expr) => ({
37-
let fn_ty = Type::func([], $ret);
37+
let fn_ty = Type::func([], &$ret);
3838
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
3939
base::set_no_unwind(decl);
4040
decl
4141
})
4242
)
4343

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

4848
@Upcalls {

src/librustc/lib/llvm.rs

+12-35
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ impl TypeNames {
21412141
}
21422142

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

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

21602160
unsafe {
2161-
let kind = llvm::LLVMGetTypeKind(ty);
2161+
let kind = ty.kind();
21622162

21632163
match kind {
21642164
Void => ~"Void",
@@ -2172,31 +2172,28 @@ impl TypeNames {
21722172
Metadata => ~"Metadata",
21732173
X86_MMX => ~"X86_MMAX",
21742174
Integer => {
2175-
fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty) as int)
2175+
fmt!("i%d", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
21762176
}
21772177
Function => {
2178-
let out_ty = llvm::LLVMGetReturnType(ty);
2179-
let n_args = llvm::LLVMCountParamTypes(ty) as uint;
2180-
let args = vec::from_elem(n_args, 0 as TypeRef);
2181-
llvm::LLVMGetParamTypes(ty, vec::raw::to_ptr(args));
2182-
2178+
let out_ty = ty.return_type();
2179+
let args = ty.func_params();
21832180
let args = args.map(|&ty| self.type_to_str(ty)).connect(", ");
21842181
let out_ty = self.type_to_str(out_ty);
21852182
fmt!("fn(%s) -> %s", args, out_ty)
21862183
}
21872184
Struct => {
2188-
let tys = struct_tys(ty);
2185+
let tys = ty.field_types();
21892186
let tys = tys.map(|&ty| self.type_to_str(ty)).connect(", ");
21902187
fmt!("{%s}", tys)
21912188
}
21922189
Array => {
2193-
let el_ty = llvm::LLVMGetElementType(ty);
2190+
let el_ty = ty.element_type();
21942191
let el_ty = self.type_to_str(el_ty);
2195-
let len = llvm::LLVMGetArrayLength(ty) as uint;
2192+
let len = ty.array_length();
21962193
fmt!("[%s x %u]", el_ty, len)
21972194
}
21982195
Pointer => {
2199-
let el_ty = llvm::LLVMGetElementType(ty);
2196+
let el_ty = ty.element_type();
22002197
let el_ty = self.type_to_str(el_ty);
22012198
fmt!("*%s", el_ty)
22022199
}
@@ -2207,32 +2204,12 @@ impl TypeNames {
22072204

22082205
pub fn val_to_str(&self, val: ValueRef) -> ~str {
22092206
unsafe {
2210-
self.type_to_str(llvm::LLVMTypeOf(val))
2207+
let ty = Type::from_ref(llvm::LLVMTypeOf(val));
2208+
self.type_to_str(ty)
22112209
}
22122210
}
22132211
}
22142212

2215-
pub fn float_width(llt: TypeRef) -> uint {
2216-
unsafe {
2217-
return match llvm::LLVMGetTypeKind(llt) as int {
2218-
1 => 32u,
2219-
2 => 64u,
2220-
3 => 80u,
2221-
4 | 5 => 128u,
2222-
_ => fail!("llvm_float_width called on a non-float type")
2223-
};
2224-
}
2225-
}
2226-
2227-
pub fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] {
2228-
unsafe {
2229-
let args = vec::from_elem(llvm::LLVMCountParamTypes(fn_ty) as uint,
2230-
0 as TypeRef);
2231-
llvm::LLVMGetParamTypes(fn_ty, vec::raw::to_ptr(args));
2232-
return args;
2233-
}
2234-
}
2235-
22362213

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

src/librustc/middle/trans/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ pub fn extract_vec_elems(bcx: block,
911911
Sub(bcx, count,
912912
C_int(bcx.ccx(), (elem_count - i) as int))])
913913
}
914-
_ => unsafe { llvm::LLVMGetUndef(vt.llunit_ty) }
914+
_ => unsafe { llvm::LLVMGetUndef(vt.llunit_ty.to_ref()) }
915915
}
916916
};
917917
if slice.is_some() {

src/librustc/middle/trans/adt.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ use middle::ty;
5959
use syntax::ast;
6060
use util::ppaux::ty_to_str;
6161

62+
use middle::trans::type_::Type;
63+
6264

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

263-
assert!(padding >= 0);
264-
265265
struct_llfields(cx, most_aligned, sizing)
266-
+ [Type::array(Type::i8(), padding /*bad*/as uint)]
266+
+ [Type::array(&Type::i8(), padding)]
267267
}
268268
}
269269
}
@@ -439,7 +439,7 @@ pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
439439
// The unit-like case might have a nonzero number of unit-like fields.
440440
// (e.g., Result or Either with () as one side.)
441441
let ty = type_of::type_of(bcx.ccx(), nullfields[ix]);
442-
assert_eq!(machine::llsize_of_alloc(bcx.ccx(), llty), 0);
442+
assert_eq!(machine::llsize_of_alloc(bcx.ccx(), ty), 0);
443443
// The contents of memory at this pointer can't matter, but use
444444
// the value that's "reasonable" in case of pointer comparison.
445445
PointerCast(bcx, val, ty.ptr_to())
@@ -457,7 +457,7 @@ fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
457457
type_of::type_of(ccx, ty)
458458
};
459459
let real_ty = Type::struct_(fields, st.packed);
460-
PointerCast(bcx, val, real_llty.to_ptr().to_ref())
460+
PointerCast(bcx, val, real_ty.ptr_to())
461461
} else {
462462
val
463463
};
@@ -572,7 +572,7 @@ fn build_const_struct(ccx: &mut CrateContext, st: &Struct, vals: &[ValueRef])
572572
}
573573

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

578578
// XXX this utility routine should be somewhere more general

src/librustc/middle/trans/asm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use middle::trans::callee;
2020
use middle::trans::common::*;
2121
use middle::ty;
2222

23+
use middle::trans::type_::Type;
24+
2325
use core::str;
2426
use syntax::ast;
2527

0 commit comments

Comments
 (0)