forked from hklarner/NuSMV-a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcinitData.c
2287 lines (1831 loc) · 70.1 KB
/
cinitData.c
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ---------------------------------------------------------------------------
This file is part of the ``cinit'' package of NuSMV version 2.
Copyright (C) 1998-2001 by CMU and FBK-irst.
NuSMV version 2 is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
NuSMV version 2 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
For more information on NuSMV see <http://nusmv.fbk.eu>
or email to <[email protected]>.
Please report bugs to <[email protected]>.
To contact the NuSMV development board, email to <[email protected]>.
-----------------------------------------------------------------------------*/
/*!
\author Alessandro Mariotti
\brief Helper for the NuSMV library. Helps with extending it or
creating new tools out of it.
\todo: Missing description
*/
#if HAVE_CONFIG_H
# include "nusmv-config.h"
#endif
#include <sys/stat.h>
#include "nusmv/core/cinit/cinitInt.h"
#if NUSMV_HAVE_INTERACTIVE_SHELL
#include "nusmv/shell/cmd/cmd.h"
#endif
#include "nusmv/core/utils/Logger.h"
#include "nusmv/core/utils/ustring.h"
#include "nusmv/core/utils/utils_io.h"
#include "nusmv/core/utils/StreamMgr.h"
#include "nusmv/core/utils/Olist.h"
#include "nusmv/core/bmc/bmc.h"
#include "nusmv/core/trans/trans.h"
typedef struct CmdLineOpt_TAG {
char* name;
char* usage;
char* parameter;
/* Used for special options */
boolean (*check_and_apply)(OptsHandler_ptr, char*, NuSMVEnv_ptr);
/* Used for options which have an associated env var. */
char* env_option;
boolean deprecated;
boolean public;
string_ptr dependency;
Olist_ptr conflicts;
} CmdLineOpt;
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
typedef CmdLineOpt* CmdLineOpt_ptr;
typedef struct CoreData_TAG {
char* tool_name;
char* tool_rcfile;
char* tool_version;
char* build_date;
char* prompt_string;
char* email;
char* website;
char* bug_report_message;
char* linked_addons;
char* library_name;
char* library_version;
char* library_build_date;
char* library_email;
char* library_website;
char* library_bug_report_message;
void (*print_banner)(FILE*);
/* [AMa] The batch function should defenitely return an exit value.. */
void (*batch)(NuSMVEnv_ptr);
hash_ptr line_options;
UStringMgr_ptr string_mgr;
} CoreData;
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
typedef CoreData* CoreData_ptr;
/* Shouldn't introduce reentrancy problems */
static CoreData_ptr core_data = (CoreData_ptr)NULL;
/*---------------------------------------------------------------------------*/
/* Macro declarations */
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/* Constant declarations */
/*---------------------------------------------------------------------------*/
/* Environment related constants */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define ENV_FLAG_CORE_INITIALIZED "_nusmv_core_init_"
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define ENV_INIT_FUNS "_nusmv_core_init_funs_"
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define ENV_INIT_FUNS_NUM "_nusmv_core_init_funs_num_"
/* End of environment related constants */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define PRINT_USAGE_IN_NEWLINE 1
/* RETURN VALUES */
/* Everything went smooth */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_SUCCESS 0
/* The script file does not exits or it contains an error and
set_on_failure_script_quits is set. */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_SCRIPT_ERROR -1
/* The help has been printed out */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_HELP_PRINT 2
/* An unknown option is given */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_UNKNOWN_OPTION -1
/* An error occurred with this option */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_INVALID_OPTION -1
/* An invalid parameter is given */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_INVALID_OPTION_PARAM -1
/* A required parameter is not given */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_MISSING_OPTION_PARAM -1
/* The option depends among another option which is not given */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_MISSING_OPTION_DEP -1
/* The option conflicts with another option which is given */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_CONFLICT_OPTION -1
/* The option is given more than once */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define RET_DUPLICATE_OPTION -1
/* Max width of a printed string (in characters) */
/* #define MAX_PRINT_WIDTH 75 */
/*!
\brief \todo Missing synopsis
\todo Missing description
*/
#define MAX_PRINT_WIDTH 70
/**AutomaticStart*************************************************************/
/*---------------------------------------------------------------------------*/
/* Static function prototypes */
/*---------------------------------------------------------------------------*/
static CoreData_ptr nusmv_core_get_instance(void);
static void nusmv_core_deinit(void);
static int nusmv_core_parse_line_options(NuSMVEnv_ptr env,
int argc, char ** argv);
static void nusmv_core_print_usage(NuSMVEnv_ptr env,
boolean print_banner);
static CmdLineOpt_ptr nusmv_core_init_opt(void);
static void nusmv_core_deinit_opt(CmdLineOpt_ptr opt);
static void nusmv_core_print_string(FILE* out, char* str, int padding);
static void nusmv_core_olist_union(Olist_ptr a, Olist_ptr b);
static Olist_ptr
nusmv_core_olist_intersection(Olist_ptr a, Olist_ptr b);
static char* nusmv_core_merge(Olist_ptr set);
static Olist_ptr nusmv_core_split( UStringMgr_ptr strmgr, char* str);
static char* nusmv_core_tolower(char* str);
static void
nusmv_core_free_line_options(CoreData_ptr core_data);
/* ------------------------- CHECK AND APPLY FUNCTIONS --------------------- */
static boolean
nusmv_core_check_sin_fun(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static boolean
nusmv_core_check_rbc_fun(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static boolean
nusmv_core_set_mono_partition(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static boolean
nusmv_core_set_iwls95_partition(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static boolean
nusmv_core_set_thresh_partition(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static boolean
nusmv_core_set_cpp(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static boolean
nusmv_core_set_dp(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static boolean
core_data_set_fs(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static boolean
nusmv_core_set_pre(OptsHandler_ptr opt, char* val, NuSMVEnv_ptr env);
static int nusmv_core_start_interactive_shell_loop(NuSMVEnv_ptr env);
/**AutomaticEnd***************************************************************/
/*---------------------------------------------------------------------------*/
/* Definition of exported functions */
/*---------------------------------------------------------------------------*/
void NuSMVCore_init_data(void)
{
CoreData_ptr data = nusmv_core_get_instance();
NuSMVCore_set_tool_name(NUSMV_PACKAGE_NAME);
NuSMVCore_set_tool_version(NUSMV_PACKAGE_VERSION);
NuSMVCore_set_build_date(NUSMV_PACKAGE_BUILD_DATE);
NuSMVCore_set_prompt_string("NuSMV > ");
NuSMVCore_set_email("[email protected]");
NuSMVCore_set_website("http://nusmv.fbk.eu");
{
char* fmt = "Please report bugs to <%s>";
char* tmp = ALLOC(char, strlen(fmt) + strlen(NUSMV_PACKAGE_BUGREPORT) + 1);
sprintf(tmp, fmt, NUSMV_PACKAGE_BUGREPORT);
NuSMVCore_set_bug_report_message(tmp);
FREE(tmp);
}
NuSMVCore_set_linked_addons(NUSMV_LINKED_CORE_ADDONS);
/* Library's fields do not have a SETTER function, since they are
unchangeable from the tools */
data->library_name = util_strsav(NUSMV_LIBRARY_NAME);
data->library_version = util_strsav(NUSMV_LIBRARY_VERSION);
data->library_build_date = util_strsav(NUSMV_LIBRARY_BUILD_DATE);
data->library_website = util_strsav(NUSMV_LIBRARY_WEBSITE);
data->library_email = util_strsav(NUSMV_LIBRARY_EMAIL);
data->library_bug_report_message = util_strsav(NUSMV_LIBRARY_BUGREPORT);
data->batch = CInit_batch_main;
data->print_banner = CInit_BannerPrint;
}
void NuSMVCore_init(NuSMVEnv_ptr env, FP_V_E funs[][2], int num_funs)
{
FP_V_E** init_quit_funs = NULL;
int i;
if (num_funs > 0) {
nusmv_assert(NULL != funs);
init_quit_funs = ALLOC(FP_V_E*, num_funs);
for (i = 0; i < num_funs; i++) {
init_quit_funs[i] = ALLOC(FP_V_E, 2);
init_quit_funs[i][0] = funs[i][0];
init_quit_funs[i][1] = funs[i][1];
}
NuSMVEnv_set_value(env, ENV_INIT_FUNS, init_quit_funs);
NuSMVEnv_set_value(env, ENV_INIT_FUNS_NUM, PTR_FROM_INT(void*, num_funs));
}
CInit_init(env);
#if NUSMV_HAVE_INTERACTIVE_SHELL
/* this is not very coorect, as shell gets initialized in core
* (although only when shell is enabled at compile-time). This is
* due to the current design of the init/deinit mechanism */
Cmd_Init(env); /* inits the cmd services for the shell */
#endif
for (i = 0; i < num_funs; ++i) {
init_quit_funs[i][0](env);
}
NuSMVEnv_set_flag(env, ENV_FLAG_CORE_INITIALIZED, true);
}
void NuSMVCore_init_cmd_options(NuSMVEnv_ptr env)
{
char* libraryName = CInit_NuSMVObtainLibrary();
CoreData_ptr data = nusmv_core_get_instance();
{
const char* fmt = "does not read any initialization file "
"(%s/master%s, ~/%s) (default in batch mode)";
char* tmp = ALLOC(char, strlen(fmt) + strlen(libraryName) +
(2 * strlen(data->tool_rcfile)) + 1);
sprintf(tmp, fmt, libraryName, data->tool_rcfile, data->tool_rcfile);
NuSMVCore_add_env_command_line_option("-s", tmp, NULL, IGNORE_INIT_FILE,
true, false, NULL, NULL);
FREE(tmp);
}
NuSMVCore_add_env_command_line_option("-old_div_op",
"enables the old semantics of \"/\" "
"and \"mod\" operations instead"
" of ANSI C semantics",
NULL, USE_ANSI_C_DIV_OP,
true, false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-m", "sets the variable ordering "
"method to \"method\". "
"Reordering will be activated",
"method", REORDER_METHOD,
true, false, NULL, NULL);
{
BddOregJusticeEmptinessBddAlgorithmType alg, a1, a2;
const char* fmt = "sets the algorthim used for BDD-based language "
"emptiness of Buchi fair transition systems "
"(default is %s). The available algorthims are: %s, %s";
const char* salg;
const char* sa1;
const char* sa2;
char* tmp;
alg = DEFAULT_OREG_JUSTICE_EMPTINESS_BDD_ALGORITHM;
a1 = BDD_OREG_JUSTICE_EMPTINESS_BDD_ALGORITHM_EL_FWD;
a2 = BDD_OREG_JUSTICE_EMPTINESS_BDD_ALGORITHM_EL_BWD;
salg = Bdd_BddOregJusticeEmptinessBddAlgorithmType_to_string(alg);
sa1 = Bdd_BddOregJusticeEmptinessBddAlgorithmType_to_string(a1);
sa2 = Bdd_BddOregJusticeEmptinessBddAlgorithmType_to_string(a2);
tmp = ALLOC(char, strlen(fmt) + strlen(salg) +
strlen(sa1) + strlen(sa2) + 1);
nusmv_assert(NULL != tmp);
sprintf(tmp, fmt, salg, sa1, sa2);
NuSMVCore_add_env_command_line_option("-ojeba", tmp, "str",
OREG_JUSTICE_EMPTINESS_BDD_ALGORITHM,
true, false, NULL, NULL);
FREE(tmp);
}
{
char* tmp;
char* preps_tmp;
const char* fmt = "defines a space-separated list of pre-processors "
"to run (in the order given) on the input file. "
"The list must be in double quotes if there is more "
"than one pre-processor named.\n%s";
if (get_preprocessors_num(env) > 0) {
const char* preps_fmt = "The available preprocessors are: %s";
char* preps = get_preprocessor_names(env);
preps_tmp = ALLOC(char, strlen(preps_fmt) + strlen(preps) + 1);
sprintf(preps_tmp, preps_fmt, preps);
FREE(preps);
}
else {
const char* preps_fmt = "Warning: there are no available preprocessors";
preps_tmp = ALLOC(char, strlen(preps_fmt) + 1);
sprintf(preps_tmp, preps_fmt);
}
tmp = ALLOC(char, strlen(fmt) + strlen(preps_tmp) + 1);
sprintf(tmp, fmt, preps_tmp);
NuSMVCore_add_command_line_option("-pre", tmp, "pp_list",
nusmv_core_set_pre,
true, false, NULL, NULL);
FREE(preps_tmp);
FREE(tmp);
}
{
const char* fmt = "sets the sat_solver variable, used by BMC. "
"The available SAT solvers are: %s";
char* tmp;
char* solvers = Sat_GetAvailableSolversString();
tmp = ALLOC(char, strlen(fmt) + strlen(solvers) + 1);
sprintf(tmp, fmt, solvers);
NuSMVCore_add_env_command_line_option("-sat_solver", tmp,
"str", A_SAT_SOLVER,
true, false, NULL, NULL);
FREE(solvers);
FREE(tmp);
}
NuSMVCore_add_command_line_option("-sin", "enables (on) or disables sexp"
" inlining (default is off)", "on|off",
nusmv_core_check_sin_fun, true,
false, NULL, NULL);
NuSMVCore_add_command_line_option("-rin", "enables (on) or disables rbc"
" inlining (default is on)", "on|off",
nusmv_core_check_rbc_fun, true, false,
NULL, NULL);
NuSMVCore_add_command_line_option("-mono",
"enables monolithic transition relation",
NULL, nusmv_core_set_mono_partition, true,
false, NULL, "-thresh -iwls95 -cp");
NuSMVCore_add_command_line_option("-iwls95",
"enables Iwls95 conjunctive "
"partitioning and sets",
"cp_t", nusmv_core_set_iwls95_partition,
true, false, NULL, "-thresh -mono -cp");
NuSMVCore_add_command_line_option("-thresh",
"conjunctive partitioning with "
"threshold of each partition set"
" to \"cp_t\" (DEFAULT, with cp_t=1000)",
"cp_t", nusmv_core_set_thresh_partition,
true, false, NULL, "-iwls95 -mono -cp");
NuSMVCore_add_command_line_option("-cp",
"conjunctive partitioning with threshold"
" of each partition set to \"cp_t\" "
"(DEFAULT, with cp_t=1000). "
"Use -thresh instead of this.",
"cp_t", nusmv_core_set_thresh_partition,
true, true, NULL, "-iwls95 -mono -thresh");
#if NUSMV_HAVE_CPP
/* --------------------------------------------------------------- */
/* CPP OPTION */
NuSMVCore_add_command_line_option("-cpp",
"runs preprocessor on SMV files before "
"any specified with -pre. "
# if NUSMV_HAVE_CPP
# if NUSMV_HAVE_GETENV
"Environment variable 'CPP' can be used to "
"specify a different preprocessor. "
# endif
# else
"Preprocessor was not found when NuSMV"
" had been configured, then 'cpp' will"
" be searched at runtime when needed"
# if NUSMV_HAVE_GETENV
", or the 'CPP' environment variable "
"will be used when defined by the user"
# endif
"."
# endif
, NULL, nusmv_core_set_cpp,
true, true, NULL, NULL);
/* --------------------------------------------------------------- */
#endif
NuSMVCore_add_env_command_line_option("-r",
"enables printing of reachable states",
NULL, PRINT_REACHABLE, true,
false, NULL, NULL);
NuSMVCore_add_command_line_option("-f",
"computes the reachable states"
" (forward search) (default)",
NULL, core_data_set_fs, true, true,
NULL, "-df");
NuSMVCore_add_env_command_line_option("-df", "disables the computation of"
" reachable states",
NULL, FORWARD_SEARCH, true, false,
NULL, "-f");
NuSMVCore_add_command_line_option("-dp", "UNSUPPORTED", NULL,
nusmv_core_set_dp, false, true, NULL, NULL);
NuSMVCore_add_env_command_line_option("-old",
"keeps backward compatibility"
" with older versions of NuSMV",
NULL, BACKWARD_COMPATIBILITY, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-ctt",
"enables checking for the totality"
" of the transition relation",
NULL, OPT_CHECK_FSM, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-lp",
"lists all properties in SMV model",
NULL, LIST_PROPERTIES, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-n",
"specifies which property of SMV "
"model should be checked", "idx",
PROP_NO, true, false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-is", "does not check SPEC", NULL,
IGNORE_SPEC, true, false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-ic", "does not check COMPUTE",
NULL, IGNORE_COMPUTE, true, false,
NULL, NULL);
NuSMVCore_add_env_command_line_option("-ils", "does not check LTLSPEC",
NULL, IGNORE_LTLSPEC, true, false,
NULL, NULL);
NuSMVCore_add_env_command_line_option("-ips", "does not check PSLSPEC",
NULL, IGNORE_PSLSPEC, true, false,
NULL, NULL);
NuSMVCore_add_env_command_line_option("-ii", "does not check INVARSPEC", NULL,
IGNORE_INVAR, true, false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-flt",
"computes the reachable states"
" also for the LTL Tableau",
NULL, LTL_TABLEAU_FORWARD_SEARCH,
true, false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-i",
"reads order of variables "
"from file \"iv_file\"",
"iv_file", INPUT_ORDER_FILE, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-o",
"prints order of variables"
"to file \"ov_file\"",
"ov_file", OUTPUT_ORDER_FILE, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-t",
"reads order of vars for clustering "
"from file \"tv_file\"",
"tv_file", TRANS_ORDER_FILE, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-AG",
"enables AG only search",
NULL, AG_ONLY_SEARCH, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-reorder",
"enables reordering of "
"variables before exiting",
NULL, ENABLE_REORDER, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-dynamic",
"enables dynamic reordering "
"of variables",
NULL, DYNAMIC_REORDER, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-disable_sexp2bdd_caching",
"disables caching of expressions"
"evaluation to BDD",
NULL, ENABLE_SEXP2BDD_CACHING,
true, false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-bdd_soh",
"sets the static variable ordering "
"heuristics to \"heuristics\"",
"heuristics",
BDD_STATIC_ORDER_HEURISTICS, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-coi",
"enables cone of influence reduction",
NULL, CONE_OF_INFLUENCE, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-noaffinity",
"disables affinity clustering",
NULL, AFFINITY_CLUSTERING, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-iwl95preorder",
"enables iwls95 preordering",
NULL, IWLS95_PREORDER, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-ofm",
"prints flattened model to file "
"\"fn_file\"",
"fn_file", OUTPUT_FLATTEN_MODEL_FILE,
true, false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-disable_daggifier",
"disables the SMV model "
"dumper daggifier",
NULL, DAGGIFIER_ENABLED,
true, false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-obm",
"prints boolean model to"
" file \"bn_file\"",
"bn_file", OUTPUT_BOOLEAN_MODEL_FILE,
true, false, NULL, NULL);
#if NUSMV_HAVE_INCREMENTAL_SAT
NuSMVCore_add_env_command_line_option("-bmc_length",
"sets bmc_length variable, used by BMC",
"k", BMC_PB_LENGTH, true,
false, "-bmc", NULL);
NuSMVCore_add_env_command_line_option("-bmc",
"enables BMC instead of "
"BDD model checking",
NULL, BMC_MODE, true,
false, NULL, NULL);
#endif /* HAVE_INCREMENTAL_SAT */
NuSMVCore_add_env_command_line_option("-int",
"enables interactive mode",
NULL, BATCH, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-dcx",
"disables computation of"
" counter-examples",
NULL, COUNTER_EXAMPLES, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-load",
"executes NuSMV commands from file",
"sc_file", SCRIPT_FILE, true,
true, NULL, "-source");
NuSMVCore_add_env_command_line_option("-source",
"executes NuSMV commands from file",
"sc_file", SCRIPT_FILE, true,
false, NULL, "-load");
NuSMVCore_add_env_command_line_option("-quiet",
"Quiet mode",
NULL, QUIET_MODE, false,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-v",
"sets verbose level to \"vl\"",
"vl", VERBOSE_LEVEL, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-disable_syntactic_checks",
"Skips some correctness checks over "
"the input model. Warning: when using "
"this option, the input model MUST be "
"correct, otherwise the tool may crash",
NULL, DISABLE_SYNTACTIC_CHECKS, true,
false, NULL, NULL);
NuSMVCore_add_env_command_line_option("-keep_single_value_vars",
"Does not convert variables that have "
"only one single possible value into "
"constant DEFINEs",
NULL, KEEP_SINGLE_VALUE_VARS, true,
false, NULL, NULL);
/* ADDED CommandLineOption -a for printing initial, accepting, initial and accepting states */
NuSMVCore_add_env_command_line_option("-a",
"prints a factored form formula of the accepting states "
"to the file \"filename\" or "
"to the command line, if \"print\" is "
"specified as filename",
"filename", PRINT_ACCEPTING, true,
false, NULL, NULL);
FREE(libraryName);
}
boolean NuSMVCore_main(NuSMVEnv_ptr env, int argc, char ** argv, int* status)
{
const StreamMgr_ptr streams =
STREAM_MGR(NuSMVEnv_get_value(env, ENV_STREAM_MANAGER));
FILE* outstream = StreamMgr_get_output_stream(streams);
OptsHandler_ptr opts = NuSMVEnv_get_value(env, ENV_OPTS_HANDLER);
CoreData_ptr data = nusmv_core_get_instance();
int quit_flag = 0;
boolean requires_shutdown = true;
nusmv_assert((int*)status != NULL);
nusmv_assert(NuSMVEnv_get_flag(env, ENV_FLAG_CORE_INITIALIZED));
*status = RET_SUCCESS;
/* Parse command line options */
*status = nusmv_core_parse_line_options(env, argc, argv);
/* We don't need the command line options anymore. we can free
them. */
/* nusmv_core_free_line_options(data); */
/* Everything went smooth with parsing the command line options */
if ((*status) == RET_SUCCESS) {
if (!opt_batch(opts)) { /* interactive mode */
if (!opt_get_quiet_mode(opts)) {
data->print_banner(outstream);
}
quit_flag = nusmv_core_start_interactive_shell_loop(env);
*status = RET_SUCCESS;
}
else {
if (!opt_get_quiet_mode(opts)) {
data->print_banner(outstream);
}
if (opt_verbose_level_gt(opts, 0)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "Starting the batch interaction.\n");
}
data->batch(env);
}
}
/* Value of "quit_flag" is determined by the "quit" command */
if (quit_flag == -1 || quit_flag == -2 || quit_flag == -4) {
*status = RET_SUCCESS;
}
/* exits quickly and silently with quit_flag = -4 */
if (quit_flag == -4) {
requires_shutdown = false;
}
if (quit_flag == -3 || quit_flag == -5) {
/* Script failed and on_failure_script_quits is set */
/* Or the script file does not exist. */
*status = RET_SCRIPT_ERROR;
}
return requires_shutdown;
}
void NuSMVCore_quit(NuSMVEnv_ptr env)
{
NuSMVCore_quit_extended(env, false);
}
void NuSMVCore_quit_extended(NuSMVEnv_ptr env,
const boolean keep_core_data)
{
int i;
FP_V_E ** init_quit_funs = NuSMVEnv_get_value(env, ENV_INIT_FUNS);
int num = PTR_TO_INT(NuSMVEnv_get_value(env, ENV_INIT_FUNS_NUM));
nusmv_assert(NuSMVEnv_get_flag(env, ENV_FLAG_CORE_INITIALIZED));
for (i = (num - 1); i >= 0; --i) {
init_quit_funs[i][1](env);
}
for (i = 0; i < num; ++i) {
FREE(init_quit_funs[i]);
}
FREE(init_quit_funs);
#if NUSMV_HAVE_INTERACTIVE_SHELL
/* this is not very coorect, as shell gets initialized in core
* (although only when shell is enabled at compile-time). This is
* due to the current design of the init/deinit mechanism */
Cmd_End(env); /* quits the cmd services for the shell */
#endif
CInit_end(env);
/* The structure may be useful until the very very
end. nusmv_core_deinit is garanteed to use only simple
independant structures */
/* Free line_options if not already done by NuSMVCore_main */
if (! keep_core_data) {
CoreData_ptr data = nusmv_core_get_instance();
nusmv_core_free_line_options(data);
nusmv_core_deinit();
}
NuSMVEnv_set_flag(env, ENV_FLAG_CORE_INITIALIZED, false);
}
void NuSMVCore_reset(NuSMVEnv_ptr env)
{
OptsHandler_ptr opts = NuSMVEnv_get_value(env, ENV_OPTS_HANDLER);
FP_V_E ** init_quit_funs = NuSMVEnv_get_value(env, ENV_INIT_FUNS);
int num = PTR_TO_INT(NuSMVEnv_get_value(env, ENV_INIT_FUNS_NUM));
int i = 0;
nusmv_assert(NuSMVEnv_get_flag(env, ENV_FLAG_CORE_INITIALIZED));
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "Shutting down the system...\n");
Logger_inc_indent_size(logger);
}
/* Quit all the registered libs */
for (i = (num - 1); i >= 0; --i) {
init_quit_funs[i][1](env);
}
CInit_reset_first(env);
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger,
"Shutdown completed, rebooting the system...\n");
}
CInit_reset_last(env);
for (i = 0; i < num; ++i) {
init_quit_funs[i][0](env);
}
if (opt_verbose_level_gt(opts, 1)) {
Logger_ptr logger = LOGGER(NuSMVEnv_get_value(env, ENV_LOGGER));
Logger_log(logger, "The system is now up and ready\n");
Logger_dec_indent_size(logger);
}
}
void NuSMVCore_add_env_command_line_option(char* name,
char* usage,
char* parameter,
char* env_var,
boolean public,
boolean deprecated,
char* dependency,
char* conflict)
{
CoreData_ptr data = nusmv_core_get_instance();
CmdLineOpt_ptr opt = nusmv_core_init_opt();
nusmv_assert((char*)NULL != name);
opt->name = util_strsav(name);
nusmv_assert((char*)NULL != usage);
opt->usage = util_strsav(usage);
if ((char*)NULL != parameter) {
opt->parameter = util_strsav(parameter);
}
nusmv_assert((char*)NULL != env_var);
opt->env_option = util_strsav(env_var);
opt->deprecated = deprecated;
opt->public = public;
if ((char*)NULL != dependency) {
opt->dependency = UStringMgr_find_string(data->string_mgr, dependency);
}
if ((char*)NULL != conflict) {
Olist_ptr split = nusmv_core_split(data->string_mgr, conflict);
nusmv_core_olist_union(opt->conflicts, split);
Olist_destroy(split);
}
nusmv_assert((hash_ptr)NULL != data->line_options);
insert_assoc(data->line_options,
NODE_PTR( UStringMgr_find_string(data->string_mgr, name)),
NODE_PTR(opt));
}
void
NuSMVCore_add_command_line_option(char* name,
char* usage,
char* parameter,
boolean (*check_and_apply)(OptsHandler_ptr, char*, NuSMVEnv_ptr),
boolean public,
boolean deprecated,
char* dependency,
char* conflict)
{
CoreData_ptr data = nusmv_core_get_instance();
CmdLineOpt_ptr opt = nusmv_core_init_opt();
nusmv_assert((char*)NULL != name);
opt->name = util_strsav(name);
nusmv_assert((char*)NULL != usage);
opt->usage = util_strsav(usage);
if ((char*)NULL != parameter) {
opt->parameter = util_strsav(parameter);
}
nusmv_assert(NULL != check_and_apply);
opt->check_and_apply = check_and_apply;