3 (declare (standard-bindings)) ;; add (block) to increase compilation time, but reduce execution time
5 ;; (include "pic18-sim.scm") ;; use includes to increase compilation time, but reduce execution time
6 ;; (include "utilities.scm")
8 ;; (include "operators.scm")
10 ;; (include "parser.scm")
11 ;; (include "cfg.scm")
12 ;; (include "optimizations.scm")
13 ;; (include "code-generation.scm")
22 (load "optimizations")
23 (load "code-generation")
24 (load "register-allocation")
26 ;------------------------------------------------------------------------------
28 ;; temporary solution, to support more than int
29 (set! ##six-types ;; TODO signed types ?
41 ;; TODO typedef should add to this list
43 '(current-exception-handler (lambda (exc) (##repl))) ; when not running in the repl
45 (define (read-source filename)
46 (shell-command (string-append "cpp -P " filename " > " filename ".tmp"))
47 ;; (##read-all-as-a-begin-expr-from-path ;; TODO use vectorized notation to have info on errors (where in the source)
48 ;; (string-append filename ".tmp")
49 ;; (readtable-start-syntax-set (current-readtable) 'six)
53 (string-append filename ".tmp")
55 (input-port-readtable-set!
57 (readtable-start-syntax-set
58 (input-port-readtable (current-input-port))
63 (define (main filename)
65 (output-port-readtable-set!
67 (readtable-sharing-allowed?-set
68 (output-port-readtable (current-output-port))
71 (let ((source (read-source filename)))
72 '(pretty-print source)
73 (let* ((ast (parse source)))
75 (let ((cfg (generate-cfg ast)))
78 (remove-branch-cascades-and-dead-code cfg)
79 (remove-converging-branches cfg)
80 (remove-dead-instructions cfg)
81 (profile-start!) ;; TODO DEBUG
82 (allocate-registers cfg)
83 (profile-stop!) ;; TODO DEBUG
84 (write-profile-report "profiling-registers") ;; TODO DEBUG
85 (assembler-gen filename cfg)
87 '(display "------------------ GENERATED CODE\n")
88 (asm-display-listing (current-output-port))
89 (asm-write-hex-file (string-append filename ".hex"))
91 '(display "------------------ EXECUTION USING SIMULATOR\n")
92 (execute-hex-file (string-append filename ".hex"))
95 (define (picobit) (main "tests/picobit/picobit-vm-sixpic.c"))
97 (include "../statprof/statprof.scm")
98 (define (profile) ; profile using picobit
99 (time (begin (with-exception-catcher
100 ;; to have the profiling results even it the compilation fails
103 (write-profile-report "profiling-picobit"))
106 (main "tests/picobit/picobit-vm-sixpic.c")
108 (write-profile-report "profiling-picobit")))