~ chicken-core (chicken-5) /chicken.scm
Trap1;;;; chicken.scm - The CHICKEN Scheme compiler (loader/main-module)2;3; Copyright (c) 2008-2022, The CHICKEN Team4; Copyright (c) 2000-2007, Felix L. Winkelmann5; All rights reserved.6;7; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following8; conditions are met:9;10; Redistributions of source code must retain the above copyright notice, this list of conditions and the following11; disclaimer.12; Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following13; disclaimer in the documentation and/or other materials provided with the distribution.14; Neither the name of the author nor the names of its contributors may be used to endorse or promote15; products derived from this software without specific prior written permission.16;17; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS18; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY19; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR20; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR21; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR22; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR24; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE25; POSSIBILITY OF SUCH DAMAGE.262728(declare29 (uses chicken-syntax chicken-ffi-syntax30 srfi-4 extras data-structures31 lolevel ; unused, but loaded to make foldable bindings available32 support compiler optimizer lfa2 compiler-syntax scrutinizer33 batch-driver c-platform c-backend user-pass))3435(module chicken.compiler.chicken ()3637(import scheme38 chicken.base39 chicken.compiler.batch-driver40 chicken.compiler.c-platform41 chicken.compiler.support42 chicken.compiler.user-pass43 chicken.fixnum44 chicken.process-context45 chicken.string)4647(include "tweaks")48(include "mini-srfi-1.scm")4950;;; Prefix argument list with default options:5152(define compiler-arguments53 (let ((args (cdr (argv))))54 (if (null? args)55 '()56 (append (take args 1) ; Leave source filename argument first.57 (string-split (or (get-environment-variable "CHICKEN_OPTIONS") ""))58 (drop args 1)))))596061;;; Process command-line options:62;63; - remove runtime-options ("-:...")64; - filter out source-filename65; - convert options into symbols (without the initial hyphens)6667(define (process-command-line args)68 (let loop ((args args) (options '()) (filename #f))69 (if (null? args)70 (values filename (reverse options))71 (let* ((arg (car args))72 (len (string-length arg))73 (char0 (string-ref arg 0)) )74 (if (and (char=? #\- char0) (> len 1))75 (if (and (> len 1) (char=? #\: (string-ref arg 1)))76 (loop (cdr args) options filename)77 (loop (cdr args) (cons (string->symbol (substring arg 1 len)) options) filename) )78 (if filename79 (loop (cdr args) (cons arg options) filename)80 (loop (cdr args) options arg) ) ) ) ) ) )818283;;; Run compiler with command-line options:8485(receive (filename options) ((or (user-options-pass) process-command-line) compiler-arguments)86 ;; TODO: Perhaps option parsing should be moved to batch-driver?87 (let loop ((os options))88 (unless (null? os)89 (let ((o (car os))90 (rest (cdr os)) )91 (cond ((eq? 'optimize-level o)92 (let ((level (string->number (car rest))))93 (case level94 ((0)95 (set! options96 (cons* 'no-compiler-syntax 'no-usual-integrations options)) )97 ((1)98 (set! options99 (cons* 'optimize-leaf-routines100 options)) )101 ((2)102 (set! options103 (cons* 'optimize-leaf-routines104 'inline105 ;XXX 'clustering106 'lfa2107 options)) )108 ((3)109 (set! options110 (cons* 'optimize-leaf-routines111 'inline112 'inline-global113 'local114 ;XXX 'clustering115 'lfa2116 'specialize117 options) ) )118 ((4)119 (set! options120 (cons* 'optimize-leaf-routines121 'inline122 'inline-global123 'specialize124 ;XXX 'clustering125 'lfa2126 'local 'unsafe127 options) ) )128 (else129 (when (>= level 5)130 (set! options131 (cons* 'disable-interrupts132 'no-trace133 'unsafe134 'block135 'specialize136 'optimize-leaf-routines137 'no-lambda-info138 'inline139 'inline-global140 'clustering141 'lfa2142 options) ) ) ) )143 (loop (cdr rest)) ) )144 ((eq? 'debug-level o)145 (case (string->number (car rest))146 ((0) (set! options (cons* 'no-lambda-info 'no-trace options)))147 ((1) (set! options (cons 'no-trace options)))148 ((2)) ; default behaviour149 ((3) (set! options (cons 'debug-info options)))150 (else (quit-compiling "invalid debug level: ~a" (car rest))))151 (loop (cdr rest)))152 ((memq o valid-compiler-options) (loop rest))153 ((memq o valid-compiler-options-with-argument)154 (if (pair? rest)155 (loop (cdr rest))156 (quit-compiling "missing argument to `-~s' option" o) ) )157 (else158 (warning159 "invalid compiler option (ignored)"160 (if (string? o) o (conc "-" o)) )161 (loop rest) ) ) ) ) )162 (apply compile-source-file filename compiler-arguments options)163 (exit)))