Merge branch 'master' of /home/pl/chr
[chr.git] / chr_compiler_options.pl
blob4728a8d1f3124a195718a8d9bd615d7e7744fd4a
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 ].
146 option_definition(check_guard_bindings,error,Flags) :-
147 Flags = [ guard_locks - error ].
149 option_definition(reduced_indexing,on,Flags) :-
150 Flags = [ reduced_indexing - on ].
151 option_definition(reduced_indexing,off,Flags) :-
152 Flags = [ reduced_indexing - off ].
154 option_definition(storage_analysis,on,Flags) :-
155 Flags = [ storage_analysis - on ].
156 option_definition(storage_analysis,off,Flags) :-
157 Flags = [ storage_analysis - off ].
159 option_definition(guard_simplification,on,Flags) :-
160 Flags = [ guard_simplification - on ].
161 option_definition(guard_simplification,off,Flags) :-
162 Flags = [ guard_simplification - off ].
164 option_definition(check_impossible_rules,on,Flags) :-
165 Flags = [ check_impossible_rules - on ].
166 option_definition(check_impossible_rules,off,Flags) :-
167 Flags = [ check_impossible_rules - off ].
169 option_definition(occurrence_subsumption,on,Flags) :-
170 Flags = [ occurrence_subsumption - on ].
171 option_definition(occurrence_subsumption,off,Flags) :-
172 Flags = [ occurrence_subsumption - off ].
174 option_definition(late_allocation,on,Flags) :-
175 Flags = [ late_allocation - on ].
176 option_definition(late_allocation,off,Flags) :-
177 Flags = [ late_allocation - off ].
179 option_definition(inline_insertremove,on,Flags) :-
180 Flags = [ inline_insertremove - on ].
181 option_definition(inline_insertremove,off,Flags) :-
182 Flags = [ inline_insertremove - off ].
184 option_definition(type_definition,TypeDef,[]) :-
185 ( nonvar(TypeDef) ->
186 TypeDef = type(T,D),
187 chr_translate:type_definition(T,D)
188 ; true).
189 option_definition(type_declaration,TypeDecl,[]) :-
190 ( nonvar(TypeDecl) ->
191 functor(TypeDecl,F,A),
192 TypeDecl =.. [_|ArgTypes],
193 chr_translate:constraint_type(F/A,ArgTypes)
194 ; true).
196 option_definition(mode,ModeDecl,[]) :-
197 ( nonvar(ModeDecl) ->
198 functor(ModeDecl,F,A),
199 ModeDecl =.. [_|ArgModes],
200 chr_translate:constraint_mode(F/A,ArgModes)
201 ; true).
202 option_definition(store,FA-Store,[]) :-
203 chr_translate:store_type(FA,Store).
205 %------------------------------------------------------------------------------%
206 option_definition(declare_stored_constraints,off,[declare_stored_constraints-off]).
207 option_definition(declare_stored_constraints,on ,[declare_stored_constraints-on]).
209 option_definition(stored,F/A,[]) :-
210 chr_translate:stored_assertion(F/A).
211 %------------------------------------------------------------------------------%
212 option_definition(experiment,off,[experiment-off]).
213 option_definition(experiment,on,[experiment-on]).
214 option_definition(experimental,off,[experiment-off]).
215 option_definition(experimental,on,[experiment-on]).
216 option_definition(sss,off,[sss-off]).
217 option_definition(sss,on,[sss-on]).
218 %------------------------------------------------------------------------------%
219 option_definition(debug,off,Flags) :-
220 option_definition(optimize,full,Flags2),
221 Flags = [ debugable - off | Flags2].
222 option_definition(debug,on,Flags) :-
223 ( local_current_prolog_flag(generate_debug_info,false) ->
224 % TODO: should not be allowed when nodebug flag is set in SWI-Prolog
225 chr_warning(any,':- chr_option(debug,on) inconsistent with current_prolog_flag(generate_debug_info,off\n\tCHR option is ignored!\n)',[]),
226 Flags = []
228 Flags = [ debugable - on ]
231 option_definition(store_counter,off,[]).
232 option_definition(store_counter,on,[store_counter-on]).
234 option_definition(observation,off,Flags) :-
235 Flags = [
236 observation_analysis - off,
237 ai_observation_analysis - off,
238 late_allocation - off,
239 storage_analysis - off
241 option_definition(observation,on,Flags) :-
242 Flags = [
243 observation_analysis - on,
244 ai_observation_analysis - on
246 option_definition(observation,regular,Flags) :-
247 Flags = [
248 observation_analysis - on,
249 ai_observation_analysis - off
251 option_definition(observation,ai,Flags) :-
252 Flags = [
253 observation_analysis - off,
254 ai_observation_analysis - on
257 option_definition(store_in_guards, on, [store_in_guards - on]).
258 option_definition(store_in_guards, off, [store_in_guards - off]).
260 option_definition(solver_events,NMod,Flags) :-
261 Flags = [solver_events - NMod].
263 option_definition(toplevel_show_store,on,Flags) :-
264 Flags = [toplevel_show_store - on].
266 option_definition(toplevel_show_store,off,Flags) :-
267 Flags = [toplevel_show_store - off].
269 option_definition(term_indexing,on,Flags) :-
270 Flags = [term_indexing - on].
271 option_definition(term_indexing,off,Flags) :-
272 Flags = [term_indexing - off].
274 option_definition(verbosity,on,Flags) :-
275 Flags = [verbosity - on].
276 option_definition(verbosity,off,Flags) :-
277 Flags = [verbosity - off].
279 option_definition(ht_removal,on,Flags) :-
280 Flags = [ht_removal - on].
281 option_definition(ht_removal,off,Flags) :-
282 Flags = [ht_removal - off].
284 option_definition(mixed_stores,on,Flags) :-
285 Flags = [mixed_stores - on].
286 option_definition(mixed_stores,off,Flags) :-
287 Flags = [mixed_stores - off].
289 option_definition(line_numbers,on,Flags) :-
290 Flags = [line_numbers - on].
291 option_definition(line_numbers,off,Flags) :-
292 Flags = [line_numbers - off].
294 option_definition(dynattr,on,Flags) :-
295 Flags = [dynattr - on].
296 option_definition(dynattr,off,Flags) :-
297 Flags = [dynattr - off].
299 option_definition(verbose,off,[verbose-off]).
300 option_definition(verbose,on,[verbose-on]).
302 option_definition(dump,off,[dump-off]).
303 option_definition(dump,on,[dump-on]).
305 init_chr_pp_flags :-
306 chr_pp_flag_definition(Name,[DefaultValue|_]),
307 set_chr_pp_flag(Name,DefaultValue),
308 fail.
309 init_chr_pp_flags.
311 set_chr_pp_flags([]).
312 set_chr_pp_flags([Name-Value|Flags]) :-
313 set_chr_pp_flag(Name,Value),
314 set_chr_pp_flags(Flags).
316 set_chr_pp_flag(Name,Value) :-
317 atom_concat('$chr_pp_',Name,GlobalVar),
318 nb_setval(GlobalVar,Value).
320 chr_pp_flag_definition(functional_dependency_analysis,[off,on]).
321 chr_pp_flag_definition(check_unnecessary_active,[off,full,simplification]).
322 chr_pp_flag_definition(reorder_heads,[off,on]).
323 chr_pp_flag_definition(set_semantics_rule,[off,on]).
324 chr_pp_flag_definition(guard_via_reschedule,[off,on]).
325 chr_pp_flag_definition(guard_locks,[on,off,error]).
326 chr_pp_flag_definition(storage_analysis,[off,on]).
327 chr_pp_flag_definition(debugable,[on,off]).
328 chr_pp_flag_definition(reduced_indexing,[off,on]).
329 chr_pp_flag_definition(observation_analysis,[off,on]).
330 chr_pp_flag_definition(ai_observation_analysis,[off,on]).
331 chr_pp_flag_definition(store_in_guards,[off,on]).
332 chr_pp_flag_definition(late_allocation,[off,on]).
333 chr_pp_flag_definition(store_counter,[off,on]).
334 chr_pp_flag_definition(guard_simplification,[off,on]).
335 chr_pp_flag_definition(check_impossible_rules,[off,on]).
336 chr_pp_flag_definition(occurrence_subsumption,[off,on]).
337 chr_pp_flag_definition(observation,[off,on]).
338 chr_pp_flag_definition(show,[off,on]).
339 chr_pp_flag_definition(inline_insertremove,[on,off]).
340 chr_pp_flag_definition(solver_events,[none,_]).
341 chr_pp_flag_definition(toplevel_show_store,[on,off]).
342 chr_pp_flag_definition(term_indexing,[off,on]).
343 chr_pp_flag_definition(verbosity,[on,off]).
344 chr_pp_flag_definition(ht_removal,[off,on]).
345 chr_pp_flag_definition(mixed_stores,[on,off]).
346 chr_pp_flag_definition(line_numbers,[off,on]).
347 chr_pp_flag_definition(dynattr,[off,on]).
348 chr_pp_flag_definition(experiment,[off,on]).
349 chr_pp_flag_definition(sss,[off,on]).
350 % emit compiler inferred code
351 chr_pp_flag_definition(verbose,[off,on]).
352 % emit input code and output code
353 chr_pp_flag_definition(dump,[off,on]).
355 chr_pp_flag_definition(declare_stored_constraints,[off,on]).
357 chr_pp_flag(Name,Value) :-
358 atom_concat('$chr_pp_',Name,GlobalVar),
359 nb_getval(GlobalVar,V),
360 ( V == [] ->
361 chr_pp_flag_definition(Name,[Value|_])
363 V = Value
367 % TODO: add whatever goes wrong with (debug,on), (optimize,full) combo here!
368 % trivial example of what does go wrong:
369 % b <=> true.
370 % !!!
371 sanity_check :-
372 chr_pp_flag(store_in_guards, on),
373 chr_pp_flag(ai_observation_analysis, on),
374 chr_warning(any, 'ai_observation_analysis should be turned off when using store_in_guards\n', []),
375 fail.
376 sanity_check.
377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%