Add partial support for pointer arithmetic.

Only pointer +/- integral is supported. pointer - pointer will come later.
This commit is contained in:
Bill Currie 2012-11-03 14:03:28 +09:00
parent afbab60c25
commit 48fe9f729d
2 changed files with 25 additions and 0 deletions

View file

@ -450,6 +450,13 @@ do_op_pointer (int op, expr_t *e, expr_t *e1, expr_t *e2)
type_t *type;
static int valid[] = {'=', PAS, '&', 'M', '.', EQ, NE, 0};
if (is_integral (type = get_type (e2)) && (op == '-' || op == '+')) {
// pointer arithmetic
expr_t *ptoi = new_alias_expr (type, e1);
e->e.expr.e1 = ptoi;
e = fold_constants (e);
return new_alias_expr (get_type (e1), e);
}
if (!valid_op (op, valid))
return error (e1, "invalid operator for pointer");

View file

@ -33,3 +33,21 @@ weapon_range =
}
};
void
duffs_device (int *to, int *from, int count)
{
int n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to = *from++;
case 7: *to = *from++;
case 6: *to = *from++;
case 5: *to = *from++;
case 4: *to = *from++;
case 3: *to = *from++;
case 2: *to = *from++;
case 1: *to = *from++;
} while(--n > 0);
}
}