source: Deliverables/D2.2/8051/src/options.ml @ 1542

Last change on this file since 1542 was 1542, checked in by tranquil, 8 years ago

merge of indexed labels branch

File size: 6.8 KB
Line 
1open Misc.ArgExt
2
3let default_choice       = "default"
4let option_settings_step = "during option settings"
5
6let language_from_string kind default s =
7  try 
8    Languages.from_string s
9  with Not_found -> 
10    if s = default_choice then 
11      default
12    else 
13      Error.global_error option_settings_step
14        (Printf.sprintf "`%s' is not a valid %s language." s kind)
15 
16let source_language_of_string   = language_from_string "source" Languages.Clight
17let source_language             = ref (source_language_of_string default_choice)
18let set_source_language s       = source_language := source_language_of_string s
19let get_source_language ()      = !source_language
20
21let target_language_of_string   = language_from_string "target" Languages.ASM
22let target_language             = ref (target_language_of_string default_choice)
23let set_target_language s       = target_language := target_language_of_string s
24let get_target_language ()      = !target_language
25
26let input_files                 = ref []
27let add_input_file f            = input_files := f :: !input_files
28let input_files ()              = !input_files
29
30let output_files                = ref None
31let set_output_files s          = output_files := Some s
32let get_output_files ()         = !output_files
33
34let annotation_flag             = ref false
35let request_annotation          = (:=) annotation_flag
36let annotation_requested ()     = !annotation_flag
37
38let interpretation_flag         = ref false
39let request_interpretation      = (:=) interpretation_flag
40let interpretation_requested () = !interpretation_flag
41
42let interpretations_flag         = ref false
43let request_interpretations      = (:=) interpretations_flag
44let interpretations_requested () = !interpretations_flag
45
46let debug_flag                  = ref false
47let set_debug                   = (:=) debug_flag
48let is_debug_enabled ()         = !debug_flag
49
50let transformations = ref []
51let add_transformation t () = transformations := !transformations @ [t]
52let add_transformations ts () = transformations := !transformations @ ts
53let get_transformations () = !transformations
54
55let cost_ternary_flag           = ref true
56let set_cost_ternary            = (:=) cost_ternary_flag
57let is_cost_ternary_enabled ()  = !cost_ternary_flag
58
59let asm_pretty_flag             = ref false
60let set_asm_pretty              = (:=) asm_pretty_flag
61let is_asm_pretty ()            = !asm_pretty_flag
62
63let lustre_flag                 = ref false
64let set_lustre_file             = (:=) lustre_flag
65let is_lustre_file ()           = !lustre_flag
66
67let remove_lustre_externals       = ref false
68let set_remove_lustre_externals   = (:=) remove_lustre_externals
69let is_remove_lustre_externals () = !remove_lustre_externals
70
71let lustre_test                 = ref None
72let set_lustre_test s           = lustre_test := Some s
73let get_lustre_test ()          = !lustre_test
74
75let lustre_test_cases           = ref 100
76let set_lustre_test_cases       = (:=) lustre_test_cases
77let get_lustre_test_cases ()    = !lustre_test_cases
78
79let lustre_test_cycles          = ref 100
80let set_lustre_test_cycles      = (:=) lustre_test_cycles
81let get_lustre_test_cycles ()   = !lustre_test_cycles
82
83let lustre_test_min_int         = ref (-1000)
84let set_lustre_test_min_int     = (:=) lustre_test_min_int
85let get_lustre_test_min_int ()  = !lustre_test_min_int
86
87let lustre_test_max_int         = ref 1000
88let set_lustre_test_max_int     = (:=) lustre_test_max_int
89let get_lustre_test_max_int ()  = !lustre_test_max_int
90
91
92(*
93let print_result_flag           = ref false
94let set_print_result            = (:=) print_result_flag
95let is_print_result_enabled ()  = !print_result_flag
96*)
97
98let dev_test                    = ref false
99let set_dev_test                = (:=) dev_test
100let is_dev_test_enabled ()      = !dev_test
101
102let help_specify_opt_stage (trans : Languages.transformation) =
103        Printf.sprintf "(done at the %s stage)." (Languages.to_string (fst trans)) 
104
105let basic_optimizations =
106  [
107    LoopPeeling.trans;
108    ConstPropagation.trans;
109    CopyPropagation.trans;
110    RedundancyElimination.trans;
111    CopyPropagation.trans;
112    RedundancyElimination.trans
113  ]
114 
115
116let options = OptionsParsing.register [
117(*
118  "-s", Arg.String set_source_language,
119  " Choose the source language between:";
120  extra_doc " Clight, Cminor";
121  extra_doc " [default is C]";
122*)
123
124  "-l", Arg.String set_target_language,
125  " Choose the target language between:";
126  extra_doc " Clight, Cminor, RTLabs, RTL, ERTL, LTL, LIN, ASM";
127  extra_doc " [default is ASM]";
128
129  "-a", Arg.Set annotation_flag,
130  " Add cost annotations on the source code.";
131
132  "-i", Arg.Set interpretation_flag,
133  " Interpret the compiled code.";
134
135  "-is", Arg.Set interpretations_flag,
136  " Interpret all the compilation passes.";
137
138  "-d", Arg.Set debug_flag,
139  " Debugging mode.";
140
141  "-o", Arg.String set_output_files,
142  " Prefix of the output files.";
143
144  "-asm-pretty", Arg.Set asm_pretty_flag,
145  " Output a pretty-printed assembly file.";
146
147  "-lustre", Arg.Set lustre_flag,
148  " Input file is a Lustre file.";
149
150  "-remove-lustre-externals", Arg.Set remove_lustre_externals,
151  " Remove Lustre externals.";
152
153  "-lustre-test", Arg.String set_lustre_test,
154  " Input file is a Lustre file, testing requested.";
155
156  "-lustre-test-cases", Arg.Int set_lustre_test_cases,
157  " Set the number of test cases when testing a Lustre";
158  extra_doc " file.";
159  extra_doc " [default is 100]";
160
161  "-lustre-test-cycles", Arg.Int set_lustre_test_cycles,
162  " Set the number of cycles for each case when testing";
163  extra_doc " a Lustre file.";
164  extra_doc " [default is 100]";
165
166  "-lustre-test-min-int", Arg.Int set_lustre_test_min_int,
167  " Random int minimum value when testing a Lustre file.";
168  extra_doc " [default is -1000]";
169
170  "-lustre-test-max-int", Arg.Int set_lustre_test_max_int,
171  " Random int maximum value when testing a Lustre file.";
172  extra_doc " [default is 1000]";
173
174  "-peel", Arg.Unit (add_transformation LoopPeeling.trans),
175  " Apply loop peeling " ^
176    help_specify_opt_stage LoopPeeling.trans;
177
178  "-cst-prop", Arg.Unit (add_transformation ConstPropagation.trans),
179  " Apply constant propagation " ^
180    help_specify_opt_stage ConstPropagation.trans;
181
182  "-cpy-prop", Arg.Unit (add_transformation CopyPropagation.trans),
183  " Apply copy propagation " ^
184    help_specify_opt_stage CopyPropagation.trans;
185
186  "-pre", Arg.Unit (add_transformation RedundancyElimination.trans),
187  " Apply partial redundancy elimination " ^
188    help_specify_opt_stage RedundancyElimination.trans;
189
190  "-unroll-for",
191  Arg.Int (fun i -> add_transformation (LoopUnrolling.trans ~factor:i ()) ()),
192  " Apply loop unrolling, specifying factor " ^
193  help_specify_opt_stage (LoopUnrolling.trans ());
194
195  "-unroll", Arg.Unit (add_transformation (LoopUnrolling.trans ())),
196  " Apply loop unrolling " ^
197  help_specify_opt_stage (LoopUnrolling.trans ());
198
199  "-O", Arg.Unit (add_transformations basic_optimizations),
200  " Apply some optimizations.";
201
202  "-no-cost-tern",  Arg.Clear cost_ternary_flag,
203  " Replace cost ternary expressions with equivalent branch statements.";
204 
205(*
206  "-res", Arg.Set print_result_flag,
207  " Print the result of interpretations.";
208*)
209
210  "-dev", Arg.Set dev_test,
211  " Playground for developers.";
212]
Note: See TracBrowser for help on using the repository browser.