2018-07-21 16:28:47 +00:00
|
|
|
#! @BASH@
|
2016-10-12 21:40:11 +00:00
|
|
|
# -*-scheme-*-
|
2018-07-21 22:43:39 +00:00
|
|
|
if [ "$V" = 2 ]; then
|
2018-05-25 06:05:02 +00:00
|
|
|
set -x
|
|
|
|
fi
|
2018-07-09 08:46:28 +00:00
|
|
|
prefix=${prefix-@prefix@}
|
2018-11-06 19:29:35 +00:00
|
|
|
program_prefix=${program_prefix-@program_prefix@}
|
2018-07-21 16:28:47 +00:00
|
|
|
MES_PREFIX=${MES_PREFIX-$prefix/share/mes}
|
2018-05-29 18:07:46 +00:00
|
|
|
export MES_PREFIX
|
2018-05-03 18:32:06 +00:00
|
|
|
mes_p=$(command -v mes)
|
2018-07-21 22:43:39 +00:00
|
|
|
mescc=$(command -v $0)
|
2018-07-21 05:15:52 +00:00
|
|
|
|
|
|
|
guile_site_dir=${guile_site_dir-@guile_site_dir@}
|
|
|
|
GUILE_LOAD_PATH=$guile_site_dir:$GUILE_LOAD_PATH
|
|
|
|
|
2018-04-27 21:47:31 +00:00
|
|
|
if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile" ]; then
|
2018-07-09 08:46:28 +00:00
|
|
|
guile_site_ccache_dir=${guile_site_ccache_dir-@guile_site_ccache_dir@}
|
2018-07-21 05:15:52 +00:00
|
|
|
GUILE_LOAD_COMPILED_PATH=$guile_site_ccache_dir:$GUILE_LOAD_COMPILED_PATH
|
2018-07-09 08:46:28 +00:00
|
|
|
GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0}
|
|
|
|
export GUILE_AUTO_COMPILE
|
2018-07-21 22:43:39 +00:00
|
|
|
exec ${GUILE-guile} -L $guile_site_dir -e '(mescc)' -s "$mescc" "$@"
|
2018-04-27 21:47:31 +00:00
|
|
|
else
|
|
|
|
MES=${MES-$(dirname $0)/mes}
|
2018-07-25 06:14:13 +00:00
|
|
|
exec ${MES-mes} -e '(mescc)' -s "$mescc" "$@"
|
2017-12-09 21:38:51 +00:00
|
|
|
fi
|
2016-10-12 21:40:11 +00:00
|
|
|
!#
|
|
|
|
|
2018-07-22 12:24:36 +00:00
|
|
|
;;; GNU Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-10-12 21:40:11 +00:00
|
|
|
;;;
|
2018-07-22 12:24:36 +00:00
|
|
|
;;; This file is part of GNU Mes.
|
2016-10-12 21:40:11 +00:00
|
|
|
;;;
|
2018-07-22 12:24:36 +00:00
|
|
|
;;; GNU Mes is free software; you can redistribute it and/or modify it
|
2016-10-12 21:40:11 +00:00
|
|
|
;;; 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.
|
|
|
|
;;;
|
2018-07-22 12:24:36 +00:00
|
|
|
;;; GNU Mes is distributed in the hope that it will be useful, but
|
2016-10-12 21:40:11 +00:00
|
|
|
;;; 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
|
2018-07-22 12:24:36 +00:00
|
|
|
;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2016-10-12 21:40:11 +00:00
|
|
|
|
2018-04-27 21:47:31 +00:00
|
|
|
(define-module (mescc)
|
|
|
|
#:use-module (ice-9 getopt-long)
|
2018-05-25 06:05:02 +00:00
|
|
|
#:use-module (mes misc)
|
|
|
|
#:use-module (mescc mescc)
|
2018-04-27 21:47:31 +00:00
|
|
|
#:export (main))
|
2016-10-12 21:40:11 +00:00
|
|
|
|
2018-05-29 18:07:46 +00:00
|
|
|
(define %prefix (or (getenv "MES_PREFIX")
|
2018-07-09 08:46:28 +00:00
|
|
|
(if (string-prefix? "@prefix" "@prefix@")
|
2018-05-29 18:07:46 +00:00
|
|
|
""
|
2018-07-09 08:46:28 +00:00
|
|
|
"@prefix@/share/mes")))
|
2016-10-12 21:40:11 +00:00
|
|
|
|
2018-05-25 06:05:02 +00:00
|
|
|
(define %version (if (string-prefix? "@VERSION" "@VERSION@") "git"
|
|
|
|
"@VERSION@"))
|
|
|
|
|
2018-04-27 21:47:31 +00:00
|
|
|
(cond-expand
|
|
|
|
(mes
|
2018-05-25 06:05:02 +00:00
|
|
|
(define (set-port-encoding! port encoding) #t)
|
|
|
|
(mes-use-module (mes guile))
|
|
|
|
(mes-use-module (mes misc))
|
|
|
|
(mes-use-module (mes getopt-long))
|
|
|
|
(mes-use-module (mes display))
|
|
|
|
(mes-use-module (mescc mescc)))
|
2018-04-27 21:47:31 +00:00
|
|
|
(guile
|
2018-05-25 06:05:02 +00:00
|
|
|
(define-macro (mes-use-module . rest) #t)))
|
2016-12-31 08:03:07 +00:00
|
|
|
|
2018-07-21 22:43:39 +00:00
|
|
|
(when (and=> (getenv "V") (lambda (v) (> (string->number v) 1)))
|
|
|
|
(format (current-error-port) "mescc[~a]...\n" %scheme))
|
2017-04-02 16:50:07 +00:00
|
|
|
|
2017-05-17 11:56:25 +00:00
|
|
|
(define (parse-opts args)
|
|
|
|
(let* ((option-spec
|
2018-10-06 13:56:14 +00:00
|
|
|
'((align)
|
|
|
|
(assemble (single-char #\c))
|
2018-08-14 18:32:56 +00:00
|
|
|
(base-address (value #t))
|
2018-05-25 06:05:02 +00:00
|
|
|
(compile (single-char #\S))
|
2018-01-02 06:05:41 +00:00
|
|
|
(define (single-char #\D) (value #t))
|
2018-05-25 06:05:02 +00:00
|
|
|
(debug-info (single-char #\g))
|
2018-11-08 21:41:20 +00:00
|
|
|
(dumpmachine (single-char #\d))
|
2017-05-17 11:56:25 +00:00
|
|
|
(help (single-char #\h))
|
2018-01-02 06:05:41 +00:00
|
|
|
(include (single-char #\I) (value #t))
|
2018-05-29 18:07:46 +00:00
|
|
|
(library-dir (single-char #\L) (value #t))
|
2018-05-25 06:05:02 +00:00
|
|
|
(library (single-char #\l) (value #t))
|
2018-08-14 18:32:56 +00:00
|
|
|
(machine (single-char #\m) (value #t))
|
2018-05-25 06:05:02 +00:00
|
|
|
(preprocess (single-char #\E))
|
2018-11-08 13:07:27 +00:00
|
|
|
(std (value #t))
|
2018-05-25 06:05:02 +00:00
|
|
|
(output (single-char #\o) (value #t))
|
2018-11-08 13:07:27 +00:00
|
|
|
(optimize (single-char #\O) (value #t))
|
2018-04-27 21:47:31 +00:00
|
|
|
(version (single-char #\V))
|
2018-05-25 06:05:02 +00:00
|
|
|
(verbose (single-char #\v))
|
2018-11-08 13:07:27 +00:00
|
|
|
(write (single-char #\w) (value #t))
|
|
|
|
(language (single-char #\x) (value #t))))
|
|
|
|
(single-dash-options '("-dumpmachine" "-std"))
|
2018-11-08 21:41:20 +00:00
|
|
|
(args (map (lambda (o)
|
|
|
|
(if (member o single-dash-options) (string-append "-" o)
|
|
|
|
o))
|
|
|
|
args))
|
2017-05-22 17:22:18 +00:00
|
|
|
(options (getopt-long args option-spec))
|
|
|
|
(help? (option-ref options 'help #f))
|
|
|
|
(files (option-ref options '() '()))
|
|
|
|
(usage? (and (not help?) (null? files)))
|
2017-05-17 11:56:25 +00:00
|
|
|
(version? (option-ref options 'version #f)))
|
2018-11-08 21:41:20 +00:00
|
|
|
(cond ((option-ref options 'dumpmachine #f)
|
|
|
|
(display "x86-mes")
|
|
|
|
(exit 0))
|
|
|
|
(version? (format #t "mescc (GNU Mes) ~a\n" %version) (exit 0))
|
|
|
|
(else
|
|
|
|
(and (or help? usage?)
|
|
|
|
(format (or (and usage? (current-error-port)) (current-output-port)) "\
|
2018-04-27 21:47:31 +00:00
|
|
|
Usage: mescc [OPTION]... FILE...
|
2018-11-08 13:07:27 +00:00
|
|
|
--align align globals
|
|
|
|
-dumpmachine display the compiler's target processor
|
2018-08-14 18:32:56 +00:00
|
|
|
--base-address=ADRRESS
|
2018-11-08 13:07:27 +00:00
|
|
|
use BaseAddress ADDRESS [0x1000000]
|
|
|
|
-D DEFINE[=VALUE] define DEFINE [VALUE=1]
|
|
|
|
-E preprocess only; do not compile, assemble or link
|
|
|
|
-g add debug info [GDB, objdump] TODO: hex2 footer
|
|
|
|
-h, --help display this help and exit
|
|
|
|
-I DIR append DIR to include path
|
|
|
|
-L DIR append DIR to library path
|
|
|
|
-l LIBNAME link with LIBNAME
|
|
|
|
-m BITS compile for BITS bits [32]
|
|
|
|
-o FILE write output to FILE
|
|
|
|
-O LEVEL use optimizing LEVEL
|
|
|
|
-S preprocess and compile only; do not assemble or link
|
|
|
|
--std=STANDARD assume that the input sources are for STANDARD
|
|
|
|
-v, --version display version and exit
|
|
|
|
-w,--write=TYPE dump Nyacc AST using TYPE {pretty-print,write}
|
|
|
|
-x LANGUAGE specify LANGUAGE of the following input files
|
2018-04-27 21:47:31 +00:00
|
|
|
|
|
|
|
Environment variables:
|
|
|
|
|
2018-11-08 13:07:27 +00:00
|
|
|
MES=BINARY run on mes-executable BINARY {mes,guile}
|
|
|
|
MES_DEBUG=LEVEL show debug output with verbosity LEVEL {0..5}
|
|
|
|
NYACC_TRACE=1 show Nyacc progress
|
2017-05-17 11:56:25 +00:00
|
|
|
")
|
2018-11-08 21:41:20 +00:00
|
|
|
(exit (or (and usage? 2) 0)))
|
|
|
|
options))))
|
2017-05-17 11:56:25 +00:00
|
|
|
|
|
|
|
(define (main args)
|
2018-04-22 09:51:28 +00:00
|
|
|
(let* ((options (parse-opts args))
|
2018-05-25 06:05:02 +00:00
|
|
|
(options (acons 'prefix %prefix options))
|
|
|
|
(preprocess? (option-ref options 'preprocess #f))
|
|
|
|
(compile? (option-ref options 'compile #f))
|
|
|
|
(assemble? (option-ref options 'assemble #f))
|
|
|
|
(verbose? (option-ref options 'verbose (getenv "MES_DEBUG"))))
|
|
|
|
(when verbose?
|
2018-04-27 21:47:31 +00:00
|
|
|
(setenv "NYACC_TRACE" "yes")
|
2018-05-25 06:05:02 +00:00
|
|
|
(format (current-error-port) "options=~s\n" options))
|
|
|
|
(cond (preprocess? (mescc:preprocess options))
|
|
|
|
(compile? (mescc:compile options))
|
|
|
|
(assemble? (mescc:assemble options))
|
|
|
|
(else (mescc:link options)))))
|
2018-04-09 05:12:38 +00:00
|
|
|
'done
|