From 66993ebce5086fdf2306ea6e08dcadf91c710b6d Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 11 Nov 2016 17:19:04 -0500 Subject: [PATCH] Issue #43 - Add `-O0` to disable optimizations This is the first step to being able to specify optimization level from the command line. This will be more important as more optimizations are added and when (if) some of them are not always safe to apply. --- cyclone.scm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cyclone.scm b/cyclone.scm index 919e0de1..101fa667 100644 --- a/cyclone.scm +++ b/cyclone.scm @@ -22,6 +22,8 @@ (scheme cyclone macros) (scheme cyclone libraries)) +(define *optimization-level* 2) ;; Default level + ;; Code emission. ; c-compile-and-emit : (string -> A) exp -> void @@ -228,10 +230,11 @@ (trace:info "---------------- after CPS:") (trace:info input-program) ;pretty-print - (set! input-program - (optimize-cps input-program)) - (trace:info "---------------- after cps optimizations:") - (trace:info input-program) + (when (> *optimization-level* 0) + (set! input-program + (optimize-cps input-program)) + (trace:info "---------------- after cps optimizations:") + (trace:info input-program)) (set! input-program (map @@ -380,6 +383,11 @@ (equal? #\- (string-ref arg 0))))) args)) (compile? #t)) + ;; Set optimization level(s) + (if (member "-O0" args) + (set! *optimization-level* 0)) + ;; TODO: place more optimization reading here as necessary + ;; End optimizations (if (member "-t" args) (set! *trace-level* 4)) ;; Show all trace output (if (member "-d" args) @@ -392,6 +400,8 @@ -d Only generate intermediate C files, do not compile them -h, --help Display usage information -v Display version information + -Ox Optimization level, higher means more optimizations will + be used. Set to 0 to disable optimizations. --autogen Cyclone developer use only, create autogen.out file ") (newline))