@@ -41,15 +41,16 @@ fn llelement_type(TypeRef llty) -> TypeRef {
41
41
42
42
tag dest_slot {
43
43
dst_nil;
44
- dst_val ( ValueRef ) ;
44
+ dst_imm ( @mutable option[ ValueRef ] ) ;
45
+ dst_ptr ( ValueRef ) ;
45
46
}
46
47
47
48
tag dest_mode { dm_copy; dm_move; dm_alias; }
48
49
49
50
type dest = rec ( dest_slot slot, dest_mode mode) ;
50
51
51
52
fn dest_slot_for_ptr ( & ty:: ctxt tcx, ValueRef llptr, ty:: t t) -> dest_slot {
52
- if ty:: type_is_nil ( tcx, t) { dst_nil } else { dst_val ( llptr) }
53
+ if ty:: type_is_nil ( tcx, t) { dst_nil } else { dst_ptr ( llptr) }
53
54
}
54
55
55
56
fn dest_copy ( & ty:: ctxt tcx, ValueRef llptr, ty:: t t) -> dest {
@@ -69,16 +70,34 @@ fn dest_tmp(&@block_ctxt bcx, ty::t t, bool alias) -> tup(@block_ctxt, dest) {
69
70
if ty:: type_is_nil ( bcx_tcx ( bcx) , t) {
70
71
ret tup ( bcx, rec ( slot=dst_nil, mode=mode) ) ;
71
72
}
73
+ if trans:: type_is_immediate ( bcx_ccx ( bcx) , t) {
74
+ ret tup ( bcx, rec ( slot=dst_imm ( @mutable none) , mode=mode) ) ;
75
+ }
72
76
auto r = trans:: alloc_ty ( bcx, t) ;
73
77
trans:: add_clean ( bcx, r. val , t) ;
74
78
ret tup( r. bcx , rec ( slot=dest_slot_for_ptr ( bcx_tcx ( bcx) , r. val , t) ,
75
79
mode=mode) ) ;
76
80
}
77
81
82
+ // Invariant: the type of the destination must be structural (non-immediate).
78
83
fn dest_ptr ( & dest dest) -> ValueRef {
79
84
alt ( dest. slot ) {
80
- dst_nil { tc : : C_null ( tc:: T_ptr ( tc:: T_i8 ( ) ) ) }
81
- dst_val( ?llptr) { llptr }
85
+ dst_nil { fail "nil dest in dest_ptr" }
86
+ dst_imm ( _) { fail "immediate dest in dest_ptr" }
87
+ dst_ptr ( ?llptr) { llptr }
88
+ }
89
+ }
90
+
91
+ fn dest_llval ( & dest dest) -> ValueRef {
92
+ alt ( dest. slot ) {
93
+ dst_nil { ret tc:: C_nil ( ) ; }
94
+ dst_imm ( ?box) {
95
+ alt ( * box) {
96
+ none { fail "immediate wasn't filled in prior to dest_llval" ; }
97
+ some ( ?llval) { ret llval; }
98
+ }
99
+ }
100
+ dst_ptr ( ?llval) { ret llval; }
82
101
}
83
102
}
84
103
@@ -100,9 +119,15 @@ fn store(&@block_ctxt bcx, &dest dest, ValueRef llsrc, bool cast)
100
119
-> @block_ctxt {
101
120
alt ( dest. slot ) {
102
121
dst_nil { /* no-op */ }
103
- dst_val( ?lldestptr_orig) {
122
+ dst_imm( ?box) {
123
+ if !std:: option:: is_none ( * box) {
124
+ fail "attempt to store an immediate twice" ;
125
+ } ;
126
+ * box = some ( llsrc) ;
127
+ }
128
+ dst_ptr ( ?lldestptr_orig) {
104
129
auto lldestptr = lldestptr_orig;
105
- if ( cast) {
130
+ if cast {
106
131
lldestptr = bcx. build . PointerCast ( lldestptr,
107
132
tc:: T_ptr ( lltype_of ( llsrc) ) ) ;
108
133
}
@@ -201,39 +226,47 @@ fn trans_log(&@block_ctxt cx, &span sp, int level, &@ast::expr expr)
201
226
ret lllevelptr;
202
227
}
203
228
204
- fn trans_log_upcall ( & @block_ctxt bcx , & span sp, ValueRef in_llval,
205
- int level , ty:: t t) {
229
+ fn trans_log_upcall ( & @block_ctxt cx , & span sp, ValueRef in_llval,
230
+ int level , ty:: t t) -> @block_ctxt {
231
+ auto bcx = cx;
206
232
auto llval = in_llval;
207
- auto by_val ; auto llupcall;
233
+ auto llupcall;
208
234
alt ( ty:: struct ( bcx_tcx ( bcx) , t) ) {
209
235
ty:: ty_machine ( ast:: ty_f32) {
210
- by_val = true ; llupcall = bcx_ccx ( bcx) . upcalls . log_float ;
236
+ llupcall = bcx_ccx ( bcx) . upcalls . log_float ;
211
237
}
212
238
ty:: ty_machine ( ast:: ty_f64) | ty:: ty_float {
213
- by_val = false ; llupcall = bcx_ccx ( bcx) . upcalls . log_double ;
239
+ llupcall = bcx_ccx ( bcx) . upcalls . log_double ;
240
+
241
+ // TODO: Here we have to spill due to legacy calling conventions.
242
+ // This is no longer necessary.
243
+ auto r = trans:: alloc_ty ( bcx, t) ;
244
+ bcx = r. bcx ; auto llptr = r. val ;
245
+ bcx. build . Store ( llval, llptr) ;
246
+ llval = llptr;
214
247
}
215
248
ty:: ty_bool | ty:: ty_machine ( ast:: ty_i8) |
216
249
ty:: ty_machine ( ast:: ty_i16) | ty:: ty_machine ( ast:: ty_u8) |
217
250
ty:: ty_machine ( ast:: ty_u16) {
218
- by_val = true ; llupcall = bcx_ccx ( bcx) . upcalls . log_int ;
251
+ llupcall = bcx_ccx ( bcx) . upcalls . log_int ;
219
252
llval = bcx. build . ZExt ( llval, tc:: T_i32 ( ) ) ;
220
253
}
221
254
ty:: ty_int | ty:: ty_machine ( ast:: ty_i32) |
222
255
ty:: ty_machine ( ast:: ty_u32) {
223
- by_val = true ; llupcall = bcx_ccx ( bcx) . upcalls . log_int ;
256
+ llupcall = bcx_ccx ( bcx) . upcalls . log_int ;
224
257
}
225
258
ty:: ty_istr {
226
- by_val = false ; llupcall = bcx_ccx ( bcx) . upcalls . log_istr ;
259
+ llupcall = bcx_ccx ( bcx) . upcalls . log_istr ;
227
260
}
228
261
_ {
229
262
bcx_ccx( bcx) . sess . span_unimpl ( sp, "logging for values of type " +
230
263
ppaux:: ty_to_str ( bcx_tcx ( bcx) , t) ) ;
231
264
}
232
265
}
233
266
234
- if by_val { llval = bcx. build . Load ( llval) ; }
235
267
bcx. build . Call ( llupcall,
236
268
~[ bcx_fcx ( bcx) . lltaskptr , tc:: C_int ( level) , llval] ) ;
269
+ ret bcx;
237
270
}
238
271
239
272
auto bcx = cx;
@@ -253,7 +286,7 @@ fn trans_log(&@block_ctxt cx, &span sp, int level, &@ast::expr expr)
253
286
log_bcx = r. _0 ; auto tmp = r. _1 ;
254
287
log_bcx = trans_expr ( log_bcx, tmp, expr) ;
255
288
256
- trans_log_upcall ( log_bcx, sp, dest_ptr ( tmp) , level, expr_t) ;
289
+ log_bcx = trans_log_upcall ( log_bcx, sp, dest_llval ( tmp) , level, expr_t) ;
257
290
258
291
log_bcx = trans:: trans_block_cleanups ( log_bcx,
259
292
trans:: find_scope_cx ( log_bcx) ) ;
0 commit comments