Deleted append/2, now available from library lists
[chr.git] / chr_compiler_options.pl
blob0c4ceb526bab3c9e517776894cdeceb687de2134
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 option_definition(debug,off,Flags) :-
204 option_definition(optimize,full,Flags2),
205 Flags = [ debugable - off | Flags2].
206 option_definition(debug,on,Flags) :-
207 ( local_current_prolog_flag(generate_debug_info,false) ->
208 % TODO: should not be allowed when nodebug flag is set in SWI-Prolog
209 chr_warning(any,':- chr_option(debug,on) inconsistent with current_prolog_flag(generate_debug_info,off\n\tCHR option is ignored!\n)',[]),
210 Flags = []
212 Flags = [ debugable - on ]
215 option_definition(store_counter,off,[]).
216 option_definition(store_counter,on,[store_counter-on]).
218 option_definition(observation,off,Flags) :-
219 Flags = [
220 observation_analysis - off,
221 ai_observation_analysis - off,
222 late_allocation - off,
223 storage_analysis - off
225 option_definition(observation,on,Flags) :-
226 Flags = [
227 observation_analysis - on,
228 ai_observation_analysis - on
230 option_definition(observation,regular,Flags) :-
231 Flags = [
232 observation_analysis - on,
233 ai_observation_analysis - off
235 option_definition(observation,ai,Flags) :-
236 Flags = [
237 observation_analysis - off,
238 ai_observation_analysis - on
241 option_definition(store_in_guards, on, [store_in_guards - on]).
242 option_definition(store_in_guards, off, [store_in_guards - off]).
244 option_definition(solver_events,NMod,Flags) :-
245 Flags = [solver_events - NMod].
247 option_definition(toplevel_show_store,on,Flags) :-
248 Flags = [toplevel_show_store - on].
250 option_definition(toplevel_show_store,off,Flags) :-
251 Flags = [toplevel_show_store - off].
253 option_definition(term_indexing,on,Flags) :-
254 Flags = [term_indexing - on].
255 option_definition(term_indexing,off,Flags) :-
256 Flags = [term_indexing - off].
258 option_definition(verbosity,on,Flags) :-
259 Flags = [verbosity - on].
260 option_definition(verbosity,off,Flags) :-
261 Flags = [verbosity - off].
263 option_definition(ht_removal,on,Flags) :-
264 Flags = [ht_removal - on].
265 option_definition(ht_removal,off,Flags) :-
266 Flags = [ht_removal - off].
268 option_definition(mixed_stores,on,Flags) :-
269 Flags = [mixed_stores - on].
270 option_definition(mixed_stores,off,Flags) :-
271 Flags = [mixed_stores - off].
273 option_definition(line_numbers,on,Flags) :-
274 Flags = [line_numbers - on].
275 option_definition(line_numbers,off,Flags) :-
276 Flags = [line_numbers - off].
278 option_definition(dynattr,on,Flags) :-
279 Flags = [dynattr - on].
280 option_definition(dynattr,off,Flags) :-
281 Flags = [dynattr - off].
283 init_chr_pp_flags :-
284 chr_pp_flag_definition(Name,[DefaultValue|_]),
285 set_chr_pp_flag(Name,DefaultValue),
286 fail.
287 init_chr_pp_flags.
289 set_chr_pp_flags([]).
290 set_chr_pp_flags([Name-Value|Flags]) :-
291 set_chr_pp_flag(Name,Value),
292 set_chr_pp_flags(Flags).
294 set_chr_pp_flag(Name,Value) :-
295 atom_concat('$chr_pp_',Name,GlobalVar),
296 nb_setval(GlobalVar,Value).
298 chr_pp_flag_definition(functional_dependency_analysis,[off,on]).
299 chr_pp_flag_definition(check_unnecessary_active,[off,full,simplification]).
300 chr_pp_flag_definition(reorder_heads,[off,on]).
301 chr_pp_flag_definition(set_semantics_rule,[off,on]).
302 chr_pp_flag_definition(guard_via_reschedule,[off,on]).
303 chr_pp_flag_definition(guard_locks,[on,off]).
304 chr_pp_flag_definition(storage_analysis,[off,on]).
305 chr_pp_flag_definition(debugable,[on,off]).
306 chr_pp_flag_definition(reduced_indexing,[off,on]).
307 chr_pp_flag_definition(observation_analysis,[off,on]).
308 chr_pp_flag_definition(ai_observation_analysis,[off,on]).
309 chr_pp_flag_definition(store_in_guards,[off,on]).
310 chr_pp_flag_definition(late_allocation,[off,on]).
311 chr_pp_flag_definition(store_counter,[off,on]).
312 chr_pp_flag_definition(guard_simplification,[off,on]).
313 chr_pp_flag_definition(check_impossible_rules,[off,on]).
314 chr_pp_flag_definition(occurrence_subsumption,[off,on]).
315 chr_pp_flag_definition(observation,[off,on]).
316 chr_pp_flag_definition(show,[off,on]).
317 chr_pp_flag_definition(inline_insertremove,[on,off]).
318 chr_pp_flag_definition(solver_events,[none,_]).
319 chr_pp_flag_definition(toplevel_show_store,[on,off]).
320 chr_pp_flag_definition(term_indexing,[off,on]).
321 chr_pp_flag_definition(verbosity,[on,off]).
322 chr_pp_flag_definition(ht_removal,[off,on]).
323 chr_pp_flag_definition(mixed_stores,[off,on]).
324 chr_pp_flag_definition(line_numbers,[off,on]).
325 chr_pp_flag_definition(dynattr,[off,on]).
327 chr_pp_flag(Name,Value) :-
328 atom_concat('$chr_pp_',Name,GlobalVar),
329 nb_getval(GlobalVar,V),
330 ( V == [] ->
331 chr_pp_flag_definition(Name,[Value|_])
333 V = Value
337 % TODO: add whatever goes wrong with (debug,on), (optimize,full) combo here!
338 % trivial example of what does go wrong:
339 % b <=> true.
340 % !!!
341 sanity_check :-
342 chr_pp_flag(store_in_guards, on),
343 chr_pp_flag(ai_observation_analysis, on),
344 chr_warning(any, 'ai_observation_analysis should be turned off when using store_in_guards\n', []),
345 fail.
346 sanity_check.
347 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%