about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Sullivan <sully@msully.net>2011-08-01 15:08:16 -0700
committerMichael Sullivan <sully@msully.net>2011-08-01 15:18:44 -0700
commita32f287c8a528143566972721be88344a35eb81b (patch)
tree4eb27c399d2530b72a97a94f6616667a05021346 /src
parent7b87fa368333130830aea07f3d01aff4b009cbaa (diff)
downloadrust-a32f287c8a528143566972721be88344a35eb81b.tar.gz
rust-a32f287c8a528143566972721be88344a35eb81b.zip
Add a GEPi function that wraps GEP with integer arguments.
Diffstat (limited to 'src')
-rw-r--r--src/comp/middle/trans.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 90ce96e415f..29efc4f9339 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -662,6 +662,26 @@ fn dynamic_align_of(cx: &@block_ctxt, t: &ty::t) -> result {
     }
 }
 
+// Simple wrapper around GEP that takes an array of ints and wraps them
+// in C_int()
+fn GEPi(cx: &@block_ctxt, base: ValueRef, ixs: &int[]) -> ValueRef {
+    let v: ValueRef[] = ~[];
+    for i: int  in ixs { v += ~[C_int(i)]; }
+    ret cx.build.GEP(base, v);
+}
+
+// Increment a pointer by a given amount and then cast it to be a pointer
+// to a given type.
+fn bump_ptr(bcx: &@block_ctxt, t: &ty::t, base: ValueRef, sz: ValueRef)
+    -> ValueRef {
+    let raw = bcx.build.PointerCast(base, T_ptr(T_i8()));
+    let bumped = bcx.build.GEP(raw, ~[sz]);
+    if ty::type_has_dynamic_size(bcx_tcx(bcx), t) {
+        ret bumped;
+    }
+    let typ = T_ptr(type_of(bcx_ccx(bcx), bcx.sp, t));
+    ret bcx.build.PointerCast(bumped, typ);
+}
 
 // Replacement for the LLVM 'GEP' instruction when field-indexing into a
 // tuple-like structure (tup, rec) with a static index. This one is driven off
@@ -672,11 +692,8 @@ fn GEP_tup_like(cx: &@block_ctxt, t: &ty::t, base: ValueRef, ixs: &int[]) ->
    result {
     assert (ty::type_is_tup_like(bcx_tcx(cx), t));
     // It might be a static-known type. Handle this.
-
     if !ty::type_has_dynamic_size(bcx_tcx(cx), t) {
-        let v: ValueRef[] = ~[];
-        for i: int  in ixs { v += ~[C_int(i)]; }
-        ret rslt(cx, cx.build.GEP(base, v));
+        ret rslt(cx, GEPi(cx, base, ixs));
     }
     // It is a dynamic-containing type that, if we convert directly to an LLVM
     // TypeRef, will be all wrong; there's no proper LLVM type to represent
@@ -745,14 +762,7 @@ fn GEP_tup_like(cx: &@block_ctxt, t: &ty::t, base: ValueRef, ixs: &int[]) ->
 
     let bcx = cx;
     let sz = size_of(bcx, prefix_ty);
-    bcx = sz.bcx;
-    let raw = bcx.build.PointerCast(base, T_ptr(T_i8()));
-    let bumped = bcx.build.GEP(raw, ~[sz.val]);
-    if ty::type_has_dynamic_size(bcx_tcx(cx), s.target) {
-        ret rslt(bcx, bumped);
-    }
-    let typ = T_ptr(type_of(bcx_ccx(bcx), bcx.sp, s.target));
-    ret rslt(bcx, bcx.build.PointerCast(bumped, typ));
+    ret rslt(sz.bcx, bump_ptr(sz.bcx, s.target, base, sz.val));
 }