]> git.proxmox.com Git - rustc.git/blob - src/librustc_trans/trans/llrepr.rs
6dd566797970e5aa820675ee245706d293a424b7
[rustc.git] / src / librustc_trans / trans / llrepr.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 use trans::context::CrateContext;
12 use trans::type_::Type;
13 use llvm::ValueRef;
14
15 pub trait LlvmRepr {
16 fn llrepr(&self, ccx: &CrateContext) -> String;
17 }
18
19 impl<T:LlvmRepr> LlvmRepr for [T] {
20 fn llrepr(&self, ccx: &CrateContext) -> String {
21 let reprs: Vec<String> = self.iter().map(|t| t.llrepr(ccx)).collect();
22 format!("[{}]", reprs.connect(","))
23 }
24 }
25
26 impl LlvmRepr for Type {
27 fn llrepr(&self, ccx: &CrateContext) -> String {
28 ccx.tn().type_to_string(*self)
29 }
30 }
31
32 impl LlvmRepr for ValueRef {
33 fn llrepr(&self, ccx: &CrateContext) -> String {
34 ccx.tn().val_to_string(*self)
35 }
36 }