6/simp.c
/* Simplifies taking a slice of an array, pointer,
 * or other slice down to primitive pointer operations */
Simplifies taking a slice of an array, pointer,
or other slice down to primitive pointer operations
Simplifies taking a slice of an array pointer or other slice down to primitive pointer operations
static Node *simpslice(Simp *s, Node *n, Node *dst)
{
    Node *t;
    Node *start, *end;
    Node *base, *sz, *len;
    Node *stbase, *stlen;
    if (dst)
        t = dst;
    else
        t = temp(s, n);
    base = slicebase(s, n->expr.args[0], n->expr.args[1]);
    start = ptrsized(s, rval(s, n->expr.args[1], NULL));
    end = ptrsized(s, rval(s, n->expr.args[2], NULL));
    len = sub(end, start);
    if (tybase(exprtype(t))->type == Typtr) {
        stbase = set(simpcast(s, t, mktyptr(t->loc, tyintptr)), base);
        sz = addk(simpcast(s, t, mktyptr(t->loc, tyintptr)), Ptrsz);
    } else {
        stbase = set(deref(addr(s, t, tyintptr), NULL), base);
        sz = addk(addr(s, t, tyintptr), Ptrsz);
    }
    stlen = set(deref(sz, NULL), len);
    append(s, stbase);
    append(s, stlen);
    return t;
}
static Node * simpslice ( Simp * s , Node * n , Node * dst ) { Node * t ; Node * start , * end ; Node * base , * sz , * len ; Node * stbase , * stlen ; if ( dst ) t = dst ; else t = temp ( s , n ) ; base = slicebase ( s , n -> expr . args [ 0 ] , n -> expr . args [ 1 ] ) ; start = ptrsized ( s , rval ( s , n -> expr . args [ 1 ] , NULL ) ) ; end = ptrsized ( s , rval ( s , n -> expr . args [ 2 ] , NULL ) ) ; len = sub ( end , start ) ; if ( tybase ( exprtype ( t ) ) -> type == Typtr ) { stbase = set ( simpcast ( s , t , mktyptr ( t -> loc , tyintptr ) ) , base ) ; sz = addk ( simpcast ( s , t , mktyptr ( t -> loc , tyintptr ) ) , Ptrsz ) ; } else { stbase = set ( deref ( addr ( s , t , tyintptr ) , NULL ) , base ) ; sz = addk ( addr ( s , t , tyintptr ) , Ptrsz ) ; } stlen = set ( deref ( sz , NULL ) , len ) ; append ( s , stbase ) ; append ( s , stlen ) ; return t ; }
Simplifies taking a slice of an array, pointer,
 or other slice down to primitive pointer operations
Simplifies taking a slice of an array pointer or other slice down to primitive pointer operations
/* *(&slice) = (void*)base + off*sz */ /* we can be storing through a pointer, in the case
     * of '*foo = bar'. */ /* *(&slice + ptrsz) = len */