mescc: Tinycc support: ((unsigned char*)str)[0].

* module/language/c99/compiler.mes (expr->accu): Consider size of
  expr array deref.
* stage0/x86.M1 (movzbl_0x32(%ebp),%eax): New define.
* scaffold/tests/7d-cast-char.c: Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-08-04 11:34:01 +02:00
parent 5fadb4cbbf
commit 949e320622
4 changed files with 42 additions and 3 deletions

View file

@ -162,7 +162,8 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
"79-int-array"
"7a-struct-char-array"
"7b-struct-int-array"
"7c-dynarray"))
"7c-dynarray"
"7d-cast-char"))
(add-target (group "check-scaffold-tests/7" #:dependencies (filter (target-prefix? "check-scaffold/tests/7") %targets)))

View file

@ -592,8 +592,12 @@
;; <expr>[baz]
((array-ref ,index ,array)
(let ((info ((expr->accu* info) o)))
(append-text info (wrap-as (i386:mem->accu)))))
(let* ((info ((expr->accu* info) o))
(ptr (expr->pointer info array))
(size (if (= ptr 1) (expr->size info array)
4)))
(append-text info (wrap-as (if (= size 1) (i386:byte-mem->accu)
(i386:mem->accu))))))
;; bar.f.i
((d-sel (ident ,field1) (d-sel (ident ,field0) (p-expr (ident ,struct0))))

View file

@ -0,0 +1,33 @@
/* -*-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"
int
test ()
{
char *s = "int";
char c = s[0];
if (c != 'i') return 1;
int i = ((unsigned char *)s)[0];
if (i != 'i') return 2;
return 0;
}

View file

@ -120,6 +120,7 @@ DEFINE movzbl_%dl,%edx 0fb6d2
DEFINE movzbl_(%eax),%eax 0fb600
DEFINE movzbl_(%eax),%edx 0fb610
DEFINE movzbl_(%edx),%edx 0fb612
DEFINE movzbl_0x32(%ebp),%eax 0fb685
DEFINE movzbl_0x8(%ebp),%eax 0fb645
DEFINE movzbl_0x8(%ebp),%edx 0fb655
DEFINE mul____%edx f7e2