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

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

corrected a bug in loop peeling where continue and breaks were not handled right

File size: 7.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 reindex_flag                = ref true
51
52let transformations = ref []
53let reindexing_transformations = ref []
54let add_transformation, add_reindexing_transformation =
55  let add_to l t () = l := !l @ [t] in
56  add_to transformations, add_to reindexing_transformations
57let add_transformations (safe, reindexing) () =
58  transformations := !transformations @ safe ;
59  reindexing_transformations := !reindexing_transformations @ reindexing
60let get_transformations () =
61  if !reindex_flag then
62    !transformations @ !reindexing_transformations
63  else !transformations
64
65let cost_ternary_flag           = ref true
66let set_cost_ternary            = (:=) cost_ternary_flag
67let is_cost_ternary_enabled ()  = !cost_ternary_flag
68
69let asm_pretty_flag             = ref false
70let set_asm_pretty              = (:=) asm_pretty_flag
71let is_asm_pretty ()            = !asm_pretty_flag
72
73let lustre_flag                 = ref false
74let set_lustre_file             = (:=) lustre_flag
75let is_lustre_file ()           = !lustre_flag
76
77let remove_lustre_externals       = ref false
78let set_remove_lustre_externals   = (:=) remove_lustre_externals
79let is_remove_lustre_externals () = !remove_lustre_externals
80
81let lustre_test                 = ref None
82let set_lustre_test s           = lustre_test := Some s
83let get_lustre_test ()          = !lustre_test
84
85let lustre_test_cases           = ref 100
86let set_lustre_test_cases       = (:=) lustre_test_cases
87let get_lustre_test_cases ()    = !lustre_test_cases
88
89let lustre_test_cycles          = ref 100
90let set_lustre_test_cycles      = (:=) lustre_test_cycles
91let get_lustre_test_cycles ()   = !lustre_test_cycles
92
93let lustre_test_min_int         = ref (-1000)
94let set_lustre_test_min_int     = (:=) lustre_test_min_int
95let get_lustre_test_min_int ()  = !lustre_test_min_int
96
97let lustre_test_max_int         = ref 1000
98let set_lustre_test_max_int     = (:=) lustre_test_max_int
99let get_lustre_test_max_int ()  = !lustre_test_max_int
100
101
102(*
103let print_result_flag           = ref false
104let set_print_result            = (:=) print_result_flag
105let is_print_result_enabled ()  = !print_result_flag
106*)
107
108let dev_test                    = ref false
109let set_dev_test                = (:=) dev_test
110let is_dev_test_enabled ()      = !dev_test
111
112let help_specify_opt_stage ?(reind = false) (trans : Languages.transformation) =
113  extra_doc (Printf.sprintf " [%sdone in %s]"
114               (if reind then "reindexing transformation, " else "")
115               (Languages.to_string (fst trans)))
116
117let basic_optimizations =
118  ([
119    ConstPropagation.trans;
120    CopyPropagation.trans;
121    RedundancyElimination.trans;
122    CopyPropagation.trans;
123    RedundancyElimination.trans;
124    RTLConstPropagation.trans;
125    SimplePeephole.trans
126  ],[
127    LoopPeeling.trans
128  ])
129
130let options = OptionsParsing.register [
131(*
132  "-s", Arg.String set_source_language,
133  " Choose the source language between:";
134  extra_doc " Clight, Cminor";
135  extra_doc " [default is C]";
136*)
137
138  "-l", Arg.String set_target_language,
139  " Choose the target language between:";
140  extra_doc " Clight, Cminor, RTLabs, RTL, ERTL, LTL, LIN, ASM";
141  extra_doc " [default is ASM]";
142
143  "-a", Arg.Set annotation_flag,
144  " Add cost annotations on the source code.";
145
146  "-i", Arg.Set interpretation_flag,
147  " Interpret the compiled code.";
148
149  "-is", Arg.Set interpretations_flag,
150  " Interpret all the compilation passes.";
151
152  "-d", Arg.Set debug_flag,
153  " Debugging mode.";
154
155  "-o", Arg.String set_output_files,
156  " Prefix of the output files.";
157
158  "-asm-pretty", Arg.Set asm_pretty_flag,
159  " Output a pretty-printed assembly file.";
160
161  "-lustre", Arg.Set lustre_flag,
162  " Input file is a Lustre file.";
163
164  "-remove-lustre-externals", Arg.Set remove_lustre_externals,
165  " Remove Lustre externals.";
166
167  "-lustre-test", Arg.String set_lustre_test,
168  " Input file is a Lustre file, testing requested.";
169
170  "-lustre-test-cases", Arg.Int set_lustre_test_cases,
171  " Set the number of test cases when testing a Lustre";
172  extra_doc " file.";
173  extra_doc " [default is 100]";
174
175  "-lustre-test-cycles", Arg.Int set_lustre_test_cycles,
176  " Set the number of cycles for each case when testing";
177  extra_doc " a Lustre file.";
178  extra_doc " [default is 100]";
179
180  "-lustre-test-min-int", Arg.Int set_lustre_test_min_int,
181  " Random int minimum value when testing a Lustre file.";
182  extra_doc " [default is -1000]";
183
184  "-lustre-test-max-int", Arg.Int set_lustre_test_max_int,
185  " Random int maximum value when testing a Lustre file.";
186  extra_doc " [default is 1000]";
187
188  "-peel", Arg.Unit (add_reindexing_transformation LoopPeeling.trans),
189  " Apply loop peeling.";
190    help_specify_opt_stage ~reind:true LoopPeeling.trans;
191
192  "-cst-prop", Arg.Unit (add_transformations
193                           ([ConstPropagation.trans;
194                             RTLConstPropagation.trans], [])),
195  " Apply constant propagation.";
196  help_specify_opt_stage ConstPropagation.trans;
197  help_specify_opt_stage RTLConstPropagation.trans;
198
199  "-cpy-prop", Arg.Unit (add_transformation CopyPropagation.trans),
200  " Apply copy propagation.";
201    help_specify_opt_stage CopyPropagation.trans;
202
203  "-pre", Arg.Unit (add_transformation RedundancyElimination.trans),
204  " Apply partial redundancy elimination.";
205    help_specify_opt_stage RedundancyElimination.trans;
206
207  "-unroll-for",
208  Arg.Int (fun i -> add_reindexing_transformation (
209    LoopUnrolling.trans ~factor:i ()) ()),
210  " Apply loop unrolling, specifying factor.";
211  help_specify_opt_stage ~reind:true (LoopUnrolling.trans ());
212
213  "-unroll", Arg.Unit (add_reindexing_transformation (LoopUnrolling.trans ())),
214  " Apply loop unrolling.";
215  help_specify_opt_stage ~reind:true (LoopUnrolling.trans ());
216
217  "-peeph", Arg.Unit (add_transformation SimplePeephole.trans),
218  " Apply some basic peephole optimizations.";
219  help_specify_opt_stage (SimplePeephole.trans);
220
221  "-O", Arg.Unit (add_transformations basic_optimizations),
222  " Apply some optimizations.";
223
224  "-no-cost-tern",  Arg.Clear cost_ternary_flag,
225  " Replace cost ternary expressions with equivalent";
226  extra_doc " branch statements.";
227
228  "-no-reindex", Arg.Clear reindex_flag,
229  " Prevent optimizations that reindex labels.";
230(*
231  "-res", Arg.Set print_result_flag,
232  " Print the result of interpretations.";
233*)
234
235  "-dev", Arg.Set dev_test,
236  " Playground for developers.";
237]
Note: See TracBrowser for help on using the repository browser.