1 | |
---|
2 | #include "io.h" |
---|
3 | #include "ioInt.h" |
---|
4 | #include "ntk.h" |
---|
5 | #include "ord.h" |
---|
6 | #include "part.h" |
---|
7 | #include "maig.h" |
---|
8 | #include "ntmaig.h" |
---|
9 | #include "fsm.h" |
---|
10 | #include "ctlp.h" |
---|
11 | #include "ctlsp.h" |
---|
12 | #include "mc.h" |
---|
13 | #include "mcInt.h" |
---|
14 | #include "grabInt.h" |
---|
15 | #include "bmc.h" |
---|
16 | #include "bmcInt.h" |
---|
17 | #include <stdio.h> |
---|
18 | #include <stdlib.h> |
---|
19 | |
---|
20 | |
---|
21 | /*---------------------------------------------------------------------------*/ |
---|
22 | /* Constant declarations */ |
---|
23 | /*---------------------------------------------------------------------------*/ |
---|
24 | /* |
---|
25 | * States of the state machine used to parse the input variable name list file. |
---|
26 | */ |
---|
27 | #define STATE_TEST 0 /* next char is in first column */ |
---|
28 | #define STATE_WAIT 1 /* wait until end of line '\n' is reached */ |
---|
29 | #define STATE_IN 2 /* parsing a variable name */ |
---|
30 | |
---|
31 | /* |
---|
32 | * Maximum permissible length of a variable name in the input variable name list file. |
---|
33 | */ |
---|
34 | #define MAX_NAME_LENGTH 200 |
---|
35 | #define LENGTH_1 255 |
---|
36 | #define SIZE_1 100 |
---|
37 | |
---|
38 | /* |
---|
39 | * INPUT FILES |
---|
40 | */ |
---|
41 | /*********************************************************/ |
---|
42 | |
---|
43 | #define BLIF_MV_FILE_C1 "EX_C1/Concret_Main.mv" |
---|
44 | #define FAIRNESS_FILE_C1 "EX_C1/machine_concret.fair" |
---|
45 | #define CTL_FILE_C1 "EX_C1/machine_concret.ctl" |
---|
46 | #define CNF_FILE_C1 "EX_C1/SATcnf_c1.cnf" |
---|
47 | #define CNF_FILE_C1_BIS "EX_C1/SATcnf_c1_bis.cnf" |
---|
48 | #define DEBUG_FILE_C1 "EX_C1/TEST_debug_trace" |
---|
49 | |
---|
50 | |
---|
51 | #define BLIF_MV_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED/main_abstract.mv" |
---|
52 | #define FAIRNESS_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED/main_abstract.fair" |
---|
53 | #define CTL_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED/machine_concret.ctl" |
---|
54 | #define CNF_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED/SATcnf_a1.cnf" |
---|
55 | #define DEBUG_FILE_A1 "TEST_debug_trace" |
---|
56 | |
---|
57 | /*****************************************************/ |
---|
58 | /* |
---|
59 | #define BLIF_MV_FILE_C1 "PBS_VCI_PI/new_main.mv" |
---|
60 | #define FAIRNESS_FILE_C1 "PBS_VCI_PI/main_mod.fair" |
---|
61 | #define CTL_FILE_C1 "PBS_VCI_PI/propri_mod.ctl" |
---|
62 | #define CNF_FILE_C1 "PBS_VCI_PI/SATcnf_c1.cnf" |
---|
63 | #define CNF_FILE_C1_BIS "PBS_VCI_PI/SATcnf_c1_bis.cnf" |
---|
64 | #define DEBUG_FILE_C1 "PBS_VCI_PI/debug_trace" |
---|
65 | |
---|
66 | |
---|
67 | #define BLIF_MV_FILE_A1 "PBS_VCI_PI/new_main.mv" |
---|
68 | #define FAIRNESS_FILE_A1 "PBS_VCI_PI/main_mod.fair" |
---|
69 | #define CTL_FILE_A1 "PBS_VCI_PI/propri_mod.ctl" |
---|
70 | #define CNF_FILE_A1 "PBS_VCI_PI/SATcnf_a1.cnf" |
---|
71 | #define DEBUG_FILE_A1 "PBS_VCI_PI/debug_trace" |
---|
72 | */ |
---|
73 | |
---|
74 | //#define BLIF_MV_FILE_C1 "VCI_PI/Concrete/main_concret.mv" |
---|
75 | //#define FAIRNESS_FILE_C1 "VCI_PI/Concrete/main_concret.fair" |
---|
76 | //#define CTL_FILE_C1 "VCI_PI/Concrete/main_concret.ctl" |
---|
77 | //#define CNF_FILE_C1 "VCI_PI/Concrete/SATcnf_c1.cnf" |
---|
78 | //#define DEBUG_FILE_C1 "VCI_PI/Concrete/debug_trace" |
---|
79 | |
---|
80 | //#define BLIF_MV_FILE_A1 "VCI_PI/Concrete/main_concret.mv" |
---|
81 | //#define FAIRNESS_FILE_A1 "VCI_PI/Concrete/main_concret.fair" |
---|
82 | //#define CTL_FILE_A1 "VCI_PI/Concrete/main_concret.ctl" |
---|
83 | //#define CNF_FILE_A1 "VCI_PI/Concrete/SATcnf_a1.cnf" |
---|
84 | //#define DEBUG_FILE_A1 "VCI_PI/Concrete/debug_trace" |
---|
85 | |
---|
86 | //#define BLIF_MV_FILE_A1 "VCI_PI/main_abstract.mv" |
---|
87 | //#define FAIRNESS_FILE_A1 "VCI_PI/main_abstract.fair" |
---|
88 | //#define CTL_FILE_A1 "VCI_PI/main_concret.ctl" |
---|
89 | //#define CNF_FILE_A1 "VCI_PI/SATcnf_a1.cnf" |
---|
90 | //#define DEBUG_FILE_A1 "VCI_PI/debug_trace" |
---|
91 | |
---|
92 | // #define BLIF_MV_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/main_abstract.mv" |
---|
93 | // #define FAIRNESS_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/main_abstract.fair" |
---|
94 | // #define CTL_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/machine_concret.ctl" |
---|
95 | // #define CNF_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/SATcnf_a1.cnf" |
---|
96 | // #define DEBUG_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/debug_trace" |
---|
97 | |
---|
98 | // #define BLIF_MV_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/main_abstract.mv" |
---|
99 | // #define FAIRNESS_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/main_abstract.fair" |
---|
100 | // #define CTL_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/machine_concret.ctl" |
---|
101 | // #define CNF_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/SATcnf_a1.cnf" |
---|
102 | // #define DEBUG_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/debug_trace" |
---|
103 | |
---|
104 | // #define BLIF_MV_FILE_C1 "METRONOME/metronome.mv" |
---|
105 | // #define FAIRNESS_FILE_C1 "METRONOME/metronome.fair" |
---|
106 | // #define CTL_FILE_C1 "METRONOME/metronome.ctl" |
---|
107 | // #define CNF_FILE_C1 "METRONOME/SATcnf_c2.cnf" |
---|
108 | |
---|
109 | // #define BLIF_MV_FILE_C1 "GATES/NOT/Concret_Main.mv" |
---|
110 | // #define FAIRNESS_FILE_C1 "GATES/NOT/not.fair" |
---|
111 | // #define CTL_FILE_C1 "GATES/NOT/not.ctl" |
---|
112 | // #define CNF_FILE_C1 "GATES/NOT/SATcnf_not.cnf" |
---|
113 | |
---|
114 | // #define BLIF_MV_FILE_C1 "GATES/NOT2/Concret_Main.mv" |
---|
115 | // #define FAIRNESS_FILE_C1 "GATES/NOT2/not2.fair" |
---|
116 | // #define CTL_FILE_C1 "GATES/NOT2/not2.ctl" |
---|
117 | // #define CNF_FILE_C1 "GATES/NOT2/SATcnf_not2.cnf" |
---|
118 | |
---|
119 | // #define BLIF_MV_FILE_C1 "GATES/NOT4/Concret_Main.mv" |
---|
120 | // #define FAIRNESS_FILE_C1 "GATES/NOT4/not4.fair" |
---|
121 | // #define CTL_FILE_C1 "GATES/NOT4/not4.ctl" |
---|
122 | // #define CNF_FILE_C1 "GATES/NOT4/SATcnf_not4.cnf" |
---|
123 | |
---|
124 | // #define BLIF_MV_FILE_C1 "GATES/AND/Concret_Main.mv" |
---|
125 | // #define FAIRNESS_FILE_C1 "GATES/AND/and.fair" |
---|
126 | // #define CTL_FILE_C1 "GATES/AND/and.ctl" |
---|
127 | // #define CNF_FILE_C1 "GATES/AND/SATcnf_and.cnf" |
---|
128 | |
---|
129 | // #define BLIF_MV_FILE_C1 "GATES/AND2/Concret_Main.mv" |
---|
130 | // #define FAIRNESS_FILE_C1 "GATES/AND2/and2.fair" |
---|
131 | // #define CTL_FILE_C1 "GATES/AND2/and2.ctl" |
---|
132 | // #define CNF_FILE_C1 "GATES/AND2/SATcnf_and2.cnf" |
---|
133 | |
---|
134 | // #define BLIF_MV_FILE_C1 "GATES/OR/Concret_Main.mv" |
---|
135 | // #define FAIRNESS_FILE_C1 "GATES/OR/or.fair" |
---|
136 | // #define CTL_FILE_C1 "GATES/OR/or.ctl" |
---|
137 | // #define CNF_FILE_C1 "GATES/OR/SATcnf_or.cnf" |
---|
138 | |
---|
139 | // #define BLIF_MV_FILE_C1 "GATES/OR2/Concret_Main.mv" |
---|
140 | // #define FAIRNESS_FILE_C1 "GATES/OR2/or2.fair" |
---|
141 | // #define CTL_FILE_C1 "GATES/OR2/or2.ctl" |
---|
142 | // #define CNF_FILE_C1 "GATES/OR2/SATcnf_or2.cnf" |
---|
143 | |
---|
144 | // #define BLIF_MV_FILE_C1 "GATES/SFM2006_Circuit/Concret_Main.mv" |
---|
145 | // #define FAIRNESS_FILE_C1 "GATES/SFM2006_Circuit/sfm.fair" |
---|
146 | // #define CTL_FILE_C1 "GATES/SFM2006_Circuit/sfm.ctl" |
---|
147 | // #define CNF_FILE_C1 "GATES/SFM2006_Circuit/SATcnf_sfm.cnf" |
---|
148 | |
---|
149 | // #define BLIF_MV_FILE_C1 "GATES/SFM2006_Circuit2/Concret_Main.mv" |
---|
150 | // #define FAIRNESS_FILE_C1 "GATES/SFM2006_Circuit2/sfm2.fair" |
---|
151 | // #define CTL_FILE_C1 "GATES/SFM2006_Circuit2/sfm2.ctl" |
---|
152 | // #define CNF_FILE_C1 "GATES/SFM2006_Circuit2/SATcnf_sfm2.cnf" |
---|
153 | |
---|
154 | // #define BLIF_MV_FILE_C1 "GATES/SFM2006_Circuit3/Concret_Main.mv" |
---|
155 | // #define FAIRNESS_FILE_C1 "GATES/SFM2006_Circuit3/sfm3.fair" |
---|
156 | // #define CTL_FILE_C1 "GATES/SFM2006_Circuit3/sfm3.ctl" |
---|
157 | // #define CNF_FILE_C1 "GATES/SFM2006_Circuit3/SATcnf_sfm3.cnf" |
---|
158 | |
---|
159 | //#define BLIF_MV_FILE_A2 "MEE/metronome.mv" |
---|
160 | //#define FAIRNESS_FILE_A2 "EC1/machine_concret.fair" |
---|
161 | //#define CTL_FILE_A1 "EX1/machine_concret.ctl" |
---|
162 | //#define CNF_FILE_A2 "EX1/SATcnf_a2.cnf" |
---|
163 | |
---|
164 | /*---------------------------------------------------------------------------*/ |
---|
165 | /* Structure declarations */ |
---|
166 | /*---------------------------------------------------------------------------*/ |
---|
167 | /**Struct********************************************************************** |
---|
168 | Synopsis [A struct to store a string of characters] |
---|
169 | ******************************************************************************/ |
---|
170 | typedef char string1 [255]; |
---|
171 | |
---|
172 | |
---|
173 | /**Struct********************************************************************** |
---|
174 | Synopsis [A struct to store of variables in the counter-example.] |
---|
175 | ******************************************************************************/ |
---|
176 | typedef struct { |
---|
177 | int varIndex; // not really necessary |
---|
178 | int varId; |
---|
179 | int varValue; |
---|
180 | // char *varName |
---|
181 | // char *symbolicValue |
---|
182 | string1 varName; // change to dynamic allocation later |
---|
183 | string1 symbolicValue; // change to dynamic allocation later |
---|
184 | } CEXVarStruct; |
---|
185 | |
---|
186 | |
---|
187 | /**Struct********************************************************************** |
---|
188 | Synopsis [A struct to store counter-example data.] |
---|
189 | ******************************************************************************/ |
---|
190 | typedef struct { |
---|
191 | int pathIndex; |
---|
192 | int n_outputVar; |
---|
193 | int n_inputVar; |
---|
194 | CEXVarStruct *outputVar; |
---|
195 | CEXVarStruct *inputVar; |
---|
196 | }CEXStruct; |
---|
197 | |
---|
198 | |
---|
199 | /*---------------------------------------------------------------------------*/ |
---|
200 | /* Variable declarations */ |
---|
201 | /*---------------------------------------------------------------------------*/ |
---|
202 | Hrc_Manager_t *hmgrGlobalC; |
---|
203 | |
---|
204 | FILE *vis_stderr; |
---|
205 | FILE *vis_stdout; |
---|
206 | FILE *vis_historyFile; |
---|
207 | FILE *vis_stdpipe; |
---|
208 | array_t *vm_commandHistoryArray; |
---|
209 | char *vm_programName; |
---|
210 | static int mcTimeOut; //Time-out value for model-checking |
---|
211 | static jmp_buf timeOutEnv; |
---|
212 | static long alarmLapTime; /* starting CPU time for timeout */ |
---|
213 | static jmp_buf env; |
---|
214 | |
---|
215 | extern FILE *IoYyin; |
---|
216 | extern int globalCurrentStackDepth; |
---|
217 | #ifdef IODEBUG |
---|
218 | extern int IoYydebug; |
---|
219 | #endif /*IODEBUG */ |
---|
220 | |
---|
221 | char currentPath [LENGTH_1]; |
---|
222 | static CEXVarStruct *testCEXVar; |
---|
223 | static CEXStruct *testCEX; |
---|
224 | |
---|
225 | |
---|
226 | /*---------------------------------------------------------------------------*/ |
---|
227 | /* Static function prototypes */ |
---|
228 | /*---------------------------------------------------------------------------*/ |
---|
229 | |
---|
230 | static Hrc_Manager_t *read_blif_mvMine (FILE *fp, Hrc_Manager_t *hmgr, boolean isCanonical, boolean isIncremental, boolean isVerbose); |
---|
231 | static int read_fairnessMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
232 | static int init_verifyMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
233 | static int flatten_hierarchyMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
234 | static int static_orderMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
235 | static int build_partition_mddsMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
236 | static int build_partition_maigsMine(Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
237 | static int print_ioMine (Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
238 | static int model_checkMine (Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
239 | static int print_modelsMine(Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
240 | static int print_fairnessMine(Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
241 | static Hrc_Node_t *cdMine(Hrc_Manager_t **hmgr, int argc, char **argv); //returns child or parent node |
---|
242 | static Hrc_Node_t *lsMine(Hrc_Manager_t **hmgr, int argc, char **argv); //returns current node |
---|
243 | static char *pwdMine(Hrc_Manager_t **hmgr, int argc, char **argv); //returns the path of the current node |
---|
244 | static int print_latchesMine(Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
245 | |
---|
246 | static boolean McPrintPassFailMine (mdd_manager *mddMgr, Fsm_Fsm_t *modelFsm, Mc_FwdBwdAnalysis traversalDirection, Ctlp_Formula_t *ctlFormula, mdd_t *ctlFormulaStates, mdd_t *modelInitialStates, array_t *modelCareStatesArray, McOptions_t *options, Mc_VerbosityLevel verbosity); |
---|
247 | static int McFsmDebugFormulaMine (McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, array_t *careSetArray); |
---|
248 | static array_t * McFsmStateDebugFormulaMine( McOptions_t *options, Ctlp_Formula_t *ctlFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, array_t *prevCExArray); |
---|
249 | static array_t * FsmStateDebugConvertedFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, array_t **preCExArray); |
---|
250 | static array_t * FsmPathDebugFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
251 | |
---|
252 | static void DebugIDMine(McOptions_t *options, Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm); |
---|
253 | static void DebugTrueFalseMine(Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm); |
---|
254 | static array_t * DebugBooleanMine(McOptions_t *options, Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, array_t **preCExArray); |
---|
255 | static McPath_t * DebugEXMine (Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray); |
---|
256 | static McPath_t * DebugEUMine (Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray); |
---|
257 | static McPath_t * DebugEGMine (Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, McOptions_t *options); |
---|
258 | |
---|
259 | static array_t * FsmPathDebugEXFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
260 | static array_t * FsmPathDebugEUFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
261 | static array_t * FsmPathDebugEGFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
262 | static array_t * FsmPathDebugEFFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
263 | |
---|
264 | static array_t * FsmPathDebugAXFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray, array_t **preCExArray); |
---|
265 | static array_t * FsmPathDebugAFFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray, array_t **preCExArray); |
---|
266 | static array_t * FsmPathDebugAGFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray, array_t **preCExArray); |
---|
267 | static array_t * FsmPathDebugAUFormulaMine(McOptions_t *options, mdd_t *aState, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, array_t *careSetArray, array_t **preCExArray); |
---|
268 | |
---|
269 | static int Mc_PrintPathMine (array_t *aPath, Fsm_Fsm_t *modelFsm, boolean printInput); |
---|
270 | static void McPrintTransitionMine (mdd_t *aState, mdd_t *bState, mdd_t *uInput, mdd_t *vInput, array_t *stateSupport, array_t *inputSupport, boolean printInputs, Fsm_Fsm_t *modelFsm, CEXStruct *CEXPath, int seqNumber, BmcCnfClauses_t *cnfClauses); |
---|
271 | static void Mc_MintermPrintMine (mdd_t *aMinterm, array_t *support, Ntk_Network_t *aNetwork); |
---|
272 | static char *Mc_MintermToStringMine( mdd_t *aMinterm, array_t *aSupport, Ntk_Network_t *aNetwork, CEXStruct *CEXPath, int seqNumber, boolean inOutIndicator, BmcCnfClauses_t *cnfClauses); |
---|
273 | static array_t *McConvertMintermToValueArrayMine( mdd_t *aMinterm, array_t *aSupport, mdd_manager *mddMgr); |
---|
274 | static void McStatePassesOrFailsFormulaMine ( mdd_t *aState, Ctlp_Formula_t *formula, int pass, McDbgLevel debugLevel, Fsm_Fsm_t *modelFsm); |
---|
275 | static void McStateFailsFormulaMine (mdd_t *aState, Ctlp_Formula_t *formula, McDbgLevel debugLevel, Fsm_Fsm_t *modelFsm); |
---|
276 | static void McStatePassesFormulaMine( mdd_t *aState, Ctlp_Formula_t *formula, McDbgLevel debugLevel,Fsm_Fsm_t *modelFsm); |
---|
277 | |
---|
278 | static int _HrcStringCmp(const void * s1, const void * s2); |
---|
279 | static McOptions_t *ParseMcOptions( int argc, char **argv); |
---|
280 | static void TimeOutHandle(void); |
---|
281 | static Ord_OrderType StringConvertToOrderType(char *string); |
---|
282 | static boolean NetworkCheckSuppliedNodeList(Ntk_Network_t * network, lsList suppliedNodeList, Ord_OrderType orderType); |
---|
283 | static boolean FileReadNameList(FILE * fp, lsList * nameList, int verbose); |
---|
284 | static void _IoGlobalVariablesInitialize(void); |
---|
285 | static void _IoGlobalVariablesFree(void); |
---|
286 | static void _IoGlobalSubcktInfoFree(void); |
---|
287 | static void _IoSubcktArrayFree(array_t *array); |
---|
288 | static void _IoSubcktFree(IoSubckt_t *subckt); |
---|
289 | static void _IoGlobalResetInfoFree(void); |
---|
290 | static boolean _IoNodeTestCompatibilityAux(Hrc_Manager_t *hmgr, Hrc_Node_t *hnode1, Hrc_Node_t *hnode2, boolean mode); |
---|
291 | static void _IoManagerCanonicalize(Hrc_Manager_t *hmgr); |
---|
292 | static int nodenameCompare(const void * node1, const void * node2); |
---|
293 | static void PrintNodeStats(Hrc_Node_t *node, boolean isHnode); |
---|
294 | static void NodeListChildren(Hrc_Node_t *hnode, boolean recursiveFlag, int depth); |
---|
295 | static array_t *NodeListChildrenMine(Hrc_Node_t *hnode, boolean recursiveFlag, int depth); |
---|
296 | static void PrintSpace(int depth); |
---|
297 | static int cmp(const void * s1, const void * s2); |
---|
298 | static boolean MintermCheckWellFormed(mdd_t *aMinterm, array_t *aSupport, mdd_manager *mddMgr); |
---|
299 | static boolean SetCheckSupport(mdd_t *aMinterm, array_t *aSupport, mdd_manager *mddMgr); |
---|
300 | |
---|
301 | static char *CNFVariableNameConstructor(char *varName, int varEncoding, int pathIndex); |
---|
302 | static void BmcCnfGenerateClausesForPathMine (Ntk_Network_t *network, int from, int to, int initialState, BmcCnfClauses_t *cnfClauses, st_table *nodeToMvfAigTable, st_table *CoiTable); |
---|
303 | static void BmcGenerateClausesFromStateTostateMine (bAig_Manager_t *manager, bAigEdge_t *fromAigArray, bAigEdge_t *toAigArray, int mvfSize, int fromState, int toState, BmcCnfClauses_t *cnfClauses, int outIndex); |
---|
304 | static void BmcWriteClausesMine( mAig_Manager_t *maigManager, FILE *cnfFile, BmcCnfClauses_t *cnfClauses, BmcOption_t *options); |
---|
305 | static int *DecBinConverter (int decValue, int size, int *binValue); |
---|
306 | static int SATSolverFileGen (Hrc_Manager_t **hmgr, char *fileName, int steps, BmcOption_t *options); |
---|
307 | static int SATSolver (int steps, BmcOption_t *options); |
---|
308 | static void build_unroll_circuit(Ntk_Network_t * ntk, int bound,BmcOption_t * options,BmcCnfClauses_t* cnfClauses); |
---|
309 | static array_t * checkSATCircus( satManager_t *cm,BmcOption_t * options, boolean unsatcore, satArray_t *clauseIndexInCore); |
---|
310 | static st_table * generateAllLatches(Ntk_Network_t * ntk); |
---|
311 | static void printSATAssig( array_t* result); |
---|
312 | static int findIndex(BmcCnfClauses_t* cnfClauses , char * nodeName); |
---|
313 | |
---|
314 | |
---|
315 | /********************************************************/ |
---|
316 | /* Main */ |
---|
317 | /********************************************************/ |
---|
318 | |
---|
319 | int main(int argc, char **argv) |
---|
320 | { |
---|
321 | vis_stderr =stderr; |
---|
322 | vis_stdout = stdout; |
---|
323 | |
---|
324 | Hrc_Manager_t *hmgrC; |
---|
325 | Hrc_Manager_t *hmgrA; |
---|
326 | |
---|
327 | (void)fprintf(vis_stderr,"\n============= VIS ============= \n\n"); |
---|
328 | |
---|
329 | |
---|
330 | /**** CONCRETE MODEL *****/ |
---|
331 | (void)fprintf(vis_stderr,">>>>>>>>>>>>>>>>> CONCRETE MODEL : LOAD & SET UP... \n\n"); |
---|
332 | // --- read_blif_mv --- |
---|
333 | FILE *fpC; |
---|
334 | fpC = Cmd_FileOpen(BLIF_MV_FILE_C1, "r", NIL(char *), 1); |
---|
335 | boolean isCanonicalC = 0; |
---|
336 | boolean isIncrementalC = 0; |
---|
337 | boolean isVerboseC = 0; |
---|
338 | hmgrC = read_blif_mvMine (fpC, hmgrC, isCanonicalC, isIncrementalC, isVerboseC); |
---|
339 | (void) fprintf(vis_stderr, "*** 'read_blif_mv' of the concrete model completed. *** \n"); |
---|
340 | |
---|
341 | hmgrGlobalC = hmgrC; |
---|
342 | |
---|
343 | // --- print_io (display inputs and outputs) --- |
---|
344 | int print_ioExecC; |
---|
345 | int argcIOC = 1; |
---|
346 | char *argvIOC[1] = {"print_io"}; |
---|
347 | |
---|
348 | print_ioExecC = print_ioMine (&hmgrC, argcIOC, argvIOC); |
---|
349 | (void) fprintf(vis_stderr, "*** 'print_io' for concrete model completed. *** \n"); |
---|
350 | |
---|
351 | // --- init_verify --- |
---|
352 | int init_verifyExecC; |
---|
353 | int argcIVC = 1; |
---|
354 | char *argvIVC[1] = {"init_verify"}; |
---|
355 | init_verifyExecC = init_verifyMine (&hmgrC, argcIVC, argvIVC); |
---|
356 | (void) fprintf(vis_stderr, "*** 'init_verify' for concrete model completed. *** \n"); |
---|
357 | |
---|
358 | // --- build_partition_maigs --- |
---|
359 | int build_part_maigsExecC; |
---|
360 | int argcBPMAIGSC = 1; |
---|
361 | char *argvBPMAIGSC[1] = {"build_partition_maigs"}; |
---|
362 | build_part_maigsExecC = build_partition_maigsMine (&hmgrC, argcBPMAIGSC, argvBPMAIGSC); |
---|
363 | (void) fprintf(vis_stderr, "*** 'build_partition_maigs' for concrete model completed. *** \n"); |
---|
364 | |
---|
365 | // --- read_fairness --- |
---|
366 | int fairnessReadC; |
---|
367 | int argcFC = 2; |
---|
368 | char *argvFC[2] = {"read_fairness", FAIRNESS_FILE_C1}; |
---|
369 | fairnessReadC = read_fairnessMine (&hmgrC, argcFC, argvFC); |
---|
370 | (void) fprintf(vis_stderr, "*** 'read_fairness' for concrete model completed. *** \n"); |
---|
371 | |
---|
372 | // --- print_fairness --- |
---|
373 | int fairnessPrintC; |
---|
374 | int argcFPC = 1; |
---|
375 | char *argvFPC[1] = {"print_fairness"}; |
---|
376 | fairnessPrintC = print_fairnessMine (&hmgrC, argcFPC, argvFPC); |
---|
377 | (void) fprintf(vis_stderr, "*** 'print_fairness' for concrete model completed. *** \n"); |
---|
378 | |
---|
379 | |
---|
380 | // // --- print_latches (display latches in current node) --- |
---|
381 | // int print_latchesExec; |
---|
382 | // int argcPL = 1; |
---|
383 | // char *argvPL[1]= {"print_latches"}; |
---|
384 | // |
---|
385 | // print_latchesExec = print_latchesMine (&hmgr, argcPL, argvPL); |
---|
386 | // (void) fprintf(vis_stderr, "*** 'print_latches' completed. *** \n"); |
---|
387 | |
---|
388 | (void)fprintf(vis_stderr,"\n... CONCRETE MODEL : LOAD & SET UP DONE! <<<<<<<<<<<<<<<<\n\n"); |
---|
389 | |
---|
390 | |
---|
391 | |
---|
392 | /**** ABSTRACT MODEL *****/ |
---|
393 | (void)fprintf(vis_stderr,">>>>>>>>>>>>>>>>> ABSTRACT MODEL : LOAD & SET UP...\n"); |
---|
394 | // --- read_blif_mv --- |
---|
395 | FILE *fpA; |
---|
396 | fpA = Cmd_FileOpen(BLIF_MV_FILE_A1, "r", NIL(char *), 1); |
---|
397 | boolean isCanonicalA = 0; |
---|
398 | boolean isIncrementalA = 0; |
---|
399 | boolean isVerboseA = 0; |
---|
400 | hmgrA = read_blif_mvMine (fpA, hmgrA, isCanonicalA, isIncrementalA, isVerboseA); |
---|
401 | (void) fprintf(vis_stderr, "*** 'read_blif_mv' of the abstract model completed. *** \n"); |
---|
402 | |
---|
403 | |
---|
404 | // --- print_io (display inputs and outputs) --- |
---|
405 | int print_ioExecA; |
---|
406 | int argcIOA = 1; |
---|
407 | char *argvIOA[1] = {"print_io"}; |
---|
408 | |
---|
409 | print_ioExecA = print_ioMine (&hmgrA, argcIOA, argvIOA); |
---|
410 | (void) fprintf(vis_stderr, "*** 'print_io' for abstract model completed. *** \n"); |
---|
411 | |
---|
412 | // --- init_verify --- |
---|
413 | int init_verifyExecA; |
---|
414 | int argcIVA = 1; |
---|
415 | char *argvIVA[1] = {"init_verify"}; |
---|
416 | init_verifyExecA = init_verifyMine (&hmgrA, argcIVA, argvIVA); |
---|
417 | (void) fprintf(vis_stderr, "*** 'init_verify' for abstract model completed. *** \n"); |
---|
418 | |
---|
419 | // --- read_fairness --- |
---|
420 | int fairnessReadA; |
---|
421 | int argcFA = 2; |
---|
422 | char *argvFA[2] = {"read_fairness", FAIRNESS_FILE_A1}; |
---|
423 | fairnessReadA = read_fairnessMine (&hmgrA, argcFA, argvFA); |
---|
424 | (void) fprintf(vis_stderr, "*** 'read_fairness' for abstract model completed. *** \n"); |
---|
425 | |
---|
426 | // --- print_fairness --- |
---|
427 | int fairnessPrintA; |
---|
428 | int argcFPA = 1; |
---|
429 | char *argvFPA[1] = {"print_fairness"}; |
---|
430 | fairnessPrintA = print_fairnessMine (&hmgrA, argcFPA, argvFPA); |
---|
431 | (void) fprintf(vis_stderr, "*** 'print_fairness' for abstract model completed. *** \n"); |
---|
432 | |
---|
433 | (void)fprintf(vis_stderr,"\n... ABSTRACT MODEL : LOAD & SET UP DONE! <<<<<<<<<<<<<<<<\n\n"); |
---|
434 | |
---|
435 | // --- model_check --- |
---|
436 | int model_checkExecA; |
---|
437 | int argcMCA = 4; |
---|
438 | // char *argvMC[2]= {"model_check", "EX_C1/machine_concret.ctl"}; |
---|
439 | // char *argvMC[4]= {"model_check", "-d", "3", "EX_C1/machine_concret.ctl"}; |
---|
440 | // char *argvMCA[2]= {"model_check", CTL_FILE_A1}; |
---|
441 | // char *argvMCA[4]= {"model_check", "-d", "1", CTL_FILE_A1}; |
---|
442 | char *argvMCA[4]= {"model_check", "-d", "2", CTL_FILE_A1}; |
---|
443 | // char *argvMCA[4]= {"model_check", "-d", "3", CTL_FILE_A1}; |
---|
444 | // char *argvMCA[5]= {"model_check", "-i", "-d", "3", CTL_FILE_A1}; |
---|
445 | // char *argvMC[6]= {"model_check", "-i", "-W", "-d", "2", "EX_C1/machine_concret.ctl"}; |
---|
446 | // char *argvMCA[6]= {"model_check", "-d", "2", "-f", DEBUG_FILE_A1, CTL_FILE_A1}; |
---|
447 | // char *argvMC[6]= {"model_check", "-v", "2", "-d", "2", "EX_C1/machine_concret.ctl"}; |
---|
448 | // char *argvMC[7]= {"model_check", "-i", "-w", "EX_C1/w_node_file", "-d", "2", "EX_C1/machine_concret.ctl"}; |
---|
449 | // char *argvMC[7]= {"model_check", "-d", "3", "-f", DEBUG_FILE_A1, "-i", CTL_FILE_A1}; |
---|
450 | // char *argvMC[8]= {"model_check", "-d", "3", "-f", "EX_C1/debug_trace", "-v", "2", "EX_C1/machine_concret.ctl"}; |
---|
451 | // char *argvMC[9]= {"model_check", "-d", "3", "-f", "EX_C1/debug_trace", "-i", "-v", "2", "EX_C1/machine_concret.ctl"}; |
---|
452 | |
---|
453 | model_checkExecA = model_checkMine (&hmgrA, argcMCA, argvMCA); |
---|
454 | (void) fprintf(vis_stderr, "*** 'model_check' of abstract model completed. *** \n"); |
---|
455 | |
---|
456 | |
---|
457 | (void) fprintf(vis_stderr,"\n========== END OF VIS ========= \n\n"); |
---|
458 | |
---|
459 | return 0; |
---|
460 | |
---|
461 | } |
---|
462 | |
---|
463 | |
---|
464 | /*---------------------------------------------------------------------------*/ |
---|
465 | /* Definition of static functions */ |
---|
466 | /*---------------------------------------------------------------------------*/ |
---|
467 | |
---|
468 | /**Function******************************************************************** |
---|
469 | |
---|
470 | Synopsis [] |
---|
471 | |
---|
472 | Description [Refer to 'Hrc_Manager_t * Io_BlifMvRead( FILE *fp, |
---|
473 | Hrc_Manager_t *hmgr, boolean isCanonical, boolean isIncremental, |
---|
474 | boolean isVerbose)' in ntkCmd.c] |
---|
475 | |
---|
476 | SideEffects [] |
---|
477 | |
---|
478 | SeeAlso [] |
---|
479 | |
---|
480 | ******************************************************************************/ |
---|
481 | |
---|
482 | static Hrc_Manager_t *read_blif_mvMine (FILE *fp, Hrc_Manager_t *hmgr, |
---|
483 | boolean isCanonical, boolean isIncremental, boolean isVerbose) |
---|
484 | { |
---|
485 | |
---|
486 | (void) fprintf(vis_stderr, "*** 'read_blif_mv' begins. *** \n"); |
---|
487 | |
---|
488 | Hrc_Node_t *root; |
---|
489 | static Hrc_Manager_t *newHmgr; |
---|
490 | |
---|
491 | if (isIncremental == 0){ |
---|
492 | newHmgr = Hrc_ManagerAlloc(); |
---|
493 | } |
---|
494 | else { /* isIncremental == 1 */ |
---|
495 | if (Hrc_ManagerReadCurrentNode(hmgr) == NIL(Hrc_Node_t)){ |
---|
496 | (void)fprintf(vis_stderr,"No hierarchy has been created. Cannot do inremental read-in.\n"); |
---|
497 | return NIL(Hrc_Manager_t); |
---|
498 | } |
---|
499 | newHmgr = hmgr; |
---|
500 | } |
---|
501 | |
---|
502 | if (setjmp(env)){ |
---|
503 | if (isIncremental == 0){ |
---|
504 | Hrc_ManagerFree(newHmgr); |
---|
505 | } |
---|
506 | else { |
---|
507 | int i; |
---|
508 | /* free all the new models defined in an incremental file */ |
---|
509 | for (i=0; i < array_n(globalNewModelArray); i++){ |
---|
510 | Hrc_ModelDelete(hmgr,Hrc_ModelReadName(array_fetch(Hrc_Model_t *,globalNewModelArray,i))); |
---|
511 | } |
---|
512 | } |
---|
513 | _IoGlobalVariablesFree(); |
---|
514 | return NIL(Hrc_Manager_t); |
---|
515 | } |
---|
516 | else { |
---|
517 | _IoGlobalVariablesInitialize(); |
---|
518 | if (isIncremental == 0){ |
---|
519 | globalYaccHmgr = newHmgr; |
---|
520 | } |
---|
521 | else { |
---|
522 | globalYaccHmgr = hmgr; |
---|
523 | } |
---|
524 | #ifdef IODEBUG |
---|
525 | IoYydebug = 1; |
---|
526 | #endif /* IODEBUG */ |
---|
527 | IoYyin = fp; |
---|
528 | IoYyrestart(IoYyin); |
---|
529 | if (IoYyparse() == 1){ |
---|
530 | IoError(); |
---|
531 | } |
---|
532 | |
---|
533 | /* globalNewModelArray contains all the models defined in the previous |
---|
534 | IoYyparse(). If isIncremental==0, then they are simply all the models. |
---|
535 | If isIncremental==1, then they are new models defined in the file. */ |
---|
536 | |
---|
537 | if (IoNetworkTestConsistency(newHmgr,globalNewModelArray,globalParserSubcktInfo,globalParserResetInfo,isVerbose) == 0){ |
---|
538 | IoError(); |
---|
539 | } |
---|
540 | |
---|
541 | if (globalRootModel == NIL(Hrc_Model_t)){ |
---|
542 | globalRootModel = globalFirstModel; |
---|
543 | globalRootInstanceName = util_strsav(Hrc_ModelReadName(globalRootModel)); |
---|
544 | } |
---|
545 | else if (globalRootInstanceName == NIL(char)){ |
---|
546 | globalRootInstanceName = util_strsav(Hrc_ModelReadName(globalRootModel)); |
---|
547 | } |
---|
548 | |
---|
549 | if (isCanonical == 1){ |
---|
550 | _IoManagerCanonicalize(newHmgr); |
---|
551 | } |
---|
552 | |
---|
553 | root = Hrc_ModelCreateHierarchy(newHmgr,globalRootModel,globalRootInstanceName); |
---|
554 | FREE(globalRootInstanceName); |
---|
555 | |
---|
556 | if (isIncremental == 0){ |
---|
557 | Hrc_ManagerSetRootNode(newHmgr,root); |
---|
558 | Hrc_ManagerSetCurrentNode(newHmgr,root); |
---|
559 | _IoGlobalVariablesFree(); |
---|
560 | return newHmgr; |
---|
561 | } |
---|
562 | else { /* isIncremental == 1, note that newHmgr == hmgr */ |
---|
563 | if (_IoNodeTestCompatibility(hmgr,Hrc_ManagerReadCurrentNode(hmgr),root) == 0){ |
---|
564 | int i; |
---|
565 | (void)fprintf(vis_stderr,"The blif-mv file is not compatible with the existing hierarchy.\n"); |
---|
566 | Hrc_TreeReplace(NIL(Hrc_Node_t),root); |
---|
567 | /* free all the new models defined in an incremental file */ |
---|
568 | for (i=0; i < array_n(globalNewModelArray); i++){ |
---|
569 | Hrc_ModelDelete(hmgr,Hrc_ModelReadName(array_fetch(Hrc_Model_t *,globalNewModelArray,i))); |
---|
570 | } |
---|
571 | _IoGlobalVariablesFree(); |
---|
572 | return NIL(Hrc_Manager_t); |
---|
573 | } |
---|
574 | Hrc_TreeReplace(Hrc_ManagerReadCurrentNode(hmgr),root); |
---|
575 | Hrc_ManagerSetCurrentNode(hmgr,root); |
---|
576 | _IoGlobalVariablesFree(); |
---|
577 | return hmgr; |
---|
578 | } |
---|
579 | } |
---|
580 | |
---|
581 | |
---|
582 | } |
---|
583 | |
---|
584 | |
---|
585 | /**Function******************************************************************** |
---|
586 | |
---|
587 | Synopsis [] |
---|
588 | |
---|
589 | Description [Refer to 'static int CommandInitVerify(Hrc_Manager_t ** hmgr, |
---|
590 | int argc, char ** argv);' in ntkCmd.c] |
---|
591 | |
---|
592 | SideEffects [] |
---|
593 | |
---|
594 | SeeAlso [] |
---|
595 | |
---|
596 | ******************************************************************************/ |
---|
597 | static int init_verifyMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
598 | { |
---|
599 | |
---|
600 | (void) fprintf(vis_stderr, "*** 'init_verify' begins. *** \n"); |
---|
601 | |
---|
602 | int c; |
---|
603 | Hrc_Node_t *currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
604 | |
---|
605 | /* |
---|
606 | * Parse the command line. |
---|
607 | */ |
---|
608 | util_getopt_reset(); |
---|
609 | while ((c = util_getopt(argc, argv, "bh")) != EOF) { |
---|
610 | switch (c) { |
---|
611 | case 'b': |
---|
612 | break; |
---|
613 | case 'h': |
---|
614 | goto usage; |
---|
615 | default: |
---|
616 | goto usage; |
---|
617 | } |
---|
618 | } |
---|
619 | |
---|
620 | if (currentNode == NIL(Hrc_Node_t)) { |
---|
621 | (void) fprintf(vis_stdout, "The hierarchy manager is empty. Read in design.\n"); |
---|
622 | return 1; |
---|
623 | } |
---|
624 | |
---|
625 | |
---|
626 | // ++ add condition to test if the functions failed |
---|
627 | (void) fprintf(vis_stderr, "---- 'init_verify' : (1) "); |
---|
628 | // --- init_verify : (1) flatten_hierarchy --- |
---|
629 | int flatten_hierarchyExec; |
---|
630 | int argcFH = 1; |
---|
631 | char *argvFH[1]= {"flatten_hierarchy"}; |
---|
632 | flatten_hierarchyExec = flatten_hierarchyMine (hmgr, argcFH, argvFH); |
---|
633 | // flatten_hierarchyExec = flatten_hierarchyMine (&(*hmgr), argcFH, argvFH); |
---|
634 | (void) fprintf(vis_stderr, "---- 'init_verify' : (1) *** 'flatten_hierarchy' completed. *** \n"); |
---|
635 | |
---|
636 | // --- init_verify : (2) static_order --- |
---|
637 | (void) fprintf(vis_stderr, "---- 'init_verify' : (2) "); |
---|
638 | int static_orderExec; |
---|
639 | int argcSO = 1; |
---|
640 | char *argvSO[1]= {"static_order"}; |
---|
641 | static_orderExec = static_orderMine (hmgr, argcSO, argvSO); |
---|
642 | (void) fprintf(vis_stderr, "---- 'init_verify' : (2) *** 'static_order' completed. *** \n"); |
---|
643 | |
---|
644 | // --- init_verify : (3) build_partition_mdds --- |
---|
645 | (void) fprintf(vis_stderr, "---- 'init_verify' : (3) "); |
---|
646 | int build_part_mddsExec; |
---|
647 | int argcBPMDDS = 1; |
---|
648 | char *argvBPMDDS[1]= {"build_partition_mdds"}; |
---|
649 | build_part_mddsExec = build_partition_mddsMine (hmgr, argcBPMDDS, argvBPMDDS); |
---|
650 | (void) fprintf(vis_stderr, "---- 'init_verify' : (3) *** 'build_partition_mdds' completed. *** \n"); |
---|
651 | |
---|
652 | return 0; /* normal exit */ |
---|
653 | |
---|
654 | |
---|
655 | usage: |
---|
656 | (void) fprintf(vis_stderr, "usage: init_verify [-b] [-h]\n"); |
---|
657 | (void) fprintf(vis_stderr, " -b not used any longer.\n"); |
---|
658 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
659 | return 1; /* error exit */ |
---|
660 | |
---|
661 | } |
---|
662 | |
---|
663 | |
---|
664 | /**Function******************************************************************** |
---|
665 | |
---|
666 | Synopsis [] |
---|
667 | |
---|
668 | Description [Refer to 'static int CommandFlattenHierarchy(Hrc_Manager_t ** |
---|
669 | hmgr, int argc, char ** argv);' in ntkCmd.c] |
---|
670 | |
---|
671 | SideEffects [] |
---|
672 | |
---|
673 | SeeAlso [] |
---|
674 | |
---|
675 | ******************************************************************************/ |
---|
676 | static int flatten_hierarchyMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
677 | { |
---|
678 | |
---|
679 | (void) fprintf(vis_stderr, "*** 'flatten_hierarchy' begins. *** \n"); |
---|
680 | |
---|
681 | int c; |
---|
682 | Ntk_Network_t *network; |
---|
683 | char *fileName = NIL(char); |
---|
684 | int verbose = 0; /* default */ |
---|
685 | int sweep = 1; |
---|
686 | lsList varNameList = (lsList) NULL; |
---|
687 | Hrc_Node_t *currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
688 | |
---|
689 | /* |
---|
690 | * Parse the command line. |
---|
691 | */ |
---|
692 | util_getopt_reset(); |
---|
693 | while ((c = util_getopt(argc, argv, "a:bhsv:")) != EOF) { |
---|
694 | switch (c) { |
---|
695 | case 'a': |
---|
696 | fileName = util_optarg; |
---|
697 | break; |
---|
698 | case 'b': |
---|
699 | break; |
---|
700 | case 'h': |
---|
701 | goto usage; |
---|
702 | case 's': |
---|
703 | sweep = 0; |
---|
704 | break; |
---|
705 | case 'v': |
---|
706 | verbose = atoi(util_optarg); |
---|
707 | break; |
---|
708 | default: |
---|
709 | goto usage; |
---|
710 | } |
---|
711 | } |
---|
712 | |
---|
713 | if (currentNode == NIL(Hrc_Node_t)) { |
---|
714 | (void) fprintf(vis_stdout, "The hierarchy manager is empty. Read in design.\n"); |
---|
715 | return 1; |
---|
716 | } |
---|
717 | |
---|
718 | /* |
---|
719 | * Process the file containing the variable names. |
---|
720 | */ |
---|
721 | if (fileName != NIL(char)) { |
---|
722 | FILE *fp = Cmd_FileOpen(fileName, "r", NIL(char *), 0); |
---|
723 | if (fp == NIL(FILE)) { |
---|
724 | return 1; |
---|
725 | } |
---|
726 | else { |
---|
727 | boolean status; |
---|
728 | |
---|
729 | error_init(); |
---|
730 | status = FileReadNameList(fp, &varNameList, verbose); |
---|
731 | (void) fclose(fp); |
---|
732 | if (status == FALSE) { |
---|
733 | (void) fprintf(vis_stderr, "Error reading variable name file:\n"); |
---|
734 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
735 | (void) fprintf(vis_stderr, "Cannot perform flatten_hierarchy.\n"); |
---|
736 | return 1; |
---|
737 | } |
---|
738 | } |
---|
739 | } |
---|
740 | |
---|
741 | |
---|
742 | /* |
---|
743 | * If a network already exists, delete it. Then create the new one, and |
---|
744 | * register it with the hrcNode. |
---|
745 | */ |
---|
746 | network = (Ntk_Network_t *) Hrc_NodeReadApplInfo(currentNode, |
---|
747 | NTK_HRC_NODE_APPL_KEY); |
---|
748 | if (network != NIL(Ntk_Network_t)) { |
---|
749 | (void) fprintf(vis_stdout, "Deleting current network and creating new one.\n"); |
---|
750 | Hrc_NodeFreeApplInfo(currentNode, NTK_HRC_NODE_APPL_KEY); |
---|
751 | } |
---|
752 | |
---|
753 | error_init(); |
---|
754 | |
---|
755 | network = Ntk_HrcNodeConvertToNetwork(currentNode, TRUE, varNameList); |
---|
756 | |
---|
757 | /* Clean up the varNameList. */ |
---|
758 | if (varNameList != (lsList) NULL) { |
---|
759 | lsGen gen; |
---|
760 | char *varName; |
---|
761 | |
---|
762 | lsForEachItem(varNameList, gen, varName) { |
---|
763 | FREE(varName); |
---|
764 | } |
---|
765 | (void) lsDestroy(varNameList, (void (*) (lsGeneric)) NULL); |
---|
766 | } |
---|
767 | /* sweep network */ |
---|
768 | if (network != NIL(Ntk_Network_t) && sweep ==1) { |
---|
769 | Ntk_NetworkSweep(network, verbose); |
---|
770 | } |
---|
771 | |
---|
772 | if (network == NIL(Ntk_Network_t)) { |
---|
773 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
774 | (void) fprintf(vis_stderr, "Cannot perform flatten_hierarchy.\n"); |
---|
775 | return 1; |
---|
776 | } |
---|
777 | |
---|
778 | Hrc_NodeAddApplInfo(currentNode, NTK_HRC_NODE_APPL_KEY, |
---|
779 | (Hrc_ApplInfoFreeFn) Ntk_NetworkFreeCallback, |
---|
780 | (Hrc_ApplInfoChangeFn) NULL, /* not currently used by hrc */ |
---|
781 | (void *) network); |
---|
782 | |
---|
783 | return 0; /* normal exit */ |
---|
784 | |
---|
785 | usage: |
---|
786 | (void) fprintf(vis_stderr, "usage: flatten_hierarchy [-a file] [-b] [-h] [-s] [-v #]\n"); |
---|
787 | (void) fprintf(vis_stderr, " -a file variables to abstract\n"); |
---|
788 | (void) fprintf(vis_stderr, " -b not used any longer\n"); |
---|
789 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
790 | (void) fprintf(vis_stderr, " -s do not perform a sweep\n"); |
---|
791 | (void) fprintf(vis_stderr, " -v # verbosity level\n"); |
---|
792 | return 1; /* error exit */ |
---|
793 | } |
---|
794 | |
---|
795 | |
---|
796 | /**Function******************************************************************** |
---|
797 | |
---|
798 | Synopsis [] |
---|
799 | |
---|
800 | Description [Refer to 'static int CommandStaticOrder(Hrc_Manager_t ** hmgr, |
---|
801 | int argc, char ** argv);' in ordCmd.c] |
---|
802 | |
---|
803 | SideEffects [] |
---|
804 | |
---|
805 | SeeAlso [] |
---|
806 | |
---|
807 | ******************************************************************************/ |
---|
808 | static int static_orderMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
809 | { |
---|
810 | |
---|
811 | (void) fprintf(vis_stderr, "*** 'static_order' begins. *** \n"); |
---|
812 | |
---|
813 | int c; |
---|
814 | FILE *fp; |
---|
815 | static int timeOutPeriod; |
---|
816 | static int verbose; |
---|
817 | static Ord_NodeMethod nodeMethod; |
---|
818 | static Ord_RootMethod rootMethod; |
---|
819 | static Ord_OrderType suppliedOrderType; |
---|
820 | static Ord_OrderType generatedOrderType; |
---|
821 | static boolean nsAfterSupport; |
---|
822 | lsList suppliedNodeList = (lsList) NULL; |
---|
823 | /* list of Ntk_Node_t * */ |
---|
824 | Ntk_Network_t *network; |
---|
825 | |
---|
826 | /* |
---|
827 | * These are the default values. These variables must be declared static |
---|
828 | * to avoid lint warnings. Since they are static, we must reinitialize |
---|
829 | * them outside of the variable declarations. |
---|
830 | */ |
---|
831 | timeOutPeriod = 0; |
---|
832 | verbose = 0; |
---|
833 | nodeMethod = Ord_NodesByDefault_c; |
---|
834 | rootMethod = Ord_RootsByDefault_c; |
---|
835 | suppliedOrderType = Ord_Unassigned_c; /* default */ |
---|
836 | generatedOrderType = Ord_InputAndLatch_c;/* default */ |
---|
837 | nsAfterSupport = FALSE; /* default */ |
---|
838 | |
---|
839 | /* |
---|
840 | * Parse the command line. |
---|
841 | */ |
---|
842 | util_getopt_reset(); |
---|
843 | while ((c = util_getopt(argc, argv, "av:o:s:t:n:r:h")) != EOF) { |
---|
844 | switch (c) { |
---|
845 | case 'a': |
---|
846 | nsAfterSupport = TRUE; |
---|
847 | break; |
---|
848 | case 'h': |
---|
849 | goto usage; |
---|
850 | case 'v': |
---|
851 | verbose = atoi(util_optarg); |
---|
852 | break; |
---|
853 | case 't': |
---|
854 | timeOutPeriod = atoi(util_optarg); |
---|
855 | break; |
---|
856 | case 'o': |
---|
857 | generatedOrderType = StringConvertToOrderType(util_optarg); |
---|
858 | if ((generatedOrderType == Ord_NextStateNode_c) |
---|
859 | || (generatedOrderType == Ord_Partial_c)) { |
---|
860 | (void) fprintf(vis_stderr, "disallowed output order type: %s\n", util_optarg); |
---|
861 | goto usage; |
---|
862 | } |
---|
863 | else if (generatedOrderType == Ord_Unassigned_c) { |
---|
864 | (void) fprintf(vis_stderr, "unknown output order type: %s\n", util_optarg); |
---|
865 | goto usage; |
---|
866 | } |
---|
867 | break; |
---|
868 | case 's': |
---|
869 | suppliedOrderType = StringConvertToOrderType(util_optarg); |
---|
870 | if (suppliedOrderType == Ord_Unassigned_c) { |
---|
871 | (void) fprintf(vis_stderr, "unknown input order type: %s\n", util_optarg); |
---|
872 | goto usage; |
---|
873 | } |
---|
874 | break; |
---|
875 | case 'n': |
---|
876 | if (strcmp("interleave", util_optarg) == 0) { |
---|
877 | nodeMethod = Ord_NodesByInterleaving_c; |
---|
878 | } |
---|
879 | else if (strcmp("merge_left", util_optarg) == 0) { |
---|
880 | nodeMethod = Ord_NodesByMergingLeft_c; |
---|
881 | } |
---|
882 | else if (strcmp("merge_right", util_optarg) == 0) { |
---|
883 | nodeMethod = Ord_NodesByMergingRight_c; |
---|
884 | } |
---|
885 | else if (strcmp("append", util_optarg) == 0) { |
---|
886 | nodeMethod = Ord_NodesByAppending_c; |
---|
887 | } |
---|
888 | else { |
---|
889 | (void) fprintf(vis_stderr, "unknown node order method: %s\n", util_optarg); |
---|
890 | goto usage; |
---|
891 | } |
---|
892 | break; |
---|
893 | case 'r': |
---|
894 | if (strcmp("depth", util_optarg) == 0) { |
---|
895 | rootMethod = Ord_RootsByDepth_c; |
---|
896 | } |
---|
897 | else if (strcmp("mincomm", util_optarg) == 0) { |
---|
898 | rootMethod = Ord_RootsByPerm_c; |
---|
899 | } |
---|
900 | else { |
---|
901 | (void) fprintf(vis_stderr, "unknown root order method: %s\n", util_optarg); |
---|
902 | goto usage; |
---|
903 | } |
---|
904 | break; |
---|
905 | default: |
---|
906 | goto usage; |
---|
907 | } |
---|
908 | } |
---|
909 | |
---|
910 | network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
911 | if (network == NIL(Ntk_Network_t)) { |
---|
912 | return 1; |
---|
913 | } |
---|
914 | |
---|
915 | if ((suppliedOrderType == Ord_InputAndLatch_c) && (generatedOrderType == Ord_All_c)) { |
---|
916 | (void) fprintf(vis_stderr, "-o all -s input_and_latch not currently supported\n"); |
---|
917 | return 1; |
---|
918 | } |
---|
919 | |
---|
920 | /* |
---|
921 | * The minimum set of variables that can be ordered are those specified by |
---|
922 | * Ord_InputAndLatch_c. If these have already been ordered, then just return. |
---|
923 | */ |
---|
924 | if (Ord_NetworkTestAreVariablesOrdered(network, Ord_InputAndLatch_c)) { |
---|
925 | (void) fprintf(vis_stderr, "Variables already ordered. "); |
---|
926 | (void) fprintf(vis_stderr, "Reinvoke flatten_hierarchy to undo variable ordering.\n"); |
---|
927 | return 1; |
---|
928 | } |
---|
929 | |
---|
930 | |
---|
931 | /* |
---|
932 | * Process the input ordering file. |
---|
933 | */ |
---|
934 | if (suppliedOrderType == Ord_Unassigned_c) { |
---|
935 | if (argc - util_optind > 0) { |
---|
936 | (void) fprintf(vis_stderr, "must specify -s if supplying order file\n"); |
---|
937 | goto usage; |
---|
938 | } |
---|
939 | } |
---|
940 | else { |
---|
941 | if (argc - util_optind == 0) { |
---|
942 | (void) fprintf(vis_stderr, "order file not provided\n"); |
---|
943 | goto usage; |
---|
944 | } |
---|
945 | else if (argc - util_optind > 1) { |
---|
946 | (void) fprintf(vis_stderr, "too many arguments\n"); |
---|
947 | goto usage; |
---|
948 | } |
---|
949 | |
---|
950 | fp = Cmd_FileOpen(argv[util_optind], "r", NIL(char *), 0); |
---|
951 | if (fp == NIL(FILE)) { |
---|
952 | (void) fprintf(vis_stderr, "File %s is not readable, please check if it exists\n", argv[util_optind]); |
---|
953 | return 1; |
---|
954 | } |
---|
955 | else { |
---|
956 | boolean status; |
---|
957 | |
---|
958 | error_init(); |
---|
959 | status = Ord_FileReadNodeList(fp, network, &suppliedNodeList, verbose); |
---|
960 | if (status == FALSE) { |
---|
961 | (void) fprintf(vis_stderr, "Error reading ordering file:\n"); |
---|
962 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
963 | (void) fprintf(vis_stderr, "Cannot perform static ordering.\n"); |
---|
964 | (void) fclose(fp); |
---|
965 | return 1; |
---|
966 | } |
---|
967 | else if (NetworkCheckSuppliedNodeList(network, suppliedNodeList, |
---|
968 | suppliedOrderType) == FALSE) { |
---|
969 | (void) fprintf(vis_stderr, "Incorrect nodes supplied:\n"); |
---|
970 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
971 | (void) fprintf(vis_stderr, "Cannot perform static ordering.\n"); |
---|
972 | (void) fclose(fp); |
---|
973 | (void) lsDestroy(suppliedNodeList, (void (*) (lsGeneric)) NULL); |
---|
974 | return 1; |
---|
975 | } |
---|
976 | else { |
---|
977 | (void) fclose(fp); |
---|
978 | if (verbose > 0) { |
---|
979 | (void) fprintf(vis_stdout, "\nNodes supplied in ordering file, "); |
---|
980 | (void) fprintf(vis_stdout, "according to -s option: \n"); |
---|
981 | OrdNodeListWrite(vis_stdout, suppliedNodeList); |
---|
982 | } |
---|
983 | } |
---|
984 | } |
---|
985 | } |
---|
986 | |
---|
987 | |
---|
988 | /* |
---|
989 | * In order for static ordering to proceed, network must not have any |
---|
990 | * combinational cycles. |
---|
991 | */ |
---|
992 | error_init(); |
---|
993 | if(Ntk_NetworkTestIsAcyclic(network) == 0) { |
---|
994 | (void) fprintf(vis_stderr, "Combinational cycle found: "); |
---|
995 | (void) fprintf(vis_stderr, "%s\n", error_string()); |
---|
996 | (void) fprintf(vis_stderr, "cannot perform static ordering\n"); |
---|
997 | if (suppliedOrderType != Ord_Unassigned_c) { |
---|
998 | (void) lsDestroy(suppliedNodeList, (void (*) (lsGeneric)) NULL); |
---|
999 | } |
---|
1000 | return 1; |
---|
1001 | } |
---|
1002 | |
---|
1003 | /* Start the timer before calling the variable ordering routine. */ |
---|
1004 | if (timeOutPeriod > 0){ |
---|
1005 | (void) signal(SIGALRM, (void(*)(int))TimeOutHandle); |
---|
1006 | (void) alarm(timeOutPeriod); |
---|
1007 | if (setjmp(timeOutEnv) > 0) { |
---|
1008 | (void) fprintf(vis_stderr, "Timeout occurred after %d seconds.\n", timeOutPeriod); |
---|
1009 | alarm(0); |
---|
1010 | return 1; |
---|
1011 | } |
---|
1012 | } |
---|
1013 | |
---|
1014 | /* |
---|
1015 | * Order the variables. |
---|
1016 | */ |
---|
1017 | Ord_NetworkOrderVariables(network, rootMethod, nodeMethod, nsAfterSupport, |
---|
1018 | generatedOrderType, suppliedOrderType, |
---|
1019 | suppliedNodeList, verbose); |
---|
1020 | |
---|
1021 | if (suppliedOrderType != Ord_Unassigned_c) { |
---|
1022 | (void) lsDestroy(suppliedNodeList, (void (*) (lsGeneric)) NULL); |
---|
1023 | } |
---|
1024 | |
---|
1025 | /* |
---|
1026 | * As a sanity check, make sure that all the variables in generatedOrderType |
---|
1027 | * have an MDD id. |
---|
1028 | */ |
---|
1029 | assert(Ord_NetworkTestAreVariablesOrdered(network, generatedOrderType)); |
---|
1030 | |
---|
1031 | alarm(0); |
---|
1032 | return 0; /* Everything okay */ |
---|
1033 | |
---|
1034 | usage: |
---|
1035 | (void) fprintf(vis_stderr, "usage: static_order [-a] [-h] [-n method] [-o type] [-r method] -s type [-t time] [-v #] file\n"); |
---|
1036 | (void) fprintf(vis_stderr, " -a order NS variables after support\n"); |
---|
1037 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
1038 | (void) fprintf(vis_stderr, " -n method node ordering method\n"); |
---|
1039 | (void) fprintf(vis_stderr, " (interleave (default), append, merge_left, merge_right)\n"); |
---|
1040 | (void) fprintf(vis_stderr, " -o type nodes to order (all, input_and_latch (default))\n"); |
---|
1041 | (void) fprintf(vis_stderr, " -r method root ordering method (depth, mincomm (default for < 30 latches))\n"); |
---|
1042 | (void) fprintf(vis_stderr, " -s type nodes in file (all, input_and_latch, next_state_node, partial)\n"); |
---|
1043 | (void) fprintf(vis_stderr, " -t time time out period (in seconds)\n"); |
---|
1044 | (void) fprintf(vis_stderr, " -v # verbosity level\n"); |
---|
1045 | (void) fprintf(vis_stderr, " file supplied ordering of nodes\n"); |
---|
1046 | |
---|
1047 | return 1; |
---|
1048 | |
---|
1049 | } |
---|
1050 | |
---|
1051 | |
---|
1052 | /**Function******************************************************************** |
---|
1053 | |
---|
1054 | Synopsis [] |
---|
1055 | |
---|
1056 | Description [Refer to 'static int CommandBuildPartitionMdds(Hrc_Manager_t ** |
---|
1057 | hmgr, int argc, char ** argv);' in partCmd.c] |
---|
1058 | |
---|
1059 | SideEffects [] |
---|
1060 | |
---|
1061 | SeeAlso [] |
---|
1062 | |
---|
1063 | ******************************************************************************/ |
---|
1064 | static int build_partition_mddsMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
1065 | { |
---|
1066 | |
---|
1067 | (void) fprintf(vis_stderr, "*** 'build_partition_mdds' begins. *** \n"); |
---|
1068 | |
---|
1069 | static Part_PartitionMethod method; |
---|
1070 | static boolean inTermsOfLeaves; |
---|
1071 | lsList nodeList = lsCreate(); |
---|
1072 | graph_t *partition; |
---|
1073 | static int verbose; |
---|
1074 | static int sanityCheck; |
---|
1075 | static int timeOutPeriod; |
---|
1076 | int c; |
---|
1077 | int length; |
---|
1078 | char *methodString; |
---|
1079 | char *modelName; |
---|
1080 | Hrc_Node_t *currentNode; |
---|
1081 | Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
1082 | char *nodeName; |
---|
1083 | char *tmpNodeName; |
---|
1084 | char *realName; |
---|
1085 | FILE *nodeFile; |
---|
1086 | static boolean fileUsed; |
---|
1087 | |
---|
1088 | fileUsed = FALSE; |
---|
1089 | inTermsOfLeaves = FALSE; |
---|
1090 | verbose = 0; |
---|
1091 | sanityCheck = 0; |
---|
1092 | timeOutPeriod = 0; |
---|
1093 | |
---|
1094 | nodeFile = NIL(FILE); |
---|
1095 | util_getopt_reset(); |
---|
1096 | while ((c = util_getopt(argc, argv, "f:hvin:s:t:")) != EOF) { |
---|
1097 | switch(c) { |
---|
1098 | case 'f': |
---|
1099 | fileUsed = TRUE; |
---|
1100 | nodeFile = Cmd_FileOpen(util_optarg, "r", &realName, 1); |
---|
1101 | FREE(realName); |
---|
1102 | if (nodeFile == NIL(FILE)){ |
---|
1103 | (void)fprintf(vis_stderr,"Cannot open %s\n", util_optarg); |
---|
1104 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
1105 | return 1; |
---|
1106 | } |
---|
1107 | else{ |
---|
1108 | tmpNodeName = ALLOC(char, 512); |
---|
1109 | while(fscanf(nodeFile, "%s\n", tmpNodeName) != EOF){ |
---|
1110 | if(*tmpNodeName != '#'){ |
---|
1111 | nodeName = ALLOC(char, strlen(tmpNodeName) + 2); |
---|
1112 | sprintf(nodeName, "%s", tmpNodeName); |
---|
1113 | lsNewEnd(nodeList, (lsGeneric)nodeName, NIL(lsHandle)); |
---|
1114 | } |
---|
1115 | } |
---|
1116 | FREE(tmpNodeName); |
---|
1117 | } |
---|
1118 | break; |
---|
1119 | case 'h': |
---|
1120 | goto usage; |
---|
1121 | case 'i': |
---|
1122 | inTermsOfLeaves = TRUE; |
---|
1123 | break; |
---|
1124 | case 'v': |
---|
1125 | verbose = 1; |
---|
1126 | break; |
---|
1127 | case 's': |
---|
1128 | sanityCheck = atoi(util_optarg); |
---|
1129 | break; |
---|
1130 | case 't': |
---|
1131 | timeOutPeriod = atoi(util_optarg); |
---|
1132 | break; |
---|
1133 | case 'n': |
---|
1134 | length = strlen(util_optarg); |
---|
1135 | for(c = 0; c < length; c++) { |
---|
1136 | if (util_optarg[c] == ',') { |
---|
1137 | util_optarg[c] = 0; |
---|
1138 | } /* End of if */ |
---|
1139 | } /* End of for */ |
---|
1140 | c = 0; |
---|
1141 | while (c < length) { |
---|
1142 | lsNewEnd(nodeList, &util_optarg[c], NIL(lsHandle)); |
---|
1143 | while (util_optarg[c++] != 0); |
---|
1144 | } /* End of while */ |
---|
1145 | break; |
---|
1146 | default: |
---|
1147 | goto usage; |
---|
1148 | } |
---|
1149 | } |
---|
1150 | |
---|
1151 | if (argc == util_optind) { |
---|
1152 | /* No method specified. Choosing default */ |
---|
1153 | methodString = Cmd_FlagReadByName("partition_method"); |
---|
1154 | if (methodString == NIL(char)) { |
---|
1155 | methodString = "default"; |
---|
1156 | } |
---|
1157 | } |
---|
1158 | else { |
---|
1159 | methodString = argv[util_optind]; |
---|
1160 | } |
---|
1161 | |
---|
1162 | if (strcmp(methodString,"inout") == 0) { |
---|
1163 | method = Part_InOut_c; |
---|
1164 | if (lsLength(nodeList) != 0) { |
---|
1165 | (void) fprintf(vis_stderr, "Ignoring provided list of nodes in <inout>"); |
---|
1166 | (void) fprintf(vis_stderr, " method\n"); |
---|
1167 | } /* End of if */ |
---|
1168 | if (inTermsOfLeaves) { |
---|
1169 | (void) fprintf(vis_stderr, "Ignoring -i flag in the <inout> method\n"); |
---|
1170 | } /* End of if */ |
---|
1171 | } |
---|
1172 | else if (strcmp(methodString,"partial") == 0) { |
---|
1173 | method = Part_Partial_c; |
---|
1174 | /* Make sure a list of nodes has been provided */ |
---|
1175 | if (lsLength(nodeList) == 0) { |
---|
1176 | (void) fprintf(vis_stderr, "Method <partial> requires a non-empty list"); |
---|
1177 | (void) fprintf(vis_stderr, " of nodes\n"); |
---|
1178 | |
---|
1179 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
1180 | goto usage; |
---|
1181 | } /* End of if */ |
---|
1182 | } |
---|
1183 | else if (strcmp(methodString,"total") == 0) { |
---|
1184 | method = Part_Total_c; |
---|
1185 | if (lsLength(nodeList) != 0) { |
---|
1186 | (void) fprintf(vis_stderr, "Ignoring provided list of nodes in <total>"); |
---|
1187 | (void) fprintf(vis_stderr, " method\n"); |
---|
1188 | } /* End of if */ |
---|
1189 | } |
---|
1190 | else if (strcmp(methodString,"frontier") == 0) { |
---|
1191 | method = Part_Frontier_c; |
---|
1192 | } |
---|
1193 | else if (strcmp(methodString,"boundary") == 0) { |
---|
1194 | method = Part_Boundary_c; |
---|
1195 | } |
---|
1196 | else if (strcmp(methodString, "fine") == 0) { |
---|
1197 | method = Part_Fine_c; |
---|
1198 | } |
---|
1199 | else if (strcmp(methodString, "default") == 0) { |
---|
1200 | method = Part_Default_c; |
---|
1201 | } |
---|
1202 | else { |
---|
1203 | goto usage; |
---|
1204 | } |
---|
1205 | |
---|
1206 | |
---|
1207 | /* Check if the network has been read in */ |
---|
1208 | if (network == NIL(Ntk_Network_t)) { |
---|
1209 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
1210 | return 1; |
---|
1211 | } |
---|
1212 | |
---|
1213 | /* Check if the network has the variables ordered */ |
---|
1214 | if (Ord_NetworkTestAreVariablesOrdered(network, Ord_InputAndLatch_c) == |
---|
1215 | FALSE) { |
---|
1216 | (void) fprintf(vis_stdout, "The MDD variables have not been ordered. Use static_order.\n"); |
---|
1217 | |
---|
1218 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
1219 | return 1; |
---|
1220 | } |
---|
1221 | |
---|
1222 | /* Check if there is already a partition attached to the network */ |
---|
1223 | partition = (graph_t *) Ntk_NetworkReadApplInfo(network, |
---|
1224 | PART_NETWORK_APPL_KEY); |
---|
1225 | |
---|
1226 | /* If there is, just return. */ |
---|
1227 | if (partition != NIL(graph_t)) { |
---|
1228 | (void) fprintf(vis_stderr, "partition already built; reinvoke "); |
---|
1229 | (void) fprintf(vis_stderr, "flatten_hierarchy to remove the current partition\n"); |
---|
1230 | return 1; |
---|
1231 | } |
---|
1232 | |
---|
1233 | /* Read the name of the model to be passed to Part_NetworkCreatePartition */ |
---|
1234 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
1235 | modelName = Hrc_NodeReadModelName(currentNode); |
---|
1236 | |
---|
1237 | /* Set the timeout */ |
---|
1238 | if (timeOutPeriod > 0) { |
---|
1239 | (void) signal(SIGALRM, (void(*)(int))TimeOutHandle); |
---|
1240 | (void) alarm(timeOutPeriod); |
---|
1241 | if (setjmp(timeOutEnv) > 0) { |
---|
1242 | (void) fprintf(vis_stdout, "Partition: timeout occurred after "); |
---|
1243 | (void) fprintf(vis_stdout, "%d seconds\n", timeOutPeriod); |
---|
1244 | alarm(0); |
---|
1245 | |
---|
1246 | /* Partial clean up */ |
---|
1247 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
1248 | return 1; |
---|
1249 | } |
---|
1250 | } |
---|
1251 | |
---|
1252 | /* |
---|
1253 | * Execute the partition algorithm. The two nil pointers is to indicate |
---|
1254 | * that the graph must represent the complete network. |
---|
1255 | */ |
---|
1256 | partition = Part_NetworkCreatePartition(network, currentNode, modelName, (lsList)0, |
---|
1257 | (lsList)0, NIL(mdd_t), method, nodeList, |
---|
1258 | inTermsOfLeaves, verbose, |
---|
1259 | sanityCheck); |
---|
1260 | |
---|
1261 | /* Register the partition in the network if any */ |
---|
1262 | Ntk_NetworkAddApplInfo(network, PART_NETWORK_APPL_KEY, |
---|
1263 | (Ntk_ApplInfoFreeFn) Part_PartitionFreeCallback, |
---|
1264 | (void *) partition); |
---|
1265 | |
---|
1266 | /* Deactivate the alarm */ |
---|
1267 | alarm(0); |
---|
1268 | |
---|
1269 | /* Clean up */ |
---|
1270 | if(fileUsed){ |
---|
1271 | lsDestroy(nodeList, PartNameFree); |
---|
1272 | } |
---|
1273 | else{ |
---|
1274 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
1275 | } |
---|
1276 | return 0; |
---|
1277 | |
---|
1278 | usage: |
---|
1279 | (void) fprintf(vis_stderr, "usage: build_partition_mdds [options] [method]\n"); |
---|
1280 | (void) fprintf(vis_stderr, "Options:\n"); |
---|
1281 | (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); |
---|
1282 | (void) fprintf(vis_stderr, " -i\t\tBuild the functions in the partition in terms of the\n"); |
---|
1283 | (void) fprintf(vis_stderr, " \t\tcombinational inputs of the system. This option is redundant if\n"); |
---|
1284 | (void) fprintf(vis_stderr, " \t\tthe inout partition is chosen.\n"); |
---|
1285 | (void) fprintf(vis_stderr, " -n <list>\tComma separated list of network nodes to preserve in the\n"); |
---|
1286 | (void) fprintf(vis_stderr, " \tpartitioning. It only matters if the partial method has been\n"); |
---|
1287 | (void) fprintf(vis_stderr, " \tselected.\n"); |
---|
1288 | (void) fprintf(vis_stderr, " -f <file>\tSpecifies the file containing names of network nodes\n"); |
---|
1289 | (void) fprintf(vis_stderr, " \tto preserve while partitioning. This option matters only \n"); |
---|
1290 | (void) fprintf(vis_stderr, " \tif the partial method has been selected. Each node name must\n"); |
---|
1291 | (void) fprintf(vis_stderr, " \tbe listed on a new line. Comments in <file> must begin with '#'.\n"); |
---|
1292 | (void) fprintf(vis_stderr, " -s <num>\tLevel of severity check applied after computation. 0 being no\n"); |
---|
1293 | (void) fprintf(vis_stderr, " \t\tcheck, 1 begin simple check and >1 being exhaustive check.\n"); |
---|
1294 | (void) fprintf(vis_stderr, " -t <sec>\tTime in seconds allowed to build the partition. If the\n"); |
---|
1295 | (void) fprintf(vis_stderr, " \tcomputation time goes above that limit, the process of building\n"); |
---|
1296 | (void) fprintf(vis_stderr, " \tthe partition is aborted.\n"); |
---|
1297 | (void) fprintf(vis_stderr, " -v\t\tverbose\n"); |
---|
1298 | (void) fprintf(vis_stderr, "Methods\n"); |
---|
1299 | (void) fprintf(vis_stderr, " inout\tIt represents the network with one MDD for\n"); |
---|
1300 | (void) fprintf(vis_stderr, " \teach combinational output as a function of the combinational\n"); |
---|
1301 | (void) fprintf(vis_stderr, " \tinputs\n"); |
---|
1302 | (void) fprintf(vis_stderr, " total\tPartitions the network preserving its structure. Every node in\n"); |
---|
1303 | (void) fprintf(vis_stderr, " \tthe network will produce a vertex in the partition graph. The\n"); |
---|
1304 | (void) fprintf(vis_stderr, " \tflag -i explained above controls the support of\n"); |
---|
1305 | (void) fprintf(vis_stderr, " \tthe functions attached to the vertices.\n"); |
---|
1306 | (void) fprintf(vis_stderr, " frontier\tThe default method. Partitions the network creating vertices for intermediate nodes\n"); |
---|
1307 | (void) fprintf(vis_stderr, " \tas necessary to control the BDD size. The threshold value of the\n"); |
---|
1308 | (void) fprintf(vis_stderr, " \tBDD can be specified by partition_threshold.\n"); |
---|
1309 | (void) fprintf(vis_stderr, " partial\tPartitions the network preserving certain nodes specified with\n"); |
---|
1310 | (void) fprintf(vis_stderr, " \tthe option -n or -f.\n"); |
---|
1311 | (void) fprintf(vis_stderr, " boundary\tPartitions the network preserving all nodes that are \n"); |
---|
1312 | (void) fprintf(vis_stderr, " \tsubcircuit IOs.\n"); |
---|
1313 | |
---|
1314 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
1315 | |
---|
1316 | return 1; /* Error exit */ |
---|
1317 | } /* End of CommandBuildPartitionMdds */ |
---|
1318 | |
---|
1319 | |
---|
1320 | /**Function******************************************************************** |
---|
1321 | |
---|
1322 | Synopsis [] |
---|
1323 | |
---|
1324 | Description [Refer to 'static int CommandBuildPartitionMAigs(Hrc_Manager_t |
---|
1325 | ** hmgr, int argc, char ** argv);' in ntmaigCmd.c] |
---|
1326 | |
---|
1327 | SideEffects [] |
---|
1328 | |
---|
1329 | SeeAlso [] |
---|
1330 | |
---|
1331 | ******************************************************************************/ |
---|
1332 | static int build_partition_maigsMine(Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
1333 | { |
---|
1334 | |
---|
1335 | (void) fprintf(vis_stderr, "*** 'build_partition_maigs' begins. *** \n"); |
---|
1336 | |
---|
1337 | Ntk_Node_t *node, *latch; |
---|
1338 | lsGen gen; |
---|
1339 | array_t *result; /* array of MvfAig_Function_t* */ |
---|
1340 | array_t *roots; |
---|
1341 | st_table *leaves; |
---|
1342 | array_t *inputs; |
---|
1343 | Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
1344 | mAig_Manager_t *manager; |
---|
1345 | MvfAig_Function_t *mvfAig; |
---|
1346 | st_table *nodeToMvfAigTable; /* mapes each node with its mvfAig */ |
---|
1347 | int c, sweepFlag, DFSFlag; |
---|
1348 | int i; |
---|
1349 | |
---|
1350 | sweepFlag = 1; |
---|
1351 | DFSFlag = 0; |
---|
1352 | util_getopt_reset(); |
---|
1353 | while ((c = util_getopt(argc,argv,"sdnh")) != EOF){ |
---|
1354 | switch(c){ |
---|
1355 | case 's': |
---|
1356 | sweepFlag = 1; |
---|
1357 | break; |
---|
1358 | case 'd': |
---|
1359 | DFSFlag = 1; |
---|
1360 | break; |
---|
1361 | case 'n': |
---|
1362 | sweepFlag = 0; |
---|
1363 | break; |
---|
1364 | case 'h': |
---|
1365 | goto usage; |
---|
1366 | default: |
---|
1367 | goto usage; |
---|
1368 | } |
---|
1369 | } |
---|
1370 | if (network == NIL(Ntk_Network_t)) { |
---|
1371 | return 1; |
---|
1372 | } |
---|
1373 | |
---|
1374 | manager = Ntk_NetworkReadMAigManager(network); |
---|
1375 | |
---|
1376 | if (manager == NIL(mAig_Manager_t)) { |
---|
1377 | manager = mAig_initAig(); |
---|
1378 | Ntk_NetworkSetMAigManager(network, manager); |
---|
1379 | /* |
---|
1380 | mAig_mAigSetNetwork(manager, network); |
---|
1381 | */ |
---|
1382 | } |
---|
1383 | |
---|
1384 | /* Check if there is already a MvfAigs Table attached to the network */ |
---|
1385 | nodeToMvfAigTable = (st_table *) Ntk_NetworkReadApplInfo(network, |
---|
1386 | MVFAIG_NETWORK_APPL_KEY); |
---|
1387 | |
---|
1388 | if (nodeToMvfAigTable != NIL(st_table)){ |
---|
1389 | /* |
---|
1390 | st_foreach_item(nodeToMvfAigTable, stGen, (char **) &node, (char **) &MvfAig) { |
---|
1391 | printf("\nNode name = %s :",Ntk_NodeReadName(node)); |
---|
1392 | for (j=0; j< array_n(MvfAig); j++){ |
---|
1393 | printf(" %d ",array_fetch(bAigEdge_t, (array_t *) MvfAig, j)); |
---|
1394 | } |
---|
1395 | } |
---|
1396 | */ |
---|
1397 | (void) fprintf(vis_stderr, "maig partition already built; reinvoke\n"); |
---|
1398 | (void) fprintf(vis_stderr, "flatten_hierarchy to remove the current maig partition\n"); |
---|
1399 | return 1; |
---|
1400 | } |
---|
1401 | |
---|
1402 | roots = array_alloc(Ntk_Node_t *, 0); |
---|
1403 | Ntk_NetworkForEachCombOutput(network, gen, node) { |
---|
1404 | array_insert_last(Ntk_Node_t *, roots, node); |
---|
1405 | } |
---|
1406 | Ntk_NetworkForEachNode(network, gen, node) { |
---|
1407 | if(Ntk_NodeTestIsShadow(node)) continue; |
---|
1408 | if(Ntk_NodeTestIsCombInput(node)) continue; |
---|
1409 | if(Ntk_NodeTestIsCombOutput(node))continue; |
---|
1410 | |
---|
1411 | if(Ntk_NodeReadNumFanouts(node) == 0 && Ntk_NodeReadNumFanins(node)) { |
---|
1412 | /** |
---|
1413 | fprintf(vis_stdout, "WARNING : dangling node %s\n", Ntk_NodeReadName(node)); |
---|
1414 | **/ |
---|
1415 | array_insert_last(Ntk_Node_t *, roots, node); |
---|
1416 | } |
---|
1417 | } |
---|
1418 | |
---|
1419 | leaves = st_init_table(st_ptrcmp, st_ptrhash); |
---|
1420 | |
---|
1421 | inputs = array_alloc(Ntk_Node_t *, 16); |
---|
1422 | Ntk_NetworkForEachCombInput(network, gen, node) { |
---|
1423 | array_insert_last(Ntk_Node_t *, inputs, node); |
---|
1424 | } |
---|
1425 | array_sort(inputs, nodenameCompare); |
---|
1426 | for(i=0; i<array_n(inputs); i++) { |
---|
1427 | node = array_fetch(Ntk_Node_t *, inputs, i); |
---|
1428 | st_insert(leaves, node, (char *) ntmaig_UNUSED); |
---|
1429 | Ntk_NodeSetMAigId(node, |
---|
1430 | mAig_CreateVar(manager, |
---|
1431 | Ntk_NodeReadName(node), |
---|
1432 | Var_VariableReadNumValues(Ntk_NodeReadVariable(node)))); |
---|
1433 | } |
---|
1434 | |
---|
1435 | if(DFSFlag == 0) |
---|
1436 | bAig_BuildAigBFSManner(network, manager, leaves, sweepFlag); |
---|
1437 | |
---|
1438 | result = ntmaig_NetworkBuildMvfAigs(network, roots, leaves); |
---|
1439 | |
---|
1440 | nodeToMvfAigTable = (st_table *) Ntk_NetworkReadApplInfo(network, |
---|
1441 | MVFAIG_NETWORK_APPL_KEY); |
---|
1442 | Ntk_NetworkForEachLatch(network, gen, latch) { |
---|
1443 | node = Ntk_LatchReadDataInput(latch); |
---|
1444 | st_lookup(nodeToMvfAigTable, node, &mvfAig); |
---|
1445 | Ntk_NodeSetMAigId(node, |
---|
1446 | mAig_CreateVarFromAig(manager, Ntk_NodeReadName(node), mvfAig)); |
---|
1447 | node = Ntk_LatchReadInitialInput(latch); |
---|
1448 | st_lookup(nodeToMvfAigTable, node, &mvfAig); |
---|
1449 | Ntk_NodeSetMAigId(node, |
---|
1450 | mAig_CreateVarFromAig(manager, Ntk_NodeReadName(node), mvfAig)); |
---|
1451 | } |
---|
1452 | |
---|
1453 | roots->num = 0; |
---|
1454 | Ntk_NetworkForEachLatch(network, gen, latch) { |
---|
1455 | if(!st_lookup(nodeToMvfAigTable, latch, &mvfAig)) |
---|
1456 | array_insert_last(Ntk_Node_t *, roots, latch); |
---|
1457 | } |
---|
1458 | result = ntmaig_NetworkBuildMvfAigs(network, roots, leaves); |
---|
1459 | |
---|
1460 | array_free(roots); |
---|
1461 | array_free(inputs); |
---|
1462 | st_free_table(leaves); |
---|
1463 | |
---|
1464 | /* |
---|
1465 | * Free the array of MvfAigs. |
---|
1466 | */ |
---|
1467 | MvfAig_FunctionArrayFree(result); |
---|
1468 | |
---|
1469 | if(sweepFlag) |
---|
1470 | bAig_BddSweepMain(network, 0); |
---|
1471 | |
---|
1472 | return 0; |
---|
1473 | |
---|
1474 | usage: |
---|
1475 | (void) fprintf(vis_stderr, "usage: build_partition_maig [-h]\n"); |
---|
1476 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
1477 | (void) fprintf(vis_stderr, " -n disable bdd sweeping\n"); |
---|
1478 | (void) fprintf(vis_stderr, " -d build AIG DFS manner\n"); |
---|
1479 | return 1; /* error exit */ |
---|
1480 | |
---|
1481 | } |
---|
1482 | |
---|
1483 | /**Function******************************************************************** |
---|
1484 | |
---|
1485 | Synopsis [] |
---|
1486 | |
---|
1487 | Description [Refer to 'static int CommandReadFairness(Hrc_Manager_t ** hmgr, |
---|
1488 | int argc, char ** argv)' in fsmCmd.c] |
---|
1489 | |
---|
1490 | SideEffects [] |
---|
1491 | |
---|
1492 | SeeAlso [] |
---|
1493 | |
---|
1494 | ******************************************************************************/ |
---|
1495 | |
---|
1496 | static int read_fairnessMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
1497 | { |
---|
1498 | |
---|
1499 | (void) fprintf(vis_stderr, "*** 'read_fairness' begins. *** \n"); |
---|
1500 | |
---|
1501 | int c; |
---|
1502 | FILE *fp; |
---|
1503 | array_t *formulaArray; |
---|
1504 | Fsm_Fsm_t *fsm = Fsm_HrcManagerReadCurrentFsm(*hmgr); |
---|
1505 | |
---|
1506 | /* |
---|
1507 | * Parse command line options. |
---|
1508 | */ |
---|
1509 | util_getopt_reset(); |
---|
1510 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
1511 | switch(c) { |
---|
1512 | case 'h': |
---|
1513 | goto usage; |
---|
1514 | default: |
---|
1515 | goto usage; |
---|
1516 | } |
---|
1517 | /* NOT REACHED */ |
---|
1518 | } |
---|
1519 | |
---|
1520 | if (fsm == NIL(Fsm_Fsm_t)) { |
---|
1521 | (void) fprintf(vis_stderr, "** fair error: Fairness constraint not recorded.\n"); |
---|
1522 | return 1; |
---|
1523 | } |
---|
1524 | |
---|
1525 | /* |
---|
1526 | * Open the fairness file. |
---|
1527 | */ |
---|
1528 | if (argc - util_optind == 0) { |
---|
1529 | (void) fprintf(vis_stderr, "** fair error: fairness file not provided\n"); |
---|
1530 | goto usage; |
---|
1531 | } |
---|
1532 | else if (argc - util_optind > 1) { |
---|
1533 | (void) fprintf(vis_stderr, "** fair error: too many arguments\n"); |
---|
1534 | goto usage; |
---|
1535 | } |
---|
1536 | |
---|
1537 | fp = Cmd_FileOpen(argv[util_optind], "r", NIL(char *), 0); |
---|
1538 | if (fp == NIL(FILE)) { |
---|
1539 | return 1; |
---|
1540 | } |
---|
1541 | |
---|
1542 | /* |
---|
1543 | * Parse the formulas in the file. |
---|
1544 | */ |
---|
1545 | formulaArray = Ctlp_FileParseFormulaArray(fp); |
---|
1546 | (void) fclose(fp); |
---|
1547 | |
---|
1548 | if (formulaArray == NIL(array_t)) { |
---|
1549 | (void) fprintf(vis_stderr, "** fair error: error reading fairness conditions.\n"); |
---|
1550 | return 1; |
---|
1551 | } |
---|
1552 | else if (array_n(formulaArray) == 0) { |
---|
1553 | (void) fprintf(vis_stderr, "** fair error: fairness file is empty.\n"); |
---|
1554 | (void) fprintf(vis_stderr, "** fair error: Use reset_fairness to reset the fairness constraint."); |
---|
1555 | return 1; |
---|
1556 | } |
---|
1557 | else { |
---|
1558 | int j; |
---|
1559 | Fsm_Fairness_t *fairness; |
---|
1560 | Ntk_Network_t *network = Fsm_FsmReadNetwork(fsm); |
---|
1561 | |
---|
1562 | /* |
---|
1563 | * First check that each formula is semantically correct wrt the network. |
---|
1564 | */ |
---|
1565 | error_init(); |
---|
1566 | for (j = 0; j < array_n(formulaArray); j++) { |
---|
1567 | Ctlp_Formula_t *formula; |
---|
1568 | boolean status; |
---|
1569 | |
---|
1570 | formula = array_fetch(Ctlp_Formula_t *, formulaArray, j); |
---|
1571 | status = Mc_FormulaStaticSemanticCheckOnNetwork(formula, network, FALSE); |
---|
1572 | |
---|
1573 | if (status == FALSE) { |
---|
1574 | (void) fprintf(vis_stderr, |
---|
1575 | "** fair error: error reading fairness constraint "); |
---|
1576 | Ctlp_FormulaPrint(vis_stderr, formula); |
---|
1577 | (void) fprintf(vis_stderr, ":\n"); |
---|
1578 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
1579 | (void) fprintf(vis_stderr, "\n"); |
---|
1580 | return 1; |
---|
1581 | } |
---|
1582 | } |
---|
1583 | |
---|
1584 | |
---|
1585 | /* |
---|
1586 | * Interpret the array of CTL formulas as a set of Buchi conditions. |
---|
1587 | * Hence, create a single disjunct, consisting of k conjuncts, where k is |
---|
1588 | * the number of CTL formulas read in. The jth conjunct has the jth |
---|
1589 | * formula as its finallyInf component, and NULL as its globallyInf |
---|
1590 | * component. |
---|
1591 | */ |
---|
1592 | fairness = FsmFairnessAlloc(fsm); |
---|
1593 | for (j = 0; j < array_n(formulaArray); j++) { |
---|
1594 | Ctlp_Formula_t *formula = array_fetch(Ctlp_Formula_t *, formulaArray, j); |
---|
1595 | |
---|
1596 | FsmFairnessAddConjunct(fairness, formula, NIL(Ctlp_Formula_t), 0, j); |
---|
1597 | } |
---|
1598 | array_free(formulaArray); /* Don't free the formulas themselves. */ |
---|
1599 | |
---|
1600 | /* |
---|
1601 | * Remove any existing fairnessInfo associated with the FSM, and update |
---|
1602 | * the fairnessInfo.constraint with the new fairness just read. |
---|
1603 | */ |
---|
1604 | FsmFsmFairnessInfoUpdate(fsm, NIL(mdd_t), fairness, NIL(array_t)); |
---|
1605 | |
---|
1606 | return 0; |
---|
1607 | } |
---|
1608 | |
---|
1609 | usage: |
---|
1610 | (void) fprintf(vis_stderr, "usage: read_fairness [-h] file\n"); |
---|
1611 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
1612 | (void) fprintf(vis_stderr, " file file containing the list of conditions\n"); |
---|
1613 | return 1; |
---|
1614 | |
---|
1615 | } |
---|
1616 | |
---|
1617 | /**Function******************************************************************** |
---|
1618 | |
---|
1619 | Synopsis [] |
---|
1620 | |
---|
1621 | Description [Refer to 'static int CommandPrintFairness(Hrc_Manager_t ** hmgr, |
---|
1622 | int argc, char ** argv)' in fsmCmd.c] |
---|
1623 | |
---|
1624 | SideEffects [] |
---|
1625 | |
---|
1626 | SeeAlso [] |
---|
1627 | |
---|
1628 | ******************************************************************************/ |
---|
1629 | |
---|
1630 | static int print_fairnessMine(Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
1631 | { |
---|
1632 | |
---|
1633 | (void) fprintf(vis_stderr, "*** 'print_fairness' begins. *** \n"); |
---|
1634 | |
---|
1635 | int c; |
---|
1636 | Fsm_Fairness_t *constraint; |
---|
1637 | int numDisjuncts; |
---|
1638 | Fsm_Fsm_t *fsm = Fsm_HrcManagerReadCurrentFsm(*hmgr); |
---|
1639 | |
---|
1640 | /* |
---|
1641 | * Parse command line options. |
---|
1642 | */ |
---|
1643 | util_getopt_reset(); |
---|
1644 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
1645 | switch(c) { |
---|
1646 | case 'h': |
---|
1647 | goto usage; |
---|
1648 | default: |
---|
1649 | goto usage; |
---|
1650 | } |
---|
1651 | /* NOT REACHED */ |
---|
1652 | } |
---|
1653 | |
---|
1654 | if (fsm == NIL(Fsm_Fsm_t)) { |
---|
1655 | return 1; |
---|
1656 | } |
---|
1657 | |
---|
1658 | /* |
---|
1659 | * Print the fairness constraint. It is assumed that there is at least one |
---|
1660 | * disjunct present. Currently, only Buchi constraints can be printed out. |
---|
1661 | */ |
---|
1662 | constraint = Fsm_FsmReadFairnessConstraint(fsm); |
---|
1663 | assert(constraint != NIL(Fsm_Fairness_t)); |
---|
1664 | numDisjuncts = Fsm_FairnessReadNumDisjuncts(constraint); |
---|
1665 | assert(numDisjuncts != 0); |
---|
1666 | |
---|
1667 | if (numDisjuncts > 1) { |
---|
1668 | (void) fprintf(vis_stdout, "Fairness constraint not Buchi..."); |
---|
1669 | (void) fprintf(vis_stdout, "don't know how to print.\n"); |
---|
1670 | } |
---|
1671 | else { |
---|
1672 | int i; |
---|
1673 | int numConjuncts = Fsm_FairnessReadNumConjunctsOfDisjunct(constraint, 0); |
---|
1674 | |
---|
1675 | (void) fprintf(vis_stdout, "Fairness constraint:\n"); |
---|
1676 | for (i = 0; i < numConjuncts; i++) { |
---|
1677 | if (Fsm_FairnessReadGloballyInfFormula(constraint, 0, i) != |
---|
1678 | NIL(Ctlp_Formula_t)) { |
---|
1679 | (void) fprintf(vis_stdout, "Fairness constraint not Buchi..."); |
---|
1680 | (void) fprintf(vis_stdout, "don't know how to print.\n"); |
---|
1681 | } |
---|
1682 | |
---|
1683 | Ctlp_FormulaPrint(vis_stdout, |
---|
1684 | Fsm_FairnessReadFinallyInfFormula(constraint, 0, i)); |
---|
1685 | (void) fprintf(vis_stdout, ";\n"); |
---|
1686 | } |
---|
1687 | } |
---|
1688 | |
---|
1689 | return 0; |
---|
1690 | |
---|
1691 | usage: |
---|
1692 | (void) fprintf(vis_stderr, "usage: print_fairness [-h]\n"); |
---|
1693 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
1694 | return 1; |
---|
1695 | |
---|
1696 | } |
---|
1697 | |
---|
1698 | |
---|
1699 | /**Function******************************************************************** |
---|
1700 | |
---|
1701 | Synopsis [] |
---|
1702 | |
---|
1703 | Description [Refer to 'static int CommandPrintIo(Hrc_Manager_t **hmgr, int |
---|
1704 | argc, char **argv);' in hrcCmd.c] |
---|
1705 | |
---|
1706 | SideEffects [] |
---|
1707 | |
---|
1708 | SeeAlso [] |
---|
1709 | |
---|
1710 | ******************************************************************************/ |
---|
1711 | |
---|
1712 | static int print_ioMine (Hrc_Manager_t **hmgr, int argc, char **argv) |
---|
1713 | { |
---|
1714 | |
---|
1715 | (void) fprintf(vis_stderr, "*** 'print_io' begins. *** \n"); |
---|
1716 | |
---|
1717 | int c, i; |
---|
1718 | Hrc_Node_t *node; |
---|
1719 | Var_Variable_t *var; |
---|
1720 | array_t *tmpArray; |
---|
1721 | |
---|
1722 | util_getopt_reset(); |
---|
1723 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
1724 | switch(c){ |
---|
1725 | case 'h': |
---|
1726 | goto usage; |
---|
1727 | default: |
---|
1728 | goto usage; |
---|
1729 | } |
---|
1730 | } |
---|
1731 | /* if there are some arguments left */ |
---|
1732 | if (argc != util_optind){ |
---|
1733 | goto usage; |
---|
1734 | } |
---|
1735 | node = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
1736 | if (node == NIL(Hrc_Node_t)){ |
---|
1737 | (void)fprintf(vis_stderr,"No file has been read in.\n"); |
---|
1738 | return 1; |
---|
1739 | } |
---|
1740 | |
---|
1741 | if (Hrc_NodeReadNumFormalInputs(node) == 0){ |
---|
1742 | fprintf(vis_stdout,"No inputs\n"); |
---|
1743 | } |
---|
1744 | else { |
---|
1745 | tmpArray = array_alloc(char *,0); |
---|
1746 | Hrc_NodeForEachFormalInput(node,i,var){ |
---|
1747 | array_insert_last(char *,tmpArray,Var_VariableReadName(var)); |
---|
1748 | } |
---|
1749 | array_sort(tmpArray,_HrcStringCmp); |
---|
1750 | fprintf(vis_stdout,"inputs:"); |
---|
1751 | for (i=0; i < array_n(tmpArray); i++){ |
---|
1752 | fprintf(vis_stdout," %s",array_fetch(char *,tmpArray,i)); |
---|
1753 | } |
---|
1754 | fprintf(vis_stdout,"\n"); |
---|
1755 | array_free(tmpArray); |
---|
1756 | } |
---|
1757 | |
---|
1758 | if (Hrc_NodeReadNumFormalOutputs(node) == 0){ |
---|
1759 | fprintf(vis_stdout,"No outputs\n"); |
---|
1760 | } |
---|
1761 | else { |
---|
1762 | tmpArray = array_alloc(char *,0); |
---|
1763 | Hrc_NodeForEachFormalOutput(node,i,var){ |
---|
1764 | array_insert_last(char *,tmpArray,Var_VariableReadName(var)); |
---|
1765 | } |
---|
1766 | array_sort(tmpArray,_HrcStringCmp); |
---|
1767 | fprintf(vis_stdout,"outputs:"); |
---|
1768 | for (i=0; i < array_n(tmpArray); i++){ |
---|
1769 | fprintf(vis_stdout," %s",array_fetch(char *,tmpArray,i)); |
---|
1770 | } |
---|
1771 | fprintf(vis_stdout,"\n"); |
---|
1772 | array_free(tmpArray); |
---|
1773 | } |
---|
1774 | return 0; |
---|
1775 | |
---|
1776 | usage: |
---|
1777 | (void) fprintf(vis_stderr,"usage: print_io [-h]\n"); |
---|
1778 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
1779 | return 1; |
---|
1780 | |
---|
1781 | } |
---|
1782 | |
---|
1783 | |
---|
1784 | /**Function******************************************************************** |
---|
1785 | |
---|
1786 | Synopsis [] |
---|
1787 | |
---|
1788 | Description [Refer to 'static int CommandMc (Hrc_Manager_t **hmgr, int argc, |
---|
1789 | char **argv)' function in mcCmd.c] |
---|
1790 | |
---|
1791 | SideEffects [] |
---|
1792 | |
---|
1793 | SeeAlso [] |
---|
1794 | |
---|
1795 | ******************************************************************************/ |
---|
1796 | static int model_checkMine (Hrc_Manager_t **hmgr, int argc, char **argv) |
---|
1797 | { |
---|
1798 | |
---|
1799 | (void) fprintf(vis_stderr, "*** 'model_check' begins. *** \n"); |
---|
1800 | |
---|
1801 | /* options */ |
---|
1802 | McOptions_t *options; |
---|
1803 | Mc_VerbosityLevel verbosity; |
---|
1804 | Mc_DcLevel dcLevel; |
---|
1805 | FILE *ctlFile; |
---|
1806 | int timeOutPeriod = 0; |
---|
1807 | Mc_FwdBwdAnalysis traversalDirection; |
---|
1808 | int buildOnionRings = 0; |
---|
1809 | FILE *guideFile; |
---|
1810 | FILE *systemFile; |
---|
1811 | Mc_GuidedSearch_t guidedSearchType = Mc_None_c; |
---|
1812 | Ctlp_FormulaArray_t *hintsArray = NIL(Fsm_HintsArray_t); |
---|
1813 | array_t *hintsStatesArray = NIL(array_t); /* array of mdd_t* */ |
---|
1814 | st_table *systemVarBddIdTable; |
---|
1815 | boolean noShare = 0; |
---|
1816 | Mc_GSHScheduleType GSHschedule; |
---|
1817 | boolean checkVacuity; |
---|
1818 | boolean performCoverageHoskote; |
---|
1819 | boolean performCoverageImproved; |
---|
1820 | |
---|
1821 | /* CTL formulae */ |
---|
1822 | array_t *ctlArray; |
---|
1823 | array_t *ctlNormalFormulaArray; |
---|
1824 | int i; |
---|
1825 | int numFormulae; |
---|
1826 | /* FSM, network and image */ |
---|
1827 | Fsm_Fsm_t *totalFsm = NIL(Fsm_Fsm_t); |
---|
1828 | Fsm_Fsm_t *modelFsm = NIL(Fsm_Fsm_t); |
---|
1829 | Fsm_Fsm_t *reducedFsm = NIL(Fsm_Fsm_t); |
---|
1830 | Ntk_Network_t *network; |
---|
1831 | mdd_t *modelCareStates = NIL(mdd_t); |
---|
1832 | array_t *modelCareStatesArray = NIL(array_t); |
---|
1833 | mdd_t *modelInitialStates; |
---|
1834 | mdd_t *fairStates; |
---|
1835 | Fsm_Fairness_t *fairCond; |
---|
1836 | mdd_manager *mddMgr; |
---|
1837 | array_t *bddIdArray; |
---|
1838 | Img_ImageInfo_t *imageInfo; |
---|
1839 | Mc_EarlyTermination_t *earlyTermination; |
---|
1840 | /* Coverage estimation */ |
---|
1841 | mdd_t *totalcoveredstates = NIL(mdd_t); |
---|
1842 | array_t *signalTypeList = array_alloc(int,0); |
---|
1843 | array_t *signalList = array_alloc(char *,0); |
---|
1844 | array_t *statesCoveredList = array_alloc(mdd_t *,0); |
---|
1845 | array_t *newCoveredStatesList = array_alloc(mdd_t *,0); |
---|
1846 | array_t *statesToRemoveList = array_alloc(mdd_t *,0); |
---|
1847 | |
---|
1848 | /* Early termination is only partially implemented right now. It needs |
---|
1849 | distribution over all operators, including limited cases of temporal |
---|
1850 | operators. That should be relatively easy to implement. */ |
---|
1851 | |
---|
1852 | /* time keeping */ |
---|
1853 | long totalInitialTime; /* for model checking */ |
---|
1854 | long initialTime, finalTime; /* for model checking */ |
---|
1855 | |
---|
1856 | error_init(); |
---|
1857 | Img_ResetNumberOfImageComputation(Img_Both_c); |
---|
1858 | |
---|
1859 | /* read options */ |
---|
1860 | if (!(options = ParseMcOptions(argc, argv))) { |
---|
1861 | return 1; |
---|
1862 | } |
---|
1863 | verbosity = McOptionsReadVerbosityLevel(options); |
---|
1864 | dcLevel = McOptionsReadDcLevel(options); |
---|
1865 | ctlFile = McOptionsReadCtlFile(options); |
---|
1866 | timeOutPeriod = McOptionsReadTimeOutPeriod(options); |
---|
1867 | traversalDirection = McOptionsReadTraversalDirection(options); |
---|
1868 | buildOnionRings = |
---|
1869 | (McOptionsReadDbgLevel(options) != McDbgLevelNone_c || verbosity); |
---|
1870 | noShare = McOptionsReadUseFormulaTree(options); |
---|
1871 | GSHschedule = McOptionsReadSchedule(options); |
---|
1872 | checkVacuity = McOptionsReadVacuityDetect(options); |
---|
1873 | /* for the command mc -C foo.ctl */ |
---|
1874 | performCoverageHoskote = McOptionsReadCoverageHoskote(options); |
---|
1875 | /* for the command mc -I foo.ctl */ |
---|
1876 | performCoverageImproved = McOptionsReadCoverageImproved(options); |
---|
1877 | |
---|
1878 | /* Check for incompatible options and do some option-specific |
---|
1879 | * intializations. |
---|
1880 | */ |
---|
1881 | |
---|
1882 | if (traversalDirection == McFwd_c) { |
---|
1883 | if (checkVacuity) { |
---|
1884 | fprintf(vis_stderr, "** mc error: -V and -B are incompatible with -F\n"); |
---|
1885 | McOptionsFree(options); |
---|
1886 | return 1; |
---|
1887 | } |
---|
1888 | if (performCoverageHoskote || performCoverageImproved) { |
---|
1889 | fprintf(vis_stderr, "** mc error: -I and -C are incompatible with -F\n"); |
---|
1890 | McOptionsFree(options); |
---|
1891 | return 1; |
---|
1892 | } |
---|
1893 | } |
---|
1894 | |
---|
1895 | if (checkVacuity) { |
---|
1896 | if (performCoverageHoskote || performCoverageImproved) { |
---|
1897 | fprintf(vis_stderr, "** mc error: -I and -C are incompatible with -V and -B\n"); |
---|
1898 | McOptionsFree(options); |
---|
1899 | return 1; |
---|
1900 | } |
---|
1901 | } |
---|
1902 | |
---|
1903 | guideFile = McOptionsReadGuideFile(options); |
---|
1904 | |
---|
1905 | if(guideFile != NIL(FILE) ){ |
---|
1906 | guidedSearchType = Mc_ReadGuidedSearchType(); |
---|
1907 | if(guidedSearchType == Mc_None_c){ /* illegal setting */ |
---|
1908 | fprintf(vis_stderr, "** mc error: Unknown hint type\n"); |
---|
1909 | fclose(guideFile); |
---|
1910 | McOptionsFree(options); |
---|
1911 | return 1; |
---|
1912 | } |
---|
1913 | |
---|
1914 | if(traversalDirection == McFwd_c){ /* illegal combination */ |
---|
1915 | fprintf(vis_stderr, "** mc error: -g is incompatible with -F\n"); |
---|
1916 | fclose(guideFile); |
---|
1917 | McOptionsFree(options); |
---|
1918 | return 1; |
---|
1919 | } |
---|
1920 | |
---|
1921 | if(Img_UserSpecifiedMethod() != Img_Iwls95_c && |
---|
1922 | Img_UserSpecifiedMethod() != Img_Monolithic_c && |
---|
1923 | Img_UserSpecifiedMethod() != Img_Mlp_c){ |
---|
1924 | fprintf(vis_stderr, "** mc error: -g only works with iwls95, MLP, or monolithic image methods.\n"); |
---|
1925 | fclose(guideFile); |
---|
1926 | McOptionsFree(options); |
---|
1927 | return 1; |
---|
1928 | } |
---|
1929 | |
---|
1930 | hintsArray = Mc_ReadHints(guideFile); |
---|
1931 | fclose(guideFile); guideFile = NIL(FILE); |
---|
1932 | if( hintsArray == NIL(array_t) ){ |
---|
1933 | McOptionsFree(options); |
---|
1934 | return 1; |
---|
1935 | } |
---|
1936 | |
---|
1937 | } /* if guided search */ |
---|
1938 | |
---|
1939 | /* If don't-cares are used, -r implies -c. Note that the satisfying |
---|
1940 | sets of a subformula are only in terms of propositions therein |
---|
1941 | and their cone of influence. Hence, we can share satisfying sets |
---|
1942 | among formulae. I don't quite understand what the problem with |
---|
1943 | don't-cares is (RB) */ |
---|
1944 | if (McOptionsReadReduceFsm(options)) |
---|
1945 | if (dcLevel != McDcLevelNone_c) |
---|
1946 | McOptionsSetUseFormulaTree(options, TRUE); |
---|
1947 | |
---|
1948 | if (traversalDirection == McFwd_c && |
---|
1949 | McOptionsReadDbgLevel(options) != McDbgLevelNone_c) { |
---|
1950 | McOptionsSetDbgLevel(options, McDbgLevelNone_c); |
---|
1951 | (void)fprintf(vis_stderr, "** mc warning : option -d is ignored.\n"); |
---|
1952 | } |
---|
1953 | |
---|
1954 | /* Read CTL formulae */ |
---|
1955 | ctlArray = Ctlsp_FileParseCTLFormulaArray(ctlFile); |
---|
1956 | fclose(ctlFile); ctlFile = NIL(FILE); |
---|
1957 | if (ctlArray == NIL(array_t)) { |
---|
1958 | (void) fprintf(vis_stderr, |
---|
1959 | "** mc error: error in parsing formulas from file\n"); |
---|
1960 | McOptionsFree(options); |
---|
1961 | return 1; |
---|
1962 | } |
---|
1963 | |
---|
1964 | /* read network */ |
---|
1965 | network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
1966 | if (network == NIL(Ntk_Network_t)) { |
---|
1967 | fprintf(vis_stdout, "%s\n", error_string()); |
---|
1968 | error_init(); |
---|
1969 | Ctlp_FormulaArrayFree(ctlArray); |
---|
1970 | McOptionsFree(options); |
---|
1971 | return 1; |
---|
1972 | } |
---|
1973 | |
---|
1974 | /* read fsm */ |
---|
1975 | totalFsm = Fsm_NetworkReadOrCreateFsm(network); |
---|
1976 | if (totalFsm == NIL(Fsm_Fsm_t)) { |
---|
1977 | fprintf(vis_stdout, "%s\n", error_string()); |
---|
1978 | error_init(); |
---|
1979 | Ctlp_FormulaArrayFree(ctlArray); |
---|
1980 | McOptionsFree(options); |
---|
1981 | return 1; |
---|
1982 | } |
---|
1983 | |
---|
1984 | /* Assign variables to system if doing FAFW */ |
---|
1985 | systemVarBddIdTable = NIL(st_table); |
---|
1986 | systemFile = McOptionsReadSystemFile(options); |
---|
1987 | if (systemFile != NIL(FILE)) { |
---|
1988 | systemVarBddIdTable = Mc_ReadSystemVariablesFAFW(totalFsm, systemFile); |
---|
1989 | fclose(systemFile); systemFile = NIL(FILE); |
---|
1990 | if (systemVarBddIdTable == (st_table *)-1 ) { /* FS: error message? */ |
---|
1991 | Ctlp_FormulaArrayFree(ctlArray); |
---|
1992 | McOptionsFree(options); |
---|
1993 | return 1; |
---|
1994 | } |
---|
1995 | } /* if FAFW */ |
---|
1996 | |
---|
1997 | if(options->FAFWFlag && systemVarBddIdTable == 0) { |
---|
1998 | systemVarBddIdTable = Mc_SetAllInputToSystem(totalFsm); |
---|
1999 | } |
---|
2000 | |
---|
2001 | if (verbosity > McVerbosityNone_c) |
---|
2002 | totalInitialTime = util_cpu_time(); |
---|
2003 | else /* to remove uninitialized variable warning */ |
---|
2004 | totalInitialTime = 0; |
---|
2005 | |
---|
2006 | if(traversalDirection == McFwd_c){ |
---|
2007 | mdd_t *totalInitialStates; |
---|
2008 | double nInitialStates; |
---|
2009 | |
---|
2010 | totalInitialStates = Fsm_FsmComputeInitialStates(totalFsm); |
---|
2011 | nInitialStates = mdd_count_onset(Fsm_FsmReadMddManager(totalFsm), |
---|
2012 | totalInitialStates, |
---|
2013 | Fsm_FsmReadPresentStateVars(totalFsm)); |
---|
2014 | mdd_free(totalInitialStates); |
---|
2015 | |
---|
2016 | /* If the number of initial states is only one, we can use both |
---|
2017 | * conversion formulas(init ^ f != FALSE and init ^ !f == FALSE), |
---|
2018 | * however, if we have multiple initial states, we should use |
---|
2019 | * p0 ^ !f == FALSE. |
---|
2020 | */ |
---|
2021 | ctlNormalFormulaArray = |
---|
2022 | Ctlp_FormulaArrayConvertToForward(ctlArray, (nInitialStates == 1.0), |
---|
2023 | noShare); |
---|
2024 | /* end conversion for forward traversal */ |
---|
2025 | } else if (noShare) { /* conversion for backward, no sharing */ |
---|
2026 | ctlNormalFormulaArray = |
---|
2027 | Ctlp_FormulaArrayConvertToExistentialFormTree(ctlArray); |
---|
2028 | }else{ /* conversion for backward, with sharing */ |
---|
2029 | /* Note that converting to DAG after converting to existential form would |
---|
2030 | lead to more sharing, but it cannot be done since equal subformula that |
---|
2031 | are converted from different formulae need different pointers back to |
---|
2032 | their originals */ |
---|
2033 | if (checkVacuity) { |
---|
2034 | ctlNormalFormulaArray = |
---|
2035 | Ctlp_FormulaArrayConvertToExistentialFormTree(ctlArray); |
---|
2036 | } |
---|
2037 | else { |
---|
2038 | array_t *temp = Ctlp_FormulaArrayConvertToDAG( ctlArray ); |
---|
2039 | array_free( ctlArray ); |
---|
2040 | ctlArray = temp; |
---|
2041 | ctlNormalFormulaArray = |
---|
2042 | Ctlp_FormulaDAGConvertToExistentialFormDAG(ctlArray); |
---|
2043 | } |
---|
2044 | } |
---|
2045 | /* At this point, ctlNormalFormulaArray contains the formulas that are |
---|
2046 | actually going to be checked, and ctlArray contains the formulas from |
---|
2047 | which the conversion has been done. Both need to be kept around until the |
---|
2048 | end, for debugging purposes. */ |
---|
2049 | |
---|
2050 | numFormulae = array_n(ctlNormalFormulaArray); |
---|
2051 | |
---|
2052 | /* time out */ |
---|
2053 | if (timeOutPeriod > 0) { |
---|
2054 | /* Set the static variables used by the signal handler. */ |
---|
2055 | mcTimeOut = timeOutPeriod; |
---|
2056 | alarmLapTime = util_cpu_ctime(); |
---|
2057 | (void) signal(SIGALRM, (void(*)(int))TimeOutHandle); |
---|
2058 | (void) alarm(timeOutPeriod); |
---|
2059 | if (setjmp(timeOutEnv) > 0) { |
---|
2060 | (void) fprintf(vis_stdout, |
---|
2061 | "# MC: timeout occurred after %d seconds.\n", timeOutPeriod); |
---|
2062 | (void) fprintf(vis_stdout, "# MC: data may be corrupted.\n"); |
---|
2063 | if (verbosity > McVerbosityNone_c) { |
---|
2064 | fprintf(vis_stdout, "-- total %d image computations and %d preimage computations\n", |
---|
2065 | Img_GetNumberOfImageComputation(Img_Forward_c), |
---|
2066 | Img_GetNumberOfImageComputation(Img_Backward_c)); |
---|
2067 | } |
---|
2068 | alarm(0); |
---|
2069 | return 1; |
---|
2070 | } |
---|
2071 | } |
---|
2072 | |
---|
2073 | |
---|
2074 | /* Create reduced fsm, if necessary */ |
---|
2075 | if (!McOptionsReadReduceFsm(options)){ |
---|
2076 | /* We want to minimize only when "-r" option is not specified */ |
---|
2077 | /* reduceFsm would be NIL, if there is no reduction observed */ |
---|
2078 | assert (reducedFsm == NIL(Fsm_Fsm_t)); |
---|
2079 | reducedFsm = McConstructReducedFsm(network, ctlNormalFormulaArray); |
---|
2080 | if (reducedFsm != NIL(Fsm_Fsm_t) && verbosity != McVerbosityNone_c) { |
---|
2081 | mddMgr = Fsm_FsmReadMddManager(reducedFsm); |
---|
2082 | bddIdArray = mdd_id_array_to_bdd_id_array(mddMgr, |
---|
2083 | Fsm_FsmReadPresentStateVars(reducedFsm)); |
---|
2084 | (void)fprintf(vis_stdout,"Local system includes "); |
---|
2085 | (void)fprintf(vis_stdout,"%d (%d) multi-value (boolean) variables.\n", |
---|
2086 | array_n(Fsm_FsmReadPresentStateVars(reducedFsm)), |
---|
2087 | array_n(bddIdArray)); |
---|
2088 | array_free(bddIdArray); |
---|
2089 | } |
---|
2090 | } |
---|
2091 | |
---|
2092 | /************** for all formulae **********************************/ |
---|
2093 | for(i = 0; i < numFormulae; i++) { |
---|
2094 | int nImgComps, nPreComps; |
---|
2095 | boolean result; |
---|
2096 | Ctlp_Formula_t *ctlFormula = array_fetch(Ctlp_Formula_t *, |
---|
2097 | ctlNormalFormulaArray, i); |
---|
2098 | |
---|
2099 | modelFsm = NIL(Fsm_Fsm_t); |
---|
2100 | |
---|
2101 | /* do a check */ |
---|
2102 | if (!Mc_FormulaStaticSemanticCheckOnNetwork(ctlFormula, network, FALSE)) { |
---|
2103 | (void) fprintf(vis_stdout, |
---|
2104 | "** mc error: error in parsing Atomic Formula:\n%s\n", |
---|
2105 | error_string()); |
---|
2106 | error_init(); |
---|
2107 | Ctlp_FormulaFree(ctlFormula); |
---|
2108 | continue; |
---|
2109 | } |
---|
2110 | |
---|
2111 | /* Create reduced fsm */ |
---|
2112 | if (McOptionsReadReduceFsm(options)) { |
---|
2113 | /* We have not done top level reduction. */ |
---|
2114 | /* Using the same variable reducedFsm here */ |
---|
2115 | array_t *oneFormulaArray = array_alloc(Ctlp_Formula_t *, 1); |
---|
2116 | |
---|
2117 | assert(reducedFsm == NIL(Fsm_Fsm_t)); |
---|
2118 | array_insert_last(Ctlp_Formula_t *, oneFormulaArray, ctlFormula); |
---|
2119 | reducedFsm = McConstructReducedFsm(network, oneFormulaArray); |
---|
2120 | array_free(oneFormulaArray); |
---|
2121 | |
---|
2122 | if (reducedFsm && verbosity != McVerbosityNone_c) { |
---|
2123 | mddMgr = Fsm_FsmReadMddManager(reducedFsm); |
---|
2124 | bddIdArray = mdd_id_array_to_bdd_id_array(mddMgr, |
---|
2125 | Fsm_FsmReadPresentStateVars(reducedFsm)); |
---|
2126 | (void)fprintf(vis_stdout,"Local system includes "); |
---|
2127 | (void)fprintf(vis_stdout,"%d (%d) multi-value (boolean) variables.\n", |
---|
2128 | array_n(Fsm_FsmReadPresentStateVars(reducedFsm)), |
---|
2129 | array_n(bddIdArray)); |
---|
2130 | array_free(bddIdArray); |
---|
2131 | } |
---|
2132 | }/* if readreducefsm */ |
---|
2133 | |
---|
2134 | /* Let us see if we got any reduction via top level or via "-r" */ |
---|
2135 | if (reducedFsm == NIL(Fsm_Fsm_t)) |
---|
2136 | modelFsm = totalFsm; /* no reduction */ |
---|
2137 | else |
---|
2138 | modelFsm = reducedFsm; /* some reduction at some point */ |
---|
2139 | |
---|
2140 | /* compute initial states */ |
---|
2141 | modelInitialStates = Fsm_FsmComputeInitialStates(modelFsm); |
---|
2142 | if (modelInitialStates == NIL(mdd_t)) { |
---|
2143 | int j; |
---|
2144 | (void) fprintf(vis_stdout, |
---|
2145 | "** mc error: Cannot build init states (mutual latch dependency?)\n%s\n", |
---|
2146 | error_string()); |
---|
2147 | if (modelFsm != totalFsm) |
---|
2148 | Fsm_FsmFree(reducedFsm); |
---|
2149 | |
---|
2150 | alarm(0); |
---|
2151 | |
---|
2152 | for(j = i; j < numFormulae; j++) |
---|
2153 | Ctlp_FormulaFree( |
---|
2154 | array_fetch( Ctlp_Formula_t *, ctlNormalFormulaArray, j ) ); |
---|
2155 | array_free( ctlNormalFormulaArray ); |
---|
2156 | |
---|
2157 | Ctlp_FormulaArrayFree( ctlArray ); |
---|
2158 | |
---|
2159 | McOptionsFree(options); |
---|
2160 | |
---|
2161 | return 1; |
---|
2162 | } |
---|
2163 | |
---|
2164 | earlyTermination = Mc_EarlyTerminationAlloc(McAll_c, modelInitialStates); |
---|
2165 | |
---|
2166 | if(hintsArray != NIL(Ctlp_FormulaArray_t)) { |
---|
2167 | hintsStatesArray = Mc_EvaluateHints(modelFsm, hintsArray); |
---|
2168 | if( hintsStatesArray == NIL(array_t) || |
---|
2169 | (guidedSearchType == Mc_Global_c && |
---|
2170 | Ctlp_CheckClassOfExistentialFormula(ctlFormula) == Ctlp_Mixed_c)) { |
---|
2171 | int j; |
---|
2172 | |
---|
2173 | if( guidedSearchType == Mc_Global_c && |
---|
2174 | Ctlp_CheckClassOfExistentialFormula(ctlFormula) == Ctlp_Mixed_c) |
---|
2175 | fprintf(vis_stderr, "** mc error: global hints incompatible with " |
---|
2176 | "mixed formulae\n"); |
---|
2177 | |
---|
2178 | Mc_EarlyTerminationFree(earlyTermination); |
---|
2179 | mdd_free(modelInitialStates); |
---|
2180 | if (modelFsm != totalFsm) |
---|
2181 | Fsm_FsmFree(reducedFsm); |
---|
2182 | alarm(0); |
---|
2183 | for(j = i; j < numFormulae; j++) |
---|
2184 | Ctlp_FormulaFree( |
---|
2185 | array_fetch( Ctlp_Formula_t *, ctlNormalFormulaArray, j ) ); |
---|
2186 | array_free( ctlNormalFormulaArray ); |
---|
2187 | Ctlp_FormulaArrayFree( ctlArray ); |
---|
2188 | McOptionsFree(options); |
---|
2189 | return 1; |
---|
2190 | } /* problem with hints */ |
---|
2191 | } /* hints exist */ |
---|
2192 | |
---|
2193 | /* stats */ |
---|
2194 | if (verbosity > McVerbosityNone_c) { |
---|
2195 | initialTime = util_cpu_time(); |
---|
2196 | nImgComps = Img_GetNumberOfImageComputation(Img_Forward_c); |
---|
2197 | nPreComps = Img_GetNumberOfImageComputation(Img_Backward_c); |
---|
2198 | } else { /* to remove uninitialized variable warnings */ |
---|
2199 | initialTime = 0; |
---|
2200 | nImgComps = 0; |
---|
2201 | nPreComps = 0; |
---|
2202 | } |
---|
2203 | mddMgr = Fsm_FsmReadMddManager(modelFsm); |
---|
2204 | |
---|
2205 | /* compute don't cares. */ |
---|
2206 | if (modelCareStatesArray == NIL(array_t)) { |
---|
2207 | long iTime; /* starting time for reachability analysis */ |
---|
2208 | if (verbosity > McVerbosityNone_c && i == 0) |
---|
2209 | iTime = util_cpu_time(); |
---|
2210 | else /* to remove uninitialized variable warnings */ |
---|
2211 | iTime = 0; |
---|
2212 | |
---|
2213 | /* ardc */ |
---|
2214 | if (dcLevel == McDcLevelArdc_c) { |
---|
2215 | Fsm_ArdcOptions_t *ardcOptions = McOptionsReadArdcOptions(options); |
---|
2216 | |
---|
2217 | modelCareStatesArray = Fsm_ArdcComputeOverApproximateReachableStates( |
---|
2218 | modelFsm, 0, verbosity, 0, 0, 0, 0, 0, 0, ardcOptions); |
---|
2219 | if (verbosity > McVerbosityNone_c && i == 0) |
---|
2220 | Fsm_ArdcPrintReachabilityResults(modelFsm, util_cpu_time() - iTime); |
---|
2221 | |
---|
2222 | /* rch dc */ |
---|
2223 | } else if (dcLevel >= McDcLevelRch_c) { |
---|
2224 | modelCareStates = |
---|
2225 | Fsm_FsmComputeReachableStates(modelFsm, 0, 1, 0, 0, 0, 0, 0, |
---|
2226 | Fsm_Rch_Default_c, 0, 0, |
---|
2227 | NIL(array_t), FALSE, NIL(array_t)); |
---|
2228 | if (verbosity > McVerbosityNone_c && i == 0) { |
---|
2229 | Fsm_FsmReachabilityPrintResults(modelFsm, util_cpu_time() - iTime, |
---|
2230 | Fsm_Rch_Default_c); |
---|
2231 | } |
---|
2232 | |
---|
2233 | modelCareStatesArray = array_alloc(mdd_t *, 0); |
---|
2234 | array_insert(mdd_t *, modelCareStatesArray, 0, modelCareStates); |
---|
2235 | } else { |
---|
2236 | modelCareStates = mdd_one(mddMgr); |
---|
2237 | modelCareStatesArray = array_alloc(mdd_t *, 0); |
---|
2238 | array_insert(mdd_t *, modelCareStatesArray, 0, modelCareStates); |
---|
2239 | } |
---|
2240 | } |
---|
2241 | |
---|
2242 | Fsm_MinimizeTransitionRelationWithReachabilityInfo( |
---|
2243 | modelFsm, (traversalDirection == McFwd_c) ? Img_Both_c : Img_Backward_c, |
---|
2244 | verbosity > 1); |
---|
2245 | |
---|
2246 | /* fairness conditions */ |
---|
2247 | fairStates = Fsm_FsmComputeFairStates(modelFsm, modelCareStatesArray, |
---|
2248 | verbosity, dcLevel, GSHschedule, |
---|
2249 | McBwd_c, FALSE); |
---|
2250 | fairCond = Fsm_FsmReadFairnessConstraint(modelFsm); |
---|
2251 | |
---|
2252 | if (mdd_lequal(modelInitialStates, fairStates, 1, 0)) { |
---|
2253 | (void)fprintf(vis_stdout, |
---|
2254 | "** mc warning: There are no fair initial states\n"); |
---|
2255 | } |
---|
2256 | else if (!mdd_lequal(modelInitialStates, fairStates, 1, 1)) { |
---|
2257 | (void)fprintf(vis_stdout, |
---|
2258 | "** mc warning: Some initial states are not fair\n"); |
---|
2259 | } |
---|
2260 | |
---|
2261 | /* some user feedback */ |
---|
2262 | if (verbosity != McVerbosityNone_c) { |
---|
2263 | (void)fprintf(vis_stdout, "Checking formula[%d] : ", i + 1); |
---|
2264 | Ctlp_FormulaPrint(vis_stdout, |
---|
2265 | Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
2266 | (void)fprintf (vis_stdout, "\n"); |
---|
2267 | if (traversalDirection == McFwd_c) { |
---|
2268 | (void)fprintf(vis_stdout, "Forward formula : "); |
---|
2269 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
2270 | (void)fprintf(vis_stdout, "\n"); |
---|
2271 | } |
---|
2272 | } |
---|
2273 | |
---|
2274 | /************** the actual computation **********************************/ |
---|
2275 | if (checkVacuity) { |
---|
2276 | McVacuityDetection(modelFsm, ctlFormula, i, |
---|
2277 | fairStates, fairCond, modelCareStatesArray, |
---|
2278 | earlyTermination, hintsStatesArray, |
---|
2279 | guidedSearchType, modelInitialStates, |
---|
2280 | options); |
---|
2281 | } |
---|
2282 | else { /* Normal Model Checking */ |
---|
2283 | mdd_t *ctlFormulaStates = |
---|
2284 | Mc_FsmEvaluateFormula(modelFsm, ctlFormula, fairStates, |
---|
2285 | fairCond, modelCareStatesArray, |
---|
2286 | earlyTermination, hintsStatesArray, |
---|
2287 | guidedSearchType, verbosity, dcLevel, |
---|
2288 | buildOnionRings, GSHschedule); |
---|
2289 | |
---|
2290 | McEstimateCoverage(modelFsm, ctlFormula, i, fairStates, fairCond, |
---|
2291 | modelCareStatesArray, earlyTermination, |
---|
2292 | hintsStatesArray, guidedSearchType, verbosity, |
---|
2293 | dcLevel, buildOnionRings, GSHschedule, |
---|
2294 | traversalDirection, modelInitialStates, |
---|
2295 | ctlFormulaStates, &totalcoveredstates, |
---|
2296 | signalTypeList, signalList, statesCoveredList, |
---|
2297 | newCoveredStatesList, statesToRemoveList, |
---|
2298 | performCoverageHoskote, performCoverageImproved); |
---|
2299 | |
---|
2300 | Mc_EarlyTerminationFree(earlyTermination); |
---|
2301 | if(hintsStatesArray != NIL(array_t)) |
---|
2302 | mdd_array_free(hintsStatesArray); |
---|
2303 | /* Set up things for possible FAFW analysis of counterexample. */ |
---|
2304 | Fsm_FsmSetFAFWFlag(modelFsm, options->FAFWFlag); |
---|
2305 | Fsm_FsmSetSystemVariableFAFW(modelFsm, systemVarBddIdTable); |
---|
2306 | /* user feedback on succes/fail */ |
---|
2307 | result = McPrintPassFailMine(mddMgr, modelFsm, traversalDirection, |
---|
2308 | ctlFormula, ctlFormulaStates, |
---|
2309 | modelInitialStates, modelCareStatesArray, |
---|
2310 | options, verbosity); |
---|
2311 | Fsm_FsmSetFAFWFlag(modelFsm, 0); |
---|
2312 | Fsm_FsmSetSystemVariableFAFW(modelFsm, NULL); |
---|
2313 | mdd_free(ctlFormulaStates); |
---|
2314 | } |
---|
2315 | |
---|
2316 | if (verbosity > McVerbosityNone_c) { |
---|
2317 | finalTime = util_cpu_time(); |
---|
2318 | fprintf(vis_stdout, "-- mc time = %10g\n", |
---|
2319 | (double)(finalTime - initialTime) / 1000.0); |
---|
2320 | fprintf(vis_stdout, |
---|
2321 | "-- %d image computations and %d preimage computations\n", |
---|
2322 | Img_GetNumberOfImageComputation(Img_Forward_c) - nImgComps, |
---|
2323 | Img_GetNumberOfImageComputation(Img_Backward_c) - nPreComps); |
---|
2324 | } |
---|
2325 | mdd_free(modelInitialStates); |
---|
2326 | mdd_free(fairStates); |
---|
2327 | Ctlp_FormulaFree(ctlFormula); |
---|
2328 | |
---|
2329 | if ((McOptionsReadReduceFsm(options)) && |
---|
2330 | (reducedFsm != NIL(Fsm_Fsm_t))) { |
---|
2331 | /* |
---|
2332 | ** We need to free the reducedFsm only if it was created under "-r" |
---|
2333 | ** option and was non-NIL. |
---|
2334 | */ |
---|
2335 | Fsm_FsmFree(reducedFsm); |
---|
2336 | reducedFsm = NIL(Fsm_Fsm_t); |
---|
2337 | modelFsm = NIL(Fsm_Fsm_t); |
---|
2338 | if (modelCareStates) { |
---|
2339 | mdd_array_free(modelCareStatesArray); |
---|
2340 | modelCareStates = NIL(mdd_t); |
---|
2341 | modelCareStatesArray = NIL(array_t); |
---|
2342 | } else if (modelCareStatesArray) { |
---|
2343 | modelCareStatesArray = NIL(array_t); |
---|
2344 | } |
---|
2345 | } |
---|
2346 | }/* for all formulae */ |
---|
2347 | |
---|
2348 | if (verbosity > McVerbosityNone_c) { |
---|
2349 | finalTime = util_cpu_time(); |
---|
2350 | fprintf(vis_stdout, "-- total mc time = %10g\n", |
---|
2351 | (double)(finalTime - totalInitialTime) / 1000.0); |
---|
2352 | fprintf(vis_stdout, |
---|
2353 | "-- total %d image computations and %d preimage computations\n", |
---|
2354 | Img_GetNumberOfImageComputation(Img_Forward_c), |
---|
2355 | Img_GetNumberOfImageComputation(Img_Backward_c)); |
---|
2356 | /* Print tfm options if we have a global fsm. */ |
---|
2357 | if (!McOptionsReadReduceFsm(options) && modelFsm != NIL(Fsm_Fsm_t)) { |
---|
2358 | imageInfo = Fsm_FsmReadImageInfo(modelFsm); |
---|
2359 | if (Img_ImageInfoObtainMethodType(imageInfo) == Img_Tfm_c || |
---|
2360 | Img_ImageInfoObtainMethodType(imageInfo) == Img_Hybrid_c) { |
---|
2361 | Img_TfmPrintStatistics(imageInfo, Img_Both_c); |
---|
2362 | } |
---|
2363 | } |
---|
2364 | } |
---|
2365 | |
---|
2366 | /* Print results of coverage computation */ |
---|
2367 | McPrintCoverageSummary(modelFsm, dcLevel, |
---|
2368 | options, modelCareStatesArray, |
---|
2369 | modelCareStates, totalcoveredstates, |
---|
2370 | signalTypeList, signalList, statesCoveredList, |
---|
2371 | performCoverageHoskote, performCoverageImproved); |
---|
2372 | mdd_array_free(newCoveredStatesList); |
---|
2373 | mdd_array_free(statesToRemoveList); |
---|
2374 | array_free(signalTypeList); |
---|
2375 | array_free(signalList); |
---|
2376 | mdd_array_free(statesCoveredList); |
---|
2377 | if (totalcoveredstates != NIL(mdd_t)) |
---|
2378 | mdd_free(totalcoveredstates); |
---|
2379 | |
---|
2380 | if (modelCareStates) { |
---|
2381 | mdd_array_free(modelCareStatesArray); |
---|
2382 | } |
---|
2383 | |
---|
2384 | if(hintsArray) |
---|
2385 | Ctlp_FormulaArrayFree(hintsArray); |
---|
2386 | |
---|
2387 | if ((McOptionsReadReduceFsm(options) == FALSE) && |
---|
2388 | (reducedFsm != NIL(Fsm_Fsm_t))) { |
---|
2389 | /* If "-r" was not specified and we did some reduction at top |
---|
2390 | level, we need to free it */ |
---|
2391 | Fsm_FsmFree(reducedFsm); |
---|
2392 | reducedFsm = NIL(Fsm_Fsm_t); |
---|
2393 | modelFsm = NIL(Fsm_Fsm_t); |
---|
2394 | } |
---|
2395 | |
---|
2396 | if(systemVarBddIdTable) |
---|
2397 | st_free_table(systemVarBddIdTable); |
---|
2398 | array_free(ctlNormalFormulaArray); |
---|
2399 | (void) fprintf(vis_stdout, "\n"); |
---|
2400 | |
---|
2401 | Ctlp_FormulaArrayFree(ctlArray); |
---|
2402 | McOptionsFree(options); |
---|
2403 | alarm(0); |
---|
2404 | return 0; |
---|
2405 | |
---|
2406 | } |
---|
2407 | |
---|
2408 | |
---|
2409 | /**Function******************************************************************** |
---|
2410 | |
---|
2411 | Synopsis [Parse command line options for mc.] |
---|
2412 | |
---|
2413 | SideEffects [] |
---|
2414 | |
---|
2415 | ******************************************************************************/ |
---|
2416 | static McOptions_t * |
---|
2417 | ParseMcOptions( |
---|
2418 | int argc, |
---|
2419 | char **argv) |
---|
2420 | { |
---|
2421 | unsigned int i; |
---|
2422 | int c; |
---|
2423 | char *guideFileName = NIL(char); |
---|
2424 | char *variablesForSystem = NIL(char); |
---|
2425 | FILE *guideFile = NIL(FILE); |
---|
2426 | FILE *systemFile = NIL(FILE); |
---|
2427 | boolean doCoverageHoskote = FALSE; |
---|
2428 | boolean doCoverageImproved = FALSE; |
---|
2429 | boolean useMore = FALSE; |
---|
2430 | boolean reduceFsm = FALSE; |
---|
2431 | boolean printInputs = FALSE; |
---|
2432 | boolean useFormulaTree = FALSE; |
---|
2433 | boolean vd = FALSE; |
---|
2434 | boolean beer = FALSE; |
---|
2435 | boolean FAFWFlag = FALSE; |
---|
2436 | boolean GFAFWFlag = FALSE; |
---|
2437 | FILE *inputFp=NIL(FILE); |
---|
2438 | FILE *debugOut=NIL(FILE); |
---|
2439 | char *debugOutName=NIL(char); |
---|
2440 | Mc_DcLevel dcLevel = McDcLevelRch_c; |
---|
2441 | McDbgLevel dbgLevel = McDbgLevelNone_c; |
---|
2442 | Mc_VerbosityLevel verbosityLevel = McVerbosityNone_c; |
---|
2443 | Mc_FwdBwdAnalysis fwdBwd = McFwd_c; |
---|
2444 | McOptions_t *options = McOptionsAlloc(); |
---|
2445 | int timeOutPeriod = 0; |
---|
2446 | Mc_FwdBwdAnalysis traversalDirection = McBwd_c; |
---|
2447 | Fsm_ArdcOptions_t *ardcOptions; |
---|
2448 | Mc_GSHScheduleType schedule = McGSH_EL_c; |
---|
2449 | |
---|
2450 | /* |
---|
2451 | * Parse command line options. |
---|
2452 | */ |
---|
2453 | |
---|
2454 | util_getopt_reset(); |
---|
2455 | while ((c = util_getopt(argc, argv, "bcirmg:hv:d:D:VBf:t:CIFR:S:GWw:")) != EOF) { |
---|
2456 | switch(c) { |
---|
2457 | case 'g': |
---|
2458 | guideFileName = util_strsav(util_optarg); |
---|
2459 | break; |
---|
2460 | case 'h': |
---|
2461 | goto usage; |
---|
2462 | case 'v': |
---|
2463 | for (i = 0; i < strlen(util_optarg); i++) { |
---|
2464 | if (!isdigit((int)util_optarg[i])) { |
---|
2465 | goto usage; |
---|
2466 | } |
---|
2467 | } |
---|
2468 | verbosityLevel = (Mc_VerbosityLevel) atoi(util_optarg); |
---|
2469 | break; |
---|
2470 | case 'd': |
---|
2471 | for (i = 0; i < strlen(util_optarg); i++) { |
---|
2472 | if (!isdigit((int)util_optarg[i])) { |
---|
2473 | goto usage; |
---|
2474 | } |
---|
2475 | } |
---|
2476 | dbgLevel = (McDbgLevel) atoi(util_optarg); |
---|
2477 | break; |
---|
2478 | case 'D': |
---|
2479 | for (i = 0; i < strlen(util_optarg); i++) { |
---|
2480 | if (!isdigit((int)util_optarg[i])) { |
---|
2481 | goto usage; |
---|
2482 | } |
---|
2483 | } |
---|
2484 | dcLevel = (Mc_DcLevel) atoi(util_optarg); |
---|
2485 | break; |
---|
2486 | case 'b': |
---|
2487 | fwdBwd = McBwd_c; |
---|
2488 | break; |
---|
2489 | case 'V': /*Vacuity detection option*/ |
---|
2490 | vd = TRUE; |
---|
2491 | break; |
---|
2492 | case 'B': /*Vacuity detection Beer et al method option*/ |
---|
2493 | vd = TRUE; |
---|
2494 | beer = TRUE; |
---|
2495 | break; |
---|
2496 | case 'f': |
---|
2497 | debugOutName = util_strsav(util_optarg); |
---|
2498 | break; |
---|
2499 | case 'm': |
---|
2500 | useMore = TRUE; |
---|
2501 | break; |
---|
2502 | case 'r' : |
---|
2503 | reduceFsm = TRUE; |
---|
2504 | break; |
---|
2505 | case 'c': |
---|
2506 | useFormulaTree = TRUE; |
---|
2507 | break; |
---|
2508 | case 't' : |
---|
2509 | timeOutPeriod = atoi(util_optarg); |
---|
2510 | break; |
---|
2511 | case 'i' : |
---|
2512 | printInputs = TRUE; |
---|
2513 | break; |
---|
2514 | case 'F' : |
---|
2515 | traversalDirection = McFwd_c; |
---|
2516 | break; |
---|
2517 | case 'S' : |
---|
2518 | schedule = McStringConvertToScheduleType(util_optarg); |
---|
2519 | break; |
---|
2520 | case 'w': |
---|
2521 | variablesForSystem = util_strsav(util_optarg); |
---|
2522 | case 'W': |
---|
2523 | FAFWFlag = 1; |
---|
2524 | break; |
---|
2525 | case 'G': |
---|
2526 | GFAFWFlag = 1; |
---|
2527 | break; |
---|
2528 | case 'C' : |
---|
2529 | doCoverageHoskote = TRUE; |
---|
2530 | break; |
---|
2531 | case 'I' : |
---|
2532 | doCoverageImproved = TRUE; |
---|
2533 | break; |
---|
2534 | default: |
---|
2535 | goto usage; |
---|
2536 | } |
---|
2537 | } |
---|
2538 | |
---|
2539 | /* |
---|
2540 | * Open the ctl file. |
---|
2541 | */ |
---|
2542 | if (argc - util_optind == 0) { |
---|
2543 | (void) fprintf(vis_stderr, "** mc error: file containing ctl formulas not provided\n"); |
---|
2544 | goto usage; |
---|
2545 | } |
---|
2546 | else if (argc - util_optind > 1) { |
---|
2547 | (void) fprintf(vis_stderr, "** mc error: too many arguments\n"); |
---|
2548 | goto usage; |
---|
2549 | } |
---|
2550 | |
---|
2551 | McOptionsSetFwdBwd(options, fwdBwd); |
---|
2552 | McOptionsSetUseMore(options, useMore); |
---|
2553 | McOptionsSetReduceFsm(options, reduceFsm); |
---|
2554 | McOptionsSetVacuityDetect(options, vd); |
---|
2555 | McOptionsSetBeerMethod(options, beer); |
---|
2556 | McOptionsSetUseFormulaTree(options, useFormulaTree); |
---|
2557 | McOptionsSetPrintInputs(options, printInputs); |
---|
2558 | McOptionsSetTimeOutPeriod(options, timeOutPeriod); |
---|
2559 | McOptionsSetFAFWFlag(options, FAFWFlag + GFAFWFlag); |
---|
2560 | McOptionsSetCoverageHoskote(options, doCoverageHoskote); |
---|
2561 | McOptionsSetCoverageImproved(options, doCoverageImproved); |
---|
2562 | |
---|
2563 | if((FAFWFlag > 0 || GFAFWFlag > 0) && dbgLevel == 0) { |
---|
2564 | fprintf(vis_stderr, "** mc warning : -w and -W options are ignored without -d option\n"); |
---|
2565 | } |
---|
2566 | |
---|
2567 | if((FAFWFlag > 0 || GFAFWFlag > 0) && printInputs == 0) { |
---|
2568 | fprintf(vis_stderr, "** mc warning : -i is recommended with -w or -W option\n"); |
---|
2569 | } |
---|
2570 | if(FAFWFlag) { |
---|
2571 | if (bdd_get_package_name() != CUDD) { |
---|
2572 | fprintf(vis_stderr, "** mc warning : -w and -W option is only available with CUDD\n"); |
---|
2573 | FAFWFlag = 0; |
---|
2574 | FREE(variablesForSystem); |
---|
2575 | variablesForSystem = NIL(char); |
---|
2576 | } |
---|
2577 | } |
---|
2578 | |
---|
2579 | |
---|
2580 | if (schedule == McGSH_Unassigned_c) { |
---|
2581 | (void) fprintf(vis_stderr, "unknown schedule: %s\n", util_optarg); |
---|
2582 | goto usage; |
---|
2583 | } else { |
---|
2584 | McOptionsSetSchedule(options, schedule); |
---|
2585 | } |
---|
2586 | inputFp = Cmd_FileOpen(argv[util_optind], "r", NIL(char *), 0); |
---|
2587 | if (inputFp == NIL(FILE)) { |
---|
2588 | McOptionsFree(options); |
---|
2589 | if (guideFileName != NIL(char)) FREE(guideFileName); |
---|
2590 | return NIL(McOptions_t); |
---|
2591 | } |
---|
2592 | McOptionsSetCtlFile(options, inputFp); |
---|
2593 | |
---|
2594 | if (debugOutName != NIL(char)) { |
---|
2595 | debugOut = Cmd_FileOpen(debugOutName, "w", NIL(char *), 0); |
---|
2596 | FREE(debugOutName); |
---|
2597 | if (debugOut == NIL(FILE)) { |
---|
2598 | McOptionsFree(options); |
---|
2599 | if (guideFileName != NIL(char)) FREE(guideFileName); |
---|
2600 | return NIL(McOptions_t); |
---|
2601 | } |
---|
2602 | } |
---|
2603 | McOptionsSetDebugFile(options, debugOut); |
---|
2604 | |
---|
2605 | |
---|
2606 | if (guideFileName != NIL(char)) { |
---|
2607 | guideFile = Cmd_FileOpen(guideFileName, "r", NIL(char *), 0); |
---|
2608 | if (guideFile == NIL(FILE)) { |
---|
2609 | fprintf(vis_stderr, "** mc error: cannot open guided search file %s.\n", |
---|
2610 | guideFileName); |
---|
2611 | FREE(guideFileName); |
---|
2612 | guideFileName = NIL(char); |
---|
2613 | McOptionsFree(options); |
---|
2614 | return NIL(McOptions_t); |
---|
2615 | } |
---|
2616 | FREE(guideFileName); |
---|
2617 | guideFileName = NIL(char); |
---|
2618 | } |
---|
2619 | McOptionsSetGuideFile(options, guideFile); |
---|
2620 | |
---|
2621 | if (variablesForSystem != NIL(char)) { |
---|
2622 | systemFile = Cmd_FileOpen(variablesForSystem, "r", NIL(char *), 0); |
---|
2623 | if (systemFile == NIL(FILE)) { |
---|
2624 | fprintf(vis_stderr, "** mc error: cannot open system variables file for FAFW %s.\n", |
---|
2625 | variablesForSystem); |
---|
2626 | FREE(variablesForSystem); |
---|
2627 | variablesForSystem = NIL(char); |
---|
2628 | McOptionsFree(options); |
---|
2629 | return NIL(McOptions_t); |
---|
2630 | } |
---|
2631 | FREE(variablesForSystem); |
---|
2632 | variablesForSystem = NIL(char); |
---|
2633 | } |
---|
2634 | McOptionsSetVariablesForSystem(options, systemFile); |
---|
2635 | |
---|
2636 | if ((verbosityLevel != McVerbosityNone_c) && |
---|
2637 | (verbosityLevel != McVerbosityLittle_c) && |
---|
2638 | (verbosityLevel != McVerbositySome_c) && |
---|
2639 | (verbosityLevel != McVerbosityMax_c)) { |
---|
2640 | goto usage; |
---|
2641 | } |
---|
2642 | else { |
---|
2643 | McOptionsSetVerbosityLevel(options, verbosityLevel); |
---|
2644 | } |
---|
2645 | |
---|
2646 | if ((dbgLevel != McDbgLevelNone_c) && |
---|
2647 | (dbgLevel != McDbgLevelMin_c) && |
---|
2648 | (dbgLevel != McDbgLevelMinVerbose_c) && |
---|
2649 | (dbgLevel != McDbgLevelMax_c) && |
---|
2650 | (dbgLevel != McDbgLevelInteractive_c)) { |
---|
2651 | goto usage; |
---|
2652 | } |
---|
2653 | else { |
---|
2654 | McOptionsSetDbgLevel(options, dbgLevel); |
---|
2655 | } |
---|
2656 | |
---|
2657 | if ((dcLevel != McDcLevelNone_c) && |
---|
2658 | (dcLevel != McDcLevelRch_c ) && |
---|
2659 | (dcLevel != McDcLevelRchFrontier_c ) && |
---|
2660 | (dcLevel != McDcLevelArdc_c )) { |
---|
2661 | goto usage; |
---|
2662 | } |
---|
2663 | else { |
---|
2664 | McOptionsSetDcLevel(options, dcLevel); |
---|
2665 | } |
---|
2666 | |
---|
2667 | McOptionsSetTraversalDirection(options, traversalDirection); |
---|
2668 | if (dcLevel == McDcLevelArdc_c) { |
---|
2669 | ardcOptions = Fsm_ArdcAllocOptionsStruct(); |
---|
2670 | Fsm_ArdcGetDefaultOptions(ardcOptions); |
---|
2671 | } else |
---|
2672 | ardcOptions = NIL(Fsm_ArdcOptions_t); |
---|
2673 | McOptionsSetArdcOptions(options, ardcOptions); |
---|
2674 | |
---|
2675 | return options; |
---|
2676 | |
---|
2677 | usage: |
---|
2678 | (void) fprintf(vis_stderr, "usage: model_check [-b][-c][-d dbg_level][-f dbg_file][-g <hintfile>][-h][-i][-m][-r][-V][-B][-t period][-C][-I][-P][-v verbosity_level][-D dc_level][-F][-S <schedule>] <ctl_file>\n"); |
---|
2679 | (void) fprintf(vis_stderr, " -b \tUse backward analysis in debugging\n"); |
---|
2680 | (void) fprintf(vis_stderr, " -c \tNo sharing of CTL parse tree. This option does not matter for vacuity detection.\n"); |
---|
2681 | (void) fprintf(vis_stderr, " -d <dbg_level>\n"); |
---|
2682 | (void) fprintf(vis_stderr, " debug_level = 0 => no debugging (Default)\n"); |
---|
2683 | (void) fprintf(vis_stderr, " debug_level = 1 => automatic minimal debugging\n"); |
---|
2684 | (void) fprintf(vis_stderr, " debug_level = 2 => automatic minimal debugging with extra verbosity\n"); |
---|
2685 | (void) fprintf(vis_stderr, " debug_level = 3 => automatic maximal debugging\n"); |
---|
2686 | (void) fprintf(vis_stderr, " debug_level = 4 => interactive debugging\n"); |
---|
2687 | (void) fprintf(vis_stderr, " -f <dbg_out>\n"); |
---|
2688 | (void) fprintf(vis_stderr, " write error trace to dbg_out\n"); |
---|
2689 | (void) fprintf(vis_stderr, " -g <hint_file> \tSpecify file for guided search.\n"); |
---|
2690 | (void) fprintf(vis_stderr, " -h \tPrints this usage message.\n"); |
---|
2691 | (void) fprintf(vis_stderr, " -i \tPrint input values in debug traces.\n"); |
---|
2692 | (void) fprintf(vis_stderr, " -m \tPipe debug output through more.\n"); |
---|
2693 | (void) fprintf(vis_stderr, " -r reduce FSM with respect to formula being verified\n"); |
---|
2694 | (void) fprintf(vis_stderr, " -t <period> time out period\n"); |
---|
2695 | (void) fprintf(vis_stderr, " -v <verbosity_level>\n"); |
---|
2696 | (void) fprintf(vis_stderr, " verbosity_level = 0 => no feedback (Default)\n"); |
---|
2697 | (void) fprintf(vis_stderr, " verbosity_level = 1 => code status\n"); |
---|
2698 | (void) fprintf(vis_stderr, " verbosity_level = 2 => code status and CPU usage profile\n"); |
---|
2699 | (void) fprintf(vis_stderr, " -w <node file> \tSpecify variables controlled by system.\n"); |
---|
2700 | (void) fprintf(vis_stderr, " -B vacuity detection for w-ACTL formulae using method of Beer et al \n"); |
---|
2701 | (void) fprintf(vis_stderr, " -C Compute coverage of all observable signals using Hoskote et.al's implementation\n"); |
---|
2702 | (void) fprintf(vis_stderr, " -D <dc_level>\n"); |
---|
2703 | (void) fprintf(vis_stderr, " dc_level = 0 => no use of don't cares\n"); |
---|
2704 | (void) fprintf(vis_stderr, " dc_level = 1 => use unreached states as don't cares (Default)\n"); |
---|
2705 | (void) fprintf(vis_stderr, " dc_level = 2 => use unreached states as don't cares\n"); |
---|
2706 | |
---|
2707 | (void) fprintf(vis_stderr, " and aggressive use of DC's to simplify MDD's\n"); |
---|
2708 | (void) fprintf(vis_stderr, " dc_level = 3 => use over-approximate unreached states as don't cares\n"); |
---|
2709 | (void) fprintf(vis_stderr, " and aggressive use of DC's to simplify MDD's\n"); |
---|
2710 | (void) fprintf(vis_stderr, " -F \tUse forward model checking.\n"); |
---|
2711 | (void) fprintf(vis_stderr, " -G \tUse general fate and free will algorithm.\n"); |
---|
2712 | (void) fprintf(vis_stderr, " -I Compute coverage of all observable signals using improved coverage implementation\n"); |
---|
2713 | (void) fprintf(vis_stderr, " -S <schedule>\n"); |
---|
2714 | (void) fprintf(vis_stderr, " schedule is one of {EL,EL1,EL2,budget,random,off}\n"); |
---|
2715 | (void) fprintf(vis_stderr, " -V thorough vacuity detection\n"); |
---|
2716 | (void) fprintf(vis_stderr, " -W \tUse fate and free will algorithm when all the variables are controlled by system.\n"); |
---|
2717 | (void) fprintf(vis_stderr, " <ctl_file> The input file containing CTL formula to be checked.\n"); |
---|
2718 | |
---|
2719 | if (guideFileName != NIL(char)) FREE(guideFileName); |
---|
2720 | McOptionsFree(options); |
---|
2721 | |
---|
2722 | return NIL(McOptions_t); |
---|
2723 | } |
---|
2724 | |
---|
2725 | |
---|
2726 | /**Function******************************************************************** |
---|
2727 | |
---|
2728 | Synopsis [] |
---|
2729 | |
---|
2730 | Description [Refer to 'static int CommandPrintModels (Hrc_Manager_t **hmgr, |
---|
2731 | int argc, char **argv)' function in hrcCmd.c] |
---|
2732 | |
---|
2733 | SideEffects [] |
---|
2734 | |
---|
2735 | SeeAlso [] |
---|
2736 | |
---|
2737 | ******************************************************************************/ |
---|
2738 | |
---|
2739 | static int print_modelsMine(Hrc_Manager_t **hmgr, int argc, char **argv) |
---|
2740 | { |
---|
2741 | |
---|
2742 | (void) fprintf(vis_stderr, "*** 'print_models' begins. *** \n"); |
---|
2743 | |
---|
2744 | st_generator *gen; |
---|
2745 | char *name; |
---|
2746 | Hrc_Model_t *model; |
---|
2747 | Hrc_Node_t *node; |
---|
2748 | int c; |
---|
2749 | |
---|
2750 | util_getopt_reset(); |
---|
2751 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
2752 | switch(c){ |
---|
2753 | case 'h': |
---|
2754 | goto usage; |
---|
2755 | default: |
---|
2756 | goto usage; |
---|
2757 | } |
---|
2758 | } |
---|
2759 | if(argc != 1) { |
---|
2760 | goto usage; |
---|
2761 | } |
---|
2762 | |
---|
2763 | node = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
2764 | if (node == NIL(Hrc_Node_t)){ |
---|
2765 | (void)fprintf(vis_stderr,"No file has been read in.\n"); |
---|
2766 | return 1; |
---|
2767 | } |
---|
2768 | |
---|
2769 | Hrc_ManagerForEachModel(*hmgr, gen, name, model) { |
---|
2770 | PrintNodeStats(Hrc_ModelReadMasterNode(model), FALSE); |
---|
2771 | (void) fprintf(vis_stdout, "subckts = %d\n", |
---|
2772 | st_count(Hrc_ModelReadSubcktTable(model))); |
---|
2773 | } |
---|
2774 | return 0; |
---|
2775 | |
---|
2776 | usage: |
---|
2777 | (void) fprintf(vis_stderr, "usage: print_models [-h]\n"); |
---|
2778 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
2779 | return 1; |
---|
2780 | |
---|
2781 | } |
---|
2782 | |
---|
2783 | /**Function******************************************************************** |
---|
2784 | |
---|
2785 | Synopsis [This function prints the statistics of a node.] |
---|
2786 | |
---|
2787 | SideEffects [] |
---|
2788 | |
---|
2789 | SeeAlso [] |
---|
2790 | |
---|
2791 | ******************************************************************************/ |
---|
2792 | static void |
---|
2793 | PrintNodeStats( |
---|
2794 | Hrc_Node_t *node, |
---|
2795 | boolean isHnode) |
---|
2796 | { |
---|
2797 | (void) fprintf(vis_stdout, "Model name = %s", Hrc_NodeReadModelName(node)); |
---|
2798 | if(isHnode) { |
---|
2799 | (void) fprintf(vis_stdout, ", Instance name = %s\n", |
---|
2800 | Hrc_NodeReadInstanceName(node)); |
---|
2801 | } |
---|
2802 | else { |
---|
2803 | (void) fprintf(vis_stdout, "\n"); |
---|
2804 | } |
---|
2805 | (void) fprintf(vis_stdout, "inputs = %d,", Hrc_NodeReadNumFormalInputs(node)); |
---|
2806 | (void) fprintf(vis_stdout, " outputs = %d,", Hrc_NodeReadNumFormalOutputs(node)); |
---|
2807 | (void) fprintf(vis_stdout, " variables = %d,", Hrc_NodeReadNumVariables(node)); |
---|
2808 | (void) fprintf(vis_stdout, " tables = %d,", Hrc_NodeReadNumTables(node)); |
---|
2809 | (void) fprintf(vis_stdout, " latches = %d", Hrc_NodeReadNumLatches(node)); |
---|
2810 | if(isHnode) { |
---|
2811 | (void) fprintf(vis_stdout, ", children = %d\n", Hrc_NodeReadNumChildren(node)); |
---|
2812 | } |
---|
2813 | else { |
---|
2814 | (void) fprintf(vis_stdout, "\n"); |
---|
2815 | } |
---|
2816 | } |
---|
2817 | |
---|
2818 | /**Function******************************************************************** |
---|
2819 | |
---|
2820 | Synopsis [returns child or parent node (it is actually the current node)] |
---|
2821 | |
---|
2822 | Description [Refer to 'static int CommandCd (Hrc_Manager_t **hmgr, |
---|
2823 | int argc, char **argv)' function in hrcCmd.c] |
---|
2824 | |
---|
2825 | SideEffects [] |
---|
2826 | |
---|
2827 | SeeAlso [] |
---|
2828 | |
---|
2829 | ******************************************************************************/ |
---|
2830 | static Hrc_Node_t *cdMine(Hrc_Manager_t **hmgr, int argc, char **argv) |
---|
2831 | { |
---|
2832 | |
---|
2833 | (void) fprintf(vis_stderr, "*** 'cd' begins. *** \n"); |
---|
2834 | |
---|
2835 | Hrc_Node_t *currentNode, *parent, *child; |
---|
2836 | int c; |
---|
2837 | |
---|
2838 | util_getopt_reset(); |
---|
2839 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
2840 | switch(c){ |
---|
2841 | case 'h': |
---|
2842 | goto usage; |
---|
2843 | default: |
---|
2844 | goto usage; |
---|
2845 | } |
---|
2846 | } |
---|
2847 | |
---|
2848 | if (argc != 2){ |
---|
2849 | goto usage; |
---|
2850 | } |
---|
2851 | |
---|
2852 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
2853 | if (currentNode == NIL(Hrc_Node_t)){ |
---|
2854 | (void)fprintf(vis_stdout,"No file has been read in.\n"); |
---|
2855 | return NIL(Hrc_Node_t); |
---|
2856 | } |
---|
2857 | /* go to the parent node */ |
---|
2858 | if (strcmp(*(++argv),"..") == 0){ |
---|
2859 | if ((parent = Hrc_NodeReadParentNode(currentNode)) == NIL(Hrc_Node_t)){ |
---|
2860 | (void)fprintf(vis_stderr,"You are at the root node. Can't cd to a parent.\n"); |
---|
2861 | return currentNode; |
---|
2862 | } |
---|
2863 | Hrc_ManagerSetCurrentNode(*hmgr,parent); |
---|
2864 | return parent; |
---|
2865 | } |
---|
2866 | |
---|
2867 | if ((child = Hrc_NodeFindChildByName(currentNode,*argv)) == NIL(Hrc_Node_t)){ |
---|
2868 | (void)fprintf(vis_stderr,"No child node whose name is %s exists in the current node.\n",*argv); |
---|
2869 | return currentNode; |
---|
2870 | } |
---|
2871 | Hrc_ManagerSetCurrentNode(*hmgr,child); |
---|
2872 | return child; |
---|
2873 | |
---|
2874 | usage: |
---|
2875 | (void)fprintf(vis_stderr,"usage: cd [-h] child_name or cd ..\n"); |
---|
2876 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
2877 | return NIL(Hrc_Node_t); |
---|
2878 | } |
---|
2879 | |
---|
2880 | |
---|
2881 | /**Function******************************************************************** |
---|
2882 | |
---|
2883 | Synopsis [returns current node] |
---|
2884 | |
---|
2885 | Description [Refer to 'static int CommandLs (Hrc_Manager_t **hmgr, |
---|
2886 | int argc, char **argv)' function in hrcCmd.c] |
---|
2887 | |
---|
2888 | SideEffects [] |
---|
2889 | |
---|
2890 | SeeAlso [] |
---|
2891 | |
---|
2892 | ******************************************************************************/ |
---|
2893 | static Hrc_Node_t *lsMine(Hrc_Manager_t **hmgr, int argc, char **argv){ |
---|
2894 | |
---|
2895 | (void) fprintf(vis_stderr, "*** 'ls' begins. *** \n"); |
---|
2896 | |
---|
2897 | int recursiveFlag = 0; |
---|
2898 | int c; |
---|
2899 | Hrc_Node_t *currentNode; |
---|
2900 | |
---|
2901 | util_getopt_reset(); |
---|
2902 | while ((c = util_getopt(argc, argv, "hR")) != EOF) { |
---|
2903 | switch(c){ |
---|
2904 | case 'h': |
---|
2905 | goto usage; |
---|
2906 | case 'R': |
---|
2907 | recursiveFlag = 1; |
---|
2908 | break; |
---|
2909 | default: |
---|
2910 | goto usage; |
---|
2911 | } |
---|
2912 | } |
---|
2913 | /* if there are some arguments for ls */ |
---|
2914 | if (argc != util_optind){ |
---|
2915 | goto usage; |
---|
2916 | } |
---|
2917 | |
---|
2918 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
2919 | if (currentNode == NIL(Hrc_Node_t)){ |
---|
2920 | (void)fprintf(vis_stdout,"No file has been read in.\n"); |
---|
2921 | return NIL(Hrc_Node_t); |
---|
2922 | } |
---|
2923 | NodeListChildren(currentNode, recursiveFlag, 0); |
---|
2924 | return currentNode; |
---|
2925 | |
---|
2926 | usage: |
---|
2927 | (void)fprintf(vis_stderr,"usage: ls [-h] [-R]\n"); |
---|
2928 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
2929 | (void) fprintf(vis_stderr, " -R \t\tprint recursive tree\n"); |
---|
2930 | |
---|
2931 | return NIL(Hrc_Node_t); |
---|
2932 | |
---|
2933 | } |
---|
2934 | |
---|
2935 | |
---|
2936 | /**Function******************************************************************** |
---|
2937 | |
---|
2938 | Synopsis [] |
---|
2939 | |
---|
2940 | Description [Refer to 'static int CommandPwd (Hrc_Manager_t **hmgr, |
---|
2941 | int argc, char **argv)' function in hrcCmd.c] |
---|
2942 | |
---|
2943 | SideEffects [] |
---|
2944 | |
---|
2945 | SeeAlso [] |
---|
2946 | |
---|
2947 | ******************************************************************************/ |
---|
2948 | static char *pwdMine(Hrc_Manager_t **hmgr, int argc, char **argv){ |
---|
2949 | |
---|
2950 | (void) fprintf(vis_stderr, "*** 'pwd' begins. *** \n"); |
---|
2951 | |
---|
2952 | Hrc_Node_t *currentNode; |
---|
2953 | Hrc_Node_t *rootNode; |
---|
2954 | char *separator, *hierarchicalName; |
---|
2955 | int c; |
---|
2956 | |
---|
2957 | util_getopt_reset(); |
---|
2958 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
2959 | switch(c){ |
---|
2960 | case 'h': |
---|
2961 | goto usage; |
---|
2962 | default: |
---|
2963 | goto usage; |
---|
2964 | } |
---|
2965 | } |
---|
2966 | if (argc != 1){ |
---|
2967 | goto usage; |
---|
2968 | } |
---|
2969 | |
---|
2970 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
2971 | if (currentNode == NIL(Hrc_Node_t)){ |
---|
2972 | (void)fprintf(vis_stdout,"No file has been read in.\n"); |
---|
2973 | return NIL(char); |
---|
2974 | } |
---|
2975 | rootNode = Hrc_ManagerReadRootNode(*hmgr); |
---|
2976 | separator = (char *) ((rootNode == currentNode) ? "" : "."); |
---|
2977 | hierarchicalName = Hrc_NodeFindHierarchicalName(currentNode, FALSE); |
---|
2978 | (void)fprintf(vis_stdout,"%s%s%s\n", Hrc_NodeReadInstanceName(rootNode), |
---|
2979 | separator, hierarchicalName); |
---|
2980 | (void) sprintf(currentPath, "%s%s%s", Hrc_NodeReadInstanceName(rootNode), separator, hierarchicalName); |
---|
2981 | FREE(hierarchicalName); |
---|
2982 | return currentPath; |
---|
2983 | |
---|
2984 | usage: |
---|
2985 | (void)fprintf(vis_stderr,"usage: pwd [-h]\n"); |
---|
2986 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
2987 | return NIL(char); |
---|
2988 | |
---|
2989 | } |
---|
2990 | |
---|
2991 | |
---|
2992 | /**Function******************************************************************** |
---|
2993 | |
---|
2994 | Synopsis [] |
---|
2995 | |
---|
2996 | Description [Refer to 'static int CommandPrintLatches (Hrc_Manager_t **hmgr, |
---|
2997 | int argc, char **argv)' function in hrcCmd.c] |
---|
2998 | |
---|
2999 | SideEffects [] |
---|
3000 | |
---|
3001 | SeeAlso [] |
---|
3002 | |
---|
3003 | ******************************************************************************/ |
---|
3004 | static int print_latchesMine(Hrc_Manager_t **hmgr, int argc, char **argv){ |
---|
3005 | |
---|
3006 | (void) fprintf(vis_stderr, "*** 'print_latches' begins. *** \n"); |
---|
3007 | |
---|
3008 | int c, i; |
---|
3009 | Hrc_Node_t *node; |
---|
3010 | st_generator *gen; |
---|
3011 | char *latchName; |
---|
3012 | Hrc_Latch_t *latch; |
---|
3013 | array_t *tmpArray; |
---|
3014 | |
---|
3015 | util_getopt_reset(); |
---|
3016 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
3017 | switch(c){ |
---|
3018 | case 'h': |
---|
3019 | goto usage; |
---|
3020 | default: |
---|
3021 | goto usage; |
---|
3022 | } |
---|
3023 | } |
---|
3024 | /* if there are some arguments left */ |
---|
3025 | if (argc != util_optind){ |
---|
3026 | goto usage; |
---|
3027 | } |
---|
3028 | node = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
3029 | if (node == NIL(Hrc_Node_t)){ |
---|
3030 | (void)fprintf(vis_stderr,"No file has been read in.\n"); |
---|
3031 | return 1; |
---|
3032 | } |
---|
3033 | |
---|
3034 | if (Hrc_NodeReadNumLatches(node) == 0){ |
---|
3035 | fprintf(vis_stdout,"No latches\n"); |
---|
3036 | } |
---|
3037 | else { |
---|
3038 | tmpArray = array_alloc(char *,0); |
---|
3039 | Hrc_NodeForEachLatch(node,gen,latchName,latch){ |
---|
3040 | array_insert_last(char *,tmpArray,latchName); |
---|
3041 | } |
---|
3042 | array_sort(tmpArray,_HrcStringCmp); |
---|
3043 | for (i=0; i < array_n(tmpArray); i++){ |
---|
3044 | fprintf(vis_stdout,"%s ",array_fetch(char *,tmpArray,i)); |
---|
3045 | } |
---|
3046 | fprintf(vis_stdout,"\n"); |
---|
3047 | array_free(tmpArray); |
---|
3048 | } |
---|
3049 | return 0; |
---|
3050 | |
---|
3051 | usage: |
---|
3052 | (void) fprintf(vis_stderr,"usage: print_latches [-h]\n"); |
---|
3053 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
3054 | return 1; |
---|
3055 | } |
---|
3056 | |
---|
3057 | /**Function******************************************************************** |
---|
3058 | |
---|
3059 | Synopsis [Converts a string to an order type.] |
---|
3060 | |
---|
3061 | Description [Converts a string to an order type. If string does not refer to |
---|
3062 | one of the allowed order types, then returns Ord_Unassigned_c.] |
---|
3063 | |
---|
3064 | SideEffects [] |
---|
3065 | |
---|
3066 | ******************************************************************************/ |
---|
3067 | static Ord_OrderType |
---|
3068 | StringConvertToOrderType( |
---|
3069 | char *string) |
---|
3070 | { |
---|
3071 | if (strcmp("all", string) == 0) { |
---|
3072 | return Ord_All_c; |
---|
3073 | } |
---|
3074 | else if (strcmp("input_and_latch", string) == 0) { |
---|
3075 | return Ord_InputAndLatch_c; |
---|
3076 | } |
---|
3077 | else if (strcmp("next_state_node", string) == 0) { |
---|
3078 | return Ord_NextStateNode_c; |
---|
3079 | } |
---|
3080 | else if (strcmp("partial", string) == 0) { |
---|
3081 | return Ord_Partial_c; |
---|
3082 | } |
---|
3083 | else { |
---|
3084 | return Ord_Unassigned_c; |
---|
3085 | } |
---|
3086 | } |
---|
3087 | |
---|
3088 | |
---|
3089 | /**Function******************************************************************** |
---|
3090 | |
---|
3091 | Synopsis [The core routine for the command ls.] |
---|
3092 | |
---|
3093 | Description [The core routine for the command ls. If the second argument |
---|
3094 | is set to 1, it calls the ls routine recursively all the way down to leaves.] |
---|
3095 | |
---|
3096 | SideEffects [] |
---|
3097 | |
---|
3098 | SeeAlso [] |
---|
3099 | |
---|
3100 | ******************************************************************************/ |
---|
3101 | static void |
---|
3102 | NodeListChildren( |
---|
3103 | Hrc_Node_t *hnode, |
---|
3104 | boolean recursiveFlag, |
---|
3105 | int depth) |
---|
3106 | { |
---|
3107 | st_generator *gen; |
---|
3108 | char *childName; |
---|
3109 | Hrc_Node_t *child; |
---|
3110 | int newDepth, i; |
---|
3111 | array_t *tmpArray; |
---|
3112 | |
---|
3113 | newDepth = depth + 1; |
---|
3114 | tmpArray = array_alloc(char *,0); |
---|
3115 | Hrc_NodeForEachChild(hnode,gen,childName,child){ |
---|
3116 | array_insert_last(char *,tmpArray,childName); |
---|
3117 | } |
---|
3118 | array_sort(tmpArray,_HrcStringCmp); |
---|
3119 | for (i=0; i < array_n(tmpArray); i++){ |
---|
3120 | PrintSpace(depth); |
---|
3121 | childName = array_fetch(char *,tmpArray,i); |
---|
3122 | (void)fprintf(vis_stdout,"%s\n",childName); |
---|
3123 | if (recursiveFlag == 1){ |
---|
3124 | NodeListChildren(Hrc_NodeFindChildByName(hnode,childName),recursiveFlag,newDepth); |
---|
3125 | } |
---|
3126 | } |
---|
3127 | array_free(tmpArray); |
---|
3128 | } |
---|
3129 | |
---|
3130 | /**Function******************************************************************** |
---|
3131 | |
---|
3132 | Synopsis [The core routine for the command ls. Returns array_t] |
---|
3133 | |
---|
3134 | Description [The core routine for the command ls. If the second argument |
---|
3135 | is set to 1, it calls the ls routine recursively all the way down to leaves.] |
---|
3136 | |
---|
3137 | SideEffects [] |
---|
3138 | |
---|
3139 | SeeAlso [] |
---|
3140 | |
---|
3141 | ******************************************************************************/ |
---|
3142 | static array_t *NodeListChildrenMine(Hrc_Node_t *hnode, boolean recursiveFlag, int depth){ |
---|
3143 | |
---|
3144 | st_generator *gen; |
---|
3145 | char *childName; |
---|
3146 | Hrc_Node_t *child; |
---|
3147 | int newDepth, i; |
---|
3148 | array_t *tmpArray; |
---|
3149 | |
---|
3150 | newDepth = depth + 1; |
---|
3151 | tmpArray = array_alloc(char *,0); |
---|
3152 | Hrc_NodeForEachChild(hnode,gen,childName,child){ |
---|
3153 | array_insert_last(char *,tmpArray,childName); |
---|
3154 | } |
---|
3155 | array_sort(tmpArray,_HrcStringCmp); |
---|
3156 | for (i=0; i < array_n(tmpArray); i++){ |
---|
3157 | PrintSpace(depth); |
---|
3158 | childName = array_fetch(char *,tmpArray,i); |
---|
3159 | (void)fprintf(vis_stdout,"%s\n",childName); |
---|
3160 | if (recursiveFlag == 1){ |
---|
3161 | NodeListChildren(Hrc_NodeFindChildByName(hnode,childName),recursiveFlag,newDepth); |
---|
3162 | } |
---|
3163 | } |
---|
3164 | // array_free(tmpArray); |
---|
3165 | return tmpArray; |
---|
3166 | } |
---|
3167 | |
---|
3168 | /**Function******************************************************************** |
---|
3169 | |
---|
3170 | Synopsis [Prints out spaces.] |
---|
3171 | |
---|
3172 | SideEffects [] |
---|
3173 | |
---|
3174 | SeeAlso [] |
---|
3175 | |
---|
3176 | ******************************************************************************/ |
---|
3177 | static void |
---|
3178 | PrintSpace(int depth) |
---|
3179 | { |
---|
3180 | int i; |
---|
3181 | for (i=0; i < depth; i++){ |
---|
3182 | (void)fprintf(vis_stdout," "); |
---|
3183 | } |
---|
3184 | } |
---|
3185 | |
---|
3186 | |
---|
3187 | /**Function******************************************************************** |
---|
3188 | |
---|
3189 | Synopsis [Verifies that suppliedNodeList has the correct nodes.] |
---|
3190 | |
---|
3191 | Description [Returns TRUE if the set of nodes in suppliedNodeList matches |
---|
3192 | the set of nodes in network specified by orderType; else returns FALSE and |
---|
3193 | writes a message to error_string. OrderType should be one of the following: |
---|
3194 | 1) Ord_All_c: should match the set of all nodes in network; 2) |
---|
3195 | Ord_InputAndLatch_c: should match the set of inputs (primary + pseudo), |
---|
3196 | latches, and next state nodes; 3) Ord_NextStateNode_c: should match the set |
---|
3197 | of next state nodes; number should be the number of latches; 4) |
---|
3198 | Ord_Partial_c: returns TRUE automatically.] |
---|
3199 | |
---|
3200 | SideEffects [] |
---|
3201 | |
---|
3202 | ******************************************************************************/ |
---|
3203 | static boolean |
---|
3204 | NetworkCheckSuppliedNodeList( |
---|
3205 | Ntk_Network_t * network, |
---|
3206 | lsList suppliedNodeList, |
---|
3207 | Ord_OrderType orderType) |
---|
3208 | { |
---|
3209 | lsGen gen; |
---|
3210 | st_generator *stGen; |
---|
3211 | Ntk_Node_t *node; |
---|
3212 | st_table *requiredNodes; |
---|
3213 | st_table *suppliedNodes; |
---|
3214 | char *dummy; |
---|
3215 | boolean returnFlag = TRUE; |
---|
3216 | |
---|
3217 | assert(orderType != Ord_Unassigned_c); |
---|
3218 | |
---|
3219 | if (orderType == Ord_Partial_c) { |
---|
3220 | return TRUE; |
---|
3221 | } |
---|
3222 | |
---|
3223 | /* At this point, orderType must be one of the these. */ |
---|
3224 | assert((orderType == Ord_All_c) || (orderType == Ord_InputAndLatch_c) |
---|
3225 | || (orderType == Ord_NextStateNode_c)); |
---|
3226 | |
---|
3227 | |
---|
3228 | /* |
---|
3229 | * Build up the table of required nodes. Next state nodes are included by |
---|
3230 | * all 3 order types. |
---|
3231 | */ |
---|
3232 | requiredNodes = st_init_table(st_ptrcmp, st_ptrhash); |
---|
3233 | Ntk_NetworkForEachNode(network, gen, node) { |
---|
3234 | if ((orderType == Ord_All_c) || Ntk_NodeTestIsNextStateNode(node)) { |
---|
3235 | st_insert(requiredNodes, (char *) node, NIL(char)); |
---|
3236 | } |
---|
3237 | else if ((orderType == Ord_InputAndLatch_c) |
---|
3238 | && Ntk_NodeTestIsCombInput(node)) { |
---|
3239 | st_insert(requiredNodes, (char *) node, NIL(char)); |
---|
3240 | } |
---|
3241 | /* else, this node is not included by orderType */ |
---|
3242 | } |
---|
3243 | |
---|
3244 | /* |
---|
3245 | * Convert suppliedNodeList to the table of supplied nodes. |
---|
3246 | */ |
---|
3247 | suppliedNodes = st_init_table(st_ptrcmp, st_ptrhash); |
---|
3248 | lsForEachItem(suppliedNodeList, gen, node) { |
---|
3249 | int status = st_insert(suppliedNodes, (char *) node, NIL(char)); |
---|
3250 | if (status) { |
---|
3251 | error_append("node "); |
---|
3252 | error_append(Ntk_NodeReadName(node)); |
---|
3253 | error_append(" appears more than once in ordering file\n"); |
---|
3254 | returnFlag = FALSE; |
---|
3255 | } |
---|
3256 | } |
---|
3257 | |
---|
3258 | /* |
---|
3259 | * Check that suppliedNodes is contained in requiredNodes. |
---|
3260 | */ |
---|
3261 | st_foreach_item(suppliedNodes, stGen, &node, &dummy) { |
---|
3262 | if (!st_is_member(requiredNodes, node)) { |
---|
3263 | error_append("node "); |
---|
3264 | error_append(Ntk_NodeReadName(node)); |
---|
3265 | error_append(" supplied but not required\n"); |
---|
3266 | returnFlag = FALSE; |
---|
3267 | } |
---|
3268 | } |
---|
3269 | |
---|
3270 | /* |
---|
3271 | * Check that suppliedNodes is contained in requiredNodes. |
---|
3272 | */ |
---|
3273 | st_foreach_item(requiredNodes, stGen, &node, &dummy) { |
---|
3274 | if (!st_is_member(suppliedNodes, node)) { |
---|
3275 | error_append("node "); |
---|
3276 | error_append(Ntk_NodeReadName(node)); |
---|
3277 | error_append(" required but not supplied\n"); |
---|
3278 | returnFlag = FALSE; |
---|
3279 | } |
---|
3280 | } |
---|
3281 | |
---|
3282 | st_free_table(requiredNodes); |
---|
3283 | st_free_table(suppliedNodes); |
---|
3284 | return returnFlag; |
---|
3285 | } |
---|
3286 | |
---|
3287 | /**Function******************************************************************** |
---|
3288 | |
---|
3289 | Synopsis [Returns a list of names corresponding to the names in a file.] |
---|
3290 | |
---|
3291 | Description [Parses a file and builds a name list corresponding to the names |
---|
3292 | found in the first "column" of each line of the file. Any line starting |
---|
3293 | with the comment character '#' or white space is ignored. No checks are |
---|
3294 | made to see if the names are well-formed in any respect. If a problem is |
---|
3295 | found while parsing the file (e.g. name length exceeded), then a message is |
---|
3296 | written to error_string, the partial name list is freed, and the function |
---|
3297 | returns FALSE; otherwise, it returns TRUE, and a pointer to a list is |
---|
3298 | returned.] |
---|
3299 | |
---|
3300 | Comment [The parser consists of 3 states. See the documentation |
---|
3301 | accompanying the #defines defining the state names. This code was adapted |
---|
3302 | from Ord_FileReadNodeList.] |
---|
3303 | |
---|
3304 | SideEffects [] |
---|
3305 | |
---|
3306 | ******************************************************************************/ |
---|
3307 | static boolean |
---|
3308 | FileReadNameList( |
---|
3309 | FILE * fp, |
---|
3310 | lsList * nameList /* of char *, for return */, |
---|
3311 | int verbose) |
---|
3312 | { |
---|
3313 | int c; |
---|
3314 | int state; |
---|
3315 | int curPosition = 0; |
---|
3316 | char *name; |
---|
3317 | char string[MAX_NAME_LENGTH]; |
---|
3318 | boolean returnFlag = TRUE; |
---|
3319 | |
---|
3320 | *nameList = lsCreate(); |
---|
3321 | |
---|
3322 | state = STATE_TEST; |
---|
3323 | while ((c = fgetc(fp)) != EOF) { |
---|
3324 | |
---|
3325 | switch (state) { |
---|
3326 | case STATE_TEST: |
---|
3327 | /* At start of a new line. */ |
---|
3328 | if (c == '#') { |
---|
3329 | /* Line starting with comment character; wait for newline */ |
---|
3330 | state = STATE_WAIT; |
---|
3331 | } |
---|
3332 | else if ((c == ' ') || (c == '\t')) { |
---|
3333 | /* Line starting with white space; wait for newline */ |
---|
3334 | state = STATE_WAIT; |
---|
3335 | } |
---|
3336 | else if (c == '\n') { |
---|
3337 | /* Line starting with newline; go to next line */ |
---|
3338 | state = STATE_TEST; |
---|
3339 | } |
---|
3340 | else { |
---|
3341 | /* Assume starting a name. */ |
---|
3342 | curPosition = 0; |
---|
3343 | string[curPosition++] = c; |
---|
3344 | state = STATE_IN; |
---|
3345 | } |
---|
3346 | break; |
---|
3347 | case STATE_WAIT: |
---|
3348 | /* |
---|
3349 | * Waiting for the newline character. |
---|
3350 | */ |
---|
3351 | state = (c == '\n') ? STATE_TEST : STATE_WAIT; |
---|
3352 | break; |
---|
3353 | case STATE_IN: |
---|
3354 | /* |
---|
3355 | * Parsing a name. If white space reached, then terminate the |
---|
3356 | * name and process it. Else, continue parsing. |
---|
3357 | */ |
---|
3358 | if ((c == ' ') || (c == '\n') || (c == '\t')) { |
---|
3359 | string[curPosition] = '\0'; |
---|
3360 | name = util_strsav(string); |
---|
3361 | if (verbose > 1) { |
---|
3362 | (void) fprintf(vis_stdout, "Reading name: %s\n", name); |
---|
3363 | } |
---|
3364 | (void) lsNewEnd(*nameList, (lsGeneric) name, LS_NH); |
---|
3365 | |
---|
3366 | state = (c == '\n') ? STATE_TEST : STATE_WAIT; |
---|
3367 | } |
---|
3368 | else { |
---|
3369 | string[curPosition++] = c; |
---|
3370 | if (curPosition >= MAX_NAME_LENGTH) { |
---|
3371 | error_append("maximum name length exceeded"); |
---|
3372 | returnFlag = FALSE; |
---|
3373 | } |
---|
3374 | state = STATE_IN; /* redundant, but be explicit */ |
---|
3375 | } |
---|
3376 | break; |
---|
3377 | default: |
---|
3378 | fail("unrecognized state"); |
---|
3379 | } |
---|
3380 | } |
---|
3381 | |
---|
3382 | /* |
---|
3383 | * Handle case where EOF terminates a name. |
---|
3384 | */ |
---|
3385 | if (state == STATE_IN) { |
---|
3386 | string[curPosition] = '\0'; |
---|
3387 | name = util_strsav(string); |
---|
3388 | if (verbose > 1) { |
---|
3389 | (void) fprintf(vis_stdout, "Reading name: %s\n", name); |
---|
3390 | } |
---|
3391 | (void) lsNewEnd(*nameList, (lsGeneric) name, LS_NH); |
---|
3392 | |
---|
3393 | } |
---|
3394 | |
---|
3395 | if (returnFlag) { |
---|
3396 | return TRUE; |
---|
3397 | } |
---|
3398 | else { |
---|
3399 | (void) lsDestroy(*nameList, (void (*) (lsGeneric)) NULL); |
---|
3400 | return FALSE; |
---|
3401 | } |
---|
3402 | } |
---|
3403 | |
---|
3404 | /**Function******************************************************************** |
---|
3405 | |
---|
3406 | Synopsis [Initilizes all the global variables used in the parser.] |
---|
3407 | |
---|
3408 | Description [] |
---|
3409 | |
---|
3410 | SideEffects [] |
---|
3411 | |
---|
3412 | SeeAlso [] |
---|
3413 | |
---|
3414 | ******************************************************************************/ |
---|
3415 | static void |
---|
3416 | _IoGlobalVariablesInitialize(void) |
---|
3417 | { |
---|
3418 | globalLineNumber = 1; |
---|
3419 | globalModel = NIL(Hrc_Model_t); |
---|
3420 | globalHnode = NIL(Hrc_Node_t); |
---|
3421 | globalFirstModel = NIL(Hrc_Model_t); /* set once */ |
---|
3422 | globalRootModel = NIL(Hrc_Model_t); /* set once */ |
---|
3423 | globalRootInstanceName = NIL(char); /* set once */ |
---|
3424 | globalMvNameArray = NIL(array_t); |
---|
3425 | globalSymValueArray = NIL(array_t); |
---|
3426 | globalTableInputArray = NIL(array_t); |
---|
3427 | globalTableOutputArray = NIL(array_t); |
---|
3428 | globalTableDefaultArray = NIL(array_t); |
---|
3429 | globalTableSymCubeArray = NIL(array_t); |
---|
3430 | globalFormalNameArray = NIL(array_t); |
---|
3431 | globalActualNameArray = NIL(array_t); |
---|
3432 | |
---|
3433 | globalSubcktArray = NIL(array_t); |
---|
3434 | globalResetArray = NIL(array_t); |
---|
3435 | |
---|
3436 | globalNewModelArray = array_alloc(Hrc_Model_t *,0); |
---|
3437 | |
---|
3438 | globalCurrentStackDepth = 0; |
---|
3439 | |
---|
3440 | /* a hash table from a model name to an array of resets/subcircuits in the model */ |
---|
3441 | globalParserResetInfo = st_init_table(st_ptrcmp,st_ptrhash); |
---|
3442 | globalParserSubcktInfo = st_init_table(st_ptrcmp,st_ptrhash); |
---|
3443 | } |
---|
3444 | |
---|
3445 | /**Function******************************************************************** |
---|
3446 | |
---|
3447 | Synopsis [Frees all the global data structures used in the parser.] |
---|
3448 | |
---|
3449 | Description [] |
---|
3450 | |
---|
3451 | SideEffects [] |
---|
3452 | |
---|
3453 | SeeAlso [] |
---|
3454 | |
---|
3455 | ******************************************************************************/ |
---|
3456 | static void |
---|
3457 | _IoGlobalVariablesFree(void) |
---|
3458 | { |
---|
3459 | array_free(globalNewModelArray); |
---|
3460 | _IoGlobalResetInfoFree(); |
---|
3461 | _IoGlobalSubcktInfoFree(); |
---|
3462 | } |
---|
3463 | |
---|
3464 | |
---|
3465 | /**Function******************************************************************** |
---|
3466 | |
---|
3467 | Synopsis [Frees the subckt information only used by the parser.] |
---|
3468 | |
---|
3469 | Description [] |
---|
3470 | |
---|
3471 | SideEffects [] |
---|
3472 | |
---|
3473 | SeeAlso [] |
---|
3474 | |
---|
3475 | ******************************************************************************/ |
---|
3476 | static void |
---|
3477 | _IoGlobalSubcktInfoFree(void) |
---|
3478 | { |
---|
3479 | st_generator *gen; |
---|
3480 | char *key, *val; |
---|
3481 | |
---|
3482 | st_foreach_item(globalParserSubcktInfo,gen,&key,&val){ |
---|
3483 | if ((array_t *)val != NIL(array_t)){ |
---|
3484 | _IoSubcktArrayFree((array_t *)val); |
---|
3485 | } |
---|
3486 | } |
---|
3487 | st_free_table(globalParserSubcktInfo); |
---|
3488 | } |
---|
3489 | |
---|
3490 | |
---|
3491 | /**Function******************************************************************** |
---|
3492 | |
---|
3493 | Synopsis [Frees an array of the subckt data structure only used by the parser.] |
---|
3494 | |
---|
3495 | Description [] |
---|
3496 | |
---|
3497 | SideEffects [] |
---|
3498 | |
---|
3499 | SeeAlso [] |
---|
3500 | |
---|
3501 | ******************************************************************************/ |
---|
3502 | static void |
---|
3503 | _IoSubcktArrayFree(array_t *array) |
---|
3504 | { |
---|
3505 | int i; |
---|
3506 | |
---|
3507 | for (i=0; i < array_n(array); i++){ |
---|
3508 | _IoSubcktFree(array_fetch(IoSubckt_t *,array,i)); |
---|
3509 | } |
---|
3510 | array_free(array); |
---|
3511 | } |
---|
3512 | |
---|
3513 | /**Function******************************************************************** |
---|
3514 | |
---|
3515 | Synopsis [Frees the subckt data structure used by the parser.] |
---|
3516 | |
---|
3517 | Description [] |
---|
3518 | |
---|
3519 | SideEffects [] |
---|
3520 | |
---|
3521 | SeeAlso [] |
---|
3522 | |
---|
3523 | ******************************************************************************/ |
---|
3524 | static void |
---|
3525 | _IoSubcktFree(IoSubckt_t *subckt) |
---|
3526 | { |
---|
3527 | FREE(subckt->modelName); |
---|
3528 | FREE(subckt->instanceName); |
---|
3529 | IoStringArrayFree(subckt->formalNameArray); |
---|
3530 | IoStringArrayFree(subckt->actualNameArray); |
---|
3531 | FREE(subckt); |
---|
3532 | } |
---|
3533 | |
---|
3534 | |
---|
3535 | /**Function******************************************************************** |
---|
3536 | |
---|
3537 | Synopsis [Frees the reset data structure used only by the parser.] |
---|
3538 | |
---|
3539 | Description [] |
---|
3540 | |
---|
3541 | SideEffects [] |
---|
3542 | |
---|
3543 | SeeAlso [] |
---|
3544 | |
---|
3545 | ******************************************************************************/ |
---|
3546 | static void |
---|
3547 | _IoGlobalResetInfoFree(void) |
---|
3548 | { |
---|
3549 | st_generator *gen; |
---|
3550 | char *key, *val; |
---|
3551 | int i; |
---|
3552 | Tbl_Table_t *resetTable; |
---|
3553 | |
---|
3554 | st_foreach_item(globalParserResetInfo,gen,&key,&val){ |
---|
3555 | if ((array_t *)val != NIL(array_t)){ |
---|
3556 | for (i=0; i < array_n((array_t *)val); i++){ |
---|
3557 | resetTable = array_fetch(Tbl_Table_t *,(array_t *)val,i); |
---|
3558 | if (resetTable != NIL(Tbl_Table_t)){ |
---|
3559 | Tbl_TableFree(resetTable); |
---|
3560 | } |
---|
3561 | } |
---|
3562 | array_free((array_t *)val); |
---|
3563 | } |
---|
3564 | } |
---|
3565 | st_free_table(globalParserResetInfo); |
---|
3566 | } |
---|
3567 | |
---|
3568 | |
---|
3569 | /**Function******************************************************************** |
---|
3570 | |
---|
3571 | Synopsis [Checks if two hnodes are compatible with respect to their input |
---|
3572 | or output interface depending on the last boolean flag.] |
---|
3573 | |
---|
3574 | Description [Checks if two hnodes are compatible with respect to their input |
---|
3575 | or output interface depending on the last boolean flag. 0 for input and 1 |
---|
3576 | for output.] |
---|
3577 | |
---|
3578 | SideEffects [] |
---|
3579 | |
---|
3580 | SeeAlso [] |
---|
3581 | |
---|
3582 | ******************************************************************************/ |
---|
3583 | static boolean |
---|
3584 | _IoNodeTestCompatibilityAux( |
---|
3585 | Hrc_Manager_t *hmgr, |
---|
3586 | Hrc_Node_t *hnode1, |
---|
3587 | Hrc_Node_t *hnode2, |
---|
3588 | boolean mode) |
---|
3589 | { |
---|
3590 | int i, n; |
---|
3591 | array_t *formalVars1, *formalVars2; |
---|
3592 | Var_Variable_t *var1, *var2; |
---|
3593 | |
---|
3594 | if (mode == 0){ |
---|
3595 | formalVars1 = Hrc_NodeReadFormalInputs(hnode1); |
---|
3596 | formalVars2 = Hrc_NodeReadFormalInputs(hnode2); |
---|
3597 | } |
---|
3598 | else { |
---|
3599 | formalVars1 = Hrc_NodeReadFormalOutputs(hnode1); |
---|
3600 | formalVars2 = Hrc_NodeReadFormalOutputs(hnode2); |
---|
3601 | } |
---|
3602 | if ((n = array_n(formalVars1)) != array_n(formalVars2)){ |
---|
3603 | error_append("Two hnodes have different number of formal "); |
---|
3604 | if (mode == 0){ |
---|
3605 | error_append("inputs.\n"); |
---|
3606 | } |
---|
3607 | else { |
---|
3608 | error_append("outputs.\n"); |
---|
3609 | } |
---|
3610 | return 0; |
---|
3611 | } |
---|
3612 | for (i=0; i < n; i++){ |
---|
3613 | var1 = array_fetch(Var_Variable_t *,formalVars1,i); |
---|
3614 | var2 = array_fetch(Var_Variable_t *,formalVars2,i); |
---|
3615 | if (strcmp(Var_VariableReadName(var1),Var_VariableReadName(var2)) != 0){ |
---|
3616 | error_append("Two hnodes have different ports, "); |
---|
3617 | error_append(Var_VariableReadName(var1)); |
---|
3618 | error_append(" and "); |
---|
3619 | error_append(Var_VariableReadName(var2)); |
---|
3620 | error_append("\n"); |
---|
3621 | return 0; |
---|
3622 | } |
---|
3623 | if (Var_VariablesTestHaveSameDomain(var1,var2) == 0){ |
---|
3624 | error_append("Two hnodes have ports defined over different domains, "); |
---|
3625 | error_append(Var_VariableReadName(var1)); |
---|
3626 | error_append(" and "); |
---|
3627 | error_append(Var_VariableReadName(var2)); |
---|
3628 | error_append("\n"); |
---|
3629 | return 0; |
---|
3630 | } |
---|
3631 | } |
---|
3632 | return 1; |
---|
3633 | } |
---|
3634 | |
---|
3635 | |
---|
3636 | /**Function******************************************************************** |
---|
3637 | |
---|
3638 | Synopsis [Canonicalizes all the tables in a given manager using |
---|
3639 | Tbl_TableCanonicalize().] |
---|
3640 | |
---|
3641 | SideEffects [The original tables will be overwritten.] |
---|
3642 | |
---|
3643 | SeeAlso [] |
---|
3644 | |
---|
3645 | ******************************************************************************/ |
---|
3646 | static void |
---|
3647 | _IoManagerCanonicalize( |
---|
3648 | Hrc_Manager_t *hmgr) |
---|
3649 | { |
---|
3650 | int i; |
---|
3651 | Hrc_Model_t *model; |
---|
3652 | Hrc_Node_t *node; |
---|
3653 | Tbl_Table_t *table; |
---|
3654 | st_generator *gen, *gen2; |
---|
3655 | char *modelName, *latchName; |
---|
3656 | Hrc_Latch_t *latch; |
---|
3657 | |
---|
3658 | Hrc_ManagerForEachModel(hmgr,gen,modelName,model){ |
---|
3659 | node = Hrc_ModelReadMasterNode(model); |
---|
3660 | Hrc_NodeForEachNameTable(node,i,table){ |
---|
3661 | Tbl_TableCanonicalize(table); |
---|
3662 | } |
---|
3663 | Hrc_NodeForEachLatch(node,gen2,latchName,latch){ |
---|
3664 | Tbl_TableCanonicalize(Hrc_LatchReadResetTable(latch)); |
---|
3665 | } |
---|
3666 | } |
---|
3667 | } |
---|
3668 | |
---|
3669 | |
---|
3670 | /**Function******************************************************************** |
---|
3671 | |
---|
3672 | Synopsis [Handle function for timeout.] |
---|
3673 | |
---|
3674 | Description [This function is called when the time out occurs. |
---|
3675 | Since alarm is set with an elapsed time, this function checks if the |
---|
3676 | CPU time corresponds to the timeout of the command. If not, it |
---|
3677 | reprograms the alarm to fire again later.] |
---|
3678 | |
---|
3679 | SideEffects [] |
---|
3680 | |
---|
3681 | ******************************************************************************/ |
---|
3682 | static void |
---|
3683 | TimeOutHandle(void) |
---|
3684 | { |
---|
3685 | int seconds = (int) ((util_cpu_ctime() - alarmLapTime) / 1000); |
---|
3686 | |
---|
3687 | if (seconds < mcTimeOut) { |
---|
3688 | unsigned slack = (unsigned) (mcTimeOut - seconds); |
---|
3689 | (void) signal(SIGALRM, (void(*)(int)) TimeOutHandle); |
---|
3690 | (void) alarm(slack); |
---|
3691 | } else { |
---|
3692 | longjmp(timeOutEnv, 1); |
---|
3693 | } |
---|
3694 | } /* TimeOutHandle */ |
---|
3695 | |
---|
3696 | |
---|
3697 | /**Function******************************************************************** |
---|
3698 | |
---|
3699 | Synopsis [] |
---|
3700 | |
---|
3701 | Description [] |
---|
3702 | |
---|
3703 | SideEffects [] |
---|
3704 | |
---|
3705 | SeeAlso [] |
---|
3706 | |
---|
3707 | ******************************************************************************/ |
---|
3708 | static int |
---|
3709 | nodenameCompare( |
---|
3710 | const void * node1, |
---|
3711 | const void * node2) |
---|
3712 | { |
---|
3713 | Ntk_Node_t *v1, *v2; |
---|
3714 | char *name1, *name2; |
---|
3715 | |
---|
3716 | v1 = *(Ntk_Node_t **)(node1); |
---|
3717 | v2 = *(Ntk_Node_t **)(node2); |
---|
3718 | name1 = Ntk_NodeReadName(v1); |
---|
3719 | name2 = Ntk_NodeReadName(v2); |
---|
3720 | |
---|
3721 | return (strcmp(name1, name2)); |
---|
3722 | } |
---|
3723 | |
---|
3724 | |
---|
3725 | /**Function******************************************************************** |
---|
3726 | |
---|
3727 | Synopsis [This function is used for string comparison in array_sort.] |
---|
3728 | |
---|
3729 | Description [This function is used for string comparison in array_sort.] |
---|
3730 | |
---|
3731 | SideEffects [] |
---|
3732 | |
---|
3733 | SeeAlso [] |
---|
3734 | |
---|
3735 | ******************************************************************************/ |
---|
3736 | static int |
---|
3737 | _HrcStringCmp( |
---|
3738 | const void * s1, |
---|
3739 | const void * s2) |
---|
3740 | { |
---|
3741 | return(strcmp(*(char **)s1, *(char **)s2)); |
---|
3742 | } |
---|
3743 | |
---|
3744 | |
---|
3745 | /**Function******************************************************************** |
---|
3746 | |
---|
3747 | Synopsis [Prints whether model checking passed or failed] |
---|
3748 | |
---|
3749 | Description [Prints whether model checking passed or failed, and if |
---|
3750 | requested, a debug trace.] |
---|
3751 | |
---|
3752 | SideEffects [] |
---|
3753 | |
---|
3754 | ******************************************************************************/ |
---|
3755 | static boolean |
---|
3756 | McPrintPassFailMine( |
---|
3757 | mdd_manager *mddMgr, |
---|
3758 | Fsm_Fsm_t *modelFsm, |
---|
3759 | Mc_FwdBwdAnalysis traversalDirection, |
---|
3760 | Ctlp_Formula_t *ctlFormula, |
---|
3761 | mdd_t *ctlFormulaStates, |
---|
3762 | mdd_t *modelInitialStates, |
---|
3763 | array_t *modelCareStatesArray, |
---|
3764 | McOptions_t *options, |
---|
3765 | Mc_VerbosityLevel verbosity) |
---|
3766 | { |
---|
3767 | (void) fprintf(vis_stdout, "![McPrintPassFailMine] Original CTL Formula : "); |
---|
3768 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
3769 | (void) fprintf(vis_stdout, "\n![McPrintPassFailMine] MC CTL Formula : "); |
---|
3770 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
3771 | fprintf(vis_stdout, "\n"); |
---|
3772 | if (mdd_lequal(modelInitialStates, ctlFormulaStates, 1, 1)) { |
---|
3773 | fprintf(vis_stdout, "# MC: formula passed --- "); |
---|
3774 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
3775 | fprintf(vis_stdout, "\n"); |
---|
3776 | return TRUE; |
---|
3777 | } |
---|
3778 | else { |
---|
3779 | fprintf(vis_stdout, "# MC: formula failed --- "); |
---|
3780 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
3781 | fprintf(vis_stdout, "\n"); |
---|
3782 | if (McOptionsReadDbgLevel(options) != McDbgLevelNone_c) { |
---|
3783 | McFsmDebugFormulaMine(options, ctlFormula,modelFsm, modelCareStatesArray); |
---|
3784 | } |
---|
3785 | return FALSE; |
---|
3786 | } |
---|
3787 | } |
---|
3788 | |
---|
3789 | |
---|
3790 | /**Function******************************************************************** |
---|
3791 | |
---|
3792 | Synopsis [Debug CTL formula in existential normal form] |
---|
3793 | |
---|
3794 | Description [Debug CTL formula in existential normal form. The extent to |
---|
3795 | which debug information is generated is a function of options settings. |
---|
3796 | |
---|
3797 | The debugger works with ctlFormula, but uses the pointers back to |
---|
3798 | the original formula that it was converted from, to give the user |
---|
3799 | more sensible feedback. To do this, it relies on a specific |
---|
3800 | translation: only EF, AU, AF, AG, and AX are converted. Hence, the |
---|
3801 | only times that the converted bit is set, we have a conversion of |
---|
3802 | one of these formulas, and the operator is either EU, or negation. |
---|
3803 | in the latter case, we can conclude from the child of the negation |
---|
3804 | what formula we converted from: EX means AX, EG means AF, EU means AG, |
---|
3805 | and OR means AU. |
---|
3806 | ] |
---|
3807 | |
---|
3808 | SideEffects [Affects vis_stdpipe] |
---|
3809 | |
---|
3810 | SeeAlso [Ctlp_FormulaConvertToExistentialForm] |
---|
3811 | |
---|
3812 | ******************************************************************************/ |
---|
3813 | static int |
---|
3814 | McFsmDebugFormulaMine( |
---|
3815 | McOptions_t *options, |
---|
3816 | Ctlp_Formula_t *ctlFormula, |
---|
3817 | Fsm_Fsm_t *modelFsm, |
---|
3818 | array_t *careSetArray) |
---|
3819 | { |
---|
3820 | (void) fprintf(vis_stdout, "![McFsmDebugFormulaMine] Original CTL Formula : "); |
---|
3821 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
3822 | (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] MC CTL Formula : "); |
---|
3823 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
3824 | fprintf(vis_stdout, "\n"); |
---|
3825 | mdd_t *modelInitialStates = Fsm_FsmComputeInitialStates(modelFsm); |
---|
3826 | mdd_t *goodStates = Ctlp_FormulaObtainLatestApprox(ctlFormula); |
---|
3827 | mdd_t *badStates = mdd_and(modelInitialStates, goodStates, 1, 0); |
---|
3828 | mdd_t *witnessSuccState; |
---|
3829 | FILE *debugFile = McOptionsReadDebugFile(options); |
---|
3830 | FILE *oldStdOut; |
---|
3831 | FILE *oldStdErr; |
---|
3832 | extern FILE *vis_stdpipe; |
---|
3833 | char *nrOfTracesString; |
---|
3834 | int nrOfTraces; /* nr of debug traces that we output */ |
---|
3835 | int i; /* counts debug traces */ |
---|
3836 | array_t *completeCExArray; |
---|
3837 | array_t *initCExArray; |
---|
3838 | initCExArray = array_alloc(mdd_t *, 0); |
---|
3839 | |
---|
3840 | mdd_free(modelInitialStates); |
---|
3841 | |
---|
3842 | oldStdOut = vis_stdout; |
---|
3843 | oldStdErr = vis_stderr; |
---|
3844 | |
---|
3845 | nrOfTracesString = Cmd_FlagReadByName("nr_counterexamples"); |
---|
3846 | if(nrOfTracesString == NIL(char)) |
---|
3847 | nrOfTraces = 1; |
---|
3848 | else |
---|
3849 | nrOfTraces = atoi(nrOfTracesString); |
---|
3850 | |
---|
3851 | (void) fprintf(vis_stderr, "[McFsmDebugFormulaMine] Number of debug traces = %d \n", nrOfTraces); |
---|
3852 | |
---|
3853 | if (debugFile) { |
---|
3854 | vis_stdpipe = debugFile; |
---|
3855 | vis_stdout = vis_stdpipe; |
---|
3856 | (void)fprintf(vis_stdpipe, "# MC: formula failed --- "); |
---|
3857 | Ctlp_FormulaPrint(vis_stdpipe,Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
3858 | (void)fprintf(vis_stdpipe, "\n"); |
---|
3859 | } else if (McOptionsReadUseMore(options)){ |
---|
3860 | vis_stdpipe = popen("more", "w"); |
---|
3861 | vis_stdout = vis_stdpipe; |
---|
3862 | vis_stderr = vis_stdpipe; |
---|
3863 | } |
---|
3864 | else |
---|
3865 | vis_stdpipe = vis_stdout; |
---|
3866 | |
---|
3867 | for(i = 0; i < nrOfTraces; i++){ |
---|
3868 | (void)fprintf(vis_stdout, "# MC: Calling debugger for trace %d\n", |
---|
3869 | i+1); |
---|
3870 | witnessSuccState = McComputeACloseState(badStates, goodStates, modelFsm); |
---|
3871 | |
---|
3872 | completeCExArray = McFsmStateDebugFormulaMine(options, ctlFormula, witnessSuccState, modelFsm, |
---|
3873 | careSetArray, initCExArray); |
---|
3874 | (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] -> nb completeCExArray : %d \n", array_n(completeCExArray)); |
---|
3875 | // (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] -> nb initCExArray : %d \n", array_n(initCExArray)); |
---|
3876 | |
---|
3877 | (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] START xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n"); |
---|
3878 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
3879 | Mc_PrintPathMine( completeCExArray, modelFsm, printInputs ); |
---|
3880 | (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] END xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n"); |
---|
3881 | |
---|
3882 | (void)fprintf(vis_stdout, "\n"); |
---|
3883 | |
---|
3884 | mdd_free(witnessSuccState); |
---|
3885 | } |
---|
3886 | mdd_free(badStates); |
---|
3887 | mdd_free(goodStates); |
---|
3888 | |
---|
3889 | if (vis_stdout != oldStdOut && vis_stdout != debugFile) |
---|
3890 | (void)pclose(vis_stdpipe); |
---|
3891 | |
---|
3892 | vis_stdout = oldStdOut; |
---|
3893 | vis_stderr = oldStdErr; |
---|
3894 | |
---|
3895 | return 1; |
---|
3896 | } |
---|
3897 | |
---|
3898 | |
---|
3899 | /**Function******************************************************************** |
---|
3900 | |
---|
3901 | Synopsis [Debug CTL formula in existential normal form at state aState] |
---|
3902 | |
---|
3903 | Description [Debug CTL formula in existential normal form at state |
---|
3904 | aState. Formula is assumed to have been CONVERTED to existential normal |
---|
3905 | form.] |
---|
3906 | |
---|
3907 | SideEffects [] |
---|
3908 | |
---|
3909 | ******************************************************************************/ |
---|
3910 | static array_t * |
---|
3911 | McFsmStateDebugFormulaMine( |
---|
3912 | McOptions_t *options, |
---|
3913 | Ctlp_Formula_t *ctlFormula, |
---|
3914 | mdd_t *aState, |
---|
3915 | Fsm_Fsm_t *modelFsm, |
---|
3916 | array_t *careSetArray, |
---|
3917 | array_t *prevCExArray) |
---|
3918 | { |
---|
3919 | (void) fprintf(vis_stdout, "![McFsmStateDebugFormulaMine] Original CTL Formula : "); |
---|
3920 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
3921 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] MC CTL Formula : "); |
---|
3922 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 0 --> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
3923 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
3924 | fprintf(vis_stdout, "\n"); |
---|
3925 | |
---|
3926 | |
---|
3927 | Ctlp_Formula_t *originalFormula; |
---|
3928 | array_t *cExampleArray; |
---|
3929 | // array_t *preCExArray; |
---|
3930 | array_t *fullCExArray; |
---|
3931 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
3932 | |
---|
3933 | //prevCExArray = array_alloc(mdd_t *, 0); |
---|
3934 | // fullCExArray = prevCExArray; |
---|
3935 | if ( ctlFormula == NIL(Ctlp_Formula_t) ) { |
---|
3936 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] * END * \n"); |
---|
3937 | fullCExArray = prevCExArray; |
---|
3938 | return fullCExArray; |
---|
3939 | } |
---|
3940 | if ( Ctlp_FormulaTestIsConverted( ctlFormula ) ) { |
---|
3941 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> FsmStateDebugConvertedFormulaMine \n"); |
---|
3942 | cExampleArray = FsmStateDebugConvertedFormulaMine(options, ctlFormula, aState, modelFsm, |
---|
3943 | careSetArray, &prevCExArray); |
---|
3944 | |
---|
3945 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 1 --> nb cExampleArray : %d ", array_n(cExampleArray )); |
---|
3946 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 1 --> nb prevCExArray : %d ", array_n(prevCExArray)); |
---|
3947 | |
---|
3948 | // boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
3949 | // Mc_PrintPathMine( cExampleArray, modelFsm, printInputs ); |
---|
3950 | |
---|
3951 | if (array_n(prevCExArray)==0 ) { |
---|
3952 | fullCExArray = cExampleArray; |
---|
3953 | } |
---|
3954 | else { |
---|
3955 | fullCExArray = McCreateMergedPath(cExampleArray, prevCExArray); |
---|
3956 | } |
---|
3957 | |
---|
3958 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 1 --> nb fullCExArray : %d ", array_n(fullCExArray )); |
---|
3959 | prevCExArray = fullCExArray; |
---|
3960 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 1 --> nb prevCExArray End : %d ", array_n(prevCExArray)); |
---|
3961 | |
---|
3962 | /* (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] START OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00000000O\n"); |
---|
3963 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
3964 | Mc_PrintPathMine( fullCExArray, modelFsm, printInputs ); |
---|
3965 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] END 0OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00000000O\n"); |
---|
3966 | */ |
---|
3967 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] * END * \n"); |
---|
3968 | return fullCExArray; |
---|
3969 | } |
---|
3970 | |
---|
3971 | originalFormula = Ctlp_FormulaReadOriginalFormula( ctlFormula ); |
---|
3972 | |
---|
3973 | switch ( Ctlp_FormulaReadType( ctlFormula ) ) { |
---|
3974 | |
---|
3975 | case Ctlp_ID_c : |
---|
3976 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugIDMine \n"); |
---|
3977 | DebugIDMine( options, ctlFormula, aState, modelFsm ); |
---|
3978 | fullCExArray = prevCExArray; |
---|
3979 | break; |
---|
3980 | |
---|
3981 | case Ctlp_TRUE_c: |
---|
3982 | case Ctlp_FALSE_c: |
---|
3983 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugTrueFalseMine \n"); |
---|
3984 | DebugTrueFalseMine( ctlFormula, aState, modelFsm ); |
---|
3985 | fullCExArray = prevCExArray; |
---|
3986 | break; |
---|
3987 | |
---|
3988 | case Ctlp_EQ_c: |
---|
3989 | case Ctlp_XOR_c: |
---|
3990 | case Ctlp_THEN_c: |
---|
3991 | case Ctlp_NOT_c: |
---|
3992 | case Ctlp_AND_c: |
---|
3993 | case Ctlp_OR_c: |
---|
3994 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugBooleanMine \n"); |
---|
3995 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 2 --> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
3996 | cExampleArray = DebugBooleanMine(options, ctlFormula, aState, modelFsm, careSetArray, &prevCExArray); |
---|
3997 | |
---|
3998 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 2 --> nb cExampleArray : %d ", array_n(cExampleArray )); |
---|
3999 | |
---|
4000 | |
---|
4001 | /* if (array_n(prevCExArray)==0 ) { |
---|
4002 | fullCExArray = cExampleArray; |
---|
4003 | } |
---|
4004 | else { |
---|
4005 | fullCExArray = McCreateMergedPath(cExampleArray, prevCExArray); |
---|
4006 | } |
---|
4007 | */ |
---|
4008 | |
---|
4009 | fullCExArray = cExampleArray; |
---|
4010 | prevCExArray = fullCExArray; |
---|
4011 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 2 --> nb prevCExArray after DB : %d ", array_n(prevCExArray)); |
---|
4012 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 2 --> nb fullCExArray : %d ", array_n(fullCExArray )); |
---|
4013 | |
---|
4014 | break; |
---|
4015 | |
---|
4016 | case Ctlp_EX_c: |
---|
4017 | case Ctlp_EU_c: |
---|
4018 | case Ctlp_EG_c: |
---|
4019 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> Ctlp_EG_c\n"); |
---|
4020 | if ( !McStateSatisfiesFormula( ctlFormula, aState ) ) { |
---|
4021 | mdd_t *passStates = Ctlp_FormulaObtainLatestApprox(ctlFormula); |
---|
4022 | mdd_t *closeState; |
---|
4023 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork(modelFsm); |
---|
4024 | array_t *PSVars = Fsm_FsmReadPresentStateVars(modelFsm); |
---|
4025 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> McStateFailsFormulaMine \n"); |
---|
4026 | |
---|
4027 | McStateFailsFormulaMine(aState, originalFormula, debugLevel, modelFsm); |
---|
4028 | if (mdd_is_tautology(passStates, 0)) { |
---|
4029 | fprintf(vis_stdout, |
---|
4030 | "--No state satisfies the formula\n"); |
---|
4031 | mdd_free(passStates); |
---|
4032 | |
---|
4033 | fullCExArray = prevCExArray; |
---|
4034 | break; |
---|
4035 | } |
---|
4036 | fprintf(vis_stdout, |
---|
4037 | "--A simple counter example does not exist since it\n"); |
---|
4038 | fprintf(vis_stdout, |
---|
4039 | " requires generating all paths from the state\n"); |
---|
4040 | fprintf(vis_stdout, |
---|
4041 | "--A state at minimum distance satisfying the formula is\n"); |
---|
4042 | closeState = McComputeACloseState(passStates, aState, modelFsm); |
---|
4043 | mdd_free(passStates); |
---|
4044 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> Mc_MintermPrintMine \n"); |
---|
4045 | Mc_MintermPrintMine(closeState, PSVars, modelNetwork); |
---|
4046 | mdd_free(closeState); |
---|
4047 | |
---|
4048 | fullCExArray = prevCExArray; |
---|
4049 | |
---|
4050 | break; |
---|
4051 | } |
---|
4052 | else { |
---|
4053 | McPath_t *witnessPath = NIL(McPath_t); |
---|
4054 | if ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EX_c ) { |
---|
4055 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugEXMine \n"); |
---|
4056 | witnessPath = DebugEXMine(ctlFormula, aState, modelFsm, careSetArray); |
---|
4057 | } |
---|
4058 | else if ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EU_c ) { |
---|
4059 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugEUMine \n"); |
---|
4060 | witnessPath = DebugEUMine(ctlFormula, aState, modelFsm, careSetArray); |
---|
4061 | } |
---|
4062 | else { |
---|
4063 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugEGMine \n"); |
---|
4064 | witnessPath = DebugEGMine(ctlFormula, aState, modelFsm, careSetArray, |
---|
4065 | options); |
---|
4066 | } |
---|
4067 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> FsmPathDebugFormulaMine \n"); |
---|
4068 | cExampleArray = FsmPathDebugFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
4069 | careSetArray, &prevCExArray); |
---|
4070 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 3 --> nb cExampleArray : %d ", array_n(cExampleArray )); |
---|
4071 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 3 --> nb prevCExArray : %d ", array_n(prevCExArray)); |
---|
4072 | |
---|
4073 | /* if (array_n(prevCExArray)==0 ) { |
---|
4074 | fullCExArray = cExampleArray; |
---|
4075 | } |
---|
4076 | else { |
---|
4077 | fullCExArray = McCreateMergedPath(cExampleArray, prevCExArray); |
---|
4078 | } |
---|
4079 | */ |
---|
4080 | fullCExArray = prevCExArray; |
---|
4081 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 3 --> nb fullCExArray : %d ", array_n(fullCExArray )); |
---|
4082 | |
---|
4083 | // McPathFree( witnessPath ); //NOTE: INITIALLY FREED |
---|
4084 | } |
---|
4085 | break; |
---|
4086 | |
---|
4087 | case Ctlp_Cmp_c: |
---|
4088 | case Ctlp_Init_c: |
---|
4089 | case Ctlp_FwdU_c: |
---|
4090 | case Ctlp_FwdG_c: |
---|
4091 | case Ctlp_EY_c: |
---|
4092 | case Ctlp_EH_c: |
---|
4093 | fullCExArray = prevCExArray; |
---|
4094 | break; |
---|
4095 | |
---|
4096 | default: { |
---|
4097 | fail("Bad switch in debugging normal formula\n"); |
---|
4098 | fullCExArray = prevCExArray; |
---|
4099 | } |
---|
4100 | } |
---|
4101 | // *prevCExArray = fullCExArray; |
---|
4102 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] LAST --> nb prevCExArray End: %d ", array_n(prevCExArray)); |
---|
4103 | /* (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] START OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00000000O\n"); |
---|
4104 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
4105 | Mc_PrintPathMine( prevCExArray, modelFsm, printInputs ); |
---|
4106 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] END 0OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00000000O\n"); |
---|
4107 | */ |
---|
4108 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] * END * \n"); |
---|
4109 | return fullCExArray; |
---|
4110 | |
---|
4111 | } |
---|
4112 | |
---|
4113 | /**Function******************************************************************** |
---|
4114 | |
---|
4115 | Synopsis [Debug a converted formula] |
---|
4116 | |
---|
4117 | Comment [There are five kinds of formula that are converted: EF, AU, AF, AG, |
---|
4118 | AX. The Ctlp_Formula_t structure has a pointer back to the original formula |
---|
4119 | (where one exists). For the non-trivial cases (AU, AF, AG, AX) if the |
---|
4120 | formula is false, we create a counter example, i.e. a fair path which fails |
---|
4121 | the property. The AG, AX, AF cases are simple; the AU case is tricky because |
---|
4122 | this can be failed on two ways.] |
---|
4123 | |
---|
4124 | SideEffects [] |
---|
4125 | |
---|
4126 | ******************************************************************************/ |
---|
4127 | static array_t * |
---|
4128 | FsmStateDebugConvertedFormulaMine( |
---|
4129 | McOptions_t *options, |
---|
4130 | Ctlp_Formula_t *ctlFormula, |
---|
4131 | mdd_t *aState, |
---|
4132 | Fsm_Fsm_t *modelFsm, |
---|
4133 | array_t *careSetArray, |
---|
4134 | array_t **preCExArray) |
---|
4135 | { |
---|
4136 | (void) fprintf(vis_stdout, "![FsmStateDebugConvertedFormulaMine] Original CTL Formula : "); |
---|
4137 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
4138 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] MC CTL Formula : "); |
---|
4139 | // (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
4140 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
4141 | fprintf(vis_stdout, "\n"); |
---|
4142 | |
---|
4143 | McPath_t *witnessPath; |
---|
4144 | McPath_t *counterExamplePath; |
---|
4145 | |
---|
4146 | array_t *cExArray; |
---|
4147 | |
---|
4148 | Ctlp_Formula_t *originalFormula =Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
4149 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
4150 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
4151 | |
---|
4152 | if ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EU_c ) { |
---|
4153 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> Ctlp_EU_c \n"); |
---|
4154 | if ( !McStateSatisfiesFormula( ctlFormula, aState ) ) { |
---|
4155 | mdd_t *passStates = Ctlp_FormulaObtainLatestApprox(ctlFormula); |
---|
4156 | mdd_t *closeState; |
---|
4157 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork(modelFsm); |
---|
4158 | array_t *PSVars = Fsm_FsmReadPresentStateVars(modelFsm); |
---|
4159 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> McStateFailsFormulaMine \n"); |
---|
4160 | McStateFailsFormulaMine( aState, originalFormula, debugLevel, modelFsm ); |
---|
4161 | if (mdd_is_tautology(passStates, 0)) { |
---|
4162 | fprintf(vis_stdout, |
---|
4163 | "--No state satisfies the formula\n"); |
---|
4164 | } else { |
---|
4165 | fprintf(vis_stdout, |
---|
4166 | "\n--A simple counter example does not exist since it\n"); |
---|
4167 | fprintf(vis_stdout, |
---|
4168 | " requires generating all paths from the state\n"); |
---|
4169 | fprintf(vis_stdout, |
---|
4170 | "--A state at minimum distance satisfying the formula is\n"); |
---|
4171 | closeState = McComputeACloseState(passStates, aState, modelFsm); |
---|
4172 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> Mc_MintermPrintMine \n"); |
---|
4173 | Mc_MintermPrintMine(closeState, PSVars, modelNetwork); |
---|
4174 | mdd_free(closeState); |
---|
4175 | } |
---|
4176 | mdd_free(passStates); |
---|
4177 | } |
---|
4178 | else { |
---|
4179 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> DebugEUMine \n"); |
---|
4180 | witnessPath = DebugEUMine(ctlFormula, aState, modelFsm, careSetArray); |
---|
4181 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugEFFormulaMine\n"); |
---|
4182 | cExArray = FsmPathDebugEFFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
4183 | careSetArray, preCExArray); |
---|
4184 | // McPathFree( witnessPath ); |
---|
4185 | } |
---|
4186 | cExArray = *preCExArray; |
---|
4187 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] ** END ** \n"); |
---|
4188 | return cExArray; |
---|
4189 | //return cExArray; // EF Formula not yet treated |
---|
4190 | } |
---|
4191 | |
---|
4192 | /* |
---|
4193 | * The original formula must be an AX,AF,AG, or AU formula |
---|
4194 | */ |
---|
4195 | if ( McStateSatisfiesFormula( ctlFormula, aState ) ) { |
---|
4196 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> McStatePassesFormulaMine\n"); |
---|
4197 | McStatePassesFormulaMine( aState, originalFormula, debugLevel, modelFsm ); |
---|
4198 | fprintf(vis_stdout, |
---|
4199 | "--A simple witness does not exist since it requires\n"); |
---|
4200 | fprintf(vis_stdout, " generating all paths from the state\n"); |
---|
4201 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] ** END ** \n"); |
---|
4202 | cExArray = *preCExArray; //Added to avoid seg fault |
---|
4203 | return cExArray; // maybe aState gotta checkout later!! |
---|
4204 | } |
---|
4205 | |
---|
4206 | switch ( Ctlp_FormulaReadType( lFormula ) ) { |
---|
4207 | case Ctlp_EX_c: { |
---|
4208 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> DebugEXMine\n"); |
---|
4209 | counterExamplePath = DebugEXMine(lFormula, aState, modelFsm, careSetArray); |
---|
4210 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugAXFormulaMine\n"); |
---|
4211 | cExArray = FsmPathDebugAXFormulaMine(options, ctlFormula, modelFsm, counterExamplePath, careSetArray, preCExArray); |
---|
4212 | // McPathFree( counterExamplePath ); //NOTE: INITIALLY FREED |
---|
4213 | break; |
---|
4214 | } |
---|
4215 | |
---|
4216 | case Ctlp_EG_c: { |
---|
4217 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> DebugEGMine\n"); |
---|
4218 | counterExamplePath = DebugEGMine(lFormula, aState, modelFsm, careSetArray, |
---|
4219 | options); |
---|
4220 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugAFFormulaMine\n"); |
---|
4221 | cExArray = FsmPathDebugAFFormulaMine(options, ctlFormula, modelFsm, counterExamplePath, |
---|
4222 | careSetArray, preCExArray); |
---|
4223 | // McPathFree( counterExamplePath ); //NOTE: INITIALLY FREED |
---|
4224 | break; |
---|
4225 | } |
---|
4226 | |
---|
4227 | case Ctlp_EU_c: { |
---|
4228 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> DebugEUMine\n"); |
---|
4229 | counterExamplePath = DebugEUMine(lFormula, aState, modelFsm, careSetArray); |
---|
4230 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugAGFormulaMine\n"); |
---|
4231 | cExArray = FsmPathDebugAGFormulaMine(options, ctlFormula, modelFsm, counterExamplePath, |
---|
4232 | careSetArray, preCExArray); |
---|
4233 | // McPathFree( counterExamplePath ); //NOTE: INITIALLY FREED |
---|
4234 | break; |
---|
4235 | } |
---|
4236 | |
---|
4237 | case Ctlp_OR_c: { |
---|
4238 | /* |
---|
4239 | * need special functions bcoz of two possibilities |
---|
4240 | */ |
---|
4241 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugAUFormulaMine\n"); |
---|
4242 | cExArray = FsmPathDebugAUFormulaMine(options, aState, ctlFormula, modelFsm, |
---|
4243 | careSetArray, preCExArray); |
---|
4244 | |
---|
4245 | break; |
---|
4246 | } |
---|
4247 | |
---|
4248 | default: fail("Bad formula type in handling converted operator\n"); |
---|
4249 | } |
---|
4250 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] LAST ---> nb preCExArray : %d", array_n(*preCExArray)); |
---|
4251 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] LAST ---> nb cExArray : %d", array_n(cExArray )); |
---|
4252 | |
---|
4253 | // boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
4254 | // (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] printInputs = %s \n", (printInputs==TRUE)? "TRUE":"FALSE"); |
---|
4255 | // Mc_PrintPathMine(cExArray, modelFsm, printInputs ); |
---|
4256 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] ** END ** \n"); |
---|
4257 | return cExArray; |
---|
4258 | } |
---|
4259 | |
---|
4260 | |
---|
4261 | /**Function******************************************************************** |
---|
4262 | |
---|
4263 | Synopsis [Debug a formula of the form EX, EG, EU, EF.] |
---|
4264 | |
---|
4265 | SideEffects [] |
---|
4266 | |
---|
4267 | ******************************************************************************/ |
---|
4268 | static array_t * |
---|
4269 | FsmPathDebugFormulaMine( |
---|
4270 | McOptions_t *options, |
---|
4271 | Ctlp_Formula_t *ctlFormula, |
---|
4272 | Fsm_Fsm_t *modelFsm, |
---|
4273 | McPath_t *witnessPath, |
---|
4274 | array_t *careSetArray, |
---|
4275 | array_t **preCExArray) |
---|
4276 | { |
---|
4277 | (void) fprintf(vis_stdout, "![FsmPathDebugFormulaMine] Original CTL Formula : "); |
---|
4278 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
4279 | (void) fprintf(vis_stdout, "\n![FsmPathDebugFormulaMine] MC CTL Formula : "); |
---|
4280 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
4281 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
4282 | fprintf(vis_stdout, "\n"); |
---|
4283 | |
---|
4284 | array_t *witnessArray; |
---|
4285 | switch ( Ctlp_FormulaReadType( ctlFormula ) ) { |
---|
4286 | case Ctlp_EX_c: { |
---|
4287 | witnessArray = FsmPathDebugEXFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
4288 | careSetArray, preCExArray); |
---|
4289 | break; |
---|
4290 | } |
---|
4291 | |
---|
4292 | case Ctlp_EU_c: { |
---|
4293 | witnessArray = FsmPathDebugEUFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
4294 | careSetArray, preCExArray); |
---|
4295 | break; |
---|
4296 | } |
---|
4297 | |
---|
4298 | case Ctlp_EG_c: { |
---|
4299 | witnessArray = FsmPathDebugEGFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
4300 | careSetArray, preCExArray); |
---|
4301 | break; |
---|
4302 | } |
---|
4303 | default: { |
---|
4304 | fail("bad switch in converting converted formula\n"); |
---|
4305 | } |
---|
4306 | } |
---|
4307 | |
---|
4308 | (void) fprintf(vis_stdout, "\n![FsmPathDebugFormulaMine] ---> witnessArray : %d *END*\n", array_n(witnessArray)); |
---|
4309 | |
---|
4310 | return witnessArray; |
---|
4311 | } |
---|
4312 | |
---|
4313 | |
---|
4314 | /**Function******************************************************************** |
---|
4315 | |
---|
4316 | Synopsis [Debug an Atomic Formula] |
---|
4317 | |
---|
4318 | Description [Debug an Atomic Formula. As per the semantics of fair CTL, a |
---|
4319 | state satisfies an Atomic Formula just in case the given wire computes the |
---|
4320 | appropriate Boolean function on that state as input. The state has to be |
---|
4321 | fair; however we do NOT justify the fairness by printing a path to a fair |
---|
4322 | cycle. THe user can achieve this effect by adding ANDing in a formula EG |
---|
4323 | TRUE.] |
---|
4324 | |
---|
4325 | SideEffects [] |
---|
4326 | |
---|
4327 | ******************************************************************************/ |
---|
4328 | static void |
---|
4329 | DebugIDMine( |
---|
4330 | McOptions_t *options, |
---|
4331 | Ctlp_Formula_t *aFormula, |
---|
4332 | mdd_t *aState, |
---|
4333 | Fsm_Fsm_t *modelFsm) |
---|
4334 | { |
---|
4335 | |
---|
4336 | (void) fprintf(vis_stdout, "![DebugIDMine] Original CTL Formula : "); |
---|
4337 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
4338 | (void) fprintf(vis_stdout, "\n![DebugIDMine] MC CTL Formula : "); |
---|
4339 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
4340 | fprintf(vis_stdout, "\n"); |
---|
4341 | |
---|
4342 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(aFormula); |
---|
4343 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
4344 | |
---|
4345 | if ( McStateSatisfiesFormula( aFormula, aState ) ) { |
---|
4346 | McStatePassesFormulaMine( aState, originalFormula, debugLevel, modelFsm ); |
---|
4347 | } |
---|
4348 | else { |
---|
4349 | McStateFailsFormulaMine( aState, originalFormula, debugLevel, modelFsm ); |
---|
4350 | } |
---|
4351 | } |
---|
4352 | |
---|
4353 | /**Function******************************************************************** |
---|
4354 | |
---|
4355 | Synopsis [Debug a TRUE/FALSE formula] |
---|
4356 | |
---|
4357 | SideEffects [] |
---|
4358 | |
---|
4359 | ******************************************************************************/ |
---|
4360 | static void |
---|
4361 | DebugTrueFalseMine( |
---|
4362 | Ctlp_Formula_t *aFormula, |
---|
4363 | mdd_t *aState, |
---|
4364 | Fsm_Fsm_t *modelFsm) |
---|
4365 | { |
---|
4366 | (void) fprintf(vis_stdout, "![DebugTrueFalseMine] Original CTL Formula : "); |
---|
4367 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
4368 | (void) fprintf(vis_stdout, "\n![[DebugTrueFalseMine] MC CTL Formula : "); |
---|
4369 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
4370 | |
---|
4371 | fprintf(vis_stdout, "\n"); |
---|
4372 | fprintf(vis_stdout, "--Nothing to debug for %s\n", |
---|
4373 | ((Ctlp_FormulaReadType(aFormula) == Ctlp_TRUE_c) ? "TRUE\n" : "FALSE\n")); |
---|
4374 | } |
---|
4375 | |
---|
4376 | /**Function******************************************************************** |
---|
4377 | |
---|
4378 | Synopsis [Debug a Boolean formula] |
---|
4379 | |
---|
4380 | Desciption [Debug a Boolean formula. For Boolean formula built out of binary |
---|
4381 | connective, we may debug only one branch, if say the formula is an AND and |
---|
4382 | the left branch is fails.] |
---|
4383 | |
---|
4384 | SideEffects [] |
---|
4385 | |
---|
4386 | ******************************************************************************/ |
---|
4387 | static array_t * |
---|
4388 | DebugBooleanMine( |
---|
4389 | McOptions_t *options, |
---|
4390 | Ctlp_Formula_t *aFormula, |
---|
4391 | mdd_t *aState, |
---|
4392 | Fsm_Fsm_t *modelFsm, |
---|
4393 | array_t *careSetArray, |
---|
4394 | array_t **preCExArray) |
---|
4395 | { |
---|
4396 | (void) fprintf(vis_stdout, "![DebugBooleanMine] Original CTL Formula : "); |
---|
4397 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
4398 | (void) fprintf(vis_stdout, "\n![DebugBooleanMine] MC CTL Formula : "); |
---|
4399 | (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 0 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
4400 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
4401 | fprintf(vis_stdout, "\n"); |
---|
4402 | |
---|
4403 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(aFormula); |
---|
4404 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( aFormula ); |
---|
4405 | Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( aFormula ); |
---|
4406 | McDbgLevel debugLevel = McOptionsReadDbgLevel(options); |
---|
4407 | |
---|
4408 | if (McStateSatisfiesFormula(aFormula, aState)) { |
---|
4409 | McStatePassesFormulaMine(aState, originalFormula, debugLevel, modelFsm); |
---|
4410 | } else { |
---|
4411 | McStateFailsFormulaMine(aState, originalFormula, debugLevel, modelFsm); |
---|
4412 | } |
---|
4413 | |
---|
4414 | /* We always debug the first (left) child. */ |
---|
4415 | array_t *cExArray; |
---|
4416 | // array_t *prevCExArray; |
---|
4417 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
4418 | cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
4419 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 1 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
4420 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 1 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
4421 | /* What we do for the second child depends on the type of the formula. |
---|
4422 | * For Ctlp_AND_c, Ctlp_OR_c, Ctlp_THEN_c the right child may not be |
---|
4423 | * needed. With early termination, the right child may not have the |
---|
4424 | * information required to produce a counterexample; hence, its debugging |
---|
4425 | * is not optional. (We may get incorrect answers.) |
---|
4426 | */ |
---|
4427 | if (Ctlp_FormulaReadType(aFormula) == Ctlp_AND_c) { |
---|
4428 | /* If aFormula fails and aState does not satisfy lFormula |
---|
4429 | * 1. The information about aState at the right child is not |
---|
4430 | * necessarilty correct. (aState was a don't care state.) |
---|
4431 | * 2. A counterexample to lFormula is a counterexample to |
---|
4432 | * aFormula. |
---|
4433 | * So, if aFormula fails, we should debug the right child only if |
---|
4434 | * aState satisfies lFormula. |
---|
4435 | * If, on the other hand, aFormula passes, then aState must satisfy |
---|
4436 | * lFormula, and we need to witness both lFormula and rFormula. |
---|
4437 | */ |
---|
4438 | if (McStateSatisfiesFormula(lFormula, aState)) { |
---|
4439 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, aState, modelFsm, |
---|
4440 | careSetArray, *preCExArray); |
---|
4441 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 2 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
4442 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 2 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
4443 | } |
---|
4444 | } else if (Ctlp_FormulaReadType(aFormula) == Ctlp_OR_c) { |
---|
4445 | /* if aFormula passes, we should debug the right child only if |
---|
4446 | * aState does not satisfy lFormula. |
---|
4447 | * If, on the other hand, aFormula fails, then aState may not satisfy |
---|
4448 | * lFormula, and we need to produce counterexamples for both lFormula |
---|
4449 | * and rFormula. |
---|
4450 | */ |
---|
4451 | if (!McStateSatisfiesFormula(lFormula, aState)) { |
---|
4452 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, aState, modelFsm, |
---|
4453 | careSetArray, *preCExArray); |
---|
4454 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 3 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
4455 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 3 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
4456 | } |
---|
4457 | } else if (Ctlp_FormulaReadType(aFormula) == Ctlp_THEN_c) { |
---|
4458 | /* This case is like the OR, with the polarity of the left |
---|
4459 | * left child reversed. |
---|
4460 | */ |
---|
4461 | if (McStateSatisfiesFormula(lFormula, aState)) { |
---|
4462 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, aState, modelFsm, |
---|
4463 | careSetArray, *preCExArray); |
---|
4464 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 4 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
4465 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 4 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
4466 | } |
---|
4467 | } else if (Ctlp_FormulaReadType(aFormula) != Ctlp_NOT_c) { |
---|
4468 | /* For Ctlp_EQ_c and Ctlp_XOR_c both children must be debugged. */ |
---|
4469 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
4470 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 5 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
4471 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 5 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
4472 | } |
---|
4473 | (void) fprintf(vis_stdout, "\n![DebugBooleanMine] LAST ---> nb prevCExArray : %d ", array_n(*preCExArray)); |
---|
4474 | (void) fprintf(vis_stdout, "\n![DebugBooleanMine] LAST ---> nb cExArray : %d *END*\n", array_n(cExArray)); |
---|
4475 | return cExArray; |
---|
4476 | } |
---|
4477 | |
---|
4478 | |
---|
4479 | /**Function******************************************************************** |
---|
4480 | |
---|
4481 | Synopsis [Debug a formula of type EX.] |
---|
4482 | |
---|
4483 | Description [Debug a formula of type EX at specified state. It is assumed |
---|
4484 | that aState satisfies the EX formula.] |
---|
4485 | |
---|
4486 | SideEffects [] |
---|
4487 | |
---|
4488 | ******************************************************************************/ |
---|
4489 | static McPath_t * |
---|
4490 | DebugEXMine( |
---|
4491 | Ctlp_Formula_t *aFormula, |
---|
4492 | mdd_t *aState, |
---|
4493 | Fsm_Fsm_t *modelFsm, |
---|
4494 | array_t *careSetArray) |
---|
4495 | { |
---|
4496 | (void) fprintf(vis_stdout, "![DebugEXMine] Original CTL Formula : "); |
---|
4497 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
4498 | (void) fprintf(vis_stdout, "\n![DebugEXMine] MC CTL Formula : "); |
---|
4499 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
4500 | fprintf(vis_stdout, "\n"); |
---|
4501 | |
---|
4502 | mdd_t *aDupState = mdd_dup( aState ); |
---|
4503 | mdd_t *aStateSuccs; |
---|
4504 | mdd_t *statesSatisfyingLeftFormula; |
---|
4505 | mdd_t *targetStates; |
---|
4506 | mdd_t *witnessSuccState; |
---|
4507 | Ctlp_Formula_t *lFormula; |
---|
4508 | McPath_t *witnessPath = McPathAlloc(); |
---|
4509 | array_t *stemArray = array_alloc( mdd_t *, 0 ); |
---|
4510 | Img_ImageInfo_t * imageInfo = Fsm_FsmReadOrCreateImageInfo(modelFsm, 0, 1); |
---|
4511 | |
---|
4512 | /* |
---|
4513 | * By using careSet here, can end up with unreachable successors |
---|
4514 | */ |
---|
4515 | aStateSuccs = Img_ImageInfoComputeImageWithDomainVars(imageInfo, |
---|
4516 | aState, aState, careSetArray); |
---|
4517 | |
---|
4518 | lFormula = Ctlp_FormulaReadLeftChild( aFormula ); |
---|
4519 | statesSatisfyingLeftFormula = Ctlp_FormulaObtainLatestApprox( lFormula ); |
---|
4520 | |
---|
4521 | targetStates = mdd_and( aStateSuccs, statesSatisfyingLeftFormula, 1, 1 ); |
---|
4522 | mdd_free( aStateSuccs ); mdd_free( statesSatisfyingLeftFormula ); |
---|
4523 | |
---|
4524 | witnessSuccState = Mc_ComputeACloseState( targetStates, aState, modelFsm ); |
---|
4525 | mdd_free( targetStates ); |
---|
4526 | |
---|
4527 | array_insert_last( mdd_t *, stemArray, aDupState ); |
---|
4528 | array_insert_last( mdd_t *, stemArray, witnessSuccState ); |
---|
4529 | |
---|
4530 | McPathSetStemArray( witnessPath, stemArray ); |
---|
4531 | |
---|
4532 | return witnessPath; |
---|
4533 | } |
---|
4534 | |
---|
4535 | /**Function******************************************************************** |
---|
4536 | |
---|
4537 | Synopsis [Debug a formula of type EU.] |
---|
4538 | |
---|
4539 | Description [Debug a formula of type EU at specified state. It is assumed that |
---|
4540 | state fails formula.] |
---|
4541 | |
---|
4542 | SideEffects [] |
---|
4543 | |
---|
4544 | ******************************************************************************/ |
---|
4545 | static McPath_t * |
---|
4546 | DebugEUMine( |
---|
4547 | Ctlp_Formula_t *aFormula, |
---|
4548 | mdd_t *aState, |
---|
4549 | Fsm_Fsm_t *modelFsm, |
---|
4550 | array_t *careSetArray) |
---|
4551 | { |
---|
4552 | (void) fprintf(vis_stdout, "![DebugEUMine] Original CTL Formula : "); |
---|
4553 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
4554 | (void) fprintf(vis_stdout, "\n![DebugEUMine] MC CTL Formula : "); |
---|
4555 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
4556 | fprintf(vis_stdout, "\n"); |
---|
4557 | |
---|
4558 | McPath_t *witnessPath = McPathAlloc(); |
---|
4559 | array_t *OnionRings = (array_t *) Ctlp_FormulaReadDebugData( aFormula ); |
---|
4560 | array_t *pathToCore = Mc_BuildPathToCore(aState, OnionRings, |
---|
4561 | modelFsm, |
---|
4562 | McGreaterOrEqualZero_c ); |
---|
4563 | |
---|
4564 | McPathSetStemArray( witnessPath, pathToCore ); |
---|
4565 | |
---|
4566 | return witnessPath; |
---|
4567 | } |
---|
4568 | |
---|
4569 | /**Function******************************************************************** |
---|
4570 | |
---|
4571 | Synopsis [Debug a formula of type EG.] |
---|
4572 | |
---|
4573 | Description [Debug a formula of type EG at specified state. It is assumed |
---|
4574 | that state fails formula. Refer to Clarke et al DAC 1995 for details of the |
---|
4575 | algorithm.] |
---|
4576 | |
---|
4577 | SideEffects [] |
---|
4578 | |
---|
4579 | ******************************************************************************/ |
---|
4580 | static McPath_t * |
---|
4581 | DebugEGMine( |
---|
4582 | Ctlp_Formula_t *aFormula, |
---|
4583 | mdd_t *aState, |
---|
4584 | Fsm_Fsm_t *modelFsm, |
---|
4585 | array_t *careSetArray, |
---|
4586 | McOptions_t *options) |
---|
4587 | { |
---|
4588 | (void) fprintf(vis_stdout, "![DebugEGMine] Original CTL Formula : "); |
---|
4589 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
4590 | (void) fprintf(vis_stdout, "\n![DebugEGMine] MC CTL Formula : "); |
---|
4591 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
4592 | fprintf(vis_stdout, "\n"); |
---|
4593 | |
---|
4594 | array_t *arrayOfOnionRings = (array_t *) Ctlp_FormulaReadDebugData(aFormula); |
---|
4595 | mdd_t *invariantMdd = Ctlp_FormulaObtainLatestApprox( aFormula ); |
---|
4596 | McPath_t *fairPath = McBuildFairPath(aState, invariantMdd, arrayOfOnionRings, |
---|
4597 | modelFsm, careSetArray, |
---|
4598 | McOptionsReadVerbosityLevel(options), |
---|
4599 | McOptionsReadDcLevel(options), |
---|
4600 | McOptionsReadFwdBwd(options)); |
---|
4601 | mdd_free( invariantMdd ); |
---|
4602 | |
---|
4603 | return fairPath; |
---|
4604 | } |
---|
4605 | |
---|
4606 | |
---|
4607 | /**Function******************************************************************** |
---|
4608 | |
---|
4609 | Synopsis [Debug a path for EX type formula.] |
---|
4610 | |
---|
4611 | SideEffects [] |
---|
4612 | |
---|
4613 | ******************************************************************************/ |
---|
4614 | static array_t * |
---|
4615 | FsmPathDebugEXFormulaMine( |
---|
4616 | McOptions_t *options, |
---|
4617 | Ctlp_Formula_t *ctlFormula, |
---|
4618 | Fsm_Fsm_t *modelFsm, |
---|
4619 | McPath_t *witnessPath, |
---|
4620 | array_t *careSetArray, |
---|
4621 | array_t **preCExArray) |
---|
4622 | { |
---|
4623 | |
---|
4624 | (void) fprintf(vis_stdout, "![FsmPathDebugEXFormulaMine] Original CTL Formula : "); |
---|
4625 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
4626 | (void) fprintf(vis_stdout, "\n![FsmPathDebugEXFormulaMine] MC CTL Formula : "); |
---|
4627 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEXFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
4628 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
4629 | fprintf(vis_stdout, "\n"); |
---|
4630 | |
---|
4631 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
4632 | array_t *witnessArray = McPathReadStemArray( witnessPath ); |
---|
4633 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
4634 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
4635 | Fsm_FsmReadNetwork(modelFsm)); |
---|
4636 | Ctlp_Formula_t *lChild = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
4637 | char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula ); |
---|
4638 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
4639 | mdd_t *secondlastState; |
---|
4640 | if(array_n(witnessArray)<2) |
---|
4641 | { |
---|
4642 | fprintf(vis_stdout,"witnessArray has less than two elements, return\n"); |
---|
4643 | if (array_n(witnessArray) > 0) return witnessArray; |
---|
4644 | else return NIL(array_t); |
---|
4645 | } |
---|
4646 | secondlastState= array_fetch( mdd_t *, witnessArray, (array_n(witnessArray)-1) ); |
---|
4647 | |
---|
4648 | (void) fprintf(vis_stderr, "-[FsmPathDebugEXFormulaMine] array_n(witnessArrayEX) = %d\n",array_n(witnessArray)); |
---|
4649 | |
---|
4650 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
4651 | fprintf(vis_stdout, "--State\n%spasses EX formula\n\n", |
---|
4652 | firstStateName); |
---|
4653 | else |
---|
4654 | fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName, |
---|
4655 | ctlFormulaText ); |
---|
4656 | |
---|
4657 | FREE(firstStateName); |
---|
4658 | FREE(ctlFormulaText); |
---|
4659 | |
---|
4660 | array_t *cExArray; |
---|
4661 | // array_t *prevCExArray; |
---|
4662 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
4663 | |
---|
4664 | switch ( McOptionsReadDbgLevel( options ) ) { |
---|
4665 | case McDbgLevelMin_c: |
---|
4666 | case McDbgLevelMinVerbose_c: |
---|
4667 | case McDbgLevelMax_c: |
---|
4668 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
4669 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
4670 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
4671 | // cExArray = McFsmStateDebugFormulaMine(options, lChild, secondlastState, modelFsm, careSetArray, prevCExArray); |
---|
4672 | cExArray = McFsmStateDebugFormulaMine(options, lChild, secondlastState, modelFsm, careSetArray, *preCExArray); |
---|
4673 | break; |
---|
4674 | case McDbgLevelInteractive_c: |
---|
4675 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
4676 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
4677 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
4678 | if (McQueryContinue("Continue debugging EX formula? (1-yes,0-no)\n")) |
---|
4679 | // cExArray = McFsmStateDebugFormulaMine(options, lChild, secondlastState, modelFsm, careSetArray, prevCExArray); |
---|
4680 | cExArray = McFsmStateDebugFormulaMine(options, lChild, secondlastState, modelFsm, careSetArray, *preCExArray); |
---|
4681 | break; |
---|
4682 | default: |
---|
4683 | fail("Reached bad switch in FsmPathDebugEXFormulaMine\n"); |
---|
4684 | } |
---|
4685 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEXFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
4686 | // array_free(prevCExArray); |
---|
4687 | return witnessArray; |
---|
4688 | } |
---|
4689 | |
---|
4690 | |
---|
4691 | /**Function******************************************************************** |
---|
4692 | |
---|
4693 | Synopsis [Debug a path for EU type formula.] |
---|
4694 | |
---|
4695 | SideEffects [] |
---|
4696 | |
---|
4697 | ******************************************************************************/ |
---|
4698 | static array_t * |
---|
4699 | FsmPathDebugEUFormulaMine( |
---|
4700 | McOptions_t *options, |
---|
4701 | Ctlp_Formula_t *ctlFormula, |
---|
4702 | Fsm_Fsm_t *modelFsm, |
---|
4703 | McPath_t *witnessPath, |
---|
4704 | array_t *careSetArray, |
---|
4705 | array_t **preCExArray) |
---|
4706 | { |
---|
4707 | (void) fprintf(vis_stdout, "![FsmPathDebugEUFormulaMine] Original CTL Formula : "); |
---|
4708 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
4709 | (void) fprintf(vis_stdout, "\n![FsmPathDebugEUFormulaMine] MC CTL Formula : "); |
---|
4710 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEUFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
4711 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
4712 | fprintf(vis_stdout, "\n"); |
---|
4713 | array_t *cExArray; |
---|
4714 | // array_t *prevCExArray; |
---|
4715 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
4716 | |
---|
4717 | char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula ); |
---|
4718 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
4719 | Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( ctlFormula ); |
---|
4720 | char *lFormulaText = Ctlp_FormulaConvertToString( lFormula ); |
---|
4721 | char *rFormulaText = Ctlp_FormulaConvertToString( rFormula ); |
---|
4722 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
4723 | array_t *witnessArray = McPathReadStemArray( witnessPath ); |
---|
4724 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
4725 | mdd_t *lastState = GET_NORMAL_PT(array_fetch_last( mdd_t *, witnessArray )); |
---|
4726 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
4727 | Fsm_FsmReadNetwork(modelFsm)); |
---|
4728 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
4729 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
4730 | |
---|
4731 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
4732 | fprintf(vis_stdout, "--State\n%spasses EU formula\n\n", |
---|
4733 | firstStateName); |
---|
4734 | else |
---|
4735 | fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName, |
---|
4736 | ctlFormulaText ); |
---|
4737 | |
---|
4738 | if ( array_n(witnessArray ) == 1 ) { |
---|
4739 | (void) fprintf(vis_stderr, "-[FsmPathDebugEUFormulaMine] *VERIFICATION REQUIRED!* CEx n_state = %d \n", array_n(witnessArray)); |
---|
4740 | Mc_PrintPath(witnessArray, modelFsm, printInputs); // added |
---|
4741 | } |
---|
4742 | |
---|
4743 | (void) fprintf(vis_stderr, "-[FsmPathDebugEUFormulaMine] array_n(witnessArrayEU) = %d\n",array_n(witnessArray)); |
---|
4744 | |
---|
4745 | FREE(firstStateName); |
---|
4746 | FREE(ctlFormulaText); |
---|
4747 | |
---|
4748 | switch ( debugLevel ) { |
---|
4749 | case McDbgLevelMin_c: |
---|
4750 | case McDbgLevelMinVerbose_c: |
---|
4751 | if ( array_n(witnessArray ) == 1 ) { |
---|
4752 | if( debugLevel != McDbgLevelMin_c ) |
---|
4753 | fprintf(vis_stdout, "since %s is true at this state", rFormulaText); |
---|
4754 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
4755 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
4756 | } |
---|
4757 | else { |
---|
4758 | if( debugLevel != McDbgLevelMin_c ) |
---|
4759 | fprintf(vis_stdout, "--Path on which %s is true till %s is true\n", |
---|
4760 | lFormulaText, rFormulaText); |
---|
4761 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
4762 | Mc_PrintPath(witnessArray, modelFsm, printInputs); |
---|
4763 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
4764 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
4765 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
4766 | } |
---|
4767 | break; |
---|
4768 | case McDbgLevelMax_c: |
---|
4769 | case McDbgLevelInteractive_c: |
---|
4770 | if ( array_n(witnessArray ) == 1 ) { |
---|
4771 | fprintf(vis_stdout, "since %s is true at this state", rFormulaText); |
---|
4772 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
4773 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
4774 | } |
---|
4775 | else { |
---|
4776 | int i; |
---|
4777 | fprintf(vis_stdout, "--Path on which %s is true till %s is true\n", |
---|
4778 | lFormulaText, rFormulaText); |
---|
4779 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
4780 | Mc_PrintPath(witnessArray,modelFsm,printInputs); |
---|
4781 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
4782 | for( i=0 ; i < ( array_n( witnessArray ) - 1 ); i++ ) { |
---|
4783 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
4784 | |
---|
4785 | if (debugLevel == McDbgLevelMax_c || |
---|
4786 | (debugLevel == McDbgLevelInteractive_c && |
---|
4787 | McQueryContinue( |
---|
4788 | "Continue debugging EU formula? (1-yes,0-no)\n"))) { |
---|
4789 | // cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
4790 | cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
4791 | } |
---|
4792 | } |
---|
4793 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
4794 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
4795 | } |
---|
4796 | break; |
---|
4797 | default: |
---|
4798 | fail("Should not be here - bad switch in debugging EU formula\n"); |
---|
4799 | } |
---|
4800 | |
---|
4801 | FREE(lFormulaText); |
---|
4802 | FREE(rFormulaText); |
---|
4803 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEUFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
4804 | // array_free(prevCExArray); |
---|
4805 | return witnessArray; |
---|
4806 | } |
---|
4807 | |
---|
4808 | /**Function******************************************************************** |
---|
4809 | |
---|
4810 | Synopsis [Debug a path for EG type formula.] |
---|
4811 | |
---|
4812 | SideEffects [] |
---|
4813 | |
---|
4814 | ******************************************************************************/ |
---|
4815 | static array_t * |
---|
4816 | FsmPathDebugEGFormulaMine( |
---|
4817 | McOptions_t *options, |
---|
4818 | Ctlp_Formula_t *ctlFormula, |
---|
4819 | Fsm_Fsm_t *modelFsm, |
---|
4820 | McPath_t *witnessPath, |
---|
4821 | array_t *careSetArray, |
---|
4822 | array_t **preCExArray) |
---|
4823 | { |
---|
4824 | (void) fprintf(vis_stdout, "![FsmPathDebugEGFormulaMine] Original CTL Formula : "); |
---|
4825 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
4826 | (void) fprintf(vis_stdout, "\n![FsmPathDebugEGFormulaMine] MC CTL Formula : "); |
---|
4827 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEGFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
4828 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
4829 | fprintf(vis_stdout, "\n"); |
---|
4830 | array_t *cExArray; |
---|
4831 | // array_t *prevCExArray; |
---|
4832 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
4833 | |
---|
4834 | mdd_t *firstState; |
---|
4835 | char *firstStateName; |
---|
4836 | array_t *witnessArray; |
---|
4837 | array_t *witness; |
---|
4838 | char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula ); |
---|
4839 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
4840 | array_t *stemArray = McPathReadStemArray( witnessPath ); |
---|
4841 | array_t *cycleArray = McPathReadCycleArray( witnessPath ); |
---|
4842 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
4843 | char *lFormulaText = Ctlp_FormulaConvertToString( lFormula ); |
---|
4844 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
4845 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
4846 | |
---|
4847 | witnessArray = McCreateMergedPath( stemArray, cycleArray ); |
---|
4848 | firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
4849 | firstStateName = Mc_MintermToString(firstState, PSVars,Fsm_FsmReadNetwork(modelFsm)); |
---|
4850 | |
---|
4851 | |
---|
4852 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(stemArrayEG) = %d\n",array_n(stemArray)); |
---|
4853 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(cycleArrayEG) = %d\n",array_n(cycleArray)); |
---|
4854 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(witnessArrayEG) = %d\n",array_n(witnessArray)); |
---|
4855 | |
---|
4856 | |
---|
4857 | |
---|
4858 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
4859 | fprintf(vis_stdout, "--State\n%spasses EG formula\n\n", |
---|
4860 | firstStateName); |
---|
4861 | else |
---|
4862 | fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName, |
---|
4863 | ctlFormulaText ); |
---|
4864 | |
---|
4865 | FREE(firstStateName); |
---|
4866 | FREE(ctlFormulaText); |
---|
4867 | |
---|
4868 | switch ( debugLevel ) { |
---|
4869 | case McDbgLevelMin_c: |
---|
4870 | case McDbgLevelMinVerbose_c: { |
---|
4871 | McPath_t *normalPath = McPathNormalize( witnessPath ); |
---|
4872 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
4873 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
4874 | |
---|
4875 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
4876 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
4877 | witness = McCreateMergedPath( stem, cycle ); |
---|
4878 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
4879 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
4880 | Mc_PrintPath( witness, modelFsm, printInputs ); |
---|
4881 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
4882 | |
---|
4883 | if(debugLevel != McDbgLevelMin_c) |
---|
4884 | fprintf(vis_stdout, "--Witness is a fair path where %s is always true\n", |
---|
4885 | lFormulaText); |
---|
4886 | |
---|
4887 | FREE( lFormulaText ); |
---|
4888 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
4889 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
4890 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
4891 | |
---|
4892 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
4893 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
4894 | fprintf(vis_stdout, "\n"); |
---|
4895 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
4896 | McPathFree( normalPath ); |
---|
4897 | break; |
---|
4898 | } |
---|
4899 | case McDbgLevelMax_c: |
---|
4900 | case McDbgLevelInteractive_c: { |
---|
4901 | McPath_t *normalPath = McPathNormalize( witnessPath ); |
---|
4902 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
4903 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
4904 | int i; |
---|
4905 | |
---|
4906 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
4907 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
4908 | witness = McCreateMergedPath( stem, cycle ); |
---|
4909 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
4910 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
4911 | Mc_PrintPath( witness, modelFsm, printInputs ); |
---|
4912 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
4913 | |
---|
4914 | fprintf(vis_stdout, "--Witness is a fair path where %s is always true\n", |
---|
4915 | lFormulaText); |
---|
4916 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
4917 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
4918 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
4919 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
4920 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
4921 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
4922 | for( i=0 ; i < ( array_n( witnessArray )-1 ); i++ ) { |
---|
4923 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
4924 | |
---|
4925 | if (debugLevel == McDbgLevelMax_c || |
---|
4926 | (debugLevel == McDbgLevelInteractive_c && |
---|
4927 | McQueryContinue( |
---|
4928 | "--Continue debugging EG formula? (1-yes,0-no)\n"))) { |
---|
4929 | // cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
4930 | cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
4931 | } |
---|
4932 | } |
---|
4933 | break; |
---|
4934 | } |
---|
4935 | default: |
---|
4936 | fail("Bad switch in FsmPathDebugEGFormulaMine\n"); |
---|
4937 | witness = NIL(array_t); |
---|
4938 | } |
---|
4939 | |
---|
4940 | McNormalizeBddPointer(witnessArray); |
---|
4941 | mdd_array_free( witnessArray ); |
---|
4942 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEGFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
4943 | // array_free(prevCExArray); |
---|
4944 | return witness; |
---|
4945 | } |
---|
4946 | |
---|
4947 | /**Function******************************************************************** |
---|
4948 | |
---|
4949 | Synopsis [Debug a EF formula] |
---|
4950 | |
---|
4951 | SideEffects [] |
---|
4952 | |
---|
4953 | ******************************************************************************/ |
---|
4954 | static array_t * |
---|
4955 | FsmPathDebugEFFormulaMine( |
---|
4956 | McOptions_t *options, |
---|
4957 | Ctlp_Formula_t *ctlFormula, |
---|
4958 | Fsm_Fsm_t *modelFsm, |
---|
4959 | McPath_t *witnessPath, |
---|
4960 | array_t *careSetArray, |
---|
4961 | array_t **preCExArray) |
---|
4962 | { |
---|
4963 | (void) fprintf(vis_stdout, "![FsmPathDebugEFFormulaMine] Original CTL Formula : "); |
---|
4964 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
4965 | (void) fprintf(vis_stdout, "\n![FsmPathDebugEFFormulaMine] MC CTL Formula : "); |
---|
4966 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEFFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
4967 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
4968 | fprintf(vis_stdout, "\n"); |
---|
4969 | array_t *cExArray; |
---|
4970 | // array_t *prevCExArray; |
---|
4971 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
4972 | |
---|
4973 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
4974 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
4975 | |
---|
4976 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
4977 | array_t *witnessArray = McPathReadStemArray( witnessPath ); |
---|
4978 | |
---|
4979 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
4980 | mdd_t *lastState = array_fetch_last( mdd_t *, witnessArray ); |
---|
4981 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
4982 | Fsm_FsmReadNetwork(modelFsm)); |
---|
4983 | |
---|
4984 | Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( ctlFormula ); |
---|
4985 | Ctlp_Formula_t *rOriginalFormula = Ctlp_FormulaReadOriginalFormula(rFormula); |
---|
4986 | char *rOriginalFormulaText = Ctlp_FormulaConvertToString( rOriginalFormula ); |
---|
4987 | char *rFormulaText = Ctlp_FormulaConvertToString( rFormula ); |
---|
4988 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
4989 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
4990 | |
---|
4991 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
4992 | fprintf(vis_stdout, "--State\n%spasses EF formula\n\n", |
---|
4993 | firstStateName); |
---|
4994 | else |
---|
4995 | fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName, |
---|
4996 | originalFormulaText ); |
---|
4997 | |
---|
4998 | // Added in case if there's no counter example => CTL fails at initial state |
---|
4999 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAGFormulaMine] 1) CEx n_state = %d \n", array_n(witnessArray)); |
---|
5000 | if ( array_n(witnessArray ) == 1 ) { |
---|
5001 | (void) fprintf(vis_stderr, "-[FsmPathDebugEFFormulaMine] *VERIFICATION REQUIRED!* CEx n_state = %d \n", array_n(witnessArray)); |
---|
5002 | Mc_PrintPath(witnessArray, modelFsm, printInputs); // added |
---|
5003 | } |
---|
5004 | (void) fprintf(vis_stderr, "-[FsmPathDebugEFFormulaMine] array_n(witnessArrayEF) = %d\n",array_n(witnessArray)); |
---|
5005 | |
---|
5006 | FREE(firstStateName); |
---|
5007 | FREE(originalFormulaText); |
---|
5008 | |
---|
5009 | switch ( debugLevel ) { |
---|
5010 | case McDbgLevelMin_c: |
---|
5011 | case McDbgLevelMinVerbose_c: |
---|
5012 | if ( array_n(witnessArray ) == 1 ) { |
---|
5013 | if( debugLevel != McDbgLevelMin_c) |
---|
5014 | fprintf(vis_stdout, "since %s is true at this state\n", |
---|
5015 | rOriginalFormulaText); |
---|
5016 | |
---|
5017 | FREE( rOriginalFormulaText ); |
---|
5018 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5019 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5020 | } |
---|
5021 | else { |
---|
5022 | if( debugLevel != McDbgLevelMin_c) |
---|
5023 | fprintf(vis_stdout, |
---|
5024 | "--Witness is a path to a state where %s is finally true\n", |
---|
5025 | rOriginalFormulaText); |
---|
5026 | (void) fprintf( vis_stdout, "\n--Fair path stem:\n"); |
---|
5027 | FREE( rOriginalFormulaText ); |
---|
5028 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5029 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
5030 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5031 | } |
---|
5032 | break; |
---|
5033 | case McDbgLevelMax_c: |
---|
5034 | case McDbgLevelInteractive_c: |
---|
5035 | if ( array_n(witnessArray ) == 1 ) { |
---|
5036 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5037 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5038 | } |
---|
5039 | else |
---|
5040 | { |
---|
5041 | fprintf(vis_stdout, |
---|
5042 | "--Witness is a path to a state where %s is finally true\n", |
---|
5043 | rOriginalFormulaText); |
---|
5044 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5045 | Mc_PrintPath( witnessArray, modelFsm, printInputs); |
---|
5046 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5047 | if (debugLevel == McDbgLevelMax_c || |
---|
5048 | (debugLevel == McDbgLevelInteractive_c && |
---|
5049 | McQueryContinue( |
---|
5050 | "--Continue debugging EF formula? (1-yes,0-no)\n"))) |
---|
5051 | { |
---|
5052 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5053 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5054 | } |
---|
5055 | } |
---|
5056 | break; |
---|
5057 | default: |
---|
5058 | fail("bad switch in debugging EF\n"); |
---|
5059 | } |
---|
5060 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEFFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
5061 | // array_free(prevCExArray); |
---|
5062 | FREE(rFormulaText); |
---|
5063 | return witnessArray; |
---|
5064 | } |
---|
5065 | |
---|
5066 | |
---|
5067 | /**Function******************************************************************** |
---|
5068 | |
---|
5069 | Synopsis [Debug a AX formula] |
---|
5070 | |
---|
5071 | SideEffects [] |
---|
5072 | |
---|
5073 | ******************************************************************************/ |
---|
5074 | static array_t * |
---|
5075 | FsmPathDebugAXFormulaMine( |
---|
5076 | McOptions_t *options, |
---|
5077 | Ctlp_Formula_t *ctlFormula, |
---|
5078 | Fsm_Fsm_t *modelFsm, |
---|
5079 | McPath_t *counterExamplePath, |
---|
5080 | array_t *careSetArray, |
---|
5081 | array_t **preCExArray) |
---|
5082 | { |
---|
5083 | (void) fprintf(vis_stdout, "![FsmPathDebugAXFormulaMine] Original CTL Formula : "); |
---|
5084 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
5085 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAXFormulaMine] MC CTL Formula : "); |
---|
5086 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAXFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
5087 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
5088 | fprintf(vis_stdout, "\n"); |
---|
5089 | array_t *cExArray; |
---|
5090 | // array_t *prevCExArray; |
---|
5091 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
5092 | |
---|
5093 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
5094 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
5095 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
5096 | Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula ); |
---|
5097 | Ctlp_Formula_t *lllFormula = Ctlp_FormulaReadLeftChild( llFormula ); |
---|
5098 | |
---|
5099 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
5100 | array_t *witnessArray = McPathReadStemArray( counterExamplePath ); |
---|
5101 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
5102 | mdd_t *lastState = array_fetch( mdd_t *, witnessArray, 1 ); |
---|
5103 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
5104 | Fsm_FsmReadNetwork(modelFsm)); |
---|
5105 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
5106 | |
---|
5107 | (void) fprintf(vis_stderr, "-[FsmPathDebugAXFormulaMine] array_n(witnessArrayAX) = %d\n",array_n(witnessArray)); |
---|
5108 | |
---|
5109 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
5110 | fprintf(vis_stdout, "--State\n%sfails AX formula\n\n", |
---|
5111 | firstStateName); |
---|
5112 | else |
---|
5113 | fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName, |
---|
5114 | originalFormulaText ); |
---|
5115 | |
---|
5116 | FREE(firstStateName); |
---|
5117 | FREE(originalFormulaText); |
---|
5118 | |
---|
5119 | switch ( McOptionsReadDbgLevel( options ) ) { |
---|
5120 | case McDbgLevelMin_c: |
---|
5121 | case McDbgLevelMinVerbose_c: |
---|
5122 | case McDbgLevelMax_c: |
---|
5123 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5124 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
5125 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5126 | fprintf(vis_stdout, "\n"); |
---|
5127 | // cExArray = McFsmStateDebugFormulaMine(options, lllFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5128 | cExArray = McFsmStateDebugFormulaMine(options, lllFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5129 | break; |
---|
5130 | case McDbgLevelInteractive_c: |
---|
5131 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5132 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
5133 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5134 | if ( McQueryContinue("Continue debugging EX formula? (1-yes,0-no)\n") ) { |
---|
5135 | // cExArray = McFsmStateDebugFormulaMine(options, lllFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5136 | cExArray = McFsmStateDebugFormulaMine(options, lllFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5137 | } |
---|
5138 | break; |
---|
5139 | default: |
---|
5140 | fail("Bad switch in FsmPathDebugAXFormulaMine\n"); |
---|
5141 | } |
---|
5142 | |
---|
5143 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAXFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
5144 | // array_free(prevCExArray); |
---|
5145 | return witnessArray; |
---|
5146 | } |
---|
5147 | |
---|
5148 | /**Function******************************************************************** |
---|
5149 | |
---|
5150 | Synopsis [Debug a AF formula] |
---|
5151 | |
---|
5152 | SideEffects [] |
---|
5153 | |
---|
5154 | ******************************************************************************/ |
---|
5155 | static array_t * |
---|
5156 | FsmPathDebugAFFormulaMine( |
---|
5157 | McOptions_t *options, |
---|
5158 | Ctlp_Formula_t *ctlFormula, |
---|
5159 | Fsm_Fsm_t *modelFsm, |
---|
5160 | McPath_t *counterExamplePath, |
---|
5161 | array_t *careSetArray, |
---|
5162 | array_t **preCExArray) |
---|
5163 | { |
---|
5164 | (void) fprintf(vis_stdout, "![FsmPathDebugAFFormulaMine] Original CTL Formula : "); |
---|
5165 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
5166 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAFFormulaMine] MC CTL Formula : "); |
---|
5167 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAFFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
5168 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
5169 | fprintf(vis_stdout, "\n"); |
---|
5170 | array_t *cExArray; |
---|
5171 | // array_t *prevCExArray; |
---|
5172 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
5173 | |
---|
5174 | |
---|
5175 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
5176 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
5177 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
5178 | Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula ); |
---|
5179 | Ctlp_Formula_t *lllFormula = Ctlp_FormulaReadLeftChild( llFormula ); |
---|
5180 | Ctlp_Formula_t *lllOriginalFormula = Ctlp_FormulaReadOriginalFormula( |
---|
5181 | lllFormula); |
---|
5182 | char *lllOriginalFormulaText = Ctlp_FormulaConvertToString( |
---|
5183 | lllOriginalFormula); |
---|
5184 | |
---|
5185 | mdd_t *firstState; |
---|
5186 | array_t *witnessArray; |
---|
5187 | array_t *witness; |
---|
5188 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
5189 | array_t *stemArray = McPathReadStemArray( counterExamplePath ); |
---|
5190 | array_t *cycleArray = McPathReadCycleArray( counterExamplePath ); |
---|
5191 | char *firstStateName; |
---|
5192 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
5193 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
5194 | |
---|
5195 | witnessArray = McCreateMergedPath( stemArray, cycleArray ); |
---|
5196 | firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
5197 | firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
5198 | Fsm_FsmReadNetwork(modelFsm)); |
---|
5199 | |
---|
5200 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(stemArrayEG) = %d\n",array_n(stemArray)); |
---|
5201 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(cycleArrayEG) = %d\n",array_n(cycleArray)); |
---|
5202 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(witnessArrayEG) = %d\n",array_n(witnessArray)); |
---|
5203 | |
---|
5204 | |
---|
5205 | |
---|
5206 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
5207 | fprintf(vis_stdout, "--State\n%sfails AF formula\n\n", |
---|
5208 | firstStateName); |
---|
5209 | else |
---|
5210 | fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName, |
---|
5211 | originalFormulaText ); |
---|
5212 | FREE(firstStateName); |
---|
5213 | FREE(originalFormulaText); |
---|
5214 | |
---|
5215 | switch ( debugLevel ) { |
---|
5216 | case McDbgLevelMin_c: |
---|
5217 | case McDbgLevelMinVerbose_c: { |
---|
5218 | McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
5219 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
5220 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
5221 | |
---|
5222 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
5223 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
5224 | witness = McCreateMergedPath( stem, cycle ); |
---|
5225 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
5226 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
5227 | Mc_PrintPath( witness, modelFsm, printInputs ); |
---|
5228 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
5229 | |
---|
5230 | if( debugLevel != McDbgLevelMin_c) |
---|
5231 | fprintf(vis_stdout, "--A fair path on which %s is always false:\n", |
---|
5232 | lllOriginalFormulaText ); |
---|
5233 | |
---|
5234 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5235 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
5236 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
5237 | |
---|
5238 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
5239 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
5240 | fprintf(vis_stdout, "\n"); |
---|
5241 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5242 | McPathFree( normalPath ); |
---|
5243 | break; |
---|
5244 | } |
---|
5245 | case McDbgLevelMax_c: |
---|
5246 | case McDbgLevelInteractive_c: { |
---|
5247 | int i; |
---|
5248 | McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
5249 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
5250 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
5251 | |
---|
5252 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
5253 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
5254 | witness = McCreateMergedPath( stem, cycle ); |
---|
5255 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
5256 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
5257 | Mc_PrintPath( witness, modelFsm, printInputs ); |
---|
5258 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
5259 | |
---|
5260 | |
---|
5261 | fprintf(vis_stdout, "--A fair path on which %s is always false:\n", |
---|
5262 | lllOriginalFormulaText ); |
---|
5263 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5264 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
5265 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
5266 | |
---|
5267 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
5268 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
5269 | fprintf(vis_stdout, "\n"); |
---|
5270 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5271 | McPathFree( normalPath ); |
---|
5272 | for( i=0 ; i < ( array_n( witnessArray )-1 ); i++ ) { |
---|
5273 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
5274 | |
---|
5275 | if (debugLevel == McDbgLevelMax_c || |
---|
5276 | (debugLevel == McDbgLevelInteractive_c && |
---|
5277 | McQueryContinue( |
---|
5278 | "--Continue debugging AF formula? (1-yes,0-no)\n"))) { |
---|
5279 | // cExArray = McFsmStateDebugFormulaMine(options, lllFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
5280 | cExArray = McFsmStateDebugFormulaMine(options, lllFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
5281 | } |
---|
5282 | } |
---|
5283 | |
---|
5284 | break; |
---|
5285 | } |
---|
5286 | default: { |
---|
5287 | fail("Bad case in switch for debugging AF formula\n"); |
---|
5288 | witness = NIL(array_t); |
---|
5289 | } |
---|
5290 | } |
---|
5291 | |
---|
5292 | // array_free(prevCExArray); |
---|
5293 | McNormalizeBddPointer(witnessArray); |
---|
5294 | mdd_array_free( witnessArray ); |
---|
5295 | FREE(lllOriginalFormulaText); |
---|
5296 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAFFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
5297 | return witness; |
---|
5298 | } |
---|
5299 | |
---|
5300 | /**Function******************************************************************** |
---|
5301 | |
---|
5302 | Synopsis [Debug an AG formula.] |
---|
5303 | |
---|
5304 | Description [Debugs an AG formula. What it really wants is a formula of the |
---|
5305 | form !EF! phi, that was converted from the formula AG phi, with all the |
---|
5306 | converted pointers set as required: the top ! points to the original AG |
---|
5307 | formula, and top node of phi points to the original phi.] |
---|
5308 | |
---|
5309 | SideEffects [] |
---|
5310 | |
---|
5311 | ******************************************************************************/ |
---|
5312 | static array_t * |
---|
5313 | FsmPathDebugAGFormulaMine( |
---|
5314 | McOptions_t *options, |
---|
5315 | Ctlp_Formula_t *ctlFormula, |
---|
5316 | Fsm_Fsm_t *modelFsm, |
---|
5317 | McPath_t *counterExamplePath, |
---|
5318 | array_t *careSetArray, |
---|
5319 | array_t **preCExArray) |
---|
5320 | { |
---|
5321 | (void) fprintf(vis_stdout, "![FsmPathDebugAGFormulaMine] Original CTL Formula : "); |
---|
5322 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
5323 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAGFormulaMine] MC CTL Formula : "); |
---|
5324 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAGFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
5325 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
5326 | fprintf(vis_stdout, "\n"); |
---|
5327 | array_t *cExArray; |
---|
5328 | // array_t *prevCExArray; |
---|
5329 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
5330 | |
---|
5331 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
5332 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
5333 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
5334 | Ctlp_Formula_t *lrFormula = Ctlp_FormulaReadRightChild( lFormula ); |
---|
5335 | Ctlp_Formula_t *lrlFormula = Ctlp_FormulaReadLeftChild( lrFormula ); |
---|
5336 | Ctlp_Formula_t *lrlOriginalFormula = Ctlp_FormulaReadOriginalFormula( |
---|
5337 | lrlFormula); |
---|
5338 | char *lrlOriginalFormulaText = Ctlp_FormulaConvertToString( |
---|
5339 | lrlOriginalFormula); |
---|
5340 | |
---|
5341 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
5342 | array_t *witnessArray = McPathReadStemArray( counterExamplePath ); |
---|
5343 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
5344 | mdd_t *lastState = GET_NORMAL_PT(array_fetch_last( mdd_t *, witnessArray )); |
---|
5345 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
5346 | Fsm_FsmReadNetwork(modelFsm)); |
---|
5347 | |
---|
5348 | // CEXStruct CEXPath [array_n( aPath )]; |
---|
5349 | // *Mc_MintermToStringMine( mdd_t *aMinterm, array_t *aSupport, Ntk_Network_t *aNetwork, CEXStruct *CEXPath, int seqNumber, boolean inOutIndicator, BmcCnfClauses_t *cnfClauses); |
---|
5350 | (void) fprintf(vis_stderr, "-[FsmPathDebugAGFormulaMine] array_n(witnessArrayAG) = %d\n",array_n(witnessArray)); |
---|
5351 | |
---|
5352 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
5353 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
5354 | |
---|
5355 | assert( Ctlp_FormulaReadType(ctlFormula) == Ctlp_NOT_c ); |
---|
5356 | assert( Ctlp_FormulaTestIsConverted(ctlFormula) ); |
---|
5357 | assert( Ctlp_FormulaReadType(originalFormula) == Ctlp_AG_c ); |
---|
5358 | assert( originalFormulaText != NIL(char) ); |
---|
5359 | assert( Ctlp_FormulaReadType(lFormula) == Ctlp_EU_c ); |
---|
5360 | assert( Ctlp_FormulaReadType(Ctlp_FormulaReadLeftChild(lFormula)) == |
---|
5361 | Ctlp_TRUE_c ); |
---|
5362 | assert( Ctlp_FormulaReadType(lrFormula) == Ctlp_NOT_c ); |
---|
5363 | assert( lrlOriginalFormula != NIL(Ctlp_Formula_t) ); |
---|
5364 | |
---|
5365 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
5366 | fprintf(vis_stdout, "--State\n%sfails AG formula\n\n", |
---|
5367 | firstStateName); |
---|
5368 | else |
---|
5369 | fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName, |
---|
5370 | originalFormulaText ); |
---|
5371 | |
---|
5372 | // Added in case if there's no counter example => CTL fails at initial state |
---|
5373 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAGFormulaMine] 1) CEx n_state = %d \n", array_n(witnessArray)); |
---|
5374 | if ( array_n(witnessArray ) == 1 ) { |
---|
5375 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAGFormulaMine] 2) CEx n_state = %d \n", array_n(witnessArray)); |
---|
5376 | Mc_PrintPath(witnessArray, modelFsm, printInputs); // added |
---|
5377 | } |
---|
5378 | FREE(firstStateName); |
---|
5379 | FREE(originalFormulaText); |
---|
5380 | |
---|
5381 | switch ( debugLevel ) { |
---|
5382 | case McDbgLevelMin_c: |
---|
5383 | case McDbgLevelMinVerbose_c:{ |
---|
5384 | if ( array_n(witnessArray ) == 1 ) { |
---|
5385 | if( debugLevel != McDbgLevelMin_c) |
---|
5386 | fprintf(vis_stdout, "since %s is false at this state\n", |
---|
5387 | lrlOriginalFormulaText ); |
---|
5388 | // cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5389 | cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5390 | } |
---|
5391 | else { |
---|
5392 | if( debugLevel != McDbgLevelMin_c) |
---|
5393 | fprintf(vis_stdout, |
---|
5394 | "--Counter example is a path to a state where %s is false\n", |
---|
5395 | lrlOriginalFormulaText); |
---|
5396 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5397 | Mc_PrintPath(witnessArray, modelFsm, printInputs); |
---|
5398 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5399 | // cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5400 | cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5401 | } |
---|
5402 | break; |
---|
5403 | } |
---|
5404 | case McDbgLevelMax_c: |
---|
5405 | case McDbgLevelInteractive_c: { |
---|
5406 | if ( array_n(witnessArray ) == 1 ) { |
---|
5407 | if( debugLevel != McDbgLevelMin_c) |
---|
5408 | fprintf(vis_stdout, "since %s is false at this state\n", |
---|
5409 | lrlOriginalFormulaText ); |
---|
5410 | // cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5411 | cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5412 | } |
---|
5413 | else { |
---|
5414 | fprintf(vis_stdout, |
---|
5415 | "--Counter example is a path to a state where %s is false\n", |
---|
5416 | lrlOriginalFormulaText); |
---|
5417 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5418 | Mc_PrintPath( witnessArray, modelFsm, printInputs); |
---|
5419 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5420 | if (debugLevel == McDbgLevelMax_c || |
---|
5421 | (debugLevel == McDbgLevelInteractive_c && |
---|
5422 | McQueryContinue( |
---|
5423 | "--Continue debugging AG formula? (1-yes,0-no)\n"))) |
---|
5424 | { |
---|
5425 | // cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5426 | cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5427 | } |
---|
5428 | } |
---|
5429 | break; |
---|
5430 | } |
---|
5431 | default: { |
---|
5432 | fail("bad switch in debugging AG\n"); |
---|
5433 | } |
---|
5434 | } |
---|
5435 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAGFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
5436 | // array_free(prevCExArray); |
---|
5437 | FREE(lrlOriginalFormulaText); |
---|
5438 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAGFormulaMine] *** Mc_PrintPathMine STARTS ----------------------\n"); |
---|
5439 | // Mc_PrintPathMine(witnessArray, modelFsm, printInputs); |
---|
5440 | // (void) fprintf(vis_stdout, "![FsmPathDebugAGFormulaMine] Mc_PrintPathMine ENDS *** -------------------------\n"); |
---|
5441 | return witnessArray; |
---|
5442 | } |
---|
5443 | |
---|
5444 | /**Function******************************************************************** |
---|
5445 | |
---|
5446 | Synopsis [Debug a AU formula] |
---|
5447 | |
---|
5448 | SideEffects [] |
---|
5449 | |
---|
5450 | ******************************************************************************/ |
---|
5451 | static array_t * |
---|
5452 | FsmPathDebugAUFormulaMine( |
---|
5453 | McOptions_t *options, |
---|
5454 | mdd_t *aState, |
---|
5455 | Ctlp_Formula_t *ctlFormula, |
---|
5456 | Fsm_Fsm_t *modelFsm, |
---|
5457 | array_t *careSetArray, |
---|
5458 | array_t **preCExArray) |
---|
5459 | { |
---|
5460 | (void) fprintf(vis_stdout, "![FsmPathDebugAUFormulaMine] Original CTL Formula : "); |
---|
5461 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
5462 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] MC CTL Formula : "); |
---|
5463 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 0 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
5464 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
5465 | fprintf(vis_stdout, "\n"); |
---|
5466 | array_t *cExArray; |
---|
5467 | // array_t *prevCExArray; |
---|
5468 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
5469 | |
---|
5470 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
5471 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
5472 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
5473 | Ctlp_Formula_t *lrFormula = Ctlp_FormulaReadRightChild( lFormula ); |
---|
5474 | Ctlp_Formula_t *lrlFormula = Ctlp_FormulaReadLeftChild( lrFormula ); |
---|
5475 | Ctlp_Formula_t *lrllFormula = Ctlp_FormulaReadLeftChild( lrlFormula ); |
---|
5476 | Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula ); |
---|
5477 | Ctlp_Formula_t *llrFormula = Ctlp_FormulaReadRightChild( llFormula ); |
---|
5478 | Ctlp_Formula_t *llrlFormula = Ctlp_FormulaReadLeftChild( llrFormula ); |
---|
5479 | Ctlp_Formula_t *llrllFormula = Ctlp_FormulaReadLeftChild( llrlFormula ); |
---|
5480 | Ctlp_Formula_t *fFormula = llrllFormula; |
---|
5481 | Ctlp_Formula_t *gFormula = lrllFormula; |
---|
5482 | Ctlp_Formula_t *fOriginalFormula = Ctlp_FormulaReadOriginalFormula(fFormula); |
---|
5483 | Ctlp_Formula_t *gOriginalFormula = Ctlp_FormulaReadOriginalFormula(gFormula); |
---|
5484 | char *fText = Ctlp_FormulaConvertToString( fOriginalFormula ); |
---|
5485 | char *gText = Ctlp_FormulaConvertToString( gOriginalFormula ); |
---|
5486 | |
---|
5487 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
5488 | char *firstStateName = Mc_MintermToString(aState, PSVars, |
---|
5489 | Fsm_FsmReadNetwork(modelFsm)); |
---|
5490 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
5491 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
5492 | |
---|
5493 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
5494 | fprintf(vis_stdout, "--State\n%sfails AU formula\n\n", |
---|
5495 | firstStateName); |
---|
5496 | else |
---|
5497 | fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName, |
---|
5498 | originalFormulaText ); |
---|
5499 | FREE(firstStateName); |
---|
5500 | FREE(originalFormulaText); |
---|
5501 | |
---|
5502 | /* orginal formula is A(fUg) => converted is !((E[!g U (!f*!g)]) + (EG!g)) */ |
---|
5503 | |
---|
5504 | if ( McStateSatisfiesFormula( llFormula, aState ) ) { |
---|
5505 | /* |
---|
5506 | * the case E[!g U (!f*!g)] is true |
---|
5507 | */ |
---|
5508 | McPath_t *counterExamplePath = DebugEUMine(llFormula, aState, modelFsm, |
---|
5509 | careSetArray); |
---|
5510 | |
---|
5511 | array_t *stemArray = McPathReadStemArray( counterExamplePath ); |
---|
5512 | array_t *witnessArray = stemArray; |
---|
5513 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
5514 | mdd_t *lastState = array_fetch_last( mdd_t *, witnessArray ); |
---|
5515 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
5516 | Fsm_FsmReadNetwork(modelFsm)); |
---|
5517 | |
---|
5518 | // Added in case if there's no counter example => CTL fails at initial state |
---|
5519 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] 1) CEx n_state = %d \n", array_n(witnessArray)); |
---|
5520 | if ( array_n(witnessArray ) == 1 ) { |
---|
5521 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] *VERIFICATION REQUIRED!* CEx n_state = %d \n", array_n(witnessArray)); |
---|
5522 | Mc_PrintPath(witnessArray, modelFsm, printInputs); // added |
---|
5523 | } |
---|
5524 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(witnessArrayEU) = %d\n",array_n(witnessArray)); |
---|
5525 | |
---|
5526 | switch ( debugLevel ) { |
---|
5527 | case McDbgLevelMinVerbose_c: |
---|
5528 | fprintf(vis_stdout, |
---|
5529 | "--Counter example is a fair path where %s is false until %s is also false\n", |
---|
5530 | gText, fText); |
---|
5531 | case McDbgLevelMin_c: |
---|
5532 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5533 | Mc_PrintPath(witnessArray, modelFsm, printInputs); |
---|
5534 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5535 | // cExArray = McFsmStateDebugFormulaMine(options, llrFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5536 | cExArray = McFsmStateDebugFormulaMine(options, llrFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5537 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 1 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
5538 | break; |
---|
5539 | |
---|
5540 | case McDbgLevelMax_c: |
---|
5541 | case McDbgLevelInteractive_c: { |
---|
5542 | if ( array_n(witnessArray ) == 1 ) { |
---|
5543 | fprintf(vis_stdout, |
---|
5544 | "--At state %s\nformula %s is false and\nformula %s is also false\n", |
---|
5545 | firstStateName, fText, gText); |
---|
5546 | if (debugLevel == McDbgLevelMax_c || |
---|
5547 | (debugLevel == McDbgLevelInteractive_c && |
---|
5548 | McQueryContinue( |
---|
5549 | "Continue debugging AU formula? (1-yes,0-no)\n"))) { |
---|
5550 | // cExArray = McFsmStateDebugFormulaMine(options, fFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
5551 | // cExArray = McFsmStateDebugFormulaMine(options, gFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
5552 | cExArray = McFsmStateDebugFormulaMine(options, fFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
5553 | cExArray = McFsmStateDebugFormulaMine(options, gFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
5554 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 2 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
5555 | } |
---|
5556 | } |
---|
5557 | else { |
---|
5558 | int i; |
---|
5559 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5560 | Mc_PrintPath(witnessArray,modelFsm,printInputs); |
---|
5561 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5562 | for( i=0 ; i < ( array_n( witnessArray ) - 1 ); i++ ) { |
---|
5563 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
5564 | |
---|
5565 | if (debugLevel == McDbgLevelMax_c || |
---|
5566 | (debugLevel == McDbgLevelInteractive_c && |
---|
5567 | McQueryContinue( |
---|
5568 | "Continue debugging AU formula? (1-yes,0-no)\n"))) { |
---|
5569 | // cExArray = McFsmStateDebugFormulaMine(options, gFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
5570 | cExArray = McFsmStateDebugFormulaMine(options, llrFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5571 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 3 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
5572 | } |
---|
5573 | } |
---|
5574 | |
---|
5575 | if (debugLevel == McDbgLevelMax_c || |
---|
5576 | (debugLevel == McDbgLevelInteractive_c && |
---|
5577 | McQueryContinue( |
---|
5578 | "Continue debugging AU formula? (1-yes,0-no)\n"))) { |
---|
5579 | // cExArray = McFsmStateDebugFormulaMine(options, fFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5580 | // cExArray = McFsmStateDebugFormulaMine(options, gFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
5581 | cExArray = McFsmStateDebugFormulaMine(options, fFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5582 | cExArray = McFsmStateDebugFormulaMine(options, gFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
5583 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 4 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
5584 | } |
---|
5585 | } |
---|
5586 | break; |
---|
5587 | } |
---|
5588 | |
---|
5589 | default: { |
---|
5590 | fail("Unknown case in debugging AU\n"); |
---|
5591 | } |
---|
5592 | }/* case */ |
---|
5593 | // McPathFree( counterExamplePath ); NOTE: INITIALLY FREED |
---|
5594 | |
---|
5595 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
5596 | |
---|
5597 | // array_free(prevCExArray); |
---|
5598 | FREE( fText ); |
---|
5599 | FREE( gText ); |
---|
5600 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] *** Mc_PrintPathMine WA STARTS ------------------\n"); |
---|
5601 | // Mc_PrintPathMine(witnessArray, modelFsm, printInputs); |
---|
5602 | // (void) fprintf(vis_stdout, "![FsmPathDebugAUFormulaMine] Mc_PrintPathMine WA ENDS *** -------------------\n"); |
---|
5603 | |
---|
5604 | *preCExArray = cExArray; |
---|
5605 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] LAST ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
5606 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] LAST ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
5607 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] ---> nb witnessArray : %d *END*\n", array_n(witnessArray)); |
---|
5608 | return witnessArray; |
---|
5609 | } |
---|
5610 | else { |
---|
5611 | /* |
---|
5612 | * must be the case that EG!g |
---|
5613 | */ |
---|
5614 | McPath_t *counterExamplePath = DebugEGMine(lrFormula, aState, modelFsm, |
---|
5615 | careSetArray, |
---|
5616 | options); |
---|
5617 | |
---|
5618 | assert( McStateSatisfiesFormula( lrFormula, aState ) ); |
---|
5619 | |
---|
5620 | array_t *stemArray = McPathReadStemArray( counterExamplePath ); |
---|
5621 | array_t *cycleArray = McPathReadCycleArray( counterExamplePath ); |
---|
5622 | array_t *witnessArray = McCreateMergedPath( stemArray, cycleArray ); |
---|
5623 | McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
5624 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
5625 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
5626 | |
---|
5627 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(stemArrayEG) = %d\n",array_n(stemArray)); |
---|
5628 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(cycleArrayEG) = %d\n",array_n(cycleArray)); |
---|
5629 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(witnessArrayEG) = %d\n",array_n(witnessArray)); |
---|
5630 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
5631 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
5632 | array_t *witness = McCreateMergedPath( stem, cycle ); |
---|
5633 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
5634 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
5635 | // Mc_PrintPathMine( witness, modelFsm, printInputs ); |
---|
5636 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
5637 | |
---|
5638 | |
---|
5639 | |
---|
5640 | if( debugLevel != McDbgLevelMin_c) |
---|
5641 | fprintf(vis_stdout, |
---|
5642 | "--Counter example is a fair path where %s is always false\n", |
---|
5643 | gText); |
---|
5644 | |
---|
5645 | switch ( debugLevel ) { |
---|
5646 | case McDbgLevelMin_c: |
---|
5647 | case McDbgLevelMinVerbose_c:{ |
---|
5648 | /* McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
5649 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
5650 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
5651 | */ |
---|
5652 | |
---|
5653 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5654 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
5655 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
5656 | |
---|
5657 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
5658 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
5659 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5660 | McPathFree( normalPath ); |
---|
5661 | |
---|
5662 | break; |
---|
5663 | } |
---|
5664 | |
---|
5665 | case McDbgLevelMax_c: |
---|
5666 | case McDbgLevelInteractive_c: |
---|
5667 | { |
---|
5668 | int i; |
---|
5669 | /* array_t *stemArray = McPathReadStemArray( counterExamplePath ); |
---|
5670 | array_t *cycleArray = McPathReadCycleArray( counterExamplePath ); |
---|
5671 | array_t *witnessArray = McCreateMergedPath( stemArray, cycleArray ); |
---|
5672 | McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
5673 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
5674 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
5675 | */ |
---|
5676 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
5677 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
5678 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
5679 | |
---|
5680 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
5681 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
5682 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
5683 | McPathFree( normalPath ); |
---|
5684 | for( i=0 ; i < ( array_n( witnessArray )-1 ); i++ ) { |
---|
5685 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
5686 | |
---|
5687 | if (debugLevel == McDbgLevelMax_c || |
---|
5688 | (debugLevel == McDbgLevelInteractive_c && |
---|
5689 | McQueryContinue( |
---|
5690 | "--Continue debugging AU formula? (1-yes,0-no)\n"))) { |
---|
5691 | // cExArray = McFsmStateDebugFormulaMine(options, lrllFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
5692 | cExArray = McFsmStateDebugFormulaMine(options, lrllFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
5693 | *preCExArray = cExArray; |
---|
5694 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] EG 1 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
5695 | } |
---|
5696 | } |
---|
5697 | break; |
---|
5698 | } |
---|
5699 | |
---|
5700 | default: { |
---|
5701 | fail("Bad switch in debugging AU formula\n"); |
---|
5702 | } |
---|
5703 | }/* case */ |
---|
5704 | |
---|
5705 | // McPathFree( counterExamplePath ); NOTE: INITIALLY FREED |
---|
5706 | // array_free(prevCExArray); |
---|
5707 | FREE( fText ); |
---|
5708 | FREE( gText ); |
---|
5709 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
5710 | |
---|
5711 | // *preCExArray = cExArray; // preCExArray = &cExArray; |
---|
5712 | |
---|
5713 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] LAST ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
5714 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] LAST ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
5715 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] ---> nb witness : %d *END*\n", array_n(witness)); |
---|
5716 | |
---|
5717 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] *** Mc_PrintPathMine STARTS ------------------ \n"); |
---|
5718 | // Mc_PrintPathMine(witness, modelFsm, printInputs); |
---|
5719 | // (void) fprintf(vis_stdout, "![FsmPathDebugAUFormulaMine] Mc_PrintPathMine ENDS *** --------------------- \n"); |
---|
5720 | return witness; |
---|
5721 | } |
---|
5722 | |
---|
5723 | } |
---|
5724 | |
---|
5725 | |
---|
5726 | |
---|
5727 | /**Function******************************************************************** |
---|
5728 | |
---|
5729 | Synopsis [Utility function - prints states on path, inputs for transitions] |
---|
5730 | |
---|
5731 | SideEffects [] |
---|
5732 | |
---|
5733 | ******************************************************************************/ |
---|
5734 | static int |
---|
5735 | Mc_PrintPathMine( |
---|
5736 | array_t *aPath, |
---|
5737 | Fsm_Fsm_t *modelFsm, |
---|
5738 | boolean printInput) |
---|
5739 | { |
---|
5740 | (void) fprintf(vis_stderr, "![Mc_PrintPathMine] \n"); |
---|
5741 | int check, forced, i; |
---|
5742 | int numForced; |
---|
5743 | mdd_t *inputSet=NIL(mdd_t); |
---|
5744 | mdd_t *uInput = NIL(mdd_t); |
---|
5745 | mdd_t *vInput = NIL(mdd_t); |
---|
5746 | |
---|
5747 | array_t *psVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
5748 | array_t *inputVars = Fsm_FsmReadInputVars( modelFsm ); |
---|
5749 | mdd_manager *mddMgr = Fsm_FsmReadMddManager( modelFsm ); |
---|
5750 | |
---|
5751 | forced = 0; |
---|
5752 | check = 1; |
---|
5753 | numForced = 0; |
---|
5754 | |
---|
5755 | |
---|
5756 | (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] NUMBER OF STEPS IN THE COUNTER EXAMPLE PATH = %d \n", array_n( aPath )); |
---|
5757 | |
---|
5758 | CEXStruct CEXPath [array_n( aPath )]; |
---|
5759 | //CEXStruct *testCEX; |
---|
5760 | //testCEX = (CEXStruct *)malloc(sizeof(CEXStruct)*array_n( aPath )); |
---|
5761 | |
---|
5762 | // --- SAT Solver File Generation --- |
---|
5763 | BmcOption_t *options = BmcOptionAlloc(); |
---|
5764 | int steps = (array_n( aPath ) - 1); // taille du contre exemple |
---|
5765 | // SATSolverFileGen (&hmgr, CNF_FILE, steps, options); |
---|
5766 | BmcCnfClauses_t *cnfClauses = NIL(BmcCnfClauses_t); |
---|
5767 | cnfClauses = BmcCnfClausesAlloc(); |
---|
5768 | Ntk_Network_t * ntk = Ntk_HrcManagerReadCurrentNetwork(hmgrGlobalC); |
---|
5769 | build_unroll_circuit(ntk,steps,options,cnfClauses); |
---|
5770 | (void) fprintf(vis_stderr, "*** CNF clauses for current network generated. *** \n\n"); |
---|
5771 | |
---|
5772 | (void) fprintf(vis_stderr, "*** Generating CNF clauses for Counter Example... *** \n\n"); |
---|
5773 | |
---|
5774 | for( i = -1 ; i < (array_n( aPath )-1); i++ ) { |
---|
5775 | |
---|
5776 | CEXPath[i+1].pathIndex = i+1; |
---|
5777 | CEXPath[i+1].n_outputVar = array_n( psVars ); |
---|
5778 | |
---|
5779 | (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] CEX PATH INDEX: CEXPath[%d].pathIndex = %d \n", i+1, CEXPath[i+1].pathIndex); |
---|
5780 | (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] NUMBER OF OUTPUTS: CEXPath[%d].n_outputVar = %d \n", i+1, CEXPath[i+1].n_outputVar); |
---|
5781 | |
---|
5782 | //deviceInfo = (deviceStruct *)malloc(sizeof(deviceStruct)*diagInfo.n_failures); |
---|
5783 | CEXPath[i+1].outputVar = (CEXVarStruct *)malloc(sizeof(CEXVarStruct)*CEXPath[i+1].n_outputVar); |
---|
5784 | //deviceInfo[i].dData = (dataStruct *)malloc(sizeof(dataStruct)*(deviceInfo[i].nb_d_data)); |
---|
5785 | |
---|
5786 | mdd_t *aState = ( i == -1 ) ? NIL(mdd_t) : array_fetch( mdd_t *, aPath, i ); |
---|
5787 | mdd_t *bState = array_fetch( mdd_t *, aPath, (i+1) ); |
---|
5788 | |
---|
5789 | // (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] aState = %ld \n", aState); |
---|
5790 | // (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] bState = %ld \n", bState); |
---|
5791 | |
---|
5792 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork(modelFsm); |
---|
5793 | |
---|
5794 | char *aStateString = aState ? Mc_MintermToString( aState, psVars, modelNetwork ) : NIL(char); |
---|
5795 | char *bStateString = Mc_MintermToStringMine( bState, psVars, modelNetwork, CEXPath, (i+1), FALSE, cnfClauses); |
---|
5796 | // (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] aState = %s \n", aStateString); |
---|
5797 | // (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] bState = %s \n", bStateString); |
---|
5798 | |
---|
5799 | |
---|
5800 | if((long)aState%2) { |
---|
5801 | aState = (mdd_t *)((long)aState -1); |
---|
5802 | forced++; |
---|
5803 | } |
---|
5804 | else forced = 0; |
---|
5805 | |
---|
5806 | if((long)bState%2) { |
---|
5807 | bState = (mdd_t *)((long)bState -1); |
---|
5808 | } |
---|
5809 | |
---|
5810 | if ( printInput == TRUE && i != -1) { |
---|
5811 | inputSet = Mc_FsmComputeDrivingInputMinterms( modelFsm, aState, bState ); |
---|
5812 | vInput = Mc_ComputeACloseMinterm( inputSet, uInput, inputVars, mddMgr ); |
---|
5813 | } |
---|
5814 | if(forced) { |
---|
5815 | fprintf(vis_stdout, "---- Forced %d\n", forced); |
---|
5816 | numForced ++; |
---|
5817 | } |
---|
5818 | McPrintTransitionMine( aState, bState, uInput, vInput, psVars, inputVars, |
---|
5819 | printInput, modelFsm, CEXPath, (i+1), cnfClauses); |
---|
5820 | |
---|
5821 | |
---|
5822 | |
---|
5823 | if ( uInput != NIL(mdd_t) ) { |
---|
5824 | mdd_free(uInput); |
---|
5825 | } |
---|
5826 | uInput = vInput; |
---|
5827 | |
---|
5828 | if ( inputSet != NIL(mdd_t) ) { |
---|
5829 | mdd_free(inputSet); |
---|
5830 | } |
---|
5831 | } |
---|
5832 | |
---|
5833 | if ( vInput != NIL(mdd_t) ) { |
---|
5834 | mdd_free(uInput); |
---|
5835 | } |
---|
5836 | |
---|
5837 | if(Fsm_FsmReadFAFWFlag(modelFsm) > 0) { |
---|
5838 | fprintf(vis_stdout, |
---|
5839 | "# MC: the number of non-trivial forced segments %d\n", |
---|
5840 | numForced); |
---|
5841 | } |
---|
5842 | |
---|
5843 | FILE *cnfFile = fopen(CNF_FILE_C1,"w"); |
---|
5844 | mAig_Manager_t * maigManager = Ntk_NetworkReadMAigManager(ntk); |
---|
5845 | BmcWriteClausesMine(maigManager, cnfFile, cnfClauses, options); |
---|
5846 | fclose(cnfFile); |
---|
5847 | |
---|
5848 | (void) fprintf(vis_stderr, "*** Generation of CNF clauses for Counter Example completed. *** \n\n"); |
---|
5849 | // --- SAT Solver --- |
---|
5850 | options->satInFile= CNF_FILE_C1; |
---|
5851 | options->verbosityLevel=BmcVerbositySome_c; |
---|
5852 | |
---|
5853 | SATSolver (steps, options); |
---|
5854 | (void) fprintf(vis_stderr, "*** SAT Solver completed. *** \n"); |
---|
5855 | |
---|
5856 | return 1; |
---|
5857 | } |
---|
5858 | |
---|
5859 | |
---|
5860 | /**Function******************************************************************** |
---|
5861 | |
---|
5862 | Synopsis [Print a transition to vis_stdout.] |
---|
5863 | |
---|
5864 | Description [Print a transition to vis_stdout. The transition is supposed to be |
---|
5865 | from aState to bState on input vInput. If uInput is not NIL, instead of |
---|
5866 | printing vInput, we only print the places where it differs from uInput. If there |
---|
5867 | is no difference anywhere, we print "-Unchanged-". Similarly, we print only the |
---|
5868 | incremental difference from aState to bState; if there is none, we print "-Unchanged-". |
---|
5869 | If aState is NIL we simply print bState and return.] |
---|
5870 | |
---|
5871 | SideEffects [] |
---|
5872 | |
---|
5873 | ******************************************************************************/ |
---|
5874 | static void |
---|
5875 | McPrintTransitionMine( |
---|
5876 | mdd_t *aState, |
---|
5877 | mdd_t *bState, |
---|
5878 | mdd_t *uInput, |
---|
5879 | mdd_t *vInput, |
---|
5880 | array_t *stateSupport, |
---|
5881 | array_t *inputSupport, |
---|
5882 | boolean printInputs, |
---|
5883 | Fsm_Fsm_t *modelFsm, |
---|
5884 | CEXStruct *CEXPath, |
---|
5885 | int seqNumber, |
---|
5886 | BmcCnfClauses_t *cnfClauses) |
---|
5887 | { |
---|
5888 | (void) fprintf(vis_stderr, "![McPrintTransitionMine] \n"); |
---|
5889 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork( modelFsm ); |
---|
5890 | char *aString = aState ? Mc_MintermToString( aState, stateSupport, modelNetwork ) : NIL(char); |
---|
5891 | char *bString = Mc_MintermToString( bState, stateSupport, modelNetwork ); |
---|
5892 | |
---|
5893 | char *tmp1String = aString; |
---|
5894 | char *tmp2String = bString; |
---|
5895 | char *ptr1; |
---|
5896 | char *ptr2; |
---|
5897 | st_table *node2MvfAigTable; |
---|
5898 | |
---|
5899 | node2MvfAigTable = |
---|
5900 | (st_table *)Ntk_NetworkReadApplInfo(modelNetwork, MVFAIG_NETWORK_APPL_KEY); |
---|
5901 | |
---|
5902 | if ( aState == NIL(mdd_t) ) { |
---|
5903 | fprintf( vis_stdout, "--State %d:\n%s\n", seqNumber, bString ); |
---|
5904 | FREE(bString); |
---|
5905 | return; |
---|
5906 | } |
---|
5907 | |
---|
5908 | fprintf(vis_stdout, "--Goes to state %d:\n", seqNumber ); |
---|
5909 | |
---|
5910 | { |
---|
5911 | boolean unchanged=TRUE; |
---|
5912 | while ( (tmp1String != NIL(char)) && ((ptr1 = strchr( tmp1String, '\n' ) ) != NIL(char) ) ) { |
---|
5913 | ptr2 = strchr( tmp2String, '\n' ); |
---|
5914 | *ptr1 = 0; |
---|
5915 | *ptr2 = 0; |
---|
5916 | if ( (strcmp( tmp1String, tmp2String ) ) ) { |
---|
5917 | fprintf( vis_stdout, "%s\n", tmp2String ); |
---|
5918 | unchanged = FALSE; |
---|
5919 | } |
---|
5920 | tmp1String = & (ptr1[1]); |
---|
5921 | tmp2String = & (ptr2[1]); |
---|
5922 | } |
---|
5923 | if (unchanged == TRUE) { |
---|
5924 | fprintf( vis_stdout, "<Unchanged>\n"); |
---|
5925 | } |
---|
5926 | } |
---|
5927 | |
---|
5928 | if ( array_n( inputSupport ) > 0 ) { |
---|
5929 | CEXPath[seqNumber].n_inputVar = array_n( inputSupport ); |
---|
5930 | } |
---|
5931 | else CEXPath[seqNumber].n_inputVar = 0; |
---|
5932 | |
---|
5933 | (void) fprintf(vis_stderr, " ---- [McPrintTransitionMine] NUMBER OF INPUTS: CEXPath[%d].n_inputVar = %d \n", seqNumber, CEXPath[seqNumber].n_inputVar); |
---|
5934 | CEXPath[seqNumber].inputVar = (CEXVarStruct *)malloc(sizeof(CEXVarStruct)*CEXPath[seqNumber].n_inputVar); |
---|
5935 | |
---|
5936 | if ( printInputs == TRUE ) { |
---|
5937 | |
---|
5938 | // (void) fprintf(vis_stderr, " ---- [McPrintTransitionMine] NUMBER OF INPUTS = %d \n", array_n( inputSupport )); |
---|
5939 | |
---|
5940 | |
---|
5941 | /* first test that there are inputs */ |
---|
5942 | if ( array_n( inputSupport ) > 0 ) { |
---|
5943 | fprintf(vis_stdout, "--On input:\n"); |
---|
5944 | |
---|
5945 | if ( uInput == NIL(mdd_t) ) { |
---|
5946 | char *vString = Mc_MintermToStringMine( vInput, inputSupport, modelNetwork, CEXPath, seqNumber, TRUE, cnfClauses); |
---|
5947 | fprintf(vis_stdout, "%s", vString ); |
---|
5948 | FREE(vString); |
---|
5949 | } |
---|
5950 | else { |
---|
5951 | boolean unchanged=TRUE; |
---|
5952 | char *uString = Mc_MintermToString( uInput, inputSupport, modelNetwork ); |
---|
5953 | char *vString = Mc_MintermToStringMine( vInput, inputSupport, modelNetwork, CEXPath, seqNumber, TRUE, cnfClauses); |
---|
5954 | tmp1String = uString; |
---|
5955 | tmp2String = vString; |
---|
5956 | // (void) fprintf(vis_stderr, " ---- [McPrintTransitionMine] uString = %s \n", uString); |
---|
5957 | // (void) fprintf(vis_stderr, " ---- [McPrintTransitionMine] vString = %s \n", vString); |
---|
5958 | |
---|
5959 | while ( (tmp1String != NIL(char)) && ((ptr1 = strchr( tmp1String, '\n' ) ) != NIL(char) ) ) { |
---|
5960 | ptr2 = strchr( tmp2String, '\n' ); |
---|
5961 | *ptr1 = 0; |
---|
5962 | *ptr2 = 0; |
---|
5963 | if ( (strcmp( tmp1String, tmp2String ) ) ) { |
---|
5964 | fprintf( vis_stdout, "%s\n", tmp2String ); |
---|
5965 | unchanged = FALSE; |
---|
5966 | } |
---|
5967 | tmp1String = & (ptr1[1]); |
---|
5968 | tmp2String = & (ptr2[1]); |
---|
5969 | } |
---|
5970 | if (unchanged == TRUE) { |
---|
5971 | fprintf( vis_stdout, "<Unchanged>\n"); |
---|
5972 | } |
---|
5973 | FREE(uString); |
---|
5974 | FREE(vString); |
---|
5975 | } |
---|
5976 | } |
---|
5977 | } |
---|
5978 | |
---|
5979 | FREE( aString ); |
---|
5980 | FREE( bString ); |
---|
5981 | fprintf (vis_stdout, "\n"); |
---|
5982 | } |
---|
5983 | |
---|
5984 | |
---|
5985 | /**Function******************************************************************** |
---|
5986 | |
---|
5987 | Synopsis [Print a minterm.] |
---|
5988 | |
---|
5989 | SideEffects [] |
---|
5990 | |
---|
5991 | ******************************************************************************/ |
---|
5992 | static void |
---|
5993 | Mc_MintermPrintMine( |
---|
5994 | mdd_t *aMinterm, |
---|
5995 | array_t *support, |
---|
5996 | Ntk_Network_t *aNetwork) |
---|
5997 | { |
---|
5998 | char *tmpString = Mc_MintermToString( aMinterm, support, aNetwork ); // to be modified!! |
---|
5999 | fprintf( vis_stdout, "%s", tmpString ); |
---|
6000 | FREE(tmpString); |
---|
6001 | } |
---|
6002 | |
---|
6003 | |
---|
6004 | /**Function******************************************************************** |
---|
6005 | |
---|
6006 | Synopsis [Return a string for a minterm. Only used in 'Mc_PrintPathMine' |
---|
6007 | function] |
---|
6008 | |
---|
6009 | SideEffects [] |
---|
6010 | |
---|
6011 | ******************************************************************************/ |
---|
6012 | static char * |
---|
6013 | Mc_MintermToStringMine( |
---|
6014 | mdd_t *aMinterm, |
---|
6015 | array_t *aSupport, |
---|
6016 | Ntk_Network_t *aNetwork, |
---|
6017 | CEXStruct *CEXPath, |
---|
6018 | int seqNumber, |
---|
6019 | boolean inOutIndicator, // TRUE = input Variables, FALSE = output Variables (independent printInput option) |
---|
6020 | BmcCnfClauses_t *cnfClauses) |
---|
6021 | { |
---|
6022 | (void) fprintf(vis_stderr, "![Mc_MintermToStringMine] \n"); |
---|
6023 | int i; |
---|
6024 | char *tmp1String; |
---|
6025 | char *tmp2String; |
---|
6026 | char bodyString[McMaxStringLength_c]; |
---|
6027 | char *mintermString = NIL(char); |
---|
6028 | mdd_manager *mddMgr = Ntk_NetworkReadMddManager( aNetwork ); |
---|
6029 | array_t *valueArray; |
---|
6030 | array_t *stringArray = array_alloc( char *, 0 ); |
---|
6031 | char *symbolicValue; |
---|
6032 | |
---|
6033 | aMinterm = GET_NORMAL_PT(aMinterm); |
---|
6034 | valueArray = McConvertMintermToValueArrayMine(aMinterm, aSupport, mddMgr); |
---|
6035 | // (void) fprintf(vis_stderr, " ---- [Mc_MintermToStringMine] CEX n outputs = %d \n", array_n( aSupport )); |
---|
6036 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] Number of variables = %d \n", array_n( aSupport )); |
---|
6037 | |
---|
6038 | // CEXVarStruct testBB [array_n( aSupport)]; |
---|
6039 | |
---|
6040 | for ( i = 0 ; i < array_n( aSupport ); i++ ) { |
---|
6041 | |
---|
6042 | int mddId = array_fetch( int, aSupport, i ); |
---|
6043 | int value = array_fetch( int, valueArray, i ); |
---|
6044 | Ntk_Node_t *node = Ntk_NetworkFindNodeByMddId( aNetwork, mddId ); |
---|
6045 | char *nodeName = Ntk_NodeReadName( node ); |
---|
6046 | Var_Variable_t *nodeVar = Ntk_NodeReadVariable( node ); |
---|
6047 | |
---|
6048 | // (void) fprintf(vis_stderr, "\n ----- [Mc_MintermToStringMine] VARIABLE %d: \n", i+1 ); |
---|
6049 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] nodeName = %s \n", nodeName); |
---|
6050 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] mddId = %d \n", mddId); |
---|
6051 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] value = %d \n", value); |
---|
6052 | |
---|
6053 | if ( Var_VariableTestIsSymbolic( nodeVar ) ) { |
---|
6054 | symbolicValue = Var_VariableReadSymbolicValueFromIndex(nodeVar, value ); |
---|
6055 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] symbolic value = %s \n", symbolicValue); |
---|
6056 | sprintf( bodyString, "%s:%s", nodeName, symbolicValue ); |
---|
6057 | //testBB[i].symbolicValue = symbolicValue; |
---|
6058 | // sprintf(testBB[i].symbolicValue, "%s", symbolicValue); |
---|
6059 | } |
---|
6060 | else { |
---|
6061 | sprintf( bodyString, "%s:%d", nodeName, value ); |
---|
6062 | //testBB[i].symbolicValue = NIL(char); |
---|
6063 | symbolicValue = "NIL"; |
---|
6064 | // sprintf(testBB[i].symbolicValue, "%s", "NIL"); |
---|
6065 | } |
---|
6066 | |
---|
6067 | |
---|
6068 | if (inOutIndicator == TRUE) { |
---|
6069 | CEXPath[seqNumber].inputVar[i].varIndex = i; |
---|
6070 | CEXPath[seqNumber].inputVar[i].varId = mddId; |
---|
6071 | CEXPath[seqNumber].inputVar[i].varValue = value; |
---|
6072 | sprintf(CEXPath[seqNumber].inputVar[i].varName, "%s", nodeName); |
---|
6073 | sprintf(CEXPath[seqNumber].inputVar[i].symbolicValue, "%s", symbolicValue); |
---|
6074 | } |
---|
6075 | else{ |
---|
6076 | CEXPath[seqNumber].outputVar[i].varIndex = i; |
---|
6077 | CEXPath[seqNumber].outputVar[i].varId = mddId; |
---|
6078 | CEXPath[seqNumber].outputVar[i].varValue = value; |
---|
6079 | sprintf(CEXPath[seqNumber].outputVar[i].varName, "%s", nodeName); |
---|
6080 | sprintf(CEXPath[seqNumber].outputVar[i].symbolicValue, "%s", symbolicValue); |
---|
6081 | } |
---|
6082 | |
---|
6083 | // testBB[i].varIndex = i; |
---|
6084 | // testBB[i].varId = mddId; |
---|
6085 | // testBB[i].varValue = value; |
---|
6086 | // sprintf(testBB[i].varName, "%s", nodeName); |
---|
6087 | // testBB[i].varName = nodeName; |
---|
6088 | |
---|
6089 | |
---|
6090 | |
---|
6091 | tmp1String = util_strsav( bodyString ); |
---|
6092 | array_insert_last( char *, stringArray, tmp1String ); |
---|
6093 | } |
---|
6094 | array_free(valueArray); |
---|
6095 | |
---|
6096 | array_sort( stringArray, cmp); |
---|
6097 | |
---|
6098 | for ( i = 0 ; i < array_n( stringArray ); i++ ) { |
---|
6099 | tmp1String = array_fetch( char *, stringArray, i ); |
---|
6100 | if( i == 0 ) { |
---|
6101 | mintermString = util_strcat3(tmp1String, "", "" ); |
---|
6102 | } |
---|
6103 | else { |
---|
6104 | tmp2String = util_strcat3(mintermString, "\n", tmp1String ); |
---|
6105 | FREE(mintermString); |
---|
6106 | mintermString = tmp2String; |
---|
6107 | } |
---|
6108 | FREE(tmp1String); |
---|
6109 | } |
---|
6110 | array_free( stringArray ); |
---|
6111 | |
---|
6112 | tmp1String = util_strcat3(mintermString, "\n", ""); |
---|
6113 | FREE(mintermString); |
---|
6114 | mintermString = tmp1String; |
---|
6115 | |
---|
6116 | int j, k; |
---|
6117 | boolean indexFound; |
---|
6118 | int lookUpResult; |
---|
6119 | int n_bitValue; // number of bit - 1 = highest bit number representing the value of the variable |
---|
6120 | int *cnfIndex= malloc(sizeof(int)*SIZE_1); |
---|
6121 | int newIndex; |
---|
6122 | array_t * newClause; |
---|
6123 | char *tempCNFString; |
---|
6124 | |
---|
6125 | for ( i = 0 ; i < array_n( aSupport ); i++ ) { |
---|
6126 | |
---|
6127 | j=0; |
---|
6128 | indexFound = TRUE; |
---|
6129 | |
---|
6130 | if (inOutIndicator == TRUE) { |
---|
6131 | /* (void) fprintf(vis_stderr, "\n CEXPath[%d].inputVar[%d].varIndex = %d \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].varIndex); |
---|
6132 | (void) fprintf(vis_stderr, " CEXPath[%d].inputVar[%d].varId = %d \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].varId); |
---|
6133 | (void) fprintf(vis_stderr, "\n"); |
---|
6134 | (void) fprintf(vis_stderr, " CEXPath[%d].inputVar[%d].varValue = %d \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].varValue); |
---|
6135 | (void) fprintf(vis_stderr, " CEXPath[%d].inputVar[%d].varName = %s \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].varName); |
---|
6136 | (void) fprintf(vis_stderr, " CEXPath[%d].inputVar[%d].symbolicValue = %s \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].symbolicValue); |
---|
6137 | */ |
---|
6138 | |
---|
6139 | // insertion of cnf clauses related to the input in Counter Example at each state |
---|
6140 | do{ |
---|
6141 | tempCNFString = CNFVariableNameConstructor(CEXPath[seqNumber].inputVar[i].varName, j, seqNumber-1); // the sequence of input begins at -1 and ends at (last sequence-1) |
---|
6142 | lookUpResult = st_lookup(cnfClauses->cnfIndexTable, tempCNFString, &cnfIndex[j]); |
---|
6143 | // (void) fprintf(vis_stderr, "[SeqNumber: %d][i: %d][j: %d] tempCNFString = %s; lookUpResult = %d; cnfIndex = %d;\n", seqNumber, i, j, tempCNFString, lookUpResult, cnfIndex); |
---|
6144 | if (lookUpResult == 0) { |
---|
6145 | indexFound = FALSE; |
---|
6146 | } |
---|
6147 | else { |
---|
6148 | indexFound = TRUE; |
---|
6149 | (void) fprintf(vis_stderr, " [CNF Index Search] Variable bit name = %s => CNF Index = %d \n", tempCNFString, cnfIndex[j]); |
---|
6150 | j++; |
---|
6151 | } |
---|
6152 | }while ((indexFound == TRUE)&&(j<SIZE_1)); |
---|
6153 | |
---|
6154 | if ((indexFound == FALSE)&&(j<SIZE_1)){ |
---|
6155 | n_bitValue = j-1; |
---|
6156 | // (void) fprintf(vis_stderr, " [Counter] n_bitValue = %d ::: j = %d. \n", n_bitValue, j); |
---|
6157 | if (n_bitValue > 0){ |
---|
6158 | // Value decomposition en binary. Then affectation of the value of each bit of the variable in CNF format for each index of the variable |
---|
6159 | |
---|
6160 | int *binaryValue = malloc (sizeof(int)*(n_bitValue+1)); |
---|
6161 | binaryValue = DecBinConverter (CEXPath[seqNumber].inputVar[i].varValue, (n_bitValue+1), binaryValue); |
---|
6162 | |
---|
6163 | // (void) fprintf(vis_stderr, "---- Decimal Value = %d ==> Binary Value = ", CEXPath[seqNumber].inputVar[i].varValue); |
---|
6164 | // for (k=0; k < n_bitValue+1; k++){ |
---|
6165 | // (void) fprintf(vis_stderr, "%d ", binaryValue[n_bitValue-k]); |
---|
6166 | // } |
---|
6167 | |
---|
6168 | for (k=0; k<(n_bitValue+1); k++){ |
---|
6169 | |
---|
6170 | newClause = array_alloc(int,1); |
---|
6171 | // if varValue = 1 => cnfIndex; if varValue = 0 => -cnfIndex |
---|
6172 | // (void) fprintf(vis_stderr, "CNF Index = %d : Value = %d \n", cnfIndex[k], binaryValue[k]); |
---|
6173 | // if (binaryValue[k] == 0) array_insert(int,newClause,0,-cnfIndex[k]); |
---|
6174 | // else array_insert(int, newClause, 0, cnfIndex[k]); |
---|
6175 | |
---|
6176 | // NOTE: MSB is on lowest bit encoding |
---|
6177 | // (void) fprintf(vis_stderr, "CNF Index = %d : Value = %d \n", cnfIndex[k], binaryValue[n_bitValue-k]); |
---|
6178 | if (binaryValue[n_bitValue-k] == 0) array_insert(int,newClause,0,-cnfIndex[k]); |
---|
6179 | else array_insert(int, newClause, 0, cnfIndex[k]); |
---|
6180 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
6181 | array_free(newClause); |
---|
6182 | } |
---|
6183 | free (binaryValue); |
---|
6184 | // (void) fprintf(vis_stderr, "![WARNING] Variable is coded in more than one bit. This case is not yet treated. <n_bitValue = %d> \n", n_bitValue); |
---|
6185 | |
---|
6186 | } |
---|
6187 | else{ |
---|
6188 | if (n_bitValue == 0){ |
---|
6189 | newClause = array_alloc(int,1); |
---|
6190 | // if varValue = 1 => cnfIndex; if varValue = 0 => -cnfIndex |
---|
6191 | if (CEXPath[seqNumber].inputVar[i].varValue == 0) array_insert(int,newClause,0,-cnfIndex[0]); |
---|
6192 | else array_insert(int, newClause, 0, cnfIndex[0]); |
---|
6193 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
6194 | array_free(newClause); |
---|
6195 | } |
---|
6196 | else { // n_bitValue = -1 or <0 |
---|
6197 | (void) fprintf(vis_stderr, "![WARNING] Variable CNF index not found. Verification required. \n", CEXPath[seqNumber].outputVar[i].varName, seqNumber); |
---|
6198 | } |
---|
6199 | } |
---|
6200 | } |
---|
6201 | else { |
---|
6202 | (void) fprintf(vis_stderr, "![WARNING] Too many CNF index found for %s at state %d! Verification required.. counter j exceeded security constraint (j < SIZE_1 = 100). \n" ); |
---|
6203 | } |
---|
6204 | |
---|
6205 | |
---|
6206 | } |
---|
6207 | else{ |
---|
6208 | /* (void) fprintf(vis_stderr, "\n CEXPath[%d].outputVar[%d].varIndex = %d \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].varIndex); |
---|
6209 | (void) fprintf(vis_stderr, " CEXPath[%d].outputVar[%d].varId = %d \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].varId); |
---|
6210 | (void) fprintf(vis_stderr, " CEXPath[%d].outputVar[%d].varValue = %d \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].varValue); |
---|
6211 | (void) fprintf(vis_stderr, " CEXPath[%d].outputVar[%d].varName = %s \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].varName); |
---|
6212 | (void) fprintf(vis_stderr, " CEXPath[%d].outputVar[%d].symbolicValue = %s \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].symbolicValue); |
---|
6213 | */ |
---|
6214 | |
---|
6215 | //--- CNF: insertion of cnf clauses related to Counter Example output at each state |
---|
6216 | // if (i>0){ // to exclude the states in CNF |
---|
6217 | |
---|
6218 | do{ |
---|
6219 | tempCNFString = CNFVariableNameConstructor(CEXPath[seqNumber].outputVar[i].varName, j, seqNumber); |
---|
6220 | //int findIndex(BmcCnfClauses_t* cnfClauses , char * nodeName) |
---|
6221 | //propIndex = findIndex(cnfClauses, tempCNFString); |
---|
6222 | lookUpResult = st_lookup(cnfClauses->cnfIndexTable, tempCNFString, &cnfIndex[j]); |
---|
6223 | // (void) fprintf(vis_stderr, "[SeqNumber: %d][i: %d][j: %d] tempCNFString = %s; lookUpResult = %d; cnfIndex = %d;\n", seqNumber, i, j, tempCNFString, lookUpResult, cnfIndex); |
---|
6224 | if (lookUpResult == 0) { |
---|
6225 | indexFound = FALSE; |
---|
6226 | } |
---|
6227 | else { |
---|
6228 | indexFound = TRUE; |
---|
6229 | (void) fprintf(vis_stderr, " [CNF Index Search] Variable bit name = %s => CNF Index = %d \n", tempCNFString, cnfIndex[j]); |
---|
6230 | j++; |
---|
6231 | } |
---|
6232 | }while ((indexFound == TRUE)&&(j<SIZE_1)); |
---|
6233 | |
---|
6234 | if ((indexFound == FALSE)&&(j<SIZE_1)){ |
---|
6235 | n_bitValue = j-1; |
---|
6236 | // (void) fprintf(vis_stderr, " [Counter] n_bitValue = %d ::: j = %d. \n", n_bitValue, j); |
---|
6237 | if (n_bitValue > 0){ |
---|
6238 | // Value decomposition en binary. Then affectation of the value of each bit of the variable in CNF format for each index of the variable |
---|
6239 | |
---|
6240 | int *binaryValue = malloc (sizeof(int)*(n_bitValue+1)); |
---|
6241 | binaryValue = DecBinConverter (CEXPath[seqNumber].outputVar[i].varValue, (n_bitValue+1), binaryValue); |
---|
6242 | |
---|
6243 | // (void) fprintf(vis_stderr, "####### Decimal Value = %d ==> Binary Value = ", CEXPath[seqNumber].outputVar[i].varValue); |
---|
6244 | // for (k=0; k<(n_bitValue+1); k++){ |
---|
6245 | // (void) fprintf(vis_stderr, "%d ", binaryValue[n_bitValue-k]); |
---|
6246 | // } |
---|
6247 | // (void) fprintf(vis_stderr, "\n"); |
---|
6248 | |
---|
6249 | for (k=0; k<(n_bitValue+1); k++){ |
---|
6250 | // for (k=(n_bitValue); k>=0; k--){ |
---|
6251 | newClause = array_alloc(int,1); |
---|
6252 | // if varValue = 1 => cnfIndex; if varValue = 0 => -cnfIndex |
---|
6253 | // (void) fprintf(vis_stderr, "CNF Index = %d : Value = %d \n", cnfIndex[k], binaryValue[k]); |
---|
6254 | // if (binaryValue[k] == 0) array_insert(int,newClause,0,-cnfIndex[k]); |
---|
6255 | // else array_insert(int, newClause, 0, cnfIndex[k]); |
---|
6256 | // NOTE: MSB is on lowest bit encoding |
---|
6257 | // (void) fprintf(vis_stderr, "CNF Index = %d : Value = %d \n", cnfIndex[k], binaryValue[n_bitValue-k]); |
---|
6258 | if (binaryValue[n_bitValue-k] == 0) array_insert(int,newClause,0,-cnfIndex[k]); |
---|
6259 | else array_insert(int, newClause, 0, cnfIndex[k]); |
---|
6260 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
6261 | array_free(newClause); |
---|
6262 | |
---|
6263 | } |
---|
6264 | free (binaryValue); |
---|
6265 | // (void) fprintf(vis_stderr, "![WARNING] Variable is coded in more than one bit. This case is not yet treated. <n_bitValue = %d> \n", n_bitValue); |
---|
6266 | |
---|
6267 | } |
---|
6268 | else{ |
---|
6269 | if (n_bitValue == 0){ |
---|
6270 | newClause = array_alloc(int,1); |
---|
6271 | // if varValue = 1 => cnfIndex; if varValue = 0 => -cnfIndex |
---|
6272 | if (CEXPath[seqNumber].outputVar[i].varValue == 0) array_insert(int,newClause,0,-cnfIndex[0]); |
---|
6273 | else array_insert(int, newClause, 0, cnfIndex[0]); |
---|
6274 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
6275 | array_free(newClause); |
---|
6276 | } |
---|
6277 | else { // n_bitValue = -1 or <0 |
---|
6278 | (void) fprintf(vis_stderr, "![WARNING] Variable CNF index not found. Verification required. \n", CEXPath[seqNumber].outputVar[i].varName, seqNumber); |
---|
6279 | } |
---|
6280 | } |
---|
6281 | } |
---|
6282 | else { |
---|
6283 | (void) fprintf(vis_stderr, "![WARNING] Too many CNF index found for %s at state %d! Verification required.. counter j exceeded security constraint (j < SIZE_1 = 100). \n" ); |
---|
6284 | } |
---|
6285 | // } |
---|
6286 | } |
---|
6287 | } |
---|
6288 | |
---|
6289 | return mintermString; |
---|
6290 | } |
---|
6291 | |
---|
6292 | |
---|
6293 | |
---|
6294 | /**Function******************************************************************** |
---|
6295 | |
---|
6296 | Synopsis [Convert a minterm to an array of integers] |
---|
6297 | |
---|
6298 | SideEffects [] |
---|
6299 | |
---|
6300 | ******************************************************************************/ |
---|
6301 | static array_t * |
---|
6302 | McConvertMintermToValueArrayMine( |
---|
6303 | mdd_t *aMinterm, |
---|
6304 | array_t *aSupport, |
---|
6305 | mdd_manager *mddMgr) |
---|
6306 | { |
---|
6307 | (void) fprintf(vis_stderr, "![McConvertMintermToValueArrayMine] \n"); |
---|
6308 | array_t *resultValueArray; |
---|
6309 | |
---|
6310 | /* this will be performed only in v0s-g executables */ |
---|
6311 | assert( MintermCheckWellFormed( aMinterm, aSupport, mddMgr )); |
---|
6312 | |
---|
6313 | resultValueArray = array_alloc( int, 0 ); |
---|
6314 | { |
---|
6315 | int i; |
---|
6316 | for( i = 0 ; i < array_n( aSupport ); i++ ) { |
---|
6317 | int aSupportVar = array_fetch( int, aSupport, i ); |
---|
6318 | int j; |
---|
6319 | for( j = 0 ; TRUE ; j++) { |
---|
6320 | |
---|
6321 | mdd_t *faceMdd, *tmpMdd; |
---|
6322 | array_t *tmpArray = array_alloc( int, 0 ); |
---|
6323 | |
---|
6324 | array_insert_last( int, tmpArray, j ); |
---|
6325 | faceMdd = mdd_literal( mddMgr, aSupportVar, tmpArray ); |
---|
6326 | array_free( tmpArray ); |
---|
6327 | |
---|
6328 | tmpMdd = mdd_and( faceMdd, aMinterm, 1, 1 ); |
---|
6329 | mdd_free( faceMdd ); |
---|
6330 | if ( !mdd_is_tautology( tmpMdd, 0 ) ) { |
---|
6331 | mdd_free( tmpMdd ); |
---|
6332 | array_insert_last( int, resultValueArray, j ); |
---|
6333 | break; |
---|
6334 | } |
---|
6335 | mdd_free( tmpMdd ); |
---|
6336 | } |
---|
6337 | } |
---|
6338 | } |
---|
6339 | |
---|
6340 | return resultValueArray; |
---|
6341 | } |
---|
6342 | |
---|
6343 | /**Function******************************************************************** |
---|
6344 | |
---|
6345 | Synopsis [Print message saying given state passes formula.] |
---|
6346 | |
---|
6347 | SideEffects [] |
---|
6348 | |
---|
6349 | ******************************************************************************/ |
---|
6350 | static void |
---|
6351 | McStatePassesFormulaMine( |
---|
6352 | mdd_t *aState, |
---|
6353 | Ctlp_Formula_t *formula, |
---|
6354 | McDbgLevel debugLevel, |
---|
6355 | Fsm_Fsm_t *modelFsm) |
---|
6356 | { |
---|
6357 | McStatePassesOrFailsFormulaMine( aState, formula, 1, debugLevel, modelFsm ); |
---|
6358 | } |
---|
6359 | |
---|
6360 | |
---|
6361 | /**Function******************************************************************** |
---|
6362 | |
---|
6363 | Synopsis [Print message saying given state fails formula.] |
---|
6364 | |
---|
6365 | SideEffects [] |
---|
6366 | |
---|
6367 | ******************************************************************************/ |
---|
6368 | static void |
---|
6369 | McStateFailsFormulaMine( |
---|
6370 | mdd_t *aState, |
---|
6371 | Ctlp_Formula_t *formula, |
---|
6372 | McDbgLevel debugLevel, |
---|
6373 | Fsm_Fsm_t *modelFsm) |
---|
6374 | { |
---|
6375 | McStatePassesOrFailsFormulaMine( aState, formula, 0, debugLevel, modelFsm ); |
---|
6376 | } |
---|
6377 | |
---|
6378 | |
---|
6379 | /**Function******************************************************************** |
---|
6380 | |
---|
6381 | Synopsis [Utility function - prints state passes or fails formula] |
---|
6382 | |
---|
6383 | SideEffects [] |
---|
6384 | |
---|
6385 | ******************************************************************************/ |
---|
6386 | static void |
---|
6387 | McStatePassesOrFailsFormulaMine ( |
---|
6388 | mdd_t *aState, |
---|
6389 | Ctlp_Formula_t *formula, |
---|
6390 | int pass, |
---|
6391 | McDbgLevel debugLevel, |
---|
6392 | Fsm_Fsm_t *modelFsm) |
---|
6393 | { |
---|
6394 | |
---|
6395 | (void) fprintf(vis_stderr, "![McStatePassesOrFailsFormulaMine] \n"); |
---|
6396 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
6397 | char *formulaText = Ctlp_FormulaConvertToString( formula ); |
---|
6398 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork( modelFsm ); |
---|
6399 | |
---|
6400 | /* Nodes created in converting formulae like AU may not have text |
---|
6401 | * attached to them. */ |
---|
6402 | if (formulaText == NIL(char)) |
---|
6403 | return; |
---|
6404 | |
---|
6405 | fprintf( vis_stdout, "--State\n"); |
---|
6406 | Mc_MintermPrintMine( aState, PSVars, modelNetwork ); |
---|
6407 | if ( pass ) |
---|
6408 | fprintf( vis_stdout, "passes "); |
---|
6409 | else |
---|
6410 | fprintf( vis_stdout, "fails "); |
---|
6411 | |
---|
6412 | if( debugLevel > McDbgLevelMin_c) |
---|
6413 | fprintf(vis_stdout, "%s.\n\n", formulaText); |
---|
6414 | else |
---|
6415 | fprintf(vis_stdout, "\n\n"); |
---|
6416 | |
---|
6417 | FREE(formulaText); |
---|
6418 | } |
---|
6419 | |
---|
6420 | |
---|
6421 | /**Function******************************************************************** |
---|
6422 | |
---|
6423 | Synopsis [Compare two strings in the from of char **] |
---|
6424 | |
---|
6425 | SideEffects [] |
---|
6426 | |
---|
6427 | ******************************************************************************/ |
---|
6428 | static int |
---|
6429 | cmp( |
---|
6430 | const void * s1, |
---|
6431 | const void * s2) |
---|
6432 | { |
---|
6433 | return(strcmp(*(char **)s1, *(char **)s2)); |
---|
6434 | } |
---|
6435 | |
---|
6436 | |
---|
6437 | |
---|
6438 | /**Function******************************************************************** |
---|
6439 | |
---|
6440 | Synopsis [Test that given mdd is a minterm.] |
---|
6441 | |
---|
6442 | SideEffects [] |
---|
6443 | |
---|
6444 | ******************************************************************************/ |
---|
6445 | static boolean |
---|
6446 | MintermCheckWellFormed( |
---|
6447 | mdd_t *aMinterm, |
---|
6448 | array_t *aSupport, |
---|
6449 | mdd_manager *mddMgr) |
---|
6450 | { |
---|
6451 | |
---|
6452 | /* first check its support */ |
---|
6453 | if (!SetCheckSupport(aMinterm, aSupport, mddMgr)) { |
---|
6454 | return FALSE; |
---|
6455 | } |
---|
6456 | |
---|
6457 | /* now check its a minterm */ |
---|
6458 | { |
---|
6459 | float cardinality = mdd_count_onset( mddMgr, aMinterm, aSupport ); |
---|
6460 | if ( cardinality != 1 ) { |
---|
6461 | fprintf( vis_stderr, "-- onset is not one\n"); |
---|
6462 | return FALSE; |
---|
6463 | } |
---|
6464 | } |
---|
6465 | return TRUE; |
---|
6466 | } |
---|
6467 | |
---|
6468 | |
---|
6469 | /**Function******************************************************************** |
---|
6470 | |
---|
6471 | Synopsis [Test that given mdd is a minterm.] |
---|
6472 | |
---|
6473 | SideEffects [] |
---|
6474 | |
---|
6475 | ******************************************************************************/ |
---|
6476 | static boolean |
---|
6477 | SetCheckSupport( |
---|
6478 | mdd_t *aMinterm, |
---|
6479 | array_t *aSupport, |
---|
6480 | mdd_manager *mddMgr) |
---|
6481 | { |
---|
6482 | if (!mdd_check_support(mddMgr, aMinterm, aSupport)) { |
---|
6483 | fprintf(vis_stderr, |
---|
6484 | "** mc error: support of minterm is not contained in claimed support\n"); |
---|
6485 | return FALSE; |
---|
6486 | } |
---|
6487 | return TRUE; |
---|
6488 | } |
---|
6489 | |
---|
6490 | |
---|
6491 | /**Function******************************************************************** |
---|
6492 | |
---|
6493 | Synopsis [CNF Clause generator - variable name contruction] |
---|
6494 | |
---|
6495 | SideEffects [] |
---|
6496 | |
---|
6497 | ******************************************************************************/ |
---|
6498 | static char *CNFVariableNameConstructor(char *varName, int varEncoding, int pathIndex) |
---|
6499 | { |
---|
6500 | char tempStr [LENGTH_1]; |
---|
6501 | char *cnfVarName; |
---|
6502 | int nChar; |
---|
6503 | |
---|
6504 | nChar = sprintf(tempStr, "%s_%d_%d", varName, varEncoding, pathIndex); // value sign has to be added later |
---|
6505 | cnfVarName = tempStr; |
---|
6506 | //(void) fprintf(vis_stderr, "[TEST] CNF Variable Name : %s [number of characters = %d] >> return : %s\n", tempStr, nChar, cnfVarName); |
---|
6507 | |
---|
6508 | return cnfVarName; |
---|
6509 | } |
---|
6510 | |
---|
6511 | /**Function******************************************************************** |
---|
6512 | |
---|
6513 | Synopsis [ |
---|
6514 | c = a <-> b = (a=0)*(b=0) + (a=1)*(b=1) .... |
---|
6515 | For a given term (a=i)*(b=i), if either is Zero, don't generate |
---|
6516 | clauses for this term. |
---|
6517 | if both are One, don't generate clauses |
---|
6518 | for c. |
---|
6519 | ] |
---|
6520 | |
---|
6521 | SideEffects [] |
---|
6522 | |
---|
6523 | ******************************************************************************/ |
---|
6524 | static void |
---|
6525 | BmcGenerateClausesFromStateTostateMine( |
---|
6526 | bAig_Manager_t *manager, |
---|
6527 | bAigEdge_t *fromAigArray, |
---|
6528 | bAigEdge_t *toAigArray, |
---|
6529 | int mvfSize, |
---|
6530 | int fromState, |
---|
6531 | int toState, |
---|
6532 | BmcCnfClauses_t *cnfClauses, |
---|
6533 | int outIndex) |
---|
6534 | { |
---|
6535 | array_t *clause, *tmpclause; |
---|
6536 | int toIndex, fromIndex, cnfIndex; |
---|
6537 | int i; |
---|
6538 | |
---|
6539 | /* used to turn off the warning messages: might be left uninitialized. |
---|
6540 | We are sure that these two variables will not be used uninitialized. |
---|
6541 | */ |
---|
6542 | toIndex =0; |
---|
6543 | fromIndex = 0; |
---|
6544 | |
---|
6545 | for(i=0; i< mvfSize; i++){ |
---|
6546 | if ((fromAigArray[i] == bAig_One) && (toAigArray[i] == bAig_One)){ |
---|
6547 | return; /* the clause is always true */ |
---|
6548 | } |
---|
6549 | } |
---|
6550 | clause = array_alloc(int, 0); |
---|
6551 | for(i=0; i< mvfSize; i++){ |
---|
6552 | if ((fromAigArray[i] != bAig_Zero) && (toAigArray[i] != bAig_Zero)){ |
---|
6553 | if (toAigArray[i] != bAig_One){ |
---|
6554 | /* to State */ |
---|
6555 | |
---|
6556 | toIndex = BmcGenerateCnfFormulaForAigFunction(manager,toAigArray[i], |
---|
6557 | toState,cnfClauses); |
---|
6558 | } |
---|
6559 | if (fromAigArray[i] != bAig_One){ |
---|
6560 | /* from State */ |
---|
6561 | fromIndex = BmcGenerateCnfFormulaForAigFunction(manager, |
---|
6562 | fromAigArray[i], |
---|
6563 | fromState, |
---|
6564 | cnfClauses); |
---|
6565 | } |
---|
6566 | /* |
---|
6567 | Create new var for the output of this node. We don't create variable for this node, we only |
---|
6568 | use its index number. |
---|
6569 | */ |
---|
6570 | cnfIndex = cnfClauses->cnfGlobalIndex++; /* index of the output of the OR of T(from, to) */ |
---|
6571 | |
---|
6572 | assert(abs(cnfIndex) <= cnfClauses->cnfGlobalIndex); |
---|
6573 | assert(abs(fromIndex) <= cnfClauses->cnfGlobalIndex); |
---|
6574 | assert(abs(toIndex) <= cnfClauses->cnfGlobalIndex); |
---|
6575 | |
---|
6576 | if (toAigArray[i] == bAig_One){ |
---|
6577 | tmpclause = array_alloc(int, 2); |
---|
6578 | array_insert(int, tmpclause, 0, -fromIndex); |
---|
6579 | array_insert(int, tmpclause, 1, cnfIndex); |
---|
6580 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
6581 | array_free(tmpclause); |
---|
6582 | |
---|
6583 | tmpclause = array_alloc(int, 2); |
---|
6584 | array_insert(int, tmpclause, 0, fromIndex); |
---|
6585 | array_insert(int, tmpclause, 1, -cnfIndex); |
---|
6586 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
6587 | array_free(tmpclause); |
---|
6588 | |
---|
6589 | } else if (fromAigArray[i] == bAig_One){ |
---|
6590 | tmpclause = array_alloc(int, 2); |
---|
6591 | array_insert(int, tmpclause, 0, -toIndex); |
---|
6592 | array_insert(int, tmpclause, 1, cnfIndex); |
---|
6593 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
6594 | array_free(tmpclause); |
---|
6595 | |
---|
6596 | tmpclause = array_alloc(int, 2); |
---|
6597 | array_insert(int, tmpclause, 0, toIndex); |
---|
6598 | array_insert(int, tmpclause, 1, -cnfIndex); |
---|
6599 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
6600 | array_free(tmpclause); |
---|
6601 | |
---|
6602 | } else { |
---|
6603 | tmpclause = array_alloc(int, 3); |
---|
6604 | array_insert(int, tmpclause, 0, -toIndex); |
---|
6605 | array_insert(int, tmpclause, 1, -fromIndex); |
---|
6606 | array_insert(int, tmpclause, 2, cnfIndex); |
---|
6607 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
6608 | array_free(tmpclause); |
---|
6609 | |
---|
6610 | tmpclause = array_alloc(int, 2); |
---|
6611 | array_insert(int, tmpclause, 0, toIndex); |
---|
6612 | array_insert(int, tmpclause, 1, -cnfIndex); |
---|
6613 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
6614 | array_free(tmpclause); |
---|
6615 | |
---|
6616 | tmpclause = array_alloc(int, 2); |
---|
6617 | array_insert(int, tmpclause, 0, fromIndex); |
---|
6618 | array_insert(int, tmpclause, 1, -cnfIndex); |
---|
6619 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
6620 | array_free(tmpclause); |
---|
6621 | } |
---|
6622 | array_insert_last(int, clause, cnfIndex); |
---|
6623 | } /* if */ |
---|
6624 | // (void) fprintf(vis_stderr, "[CNF] (%d) > To : %d; From : %d; cnfIndex : %d \n", i, toIndex, fromIndex, cnfIndex); |
---|
6625 | } /* for i loop */ |
---|
6626 | if (outIndex != 0 ){ |
---|
6627 | array_insert_last(int, clause, -outIndex); |
---|
6628 | } |
---|
6629 | BmcCnfInsertClause(cnfClauses, clause); |
---|
6630 | array_free(clause); |
---|
6631 | |
---|
6632 | return; |
---|
6633 | } |
---|
6634 | |
---|
6635 | |
---|
6636 | /**Function******************************************************************** |
---|
6637 | |
---|
6638 | Synopsis [Generate CNF formula for a path from state 'from' to state 'to'] |
---|
6639 | |
---|
6640 | Description [Unfold the transition relation 'k' states (k = to-from +1), and |
---|
6641 | generate clauses for each state. |
---|
6642 | |
---|
6643 | For a multi-valued latch of 4 vlaues. Two binary variables are used |
---|
6644 | to rpresent X, x1 and x0. For this latch, there exist three multi-valued |
---|
6645 | functions. |
---|
6646 | One for the binary reoresentation of the variable. For example the |
---|
6647 | second entry of the mvf = 1, iff ~x1 and x0. |
---|
6648 | The second mfv is for the data input of the latch. If the And/Inv graph |
---|
6649 | attached to an entry of this mvf equal to 1, X equal to the binary |
---|
6650 | representation corresponding to this entry. For example, if the And/ |
---|
6651 | INV graph attached to the first entry =1, then X = ~x1 & ~x0. |
---|
6652 | To generate the CNF to the transition relation, first generate CNF to |
---|
6653 | next state varaible using mvf of the latch. Then, generate CNF for |
---|
6654 | latch data input using current state variavles. Finaly, generate CNF |
---|
6655 | for the AND of these two MVF. This for every entry of the MVF. Then |
---|
6656 | OR the results. |
---|
6657 | The third MVF is for the initial value of the latch. It is treat the |
---|
6658 | same as the latch data input except if the initial value is constant. |
---|
6659 | |
---|
6660 | The initialState value may be either BMC_INITIAL_STATES to generate the clause for the intial states. |
---|
6661 | BMC_NO_INITIAL_STATES otherwise. |
---|
6662 | ] |
---|
6663 | |
---|
6664 | SideEffects [] |
---|
6665 | |
---|
6666 | SeeAlso [] |
---|
6667 | |
---|
6668 | ******************************************************************************/ |
---|
6669 | static void |
---|
6670 | BmcCnfGenerateClausesForPathMine( |
---|
6671 | Ntk_Network_t *network, |
---|
6672 | int from, |
---|
6673 | int to, |
---|
6674 | int initialState, |
---|
6675 | BmcCnfClauses_t *cnfClauses, |
---|
6676 | st_table *nodeToMvfAigTable, |
---|
6677 | st_table *CoiTable) |
---|
6678 | { |
---|
6679 | mAig_Manager_t *manager = Ntk_NetworkReadMAigManager(network); |
---|
6680 | st_generator *stGen; |
---|
6681 | |
---|
6682 | Ntk_Node_t *latch, *latchData, *latchInit; |
---|
6683 | MvfAig_Function_t *initMvfAig, *dataMvfAig, *latchMvfAig; |
---|
6684 | bAigEdge_t *initBAig, *latchBAig, *dataBAig; |
---|
6685 | |
---|
6686 | int i, k, mvfSize; |
---|
6687 | |
---|
6688 | st_foreach_item(CoiTable, stGen, &latch, NULL) { |
---|
6689 | |
---|
6690 | |
---|
6691 | latchInit = Ntk_LatchReadInitialInput(latch); |
---|
6692 | latchData = Ntk_LatchReadDataInput(latch); |
---|
6693 | |
---|
6694 | /* Get the multi-valued function for each node*/ |
---|
6695 | initMvfAig = Bmc_ReadMvfAig(latchInit, nodeToMvfAigTable); |
---|
6696 | if (initMvfAig == NIL(MvfAig_Function_t)){ |
---|
6697 | (void) fprintf(vis_stderr, "No multi-valued function for this node %s \n", Ntk_NodeReadName(latchInit)); |
---|
6698 | return; |
---|
6699 | } |
---|
6700 | dataMvfAig = Bmc_ReadMvfAig(latchData, nodeToMvfAigTable); |
---|
6701 | if (dataMvfAig == NIL(MvfAig_Function_t)){ |
---|
6702 | (void) fprintf(vis_stderr, "No multi-valued function for this node %s \n", Ntk_NodeReadName(latchData)); |
---|
6703 | return; |
---|
6704 | } |
---|
6705 | latchMvfAig = Bmc_ReadMvfAig(latch, nodeToMvfAigTable); |
---|
6706 | if (latchMvfAig == NIL(MvfAig_Function_t)){ |
---|
6707 | latchMvfAig = Bmc_NodeBuildMVF(network, latch); |
---|
6708 | array_free(latchMvfAig); |
---|
6709 | latchMvfAig = Bmc_ReadMvfAig(latch, nodeToMvfAigTable); |
---|
6710 | } |
---|
6711 | |
---|
6712 | mvfSize = array_n(initMvfAig); |
---|
6713 | initBAig = ALLOC(bAigEdge_t, mvfSize); |
---|
6714 | dataBAig = ALLOC(bAigEdge_t, mvfSize); |
---|
6715 | latchBAig = ALLOC(bAigEdge_t, mvfSize); |
---|
6716 | |
---|
6717 | for(i=0; i< mvfSize; i++){ |
---|
6718 | dataBAig[i] = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(dataMvfAig, i)); |
---|
6719 | latchBAig[i] = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(latchMvfAig, i)); |
---|
6720 | initBAig[i] = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(initMvfAig, i)); |
---|
6721 | } |
---|
6722 | /* |
---|
6723 | if (from == 0){ |
---|
6724 | */ |
---|
6725 | if (initialState == BMC_INITIAL_STATES){ |
---|
6726 | /* Generate the CNF for the initial state of the latch */ |
---|
6727 | BmcGenerateClausesFromStateTostateMine(manager, initBAig, latchBAig, mvfSize, -1, 0, cnfClauses, 0); |
---|
6728 | } |
---|
6729 | /* Generate the CNF for the transition functions */ |
---|
6730 | for (k=from; k < to; k++){ |
---|
6731 | BmcGenerateClausesFromStateTostateMine(manager, dataBAig, latchBAig, mvfSize, k, k+1, cnfClauses, 0); |
---|
6732 | } /* for k state loop */ |
---|
6733 | |
---|
6734 | FREE(initBAig); |
---|
6735 | FREE(dataBAig); |
---|
6736 | FREE(latchBAig); |
---|
6737 | }/* For each latch loop*/ |
---|
6738 | |
---|
6739 | return; |
---|
6740 | } |
---|
6741 | |
---|
6742 | |
---|
6743 | |
---|
6744 | /**Function******************************************************************** |
---|
6745 | |
---|
6746 | Synopsis [Write the set of clauses in diamacs format to the output file.] |
---|
6747 | |
---|
6748 | SideEffects [] |
---|
6749 | |
---|
6750 | ******************************************************************************/ |
---|
6751 | static void |
---|
6752 | BmcWriteClausesMine( |
---|
6753 | mAig_Manager_t *maigManager, |
---|
6754 | FILE *cnfFile, |
---|
6755 | BmcCnfClauses_t *cnfClauses, |
---|
6756 | BmcOption_t *options) |
---|
6757 | { |
---|
6758 | st_generator *stGen; |
---|
6759 | char *name; |
---|
6760 | int cnfIndex, i, k; |
---|
6761 | |
---|
6762 | if (options->verbosityLevel == BmcVerbosityMax_c) { |
---|
6763 | fprintf(vis_stderr, |
---|
6764 | "\n--- [CNF] Number of Variables = %d Number of Clauses = %d\n", |
---|
6765 | cnfClauses->cnfGlobalIndex-1, cnfClauses->noOfClauses); |
---|
6766 | } |
---|
6767 | st_foreach_item_int(cnfClauses->cnfIndexTable, stGen, &name, &cnfIndex) { |
---|
6768 | fprintf(cnfFile, "c %s %d\n",name, cnfIndex); |
---|
6769 | } |
---|
6770 | (void) fprintf(cnfFile, "p cnf %d %d\n", cnfClauses->cnfGlobalIndex-1, |
---|
6771 | cnfClauses->noOfClauses); |
---|
6772 | if (cnfClauses->clauseArray != NIL(array_t)) { |
---|
6773 | for (i = 0; i < cnfClauses->nextIndex; i++) { |
---|
6774 | k = array_fetch(int, cnfClauses->clauseArray, i); |
---|
6775 | (void) fprintf(cnfFile, "%d%c", k, (k == 0) ? '\n' : ' '); |
---|
6776 | } |
---|
6777 | } |
---|
6778 | return; |
---|
6779 | } |
---|
6780 | |
---|
6781 | |
---|
6782 | /**Function******************************************************************** |
---|
6783 | |
---|
6784 | Synopsis [Decimal value to binary converter - Done by Me] |
---|
6785 | |
---|
6786 | SideEffects [] |
---|
6787 | |
---|
6788 | ******************************************************************************/ |
---|
6789 | |
---|
6790 | static int *DecBinConverter (int decValue, int size, int *binValue){ |
---|
6791 | |
---|
6792 | int i; |
---|
6793 | // int tempVal; |
---|
6794 | // int *binValue = malloc (sizeof(int)*size); |
---|
6795 | |
---|
6796 | // tempVal = decValue; |
---|
6797 | for (i=0; i<size; i++){ |
---|
6798 | // (void) fprintf(vis_stderr, " ***** tempVal = %d \n", tempVal); |
---|
6799 | binValue[i] = decValue & 1; |
---|
6800 | decValue = decValue >> 1; |
---|
6801 | } |
---|
6802 | |
---|
6803 | return binValue; |
---|
6804 | } |
---|
6805 | |
---|
6806 | |
---|
6807 | /**Function******************************************************************** |
---|
6808 | |
---|
6809 | Synopsis [] |
---|
6810 | |
---|
6811 | Description [- Done by Cecile Braunstein] |
---|
6812 | |
---|
6813 | SideEffects [] |
---|
6814 | |
---|
6815 | SeeAlso [] |
---|
6816 | |
---|
6817 | ******************************************************************************/ |
---|
6818 | static void printSATAssig( array_t* result) |
---|
6819 | { |
---|
6820 | int k; |
---|
6821 | printf("RESULT : \n"); |
---|
6822 | for(k=0; k< array_n(result); k++){ |
---|
6823 | printf("%d\n",array_fetch(int, result, k)); |
---|
6824 | } |
---|
6825 | } |
---|
6826 | |
---|
6827 | /**Function******************************************************************** |
---|
6828 | |
---|
6829 | Synopsis [] |
---|
6830 | |
---|
6831 | Description [- Done by Cecile Braunstein] |
---|
6832 | |
---|
6833 | SideEffects [] |
---|
6834 | |
---|
6835 | SeeAlso [] |
---|
6836 | |
---|
6837 | ******************************************************************************/ |
---|
6838 | static int findIndex(BmcCnfClauses_t* cnfClauses , char * nodeName) |
---|
6839 | { |
---|
6840 | int index; |
---|
6841 | |
---|
6842 | st_lookup(cnfClauses->cnfIndexTable,nodeName,&index); |
---|
6843 | return index; |
---|
6844 | |
---|
6845 | } |
---|
6846 | |
---|
6847 | |
---|
6848 | /**Function******************************************************************** |
---|
6849 | |
---|
6850 | Synopsis [] |
---|
6851 | |
---|
6852 | Description [- Done by Cecile Braunstein] |
---|
6853 | |
---|
6854 | SideEffects [] |
---|
6855 | |
---|
6856 | SeeAlso [] |
---|
6857 | |
---|
6858 | ******************************************************************************/ |
---|
6859 | static st_table * generateAllLatches(Ntk_Network_t * ntk) |
---|
6860 | { |
---|
6861 | st_table *CoiTable = st_init_table(st_ptrcmp, st_ptrhash); |
---|
6862 | lsGen gen ; |
---|
6863 | Ntk_Node_t *node; |
---|
6864 | |
---|
6865 | Ntk_NetworkForEachNode(ntk,gen, node){ |
---|
6866 | if (Ntk_NodeTestIsLatch(node)){ |
---|
6867 | st_insert(CoiTable, (char *) node, (char *) 0); |
---|
6868 | } |
---|
6869 | } |
---|
6870 | return CoiTable; |
---|
6871 | } |
---|
6872 | |
---|
6873 | |
---|
6874 | /**Function******************************************************************** |
---|
6875 | |
---|
6876 | Synopsis [] |
---|
6877 | |
---|
6878 | Description [- Done by Cecile Braunstein] |
---|
6879 | |
---|
6880 | SideEffects [] |
---|
6881 | |
---|
6882 | SeeAlso [] |
---|
6883 | |
---|
6884 | ******************************************************************************/ |
---|
6885 | static void build_unroll_circuit(Ntk_Network_t * ntk, int bound, BmcOption_t * options,BmcCnfClauses_t* cnfClauses) |
---|
6886 | { |
---|
6887 | (void) fprintf(vis_stderr, "\n*** Generating CNF clauses for current network. *** \n"); |
---|
6888 | |
---|
6889 | st_table *CoiTable = generateAllLatches(ntk); |
---|
6890 | lsGen gen ; |
---|
6891 | Ntk_Node_t *node; |
---|
6892 | |
---|
6893 | |
---|
6894 | |
---|
6895 | Ntk_NetworkForEachNode(ntk,gen, node){ |
---|
6896 | if (Ntk_NodeTestIsLatch(node)){ |
---|
6897 | st_insert(CoiTable, (char *) node, (char *) 0); |
---|
6898 | } |
---|
6899 | } |
---|
6900 | |
---|
6901 | options->verbosityLevel = BmcVerbosityMax_c; |
---|
6902 | options->satSolver = CirCUs; |
---|
6903 | options->timeOutPeriod = 0; |
---|
6904 | options->printInputs = TRUE; |
---|
6905 | options->minK = bound; |
---|
6906 | options->maxK = bound; |
---|
6907 | options->step = bound; |
---|
6908 | options->dbgLevel = 1; |
---|
6909 | |
---|
6910 | //nodeToMvfAigTable Maps each node to its Multi-function And/Inv graph |
---|
6911 | st_table* nodeToMvfAigTable = (st_table *) Ntk_NetworkReadApplInfo(ntk, MVFAIG_NETWORK_APPL_KEY); |
---|
6912 | assert(nodeToMvfAigTable != NIL(st_table)); |
---|
6913 | |
---|
6914 | // Create clauses database |
---|
6915 | int initState = BMC_INITIAL_STATES; |
---|
6916 | BmcCnfGenerateClausesForPathMine(ntk, 0, bound, initState, cnfClauses, nodeToMvfAigTable, CoiTable); |
---|
6917 | |
---|
6918 | } |
---|
6919 | |
---|
6920 | |
---|
6921 | /**Function******************************************************************** |
---|
6922 | |
---|
6923 | Synopsis [SAT Solver CNF File generator - Done by Cecile Braunstein] |
---|
6924 | |
---|
6925 | Description [ OBSOLETE!!! ] |
---|
6926 | |
---|
6927 | SideEffects [] |
---|
6928 | |
---|
6929 | ******************************************************************************/ |
---|
6930 | |
---|
6931 | static int SATSolverFileGen (Hrc_Manager_t ** hmgr, char *fileName, int steps, BmcOption_t *options) |
---|
6932 | { |
---|
6933 | |
---|
6934 | (void) fprintf(vis_stderr, "\n*** Generating CNF File for SAT Solver. *** \n"); |
---|
6935 | |
---|
6936 | // BmcOption_t *options = BmcOptionAlloc(); |
---|
6937 | BmcCnfClauses_t *cnfClauses = NIL(BmcCnfClauses_t); |
---|
6938 | cnfClauses = BmcCnfClausesAlloc(); |
---|
6939 | Ntk_Network_t * ntk = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
6940 | build_unroll_circuit(ntk,steps,options,cnfClauses); |
---|
6941 | |
---|
6942 | int propIndex; |
---|
6943 | int newIndex; |
---|
6944 | array_t * newClause; |
---|
6945 | char *tempCNFString; |
---|
6946 | |
---|
6947 | tempCNFString = CNFVariableNameConstructor("o2", 0, 0); |
---|
6948 | propIndex = findIndex(cnfClauses, tempCNFString); |
---|
6949 | newClause = array_alloc(int,1); |
---|
6950 | array_insert(int,newClause,0,-propIndex); |
---|
6951 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
6952 | array_free(newClause); |
---|
6953 | |
---|
6954 | tempCNFString = CNFVariableNameConstructor("o2", 0, 1); |
---|
6955 | propIndex = findIndex(cnfClauses, tempCNFString); |
---|
6956 | newClause = array_alloc(int,1); |
---|
6957 | array_insert(int,newClause,0,-propIndex); |
---|
6958 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
6959 | array_free(newClause); |
---|
6960 | |
---|
6961 | tempCNFString = CNFVariableNameConstructor("o2", 0, 2); |
---|
6962 | propIndex = findIndex(cnfClauses, tempCNFString); |
---|
6963 | newClause = array_alloc(int,1); |
---|
6964 | array_insert(int,newClause,0, -propIndex); |
---|
6965 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
6966 | array_free(newClause); |
---|
6967 | |
---|
6968 | tempCNFString = CNFVariableNameConstructor("o2", 0, 3); |
---|
6969 | propIndex = findIndex(cnfClauses, tempCNFString); |
---|
6970 | newClause = array_alloc(int,1); |
---|
6971 | array_insert(int,newClause,0, propIndex); |
---|
6972 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
6973 | array_free(newClause); |
---|
6974 | |
---|
6975 | |
---|
6976 | FILE *cnfFile = fopen(fileName,"w"); |
---|
6977 | mAig_Manager_t * maigManager = Ntk_NetworkReadMAigManager(ntk); |
---|
6978 | BmcWriteClausesMine(maigManager, cnfFile, cnfClauses, options); |
---|
6979 | fclose(cnfFile); |
---|
6980 | |
---|
6981 | return 0; |
---|
6982 | } |
---|
6983 | |
---|
6984 | |
---|
6985 | /**Function******************************************************************** |
---|
6986 | |
---|
6987 | Synopsis [- Done by Cecile Braunstein] |
---|
6988 | |
---|
6989 | Description [] |
---|
6990 | |
---|
6991 | SideEffects [] |
---|
6992 | |
---|
6993 | SeeAlso [] |
---|
6994 | |
---|
6995 | ******************************************************************************/ |
---|
6996 | |
---|
6997 | static array_t * checkSATCircus( satManager_t *cm,BmcOption_t * options, boolean unsatcore, satArray_t *clauseIndexInCore) |
---|
6998 | { |
---|
6999 | |
---|
7000 | satOption_t *satOption; |
---|
7001 | array_t *result = NIL(array_t); |
---|
7002 | int maxSize; |
---|
7003 | |
---|
7004 | satOption = sat_InitOption(); |
---|
7005 | satOption->verbose = options->verbosityLevel; |
---|
7006 | //satOption->unsatCoreFileName = "Ucore.txt"; |
---|
7007 | satOption->clauseDeletionHeuristic = 0; |
---|
7008 | satOption->coreGeneration = unsatcore; |
---|
7009 | satOption->minimizeConflictClause = 1; |
---|
7010 | |
---|
7011 | cm->comment = ALLOC(char, 2); |
---|
7012 | cm->comment[0] = ' '; |
---|
7013 | cm->comment[1] = '\0'; |
---|
7014 | cm->stdOut = stdout; |
---|
7015 | cm->stdErr = stderr; |
---|
7016 | |
---|
7017 | cm->option = satOption; |
---|
7018 | cm->each = sat_InitStatistics(); |
---|
7019 | |
---|
7020 | cm->unitLits = sat_ArrayAlloc(16); |
---|
7021 | cm->pureLits = sat_ArrayAlloc(16); |
---|
7022 | |
---|
7023 | maxSize = 10000 << (bAigNodeSize-4); |
---|
7024 | cm->nodesArray = ALLOC(bAigEdge_t, maxSize); |
---|
7025 | cm->maxNodesArraySize = maxSize; |
---|
7026 | cm->nodesArraySize = bAigNodeSize; |
---|
7027 | |
---|
7028 | sat_AllocLiteralsDB(cm); |
---|
7029 | |
---|
7030 | sat_ReadCNF(cm, options->satInFile); |
---|
7031 | sat_Main(cm); |
---|
7032 | if(cm->status == SAT_UNSAT) { |
---|
7033 | if (options->verbosityLevel != BmcVerbosityNone_c){ |
---|
7034 | (void) fprintf(vis_stderr, "# UNSAT\n"); |
---|
7035 | } |
---|
7036 | if(unsatcore) |
---|
7037 | { |
---|
7038 | clauseIndexInCore = cm->clauseIndexInCore; |
---|
7039 | } |
---|
7040 | fflush(cm->stdOut); |
---|
7041 | |
---|
7042 | }else if(cm->status == SAT_SAT) { |
---|
7043 | if (options->verbosityLevel != BmcVerbosityNone_c){ |
---|
7044 | (void) fprintf(vis_stderr, "# SAT\n"); |
---|
7045 | } |
---|
7046 | fflush(cm->stdOut); |
---|
7047 | result = array_alloc(int, 0); |
---|
7048 | { |
---|
7049 | int i, size, value; |
---|
7050 | |
---|
7051 | size = cm->initNumVariables * bAigNodeSize; |
---|
7052 | for(i=bAigNodeSize; i<=size; i+=bAigNodeSize) { |
---|
7053 | value = SATvalue(i); |
---|
7054 | if(value == 1) { |
---|
7055 | array_insert_last(int, result, SATnodeID(i)); |
---|
7056 | } |
---|
7057 | else if(value == 0) { |
---|
7058 | array_insert_last(int, result, -(SATnodeID(i))); |
---|
7059 | } |
---|
7060 | } |
---|
7061 | } |
---|
7062 | } |
---|
7063 | return result; |
---|
7064 | } |
---|
7065 | |
---|
7066 | |
---|
7067 | /**Function******************************************************************** |
---|
7068 | |
---|
7069 | Synopsis [SAT Solver - Done by Cecile Braunstein] |
---|
7070 | |
---|
7071 | SideEffects [] |
---|
7072 | |
---|
7073 | ******************************************************************************/ |
---|
7074 | |
---|
7075 | static int SATSolver (int steps, BmcOption_t *options) |
---|
7076 | { |
---|
7077 | |
---|
7078 | (void) fprintf(vis_stderr, "*** SAT Solver begins. *** \n"); |
---|
7079 | |
---|
7080 | // Read another design and build new clauses |
---|
7081 | satManager_t *cm; |
---|
7082 | cm = sat_InitManager(0); |
---|
7083 | array_t * result = NIL(array_t); |
---|
7084 | satArray_t * coreArray= sat_ArrayAlloc(1024); |
---|
7085 | result = checkSATCircus(cm,options,steps,coreArray); |
---|
7086 | |
---|
7087 | return 0; |
---|
7088 | } |
---|
7089 | |
---|
7090 | |
---|
7091 | |
---|
7092 | |
---|