2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-01-07 16:16:52 -06:00
|
|
|
|
2012-09-04 13:54:36 -05:00
|
|
|
use lib::llvm::ValueRef;
|
2012-12-13 15:05:22 -06:00
|
|
|
use middle::trans::base::*;
|
|
|
|
use middle::trans::build::*;
|
|
|
|
use middle::trans::common::*;
|
|
|
|
use middle::trans::datum::immediate_rvalue;
|
2012-12-23 16:41:37 -06:00
|
|
|
use middle::trans::glue;
|
2013-02-25 13:11:21 -06:00
|
|
|
use middle::ty;
|
2012-12-13 15:05:22 -06:00
|
|
|
|
2013-01-30 13:46:19 -06:00
|
|
|
pub fn make_free_glue(bcx: block, vptrptr: ValueRef, box_ty: ty::t)
|
2012-02-17 06:17:40 -06:00
|
|
|
-> block {
|
2013-06-16 23:23:24 -05:00
|
|
|
let _icx = push_ctxt("uniq::make_free_glue");
|
2012-08-28 17:54:45 -05:00
|
|
|
let box_datum = immediate_rvalue(Load(bcx, vptrptr), box_ty);
|
|
|
|
|
|
|
|
let not_null = IsNotNull(bcx, box_datum.val);
|
|
|
|
do with_cond(bcx, not_null) |bcx| {
|
|
|
|
let body_datum = box_datum.box_body(bcx);
|
|
|
|
let bcx = glue::drop_ty(bcx, body_datum.to_ref_llval(bcx),
|
|
|
|
body_datum.ty);
|
2013-02-20 17:02:21 -06:00
|
|
|
if ty::type_contents(bcx.tcx(), box_ty).contains_managed() {
|
|
|
|
glue::trans_free(bcx, box_datum.val)
|
|
|
|
} else {
|
|
|
|
glue::trans_exchange_free(bcx, box_datum.val)
|
|
|
|
}
|
2012-02-17 06:17:40 -06:00
|
|
|
}
|
2011-09-22 13:44:18 -05:00
|
|
|
}
|