10
10
11
11
use llvm:: ValueRef ;
12
12
use rustc:: middle:: ty:: { self , Ty } ;
13
- use rustc_front:: hir;
14
13
use rustc_mir:: repr as mir;
15
14
16
15
use trans:: asm;
@@ -47,6 +46,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
47
46
48
47
mir:: Rvalue :: Cast ( mir:: CastKind :: Unsize , ref operand, cast_ty) => {
49
48
if common:: type_is_fat_ptr ( bcx. tcx ( ) , cast_ty) {
49
+ // into-coerce of a thin pointer to a fat pointer - just
50
+ // use the operand path.
50
51
let ( bcx, temp) = self . trans_rvalue_operand ( bcx, rvalue) ;
51
52
self . store_operand ( bcx, lldest, temp) ;
52
53
return bcx;
@@ -59,8 +60,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
59
60
let operand = self . trans_operand ( bcx, operand) ;
60
61
match operand. val {
61
62
OperandValue :: FatPtr ( ..) => unreachable ! ( ) ,
62
- OperandValue :: Imm ( llval) => {
63
- // ugly alloca.
63
+ OperandValue :: Immediate ( llval) => {
64
+ // unsize from an immediate structure. We don't
65
+ // really need a temporary alloca here, but
66
+ // avoiding it would require us to have
67
+ // `coerce_unsized_into` use extractvalue to
68
+ // index into the struct, and this case isn't
69
+ // important enough for it.
64
70
debug ! ( "trans_rvalue: creating ugly alloca" ) ;
65
71
let lltemp = base:: alloc_ty ( bcx, operand. ty , "__unsize_temp" ) ;
66
72
base:: store_ty ( bcx, llval, lltemp, operand. ty ) ;
@@ -165,7 +171,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
165
171
// and is a no-op at the LLVM level
166
172
operand. val
167
173
}
168
- OperandValue :: Imm ( lldata) => {
174
+ OperandValue :: Immediate ( lldata) => {
169
175
// "standard" unsize
170
176
let ( lldata, llextra) =
171
177
base:: unsize_thin_ptr ( bcx, lldata,
@@ -200,7 +206,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
200
206
// destination effectively creates a reference.
201
207
if common:: type_is_sized ( bcx. tcx ( ) , ty) {
202
208
( bcx, OperandRef {
203
- val : OperandValue :: Imm ( tr_lvalue. llval ) ,
209
+ val : OperandValue :: Immediate ( tr_lvalue. llval ) ,
204
210
ty : ref_ty,
205
211
} )
206
212
} else {
@@ -215,7 +221,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
215
221
mir:: Rvalue :: Len ( ref lvalue) => {
216
222
let tr_lvalue = self . trans_lvalue ( bcx, lvalue) ;
217
223
( bcx, OperandRef {
218
- val : OperandValue :: Imm ( self . lvalue_len ( bcx, tr_lvalue) ) ,
224
+ val : OperandValue :: Immediate ( self . lvalue_len ( bcx, tr_lvalue) ) ,
219
225
ty : bcx. tcx ( ) . types . usize ,
220
226
} )
221
227
}
@@ -230,7 +236,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
230
236
base:: compare_fat_ptrs ( bcx,
231
237
lhs_addr, lhs_extra,
232
238
rhs_addr, rhs_extra,
233
- lhs. ty , cmp_to_hir_cmp ( op ) ,
239
+ lhs. ty , op . to_hir_binop ( ) ,
234
240
DebugLoc :: None )
235
241
}
236
242
_ => unreachable ! ( )
@@ -242,8 +248,8 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
242
248
lhs. ty , DebugLoc :: None )
243
249
} ;
244
250
( bcx, OperandRef {
245
- val : OperandValue :: Imm ( llresult) ,
246
- ty : type_of_binop ( bcx. tcx ( ) , op, lhs. ty , rhs. ty ) ,
251
+ val : OperandValue :: Immediate ( llresult) ,
252
+ ty : self . mir . binop_ty ( bcx. tcx ( ) , op, lhs. ty , rhs. ty ) ,
247
253
} )
248
254
}
249
255
@@ -261,7 +267,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
261
267
}
262
268
} ;
263
269
( bcx, OperandRef {
264
- val : OperandValue :: Imm ( llval) ,
270
+ val : OperandValue :: Immediate ( llval) ,
265
271
ty : operand. ty ,
266
272
} )
267
273
}
@@ -281,7 +287,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
281
287
llalign,
282
288
DebugLoc :: None ) ;
283
289
( bcx, OperandRef {
284
- val : OperandValue :: Imm ( llval) ,
290
+ val : OperandValue :: Immediate ( llval) ,
285
291
ty : box_ty,
286
292
} )
287
293
}
@@ -388,7 +394,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
388
394
mir:: BinOp :: Eq | mir:: BinOp :: Lt | mir:: BinOp :: Gt |
389
395
mir:: BinOp :: Ne | mir:: BinOp :: Le | mir:: BinOp :: Ge => {
390
396
base:: compare_scalar_types ( bcx, lhs, rhs, input_ty,
391
- cmp_to_hir_cmp ( op ) , debug_loc)
397
+ op . to_hir_binop ( ) , debug_loc)
392
398
}
393
399
}
394
400
}
@@ -413,43 +419,3 @@ pub fn rvalue_creates_operand<'tcx>(rvalue: &mir::Rvalue<'tcx>) -> bool {
413
419
414
420
// (*) this is only true if the type is suitable
415
421
}
416
-
417
- fn cmp_to_hir_cmp ( op : mir:: BinOp ) -> hir:: BinOp_ {
418
- match op {
419
- mir:: BinOp :: Eq => hir:: BiEq ,
420
- mir:: BinOp :: Ne => hir:: BiNe ,
421
- mir:: BinOp :: Lt => hir:: BiLt ,
422
- mir:: BinOp :: Le => hir:: BiLe ,
423
- mir:: BinOp :: Gt => hir:: BiGt ,
424
- mir:: BinOp :: Ge => hir:: BiGe ,
425
- _ => unreachable ! ( )
426
- }
427
- }
428
-
429
- /// FIXME(nikomatsakis): I don't think this function should go here
430
- fn type_of_binop < ' tcx > (
431
- tcx : & ty:: ctxt < ' tcx > ,
432
- op : mir:: BinOp ,
433
- lhs_ty : Ty < ' tcx > ,
434
- rhs_ty : Ty < ' tcx > )
435
- -> Ty < ' tcx >
436
- {
437
- match op {
438
- mir:: BinOp :: Add | mir:: BinOp :: Sub |
439
- mir:: BinOp :: Mul | mir:: BinOp :: Div | mir:: BinOp :: Rem |
440
- mir:: BinOp :: BitXor | mir:: BinOp :: BitAnd | mir:: BinOp :: BitOr => {
441
- // these should be integers or floats of the same size. We
442
- // probably want to dump all ops in some intrinsics framework
443
- // someday.
444
- assert_eq ! ( lhs_ty, rhs_ty) ;
445
- lhs_ty
446
- }
447
- mir:: BinOp :: Shl | mir:: BinOp :: Shr => {
448
- lhs_ty // lhs_ty can be != rhs_ty
449
- }
450
- mir:: BinOp :: Eq | mir:: BinOp :: Lt | mir:: BinOp :: Le |
451
- mir:: BinOp :: Ne | mir:: BinOp :: Ge | mir:: BinOp :: Gt => {
452
- tcx. types . bool
453
- }
454
- }
455
- }
0 commit comments