mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-19 13:49:16 +02:00
Use meta file to pass data when compiling programs
This commit is contained in:
parent
1a5310b881
commit
1d0cbf96ed
1 changed files with 31 additions and 8 deletions
39
cyclone.scm
39
cyclone.scm
|
@ -794,14 +794,38 @@
|
||||||
append-dirs
|
append-dirs
|
||||||
prepend-dirs))))))
|
prepend-dirs))))))
|
||||||
(create-c-file in-prog)
|
(create-c-file in-prog)
|
||||||
(when (not program?)
|
(cond
|
||||||
|
(program?
|
||||||
|
;; Use .meta file to store information for C compiler phase
|
||||||
|
(save-program-metadata meta-file lib-deps c-linker-options))
|
||||||
|
(else
|
||||||
;; Emit .meta file
|
;; Emit .meta file
|
||||||
(with-output-to-file
|
(with-output-to-file
|
||||||
meta-file
|
meta-file
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(display ";; This file was automatically generated by the Cyclone Scheme compiler")
|
(display ";; This file was automatically generated by the Cyclone Scheme compiler")
|
||||||
(newline)
|
(newline)
|
||||||
(write (macro:get-defined-macros)))))))
|
(write (macro:get-defined-macros))))))))
|
||||||
|
|
||||||
|
(define (save-program-metadata filename lib-deps c-linker-options)
|
||||||
|
(with-output-to-file
|
||||||
|
filename
|
||||||
|
(lambda ()
|
||||||
|
(display ";; This file was automatically generated by the Cyclone Scheme compiler")
|
||||||
|
(newline)
|
||||||
|
(write `(lib-deps . ,lib-deps))
|
||||||
|
(newline)
|
||||||
|
(write `(c-linker-options . ,c-linker-options)))))
|
||||||
|
|
||||||
|
(define (load-program-metadata filename)
|
||||||
|
(let ((data (call-with-input-file filename read-all)))
|
||||||
|
(delete-file filename)
|
||||||
|
data))
|
||||||
|
|
||||||
|
(define (get-meta meta symbol default)
|
||||||
|
(if (assoc symbol meta)
|
||||||
|
(cdr (assoc symbol meta))
|
||||||
|
default))
|
||||||
|
|
||||||
(define (run-external-compiler args cc? cc-prog cc-exec cc-lib cc-so
|
(define (run-external-compiler args cc? cc-prog cc-exec cc-lib cc-so
|
||||||
cc-opts cc-prog-linker-opts cc-prog-linker-objs
|
cc-opts cc-prog-linker-opts cc-prog-linker-objs
|
||||||
|
@ -819,11 +843,6 @@
|
||||||
(else
|
(else
|
||||||
;; Account for any cond-expand declarations in the library
|
;; Account for any cond-expand declarations in the library
|
||||||
(list (lib:cond-expand (car in-prog-raw) expander)))))
|
(list (lib:cond-expand (car in-prog-raw) expander)))))
|
||||||
;; how to collect these? would it be best if we write them to file
|
|
||||||
;; and then we pick that file back up now?
|
|
||||||
(c-linker-options 'todo)
|
|
||||||
;; similar to above, may need to emit these and pick them back up now from file
|
|
||||||
(lib-deps 'todo)
|
|
||||||
;; Only read C compiler options from module being compiled
|
;; Only read C compiler options from module being compiled
|
||||||
(cc-opts*
|
(cc-opts*
|
||||||
(cond
|
(cond
|
||||||
|
@ -837,6 +856,7 @@
|
||||||
" "))))
|
" "))))
|
||||||
(exec-file (basename in-file))
|
(exec-file (basename in-file))
|
||||||
(src-file (string-append exec-file ".c"))
|
(src-file (string-append exec-file ".c"))
|
||||||
|
(meta-file (string-append exec-file ".meta"))
|
||||||
(get-comp-env
|
(get-comp-env
|
||||||
(lambda (sym str)
|
(lambda (sym str)
|
||||||
(if (> (string-length str) 0)
|
(if (> (string-length str) 0)
|
||||||
|
@ -846,7 +866,10 @@
|
||||||
;; Compile the generated C file
|
;; Compile the generated C file
|
||||||
(cond
|
(cond
|
||||||
(program?
|
(program?
|
||||||
(letrec ((objs-str
|
(letrec ((metadata (load-program-metadata meta-file))
|
||||||
|
(c-linker-options (get-meta metadata 'c-linker-options '()))
|
||||||
|
(lib-deps (get-meta metadata 'lib-deps '()))
|
||||||
|
(objs-str
|
||||||
(string-append
|
(string-append
|
||||||
cc-prog-linker-objs
|
cc-prog-linker-objs
|
||||||
(apply
|
(apply
|
||||||
|
|
Loading…
Add table
Reference in a new issue