experimental: specialize chr_enum/1 type in experiment mode
[chr.git] / chr_compiler_options.pl
blob8ef1bbbc56f353c1c1e3bb9a0cf8bfbed4694c09
1 /* $Id$
3 Part of CHR (Constraint Handling Rules)
5 Author: Tom Schrijvers
6 E-mail: Tom.Schrijvers@cs.kuleuven.be
7 WWW: http://www.swi-prolog.org
8 Copyright (C): 2005-2006, K.U. Leuven
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 As a special exception, if you link this library with other files,
25 compiled with a Free Software compiler, to produce an executable, this
26 library does not by itself cause the resulting executable to be covered
27 by the GNU General Public License. This exception does not however
28 invalidate any other reasons why the executable file might be covered by
29 the GNU General Public License.
31 :- module(chr_compiler_options,
32 [ handle_option/2
33 , init_chr_pp_flags/0
34 , chr_pp_flag/2
35 ]).
37 %% SICStus begin
38 %% :- use_module(hprolog, [nb_setval/2,nb_getval/2]).
39 %% local_current_prolog_flag(_,_) :- fail.
40 %% SICStus end
42 %% SWI begin
43 local_current_prolog_flag(X,Y) :- current_prolog_flag(X,Y).
44 %% SWI end
47 :- use_module(chr_compiler_errors).
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 % Global Options
53 handle_option(Name,Value) :-
54 var(Name), !,
55 chr_error(syntax((:- chr_option(Name,Value))),'First argument should be an atom, not a variable.\n',[]).
57 handle_option(Name,Value) :-
58 var(Value), !,
59 chr_error(syntax((:- chr_option(Name,Value))),'Second argument cannot be a variable.\n',[]).
61 handle_option(Name,Value) :-
62 option_definition(Name,Value,Flags),
64 set_chr_pp_flags(Flags).
66 handle_option(Name,Value) :-
67 \+ option_definition(Name,_,_), !,
68 chr_error(syntax((:- chr_option(Name,Value))),'Invalid option name ~w: consult the manual for valid options.\n',[Name]).
70 handle_option(Name,Value) :-
71 chr_error(syntax((:- chr_option(Name,Value))),'Invalid option value ~w: consult the manual for valid option values.\n',[Value]).
73 option_definition(optimize,experimental,Flags) :-
74 Flags = [ functional_dependency_analysis - on,
75 check_unnecessary_active - full,
76 reorder_heads - on,
77 set_semantics_rule - on,
78 storage_analysis - on,
79 guard_via_reschedule - on,
80 guard_simplification - on,
81 check_impossible_rules - on,
82 occurrence_subsumption - on,
83 observation_analysis - on,
84 ai_observation_analysis - on,
85 late_allocation - on,
86 reduced_indexing - on,
87 term_indexing - on,
88 inline_insertremove - on,
89 mixed_stores - on
91 option_definition(optimize,full,Flags) :-
92 Flags = [ functional_dependency_analysis - on,
93 check_unnecessary_active - full,
94 reorder_heads - on,
95 set_semantics_rule - on,
96 storage_analysis - on,
97 guard_via_reschedule - on,
98 guard_simplification - on,
99 check_impossible_rules - on,
100 occurrence_subsumption - on,
101 observation_analysis - on,
102 ai_observation_analysis - on,
103 late_allocation - on,
104 reduced_indexing - on,
105 inline_insertremove - on,
106 mixed_stores - off
109 option_definition(optimize,off,Flags) :-
110 Flags = [ functional_dependency_analysis - off,
111 check_unnecessary_active - off,
112 reorder_heads - off,
113 set_semantics_rule - off,
114 storage_analysis - off,
115 guard_via_reschedule - off,
116 guard_simplification - off,
117 check_impossible_rules - off,
118 occurrence_subsumption - off,
119 observation_analysis - off,
120 ai_observation_analysis - off,
121 late_allocation - off,
122 reduced_indexing - off
125 option_definition(functional_dependency_analysis,on,Flags) :-
126 Flags = [ functional_dependency_analysis - on ].
127 option_definition(functional_dependency_analysis,off,Flags) :-
128 Flags = [ functional_dependency_analysis - off ].
130 option_definition(set_semantics_rule,on,Flags) :-
131 Flags = [ set_semantics_rule - on ].
132 option_definition(set_semantics_rule,off,Flags) :-
133 Flags = [ set_semantics_rule - off ].
135 option_definition(check_unnecessary_active,full,Flags) :-
136 Flags = [ check_unnecessary_active - full ].
137 option_definition(check_unnecessary_active,simplification,Flags) :-
138 Flags = [ check_unnecessary_active - simplification ].
139 option_definition(check_unnecessary_active,off,Flags) :-
140 Flags = [ check_unnecessary_active - off ].
142 option_definition(check_guard_bindings,on,Flags) :-
143 Flags = [ guard_locks - on ].
144 option_definition(check_guard_bindings,off,Flags) :-
145 Flags = [ guard_locks - off ].
147 option_definition(reduced_indexing,on,Flags) :-
148 Flags = [ reduced_indexing - on ].
149 option_definition(reduced_indexing,off,Flags) :-
150 Flags = [ reduced_indexing - off ].
152 option_definition(storage_analysis,on,Flags) :-
153 Flags = [ storage_analysis - on ].
154 option_definition(storage_analysis,off,Flags) :-
155 Flags = [ storage_analysis - off ].
157 option_definition(guard_simplification,on,Flags) :-
158 Flags = [ guard_simplification - on ].
159 option_definition(guard_simplification,off,Flags) :-
160 Flags = [ guard_simplification - off ].
162 option_definition(check_impossible_rules,on,Flags) :-
163 Flags = [ check_impossible_rules - on ].
164 option_definition(check_impossible_rules,off,Flags) :-
165 Flags = [ check_impossible_rules - off ].
167 option_definition(occurrence_subsumption,on,Flags) :-
168 Flags = [ occurrence_subsumption - on ].
169 option_definition(occurrence_subsumption,off,Flags) :-
170 Flags = [ occurrence_subsumption - off ].
172 option_definition(late_allocation,on,Flags) :-
173 Flags = [ late_allocation - on ].
174 option_definition(late_allocation,off,Flags) :-
175 Flags = [ late_allocation - off ].
177 option_definition(inline_insertremove,on,Flags) :-
178 Flags = [ inline_insertremove - on ].
179 option_definition(inline_insertremove,off,Flags) :-
180 Flags = [ inline_insertremove - off ].
182 option_definition(type_definition,TypeDef,[]) :-
183 ( nonvar(TypeDef) ->
184 TypeDef = type(T,D),
185 chr_translate:type_definition(T,D)
186 ; true).
187 option_definition(type_declaration,TypeDecl,[]) :-
188 ( nonvar(TypeDecl) ->
189 functor(TypeDecl,F,A),
190 TypeDecl =.. [_|ArgTypes],
191 chr_translate:constraint_type(F/A,ArgTypes)
192 ; true).
194 option_definition(mode,ModeDecl,[]) :-
195 ( nonvar(ModeDecl) ->
196 functor(ModeDecl,F,A),
197 ModeDecl =.. [_|ArgModes],
198 chr_translate:constraint_mode(F/A,ArgModes)
199 ; true).
200 option_definition(store,FA-Store,[]) :-
201 chr_translate:store_type(FA,Store).
203 %------------------------------------------------------------------------------%
204 option_definition(declare_stored_constraints,off,[declare_stored_constraints-off]).
205 option_definition(declare_stored_constraints,on ,[declare_stored_constraints-on]).
207 option_definition(stored,F/A,[]) :-
208 chr_translate:stored_assertion(F/A).
209 %------------------------------------------------------------------------------%
210 option_definition(experiment,off,[experiment-off]).
211 option_definition(experiment,on,[experiment-on]).
212 option_definition(experimental,off,[experiment-off]).
213 option_definition(experimental,on,[experiment-on]).
214 %------------------------------------------------------------------------------%
215 option_definition(debug,off,Flags) :-
216 option_definition(optimize,full,Flags2),
217 Flags = [ debugable - off | Flags2].
218 option_definition(debug,on,Flags) :-
219 ( local_current_prolog_flag(generate_debug_info,false) ->
220 % TODO: should not be allowed when nodebug flag is set in SWI-Prolog
221 chr_warning(any,':- chr_option(debug,on) inconsistent with current_prolog_flag(generate_debug_info,off\n\tCHR option is ignored!\n)',[]),
222 Flags = []
224 Flags = [ debugable - on ]
227 option_definition(store_counter,off,[]).
228 option_definition(store_counter,on,[store_counter-on]).
230 option_definition(observation,off,Flags) :-
231 Flags = [
232 observation_analysis - off,
233 ai_observation_analysis - off,
234 late_allocation - off,
235 storage_analysis - off
237 option_definition(observation,on,Flags) :-
238 Flags = [
239 observation_analysis - on,
240 ai_observation_analysis - on
242 option_definition(observation,regular,Flags) :-
243 Flags = [
244 observation_analysis - on,
245 ai_observation_analysis - off
247 option_definition(observation,ai,Flags) :-
248 Flags = [
249 observation_analysis - off,
250 ai_observation_analysis - on
253 option_definition(store_in_guards, on, [store_in_guards - on]).
254 option_definition(store_in_guards, off, [store_in_guards - off]).
256 option_definition(solver_events,NMod,Flags) :-
257 Flags = [solver_events - NMod].
259 option_definition(toplevel_show_store,on,Flags) :-
260 Flags = [toplevel_show_store - on].
262 option_definition(toplevel_show_store,off,Flags) :-
263 Flags = [toplevel_show_store - off].
265 option_definition(term_indexing,on,Flags) :-
266 Flags = [term_indexing - on].
267 option_definition(term_indexing,off,Flags) :-
268 Flags = [term_indexing - off].
270 option_definition(verbosity,on,Flags) :-
271 Flags = [verbosity - on].
272 option_definition(verbosity,off,Flags) :-
273 Flags = [verbosity - off].
275 option_definition(ht_removal,on,Flags) :-
276 Flags = [ht_removal - on].
277 option_definition(ht_removal,off,Flags) :-
278 Flags = [ht_removal - off].
280 option_definition(mixed_stores,on,Flags) :-
281 Flags = [mixed_stores - on].
282 option_definition(mixed_stores,off,Flags) :-
283 Flags = [mixed_stores - off].
285 option_definition(line_numbers,on,Flags) :-
286 Flags = [line_numbers - on].
287 option_definition(line_numbers,off,Flags) :-
288 Flags = [line_numbers - off].
290 option_definition(dynattr,on,Flags) :-
291 Flags = [dynattr - on].
292 option_definition(dynattr,off,Flags) :-
293 Flags = [dynattr - off].
295 option_definition(verbose,off,[verbose-off]).
296 option_definition(verbose,on,[verbose-on]).
298 option_definition(dump,off,[dump-off]).
299 option_definition(dump,on,[dump-on]).
301 init_chr_pp_flags :-
302 chr_pp_flag_definition(Name,[DefaultValue|_]),
303 set_chr_pp_flag(Name,DefaultValue),
304 fail.
305 init_chr_pp_flags.
307 set_chr_pp_flags([]).
308 set_chr_pp_flags([Name-Value|Flags]) :-
309 set_chr_pp_flag(Name,Value),
310 set_chr_pp_flags(Flags).
312 set_chr_pp_flag(Name,Value) :-
313 atom_concat('$chr_pp_',Name,GlobalVar),
314 nb_setval(GlobalVar,Value).
316 chr_pp_flag_definition(functional_dependency_analysis,[off,on]).
317 chr_pp_flag_definition(check_unnecessary_active,[off,full,simplification]).
318 chr_pp_flag_definition(reorder_heads,[off,on]).
319 chr_pp_flag_definition(set_semantics_rule,[off,on]).
320 chr_pp_flag_definition(guard_via_reschedule,[off,on]).
321 chr_pp_flag_definition(guard_locks,[on,off]).
322 chr_pp_flag_definition(storage_analysis,[off,on]).
323 chr_pp_flag_definition(debugable,[on,off]).
324 chr_pp_flag_definition(reduced_indexing,[off,on]).
325 chr_pp_flag_definition(observation_analysis,[off,on]).
326 chr_pp_flag_definition(ai_observation_analysis,[off,on]).
327 chr_pp_flag_definition(store_in_guards,[off,on]).
328 chr_pp_flag_definition(late_allocation,[off,on]).
329 chr_pp_flag_definition(store_counter,[off,on]).
330 chr_pp_flag_definition(guard_simplification,[off,on]).
331 chr_pp_flag_definition(check_impossible_rules,[off,on]).
332 chr_pp_flag_definition(occurrence_subsumption,[off,on]).
333 chr_pp_flag_definition(observation,[off,on]).
334 chr_pp_flag_definition(show,[off,on]).
335 chr_pp_flag_definition(inline_insertremove,[on,off]).
336 chr_pp_flag_definition(solver_events,[none,_]).
337 chr_pp_flag_definition(toplevel_show_store,[on,off]).
338 chr_pp_flag_definition(term_indexing,[off,on]).
339 chr_pp_flag_definition(verbosity,[on,off]).
340 chr_pp_flag_definition(ht_removal,[off,on]).
341 chr_pp_flag_definition(mixed_stores,[on,off]).
342 chr_pp_flag_definition(line_numbers,[off,on]).
343 chr_pp_flag_definition(dynattr,[off,on]).
344 chr_pp_flag_definition(experiment,[off,on]).
345 % emit compiler inferred code
346 chr_pp_flag_definition(verbose,[off,on]).
347 % emit input code and output code
348 chr_pp_flag_definition(dump,[off,on]).
350 chr_pp_flag_definition(declare_stored_constraints,[off,on]).
352 chr_pp_flag(Name,Value) :-
353 atom_concat('$chr_pp_',Name,GlobalVar),
354 nb_getval(GlobalVar,V),
355 ( V == [] ->
356 chr_pp_flag_definition(Name,[Value|_])
358 V = Value
362 % TODO: add whatever goes wrong with (debug,on), (optimize,full) combo here!
363 % trivial example of what does go wrong:
364 % b <=> true.
365 % !!!
366 sanity_check :-
367 chr_pp_flag(store_in_guards, on),
368 chr_pp_flag(ai_observation_analysis, on),
369 chr_warning(any, 'ai_observation_analysis should be turned off when using store_in_guards\n', []),
370 fail.
371 sanity_check.
372 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%