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-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))
|
|
|
|
(output (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-04-27 21:47:31 +00:00
|
|
|
(write (single-char #\w) (value #t))))
|
2018-11-08 21:41:20 +00:00
|
|
|
(single-dash-options '("-dumpmachine"))
|
|
|
|
(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-10-06 13:56:14 +00:00
|
|
|
--align align globals
|
2018-05-25 06:05:02 +00:00
|
|
|
-c preprocess, compile and assemble only; do not link
|
2018-11-08 21:41:20 +00:00
|
|
|
-dumpmachine display the compiler's target processor
|
2018-08-14 18:32:56 +00:00
|
|
|
--base-address=ADRRESS
|
|
|
|
use BaseAddress ADDRESS [0x1000000]
|
2018-05-25 06:05:02 +00:00
|
|
|
-D DEFINE[=VALUE] define DEFINE [VALUE=1]
|
2017-05-22 17:22:18 +00:00
|
|
|
-E preprocess only; do not compile, assemble or link
|
2017-06-25 07:33:55 +00:00
|
|
|
-g add debug info [GDB, objdump] TODO: hex2 footer
|
2017-05-17 11:56:25 +00:00
|
|
|
-h, --help display this help and exit
|
|
|
|
-I DIR append DIR to include path
|
2018-05-29 18:07:46 +00:00
|
|
|
-L DIR append DIR to library path
|
2018-05-25 06:05:02 +00:00
|
|
|
-l LIBNAME link with LIBNAME
|
2018-08-14 18:32:56 +00:00
|
|
|
-m BITS compile for BITS bits [32]
|
2017-05-17 11:56:25 +00:00
|
|
|
-o FILE write output to FILE
|
2018-05-25 06:05:02 +00:00
|
|
|
-S preprocess and compile only; do not assemble or link
|
2017-05-17 11:56:25 +00:00
|
|
|
-v, --version display version and exit
|
2018-04-27 21:47:31 +00:00
|
|
|
-w,--write=TYPE dump Nyacc AST using TYPE {pretty-print,write}
|
|
|
|
|
|
|
|
Environment variables:
|
|
|
|
|
|
|
|
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
|