mescc: Tinycc support: bugfix foo[bar] = baz, with foo*[].
* module/language/c99/compiler.mes (expr->accu): Support size for more expressions. (expr->pointer): (expr->size): Support more expressions. * scaffold/tests/77-pointer-assign.c (add0): Test it.
This commit is contained in:
parent
17e0e0cab7
commit
73148c6f78
|
@ -657,8 +657,12 @@
|
|||
(append-text info ((ident-add info) name size))))
|
||||
|
||||
((de-ref ,expr)
|
||||
(let ((info ((expr->accu info) expr)))
|
||||
(append-text info (wrap-as (i386:byte-mem->accu))))) ;; FIXME: byte
|
||||
(let* ((info ((expr->accu info) expr))
|
||||
(ptr (expr->pointer info expr))
|
||||
(size (if (= ptr 1) (expr->size info expr)
|
||||
4)))
|
||||
(append-text info (wrap-as (if (= size 1) (i386:byte-mem->accu)
|
||||
(i386:mem->accu))))))
|
||||
|
||||
((fctn-call (p-expr (ident ,name)) (expr-list . ,expr-list))
|
||||
(if (equal? name "asm") (let ((arg0 (cadr (cadar expr-list)))) ;; FIXME
|
||||
|
@ -942,7 +946,9 @@
|
|||
(append-text info (wrap-as (i386:base->accu-address)))))
|
||||
((array-ref ,index (p-expr (ident ,array)))
|
||||
(let* ((type (ident->type info array))
|
||||
(size (ast-type->size info type))
|
||||
(ptr (ident->pointer info array))
|
||||
(size (if (or (= ptr 1) (= ptr -1)) (ast-type->size info type)
|
||||
4))
|
||||
(info (append-text info (wrap-as (i386:push-accu))))
|
||||
(info ((expr->accu* info) a))
|
||||
(info (append-text info (wrap-as (i386:pop-base)))))
|
||||
|
@ -1586,11 +1592,17 @@
|
|||
(define (expr->pointer info o)
|
||||
(pmatch o
|
||||
((p-expr (ident ,name)) (ident->pointer info name))
|
||||
((de-ref ,expr) (1- (expr->pointer info expr)))
|
||||
((add ,a ,b) (expr->pointer info a))
|
||||
((sub ,a ,b) (expr->pointer info a))
|
||||
(_ (stderr "expr->pointer: unsupported: ~s\n" o) 0)))
|
||||
|
||||
(define (expr->size info o)
|
||||
(pmatch o
|
||||
((p-expr (ident ,name)) (ident->size info name))
|
||||
((de-ref ,expr) (expr->size info expr))
|
||||
((add ,a ,b) (expr->size info a))
|
||||
((sub ,a ,b) (expr->size info a))
|
||||
(_ (stderr "expr->size: unsupported: ~s\n" o) 4)))
|
||||
|
||||
(define (p-expr->type info o)
|
||||
|
|
|
@ -30,11 +30,19 @@ struct foo {
|
|||
};
|
||||
|
||||
void
|
||||
add (void *ptab)
|
||||
add0 (void *ptab)
|
||||
{
|
||||
void **pp = *(void***)ptab;
|
||||
bla:
|
||||
pp[0] = 0x11223344;
|
||||
}
|
||||
|
||||
void
|
||||
add1 (void *ptab)
|
||||
{
|
||||
void ***x = (void***)ptab;
|
||||
bla:
|
||||
*(void***)ptab = 0x11223344;
|
||||
*(void***)ptab = 0x22334455;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -42,23 +50,29 @@ add2 (void *ptab)
|
|||
{
|
||||
void ***x = (void***)ptab;
|
||||
bla:
|
||||
*x = 0x22334455;
|
||||
*x = 0x33445566;
|
||||
}
|
||||
|
||||
int
|
||||
test ()
|
||||
{
|
||||
int i;
|
||||
int i = 1;
|
||||
int *p = &i;
|
||||
struct foo f;
|
||||
f.bar = &p;
|
||||
eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n");
|
||||
add (&f.bar);
|
||||
eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n");
|
||||
if (f.bar != 0x11223344) return 1;
|
||||
add2 (&f.bar);
|
||||
|
||||
add0 (&f.bar);
|
||||
eputs ("f.bar:"); eputs (itoa (*f.bar)); eputs ("\n");
|
||||
if (*f.bar != 0x11223344) return 1;
|
||||
|
||||
add1 (&f.bar);
|
||||
eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n");
|
||||
if (f.bar != 0x22334455) return 2;
|
||||
|
||||
add2 (&f.bar);
|
||||
eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n");
|
||||
if (f.bar != 0x33445566) return 3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue