3 Part of CHR
(Constraint Handling Rules
)
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
,
38 %% :- use_module
(hprolog
, [nb_setval
/2,nb_getval/2]).
39 %% local_current_prolog_flag
(_
,_
) :- fail
.
43 local_current_prolog_flag
(X
,Y
) :- current_prolog_flag
(X
,Y
).
47 :- use_module
(chr_compiler_errors
).
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 handle_option
(Name
,Value
) :-
55 chr_error
(syntax
((:- chr_option
(Name
,Value
))),'First argument should be an atom, not a variable.\n',[]).
57 handle_option
(Name
,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
,
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
,
86 reduced_indexing
- on
,
88 inline_insertremove
- on
,
91 option_definition
(optimize
,full
,Flags
) :-
92 Flags
= [ functional_dependency_analysis
- on
,
93 check_unnecessary_active
- full
,
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
,
109 option_definition
(optimize
,off
,Flags
) :-
110 Flags
= [ functional_dependency_analysis
- off
,
111 check_unnecessary_active
- 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
,[]) :-
185 chr_translate
:type_definition
(T
,D
)
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
)
194 option_definition
(mode
,ModeDecl
,[]) :-
195 ( nonvar
(ModeDecl
) ->
196 functor
(ModeDecl
,F
,A
),
197 ModeDecl
=.. [_
|ArgModes
],
198 chr_translate
:constraint_mode
(F
/A
,ArgModes
)
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 option_definition
(experimental
,off
,[experiment
-off
]).
213 option_definition
(experimental
,on
,[experiment
-on
]).
214 option_definition
(sss
,off
,[sss
-off
]).
215 option_definition
(sss
,on
,[sss
-on
]).
216 %------------------------------------------------------------------------------%
217 option_definition
(debug
,off
,Flags
) :-
218 option_definition
(optimize
,full
,Flags2
),
219 Flags
= [ debugable
- off
| Flags2
].
220 option_definition
(debug
,on
,Flags
) :-
221 ( local_current_prolog_flag
(generate_debug_info
,false
) ->
222 % TODO
: should
not be allowed
when nodebug flag is set
in SWI
-Prolog
223 chr_warning
(any
,':- chr_option(debug,on) inconsistent with current_prolog_flag(generate_debug_info,off\n\tCHR option is ignored!\n)',[]),
226 Flags
= [ debugable
- on
]
229 option_definition
(store_counter
,off
,[]).
230 option_definition
(store_counter
,on
,[store_counter
-on
]).
232 option_definition
(observation
,off
,Flags
) :-
234 observation_analysis
- off
,
235 ai_observation_analysis
- off
,
236 late_allocation
- off
,
237 storage_analysis
- off
239 option_definition
(observation
,on
,Flags
) :-
241 observation_analysis
- on
,
242 ai_observation_analysis
- on
244 option_definition
(observation
,regular
,Flags
) :-
246 observation_analysis
- on
,
247 ai_observation_analysis
- off
249 option_definition
(observation
,ai
,Flags
) :-
251 observation_analysis
- off
,
252 ai_observation_analysis
- on
255 option_definition
(store_in_guards
, on
, [store_in_guards
- on
]).
256 option_definition
(store_in_guards
, off
, [store_in_guards
- off
]).
258 option_definition
(solver_events
,NMod
,Flags
) :-
259 Flags
= [solver_events
- NMod
].
261 option_definition
(toplevel_show_store
,on
,Flags
) :-
262 Flags
= [toplevel_show_store
- on
].
264 option_definition
(toplevel_show_store
,off
,Flags
) :-
265 Flags
= [toplevel_show_store
- off
].
267 option_definition
(term_indexing
,on
,Flags
) :-
268 Flags
= [term_indexing
- on
].
269 option_definition
(term_indexing
,off
,Flags
) :-
270 Flags
= [term_indexing
- off
].
272 option_definition
(verbosity
,on
,Flags
) :-
273 Flags
= [verbosity
- on
].
274 option_definition
(verbosity
,off
,Flags
) :-
275 Flags
= [verbosity
- off
].
277 option_definition
(ht_removal
,on
,Flags
) :-
278 Flags
= [ht_removal
- on
].
279 option_definition
(ht_removal
,off
,Flags
) :-
280 Flags
= [ht_removal
- off
].
282 option_definition
(mixed_stores
,on
,Flags
) :-
283 Flags
= [mixed_stores
- on
].
284 option_definition
(mixed_stores
,off
,Flags
) :-
285 Flags
= [mixed_stores
- off
].
287 option_definition
(line_numbers
,on
,Flags
) :-
288 Flags
= [line_numbers
- on
].
289 option_definition
(line_numbers
,off
,Flags
) :-
290 Flags
= [line_numbers
- off
].
292 option_definition
(dynattr
,on
,Flags
) :-
293 Flags
= [dynattr
- on
].
294 option_definition
(dynattr
,off
,Flags
) :-
295 Flags
= [dynattr
- off
].
297 option_definition
(verbose
,off
,[verbose
-off
]).
298 option_definition
(verbose
,on
,[verbose
-on
]).
300 option_definition
(dump,off
,[dump-off
]).
301 option_definition
(dump,on
,[dump-on
]).
304 chr_pp_flag_definition
(Name
,[DefaultValue
|_
]),
305 set_chr_pp_flag
(Name
,DefaultValue
),
309 set_chr_pp_flags
([]).
310 set_chr_pp_flags
([Name
-Value
|Flags
]) :-
311 set_chr_pp_flag
(Name
,Value
),
312 set_chr_pp_flags
(Flags
).
314 set_chr_pp_flag
(Name
,Value
) :-
315 atom_concat
('$chr_pp_',Name
,GlobalVar
),
316 nb_setval
(GlobalVar
,Value
).
318 chr_pp_flag_definition
(functional_dependency_analysis
,[off
,on
]).
319 chr_pp_flag_definition
(check_unnecessary_active
,[off
,full
,simplification
]).
320 chr_pp_flag_definition
(reorder_heads
,[off
,on
]).
321 chr_pp_flag_definition
(set_semantics_rule
,[off
,on
]).
322 chr_pp_flag_definition
(guard_via_reschedule
,[off
,on
]).
323 chr_pp_flag_definition
(guard_locks
,[on
,off
]).
324 chr_pp_flag_definition
(storage_analysis
,[off
,on
]).
325 chr_pp_flag_definition
(debugable
,[on
,off
]).
326 chr_pp_flag_definition
(reduced_indexing
,[off
,on
]).
327 chr_pp_flag_definition
(observation_analysis
,[off
,on
]).
328 chr_pp_flag_definition
(ai_observation_analysis
,[off
,on
]).
329 chr_pp_flag_definition
(store_in_guards
,[off
,on
]).
330 chr_pp_flag_definition
(late_allocation
,[off
,on
]).
331 chr_pp_flag_definition
(store_counter
,[off
,on
]).
332 chr_pp_flag_definition
(guard_simplification
,[off
,on
]).
333 chr_pp_flag_definition
(check_impossible_rules
,[off
,on
]).
334 chr_pp_flag_definition
(occurrence_subsumption
,[off
,on
]).
335 chr_pp_flag_definition
(observation
,[off
,on
]).
336 chr_pp_flag_definition
(show
,[off
,on
]).
337 chr_pp_flag_definition
(inline_insertremove
,[on
,off
]).
338 chr_pp_flag_definition
(solver_events
,[none
,_
]).
339 chr_pp_flag_definition
(toplevel_show_store
,[on
,off
]).
340 chr_pp_flag_definition
(term_indexing
,[off
,on
]).
341 chr_pp_flag_definition
(verbosity
,[on
,off
]).
342 chr_pp_flag_definition
(ht_removal
,[off
,on
]).
343 chr_pp_flag_definition
(mixed_stores
,[on
,off
]).
344 chr_pp_flag_definition
(line_numbers
,[off
,on
]).
345 chr_pp_flag_definition
(dynattr
,[off
,on
]).
346 chr_pp_flag_definition
(experiment
,[off
,on
]).
347 chr_pp_flag_definition
(sss
,[off
,on
]).
348 % emit compiler inferred code
349 chr_pp_flag_definition
(verbose
,[off
,on
]).
350 % emit input code
and output code
351 chr_pp_flag_definition
(dump,[off
,on
]).
353 chr_pp_flag_definition
(declare_stored_constraints
,[off
,on
]).
355 chr_pp_flag
(Name
,Value
) :-
356 atom_concat
('$chr_pp_',Name
,GlobalVar
),
357 nb_getval
(GlobalVar
,V
),
359 chr_pp_flag_definition
(Name
,[Value
|_
])
365 % TODO
: add whatever goes wrong with
(debug
,on
), (optimize
,full
) combo here
!
366 % trivial example of what does go wrong
:
370 chr_pp_flag
(store_in_guards
, on
),
371 chr_pp_flag
(ai_observation_analysis
, on
),
372 chr_warning
(any
, 'ai_observation_analysis should be turned off when using store_in_guards\n', []),
375 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%