Skip to content

Commit f1431ad

Browse files
committed
rustc: Add a generic struct_elt() function to trans
1 parent 451fc17 commit f1431ad

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/comp/middle/trans.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,15 @@ fn val_str(type_names tn, ValueRef v) -> str {
347347
ret ty_str(tn, val_ty(v));
348348
}
349349

350+
// Returns the nth element of the given LLVM structure type.
351+
fn struct_elt(TypeRef llstructty, uint n) -> TypeRef {
352+
auto elt_count = llvm::LLVMCountStructElementTypes(llstructty);
353+
assert (n < elt_count);
354+
auto elt_tys = vec::init_elt(T_nil(), elt_count);
355+
llvm::LLVMGetStructElementTypes(llstructty, vec::buf(elt_tys));
356+
ret llvm::LLVMGetElementType(elt_tys.(n));
357+
}
358+
350359

351360
// LLVM type constructors.
352361

@@ -7686,10 +7695,7 @@ fn trans_mod(@local_ctxt cx, &ast::_mod m) {
76867695

76877696
fn get_pair_fn_ty(TypeRef llpairty) -> TypeRef {
76887697
// Bit of a kludge: pick the fn typeref out of the pair.
7689-
let vec[TypeRef] pair_tys = [T_nil(), T_nil()];
7690-
llvm::LLVMGetStructElementTypes(llpairty,
7691-
vec::buf[TypeRef](pair_tys));
7692-
ret llvm::LLVMGetElementType(pair_tys.(0));
7698+
ret struct_elt(llpairty, 0u);
76937699
}
76947700

76957701
fn decl_fn_and_pair(&@crate_ctxt ccx, &span sp,

0 commit comments

Comments
 (0)