mescc: Add __SIZEOF defines for int, long, long long.
* module/mescc/mescc.scm (arch-get-define): Rename to... (arch-get-defines): ...this. Return a list of defines: Also adding __SIZEOF_INT__, __SIZEOF_LONG__, and add __SIZEOF_LONG_LONG__ if it's >=8. (mescc:preprocess, c->info): Update callers. * include/stdint.h[!__SIZEOF_LONG_LONG__]: Remove typedefs for int64_t, uint16_t.
This commit is contained in:
parent
4f66055f3b
commit
afc922d1e2
|
@ -1,6 +1,6 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2017,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
* Copyright © 2018 Peter De Wachter <pdewacht@gmail.com>
|
* Copyright © 2018 Peter De Wachter <pdewacht@gmail.com>
|
||||||
*
|
*
|
||||||
* This file is part of GNU Mes.
|
* This file is part of GNU Mes.
|
||||||
|
@ -55,8 +55,10 @@ typedef unsigned short uint16_t;
|
||||||
typedef short int16_t;
|
typedef short int16_t;
|
||||||
typedef unsigned uint32_t;
|
typedef unsigned uint32_t;
|
||||||
typedef int int32_t;
|
typedef int int32_t;
|
||||||
|
#if __SIZEOF_LONG_LONG__
|
||||||
typedef unsigned long long uint64_t;
|
typedef unsigned long long uint64_t;
|
||||||
typedef long long int64_t;
|
typedef long long int64_t;
|
||||||
|
#endif // __SIZEOF_LONG_LONG__
|
||||||
|
|
||||||
typedef int intmax_t;
|
typedef int intmax_t;
|
||||||
typedef unsigned uintmax_t;
|
typedef unsigned uintmax_t;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#:use-module (ice-9 getopt-long)
|
#:use-module (ice-9 getopt-long)
|
||||||
#:use-module (mes misc)
|
#:use-module (mes misc)
|
||||||
|
|
||||||
|
#:use-module (mescc info)
|
||||||
#:use-module (mescc armv4 info)
|
#:use-module (mescc armv4 info)
|
||||||
#:use-module (mescc i386 info)
|
#:use-module (mescc i386 info)
|
||||||
#:use-module (mescc x86_64 info)
|
#:use-module (mescc x86_64 info)
|
||||||
|
@ -59,7 +60,7 @@
|
||||||
(prefix (option-ref options 'prefix ""))
|
(prefix (option-ref options 'prefix ""))
|
||||||
(machine (option-ref options 'machine "32"))
|
(machine (option-ref options 'machine "32"))
|
||||||
(arch (arch-get options))
|
(arch (arch-get options))
|
||||||
(defines (cons (arch-get-define options) defines))
|
(defines (append (arch-get-defines options) defines))
|
||||||
(verbose? (count-opt options 'verbose)))
|
(verbose? (count-opt options 'verbose)))
|
||||||
(with-output-to-file ast-file-name
|
(with-output-to-file ast-file-name
|
||||||
(lambda _ (for-each (cut c->ast prefix defines includes arch pretty-print/write verbose? <>) files)))))
|
(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 (option-ref options 'includedir #f) includes))
|
||||||
(includes (cons dir includes))
|
(includes (cons dir includes))
|
||||||
(prefix (option-ref options 'prefix ""))
|
(prefix (option-ref options 'prefix ""))
|
||||||
(defines (cons (arch-get-define options) defines))
|
(defines (append (arch-get-defines options) defines))
|
||||||
(arch (arch-get options))
|
(arch (arch-get options))
|
||||||
(verbose? (count-opt options 'verbose)))
|
(verbose? (count-opt options 'verbose)))
|
||||||
(with-input-from-file file-name
|
(with-input-from-file file-name
|
||||||
|
@ -326,11 +327,25 @@
|
||||||
((equal? arch "x86") (x86-info))
|
((equal? arch "x86") (x86-info))
|
||||||
((equal? arch "x86_64") (x86_64-info)))))
|
((equal? arch "x86_64") (x86_64-info)))))
|
||||||
|
|
||||||
(define (arch-get-define options)
|
(define (arch-get-defines options)
|
||||||
(let ((arch (arch-get options)))
|
(let* ((arch (arch-get options))
|
||||||
(cond ((equal? arch "arm") "__arm__=1")
|
(info (arch-get-info options))
|
||||||
((equal? arch "x86") "__i386__=1")
|
(types (.types info)))
|
||||||
((equal? arch "x86_64") "__x86_64__=1"))))
|
(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)
|
(define (arch-get-machine options)
|
||||||
(let* ((machine (option-ref options 'machine #f))
|
(let* ((machine (option-ref options 'machine #f))
|
||||||
|
|
Loading…
Reference in a new issue