* make CHR load its private stuff silently
[chr.git] / chr_compiler_options.pl
blob47c66292bbb7388b8940e8baf594645cbe01e5ac
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).
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 - on,
84 ai_observation_analysis - on,
85 late_allocation - on,
86 reduced_indexing - on,
87 term_indexing - on
89 option_definition(optimize,full,Flags) :-
90 Flags = [ functional_dependency_analysis - on,
91 check_unnecessary_active - full,
92 reorder_heads - on,
93 set_semantics_rule - on,
94 storage_analysis - on,
95 guard_via_reschedule - on,
96 guard_simplification - on,
97 check_impossible_rules - on,
98 occurrence_subsumption - on,
99 observation - on,
100 ai_observation_analysis - on,
101 late_allocation - on,
102 reduced_indexing - on
105 option_definition(optimize,off,Flags) :-
106 Flags = [ functional_dependency_analysis - off,
107 check_unnecessary_active - off,
108 reorder_heads - off,
109 set_semantics_rule - off,
110 storage_analysis - off,
111 guard_via_reschedule - off,
112 guard_simplification - off,
113 check_impossible_rules - off,
114 occurrence_subsumption - off,
115 observation - off,
116 ai_observation_analysis - off,
117 late_allocation - off,
118 reduced_indexing - off
121 option_definition(functional_dependency_analysis,on,Flags) :-
122 Flags = [ functional_dependency_analysis - on ].
123 option_definition(functional_dependency_analysis,off,Flags) :-
124 Flags = [ functional_dependency_analysis - off ].
126 option_definition(set_semantics_rule,on,Flags) :-
127 Flags = [ set_semantics_rule - on ].
128 option_definition(set_semantics_rule,off,Flags) :-
129 Flags = [ set_semantics_rule - off ].
131 option_definition(check_unnecessary_active,full,Flags) :-
132 Flags = [ check_unnecessary_active - full ].
133 option_definition(check_unnecessary_active,simplification,Flags) :-
134 Flags = [ check_unnecessary_active - simplification ].
135 option_definition(check_unnecessary_active,off,Flags) :-
136 Flags = [ check_unnecessary_active - off ].
138 option_definition(check_guard_bindings,on,Flags) :-
139 Flags = [ guard_locks - on ].
140 option_definition(check_guard_bindings,off,Flags) :-
141 Flags = [ guard_locks - off ].
143 option_definition(reduced_indexing,on,Flags) :-
144 Flags = [ reduced_indexing - on ].
145 option_definition(reduced_indexing,off,Flags) :-
146 Flags = [ reduced_indexing - off ].
148 option_definition(storage_analysis,on,Flags) :-
149 Flags = [ storage_analysis - on ].
150 option_definition(storage_analysis,off,Flags) :-
151 Flags = [ storage_analysis - off ].
153 option_definition(guard_simplification,on,Flags) :-
154 Flags = [ guard_simplification - on ].
155 option_definition(guard_simplification,off,Flags) :-
156 Flags = [ guard_simplification - off ].
158 option_definition(check_impossible_rules,on,Flags) :-
159 Flags = [ check_impossible_rules - on ].
160 option_definition(check_impossible_rules,off,Flags) :-
161 Flags = [ check_impossible_rules - off ].
163 option_definition(occurrence_subsumption,on,Flags) :-
164 Flags = [ occurrence_subsumption - on ].
165 option_definition(occurrence_subsumption,off,Flags) :-
166 Flags = [ occurrence_subsumption - off ].
168 option_definition(late_allocation,on,Flags) :-
169 Flags = [ late_allocation - on ].
170 option_definition(late_allocation,off,Flags) :-
171 Flags = [ late_allocation - off ].
173 option_definition(type_definition,TypeDef,[]) :-
174 ( nonvar(TypeDef) ->
175 TypeDef = type(T,D),
176 chr_translate:type_definition(T,D)
177 ; true).
178 option_definition(type_declaration,TypeDecl,[]) :-
179 ( nonvar(TypeDecl) ->
180 functor(TypeDecl,F,A),
181 TypeDecl =.. [_|ArgTypes],
182 chr_translate:constraint_type(F/A,ArgTypes)
183 ; true).
185 option_definition(mode,ModeDecl,[]) :-
186 ( nonvar(ModeDecl) ->
187 functor(ModeDecl,F,A),
188 ModeDecl =.. [_|ArgModes],
189 chr_translate:constraint_mode(F/A,ArgModes)
190 ; true).
191 option_definition(store,FA-Store,[]) :-
192 chr_translate:store_type(FA,Store).
194 option_definition(debug,off,Flags) :-
195 option_definition(optimize,full,Flags2),
196 Flags = [ debugable - off | Flags2].
197 option_definition(debug,on,Flags) :-
198 ( local_current_prolog_flag(generate_debug_info,off) ->
199 % TODO: should not be allowed when nodebug flag is set in SWI-Prolog
200 chr_warning(any,':- chr_option(debug,on) inconsistent with current_prolog_flag(generate_debug_info,off\n\tCHR option is ignored!\n)',[]),
201 Flags = []
203 Flags = [ debugable - on ]
206 option_definition(store_counter,off,[]).
207 option_definition(store_counter,on,[store_counter-on]).
209 option_definition(observation,off,Flags) :-
210 Flags = [
211 observation_analysis - off,
212 ai_observation_analysis - off,
213 late_allocation - off,
214 storage_analysis - off
216 option_definition(observation,on,Flags) :-
217 Flags = [
218 observation_analysis - on,
219 ai_observation_analysis - on
221 option_definition(observation,regular,Flags) :-
222 Flags = [
223 observation_analysis - on,
224 ai_observation_analysis - off
226 option_definition(observation,ai,Flags) :-
227 Flags = [
228 observation_analysis - off,
229 ai_observation_analysis - on
232 option_definition(solver_events,NMod,Flags) :-
233 Flags = [solver_events - NMod].
235 option_definition(toplevel_show_store,on,Flags) :-
236 Flags = [toplevel_show_store - on].
238 option_definition(toplevel_show_store,off,Flags) :-
239 Flags = [toplevel_show_store - off].
241 option_definition(term_indexing,on,Flags) :-
242 Flags = [term_indexing - on].
243 optioff_definition(term_indexing,off,Flags) :-
244 Flags = [term_indexing - off].
246 init_chr_pp_flags :-
247 chr_pp_flag_definition(Name,[DefaultValue|_]),
248 set_chr_pp_flag(Name,DefaultValue),
249 fail.
250 init_chr_pp_flags.
252 set_chr_pp_flags([]).
253 set_chr_pp_flags([Name-Value|Flags]) :-
254 set_chr_pp_flag(Name,Value),
255 set_chr_pp_flags(Flags).
257 set_chr_pp_flag(Name,Value) :-
258 atom_concat('$chr_pp_',Name,GlobalVar),
259 nb_setval(GlobalVar,Value).
261 chr_pp_flag_definition(functional_dependency_analysis,[off,on]).
262 chr_pp_flag_definition(check_unnecessary_active,[off,full,simplification]).
263 chr_pp_flag_definition(reorder_heads,[off,on]).
264 chr_pp_flag_definition(set_semantics_rule,[off,on]).
265 chr_pp_flag_definition(guard_via_reschedule,[off,on]).
266 chr_pp_flag_definition(guard_locks,[on,off]).
267 chr_pp_flag_definition(storage_analysis,[off,on]).
268 chr_pp_flag_definition(debugable,[on,off]).
269 chr_pp_flag_definition(reduced_indexing,[off,on]).
270 chr_pp_flag_definition(observation_analysis,[off,on]).
271 chr_pp_flag_definition(ai_observation_analysis,[off,on]).
272 chr_pp_flag_definition(late_allocation,[off,on]).
273 chr_pp_flag_definition(store_counter,[off,on]).
274 chr_pp_flag_definition(guard_simplification,[off,on]).
275 chr_pp_flag_definition(check_impossible_rules,[off,on]).
276 chr_pp_flag_definition(occurrence_subsumption,[off,on]).
277 chr_pp_flag_definition(observation,[off,on]).
278 chr_pp_flag_definition(show,[off,on]).
279 chr_pp_flag_definition(solver_events,[none,_]).
280 chr_pp_flag_definition(toplevel_show_store,[on,off]).
281 chr_pp_flag_definition(term_indexing,[off,on]).
283 chr_pp_flag(Name,Value) :-
284 atom_concat('$chr_pp_',Name,GlobalVar),
285 nb_getval(GlobalVar,V),
286 ( V == [] ->
287 chr_pp_flag_definition(Name,[Value|_])
289 V = Value
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%