suppress spurious warnings
[chr.git] / chr_compiler_options.pl
blob77bc5fe511930932bcbce66d0ae04dc2ab66f510
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 %------------------------------------------------------------------------------%
213 option_definition(debug,off,Flags) :-
214 option_definition(optimize,full,Flags2),
215 Flags = [ debugable - off | Flags2].
216 option_definition(debug,on,Flags) :-
217 ( local_current_prolog_flag(generate_debug_info,false) ->
218 % TODO: should not be allowed when nodebug flag is set in SWI-Prolog
219 chr_warning(any,':- chr_option(debug,on) inconsistent with current_prolog_flag(generate_debug_info,off\n\tCHR option is ignored!\n)',[]),
220 Flags = []
222 Flags = [ debugable - on ]
225 option_definition(store_counter,off,[]).
226 option_definition(store_counter,on,[store_counter-on]).
228 option_definition(observation,off,Flags) :-
229 Flags = [
230 observation_analysis - off,
231 ai_observation_analysis - off,
232 late_allocation - off,
233 storage_analysis - off
235 option_definition(observation,on,Flags) :-
236 Flags = [
237 observation_analysis - on,
238 ai_observation_analysis - on
240 option_definition(observation,regular,Flags) :-
241 Flags = [
242 observation_analysis - on,
243 ai_observation_analysis - off
245 option_definition(observation,ai,Flags) :-
246 Flags = [
247 observation_analysis - off,
248 ai_observation_analysis - on
251 option_definition(store_in_guards, on, [store_in_guards - on]).
252 option_definition(store_in_guards, off, [store_in_guards - off]).
254 option_definition(solver_events,NMod,Flags) :-
255 Flags = [solver_events - NMod].
257 option_definition(toplevel_show_store,on,Flags) :-
258 Flags = [toplevel_show_store - on].
260 option_definition(toplevel_show_store,off,Flags) :-
261 Flags = [toplevel_show_store - off].
263 option_definition(term_indexing,on,Flags) :-
264 Flags = [term_indexing - on].
265 option_definition(term_indexing,off,Flags) :-
266 Flags = [term_indexing - off].
268 option_definition(verbosity,on,Flags) :-
269 Flags = [verbosity - on].
270 option_definition(verbosity,off,Flags) :-
271 Flags = [verbosity - off].
273 option_definition(ht_removal,on,Flags) :-
274 Flags = [ht_removal - on].
275 option_definition(ht_removal,off,Flags) :-
276 Flags = [ht_removal - off].
278 option_definition(mixed_stores,on,Flags) :-
279 Flags = [mixed_stores - on].
280 option_definition(mixed_stores,off,Flags) :-
281 Flags = [mixed_stores - off].
283 option_definition(line_numbers,on,Flags) :-
284 Flags = [line_numbers - on].
285 option_definition(line_numbers,off,Flags) :-
286 Flags = [line_numbers - off].
288 option_definition(dynattr,on,Flags) :-
289 Flags = [dynattr - on].
290 option_definition(dynattr,off,Flags) :-
291 Flags = [dynattr - off].
293 option_definition(verbose,off,[verbose-off]).
294 option_definition(verbose,on,[verbose-on]).
296 init_chr_pp_flags :-
297 chr_pp_flag_definition(Name,[DefaultValue|_]),
298 set_chr_pp_flag(Name,DefaultValue),
299 fail.
300 init_chr_pp_flags.
302 set_chr_pp_flags([]).
303 set_chr_pp_flags([Name-Value|Flags]) :-
304 set_chr_pp_flag(Name,Value),
305 set_chr_pp_flags(Flags).
307 set_chr_pp_flag(Name,Value) :-
308 atom_concat('$chr_pp_',Name,GlobalVar),
309 nb_setval(GlobalVar,Value).
311 chr_pp_flag_definition(functional_dependency_analysis,[off,on]).
312 chr_pp_flag_definition(check_unnecessary_active,[off,full,simplification]).
313 chr_pp_flag_definition(reorder_heads,[off,on]).
314 chr_pp_flag_definition(set_semantics_rule,[off,on]).
315 chr_pp_flag_definition(guard_via_reschedule,[off,on]).
316 chr_pp_flag_definition(guard_locks,[on,off]).
317 chr_pp_flag_definition(storage_analysis,[off,on]).
318 chr_pp_flag_definition(debugable,[on,off]).
319 chr_pp_flag_definition(reduced_indexing,[off,on]).
320 chr_pp_flag_definition(observation_analysis,[off,on]).
321 chr_pp_flag_definition(ai_observation_analysis,[off,on]).
322 chr_pp_flag_definition(store_in_guards,[off,on]).
323 chr_pp_flag_definition(late_allocation,[off,on]).
324 chr_pp_flag_definition(store_counter,[off,on]).
325 chr_pp_flag_definition(guard_simplification,[off,on]).
326 chr_pp_flag_definition(check_impossible_rules,[off,on]).
327 chr_pp_flag_definition(occurrence_subsumption,[off,on]).
328 chr_pp_flag_definition(observation,[off,on]).
329 chr_pp_flag_definition(show,[off,on]).
330 chr_pp_flag_definition(inline_insertremove,[on,off]).
331 chr_pp_flag_definition(solver_events,[none,_]).
332 chr_pp_flag_definition(toplevel_show_store,[on,off]).
333 chr_pp_flag_definition(term_indexing,[off,on]).
334 chr_pp_flag_definition(verbosity,[on,off]).
335 chr_pp_flag_definition(ht_removal,[off,on]).
336 chr_pp_flag_definition(mixed_stores,[off,on]).
337 chr_pp_flag_definition(line_numbers,[off,on]).
338 chr_pp_flag_definition(dynattr,[off,on]).
339 chr_pp_flag_definition(experiment,[off,on]).
340 chr_pp_flag_definition(verbose,[off,on]).
342 chr_pp_flag_definition(declare_stored_constraints,[off,on]).
344 chr_pp_flag(Name,Value) :-
345 atom_concat('$chr_pp_',Name,GlobalVar),
346 nb_getval(GlobalVar,V),
347 ( V == [] ->
348 chr_pp_flag_definition(Name,[Value|_])
350 V = Value
354 % TODO: add whatever goes wrong with (debug,on), (optimize,full) combo here!
355 % trivial example of what does go wrong:
356 % b <=> true.
357 % !!!
358 sanity_check :-
359 chr_pp_flag(store_in_guards, on),
360 chr_pp_flag(ai_observation_analysis, on),
361 chr_warning(any, 'ai_observation_analysis should be turned off when using store_in_guards\n', []),
362 fail.
363 sanity_check.
364 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%