diff --git a/include/stdint.h b/include/stdint.h index 81f88d59..b306fa67 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software - * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2020 Jan (janneke) Nieuwenhuizen * Copyright © 2018 Peter De Wachter * * This file is part of GNU Mes. @@ -55,8 +55,10 @@ typedef unsigned short uint16_t; typedef short int16_t; typedef unsigned uint32_t; typedef int int32_t; +#if __SIZEOF_LONG_LONG__ typedef unsigned long long uint64_t; typedef long long int64_t; +#endif // __SIZEOF_LONG_LONG__ typedef int intmax_t; typedef unsigned uintmax_t; diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm index 6f334945..518e4b33 100644 --- a/module/mescc/mescc.scm +++ b/module/mescc/mescc.scm @@ -23,6 +23,7 @@ #:use-module (ice-9 getopt-long) #:use-module (mes misc) + #:use-module (mescc info) #:use-module (mescc armv4 info) #:use-module (mescc i386 info) #:use-module (mescc x86_64 info) @@ -59,7 +60,7 @@ (prefix (option-ref options 'prefix "")) (machine (option-ref options 'machine "32")) (arch (arch-get options)) - (defines (cons (arch-get-define options) defines)) + (defines (append (arch-get-defines options) defines)) (verbose? (count-opt options 'verbose))) (with-output-to-file ast-file-name (lambda _ (for-each (cut c->ast prefix defines includes arch pretty-print/write verbose? <>) files))))) @@ -96,7 +97,7 @@ (includes (cons (option-ref options 'includedir #f) includes)) (includes (cons dir includes)) (prefix (option-ref options 'prefix "")) - (defines (cons (arch-get-define options) defines)) + (defines (append (arch-get-defines options) defines)) (arch (arch-get options)) (verbose? (count-opt options 'verbose))) (with-input-from-file file-name @@ -326,11 +327,25 @@ ((equal? arch "x86") (x86-info)) ((equal? arch "x86_64") (x86_64-info))))) -(define (arch-get-define options) - (let ((arch (arch-get options))) - (cond ((equal? arch "arm") "__arm__=1") - ((equal? arch "x86") "__i386__=1") - ((equal? arch "x86_64") "__x86_64__=1")))) +(define (arch-get-defines options) + (let* ((arch (arch-get options)) + (info (arch-get-info options)) + (types (.types info))) + (define (sizeof type) + (type:size (assoc-ref types type))) + (let ((int (sizeof "int")) + (long (sizeof "long")) + (long-long (sizeof "long long"))) + (cons (cond ((equal? arch "arm") + "__arm__=1") + ((equal? arch "x86") + "__i386__=1") + ((equal? arch "x86_64") + "__x86_64__=1")) + `(,(string-append "__SIZEOF_INT__=" (number->string int)) + ,(string-append "__SIZEOF_LONG__=" (number->string long)) + ,@(if (< long-long 8) '() ;C99: long long must be >= 8 + '("__SIZEOF_LONG_LONG__=8"))))))) (define (arch-get-machine options) (let* ((machine (option-ref options 'machine #f))