Skip to content

Commit fd83b92

Browse files
author
James Miller
committed
More Type refactorings
1 parent 1968622 commit fd83b92

File tree

13 files changed

+470
-578
lines changed

13 files changed

+470
-578
lines changed

src/librustc/back/upcall.rs

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
use driver::session;
1313
use middle::trans::base;
14-
use middle::trans::common::{T_fn, T_i8, T_i32, T_int, T_ptr, T_void};
15-
use lib::llvm::{ModuleRef, ValueRef, TypeRef};
14+
use middle::trans::type_::Type;
15+
use lib::llvm::{ModuleRef, ValueRef};
1616

1717
pub struct Upcalls {
1818
trace: ValueRef,
@@ -22,40 +22,35 @@ pub struct Upcalls {
2222
reset_stack_limit: ValueRef
2323
}
2424

25-
pub fn declare_upcalls(targ_cfg: @session::config,
26-
llmod: ModuleRef) -> @Upcalls {
27-
fn decl(llmod: ModuleRef, prefix: ~str, name: ~str,
28-
tys: ~[TypeRef], rv: TypeRef) ->
29-
ValueRef {
30-
let arg_tys = tys.map(|t| *t);
31-
let fn_ty = T_fn(arg_tys, rv);
32-
return base::decl_cdecl_fn(llmod, prefix + name, fn_ty);
33-
}
34-
fn nothrow(f: ValueRef) -> ValueRef {
35-
base::set_no_unwind(f); f
36-
}
37-
let d: &fn(a: ~str, b: ~[TypeRef], c: TypeRef) -> ValueRef =
38-
|a,b,c| decl(llmod, ~"upcall_", a, b, c);
39-
let dv: &fn(a: ~str, b: ~[TypeRef]) -> ValueRef =
40-
|a,b| decl(llmod, ~"upcall_", a, b, T_void());
25+
macro_rules! upcall (
26+
(fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
27+
let fn_ty = Type::func([ $($arg),* ], $ret);
28+
base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty)
29+
});
30+
(nothrow fn $name:ident($($arg:expr),+) -> $ret:expr) => ({
31+
let fn_ty = Type::func([ $($arg),* ], $ret);
32+
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
33+
base::set_no_unwind(decl);
34+
decl
35+
});
36+
(nothrow fn $name:ident -> $ret:expr) => ({
37+
let fn_ty = Type::func([], $ret);
38+
let decl = base::decl_cdecl_fn(llmod, ~"upcall_" + stringify!($name), fn_ty);
39+
base::set_no_unwind(decl);
40+
decl
41+
})
42+
)
4143

42-
let int_t = T_int(targ_cfg);
44+
pub fn declare_upcalls(targ_cfg: @session::config, llmod: ModuleRef) -> @Upcalls {
45+
let opaque_ptr = Type::i8().to_ptr();
46+
let int_ty = Type::int(targ_cfg.arch);
4347

4448
@Upcalls {
45-
trace: dv(~"trace", ~[T_ptr(T_i8()),
46-
T_ptr(T_i8()),
47-
int_t]),
48-
call_shim_on_c_stack:
49-
d(~"call_shim_on_c_stack",
50-
// arguments: void *args, void *fn_ptr
51-
~[T_ptr(T_i8()), T_ptr(T_i8())],
52-
int_t),
49+
trace: upcall!(fn trace(opaque_ptr, opaque_ptr, int_ty) -> Type::void()),
50+
call_shim_on_c_stack: upcall!(fn call_shim_on_c_stack(opaque_ptr, opaque_ptr) -> int_ty),
5351
call_shim_on_rust_stack:
54-
d(~"call_shim_on_rust_stack",
55-
~[T_ptr(T_i8()), T_ptr(T_i8())], int_t),
56-
rust_personality:
57-
nothrow(d(~"rust_personality", ~[], T_i32())),
58-
reset_stack_limit:
59-
nothrow(dv(~"reset_stack_limit", ~[]))
52+
upcall!(fn call_shim_on_rust_stack(opaque_ptr, opaque_ptr) -> int_ty),
53+
rust_personality: upcall!(nothrow fn rust_personality -> Type::i32()),
54+
reset_stack_limit: upcall!(nothrow fn reset_stack_limit -> Type::void())
6055
}
6156
}

src/librustc/lib/llvm.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,18 +2233,6 @@ pub fn fn_ty_param_tys(fn_ty: TypeRef) -> ~[TypeRef] {
22332233
}
22342234
}
22352235

2236-
pub fn struct_tys(struct_ty: TypeRef) -> ~[TypeRef] {
2237-
unsafe {
2238-
let n_elts = llvm::LLVMCountStructElementTypes(struct_ty) as uint;
2239-
if n_elts == 0 {
2240-
return ~[];
2241-
}
2242-
let mut elts = vec::from_elem(n_elts, ptr::null());
2243-
llvm::LLVMGetStructElementTypes(struct_ty, &mut elts[0]);
2244-
return elts;
2245-
}
2246-
}
2247-
22482236

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

src/librustc/middle/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ fn create_bindings_map(bcx: block, pat: @ast::pat) -> BindingsMap {
16441644
// but during matching we need to store a *T as explained
16451645
// above
16461646
let is_move = ccx.maps.moves_map.contains(&p_id);
1647-
llmatch = alloca(bcx, T_ptr(llvariable_ty));
1647+
llmatch = alloca(bcx, llvariable_ty.ptr_to());
16481648
trmode = TrByValue(is_move, alloca(bcx, llvariable_ty));
16491649
}
16501650
ast::bind_by_ref(_) => {

src/librustc/middle/trans/adt.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use core::libc::c_ulonglong;
4949
use core::option::{Option, Some, None};
5050
use core::vec;
5151

52-
use lib::llvm::{ValueRef, TypeRef, True, IntEQ, IntNE};
52+
use lib::llvm::{ValueRef, True, IntEQ, IntNE};
5353
use middle::trans::_match;
5454
use middle::trans::build::*;
5555
use middle::trans::common::*;
@@ -212,7 +212,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr {
212212

213213
fn mk_struct(cx: &mut CrateContext, tys: &[ty::t], packed: bool) -> Struct {
214214
let lltys = tys.map(|&ty| type_of::sizing_type_of(cx, ty));
215-
let llty_rec = T_struct(lltys, packed);
215+
let llty_rec = Type::struct_(lltys, packed);
216216
Struct {
217217
size: machine::llsize_of_alloc(cx, llty_rec) /*bad*/as u64,
218218
align: machine::llalign_of_min(cx, llty_rec) /*bad*/as u64,
@@ -226,17 +226,16 @@ fn mk_struct(cx: &mut CrateContext, tys: &[ty::t], packed: bool) -> Struct {
226226
* All nominal types are LLVM structs, in order to be able to use
227227
* forward-declared opaque types to prevent circularity in `type_of`.
228228
*/
229-
pub fn fields_of(cx: &mut CrateContext, r: &Repr) -> ~[TypeRef] {
229+
pub fn fields_of(cx: &mut CrateContext, r: &Repr) -> ~[Type] {
230230
generic_fields_of(cx, r, false)
231231
}
232232
/// Like `fields_of`, but for `type_of::sizing_type_of` (q.v.).
233-
pub fn sizing_fields_of(cx: &mut CrateContext, r: &Repr) -> ~[TypeRef] {
233+
pub fn sizing_fields_of(cx: &mut CrateContext, r: &Repr) -> ~[Type] {
234234
generic_fields_of(cx, r, true)
235235
}
236-
fn generic_fields_of(cx: &mut CrateContext, r: &Repr, sizing: bool)
237-
-> ~[TypeRef] {
236+
fn generic_fields_of(cx: &mut CrateContext, r: &Repr, sizing: bool) -> ~[Type] {
238237
match *r {
239-
CEnum(*) => ~[T_enum_discrim(cx)],
238+
CEnum(*) => ~[Type::enum_discrim(cx)],
240239
Univariant(ref st, _dtor) => struct_llfields(cx, st, sizing),
241240
NullablePointer{ nonnull: ref st, _ } => struct_llfields(cx, st, sizing),
242241
General(ref sts) => {
@@ -261,14 +260,15 @@ fn generic_fields_of(cx: &mut CrateContext, r: &Repr, sizing: bool)
261260
let most_aligned = most_aligned.get();
262261
let padding = largest_size - most_aligned.size;
263262

263+
assert!(padding >= 0);
264+
264265
struct_llfields(cx, most_aligned, sizing)
265-
+ [T_array(T_i8(), padding /*bad*/as uint)]
266+
+ [Type::array(Type::i8(), padding /*bad*/as uint)]
266267
}
267268
}
268269
}
269270

270-
fn struct_llfields(cx: &mut CrateContext, st: &Struct, sizing: bool)
271-
-> ~[TypeRef] {
271+
fn struct_llfields(cx: &mut CrateContext, st: &Struct, sizing: bool) -> ~[Type] {
272272
if sizing {
273273
st.fields.map(|&ty| type_of::sizing_type_of(cx, ty))
274274
} else {
@@ -309,7 +309,7 @@ pub fn trans_get_discr(bcx: block, r: &Repr, scrutinee: ValueRef)
309309
(cases.len() - 1) as int),
310310
NullablePointer{ nonnull: ref nonnull, nndiscr, ptrfield, _ } => {
311311
ZExt(bcx, nullable_bitdiscr(bcx, nonnull, nndiscr, ptrfield, scrutinee),
312-
T_enum_discrim(bcx.ccx()))
312+
Type::enum_discrim(bcx.ccx()))
313313
}
314314
}
315315
}
@@ -438,11 +438,11 @@ pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
438438
} else {
439439
// The unit-like case might have a nonzero number of unit-like fields.
440440
// (e.g., Result or Either with () as one side.)
441-
let llty = type_of::type_of(bcx.ccx(), nullfields[ix]);
441+
let ty = type_of::type_of(bcx.ccx(), nullfields[ix]);
442442
assert_eq!(machine::llsize_of_alloc(bcx.ccx(), llty), 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.
445-
PointerCast(bcx, val, T_ptr(llty))
445+
PointerCast(bcx, val, ty.ptr_to())
446446
}
447447
}
448448
}
@@ -456,8 +456,8 @@ fn struct_field_ptr(bcx: block, st: &Struct, val: ValueRef, ix: uint,
456456
let fields = do st.fields.map |&ty| {
457457
type_of::type_of(ccx, ty)
458458
};
459-
let real_llty = T_struct(fields, st.packed);
460-
PointerCast(bcx, val, T_ptr(real_llty))
459+
let real_ty = Type::struct_(fields, st.packed);
460+
PointerCast(bcx, val, real_llty.to_ptr().to_ref())
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(T_array(T_i8(), size /*bad*/as uint))
575+
C_undef(Type::array(Type::i8(), size).to_ref())
576576
}
577577

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

src/librustc/middle/trans/asm.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
110110

111111
// Depending on how many outputs we have, the return type is different
112112
let output = if numOutputs == 0 {
113-
T_void()
113+
Type::void()
114114
} else if numOutputs == 1 {
115115
val_ty(outputs[0])
116116
} else {
117-
T_struct(outputs.map(|o| val_ty(*o)), false)
117+
Type::struct_(outputs.map(|o| val_ty(*o)), false)
118118
};
119119

120120
let dialect = match ia.dialect {
@@ -130,12 +130,12 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
130130

131131
// Again, based on how many outputs we have
132132
if numOutputs == 1 {
133-
let op = PointerCast(bcx, aoutputs[0], T_ptr(val_ty(outputs[0])));
133+
let op = PointerCast(bcx, aoutputs[0], val_ty(outputs[0]).ptr_to());
134134
Store(bcx, r, op);
135135
} else {
136136
for aoutputs.iter().enumerate().advance |(i, o)| {
137137
let v = ExtractValue(bcx, r, i);
138-
let op = PointerCast(bcx, *o, T_ptr(val_ty(outputs[i])));
138+
let op = PointerCast(bcx, *o, val_ty(outputs[i]).ptr_to());
139139
Store(bcx, v, op);
140140
}
141141
}

0 commit comments

Comments
 (0)