@@ -2141,7 +2141,7 @@ impl TypeNames {
2141
2141
}
2142
2142
2143
2143
pub fn find_name < ' r > ( & ' r self , ty : & Type ) -> Option < & ' r str > {
2144
- match self . type_names . find ( ty. to_ref ( ) ) {
2144
+ match self . type_names . find ( & ty. to_ref ( ) ) {
2145
2145
Some ( a) => Some ( a. slice ( 0 , a. len ( ) ) ) ,
2146
2146
None => None
2147
2147
}
@@ -2151,14 +2151,14 @@ impl TypeNames {
2151
2151
self . named_types . find_equiv ( & s) . map_consume ( |x| Type :: from_ref ( * x) )
2152
2152
}
2153
2153
2154
- pub fn type_to_str ( & self , ty : TypeRef ) -> ~str {
2154
+ pub fn type_to_str ( & self , ty : Type ) -> ~str {
2155
2155
match self . find_name ( & ty) {
2156
2156
option:: Some ( name) => return name. to_owned ( ) ,
2157
2157
None => ( )
2158
2158
}
2159
2159
2160
2160
unsafe {
2161
- let kind = llvm :: LLVMGetTypeKind ( ty ) ;
2161
+ let kind = ty . kind ( ) ;
2162
2162
2163
2163
match kind {
2164
2164
Void => ~"Void ",
@@ -2172,31 +2172,28 @@ impl TypeNames {
2172
2172
Metadata => ~"Metadata ",
2173
2173
X86_MMX => ~"X86_MMAX ",
2174
2174
Integer => {
2175
- fmt ! ( "i%d" , llvm:: LLVMGetIntTypeWidth ( ty) as int)
2175
+ fmt ! ( "i%d" , llvm:: LLVMGetIntTypeWidth ( ty. to_ref ( ) ) as int)
2176
2176
}
2177
2177
Function => {
2178
- let out_ty = llvm:: LLVMGetReturnType ( ty) ;
2179
- let n_args = llvm:: LLVMCountParamTypes ( ty) as uint ;
2180
- let args = vec:: from_elem ( n_args, 0 as TypeRef ) ;
2181
- llvm:: LLVMGetParamTypes ( ty, vec:: raw:: to_ptr ( args) ) ;
2182
-
2178
+ let out_ty = ty. return_type ( ) ;
2179
+ let args = ty. func_params ( ) ;
2183
2180
let args = args. map ( |& ty| self . type_to_str ( ty) ) . connect ( ", " ) ;
2184
2181
let out_ty = self . type_to_str ( out_ty) ;
2185
2182
fmt ! ( "fn(%s) -> %s" , args, out_ty)
2186
2183
}
2187
2184
Struct => {
2188
- let tys = struct_tys ( ty ) ;
2185
+ let tys = ty . field_types ( ) ;
2189
2186
let tys = tys. map ( |& ty| self . type_to_str ( ty) ) . connect ( ", " ) ;
2190
2187
fmt ! ( "{%s}" , tys)
2191
2188
}
2192
2189
Array => {
2193
- let el_ty = llvm :: LLVMGetElementType ( ty ) ;
2190
+ let el_ty = ty . element_type ( ) ;
2194
2191
let el_ty = self . type_to_str ( el_ty) ;
2195
- let len = llvm :: LLVMGetArrayLength ( ty ) as uint ;
2192
+ let len = ty . array_length ( ) ;
2196
2193
fmt ! ( "[%s x %u]" , el_ty, len)
2197
2194
}
2198
2195
Pointer => {
2199
- let el_ty = llvm :: LLVMGetElementType ( ty ) ;
2196
+ let el_ty = ty . element_type ( ) ;
2200
2197
let el_ty = self . type_to_str ( el_ty) ;
2201
2198
fmt ! ( "*%s" , el_ty)
2202
2199
}
@@ -2207,32 +2204,12 @@ impl TypeNames {
2207
2204
2208
2205
pub fn val_to_str ( & self , val : ValueRef ) -> ~str {
2209
2206
unsafe {
2210
- self . type_to_str ( llvm:: LLVMTypeOf ( val) )
2207
+ let ty = Type :: from_ref ( llvm:: LLVMTypeOf ( val) ) ;
2208
+ self . type_to_str ( ty)
2211
2209
}
2212
2210
}
2213
2211
}
2214
2212
2215
- pub fn float_width ( llt : TypeRef ) -> uint {
2216
- unsafe {
2217
- return match llvm:: LLVMGetTypeKind ( llt) as int {
2218
- 1 => 32 u,
2219
- 2 => 64 u,
2220
- 3 => 80 u,
2221
- 4 | 5 => 128 u,
2222
- _ => fail ! ( "llvm_float_width called on a non-float type" )
2223
- } ;
2224
- }
2225
- }
2226
-
2227
- pub fn fn_ty_param_tys ( fn_ty : TypeRef ) -> ~[ TypeRef ] {
2228
- unsafe {
2229
- let args = vec:: from_elem ( llvm:: LLVMCountParamTypes ( fn_ty) as uint ,
2230
- 0 as TypeRef ) ;
2231
- llvm:: LLVMGetParamTypes ( fn_ty, vec:: raw:: to_ptr ( args) ) ;
2232
- return args;
2233
- }
2234
- }
2235
-
2236
2213
2237
2214
/* Memory-managed interface to target data. */
2238
2215
0 commit comments