@@ -62,6 +62,12 @@ enum dest {
62
62
ignore,
63
63
}
64
64
65
+ // Heap selectors. Indicate which heap something should go on.
66
+ enum heap {
67
+ heap_shared,
68
+ heap_exchange,
69
+ }
70
+
65
71
fn dest_str ( ccx : @crate_ctxt , d : dest ) -> str {
66
72
alt d {
67
73
by_val( v) { #fmt[ "by_val(%s)" , val_str ( ccx. tn , * v) ] }
@@ -341,75 +347,61 @@ fn opaque_box_body(bcx: block,
341
347
PointerCast ( bcx, bodyptr, T_ptr ( type_of ( ccx, body_t) ) )
342
348
}
343
349
344
- // trans_malloc_boxed_raw : expects an unboxed type and returns a pointer to
350
+ // malloc_raw : expects an unboxed type and returns a pointer to
345
351
// enough space for a box of that type. This includes a rust_opaque_box
346
352
// header.
347
- fn malloc_boxed_raw ( bcx : block , t : ty:: t ,
348
- & static_ti: option < @tydesc_info > ) -> ValueRef {
349
- let _icx = bcx. insn_ctxt ( "trans_malloc_boxed_raw" ) ;
353
+ fn malloc_raw ( bcx : block , t : ty:: t , heap : heap ) -> ValueRef {
354
+ let _icx = bcx. insn_ctxt ( "malloc_raw" ) ;
350
355
let ccx = bcx. ccx ( ) ;
351
356
352
- // Grab the TypeRef type of box_ptr, because that's what trans_raw_malloc
353
- // wants.
354
- let box_ptr = ty:: mk_imm_box ( ccx. tcx , t) ;
355
- let llty = type_of ( ccx, box_ptr) ;
357
+ let ( mk_fn, upcall) = alt heap {
358
+ heap_shared { ( ty:: mk_imm_box, ccx. upcalls . malloc ) }
359
+ heap_exchange {
360
+ ( ty:: mk_imm_uniq, ccx. upcalls . exchange_malloc )
361
+ }
362
+ } ;
363
+
364
+ // Grab the TypeRef type of box_ptr_ty.
365
+ let box_ptr_ty = mk_fn ( bcx. tcx ( ) , t) ;
366
+ let llty = type_of ( ccx, box_ptr_ty) ;
356
367
357
368
// Get the tydesc for the body:
369
+ let mut static_ti = none;
358
370
let lltydesc = get_tydesc ( ccx, t, static_ti) ;
359
371
lazily_emit_all_tydesc_glue ( ccx, copy static_ti) ;
360
372
361
373
// Allocate space:
362
- let rval = Call ( bcx, ccx . upcalls . malloc , [ lltydesc] ) ;
374
+ let rval = Call ( bcx, upcall , [ lltydesc] ) ;
363
375
ret PointerCast ( bcx, rval, llty) ;
364
376
}
365
377
366
- // trans_malloc_boxed: usefully wraps trans_malloc_box_raw; allocates a box,
367
- // initializes the reference count to 1, and pulls out the body and rc
368
- fn malloc_boxed ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
369
- let _icx = bcx. insn_ctxt ( "trans_malloc_boxed" ) ;
370
- let mut ti = none;
371
- let box = malloc_boxed_raw ( bcx, t, ti) ;
372
- let box_no_addrspace = non_gc_box_cast (
373
- bcx, box, ty:: mk_imm_box ( bcx. tcx ( ) , t) ) ;
374
- let body = GEPi ( bcx, box_no_addrspace, [ 0 u, abi:: box_field_body] ) ;
378
+ // malloc_general: usefully wraps malloc_raw; allocates a box,
379
+ // and pulls out the body
380
+ fn malloc_general ( bcx : block , t : ty:: t , heap : heap ) ->
381
+ { box : ValueRef , body : ValueRef } {
382
+ let _icx = bcx. insn_ctxt ( "malloc_general" ) ;
383
+ let mk_ty = alt heap { heap_shared { ty:: mk_imm_box }
384
+ heap_exchange { ty : : mk_imm_uniq } } ;
385
+ let box = malloc_raw ( bcx, t, heap) ;
386
+ let non_gc_box = non_gc_box_cast ( bcx, box, mk_ty ( bcx. tcx ( ) , t) ) ;
387
+ let body = GEPi ( bcx, non_gc_box, [ 0 u, abi:: box_field_body] ) ;
375
388
ret { box : box, body : body} ;
376
389
}
377
390
378
- fn malloc_unique_raw ( bcx : block , t : ty:: t ) -> ValueRef {
379
- let _icx = bcx. insn_ctxt ( "malloc_unique_box_raw" ) ;
380
- let ccx = bcx. ccx ( ) ;
381
-
382
- // Grab the TypeRef type of box_ptr, because that's what trans_raw_malloc
383
- // wants.
384
- let box_ptr = ty:: mk_imm_uniq ( ccx. tcx , t) ;
385
- let llty = type_of ( ccx, box_ptr) ;
386
-
387
- // Get the tydesc for the body:
388
- let mut static_ti = none;
389
- let lltydesc = get_tydesc ( ccx, t, static_ti) ;
390
- lazily_emit_all_tydesc_glue ( ccx, static_ti) ;
391
-
392
- // Allocate space:
393
- let rval = Call ( bcx, ccx. upcalls . exchange_malloc , [ lltydesc] ) ;
394
- ret PointerCast ( bcx, rval, llty) ;
391
+ fn malloc_boxed ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
392
+ malloc_general ( bcx, t, heap_shared)
395
393
}
396
-
397
394
fn malloc_unique ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
398
- let _icx = bcx. insn_ctxt ( "malloc_unique_box" ) ;
399
- let box = malloc_unique_raw ( bcx, t) ;
400
- let non_gc_box = non_gc_box_cast ( bcx, box, ty:: mk_imm_uniq ( bcx. tcx ( ) , t) ) ;
401
- let body = GEPi ( bcx, non_gc_box, [ 0 u, abi:: box_field_body] ) ;
402
- ret { box : box, body : body} ;
395
+ malloc_general ( bcx, t, heap_exchange)
403
396
}
404
397
405
398
fn malloc_unique_dyn_raw ( bcx : block , t : ty:: t , size : ValueRef ) -> ValueRef {
406
- let _icx = bcx. insn_ctxt ( "malloc_unique_box_raw " ) ;
399
+ let _icx = bcx. insn_ctxt ( "malloc_unique_dyn_raw " ) ;
407
400
let ccx = bcx. ccx ( ) ;
408
401
409
- // Grab the TypeRef type of box_ptr, because that's what trans_raw_malloc
410
- // wants.
411
- let box_ptr = ty:: mk_imm_uniq ( ccx. tcx , t) ;
412
- let llty = type_of ( ccx, box_ptr) ;
402
+ // Grab the TypeRef type of box_ptr_ty.
403
+ let box_ptr_ty = ty:: mk_imm_uniq ( ccx. tcx , t) ;
404
+ let llty = type_of ( ccx, box_ptr_ty) ;
413
405
414
406
// Get the tydesc for the body:
415
407
let mut static_ti = none;
@@ -423,7 +415,7 @@ fn malloc_unique_dyn_raw(bcx: block, t: ty::t, size: ValueRef) -> ValueRef {
423
415
424
416
fn malloc_unique_dyn ( bcx : block , t : ty:: t , size : ValueRef
425
417
) -> { box : ValueRef , body : ValueRef } {
426
- let _icx = bcx. insn_ctxt ( "malloc_unique_box " ) ;
418
+ let _icx = bcx. insn_ctxt ( "malloc_unique_dyn " ) ;
427
419
let box = malloc_unique_dyn_raw ( bcx, t, size) ;
428
420
let body = GEPi ( bcx, box, [ 0 u, abi:: box_field_body] ) ;
429
421
ret { box : box, body : body} ;
0 commit comments