File: simplifier_ioutilities.pro

package info (click to toggle)
spark 2012.0.deb-9
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 29,260 kB
  • ctags: 3,098
  • sloc: ada: 186,243; cpp: 13,497; makefile: 685; yacc: 440; lex: 176; ansic: 119; sh: 16
file content (544 lines) | stat: -rw-r--r-- 21,625 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
% -----------------------------------------------------------------------------
%  (C) Altran Praxis Limited
% -----------------------------------------------------------------------------
% 
%  The SPARK toolset is free software; you can redistribute it and/or modify it
%  under terms of the GNU General Public License as published by the Free
%  Software Foundation; either version 3, or (at your option) any later
%  version. The SPARK toolset is distributed in the hope that it will be
%  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
%  Public License for more details. You should have received a copy of the GNU
%  General Public License distributed with the SPARK toolset; see file
%  COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy of
%  the license.
% 
% =============================================================================

%###############################################################################
% PURPOSE
%-------------------------------------------------------------------------------
% Provides input and output utilities that are specific to the Simplifier.
%###############################################################################

%###############################################################################
% MODULE
%###############################################################################
:- module(simplifier_ioutilities, [display_header/1,
                                   display_help/1,
                                   display_banner/1,
                                   retrieve_declaration_file/1,
                                   retrieve_simplified_proof_file/1,
                                   retrieve_proof_file/1,
                                   retrieve_proof_file_kind/1,
                                   convert_file_for_display/2,
                                   convert_file_to_base_name/2]).


%###############################################################################
% DEPENDENCIES
%###############################################################################

:- use_module('ioutilities.pro',
              [show_error/2,
               display_header_full/1,
               display_header_plain/1,
               throw_error/2]).

:- use_module('newutilities.pro',
              [implode_separator_content_list/3,
               explode_separator_content_as_list/3]).

:- use_module('data__system.pro',
              [get_system_start_date_time/2]).

:- use_module('data__provenance.pro',
              [get_provenance_proof_file_kind/1,
               get_provenance_framework/1,
               get_provenance_banner/1,
               get_provenance_date_time/2,
               get_provenance_subprogram_identifier/1]).

:- use_module('data__switches.pro',
              [get_switch_plain/1,
               get_switch_deadpaths/1]).

:- use_module('../common/versioning/version.pro',
              [toolset_support_line1/1,
               toolset_support_line2/1,
               toolset_support_line3/1,
               toolset_support_line4/1]).

:- use_module('data__data_files.pro',
              [get_datafiles_vcg/1,
               get_datafiles_dpc/1,
               get_datafiles_pfs/1,
               get_datafiles_fdl/1,
               get_datafiles_dec/1,
               get_datafiles_simplified_pfs/1,
               get_datafiles_simplified_vcg/1,
               get_datafiles_summary_dpc/1]).

%###############################################################################
% TYPES
%###############################################################################

%###############################################################################
% DATA
%###############################################################################

%###############################################################################
% PREDICATES
%###############################################################################

%===============================================================================
% display_header(+Stream).
%-------------------------------------------------------------------------------
% Display the header for the Simplifier. For correct processing, the
% command line arguments must have already been processed.
%===============================================================================

% Is not in plain mode.
display_header(Stream):-
    get_switch_plain(off),
    display_header_full(Stream),
    !.

% Is in plain mode.
display_header(Stream):-
    get_switch_plain(on),
    display_header_plain(Stream),
    !.

%None of the above is an error.
display_header(_Stream):-
    show_error('Could not calculate banner. Unexpected system configuration.', []).

%===============================================================================
% display_help(Stream).
%-------------------------------------------------------------------------------
% Display help text.
%===============================================================================

% Help for Simplifier
display_help(Stream):-
    get_switch_deadpaths(off),
    !,
    display_header(Stream),

    % Get common support information.
    toolset_support_line1(SupportLine1_Atom),
    toolset_support_line2(SupportLine2_Atom),
    toolset_support_line3(SupportLine3_Atom),
    toolset_support_line4(SupportLine4_Atom),

    format(Stream, '~n',[]),
    format(Stream, 'Usage: spadesimp [options] Target_File~n', []),
    format(Stream, '~n', []),
    format(Stream, 'Target_File - Either a .vcg or .pfs file~n', []),
    format(Stream, '~n', []),
    format(Stream, 'All options may be abbreviated to the shortest unique prefix.~n', []),
    format(Stream, '~n', []),
    format(Stream, 'Standard options~n', []),
    format(Stream, '----------------~n', []),
    format(Stream, '-help               - Display this help information.~n', []),
    format(Stream, '-version            - Display version information.~n', []),
    format(Stream, '-nolog              - Do not generate a simplification log file.~n', []),
    format(Stream, '-log=Log_File       - Specify filename for the simplification log file.~n', []),
    format(Stream, '-nowrap             - Do not line wrap output files.~n', []),
    format(Stream, '-verbose            - Display attempted simplification strategies.~n', []),
    format(Stream, '-nouserrules        - Do not use user rules.~n', []),
    format(Stream, '-plain              - Adopt a plain output style (e.g. no dates or version numbers).~n', []),
    format(Stream, '-typecheck          - Only typecheck the input files.~n', []),
    format(Stream, '-norenum            - Do not renumber hypotheses and conclusions in siv files.~n', []),

    format(Stream, '~n', []),
    format(Stream, 'Adjust strategy options~n', []),
    format(Stream, '-----------------------~n', []),
    format(Stream, '-nosimplification=SELECT~n', []),
    format(Stream, '-nostandardisation=SELECT~n', []),
    format(Stream, '-norule_substitution=SELECT~n', []),
    format(Stream, '-nocontradiction_hunt=SELECT~n', []),
    format(Stream, '-nosubstitution_elimination=SELECT~n', []),
    format(Stream, '-noexpression_reduction=SELECT~n', []),
    format(Stream, 'SELECT=(RANGE {, RANGE})~n', []),
    format(Stream, 'RANGE=Vc_Number or From_Vc_Number-To_Vc_Number~n', []),
    format(Stream, '~n', []),
    format(Stream, 'Adjust limit options~n', []),
    format(Stream, '--------------------~n', []),
    format(Stream, '-complexity_limit=Limit (Limit in range 10 .. 200)~n', []),
    format(Stream, '-depth_limit=Limit      (Limit in range  1 ..  10)~n', []),
    format(Stream, '-inference_limit=Limit  (Limit in range 10 .. 400)~n', []),
    format(Stream, '~n', []),
    format(Stream, '~a~n', [SupportLine1_Atom]),
    format(Stream, '~a~n', [SupportLine2_Atom]),
    format(Stream, '~a~n', [SupportLine3_Atom]),
    format(Stream, '~a~n', [SupportLine4_Atom]),
    !.
 
% Help for ZombieScope
display_help(Stream):-
    get_switch_deadpaths(on),
    !,
    display_header(Stream),

    % Get common support information.
    toolset_support_line1(SupportLine1_Atom),
    toolset_support_line2(SupportLine2_Atom),
    toolset_support_line3(SupportLine3_Atom),
    toolset_support_line4(SupportLine4_Atom),

    format(Stream, '~n',[]),
    format(Stream, 'Usage: zombiescope [options] Target_File~n', []),
    format(Stream, '~n', []),
    format(Stream, 'Target_File - a .dpc file~n', []),
    format(Stream, '~n', []),
    format(Stream, 'All options may be abbreviated to the shortest unique prefix.~n', []),
    format(Stream, '~n', []),
    format(Stream, 'Standard options~n', []),
    format(Stream, '----------------~n', []),
    format(Stream, '-help             - Display this help information.~n', []),
    format(Stream, '-version          - Display version information.~n', []),
    format(Stream, '-nolog            - Do not generate a ZombieScope log file.~n', []),
    format(Stream, '-log=Log_File     - Specify filename for the ZombieScope log file.~n', []),
    format(Stream, '-nowrap           - Do not line wrap output files.~n', []),
    format(Stream, '-plain            - Adopt a plain output style (e.g. no dates or version numbers).~n', []),
    format(Stream, '-norenum          - Do not renumber hypotheses and conclusions in sdp files.~n', []),
    format(Stream, '-hyp_limit=Limit  - Specify the maximum number of hypotheses that will be analysed.~n', []),

    format(Stream, '~n', []),
    format(Stream, '~a~n', [SupportLine1_Atom]),
    format(Stream, '~a~n', [SupportLine2_Atom]),
    format(Stream, '~a~n', [SupportLine3_Atom]),
    format(Stream, '~a~n', [SupportLine4_Atom]),
    !.
 
%===============================================================================
% display_banner(Stream).
%-------------------------------------------------------------------------------
% Display the banner for the Simplifier output. The banner is affected by
% the previously collected system and provenance information.
%===============================================================================

display_banner(Stream):-

    %Leading stars for banner.
    format(Stream, '*****************************************************************************~n', []),

    %Retrive and write out the leading banner.
    get_provenance_banner(Line_AtomList),
    implode_separator_content_list('\n',
                                   Line_AtomList,
                                   Line_Atom),
    format(Stream, Line_Atom, []),
    format(Stream, '~n', []),

    %Closing stars for banner.
    format(Stream, '*****************************************************************************~n', []),

    %Display some spaces.
    format(Stream, '~n', []),
    format(Stream, '~n', []),

    % Note that POGS expects the date and time details, if present, to
    % appear before the subprogram name.

    %Consider displaying time details.
    display_time_details(Stream),

    %Embed the standard header into the file.
    format(Stream, '\n', []),
    display_header(Stream),
    format(Stream, '\n', []),

    %Display subprogram identifier.
    display_subprogram_identifier(Stream),

    %Display some spaces.
    format(Stream, '\n', []),
    format(Stream, '\n', []),
    format(Stream, '\n', []),
    format(Stream, '\n', []),
    !.

%-------------------------------------------------------------------------------

% Is in plain mode.
display_time_details(_Stream):-
    get_switch_plain(on),
    !.

% Is not in plain mode.
% But did not retrieve a date time from the provenance file.

display_time_details(_Stream):-
    get_switch_plain(off),
    \+ get_provenance_date_time(_Date_Atom, _Time_Atom),
    !.




display_time_details(Stream):-
    get_switch_plain(off),
    get_provenance_date_time(Date_Atom, Time_Atom),

    % Note POGS collects both the CREATED and SIMPLIFIED dates, and expects
    % the following format.
    %
    % Once all trailing and leading space has been deleted:
    %
    % The CREATED date must start on column: 9, and be 11 chars wide.
    % The CREATED time must start on column: 22, and be 8 chars wide.
    %
    % The SIMPLIFIED date must start on column: 43, and be 11 chars wide.
    % The SIMPLIFIED time must start on column: 56, and be 8 chars wide.
    %
    % The date format is like: 09-JAN-1980
    % The time format is like: 01:59:01
    %
    % Currently POGS compares the text of the CREATED date and time with
    % relevant portions from the VCG file. The SIMPLIFIED date and time is
    % semantically compared against the date embedded into the PLG file.


    get_system_start_date_time(NowDate_Atom, NowTime_Atom),
    display_time_details_x(Stream, Date_Atom, Time_Atom, NowDate_Atom, NowTime_Atom),
    !.

%None of the above is an error.
display_time_details(_Stream):-
    show_error('Could not determine date and time details for the simplified file banner.', []).

display_time_details_x(Stream, Date_Atom, Time_Atom, NowDate_Atom, NowTime_Atom):-
    get_switch_deadpaths(off),
    format(Stream, 'CREATED ~a, ~a  SIMPLIFIED ~a, ~a\n',
           [Date_Atom, Time_Atom, NowDate_Atom, NowTime_Atom]).

display_time_details_x(Stream, Date_Atom, Time_Atom, NowDate_Atom, NowTime_Atom):-
    get_switch_deadpaths(on),
    format(Stream, 'CREATED ~a, ~a  ZombieScope ~a, ~a\n',
           [Date_Atom, Time_Atom, NowDate_Atom, NowTime_Atom]).

%-------------------------------------------------------------------------------

% The subprogram identifier is displayed in all modes.
display_subprogram_identifier(Stream):-
    get_provenance_subprogram_identifier(SubprogramIdentifier_Atom),
    format(Stream, '~a\n', [SubprogramIdentifier_Atom]),
    !.

% If in pascal mode, it is acceptable to have no subprogram identifier. In
% this case a blank line is written out.
display_subprogram_identifier(Stream):-
    get_provenance_framework(pascal),
    format(Stream, '\n', []),
    !.

% From above, expected subprogram identifier is not present.
display_subprogram_identifier(_Stream):-
    show_error('Expected subprogram identifier is not present.\n', []).

%===============================================================================
% retrieve_proof_file(-ProofFile_Atom).
%-------------------------------------------------------------------------------
% Return the overloaded proof file name (either .vcg or .pfs). Raise an
% error if this can not be done.
%===============================================================================

retrieve_proof_file(ProofFile_Atom):-
    get_provenance_proof_file_kind(ProofFileKind),
    retrieve_proof_file_x(ProofFileKind, ProofFile_Atom),
    !.

%-------------------------------------------------------------------------------

retrieve_proof_file_x(verification_conditions, VcgFile_Atom):-
    get_datafiles_vcg(VcgFile_Atom),
    !.

retrieve_proof_file_x(deadpath_search, DpcFile_Atom):-
    get_datafiles_dpc(DpcFile_Atom),
    !.

% DELETE_PATH_FUNCTIONS
retrieve_proof_file_x(path_functions, PfsFile_Atom):-
    get_datafiles_pfs(PfsFile_Atom),
    !.


retrieve_proof_file_x(ProofFileKind, _File_Atom):-
    throw_error('Unable to retrieve proof file for proof file kind: ~k',
                [ProofFileKind]).

%===============================================================================
% retrieve_simplified_proof_file(-SimplifiedProofFile_Atom).
%-------------------------------------------------------------------------------
% Return the overloaded simplified proof file name (either .siv, .sdp or .sip).
% Raise an error if this can not be done.
%===============================================================================

retrieve_simplified_proof_file(SimplifiedProofFile_Atom):-
    get_provenance_proof_file_kind(ProofFileKind),
    retrieve_simplified_proof_file_x(ProofFileKind, SimplifiedProofFile_Atom),
    !.

%-------------------------------------------------------------------------------

retrieve_simplified_proof_file_x(verification_conditions, SimplifiedVcgFile_Atom):-
    get_datafiles_simplified_vcg(SimplifiedVcgFile_Atom),
    !.

retrieve_simplified_proof_file_x(deadpath_search, SummaryDeadpathFile_Atom):-
    get_datafiles_summary_dpc(SummaryDeadpathFile_Atom),
    !.


retrieve_simplified_proof_file_x(path_functions, SimplifiedPfsFile_Atom):-
    get_datafiles_simplified_pfs(SimplifiedPfsFile_Atom),
    !.


retrieve_simplified_proof_file_x(ProofFileKind, _File_Atom):-
    throw_error('Unable to retrieve simplified proof file for proof file kind: ~k',
                [ProofFileKind]).

%===============================================================================
% retrieve_declaration_file(-DeclarationFile_Atom).
%-------------------------------------------------------------------------------
% Return the overloaded proof declaration file name (either .fdl or .dec).
% Raise an error if this can not be done.
%===============================================================================

retrieve_declaration_file(DeclarationFile_Atom):-
    get_provenance_proof_file_kind(ProofFileKind),
    retrieve_declaration_file_x(ProofFileKind, DeclarationFile_Atom),
    !.

%-------------------------------------------------------------------------------

retrieve_declaration_file_x(verification_conditions, FdlFile_Atom):-
    get_datafiles_fdl(FdlFile_Atom),
    !.

retrieve_declaration_file_x(deadpath_search, FdlFile_Atom):-
    get_datafiles_fdl(FdlFile_Atom),
    !.



retrieve_declaration_file_x(path_functions, DecFile_Atom):-
    get_datafiles_dec(DecFile_Atom),
    !.



retrieve_declaration_file_x(ProofFileKind, _File_Atom):-
    throw_error('Unable to retrieve declaration file for proof file kind: ~k',
                [ProofFileKind]).

%===============================================================================
% retrieve_proof_file_kind(-ProofFileKind).
%-------------------------------------------------------------------------------
% Based on which main proof file is available, return the proof file kind.
%===============================================================================



% If both main proof files are available, then raise an error.

retrieve_proof_file_kind(_ProofFileKind):-
    get_datafiles_vcg(VcgFile_Atom),
    convert_file_for_display(VcgFile_Atom, DisplayVcgFile_Atom),
    get_datafiles_pfs(PfsFile_Atom),
    convert_file_for_display(PfsFile_Atom, DisplayPfsFile_Atom),
    throw_error('Unexpected availability of two distinct proof files: ~a and ~a',
                [DisplayVcgFile_Atom, DisplayPfsFile_Atom]).



% If dead path is off then proof kind is verification conditions.
retrieve_proof_file_kind(verification_conditions):-
    get_switch_deadpaths(off),
    get_datafiles_vcg(_VcgFile_Atom),
    !.

% If dead path is on then proof kind is searching for dead paths.
retrieve_proof_file_kind(deadpath_search):-
    get_switch_deadpaths(on),
    get_datafiles_dpc(_DpcFile_Atom),
    !.

% Error if neither vcg or dpc files have been loaded.
retrieve_proof_file_kind(_ProofFileKind):-
 get_switch_deadpaths(off),
    throw_error('Unexpected no vcg files loaded',
                []).

% Could not locate dpc file for dead path search.
retrieve_proof_file_kind(_ProofFileKind):-
    get_switch_deadpaths(on),
    throw_error('Unexpected no dpc files loaded',
                []).


% If pfs is available then is path_functions.
retrieve_proof_file_kind(path_functions):-
    get_datafiles_pfs(_PfsFile_Atom),
    !.

% If neither are available then raise an error.
retrieve_proof_file_kind(_ProofFileKind):-
    throw_error('Unexpected no proof files available',
                []).



%===============================================================================
% convert_file_for_display(+File_Atom, -DisplayFile_Atom).
%-------------------------------------------------------------------------------
% Plain mode exists to minimise differences across platforms. This extends
% to the portrayal of files. This routine converts an internal file
% (File_Atom) into an appropriate form for display (DisplayFile_Atom).
%===============================================================================

% Is not in plain mode.
% Display the whole file.
convert_file_for_display(File_m_DisplayFile_m_Atom, File_m_DisplayFile_m_Atom):-
    get_switch_plain(off),
    !.




% Is in plain mode.
% Strip off the directory part.
convert_file_for_display(File_Atom, DisplayFile_Atom):-
    get_switch_plain(on),
    convert_file_to_base_name(File_Atom, DisplayFile_Atom),
    !.

convert_file_for_display(File_Atom, _DisplayFile_Atom):-
    throw_error('Error in converting file ~k for display',
                [File_Atom]).

%===============================================================================
% convert_file_to_base_name(+File_Atom, -BaseName_Atom).
%-------------------------------------------------------------------------------
% Given a file (File_Atom), strip off its directory part and return the
% reminder as (BaseName_Atom).
%===============================================================================

convert_file_to_base_name(File_Atom, DisplayFile_Atom):-

    %Retrieve the directory parts and file part.
    explode_separator_content_as_list('/',
                                      File_Atom,
                                      Item_AtomList),

    %The last part is the file part.
    append(_Directory_AtomList, [DisplayFile_Atom], Item_AtomList),
    !.

%###############################################################################
% END-OF-FILE