Skip to content

Commit 45933ca

Browse files
committed
rustc: Add some methods for trans for mallocing uniques
1 parent 508ccca commit 45933ca

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/rustc/middle/trans/base.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,32 @@ fn malloc_boxed(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
384384
ret {box: box, body: body};
385385
}
386386

387+
fn malloc_unique_raw(bcx: block, t: ty::t) -> ValueRef {
388+
let _icx = bcx.insn_ctxt("malloc_unique_box_raw");
389+
let ccx = bcx.ccx();
390+
391+
// Grab the TypeRef type of box_ptr, because that's what trans_raw_malloc
392+
// wants.
393+
let box_ptr = ty::mk_imm_uniq(ccx.tcx, t);
394+
let llty = type_of(ccx, box_ptr);
395+
396+
// Get the tydesc for the body:
397+
let mut static_ti = none;
398+
let lltydesc = get_tydesc(ccx, t, static_ti);
399+
lazily_emit_all_tydesc_glue(ccx, static_ti);
400+
401+
// Allocate space:
402+
let rval = Call(bcx, ccx.upcalls.exchange_malloc, [lltydesc]);
403+
ret PointerCast(bcx, rval, llty);
404+
}
405+
406+
fn malloc_unique(bcx: block, t: ty::t) -> {box: ValueRef, body: ValueRef} {
407+
let _icx = bcx.insn_ctxt("malloc_unique_box");
408+
let box = malloc_unique_raw(bcx, t);
409+
let body = GEPi(bcx, box, [0u, abi::box_field_body]);
410+
ret {box: box, body: body};
411+
}
412+
387413
// Type descriptor and type glue stuff
388414

389415
fn get_tydesc_simple(ccx: @crate_ctxt, t: ty::t) -> ValueRef {

0 commit comments

Comments
 (0)