7a8a2fc517
* module/mescc/as.scm: Support abstracted assembly. * module/mescc/i386/as.scm: Rewrite. * module/mescc/x86_64/as.scm: Implement. * module/mescc/compile.scm: Refactor to abstracted assembly. * module/mescc/M1.scm: Update for partial 64 bit support. * module/mescc/bytevectors.scm (bytevector-u64-native-set!): New procedure. * module/mescc/i386/info.scm (i386:type-alist): Use 4 byte type length also for faking double, long long, long double. * module/mescc/info.scm:modified: * module/mescc/x86_64/info.scm (x86_64:registers): New variable. * lib/x86-mes/x86.M1: Update for new register scheme. * lib/x86_64-mes/x86_64.M1: Implement. * lib/x86-mes/setjmp.c: Implement. * lib/x86_64-mes-gcc/setjmp.c: Implement. * build-aux/build-cc.sh: Update for x86_64. * build-aux/build-cc32.sh: Likewise. * build-aux/build-mes.sh: Likewise. * build-aux/build-x86_64-mes.sh: Likewise. * build-aux/check-mescc.sh: Likewise. * build-aux/test64.sh: Likewise. * include/libmes.h: Likewise. * include/setjmp.h: Likewise. * include/signal.h: Likewise. * include/stdarg.h: Likewise. * include/sys/stat.h: Likewise. * include/sys/types.h: Likewise. * include/sys/wait.h: Likewise. * include/unistd.h: Likewise. * lib/libc+gnu.c: Likewise. * lib/libc+tcc.c: Likewise. * lib/linux/gnu.c: Likewise. * lib/linux/libc-mini.c: Likewise. * lib/linux/libc.c: Likewise. * lib/linux/tcc.c: Likewise. * lib/linux/x86_64-mes-gcc/mes.c: Likewise. * lib/linux/x86_64-mes/crt1.c: Likewise. * lib/mes/abtol.c: Likewise. * lib/posix/mktemp.c: Likewise. * lib/posix/wait.c: Likewise. * lib/stdio/fopen.c: Likewise. * lib/stdio/fputc.c: Likewise. * lib/stdio/fseek.c: Likewise. * lib/stdio/printf.c: Likewise. * lib/stdio/sprintf.c: Likewise. * lib/stdio/vfprintf.c: Likewise. * lib/stdio/vsprintf.c: Likewise. * lib/stdio/vsscanf.c: Likewise. * lib/stdlib/qsort.c: Likewise. * lib/x86-mes-gcc/setjmp.c: Likewise. * scaffold/tests/11-if-1.c: Likewise. * scaffold/tests/15-if-!f.c: Likewise. * scaffold/tests/16-if-t.c: Likewise. * scaffold/tests/21-char[].c: Likewise. * scaffold/tests/23-pointer.c: Likewise. * scaffold/tests/32-compare.c: Likewise. * scaffold/tests/33-and-or.c: Likewise. * scaffold/tests/34-pre-post.c: Likewise. * scaffold/tests/35-compare-char.c: Likewise. * scaffold/tests/36-compare-arithmetic.c: Likewise. * scaffold/tests/37-compare-assign.c: Likewise. * scaffold/tests/38-compare-call.c: Likewise. * scaffold/tests/40-if-else.c: Likewise. * scaffold/tests/41-?.c: Likewise. * scaffold/tests/42-goto-label.c: Likewise. * scaffold/tests/43-for-do-while.c: Likewise. * scaffold/tests/44-switch.c: Likewise. * scaffold/tests/45-void-call.c: Likewise. * scaffold/tests/46-function-static.c: Likewise. * scaffold/tests/51-strcmp.c: Likewise. * scaffold/tests/51-strncmp.c: Likewise. * scaffold/tests/53-strcpy.c: Likewise. * scaffold/tests/54-argv.c: Likewise. * scaffold/tests/60-math.c: Likewise. * scaffold/tests/61-array.c: Likewise. * scaffold/tests/63-struct-cell.c: Likewise. * scaffold/tests/64-make-cell.c: Likewise. * scaffold/tests/65-read.c: Likewise. * scaffold/tests/70-printf.c: Likewise. * scaffold/tests/71-struct-array.c: Likewise. * scaffold/tests/72-typedef-struct-def.c: Likewise. * scaffold/tests/74-multi-line-string.c: Likewise. * scaffold/tests/76-pointer-arithmetic.c: Likewise. * scaffold/tests/79-int-array.c: Likewise. * scaffold/tests/7a-struct-char-array.c: Likewise. * scaffold/tests/7b-struct-int-array.c: Likewise. * scaffold/tests/7i-struct-struct.c: Likewise. * scaffold/tests/7k-for-each-elem.c: Likewise. * scaffold/tests/7l-struct-any-size-array.c: Likewise. * scaffold/tests/7o-struct-pre-post.c: Likewise. * scaffold/tests/7q-bit-field.c: Likewise. * scaffold/tests/7s-struct-short.c: Likewise. * scaffold/tests/80-setjmp.c: Likewise. * scaffold/tests/81-qsort.c: Likewise. * scaffold/tests/85-sizeof.c: Likewise. * scaffold/tests/87-sscanf.c: Likewise. * scaffold/tests/90-strpbrk.c: Likewise. * scaffold/tests/91-fseek.c: Likewise. * scaffold/tests/95-signal.c: Likewise. * scaffold/tests/97-fopen.c: Likewise. * scaffold/tests/99-readdir.c: Likewise. * scaffold/tests/t.c: Likewise. * lib/linux/x86_64-mes/mes.c: New file. * lib/linux/x86_64-mes/mini.c: New file. * lib/x86_64-mes/setjmp.c: New file. * scaffold/tests/06-!call-1.c: New file. * scaffold/tests/06-call-2.c: New file. * scaffold/tests/06-call-variable.c: New file. * scaffold/tests/08-assign-global.c: New file. * scaffold/tests/08-assign-negative.c: New file. * scaffold/tests/17-compare-and-or.c: New file. * scaffold/tests/17-compare-and.c: New file. * scaffold/tests/17-compare-ge.c: New file. * scaffold/tests/17-compare-gt.c: New file. * scaffold/tests/17-compare-le.c: New file. * scaffold/tests/17-compare-lt.c: New file. * scaffold/tests/17-compare-or.c: New file. * scaffold/tests/17-compare-unsigned-ge.c: New file. * scaffold/tests/17-compare-unsigned-gt.c: New file. * scaffold/tests/17-compare-unsigned-le.c: New file. * scaffold/tests/17-compare-unsigned-lt.c: New file. * scaffold/tests/21-char[]-simple.c: New file. * scaffold/tests/23-global-pointer-init-null.c: New file. * scaffold/tests/23-global-pointer-init.c: New file. * scaffold/tests/23-global-pointer-pointer-ref.c: New file. * scaffold/tests/23-global-pointer-ref.c: New file. * scaffold/tests/23-pointer-sub.c: New file. * scaffold/tests/31-oputs.c: New file. * scaffold/tests/32-call-wrap.c: New file. * scaffold/tests/38-compare-call-2.c: New file. * scaffold/tests/38-compare-call-3.c: New file. * scaffold/tests/51-pointer-sub.c: New file. * scaffold/tests/54-argc.c: New file. * scaffold/tests/63-struct-array-assign.c: New file. * scaffold/tests/63-struct-array-compare.c: New file. * scaffold/tests/63-struct-array.c: New file. * scaffold/tests/63-struct-assign.c: New file. * scaffold/tests/63-struct-function.c: New file. * scaffold/tests/63-struct-local.c: New file. * scaffold/tests/63-struct-pointer.c: New file. * scaffold/tests/63-struct.c: New file. * scaffold/tests/70-printf-hello.c: New file. * scaffold/tests/70-printf-simple.c: New file. * scaffold/tests/70-stdarg.c: New file. * scaffold/tests/70-strchr.c: New file. * scaffold/tests/73-union-hello.c: New file. * scaffold/tests/76-pointer-arithmetic-pp.c: New file. * scaffold/tests/79-int-array-simple.c: New file. * scaffold/tests/7b-struct-int-array-hello.c: New file. * scaffold/tests/7b-struct-int-array-pointer.c: New file. * scaffold/tests/7i-struct-struct-simple.c: New file. * scaffold/tests/7k-for-each-elem-simple.c: New file. * scaffold/tests/7l-struct-any-size-array-simple.c: New file. * scaffold/tests/7o-struct-pre-post-simple.c: New file. * scaffold/tests/7q-bit-field-simple.c: New file. * scaffold/tests/90-strspn.c: New file. * scaffold/tests/06-call-string.c.: Rename from 31-eputs.c. * scaffold/tests/7t-function-destruct.c: Rename from 48-function-destruct.c. * scaffold/tests/48-global-static.c: Rename from 49-global-static.c. * scaffold/tests/55-char-array.c:renamed: Rename from 4a-char-array.c. * scaffold/tests/51-itoa.c:r Rename from 52-itoa.c. * include/signal.h:(struct sigaction):
304 lines
8.8 KiB
Scheme
304 lines
8.8 KiB
Scheme
;;; GNU Mes --- Maxwell Equations of Software
|
|
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
|
;;;
|
|
;;; This file is part of GNU Mes.
|
|
;;;
|
|
;;; GNU 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.
|
|
;;;
|
|
;;; GNU 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 GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;; Commentary:
|
|
|
|
;;; info.scm defines [Guile] record data types for MesCC
|
|
|
|
;;; Code:
|
|
|
|
(define-module (mescc info)
|
|
#:use-module (ice-9 optargs)
|
|
#:use-module (srfi srfi-9)
|
|
#:use-module (srfi srfi-9 gnu)
|
|
#:use-module (srfi srfi-26)
|
|
#:export (<info>
|
|
make
|
|
clone
|
|
make-<info>
|
|
info?
|
|
|
|
.types
|
|
.constants
|
|
.functions
|
|
.globals
|
|
.locals
|
|
.function
|
|
.statics
|
|
.text
|
|
.post
|
|
.break
|
|
.continue
|
|
.allocated
|
|
.pushed
|
|
.registers
|
|
.instructions
|
|
|
|
<type>
|
|
make-type
|
|
type?
|
|
type:type
|
|
type:size
|
|
type:pointer
|
|
type:description
|
|
|
|
<c-array>
|
|
make-c-array
|
|
c-array?
|
|
c-array:type
|
|
c-array:count
|
|
|
|
<pointer>
|
|
make-pointer
|
|
pointer?
|
|
pointer:type
|
|
pointer:rank
|
|
|
|
<bit-field>
|
|
make-bit-field
|
|
bit-field?
|
|
bit-field:type
|
|
bit-field:bit
|
|
bit-field:bits
|
|
|
|
<var>
|
|
var:name
|
|
var:type
|
|
var:pointer
|
|
var:c-array
|
|
|
|
<global>
|
|
make-global
|
|
global?
|
|
global:name
|
|
global:type
|
|
global:pointer
|
|
global:c-array
|
|
global:var
|
|
global:value
|
|
global:function
|
|
global->string
|
|
|
|
<local>
|
|
make-local
|
|
local?
|
|
local:type
|
|
local:pointer
|
|
local:c-array
|
|
local:var
|
|
local:id
|
|
|
|
<function>
|
|
make-function
|
|
function?
|
|
function:name
|
|
function:type
|
|
function:text
|
|
function->string
|
|
|
|
->type
|
|
->rank
|
|
rank--
|
|
rank++
|
|
rank+=
|
|
structured-type?))
|
|
|
|
(define-immutable-record-type <info>
|
|
(make-<info> types constants functions globals locals statics function text post break continue allocated pushed registers instructions)
|
|
info?
|
|
(types .types)
|
|
(constants .constants)
|
|
(functions .functions)
|
|
(globals .globals)
|
|
(locals .locals)
|
|
(statics .statics)
|
|
(function .function)
|
|
(text .text)
|
|
(post .post)
|
|
(break .break)
|
|
(continue .continue)
|
|
(allocated .allocated)
|
|
(pushed .pushed)
|
|
(registers .registers)
|
|
(instructions .instructions))
|
|
|
|
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (statics '()) (function #f) (text '()) (post '()) (break '()) (continue '()) (allocated '()) (pushed 0) (registers '()) (instructions '()))
|
|
(cond ((eq? o <info>)
|
|
(make-<info> types constants functions globals locals statics function text post break continue allocated pushed registers instructions))))
|
|
|
|
(define (clone o . rest)
|
|
(cond ((info? o)
|
|
(let ((types (.types o))
|
|
(constants (.constants o))
|
|
(functions (.functions o))
|
|
(globals (.globals o))
|
|
(locals (.locals o))
|
|
(statics (.statics o))
|
|
(function (.function o))
|
|
(text (.text o))
|
|
(post (.post o))
|
|
(break (.break o))
|
|
(continue (.continue o))
|
|
(allocated (.allocated o))
|
|
(pushed (.pushed o))
|
|
(registers (.registers o))
|
|
(instructions (.instructions o)))
|
|
(let-keywords rest
|
|
#f
|
|
((types types)
|
|
(constants constants)
|
|
(functions functions)
|
|
(globals globals)
|
|
(locals locals)
|
|
(statics statics)
|
|
(function function)
|
|
(text text)
|
|
(post post)
|
|
(break break)
|
|
(continue continue)
|
|
(allocated allocated)
|
|
(pushed pushed)
|
|
(registers registers)
|
|
(instructions instructions))
|
|
(make <info> #:types types #:constants constants #:functions functions #:globals globals #:locals locals #:statics statics #:function function #:text text #:post post #:break break #:continue continue #:allocated allocated #:pushed pushed #:registers registers #:instructions instructions))))))
|
|
|
|
;; ("int" . ,(make-type 'builtin 4 #f 0 #f))
|
|
;; (make-type 'enum 4 0 fields)
|
|
;; (make-type 'struct (apply + (map field:size fields)) 0 fields)
|
|
|
|
(define-immutable-record-type <type>
|
|
(make-type type size description)
|
|
type?
|
|
(type type:type)
|
|
(size type:size)
|
|
(description type:description))
|
|
|
|
(define-immutable-record-type <c-array>
|
|
(make-c-array type count)
|
|
c-array?
|
|
(type c-array:type)
|
|
(count c-array:count))
|
|
|
|
(define-immutable-record-type <pointer>
|
|
(make-pointer type rank)
|
|
pointer?
|
|
(type pointer:type)
|
|
(rank pointer:rank))
|
|
|
|
(define-immutable-record-type <bit-field>
|
|
(make-bit-field type bit bits)
|
|
bit-field?
|
|
(type bit-field:type)
|
|
(bit bit-field:bit)
|
|
(bits bit-field:bits))
|
|
|
|
(define-immutable-record-type <var>
|
|
(make-var name type function id value)
|
|
var?
|
|
(name var:name)
|
|
(type var:type) ; <type>
|
|
(function var:function)
|
|
(id var:id)
|
|
(value var:value))
|
|
|
|
(define-immutable-record-type <global>
|
|
(make-global- name type var value function)
|
|
global?
|
|
(name global:name)
|
|
(type global:type)
|
|
(var global:var) ; <var>
|
|
|
|
(value global:value)
|
|
(function global:function))
|
|
|
|
(define (make-global name type value function)
|
|
(make-global- name type (make-var name type function #f value) value function))
|
|
|
|
(define (global->string o)
|
|
(or (and=> (global:function o) (cut string-append <> "-" (global:name o)))
|
|
(global:name o)))
|
|
|
|
(define-immutable-record-type <local>
|
|
(make-local- type var id)
|
|
local?
|
|
(type local:type)
|
|
(var local:var) ; <var>
|
|
|
|
(id local:id))
|
|
|
|
(define (make-local name type id)
|
|
(make-local- type (make-var name type #f id #f) id))
|
|
|
|
(define-immutable-record-type <function>
|
|
(make-function name type text)
|
|
function?
|
|
(name function:name)
|
|
(type function:type)
|
|
(text function:text))
|
|
|
|
(define (function->string o)
|
|
(function:name o))
|
|
|
|
(define (structured-type? o)
|
|
(cond ((type? o) (memq (type:type o) '(struct union)))
|
|
((global? o) ((compose structured-type? global:type) o))
|
|
((local? o) ((compose structured-type? local:type) o))
|
|
((and (pair? o) (eq? (car o) 'tag))) ;; FIXME: enum?
|
|
(else #f)))
|
|
|
|
(define (->type o)
|
|
(cond ((type? o) o)
|
|
((bit-field? o) o)
|
|
((pointer? o) ((compose ->type pointer:type) o))
|
|
((c-array? o) ((compose ->type c-array:type) o))
|
|
((and (pair? o) (eq? (car o) 'tag)) o)
|
|
;; FIXME
|
|
(#t
|
|
(format (current-error-port) "->type--: not a <type>: ~s\n" o)
|
|
(make-type 'builtin 4 #f))
|
|
(else (error "->type: not a <type>:" o))))
|
|
|
|
(define (->rank o)
|
|
(cond ((type? o) 0)
|
|
((pointer? o) (pointer:rank o))
|
|
((c-array? o) (1+ ((compose ->rank c-array:type) o)))
|
|
((local? o) ((compose ->rank local:type) o))
|
|
((global? o) ((compose ->rank global:type) o))
|
|
((bit-field? o) 0)
|
|
;; FIXME
|
|
(#t
|
|
(format (current-error-port) "->rank: not a type: ~s\n" o)
|
|
0)
|
|
(else (error "->rank: not a <type>:" o))))
|
|
|
|
(define (rank-- o)
|
|
(cond ((and (pointer? o) (= (pointer:rank o) 1)) (pointer:type o))
|
|
((pointer? o) (set-field o (pointer:rank) (1- (pointer:rank o))))
|
|
((c-array? o) (c-array:type o))
|
|
;; FIXME
|
|
(#t (format (current-error-port) "rank--: not a pointer: ~s\n" o)
|
|
o)
|
|
(else (error "rank--: not a pointer" o))))
|
|
|
|
(define (rank+= o i)
|
|
(cond ((pointer? o) (set-field o (pointer:rank) (+ i (pointer:rank o))))
|
|
(else (make-pointer o i))))
|
|
|
|
(define (rank++ o)
|
|
(rank+= o 1))
|