source: project/chicken/trunk/chicken.scm @ 5852

Last change on this file since 5852 was 4845, checked in by felix winkelmann, 13 years ago

reverted unneeded format-modular change, chicken update, minor fixes

File size: 7.3 KB
Line 
1;;;; chicken.scm - The CHICKEN Scheme compiler (loader/main-module)
2;
3; Copyright (c) 2000-2007, Felix L. Winkelmann
4; All rights reserved.
5;
6; Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
7; conditions are met:
8;
9;   Redistributions of source code must retain the above copyright notice, this list of conditions and the following
10;     disclaimer.
11;   Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12;     disclaimer in the documentation and/or other materials provided with the distribution.
13;   Neither the name of the author nor the names of its contributors may be used to endorse or promote
14;     products derived from this software without specific prior written permission.
15;
16; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
17; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18; AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
19; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24; POSSIBILITY OF SUCH DAMAGE.
25;
26; Send bugs, suggestions and ideas to:
27;
28; felix@call-with-current-continuation.org
29;
30; Felix L. Winkelmann
31; Unter den Gleichen 1
32; 37130 Gleichen
33; Germany
34
35
36(declare
37  (uses srfi-1 match srfi-4 utils support compiler optimizer driver platform backend)
38  (run-time-macros) )
39
40
41#{compiler
42  compiler-arguments
43  default-standard-bindings default-extended-bindings side-effecting-standard-bindings
44  non-foldable-standard-bindings foldable-standard-bindings non-foldable-extended-bindings foldable-extended-bindings
45  standard-bindings-that-never-return-false side-effect-free-standard-bindings-that-never-return-false
46  installation-home optimization-iterations process-command-line
47  file-io-only nonwinding-call/cc debugging
48  unit-name insert-timer-checks used-units zap-strings-flag
49  foreign-declarations debugging-executable block-compilation line-number-database-size
50  target-heap-size target-stack-size 
51  default-default-target-heap-size default-default-target-stack-size verbose-mode original-program-size
52  current-program-size line-number-database-2 foreign-lambda-stubs immutable-constants foreign-variables
53  rest-parameters-promoted-to-vector inline-table inline-table-used constant-table constants-used mutable-constants
54  broken-constant-nodes inline-substitutions-enabled compiler-warning
55  direct-call-ids foreign-type-table first-analysis
56  initialize-compiler canonicalize-expression expand-foreign-lambda update-line-number-database scan-toplevel-assignments
57  perform-cps-conversion analyze-expression simplifications perform-high-level-optimizations perform-pre-optimization!
58  reorganize-recursive-bindings substitution-table simplify-named-call
59  perform-closure-conversion prepare-for-code-generation compiler-source-file create-foreign-stub expand-foreign-lambda*
60  transform-direct-lambdas!
61  debugging-chicken bomb check-signature posq stringify symbolify build-lambda-list
62  string->c-identifier c-ify-string words check-and-open-input-file close-checked-input-file fold-inner constant?
63  collapsable-literal? immediate? canonicalize-begin-body extract-mutable-constants string->expr get get-all
64  put! collect! count! get-line get-line-2 find-lambda-container display-analysis-database varnode qnode 
65  build-node-graph build-expression-tree fold-boolean inline-lambda-bindings match-node expression-has-side-effects?
66  simple-lambda-node? compute-database-statistics print-program-statistics output gen gen-list 
67  pprint-expressions-to-file foreign-type-check estimate-foreign-result-size scan-used-variables scan-free-variables
68  topological-sort print-version print-usage initialize-analysis-database
69  default-declarations units-used-by-default words-per-flonum
70  foreign-string-result-reserve parameter-limit default-output-filename eq-inline-operator optimizable-rest-argument-operators
71  membership-test-operators membership-unfold-limit valid-compiler-options valid-compiler-options-with-argument
72  generate-code make-variable-list make-argument-list generate-foreign-stubs foreign-type-declaration
73  foreign-argument-conversion foreign-result-conversion}
74
75
76(include "tweaks")
77
78(eval-when (load) 
79  (include "chicken-more-macros")
80  (include "chicken-ffi-macros") )
81
82;;(##sys#provide 'extras 'srfi-1 'srfi-4)
83
84
85;;; Prefix argument list with default options:
86
87(define compiler-arguments
88  (append
89   (cdr (argv))
90   (remove (lambda (x) (string=? x "")) (string-split (or (getenv "CHICKEN_OPTIONS") ""))) ) )
91
92
93;;; Process command-line options:
94;
95; - remove runtime-options ("-:...")
96; - filter out source-filename
97; - convert options into symbols (without the initial hyphens)
98
99(define (process-command-line args)
100  (let loop ([args args] [options '()] [filename #f])
101    (if (null? args)
102        (values filename (reverse options))
103        (let* ([arg (car args)]
104               [len (string-length arg)]
105               [char0 (string-ref arg 0)] )
106          (if (and (char=? #\- char0) (> len 1))
107              (if (and (> len 1) (char=? #\: (string-ref arg 1)))
108                  (loop (cdr args) options filename)
109                  (loop (cdr args) (cons (string->symbol (substring arg 1 len)) options) filename) )
110              (if filename
111                  (loop (cdr args) (cons arg options) filename)
112                  (loop (cdr args) options arg) ) ) ) ) ) )
113
114
115;;; Run compiler with command-line options:
116
117(receive (filename options) ((or (user-options-pass) process-command-line) compiler-arguments)
118  (let loop ([os options])
119    (unless (null? os)
120      (let ([o (car os)]
121            [rest (cdr os)] )
122        (cond [(eq? 'optimize-level o)
123               (let ([level (string->number (car rest))])
124                 (case level
125                   [(0) #f]
126                   [(1)
127                    (set! options (cons* 'optimize-leaf-routines options)) ]
128                   [(2)
129                    (set! options
130                      (cons 'optimize-leaf-routines options) ) ] 
131                   [(3)
132                    (set! options
133                      (cons* 'optimize-leaf-routines 'unsafe options) ) ]
134                   [else (compiler-warning 'usage "invalid optimization level ~S - ignored" (car rest))] )
135                 (loop (cdr rest)) ) ]
136              [(eq? 'debug-level o)
137               (let ([level (string->number (car rest))])
138                 (case level
139                   [(0) (set! options (cons* 'no-lambda-info 'no-trace options))]
140                   [(1) (set! options (cons 'no-trace options))]
141                   [(2) #f]
142                   [else (compiler-warning 'usage "invalid debug level ~S - ignored" (car rest))] )
143                 (loop (cdr rest)) ) ]
144              [(eq? 'benchmark-mode o)
145               (set! options 
146                 (cons* 'fixnum-arithmetic 'disable-interrupts 'no-trace 'unsafe
147                        'optimize-leaf-routines 'block 'lambda-lift 'no-lambda-info
148                        options) )
149               (loop rest) ]
150              [(memq o valid-compiler-options) (loop rest)]
151              [(memq o valid-compiler-options-with-argument)
152               (if (pair? rest)
153                   (loop (cdr rest))
154                   (quit "missing argument to `-~s' option" o) ) ]
155              [else
156               (compiler-warning 
157                'usage "invalid compiler option `~a' - ignored" 
158                (if (string? o) o (conc "-" o)) )
159               (loop rest) ] ) ) ) )
160  (apply compile-source-file filename options)
161  (exit) )
Note: See TracBrowser for help on using the repository browser.