]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/trans/llrepr.rs
core: rename strbuf::StrBuf to string::String
[rust.git] / src / librustc / middle / 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 middle::trans::context::CrateContext;
12 use middle::trans::type_::Type;
13 use lib::llvm::ValueRef;
14
15 pub trait LlvmRepr {
16     fn llrepr(&self, ccx: &CrateContext) -> String;
17 }
18
19 impl<'a, T:LlvmRepr> LlvmRepr for &'a [T] {
20     fn llrepr(&self, ccx: &CrateContext) -> String {
21         let reprs: Vec<String> = self.iter().map(|t| t.llrepr(ccx)).collect();
22         format_strbuf!("[{}]", reprs.connect(","))
23     }
24 }
25
26 impl LlvmRepr for Type {
27     fn llrepr(&self, ccx: &CrateContext) -> String {
28         ccx.tn.type_to_str(*self)
29     }
30 }
31
32 impl LlvmRepr for ValueRef {
33     fn llrepr(&self, ccx: &CrateContext) -> String {
34         ccx.tn.val_to_str(*self)
35     }
36 }
37
38