mescc: Tinycc support: bugfix *(cast)foo = bar.

* module/language/c99/compiler.mes (expr->accu): Thinko for de-ref assign.
* stage0/x86.M1: Fix typos.
* module/mes/as-i386.mes: Update for typos.
* scaffold/tests/77-pointer-assign.c: Test it.
* make.scm (add-scaffold-test): Build it.
This commit is contained in:
Jan Nieuwenhuizen 2017-07-28 15:27:25 +02:00
parent c7547dfd52
commit 2e0c1c0aff
5 changed files with 76 additions and 8 deletions

View file

@ -156,7 +156,8 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
"73-union"
"74-multi-line-string"
"75-struct-union"
"76-pointer-arithmetic"))
"76-pointer-arithmetic"
"77-pointer-assign"))
(add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))

View file

@ -924,10 +924,12 @@
(size (if (= ptr 1) (ast-type->size info type)
4)))
(append-text info (append (wrap-as (i386:accu->base))
((base->ident-address info) name)))))
((base->ident-address info) name))))) ; FIXME: size
((de-ref ,expr)
(let ((info ((expr->base info) expr)))
(append-text info (wrap-as (i386:mem->base))))) ;; FIXME: size
(let* ((info ((expr->base info) expr))
(ptr (expr->pointer info expr))
(size (expr->size info expr)))
(append-text info (wrap-as (i386:accu->base-address)))))
((array-ref ,index (d-sel (ident ,field) (p-expr (ident ,struct))))
(let* ((info (append-text info (wrap-as (i386:push-accu))))
(info ((expr->accu* info) a))

View file

@ -332,11 +332,11 @@
`("mov____$i32,0x32(%eax)" (#:immediate ,n) (#:immediate ,v)))))
(define (i386:base->accu-address)
'(("mov____%edx,%(eax)"))) ; mov %edx,(%eax)
'(("mov____%edx,(%eax)"))) ; mov %edx,(%eax)
(define (i386:base-address->accu-address)
'(("mov____(%edx),%ecx") ; mov (%edx),%ecx
("mov____%ecx,%(eax)"))) ; mov %ecx,(%eax)
("mov____%ecx,(%eax)"))) ; mov %ecx,(%eax)
(define (i386:byte-base->accu-address)
'(("mov____%dl,(%eax)"))) ; mov %dl,(%eax)

View file

@ -0,0 +1,65 @@
/* -*-comment-start: "//";comment-end:""-*-
* Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of Mes.
*
* Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include "30-test.i"
struct baz {
int i;
};
struct foo {
int **bar;
};
void
add (void *ptab)
{
void ***x = (void***)ptab;
bla:
*(void***)ptab = 0x11223344;
}
void
add2 (void *ptab)
{
void ***x = (void***)ptab;
bla:
*x = 0x22334455;
}
int
test ()
{
int i;
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);
// FIXME
// eputs ("f.bar:"); eputs (itoa (f.bar)); eputs ("\n");
// if (f.bar != 0x22334455) return 2;
return 0;
}

View file

@ -86,11 +86,11 @@ DEFINE mov____%eax,0x8(%edx) 8942
DEFINE mov____%ebp,%eax 89e8
DEFINE mov____%ebp,%ecx 89e9
DEFINE mov____%ebp,%edx 89ea
DEFINE mov____%ecx,%(eax) 8908
DEFINE mov____%edx,%(eax) 8910
DEFINE mov____%ecx,(%eax) 8908
DEFINE mov____%edx,%eax 89d0
DEFINE mov____%edx,%ebx 86d3
DEFINE mov____%edx,%ecx 89d1
DEFINE mov____%edx,(%eax) 8910
DEFINE mov____%edx,0x32(%ebp) 8995
DEFINE mov____%edx,0x8(%ebp) 8955
DEFINE mov____%esp,%ebp 89e5