mescc: Tinycc support: ~, ^=.

* module/mes/as-i386.mes (i386:accu-not): New function.
  (i386:accu-negate): Rename from i386:accu-not.
* module/mes/as-i386.scm (mes): Export them.
* module/language/c99/compiler.mes (expr->accu): Support ~, ^=.
* scaffold/tests/60-math.c (test): Test it.
* stage0/x86.M1 (not____%eax): New define.
This commit is contained in:
Jan Nieuwenhuizen 2017-07-21 10:39:04 +02:00
parent cccbfe4c61
commit eff1e97cdf
5 changed files with 21 additions and 9 deletions

View File

@ -738,8 +738,11 @@
((add ,a ,b) ((binop->accu info) a b (i386:accu+base)))
((sub ,a ,b) ((binop->accu info) a b (i386:accu-base)))
((bitwise-or ,a ,b) ((binop->accu info) a b (i386:accu-or-base)))
((bitwise-and ,a ,b) ((binop->accu info) a b (i386:accu-and-base)))
((bitwise-not ,expr)
(let ((info ((ast->info info) expr)))
(append-text info (wrap-as (i386:accu-not)))))
((bitwise-or ,a ,b) ((binop->accu info) a b (i386:accu-or-base)))
((bitwise-xor ,a ,b) ((binop->accu info) a b (i386:accu-xor-base)))
((lshift ,a ,b) ((binop->accu info) a b (i386:accu<<base)))
((rshift ,a ,b) ((binop->accu info) a b (i386:accu>>base)))
@ -751,7 +754,7 @@
(let* ((test-info ((ast->info info) expr)))
(clone info #:text
(append (.text test-info)
(wrap-as (i386:accu-not)))
(wrap-as (i386:accu-negate)))
#:globals (.globals test-info))))
((neg (p-expr (fixed ,value)))
@ -832,9 +835,10 @@
((equal? op "*=") (wrap-as (i386:accu*base)))
((equal? op "/=") (wrap-as (i386:accu/base)))
((equal? op "%=") (wrap-as (i386:accu%base)))
((equal? op "|=") (wrap-as (i386:accu-or-base)))
((equal? op "&=") (wrap-as (i386:accu-and-base)))
(else (error "mescc: op ~a not supported: ~a\n" op o))))))))
((equal? op "|=") (wrap-as (i386:accu-or-base)))
((equal? op "^=") (wrap-as (i386:accu-xor-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)))
((d-sel (ident ,field) ,p-expr)

View File

@ -136,12 +136,15 @@
("mov____%edx,%ecx") ; mov %edx,%ecx
("shr____%cl,%eax"))) ; shr %cl,%eax
(define (i386:accu-or-base)
'(("or_____%edx,%eax"))) ; or %edx,%eax
(define (i386:accu-and-base)
'(("and____%edx,%eax"))) ; and %edx,%eax
(define (i386:accu-not)
'(("not____%eax"))) ; not %eax
(define (i386:accu-or-base)
'(("or_____%edx,%eax"))) ; or %edx,%eax
(define (i386:accu-xor-base)
'(("xor____%edx,%eax"))) ; xor %edx,%eax
@ -318,7 +321,7 @@
("call___*%eax") ; call *%eax
("add____$i8,%esp" (#:immediate1 ,(* n 4))))) ; add $00,%esp
(define (i386:accu-not)
(define (i386:accu-negate)
'(("sete___%al") ; sete %al
("movzbl_%al,%eax"))) ; movzbl %al,%eax

View File

@ -28,7 +28,6 @@
#:use-module (mes guile)
#:use-module (mes as)
#:export (
i386:accu-not
i386:accu-cmp-value
i386:accu->base
i386:accu->base-address
@ -47,6 +46,8 @@
i386:accu-base
i386:accu-shl
i386:accu-and-base
i386:accu-negate
i386:accu-not
i386:accu-or-base
i386:accu-xor-base
i386:accu<<base

View File

@ -122,6 +122,9 @@ test ()
puts ("t: 1 & 3\n");
if ((1 & 3) != 1) return 1;
puts ("t: ~0\n");
if (~0 != -1) return 1;
puts ("t: 1 | 3\n");
if ((1 | 2) != 3) return 1;

View File

@ -48,6 +48,7 @@ DEFINE lea____0x8(%ebp),%eax 8d45
DEFINE lea____0x8(%ebp),%edx 8d55
DEFINE leave c9
DEFINE nop 90
DEFINE not____%eax f7d0
DEFINE mov____$i32,%eax b8
DEFINE mov____$i32,%ebx bb
DEFINE mov____$i32,%ecx b9