>From 5a529310b8dd71bc09616c5397615657ad79ec75 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sun, 17 Aug 2014 15:53:28 +0200 Subject: [PATCH 12/19] compiler-modules: Make compiler-arguments and source-file nonglobal by passing them around. The compiler-arguments global was declared in chicken.scm and used only in c-backend to write the compiler arguments to the resulting C file, for informational/debugging/forensic purposes. Just like the filename and the final (derived) options, this is now passed around from chicken to batch-driver, and from batch-driver to c-backend. The variable has been renamed for (hopefully) increased clarity. As stated above, the "filename" in batch-driver is passed to some procedures. However, it is not passed to all: emit-type-file and emit-global-inline-file were the only two procedures to read the filename from the global "source-filename". This global has now been removed and the file name is passed to the procedures as an argument. --- batch-driver.scm | 9 ++++----- c-backend.scm | 4 ++-- chicken.scm | 3 ++- compiler-namespace.scm | 2 -- compiler.scm | 1 - scrutinizer.scm | 6 +++--- support.scm | 8 ++++---- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/batch-driver.scm b/batch-driver.scm index 0dfd640..a96444a 100644 --- a/batch-driver.scm +++ b/batch-driver.scm @@ -73,7 +73,7 @@ ;;; Compile a complete source file: -(define (compile-source-file filename . options) +(define (compile-source-file filename user-suppplied-options . options) (define (option-arg p) (if (null? (cdr p)) (quit-compiling "missing argument to `-~A' option" (car p)) @@ -418,7 +418,6 @@ ;; Display header: (dribble "compiling `~a' ..." filename) - (set! source-filename filename) (debugging 'r "options" options) (debugging 'r "debugging options" debugging-chicken) (debugging 'r "target heap size" target-heap-size) @@ -627,7 +626,7 @@ ;; do this here, because we must make sure we have a db (when type-output-file (dribble "generating type file `~a' ..." type-output-file) - (emit-type-file type-output-file db))) + (emit-type-file filename type-output-file db))) (set! first-analysis #f) (end-time "analysis") (print-db "analysis" '|4| db i) @@ -683,7 +682,7 @@ (when (and inline-output-file insert-timer-checks) (let ((f inline-output-file)) (dribble "generating global inline file `~a' ..." f) - (emit-global-inline-file f db) ) ) + (emit-global-inline-file filename f db) ) ) (begin-time) ;; Closure conversion (set! node2 (perform-closure-conversion node2 db)) @@ -704,7 +703,7 @@ ;; Code generation (let ((out (if outfile (open-output-file outfile) (current-output-port))) ) (dribble "generating `~A' ..." outfile) - (generate-code literals lliterals lambda-table out filename dynamic db) + (generate-code literals lliterals lambda-table out filename user-suppplied-options dynamic db) (when outfile (close-output-port out))) (end-time "code generation") diff --git a/c-backend.scm b/c-backend.scm index 9e217ea..7617996 100644 --- a/c-backend.scm +++ b/c-backend.scm @@ -69,7 +69,7 @@ ;;; Generate target code: -(define (generate-code literals lliterals lambda-table out source-file dynamic db) +(define (generate-code literals lliterals lambda-table out source-file user-supplied-options dynamic db) ;; Don't truncate floating-point precision! (flonum-print-precision (+ flonum-maximum-decimal-exponent 1)) (let () @@ -487,7 +487,7 @@ (string-split (chicken-version #t) "\n") ) "") " command line: ") - (gen-list compiler-arguments) + (gen-list user-supplied-options) (gen #t) (cond [unit-name (gen " unit: " unit-name)] [else diff --git a/chicken.scm b/chicken.scm index 79c7833..ab46a18 100644 --- a/chicken.scm +++ b/chicken.scm @@ -73,6 +73,7 @@ ;;; Run compiler with command-line options: (receive (filename options) ((or (user-options-pass) process-command-line) compiler-arguments) + ;; TODO: Perhaps option parsing should be moved to batch-driver? (let loop ((os options)) (unless (null? os) (let ((o (car os)) @@ -150,5 +151,5 @@ "invalid compiler option (ignored)" (if (string? o) o (conc "-" o)) ) (loop rest) ) ) ) ) ) - (apply compile-source-file filename options) + (apply compile-source-file filename compiler-arguments options) (exit) ) diff --git a/compiler-namespace.scm b/compiler-namespace.scm index d8609f4..3fda129 100644 --- a/compiler-namespace.scm +++ b/compiler-namespace.scm @@ -27,7 +27,6 @@ (private compiler block-compilation - compiler-arguments default-extended-bindings default-standard-bindings enable-specialization @@ -48,7 +47,6 @@ parenthesis-synonyms profile-info-vector-name profile-lambda-list - source-filename standard-bindings strict-variable-types unsafe) diff --git a/compiler.scm b/compiler.scm index 351590c..7c5835d 100644 --- a/compiler.scm +++ b/compiler.scm @@ -363,7 +363,6 @@ (define no-argc-checks #f) (define no-procedure-checks #f) (define no-global-procedure-checks #f) -(define source-filename #f) (define safe-globals-flag #f) (define explicit-use-flag #f) (define disable-stack-overflow-checking #f) diff --git a/scrutinizer.scm b/scrutinizer.scm index 5421355..0595a75 100644 --- a/scrutinizer.scm +++ b/scrutinizer.scm @@ -1871,11 +1871,11 @@ (read-file dbfile)) #t))) -(define (emit-type-file filename db) - (with-output-to-file filename +(define (emit-type-file source-file type-file db) + (with-output-to-file type-file (lambda () (print "; GENERATED BY CHICKEN " (chicken-version) " FROM " - source-filename "\n") + source-file "\n") (##sys#hash-table-for-each (lambda (sym plist) (when (and (variable-visible? sym) diff --git a/support.scm b/support.scm index a6f2d57..13c04e4 100644 --- a/support.scm +++ b/support.scm @@ -810,7 +810,7 @@ (make-node (car x) (cadr x) (map walk (cddr x))))) ;; Only used in batch-driver.scm -(define (emit-global-inline-file filename db) +(define (emit-global-inline-file source-file inline-file db) (let ((lst '()) (out '())) (##sys#hash-table-for-each @@ -833,11 +833,11 @@ (set! out (cons (list sym (node->sexpr (cdr val))) out))))) db) (if (null? out) - (delete-file* filename) - (with-output-to-file filename + (delete-file* inline-file) + (with-output-to-file inline-file (lambda () (print "; GENERATED BY CHICKEN " (chicken-version) " FROM " - source-filename "\n") + source-file "\n") (for-each (lambda (x) (pp x) -- 1.7.10.4