From eff1e97cdf791a2cd88073a64040ad4d2bb73e44 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 21 Jul 2017 10:39:04 +0200 Subject: [PATCH] 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. --- module/language/c99/compiler.mes | 12 ++++++++---- module/mes/as-i386.mes | 11 +++++++---- module/mes/as-i386.scm | 3 ++- scaffold/tests/60-math.c | 3 +++ stage0/x86.M1 | 1 + 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 70f0e0c0..99cba7d9 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -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<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) diff --git a/module/mes/as-i386.mes b/module/mes/as-i386.mes index 06c12b7f..df5de255 100644 --- a/module/mes/as-i386.mes +++ b/module/mes/as-i386.mes @@ -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 diff --git a/module/mes/as-i386.scm b/module/mes/as-i386.scm index ea6e573a..a1c3ae48 100644 --- a/module/mes/as-i386.scm +++ b/module/mes/as-i386.scm @@ -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<