Skip to content

Commit a68d6af

Browse files
committed
---
yaml --- r: 83868 b: refs/heads/try c: 35a944a h: refs/heads/master v: v3
1 parent 35d36db commit a68d6af

File tree

4 files changed

+17
-60
lines changed

4 files changed

+17
-60
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 0e4d1fc8cae42e15e00f71d9f439b01bb25a86ae
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
5-
refs/heads/try: 399a42575a3a5392277e4034812ce32c4f491929
5+
refs/heads/try: 35a944a48806356e816a68ee3758f7b2f4244fca
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/librustc/lib/llvm.rs

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
use std::c_str::ToCStr;
1717
use std::hashmap::HashMap;
18-
use std::libc::{c_uint, c_ushort};
18+
use std::libc::{c_uint, c_ushort, c_void, free};
19+
use std::str::raw::from_c_str;
1920
use std::option;
2021

2122
use middle::trans::type_::Type;
@@ -1666,6 +1667,7 @@ pub mod llvm {
16661667
-> ValueRef;
16671668

16681669
pub fn LLVMDICompositeTypeSetTypeArray(CompositeType: ValueRef, TypeArray: ValueRef);
1670+
pub fn LLVMTypeToString(Type: TypeRef) -> *c_char;
16691671

16701672
pub fn LLVMIsAArgument(value_ref: ValueRef) -> ValueRef;
16711673

@@ -1789,68 +1791,15 @@ impl TypeNames {
17891791
self.named_types.find_equiv(&s).map(|x| Type::from_ref(*x))
17901792
}
17911793

1792-
// We have a depth count, because we seem to make infinite types.
1793-
pub fn type_to_str_depth(&self, ty: Type, depth: int) -> ~str {
1794-
match self.find_name(&ty) {
1795-
option::Some(name) => return name.to_owned(),
1796-
None => ()
1797-
}
1798-
1799-
if depth == 0 {
1800-
return ~"###";
1801-
}
1802-
1794+
pub fn type_to_str(&self, ty: Type) -> ~str {
18031795
unsafe {
1804-
let kind = ty.kind();
1805-
1806-
match kind {
1807-
Void => ~"Void",
1808-
Half => ~"Half",
1809-
Float => ~"Float",
1810-
Double => ~"Double",
1811-
X86_FP80 => ~"X86_FP80",
1812-
FP128 => ~"FP128",
1813-
PPC_FP128 => ~"PPC_FP128",
1814-
Label => ~"Label",
1815-
Vector => ~"Vector",
1816-
Metadata => ~"Metadata",
1817-
X86_MMX => ~"X86_MMAX",
1818-
Integer => {
1819-
format!("i{}", llvm::LLVMGetIntTypeWidth(ty.to_ref()) as int)
1820-
}
1821-
Function => {
1822-
let out_ty = ty.return_type();
1823-
let args = ty.func_params();
1824-
let args =
1825-
args.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
1826-
let out_ty = self.type_to_str_depth(out_ty, depth-1);
1827-
format!("fn({}) -> {}", args, out_ty)
1828-
}
1829-
Struct => {
1830-
let tys = ty.field_types();
1831-
let tys = tys.map(|&ty| self.type_to_str_depth(ty, depth-1)).connect(", ");
1832-
format!("\\{{}\\}", tys)
1833-
}
1834-
Array => {
1835-
let el_ty = ty.element_type();
1836-
let el_ty = self.type_to_str_depth(el_ty, depth-1);
1837-
let len = ty.array_length();
1838-
format!("[{} x {}]", el_ty, len)
1839-
}
1840-
Pointer => {
1841-
let el_ty = ty.element_type();
1842-
let el_ty = self.type_to_str_depth(el_ty, depth-1);
1843-
format!("*{}", el_ty)
1844-
}
1845-
_ => fail2!("Unknown Type Kind ({})", kind as uint)
1846-
}
1796+
let s = llvm::LLVMTypeToString(ty.to_ref());
1797+
let ret = from_c_str(s);
1798+
free(s as *c_void);
1799+
ret
18471800
}
18481801
}
18491802

1850-
pub fn type_to_str(&self, ty: Type) -> ~str {
1851-
self.type_to_str_depth(ty, 30)
1852-
}
1853-
18541803
pub fn types_to_str(&self, tys: &[Type]) -> ~str {
18551804
let strs = tys.map(|t| self.type_to_str(*t));
18561805
format!("[{}]", strs.connect(","))

branches/try/src/rustllvm/RustWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,3 +803,10 @@ extern "C" void LLVMDICompositeTypeSetTypeArray(
803803
{
804804
unwrapDI<DICompositeType>(CompositeType).setTypeArray(unwrapDI<DIArray>(TypeArray));
805805
}
806+
807+
extern "C" char *LLVMTypeToString(LLVMTypeRef Type) {
808+
std::string s;
809+
llvm::raw_string_ostream os(s);
810+
unwrap<llvm::Type>(Type)->print(os);
811+
return strdup(os.str().data());
812+
}

branches/try/src/rustllvm/rustllvm.def.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,4 @@ LLVMRustSetNormalizedTarget
628628
LLVMRustAddAlwaysInlinePass
629629
LLVMAddReturnAttribute
630630
LLVMRemoveReturnAttribute
631+
LLVMTypeToString

0 commit comments

Comments
 (0)