minor fixes
[chr.git] / chr_compiler_options.pl
blobb2dc8d65250a4afcf22e6fdd9bfa10c18a029f2d
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 %% SICStus end
41 :- use_module(chr_compiler_errors).
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 % Global Options
47 handle_option(Name,Value) :-
48 var(Name), !,
49 chr_error(syntax((:- chr_option(Name,Value))),'First argument should be an atom, not a variable.\n',[]).
51 handle_option(Name,Value) :-
52 var(Value), !,
53 chr_error(syntax((:- chr_option(Name,Value))),'Second argument cannot be a variable.\n',[]).
55 handle_option(Name,Value) :-
56 option_definition(Name,Value,Flags),
58 set_chr_pp_flags(Flags).
60 handle_option(Name,Value) :-
61 \+ option_definition(Name,_,_), !,
62 chr_error(syntax((:- chr_option(Name,Value))),'Invalid option name ~w: consult the manual for valid options.\n',[Name]).
64 handle_option(Name,Value) :-
65 chr_error(syntax((:- chr_option(Name,Value))),'Invalid option value ~w: consult the manual for valid option values.\n',[Value]).
67 option_definition(optimize,experimental,Flags) :-
68 Flags = [ functional_dependency_analysis - on,
69 check_unnecessary_active - off,
70 reorder_heads - on,
71 set_semantics_rule - off,
72 storage_analysis - on,
73 guard_via_reschedule - on,
74 guard_simplification - on,
75 check_impossible_rules - on,
76 occurrence_subsumption - on,
77 observation - on,
78 ai_observation_analysis - on,
79 late_allocation - on,
80 reduced_indexing - on
82 option_definition(optimize,full,Flags) :-
83 Flags = [ functional_dependency_analysis - on,
84 check_unnecessary_active - full,
85 reorder_heads - on,
86 set_semantics_rule - on,
87 storage_analysis - on,
88 guard_via_reschedule - on,
89 guard_simplification - on,
90 check_impossible_rules - on,
91 occurrence_subsumption - on,
92 observation - on,
93 ai_observation_analysis - on,
94 late_allocation - on,
95 reduced_indexing - on
98 option_definition(optimize,off,Flags) :-
99 Flags = [ functional_dependency_analysis - off,
100 check_unnecessary_active - off,
101 reorder_heads - off,
102 set_semantics_rule - off,
103 storage_analysis - off,
104 guard_via_reschedule - off,
105 guard_simplification - off,
106 check_impossible_rules - off,
107 occurrence_subsumption - off,
108 observation - off,
109 ai_observation_analysis - off,
110 late_allocation - off,
111 reduced_indexing - off
114 option_definition(functional_dependency_analysis,on,Flags) :-
115 Flags = [ functional_dependency_analysis - on ].
116 option_definition(functional_dependency_analysis,off,Flags) :-
117 Flags = [ functional_dependency_analysis - off ].
119 option_definition(set_semantics_rule,on,Flags) :-
120 Flags = [ set_semantics_rule - on ].
121 option_definition(set_semantics_rule,off,Flags) :-
122 Flags = [ set_semantics_rule - off ].
124 option_definition(check_unnecessary_active,full,Flags) :-
125 Flags = [ check_unnecessary_active - full ].
126 option_definition(check_unnecessary_active,simplification,Flags) :-
127 Flags = [ check_unnecessary_active - simplification ].
128 option_definition(check_unnecessary_active,off,Flags) :-
129 Flags = [ check_unnecessary_active - off ].
131 option_definition(check_guard_bindings,on,Flags) :-
132 Flags = [ guard_locks - on ].
133 option_definition(check_guard_bindings,off,Flags) :-
134 Flags = [ guard_locks - off ].
136 option_definition(reduced_indexing,on,Flags) :-
137 Flags = [ reduced_indexing - on ].
138 option_definition(reduced_indexing,off,Flags) :-
139 Flags = [ reduced_indexing - off ].
141 option_definition(storage_analysis,on,Flags) :-
142 Flags = [ storage_analysis - on ].
143 option_definition(storage_analysis,off,Flags) :-
144 Flags = [ storage_analysis - off ].
146 option_definition(guard_simplification,on,Flags) :-
147 Flags = [ guard_simplification - on ].
148 option_definition(guard_simplification,off,Flags) :-
149 Flags = [ guard_simplification - off ].
151 option_definition(check_impossible_rules,on,Flags) :-
152 Flags = [ check_impossible_rules - on ].
153 option_definition(check_impossible_rules,off,Flags) :-
154 Flags = [ check_impossible_rules - off ].
156 option_definition(occurrence_subsumption,on,Flags) :-
157 Flags = [ occurrence_subsumption - on ].
158 option_definition(occurrence_subsumption,off,Flags) :-
159 Flags = [ occurrence_subsumption - off ].
161 option_definition(late_allocation,on,Flags) :-
162 Flags = [ late_allocation - on ].
163 option_definition(late_allocation,off,Flags) :-
164 Flags = [ late_allocation - off ].
166 option_definition(type_definition,TypeDef,[]) :-
167 ( nonvar(TypeDef) ->
168 TypeDef = type(T,D),
169 chr_translate:type_definition(T,D)
170 ; true).
171 option_definition(type_declaration,TypeDecl,[]) :-
172 ( nonvar(TypeDecl) ->
173 functor(TypeDecl,F,A),
174 TypeDecl =.. [_|ArgTypes],
175 chr_translate:constraint_type(F/A,ArgTypes)
176 ; true).
178 option_definition(mode,ModeDecl,[]) :-
179 ( nonvar(ModeDecl) ->
180 functor(ModeDecl,F,A),
181 ModeDecl =.. [_|ArgModes],
182 chr_translate:constraint_mode(F/A,ArgModes)
183 ; true).
184 option_definition(store,FA-Store,[]) :-
185 chr_translate:store_type(FA,Store).
187 option_definition(debug,off,Flags) :-
188 option_definition(optimize,full,Flags2),
189 Flags = [ debugable - off | Flags2].
190 option_definition(debug,on,Flags) :-
191 ( current_prolog_flag(generate_debug_info,off) ->
192 % TODO: should not be allowed when nodebug flag is set in SWI-Prolog
193 chr_warning(any,':- chr_option(debug,on) inconsistent with current_prolog_flag(generate_debug_info,off\n\tCHR option is ignored!\n)',[]),
194 Flags = []
196 Flags = [ debugable - on ]
199 option_definition(store_counter,off,[]).
200 option_definition(store_counter,on,[store_counter-on]).
202 option_definition(observation,off,Flags) :-
203 Flags = [
204 observation_analysis - off,
205 ai_observation_analysis - off,
206 late_allocation - off,
207 storage_analysis - off
209 option_definition(observation,on,Flags) :-
210 Flags = [
211 observation_analysis - on,
212 ai_observation_analysis - on
214 option_definition(observation,regular,Flags) :-
215 Flags = [
216 observation_analysis - on,
217 ai_observation_analysis - off
219 option_definition(observation,ai,Flags) :-
220 Flags = [
221 observation_analysis - off,
222 ai_observation_analysis - on
225 option_definition(solver_events,NMod,Flags) :-
226 Flags = [solver_events - NMod].
228 option_definition(toplevel_show_store,on,Flags) :-
229 Flags = [toplevel_show_store - on].
231 option_definition(toplevel_show_store,off,Flags) :-
232 Flags = [toplevel_show_store - off].
234 init_chr_pp_flags :-
235 chr_pp_flag_definition(Name,[DefaultValue|_]),
236 set_chr_pp_flag(Name,DefaultValue),
237 fail.
238 init_chr_pp_flags.
240 set_chr_pp_flags([]).
241 set_chr_pp_flags([Name-Value|Flags]) :-
242 set_chr_pp_flag(Name,Value),
243 set_chr_pp_flags(Flags).
245 set_chr_pp_flag(Name,Value) :-
246 atom_concat('$chr_pp_',Name,GlobalVar),
247 nb_setval(GlobalVar,Value).
249 chr_pp_flag_definition(functional_dependency_analysis,[off,on]).
250 chr_pp_flag_definition(check_unnecessary_active,[off,full,simplification]).
251 chr_pp_flag_definition(reorder_heads,[off,on]).
252 chr_pp_flag_definition(set_semantics_rule,[off,on]).
253 chr_pp_flag_definition(guard_via_reschedule,[off,on]).
254 chr_pp_flag_definition(guard_locks,[on,off]).
255 chr_pp_flag_definition(storage_analysis,[off,on]).
256 chr_pp_flag_definition(debugable,[on,off]).
257 chr_pp_flag_definition(reduced_indexing,[off,on]).
258 chr_pp_flag_definition(observation_analysis,[off,on]).
259 chr_pp_flag_definition(ai_observation_analysis,[off,on]).
260 chr_pp_flag_definition(late_allocation,[off,on]).
261 chr_pp_flag_definition(store_counter,[off,on]).
262 chr_pp_flag_definition(guard_simplification,[off,on]).
263 chr_pp_flag_definition(check_impossible_rules,[off,on]).
264 chr_pp_flag_definition(occurrence_subsumption,[off,on]).
265 chr_pp_flag_definition(observation,[off,on]).
266 chr_pp_flag_definition(show,[off,on]).
267 chr_pp_flag_definition(solver_events,[none,_]).
268 chr_pp_flag_definition(toplevel_show_store,[on,off]).
270 chr_pp_flag(Name,Value) :-
271 atom_concat('$chr_pp_',Name,GlobalVar),
272 nb_getval(GlobalVar,V),
273 ( V == [] ->
274 chr_pp_flag_definition(Name,[Value|_])
276 V = Value
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%