mescc: Tinycc support: struct assign by value.
* module/language/c99/compiler.mes (base->ident): Remove. (accu->ident): Use them to support assign of size >4 by value. * scaffold/tests/7h-struct-assign.c: Test it. * make.scm (add-scaffold-test): Build it. * module/mes/as-i386.mes (i386:base->local): Remove. (i386:accu*n->local): (i386:accu*n->label): New functions. * module/mes/as-i386.scm: Export them. * stage0/x86.M1: (mov____%ebx,0x32): (mov____%ebx,0x32(%ebp)): (mov____%ebx,0x8(%ebp)): (mov____%ebx,0x8(%edx)): (mov____%ecx,0x32(%ebp)): (mov____%ecx,0x8(%ebp)): (mov____0x32(%eax),%ebx): (mov____0x32(%eax),%ecx): (mov____0x8(%eax),%ebx): New define.
This commit is contained in:
parent
e616d6120b
commit
11d240e756
3
make.scm
3
make.scm
|
@ -166,7 +166,8 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
|
|||
"7d-cast-char"
|
||||
"7e-struct-array-access"
|
||||
"7f-struct-pointer-arithmetic"
|
||||
"7g-struct-byte-word-field"))
|
||||
"7g-struct-byte-word-field"
|
||||
"7h-struct-assign"))
|
||||
|
||||
(add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))
|
||||
|
||||
|
|
|
@ -380,16 +380,14 @@
|
|||
|
||||
(define (accu->ident info)
|
||||
(lambda (o)
|
||||
(let ((local (assoc-ref (.locals info) o)))
|
||||
(if local (wrap-as (i386:accu->local (local:id local)))
|
||||
(let ((ptr (ident->pointer info o)))
|
||||
(list (i386:accu->label `(#:address ,o))))))))
|
||||
|
||||
(define (base->ident info)
|
||||
(lambda (o)
|
||||
(let ((local (assoc-ref (.locals info) o)))
|
||||
(if local (wrap-as (i386:base->local (local:id local)))
|
||||
(list (i386:base->label `(#:address ,o)))))))
|
||||
(let* ((local (assoc-ref (.locals info) o))
|
||||
(ptr (ident->pointer info o))
|
||||
(size (if (= ptr -1) (ident->size info o)
|
||||
4)))
|
||||
(if local (if (<= size 4) (wrap-as (i386:accu->local (local:id local)))
|
||||
(wrap-as (i386:accu*n->local (local:id local) size)))
|
||||
(if (<= size 4) (wrap-as (i386:accu->label o))
|
||||
(wrap-as (i386:accu*n->label o size)))))))
|
||||
|
||||
(define (base->ident-address info)
|
||||
(lambda (o)
|
||||
|
@ -962,7 +960,8 @@
|
|||
((equal? op "<<=") (wrap-as (i386:accu<<base)))
|
||||
(else (error (format #f "mescc: op ~a not supported: ~a\n" op o)))))))))
|
||||
(pmatch a
|
||||
((p-expr (ident ,name)) (append-text info ((accu->ident info) name)))
|
||||
((p-expr (ident ,name))
|
||||
(append-text info ((accu->ident info) name)))
|
||||
((d-sel (ident ,field) ,p-expr)
|
||||
(let* ((type (p-expr->type info p-expr))
|
||||
(offset (field-offset info type field))
|
||||
|
|
|
@ -101,15 +101,18 @@
|
|||
`(,(if (< (abs n) #x80) `("mov____%eax,0x8(%ebp)" (#:immediate1 ,n))
|
||||
`("mov____%eax,0x32(%ebp)" (#:immediate ,n))))))
|
||||
|
||||
(define (i386:base->local n)
|
||||
(or n (error "invalid value: base->local: " n))
|
||||
`(("mov____%edx,0x8(%ebp)" ,(- 0 (* 4 n))))) ; mov %edx,-<0xn>(%ebp)
|
||||
|
||||
(define (i386:base->local n)
|
||||
(or n (error "invalid value: base->local: " n))
|
||||
(let ((n (- 0 (* 4 n))))
|
||||
`((if (< (abs n) #x80) `("mov____%edx,0x8(%ebp)" (#:immediate1 ,n))
|
||||
`("mov____%edx,0x32(%ebp)" (#:immediate ,n))))))
|
||||
(define (i386:accu*n->local i n)
|
||||
(or n (error "invalid value: accu->local: " n))
|
||||
(let ((o (- 0 (* 4 i))))
|
||||
(let loop ((i 0))
|
||||
(if (>= i n) '() ;; FIXME: byte, word-sized
|
||||
(let ((o (+ o i)))
|
||||
(append
|
||||
(if (< (abs o) #x80) `(("mov____0x8(%eax),%ebx" (#:immediate1 ,i))
|
||||
("mov____%ebx,0x8(%ebp)" (#:immediate1 ,o)))
|
||||
`(("mov____0x8(%eax),%ebx" (#:immediate1 ,i))
|
||||
("mov____%ebx,0x32(%ebp)" (#:immediate ,o))))
|
||||
(loop (+ i 4))))))))
|
||||
|
||||
(define (i386:local->accu n)
|
||||
(or n (error "invalid value: local->accu: " n))
|
||||
|
@ -223,6 +226,18 @@
|
|||
(define (i386:accu->label label)
|
||||
`(("mov____%eax,0x32" (#:address ,label)))) ; mov %eax,0x<label>
|
||||
|
||||
(define (i386:accu*n->label label n)
|
||||
(append
|
||||
'(("push___%edx"))
|
||||
(let loop ((i 0))
|
||||
(if (>= i n) '() ;; FIXME: byte, word-sized
|
||||
(append
|
||||
`(("mov____$i32,%edx" (#:address ,label))
|
||||
("mov____0x8(%eax),%ebx" (#:immediate1 ,i))
|
||||
("mov____%ebx,0x8(%edx)" (#:immediate1 ,i)))
|
||||
(loop (+ i 4)))))
|
||||
'(("pop____%edx"))))
|
||||
|
||||
(define (i386:accu-shl n)
|
||||
(or n (error "invalid value: accu:shl n: " n))
|
||||
`(("shl____$i8,%eax" (#:immediate1 ,n)))) ; shl $0x8,%eax
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#:export (
|
||||
i386:accu%base
|
||||
i386:accu*base
|
||||
i386:accu*n->label
|
||||
i386:accu*n->local
|
||||
i386:accu+accu
|
||||
i386:accu+base
|
||||
i386:accu+value
|
||||
|
@ -62,7 +64,6 @@
|
|||
i386:base->accu
|
||||
i386:base->accu-mem
|
||||
i386:base->label
|
||||
i386:base->local
|
||||
i386:base-mem->accu-mem
|
||||
i386:base-mem+n->accu
|
||||
i386:base-mem->accu
|
||||
|
|
47
scaffold/tests/7h-struct-assign.c
Normal file
47
scaffold/tests/7h-struct-assign.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* -*-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"
|
||||
#include <string.h>
|
||||
|
||||
struct string {
|
||||
char *str;
|
||||
int len;
|
||||
};
|
||||
|
||||
struct string g_t;
|
||||
|
||||
int
|
||||
test ()
|
||||
{
|
||||
struct string s = {"hallo"};
|
||||
s.len = strlen (s.str);
|
||||
struct string t;
|
||||
t = s;
|
||||
|
||||
if (t.len != s.len) return 1;
|
||||
if (strcmp (t.str, s.str)) return 2;
|
||||
|
||||
g_t = s;
|
||||
if (g_t.len != s.len) return 3;
|
||||
if (strcmp (g_t.str, s.str)) return 4;
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -92,8 +92,14 @@ DEFINE mov____%eax,0x8(%edx) 8942
|
|||
DEFINE mov____%ebp,%eax 89e8
|
||||
DEFINE mov____%ebp,%ecx 89e9
|
||||
DEFINE mov____%ebp,%edx 89ea
|
||||
DEFINE mov____%ebx,0x32 891d
|
||||
DEFINE mov____%ebx,0x32(%ebp) 899d
|
||||
DEFINE mov____%ebx,0x8(%ebp) 895d
|
||||
DEFINE mov____%ebx,0x8(%edx) 895a
|
||||
DEFINE mov____%ecx,(%eax) 8908
|
||||
DEFINE mov____%ecx,(%edx) 890a
|
||||
DEFINE mov____%ecx,0x32(%ebp) 898d
|
||||
DEFINE mov____%ecx,0x8(%ebp) 894d
|
||||
DEFINE mov____%edx,%eax 89d0
|
||||
DEFINE mov____%edx,%ebx 89d3
|
||||
DEFINE mov____%edx,%ecx 89d1
|
||||
|
@ -106,6 +112,8 @@ DEFINE mov____(%eax),%ecx 8b08
|
|||
DEFINE mov____(%edx),%ecx 8b0a
|
||||
DEFINE mov____(%edx),%edx 8b12
|
||||
DEFINE mov____0x32(%eax),%eax 8b80
|
||||
DEFINE mov____0x32(%eax),%ebx 8b98
|
||||
DEFINE mov____0x32(%eax),%ecx 8b88
|
||||
DEFINE mov____0x32(%ebp),%eax 8b85
|
||||
DEFINE mov____0x32(%ebp),%eax 8b85
|
||||
DEFINE mov____0x32(%ebp),%ebx 8b9d
|
||||
|
@ -115,6 +123,8 @@ DEFINE mov____0x32(%ebp),%edx 8b95
|
|||
DEFINE mov____0x32,%eax a1
|
||||
DEFINE mov____0x32,%edx 8b15
|
||||
DEFINE mov____0x8(%eax),%eax 8b40
|
||||
DEFINE mov____0x8(%eax),%ebx 8b58
|
||||
DEFINE mov____0x8(%eax),%ecx 8b48
|
||||
DEFINE mov____0x8(%ebp),%eax 8b45
|
||||
DEFINE mov____0x8(%ebp),%ebx 8b5d
|
||||
DEFINE mov____0x8(%ebp),%ecx 8b4d
|
||||
|
|
Loading…
Reference in a new issue