]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/trans/uniq.rs
e9df83549e28dda9fb4719012131ed473ed8eca5
[rust.git] / src / librustc / middle / trans / uniq.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11
12 use lib::llvm::ValueRef;
13 use middle::trans::base::*;
14 use middle::trans::build::*;
15 use middle::trans::common::*;
16 use middle::trans::datum::immediate_rvalue;
17 use middle::trans::glue;
18 use middle::ty;
19
20 pub fn make_free_glue(bcx: block, vptrptr: ValueRef, box_ty: ty::t)
21     -> block {
22     let _icx = push_ctxt("uniq::make_free_glue");
23     let box_datum = immediate_rvalue(Load(bcx, vptrptr), box_ty);
24
25     let not_null = IsNotNull(bcx, box_datum.val);
26     do with_cond(bcx, not_null) |bcx| {
27         let body_datum = box_datum.box_body(bcx);
28         let bcx = glue::drop_ty(bcx, body_datum.to_ref_llval(bcx),
29                                 body_datum.ty);
30         if ty::type_contents(bcx.tcx(), box_ty).contains_managed() {
31             glue::trans_free(bcx, box_datum.val)
32         } else {
33             glue::trans_exchange_free(bcx, box_datum.val)
34         }
35     }
36 }