[3] | 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 | |
---|
[4] | 43 | #define BLIF_MV_FILE_C1 "concrete_model/concret_main.mv" |
---|
| 44 | #define FAIRNESS_FILE_C1 "concrete_model/machine_concret.fair" |
---|
| 45 | #define CTL_FILE_C1 "concrete_model/machine_concret.ctl" |
---|
| 46 | #define CNF_FILE_C1 "concrete_model/SATcnf_c1.cnf" |
---|
| 47 | #define DEBUG_FILE_C1 "concrete_model/debug_trace_crt" |
---|
[3] | 48 | |
---|
| 49 | |
---|
[4] | 50 | #define BLIF_MV_FILE_A1 "abstract_model/main_abstract.mv" |
---|
| 51 | #define FAIRNESS_FILE_A1 "abstract_model/main_abstract.fair" |
---|
| 52 | #define CTL_FILE_A1 "abstract_model/machine_concret.ctl" |
---|
| 53 | #define CNF_FILE_A1 "abstract_model/SATcnf_a1.cnf" |
---|
| 54 | #define DEBUG_FILE_A1 "abstract_model/debug_trace_abs" |
---|
[3] | 55 | |
---|
| 56 | /*****************************************************/ |
---|
| 57 | /* |
---|
| 58 | #define BLIF_MV_FILE_C1 "PBS_VCI_PI/new_main.mv" |
---|
| 59 | #define FAIRNESS_FILE_C1 "PBS_VCI_PI/main_mod.fair" |
---|
| 60 | #define CTL_FILE_C1 "PBS_VCI_PI/propri_mod.ctl" |
---|
| 61 | #define CNF_FILE_C1 "PBS_VCI_PI/SATcnf_c1.cnf" |
---|
| 62 | #define CNF_FILE_C1_BIS "PBS_VCI_PI/SATcnf_c1_bis.cnf" |
---|
| 63 | #define DEBUG_FILE_C1 "PBS_VCI_PI/debug_trace" |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | #define BLIF_MV_FILE_A1 "PBS_VCI_PI/new_main.mv" |
---|
| 67 | #define FAIRNESS_FILE_A1 "PBS_VCI_PI/main_mod.fair" |
---|
| 68 | #define CTL_FILE_A1 "PBS_VCI_PI/propri_mod.ctl" |
---|
| 69 | #define CNF_FILE_A1 "PBS_VCI_PI/SATcnf_a1.cnf" |
---|
| 70 | #define DEBUG_FILE_A1 "PBS_VCI_PI/debug_trace" |
---|
| 71 | */ |
---|
| 72 | |
---|
| 73 | //#define BLIF_MV_FILE_C1 "VCI_PI/Concrete/main_concret.mv" |
---|
| 74 | //#define FAIRNESS_FILE_C1 "VCI_PI/Concrete/main_concret.fair" |
---|
| 75 | //#define CTL_FILE_C1 "VCI_PI/Concrete/main_concret.ctl" |
---|
| 76 | //#define CNF_FILE_C1 "VCI_PI/Concrete/SATcnf_c1.cnf" |
---|
| 77 | //#define DEBUG_FILE_C1 "VCI_PI/Concrete/debug_trace" |
---|
| 78 | |
---|
| 79 | //#define BLIF_MV_FILE_A1 "VCI_PI/Concrete/main_concret.mv" |
---|
| 80 | //#define FAIRNESS_FILE_A1 "VCI_PI/Concrete/main_concret.fair" |
---|
| 81 | //#define CTL_FILE_A1 "VCI_PI/Concrete/main_concret.ctl" |
---|
| 82 | //#define CNF_FILE_A1 "VCI_PI/Concrete/SATcnf_a1.cnf" |
---|
| 83 | //#define DEBUG_FILE_A1 "VCI_PI/Concrete/debug_trace" |
---|
| 84 | |
---|
| 85 | //#define BLIF_MV_FILE_A1 "VCI_PI/main_abstract.mv" |
---|
| 86 | //#define FAIRNESS_FILE_A1 "VCI_PI/main_abstract.fair" |
---|
| 87 | //#define CTL_FILE_A1 "VCI_PI/main_concret.ctl" |
---|
| 88 | //#define CNF_FILE_A1 "VCI_PI/SATcnf_a1.cnf" |
---|
| 89 | //#define DEBUG_FILE_A1 "VCI_PI/debug_trace" |
---|
| 90 | |
---|
| 91 | // #define BLIF_MV_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/main_abstract.mv" |
---|
| 92 | // #define FAIRNESS_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/main_abstract.fair" |
---|
| 93 | // #define CTL_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/machine_concret.ctl" |
---|
| 94 | // #define CNF_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/SATcnf_a1.cnf" |
---|
| 95 | // #define DEBUG_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2/debug_trace" |
---|
| 96 | |
---|
| 97 | // #define BLIF_MV_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/main_abstract.mv" |
---|
| 98 | // #define FAIRNESS_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/main_abstract.fair" |
---|
| 99 | // #define CTL_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/machine_concret.ctl" |
---|
| 100 | // #define CNF_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/SATcnf_a1.cnf" |
---|
| 101 | // #define DEBUG_FILE_A1 "EX_A1/Abs_Phi1_and_Phi2_REFINED2/debug_trace" |
---|
| 102 | |
---|
| 103 | // #define BLIF_MV_FILE_C1 "METRONOME/metronome.mv" |
---|
| 104 | // #define FAIRNESS_FILE_C1 "METRONOME/metronome.fair" |
---|
| 105 | // #define CTL_FILE_C1 "METRONOME/metronome.ctl" |
---|
| 106 | // #define CNF_FILE_C1 "METRONOME/SATcnf_c2.cnf" |
---|
| 107 | |
---|
| 108 | // #define BLIF_MV_FILE_C1 "GATES/NOT/Concret_Main.mv" |
---|
| 109 | // #define FAIRNESS_FILE_C1 "GATES/NOT/not.fair" |
---|
| 110 | // #define CTL_FILE_C1 "GATES/NOT/not.ctl" |
---|
| 111 | // #define CNF_FILE_C1 "GATES/NOT/SATcnf_not.cnf" |
---|
| 112 | |
---|
| 113 | // #define BLIF_MV_FILE_C1 "GATES/NOT2/Concret_Main.mv" |
---|
| 114 | // #define FAIRNESS_FILE_C1 "GATES/NOT2/not2.fair" |
---|
| 115 | // #define CTL_FILE_C1 "GATES/NOT2/not2.ctl" |
---|
| 116 | // #define CNF_FILE_C1 "GATES/NOT2/SATcnf_not2.cnf" |
---|
| 117 | |
---|
| 118 | // #define BLIF_MV_FILE_C1 "GATES/NOT4/Concret_Main.mv" |
---|
| 119 | // #define FAIRNESS_FILE_C1 "GATES/NOT4/not4.fair" |
---|
| 120 | // #define CTL_FILE_C1 "GATES/NOT4/not4.ctl" |
---|
| 121 | // #define CNF_FILE_C1 "GATES/NOT4/SATcnf_not4.cnf" |
---|
| 122 | |
---|
| 123 | // #define BLIF_MV_FILE_C1 "GATES/AND/Concret_Main.mv" |
---|
| 124 | // #define FAIRNESS_FILE_C1 "GATES/AND/and.fair" |
---|
| 125 | // #define CTL_FILE_C1 "GATES/AND/and.ctl" |
---|
| 126 | // #define CNF_FILE_C1 "GATES/AND/SATcnf_and.cnf" |
---|
| 127 | |
---|
| 128 | // #define BLIF_MV_FILE_C1 "GATES/AND2/Concret_Main.mv" |
---|
| 129 | // #define FAIRNESS_FILE_C1 "GATES/AND2/and2.fair" |
---|
| 130 | // #define CTL_FILE_C1 "GATES/AND2/and2.ctl" |
---|
| 131 | // #define CNF_FILE_C1 "GATES/AND2/SATcnf_and2.cnf" |
---|
| 132 | |
---|
| 133 | // #define BLIF_MV_FILE_C1 "GATES/OR/Concret_Main.mv" |
---|
| 134 | // #define FAIRNESS_FILE_C1 "GATES/OR/or.fair" |
---|
| 135 | // #define CTL_FILE_C1 "GATES/OR/or.ctl" |
---|
| 136 | // #define CNF_FILE_C1 "GATES/OR/SATcnf_or.cnf" |
---|
| 137 | |
---|
| 138 | // #define BLIF_MV_FILE_C1 "GATES/OR2/Concret_Main.mv" |
---|
| 139 | // #define FAIRNESS_FILE_C1 "GATES/OR2/or2.fair" |
---|
| 140 | // #define CTL_FILE_C1 "GATES/OR2/or2.ctl" |
---|
| 141 | // #define CNF_FILE_C1 "GATES/OR2/SATcnf_or2.cnf" |
---|
| 142 | |
---|
| 143 | // #define BLIF_MV_FILE_C1 "GATES/SFM2006_Circuit/Concret_Main.mv" |
---|
| 144 | // #define FAIRNESS_FILE_C1 "GATES/SFM2006_Circuit/sfm.fair" |
---|
| 145 | // #define CTL_FILE_C1 "GATES/SFM2006_Circuit/sfm.ctl" |
---|
| 146 | // #define CNF_FILE_C1 "GATES/SFM2006_Circuit/SATcnf_sfm.cnf" |
---|
| 147 | |
---|
| 148 | // #define BLIF_MV_FILE_C1 "GATES/SFM2006_Circuit2/Concret_Main.mv" |
---|
| 149 | // #define FAIRNESS_FILE_C1 "GATES/SFM2006_Circuit2/sfm2.fair" |
---|
| 150 | // #define CTL_FILE_C1 "GATES/SFM2006_Circuit2/sfm2.ctl" |
---|
| 151 | // #define CNF_FILE_C1 "GATES/SFM2006_Circuit2/SATcnf_sfm2.cnf" |
---|
| 152 | |
---|
| 153 | // #define BLIF_MV_FILE_C1 "GATES/SFM2006_Circuit3/Concret_Main.mv" |
---|
| 154 | // #define FAIRNESS_FILE_C1 "GATES/SFM2006_Circuit3/sfm3.fair" |
---|
| 155 | // #define CTL_FILE_C1 "GATES/SFM2006_Circuit3/sfm3.ctl" |
---|
| 156 | // #define CNF_FILE_C1 "GATES/SFM2006_Circuit3/SATcnf_sfm3.cnf" |
---|
| 157 | |
---|
| 158 | //#define BLIF_MV_FILE_A2 "MEE/metronome.mv" |
---|
| 159 | //#define FAIRNESS_FILE_A2 "EC1/machine_concret.fair" |
---|
| 160 | //#define CTL_FILE_A1 "EX1/machine_concret.ctl" |
---|
| 161 | //#define CNF_FILE_A2 "EX1/SATcnf_a2.cnf" |
---|
| 162 | |
---|
| 163 | /*---------------------------------------------------------------------------*/ |
---|
| 164 | /* Structure declarations */ |
---|
| 165 | /*---------------------------------------------------------------------------*/ |
---|
| 166 | /**Struct********************************************************************** |
---|
| 167 | Synopsis [A struct to store a string of characters] |
---|
| 168 | ******************************************************************************/ |
---|
| 169 | typedef char string1 [255]; |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | /**Struct********************************************************************** |
---|
| 173 | Synopsis [A struct to store of variables in the counter-example.] |
---|
| 174 | ******************************************************************************/ |
---|
| 175 | typedef struct { |
---|
| 176 | int varIndex; // not really necessary |
---|
| 177 | int varId; |
---|
| 178 | int varValue; |
---|
| 179 | // char *varName |
---|
| 180 | // char *symbolicValue |
---|
| 181 | string1 varName; // change to dynamic allocation later |
---|
| 182 | string1 symbolicValue; // change to dynamic allocation later |
---|
| 183 | } CEXVarStruct; |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | /**Struct********************************************************************** |
---|
| 187 | Synopsis [A struct to store counter-example data.] |
---|
| 188 | ******************************************************************************/ |
---|
| 189 | typedef struct { |
---|
| 190 | int pathIndex; |
---|
| 191 | int n_outputVar; |
---|
| 192 | int n_inputVar; |
---|
| 193 | CEXVarStruct *outputVar; |
---|
| 194 | CEXVarStruct *inputVar; |
---|
| 195 | }CEXStruct; |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | /*---------------------------------------------------------------------------*/ |
---|
| 199 | /* Variable declarations */ |
---|
| 200 | /*---------------------------------------------------------------------------*/ |
---|
| 201 | Hrc_Manager_t *hmgrGlobalC; |
---|
| 202 | |
---|
| 203 | FILE *vis_stderr; |
---|
| 204 | FILE *vis_stdout; |
---|
| 205 | FILE *vis_historyFile; |
---|
| 206 | FILE *vis_stdpipe; |
---|
| 207 | array_t *vm_commandHistoryArray; |
---|
| 208 | char *vm_programName; |
---|
| 209 | static int mcTimeOut; //Time-out value for model-checking |
---|
| 210 | static jmp_buf timeOutEnv; |
---|
| 211 | static long alarmLapTime; /* starting CPU time for timeout */ |
---|
| 212 | static jmp_buf env; |
---|
| 213 | |
---|
| 214 | extern FILE *IoYyin; |
---|
| 215 | extern int globalCurrentStackDepth; |
---|
| 216 | #ifdef IODEBUG |
---|
| 217 | extern int IoYydebug; |
---|
| 218 | #endif /*IODEBUG */ |
---|
| 219 | |
---|
| 220 | char currentPath [LENGTH_1]; |
---|
| 221 | static CEXVarStruct *testCEXVar; |
---|
| 222 | static CEXStruct *testCEX; |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | /*---------------------------------------------------------------------------*/ |
---|
| 226 | /* Static function prototypes */ |
---|
| 227 | /*---------------------------------------------------------------------------*/ |
---|
| 228 | |
---|
| 229 | static Hrc_Manager_t *read_blif_mvMine (FILE *fp, Hrc_Manager_t *hmgr, boolean isCanonical, boolean isIncremental, boolean isVerbose); |
---|
| 230 | static int read_fairnessMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
| 231 | static int init_verifyMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
| 232 | static int flatten_hierarchyMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
| 233 | static int static_orderMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
| 234 | static int build_partition_mddsMine (Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
| 235 | static int build_partition_maigsMine(Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
| 236 | static int print_ioMine (Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
| 237 | static int model_checkMine (Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
| 238 | static int print_modelsMine(Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
| 239 | static int print_fairnessMine(Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
| 240 | static Hrc_Node_t *cdMine(Hrc_Manager_t **hmgr, int argc, char **argv); //returns child or parent node |
---|
| 241 | static Hrc_Node_t *lsMine(Hrc_Manager_t **hmgr, int argc, char **argv); //returns current node |
---|
| 242 | static char *pwdMine(Hrc_Manager_t **hmgr, int argc, char **argv); //returns the path of the current node |
---|
| 243 | static int print_latchesMine(Hrc_Manager_t **hmgr, int argc, char **argv); |
---|
| 244 | |
---|
| 245 | 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); |
---|
| 246 | static int McFsmDebugFormulaMine (McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, array_t *careSetArray); |
---|
| 247 | static array_t * McFsmStateDebugFormulaMine( McOptions_t *options, Ctlp_Formula_t *ctlFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, array_t *prevCExArray); |
---|
| 248 | static array_t * FsmStateDebugConvertedFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, array_t **preCExArray); |
---|
| 249 | static array_t * FsmPathDebugFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
| 250 | |
---|
| 251 | static void DebugIDMine(McOptions_t *options, Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm); |
---|
| 252 | static void DebugTrueFalseMine(Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm); |
---|
| 253 | static array_t * DebugBooleanMine(McOptions_t *options, Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, array_t **preCExArray); |
---|
| 254 | static McPath_t * DebugEXMine (Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray); |
---|
| 255 | static McPath_t * DebugEUMine (Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray); |
---|
| 256 | static McPath_t * DebugEGMine (Ctlp_Formula_t *aFormula, mdd_t *aState, Fsm_Fsm_t *modelFsm, array_t *careSetArray, McOptions_t *options); |
---|
| 257 | |
---|
| 258 | static array_t * FsmPathDebugEXFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
| 259 | static array_t * FsmPathDebugEUFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
| 260 | static array_t * FsmPathDebugEGFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
| 261 | static array_t * FsmPathDebugEFFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *witnessPath, array_t *careSetArray, array_t **preCExArray); |
---|
| 262 | |
---|
| 263 | static array_t * FsmPathDebugAXFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray, array_t **preCExArray); |
---|
| 264 | static array_t * FsmPathDebugAFFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray, array_t **preCExArray); |
---|
| 265 | static array_t * FsmPathDebugAGFormulaMine(McOptions_t *options, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, McPath_t *counterExamplePath, array_t *careSetArray, array_t **preCExArray); |
---|
| 266 | static array_t * FsmPathDebugAUFormulaMine(McOptions_t *options, mdd_t *aState, Ctlp_Formula_t *ctlFormula, Fsm_Fsm_t *modelFsm, array_t *careSetArray, array_t **preCExArray); |
---|
| 267 | |
---|
| 268 | static int Mc_PrintPathMine (array_t *aPath, Fsm_Fsm_t *modelFsm, boolean printInput); |
---|
| 269 | 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); |
---|
| 270 | static void Mc_MintermPrintMine (mdd_t *aMinterm, array_t *support, Ntk_Network_t *aNetwork); |
---|
| 271 | static char *Mc_MintermToStringMine( mdd_t *aMinterm, array_t *aSupport, Ntk_Network_t *aNetwork, CEXStruct *CEXPath, int seqNumber, boolean inOutIndicator, BmcCnfClauses_t *cnfClauses); |
---|
| 272 | static array_t *McConvertMintermToValueArrayMine( mdd_t *aMinterm, array_t *aSupport, mdd_manager *mddMgr); |
---|
| 273 | static void McStatePassesOrFailsFormulaMine ( mdd_t *aState, Ctlp_Formula_t *formula, int pass, McDbgLevel debugLevel, Fsm_Fsm_t *modelFsm); |
---|
| 274 | static void McStateFailsFormulaMine (mdd_t *aState, Ctlp_Formula_t *formula, McDbgLevel debugLevel, Fsm_Fsm_t *modelFsm); |
---|
| 275 | static void McStatePassesFormulaMine( mdd_t *aState, Ctlp_Formula_t *formula, McDbgLevel debugLevel,Fsm_Fsm_t *modelFsm); |
---|
| 276 | |
---|
| 277 | static int _HrcStringCmp(const void * s1, const void * s2); |
---|
| 278 | static McOptions_t *ParseMcOptions( int argc, char **argv); |
---|
| 279 | static void TimeOutHandle(void); |
---|
| 280 | static Ord_OrderType StringConvertToOrderType(char *string); |
---|
| 281 | static boolean NetworkCheckSuppliedNodeList(Ntk_Network_t * network, lsList suppliedNodeList, Ord_OrderType orderType); |
---|
| 282 | static boolean FileReadNameList(FILE * fp, lsList * nameList, int verbose); |
---|
| 283 | static void _IoGlobalVariablesInitialize(void); |
---|
| 284 | static void _IoGlobalVariablesFree(void); |
---|
| 285 | static void _IoGlobalSubcktInfoFree(void); |
---|
| 286 | static void _IoSubcktArrayFree(array_t *array); |
---|
| 287 | static void _IoSubcktFree(IoSubckt_t *subckt); |
---|
| 288 | static void _IoGlobalResetInfoFree(void); |
---|
| 289 | static boolean _IoNodeTestCompatibilityAux(Hrc_Manager_t *hmgr, Hrc_Node_t *hnode1, Hrc_Node_t *hnode2, boolean mode); |
---|
| 290 | static void _IoManagerCanonicalize(Hrc_Manager_t *hmgr); |
---|
| 291 | static int nodenameCompare(const void * node1, const void * node2); |
---|
| 292 | static void PrintNodeStats(Hrc_Node_t *node, boolean isHnode); |
---|
| 293 | static void NodeListChildren(Hrc_Node_t *hnode, boolean recursiveFlag, int depth); |
---|
| 294 | static array_t *NodeListChildrenMine(Hrc_Node_t *hnode, boolean recursiveFlag, int depth); |
---|
| 295 | static void PrintSpace(int depth); |
---|
| 296 | static int cmp(const void * s1, const void * s2); |
---|
| 297 | static boolean MintermCheckWellFormed(mdd_t *aMinterm, array_t *aSupport, mdd_manager *mddMgr); |
---|
| 298 | static boolean SetCheckSupport(mdd_t *aMinterm, array_t *aSupport, mdd_manager *mddMgr); |
---|
| 299 | |
---|
| 300 | static char *CNFVariableNameConstructor(char *varName, int varEncoding, int pathIndex); |
---|
| 301 | static void BmcCnfGenerateClausesForPathMine (Ntk_Network_t *network, int from, int to, int initialState, BmcCnfClauses_t *cnfClauses, st_table *nodeToMvfAigTable, st_table *CoiTable); |
---|
| 302 | static void BmcGenerateClausesFromStateTostateMine (bAig_Manager_t *manager, bAigEdge_t *fromAigArray, bAigEdge_t *toAigArray, int mvfSize, int fromState, int toState, BmcCnfClauses_t *cnfClauses, int outIndex); |
---|
| 303 | static void BmcWriteClausesMine( mAig_Manager_t *maigManager, FILE *cnfFile, BmcCnfClauses_t *cnfClauses, BmcOption_t *options); |
---|
| 304 | static int *DecBinConverter (int decValue, int size, int *binValue); |
---|
| 305 | static int SATSolverFileGen (Hrc_Manager_t **hmgr, char *fileName, int steps, BmcOption_t *options); |
---|
| 306 | static int SATSolver (int steps, BmcOption_t *options); |
---|
| 307 | static void build_unroll_circuit(Ntk_Network_t * ntk, int bound,BmcOption_t * options,BmcCnfClauses_t* cnfClauses); |
---|
| 308 | static array_t * checkSATCircus( satManager_t *cm,BmcOption_t * options, boolean unsatcore, satArray_t *clauseIndexInCore); |
---|
| 309 | static st_table * generateAllLatches(Ntk_Network_t * ntk); |
---|
| 310 | static void printSATAssig( array_t* result); |
---|
| 311 | static int findIndex(BmcCnfClauses_t* cnfClauses , char * nodeName); |
---|
| 312 | |
---|
| 313 | |
---|
| 314 | /********************************************************/ |
---|
| 315 | /* Main */ |
---|
| 316 | /********************************************************/ |
---|
| 317 | |
---|
| 318 | int main(int argc, char **argv) |
---|
| 319 | { |
---|
| 320 | vis_stderr =stderr; |
---|
| 321 | vis_stdout = stdout; |
---|
| 322 | |
---|
| 323 | Hrc_Manager_t *hmgrC; |
---|
| 324 | Hrc_Manager_t *hmgrA; |
---|
| 325 | |
---|
| 326 | (void)fprintf(vis_stderr,"\n============= VIS ============= \n\n"); |
---|
| 327 | |
---|
| 328 | |
---|
| 329 | /**** CONCRETE MODEL *****/ |
---|
| 330 | (void)fprintf(vis_stderr,">>>>>>>>>>>>>>>>> CONCRETE MODEL : LOAD & SET UP... \n\n"); |
---|
| 331 | // --- read_blif_mv --- |
---|
| 332 | FILE *fpC; |
---|
| 333 | fpC = Cmd_FileOpen(BLIF_MV_FILE_C1, "r", NIL(char *), 1); |
---|
| 334 | boolean isCanonicalC = 0; |
---|
| 335 | boolean isIncrementalC = 0; |
---|
| 336 | boolean isVerboseC = 0; |
---|
| 337 | hmgrC = read_blif_mvMine (fpC, hmgrC, isCanonicalC, isIncrementalC, isVerboseC); |
---|
| 338 | (void) fprintf(vis_stderr, "*** 'read_blif_mv' of the concrete model completed. *** \n"); |
---|
| 339 | |
---|
| 340 | hmgrGlobalC = hmgrC; |
---|
| 341 | |
---|
| 342 | // --- print_io (display inputs and outputs) --- |
---|
| 343 | int print_ioExecC; |
---|
| 344 | int argcIOC = 1; |
---|
| 345 | char *argvIOC[1] = {"print_io"}; |
---|
| 346 | |
---|
| 347 | print_ioExecC = print_ioMine (&hmgrC, argcIOC, argvIOC); |
---|
| 348 | (void) fprintf(vis_stderr, "*** 'print_io' for concrete model completed. *** \n"); |
---|
| 349 | |
---|
| 350 | // --- init_verify --- |
---|
| 351 | int init_verifyExecC; |
---|
| 352 | int argcIVC = 1; |
---|
| 353 | char *argvIVC[1] = {"init_verify"}; |
---|
| 354 | init_verifyExecC = init_verifyMine (&hmgrC, argcIVC, argvIVC); |
---|
| 355 | (void) fprintf(vis_stderr, "*** 'init_verify' for concrete model completed. *** \n"); |
---|
| 356 | |
---|
| 357 | // --- build_partition_maigs --- |
---|
| 358 | int build_part_maigsExecC; |
---|
| 359 | int argcBPMAIGSC = 1; |
---|
| 360 | char *argvBPMAIGSC[1] = {"build_partition_maigs"}; |
---|
| 361 | build_part_maigsExecC = build_partition_maigsMine (&hmgrC, argcBPMAIGSC, argvBPMAIGSC); |
---|
| 362 | (void) fprintf(vis_stderr, "*** 'build_partition_maigs' for concrete model completed. *** \n"); |
---|
| 363 | |
---|
| 364 | // --- read_fairness --- |
---|
| 365 | int fairnessReadC; |
---|
| 366 | int argcFC = 2; |
---|
| 367 | char *argvFC[2] = {"read_fairness", FAIRNESS_FILE_C1}; |
---|
| 368 | fairnessReadC = read_fairnessMine (&hmgrC, argcFC, argvFC); |
---|
| 369 | (void) fprintf(vis_stderr, "*** 'read_fairness' for concrete model completed. *** \n"); |
---|
| 370 | |
---|
| 371 | // --- print_fairness --- |
---|
| 372 | int fairnessPrintC; |
---|
| 373 | int argcFPC = 1; |
---|
| 374 | char *argvFPC[1] = {"print_fairness"}; |
---|
| 375 | fairnessPrintC = print_fairnessMine (&hmgrC, argcFPC, argvFPC); |
---|
| 376 | (void) fprintf(vis_stderr, "*** 'print_fairness' for concrete model completed. *** \n"); |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | // // --- print_latches (display latches in current node) --- |
---|
| 380 | // int print_latchesExec; |
---|
| 381 | // int argcPL = 1; |
---|
| 382 | // char *argvPL[1]= {"print_latches"}; |
---|
| 383 | // |
---|
| 384 | // print_latchesExec = print_latchesMine (&hmgr, argcPL, argvPL); |
---|
| 385 | // (void) fprintf(vis_stderr, "*** 'print_latches' completed. *** \n"); |
---|
| 386 | |
---|
| 387 | (void)fprintf(vis_stderr,"\n... CONCRETE MODEL : LOAD & SET UP DONE! <<<<<<<<<<<<<<<<\n\n"); |
---|
| 388 | |
---|
| 389 | |
---|
| 390 | |
---|
| 391 | /**** ABSTRACT MODEL *****/ |
---|
| 392 | (void)fprintf(vis_stderr,">>>>>>>>>>>>>>>>> ABSTRACT MODEL : LOAD & SET UP...\n"); |
---|
| 393 | // --- read_blif_mv --- |
---|
| 394 | FILE *fpA; |
---|
| 395 | fpA = Cmd_FileOpen(BLIF_MV_FILE_A1, "r", NIL(char *), 1); |
---|
| 396 | boolean isCanonicalA = 0; |
---|
| 397 | boolean isIncrementalA = 0; |
---|
| 398 | boolean isVerboseA = 0; |
---|
| 399 | hmgrA = read_blif_mvMine (fpA, hmgrA, isCanonicalA, isIncrementalA, isVerboseA); |
---|
| 400 | (void) fprintf(vis_stderr, "*** 'read_blif_mv' of the abstract model completed. *** \n"); |
---|
| 401 | |
---|
| 402 | |
---|
| 403 | // --- print_io (display inputs and outputs) --- |
---|
| 404 | int print_ioExecA; |
---|
| 405 | int argcIOA = 1; |
---|
| 406 | char *argvIOA[1] = {"print_io"}; |
---|
| 407 | |
---|
| 408 | print_ioExecA = print_ioMine (&hmgrA, argcIOA, argvIOA); |
---|
| 409 | (void) fprintf(vis_stderr, "*** 'print_io' for abstract model completed. *** \n"); |
---|
| 410 | |
---|
| 411 | // --- init_verify --- |
---|
| 412 | int init_verifyExecA; |
---|
| 413 | int argcIVA = 1; |
---|
| 414 | char *argvIVA[1] = {"init_verify"}; |
---|
| 415 | init_verifyExecA = init_verifyMine (&hmgrA, argcIVA, argvIVA); |
---|
| 416 | (void) fprintf(vis_stderr, "*** 'init_verify' for abstract model completed. *** \n"); |
---|
| 417 | |
---|
| 418 | // --- read_fairness --- |
---|
| 419 | int fairnessReadA; |
---|
| 420 | int argcFA = 2; |
---|
| 421 | char *argvFA[2] = {"read_fairness", FAIRNESS_FILE_A1}; |
---|
| 422 | fairnessReadA = read_fairnessMine (&hmgrA, argcFA, argvFA); |
---|
| 423 | (void) fprintf(vis_stderr, "*** 'read_fairness' for abstract model completed. *** \n"); |
---|
| 424 | |
---|
| 425 | // --- print_fairness --- |
---|
| 426 | int fairnessPrintA; |
---|
| 427 | int argcFPA = 1; |
---|
| 428 | char *argvFPA[1] = {"print_fairness"}; |
---|
| 429 | fairnessPrintA = print_fairnessMine (&hmgrA, argcFPA, argvFPA); |
---|
| 430 | (void) fprintf(vis_stderr, "*** 'print_fairness' for abstract model completed. *** \n"); |
---|
| 431 | |
---|
| 432 | (void)fprintf(vis_stderr,"\n... ABSTRACT MODEL : LOAD & SET UP DONE! <<<<<<<<<<<<<<<<\n\n"); |
---|
| 433 | |
---|
| 434 | // --- model_check --- |
---|
| 435 | int model_checkExecA; |
---|
| 436 | int argcMCA = 4; |
---|
| 437 | // char *argvMC[2]= {"model_check", "EX_C1/machine_concret.ctl"}; |
---|
| 438 | // char *argvMC[4]= {"model_check", "-d", "3", "EX_C1/machine_concret.ctl"}; |
---|
| 439 | // char *argvMCA[2]= {"model_check", CTL_FILE_A1}; |
---|
| 440 | // char *argvMCA[4]= {"model_check", "-d", "1", CTL_FILE_A1}; |
---|
| 441 | char *argvMCA[4]= {"model_check", "-d", "2", CTL_FILE_A1}; |
---|
| 442 | // char *argvMCA[4]= {"model_check", "-d", "3", CTL_FILE_A1}; |
---|
| 443 | // char *argvMCA[5]= {"model_check", "-i", "-d", "3", CTL_FILE_A1}; |
---|
| 444 | // char *argvMC[6]= {"model_check", "-i", "-W", "-d", "2", "EX_C1/machine_concret.ctl"}; |
---|
| 445 | // char *argvMCA[6]= {"model_check", "-d", "2", "-f", DEBUG_FILE_A1, CTL_FILE_A1}; |
---|
| 446 | // char *argvMC[6]= {"model_check", "-v", "2", "-d", "2", "EX_C1/machine_concret.ctl"}; |
---|
| 447 | // char *argvMC[7]= {"model_check", "-i", "-w", "EX_C1/w_node_file", "-d", "2", "EX_C1/machine_concret.ctl"}; |
---|
| 448 | // char *argvMC[7]= {"model_check", "-d", "3", "-f", DEBUG_FILE_A1, "-i", CTL_FILE_A1}; |
---|
| 449 | // char *argvMC[8]= {"model_check", "-d", "3", "-f", "EX_C1/debug_trace", "-v", "2", "EX_C1/machine_concret.ctl"}; |
---|
| 450 | // char *argvMC[9]= {"model_check", "-d", "3", "-f", "EX_C1/debug_trace", "-i", "-v", "2", "EX_C1/machine_concret.ctl"}; |
---|
| 451 | |
---|
| 452 | model_checkExecA = model_checkMine (&hmgrA, argcMCA, argvMCA); |
---|
| 453 | (void) fprintf(vis_stderr, "*** 'model_check' of abstract model completed. *** \n"); |
---|
| 454 | |
---|
| 455 | |
---|
| 456 | (void) fprintf(vis_stderr,"\n========== END OF VIS ========= \n\n"); |
---|
| 457 | |
---|
| 458 | return 0; |
---|
| 459 | |
---|
| 460 | } |
---|
| 461 | |
---|
| 462 | |
---|
| 463 | /*---------------------------------------------------------------------------*/ |
---|
| 464 | /* Definition of static functions */ |
---|
| 465 | /*---------------------------------------------------------------------------*/ |
---|
| 466 | |
---|
| 467 | /**Function******************************************************************** |
---|
| 468 | |
---|
| 469 | Synopsis [] |
---|
| 470 | |
---|
| 471 | Description [Refer to 'Hrc_Manager_t * Io_BlifMvRead( FILE *fp, |
---|
| 472 | Hrc_Manager_t *hmgr, boolean isCanonical, boolean isIncremental, |
---|
| 473 | boolean isVerbose)' in ntkCmd.c] |
---|
| 474 | |
---|
| 475 | SideEffects [] |
---|
| 476 | |
---|
| 477 | SeeAlso [] |
---|
| 478 | |
---|
| 479 | ******************************************************************************/ |
---|
| 480 | |
---|
| 481 | static Hrc_Manager_t *read_blif_mvMine (FILE *fp, Hrc_Manager_t *hmgr, |
---|
| 482 | boolean isCanonical, boolean isIncremental, boolean isVerbose) |
---|
| 483 | { |
---|
| 484 | |
---|
| 485 | (void) fprintf(vis_stderr, "*** 'read_blif_mv' begins. *** \n"); |
---|
| 486 | |
---|
| 487 | Hrc_Node_t *root; |
---|
| 488 | static Hrc_Manager_t *newHmgr; |
---|
| 489 | |
---|
| 490 | if (isIncremental == 0){ |
---|
| 491 | newHmgr = Hrc_ManagerAlloc(); |
---|
| 492 | } |
---|
| 493 | else { /* isIncremental == 1 */ |
---|
| 494 | if (Hrc_ManagerReadCurrentNode(hmgr) == NIL(Hrc_Node_t)){ |
---|
| 495 | (void)fprintf(vis_stderr,"No hierarchy has been created. Cannot do inremental read-in.\n"); |
---|
| 496 | return NIL(Hrc_Manager_t); |
---|
| 497 | } |
---|
| 498 | newHmgr = hmgr; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | if (setjmp(env)){ |
---|
| 502 | if (isIncremental == 0){ |
---|
| 503 | Hrc_ManagerFree(newHmgr); |
---|
| 504 | } |
---|
| 505 | else { |
---|
| 506 | int i; |
---|
| 507 | /* free all the new models defined in an incremental file */ |
---|
| 508 | for (i=0; i < array_n(globalNewModelArray); i++){ |
---|
| 509 | Hrc_ModelDelete(hmgr,Hrc_ModelReadName(array_fetch(Hrc_Model_t *,globalNewModelArray,i))); |
---|
| 510 | } |
---|
| 511 | } |
---|
| 512 | _IoGlobalVariablesFree(); |
---|
| 513 | return NIL(Hrc_Manager_t); |
---|
| 514 | } |
---|
| 515 | else { |
---|
| 516 | _IoGlobalVariablesInitialize(); |
---|
| 517 | if (isIncremental == 0){ |
---|
| 518 | globalYaccHmgr = newHmgr; |
---|
| 519 | } |
---|
| 520 | else { |
---|
| 521 | globalYaccHmgr = hmgr; |
---|
| 522 | } |
---|
| 523 | #ifdef IODEBUG |
---|
| 524 | IoYydebug = 1; |
---|
| 525 | #endif /* IODEBUG */ |
---|
| 526 | IoYyin = fp; |
---|
| 527 | IoYyrestart(IoYyin); |
---|
| 528 | if (IoYyparse() == 1){ |
---|
| 529 | IoError(); |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | /* globalNewModelArray contains all the models defined in the previous |
---|
| 533 | IoYyparse(). If isIncremental==0, then they are simply all the models. |
---|
| 534 | If isIncremental==1, then they are new models defined in the file. */ |
---|
| 535 | |
---|
| 536 | if (IoNetworkTestConsistency(newHmgr,globalNewModelArray,globalParserSubcktInfo,globalParserResetInfo,isVerbose) == 0){ |
---|
| 537 | IoError(); |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | if (globalRootModel == NIL(Hrc_Model_t)){ |
---|
| 541 | globalRootModel = globalFirstModel; |
---|
| 542 | globalRootInstanceName = util_strsav(Hrc_ModelReadName(globalRootModel)); |
---|
| 543 | } |
---|
| 544 | else if (globalRootInstanceName == NIL(char)){ |
---|
| 545 | globalRootInstanceName = util_strsav(Hrc_ModelReadName(globalRootModel)); |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | if (isCanonical == 1){ |
---|
| 549 | _IoManagerCanonicalize(newHmgr); |
---|
| 550 | } |
---|
| 551 | |
---|
| 552 | root = Hrc_ModelCreateHierarchy(newHmgr,globalRootModel,globalRootInstanceName); |
---|
| 553 | FREE(globalRootInstanceName); |
---|
| 554 | |
---|
| 555 | if (isIncremental == 0){ |
---|
| 556 | Hrc_ManagerSetRootNode(newHmgr,root); |
---|
| 557 | Hrc_ManagerSetCurrentNode(newHmgr,root); |
---|
| 558 | _IoGlobalVariablesFree(); |
---|
| 559 | return newHmgr; |
---|
| 560 | } |
---|
| 561 | else { /* isIncremental == 1, note that newHmgr == hmgr */ |
---|
| 562 | if (_IoNodeTestCompatibility(hmgr,Hrc_ManagerReadCurrentNode(hmgr),root) == 0){ |
---|
| 563 | int i; |
---|
| 564 | (void)fprintf(vis_stderr,"The blif-mv file is not compatible with the existing hierarchy.\n"); |
---|
| 565 | Hrc_TreeReplace(NIL(Hrc_Node_t),root); |
---|
| 566 | /* free all the new models defined in an incremental file */ |
---|
| 567 | for (i=0; i < array_n(globalNewModelArray); i++){ |
---|
| 568 | Hrc_ModelDelete(hmgr,Hrc_ModelReadName(array_fetch(Hrc_Model_t *,globalNewModelArray,i))); |
---|
| 569 | } |
---|
| 570 | _IoGlobalVariablesFree(); |
---|
| 571 | return NIL(Hrc_Manager_t); |
---|
| 572 | } |
---|
| 573 | Hrc_TreeReplace(Hrc_ManagerReadCurrentNode(hmgr),root); |
---|
| 574 | Hrc_ManagerSetCurrentNode(hmgr,root); |
---|
| 575 | _IoGlobalVariablesFree(); |
---|
| 576 | return hmgr; |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | |
---|
| 584 | /**Function******************************************************************** |
---|
| 585 | |
---|
| 586 | Synopsis [] |
---|
| 587 | |
---|
| 588 | Description [Refer to 'static int CommandInitVerify(Hrc_Manager_t ** hmgr, |
---|
| 589 | int argc, char ** argv);' in ntkCmd.c] |
---|
| 590 | |
---|
| 591 | SideEffects [] |
---|
| 592 | |
---|
| 593 | SeeAlso [] |
---|
| 594 | |
---|
| 595 | ******************************************************************************/ |
---|
| 596 | static int init_verifyMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
| 597 | { |
---|
| 598 | |
---|
| 599 | (void) fprintf(vis_stderr, "*** 'init_verify' begins. *** \n"); |
---|
| 600 | |
---|
| 601 | int c; |
---|
| 602 | Hrc_Node_t *currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 603 | |
---|
| 604 | /* |
---|
| 605 | * Parse the command line. |
---|
| 606 | */ |
---|
| 607 | util_getopt_reset(); |
---|
| 608 | while ((c = util_getopt(argc, argv, "bh")) != EOF) { |
---|
| 609 | switch (c) { |
---|
| 610 | case 'b': |
---|
| 611 | break; |
---|
| 612 | case 'h': |
---|
| 613 | goto usage; |
---|
| 614 | default: |
---|
| 615 | goto usage; |
---|
| 616 | } |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | if (currentNode == NIL(Hrc_Node_t)) { |
---|
| 620 | (void) fprintf(vis_stdout, "The hierarchy manager is empty. Read in design.\n"); |
---|
| 621 | return 1; |
---|
| 622 | } |
---|
| 623 | |
---|
| 624 | |
---|
| 625 | // ++ add condition to test if the functions failed |
---|
| 626 | (void) fprintf(vis_stderr, "---- 'init_verify' : (1) "); |
---|
| 627 | // --- init_verify : (1) flatten_hierarchy --- |
---|
| 628 | int flatten_hierarchyExec; |
---|
| 629 | int argcFH = 1; |
---|
| 630 | char *argvFH[1]= {"flatten_hierarchy"}; |
---|
| 631 | flatten_hierarchyExec = flatten_hierarchyMine (hmgr, argcFH, argvFH); |
---|
| 632 | // flatten_hierarchyExec = flatten_hierarchyMine (&(*hmgr), argcFH, argvFH); |
---|
| 633 | (void) fprintf(vis_stderr, "---- 'init_verify' : (1) *** 'flatten_hierarchy' completed. *** \n"); |
---|
| 634 | |
---|
| 635 | // --- init_verify : (2) static_order --- |
---|
| 636 | (void) fprintf(vis_stderr, "---- 'init_verify' : (2) "); |
---|
| 637 | int static_orderExec; |
---|
| 638 | int argcSO = 1; |
---|
| 639 | char *argvSO[1]= {"static_order"}; |
---|
| 640 | static_orderExec = static_orderMine (hmgr, argcSO, argvSO); |
---|
| 641 | (void) fprintf(vis_stderr, "---- 'init_verify' : (2) *** 'static_order' completed. *** \n"); |
---|
| 642 | |
---|
| 643 | // --- init_verify : (3) build_partition_mdds --- |
---|
| 644 | (void) fprintf(vis_stderr, "---- 'init_verify' : (3) "); |
---|
| 645 | int build_part_mddsExec; |
---|
| 646 | int argcBPMDDS = 1; |
---|
| 647 | char *argvBPMDDS[1]= {"build_partition_mdds"}; |
---|
| 648 | build_part_mddsExec = build_partition_mddsMine (hmgr, argcBPMDDS, argvBPMDDS); |
---|
| 649 | (void) fprintf(vis_stderr, "---- 'init_verify' : (3) *** 'build_partition_mdds' completed. *** \n"); |
---|
| 650 | |
---|
| 651 | return 0; /* normal exit */ |
---|
| 652 | |
---|
| 653 | |
---|
| 654 | usage: |
---|
| 655 | (void) fprintf(vis_stderr, "usage: init_verify [-b] [-h]\n"); |
---|
| 656 | (void) fprintf(vis_stderr, " -b not used any longer.\n"); |
---|
| 657 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
| 658 | return 1; /* error exit */ |
---|
| 659 | |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | |
---|
| 663 | /**Function******************************************************************** |
---|
| 664 | |
---|
| 665 | Synopsis [] |
---|
| 666 | |
---|
| 667 | Description [Refer to 'static int CommandFlattenHierarchy(Hrc_Manager_t ** |
---|
| 668 | hmgr, int argc, char ** argv);' in ntkCmd.c] |
---|
| 669 | |
---|
| 670 | SideEffects [] |
---|
| 671 | |
---|
| 672 | SeeAlso [] |
---|
| 673 | |
---|
| 674 | ******************************************************************************/ |
---|
| 675 | static int flatten_hierarchyMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
| 676 | { |
---|
| 677 | |
---|
| 678 | (void) fprintf(vis_stderr, "*** 'flatten_hierarchy' begins. *** \n"); |
---|
| 679 | |
---|
| 680 | int c; |
---|
| 681 | Ntk_Network_t *network; |
---|
| 682 | char *fileName = NIL(char); |
---|
| 683 | int verbose = 0; /* default */ |
---|
| 684 | int sweep = 1; |
---|
| 685 | lsList varNameList = (lsList) NULL; |
---|
| 686 | Hrc_Node_t *currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 687 | |
---|
| 688 | /* |
---|
| 689 | * Parse the command line. |
---|
| 690 | */ |
---|
| 691 | util_getopt_reset(); |
---|
| 692 | while ((c = util_getopt(argc, argv, "a:bhsv:")) != EOF) { |
---|
| 693 | switch (c) { |
---|
| 694 | case 'a': |
---|
| 695 | fileName = util_optarg; |
---|
| 696 | break; |
---|
| 697 | case 'b': |
---|
| 698 | break; |
---|
| 699 | case 'h': |
---|
| 700 | goto usage; |
---|
| 701 | case 's': |
---|
| 702 | sweep = 0; |
---|
| 703 | break; |
---|
| 704 | case 'v': |
---|
| 705 | verbose = atoi(util_optarg); |
---|
| 706 | break; |
---|
| 707 | default: |
---|
| 708 | goto usage; |
---|
| 709 | } |
---|
| 710 | } |
---|
| 711 | |
---|
| 712 | if (currentNode == NIL(Hrc_Node_t)) { |
---|
| 713 | (void) fprintf(vis_stdout, "The hierarchy manager is empty. Read in design.\n"); |
---|
| 714 | return 1; |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | /* |
---|
| 718 | * Process the file containing the variable names. |
---|
| 719 | */ |
---|
| 720 | if (fileName != NIL(char)) { |
---|
| 721 | FILE *fp = Cmd_FileOpen(fileName, "r", NIL(char *), 0); |
---|
| 722 | if (fp == NIL(FILE)) { |
---|
| 723 | return 1; |
---|
| 724 | } |
---|
| 725 | else { |
---|
| 726 | boolean status; |
---|
| 727 | |
---|
| 728 | error_init(); |
---|
| 729 | status = FileReadNameList(fp, &varNameList, verbose); |
---|
| 730 | (void) fclose(fp); |
---|
| 731 | if (status == FALSE) { |
---|
| 732 | (void) fprintf(vis_stderr, "Error reading variable name file:\n"); |
---|
| 733 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
| 734 | (void) fprintf(vis_stderr, "Cannot perform flatten_hierarchy.\n"); |
---|
| 735 | return 1; |
---|
| 736 | } |
---|
| 737 | } |
---|
| 738 | } |
---|
| 739 | |
---|
| 740 | |
---|
| 741 | /* |
---|
| 742 | * If a network already exists, delete it. Then create the new one, and |
---|
| 743 | * register it with the hrcNode. |
---|
| 744 | */ |
---|
| 745 | network = (Ntk_Network_t *) Hrc_NodeReadApplInfo(currentNode, |
---|
| 746 | NTK_HRC_NODE_APPL_KEY); |
---|
| 747 | if (network != NIL(Ntk_Network_t)) { |
---|
| 748 | (void) fprintf(vis_stdout, "Deleting current network and creating new one.\n"); |
---|
| 749 | Hrc_NodeFreeApplInfo(currentNode, NTK_HRC_NODE_APPL_KEY); |
---|
| 750 | } |
---|
| 751 | |
---|
| 752 | error_init(); |
---|
| 753 | |
---|
| 754 | network = Ntk_HrcNodeConvertToNetwork(currentNode, TRUE, varNameList); |
---|
| 755 | |
---|
| 756 | /* Clean up the varNameList. */ |
---|
| 757 | if (varNameList != (lsList) NULL) { |
---|
| 758 | lsGen gen; |
---|
| 759 | char *varName; |
---|
| 760 | |
---|
| 761 | lsForEachItem(varNameList, gen, varName) { |
---|
| 762 | FREE(varName); |
---|
| 763 | } |
---|
| 764 | (void) lsDestroy(varNameList, (void (*) (lsGeneric)) NULL); |
---|
| 765 | } |
---|
| 766 | /* sweep network */ |
---|
| 767 | if (network != NIL(Ntk_Network_t) && sweep ==1) { |
---|
| 768 | Ntk_NetworkSweep(network, verbose); |
---|
| 769 | } |
---|
| 770 | |
---|
| 771 | if (network == NIL(Ntk_Network_t)) { |
---|
| 772 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
| 773 | (void) fprintf(vis_stderr, "Cannot perform flatten_hierarchy.\n"); |
---|
| 774 | return 1; |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | Hrc_NodeAddApplInfo(currentNode, NTK_HRC_NODE_APPL_KEY, |
---|
| 778 | (Hrc_ApplInfoFreeFn) Ntk_NetworkFreeCallback, |
---|
| 779 | (Hrc_ApplInfoChangeFn) NULL, /* not currently used by hrc */ |
---|
| 780 | (void *) network); |
---|
| 781 | |
---|
| 782 | return 0; /* normal exit */ |
---|
| 783 | |
---|
| 784 | usage: |
---|
| 785 | (void) fprintf(vis_stderr, "usage: flatten_hierarchy [-a file] [-b] [-h] [-s] [-v #]\n"); |
---|
| 786 | (void) fprintf(vis_stderr, " -a file variables to abstract\n"); |
---|
| 787 | (void) fprintf(vis_stderr, " -b not used any longer\n"); |
---|
| 788 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
| 789 | (void) fprintf(vis_stderr, " -s do not perform a sweep\n"); |
---|
| 790 | (void) fprintf(vis_stderr, " -v # verbosity level\n"); |
---|
| 791 | return 1; /* error exit */ |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | |
---|
| 795 | /**Function******************************************************************** |
---|
| 796 | |
---|
| 797 | Synopsis [] |
---|
| 798 | |
---|
| 799 | Description [Refer to 'static int CommandStaticOrder(Hrc_Manager_t ** hmgr, |
---|
| 800 | int argc, char ** argv);' in ordCmd.c] |
---|
| 801 | |
---|
| 802 | SideEffects [] |
---|
| 803 | |
---|
| 804 | SeeAlso [] |
---|
| 805 | |
---|
| 806 | ******************************************************************************/ |
---|
| 807 | static int static_orderMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
| 808 | { |
---|
| 809 | |
---|
| 810 | (void) fprintf(vis_stderr, "*** 'static_order' begins. *** \n"); |
---|
| 811 | |
---|
| 812 | int c; |
---|
| 813 | FILE *fp; |
---|
| 814 | static int timeOutPeriod; |
---|
| 815 | static int verbose; |
---|
| 816 | static Ord_NodeMethod nodeMethod; |
---|
| 817 | static Ord_RootMethod rootMethod; |
---|
| 818 | static Ord_OrderType suppliedOrderType; |
---|
| 819 | static Ord_OrderType generatedOrderType; |
---|
| 820 | static boolean nsAfterSupport; |
---|
| 821 | lsList suppliedNodeList = (lsList) NULL; |
---|
| 822 | /* list of Ntk_Node_t * */ |
---|
| 823 | Ntk_Network_t *network; |
---|
| 824 | |
---|
| 825 | /* |
---|
| 826 | * These are the default values. These variables must be declared static |
---|
| 827 | * to avoid lint warnings. Since they are static, we must reinitialize |
---|
| 828 | * them outside of the variable declarations. |
---|
| 829 | */ |
---|
| 830 | timeOutPeriod = 0; |
---|
| 831 | verbose = 0; |
---|
| 832 | nodeMethod = Ord_NodesByDefault_c; |
---|
| 833 | rootMethod = Ord_RootsByDefault_c; |
---|
| 834 | suppliedOrderType = Ord_Unassigned_c; /* default */ |
---|
| 835 | generatedOrderType = Ord_InputAndLatch_c;/* default */ |
---|
| 836 | nsAfterSupport = FALSE; /* default */ |
---|
| 837 | |
---|
| 838 | /* |
---|
| 839 | * Parse the command line. |
---|
| 840 | */ |
---|
| 841 | util_getopt_reset(); |
---|
| 842 | while ((c = util_getopt(argc, argv, "av:o:s:t:n:r:h")) != EOF) { |
---|
| 843 | switch (c) { |
---|
| 844 | case 'a': |
---|
| 845 | nsAfterSupport = TRUE; |
---|
| 846 | break; |
---|
| 847 | case 'h': |
---|
| 848 | goto usage; |
---|
| 849 | case 'v': |
---|
| 850 | verbose = atoi(util_optarg); |
---|
| 851 | break; |
---|
| 852 | case 't': |
---|
| 853 | timeOutPeriod = atoi(util_optarg); |
---|
| 854 | break; |
---|
| 855 | case 'o': |
---|
| 856 | generatedOrderType = StringConvertToOrderType(util_optarg); |
---|
| 857 | if ((generatedOrderType == Ord_NextStateNode_c) |
---|
| 858 | || (generatedOrderType == Ord_Partial_c)) { |
---|
| 859 | (void) fprintf(vis_stderr, "disallowed output order type: %s\n", util_optarg); |
---|
| 860 | goto usage; |
---|
| 861 | } |
---|
| 862 | else if (generatedOrderType == Ord_Unassigned_c) { |
---|
| 863 | (void) fprintf(vis_stderr, "unknown output order type: %s\n", util_optarg); |
---|
| 864 | goto usage; |
---|
| 865 | } |
---|
| 866 | break; |
---|
| 867 | case 's': |
---|
| 868 | suppliedOrderType = StringConvertToOrderType(util_optarg); |
---|
| 869 | if (suppliedOrderType == Ord_Unassigned_c) { |
---|
| 870 | (void) fprintf(vis_stderr, "unknown input order type: %s\n", util_optarg); |
---|
| 871 | goto usage; |
---|
| 872 | } |
---|
| 873 | break; |
---|
| 874 | case 'n': |
---|
| 875 | if (strcmp("interleave", util_optarg) == 0) { |
---|
| 876 | nodeMethod = Ord_NodesByInterleaving_c; |
---|
| 877 | } |
---|
| 878 | else if (strcmp("merge_left", util_optarg) == 0) { |
---|
| 879 | nodeMethod = Ord_NodesByMergingLeft_c; |
---|
| 880 | } |
---|
| 881 | else if (strcmp("merge_right", util_optarg) == 0) { |
---|
| 882 | nodeMethod = Ord_NodesByMergingRight_c; |
---|
| 883 | } |
---|
| 884 | else if (strcmp("append", util_optarg) == 0) { |
---|
| 885 | nodeMethod = Ord_NodesByAppending_c; |
---|
| 886 | } |
---|
| 887 | else { |
---|
| 888 | (void) fprintf(vis_stderr, "unknown node order method: %s\n", util_optarg); |
---|
| 889 | goto usage; |
---|
| 890 | } |
---|
| 891 | break; |
---|
| 892 | case 'r': |
---|
| 893 | if (strcmp("depth", util_optarg) == 0) { |
---|
| 894 | rootMethod = Ord_RootsByDepth_c; |
---|
| 895 | } |
---|
| 896 | else if (strcmp("mincomm", util_optarg) == 0) { |
---|
| 897 | rootMethod = Ord_RootsByPerm_c; |
---|
| 898 | } |
---|
| 899 | else { |
---|
| 900 | (void) fprintf(vis_stderr, "unknown root order method: %s\n", util_optarg); |
---|
| 901 | goto usage; |
---|
| 902 | } |
---|
| 903 | break; |
---|
| 904 | default: |
---|
| 905 | goto usage; |
---|
| 906 | } |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 910 | if (network == NIL(Ntk_Network_t)) { |
---|
| 911 | return 1; |
---|
| 912 | } |
---|
| 913 | |
---|
| 914 | if ((suppliedOrderType == Ord_InputAndLatch_c) && (generatedOrderType == Ord_All_c)) { |
---|
| 915 | (void) fprintf(vis_stderr, "-o all -s input_and_latch not currently supported\n"); |
---|
| 916 | return 1; |
---|
| 917 | } |
---|
| 918 | |
---|
| 919 | /* |
---|
| 920 | * The minimum set of variables that can be ordered are those specified by |
---|
| 921 | * Ord_InputAndLatch_c. If these have already been ordered, then just return. |
---|
| 922 | */ |
---|
| 923 | if (Ord_NetworkTestAreVariablesOrdered(network, Ord_InputAndLatch_c)) { |
---|
| 924 | (void) fprintf(vis_stderr, "Variables already ordered. "); |
---|
| 925 | (void) fprintf(vis_stderr, "Reinvoke flatten_hierarchy to undo variable ordering.\n"); |
---|
| 926 | return 1; |
---|
| 927 | } |
---|
| 928 | |
---|
| 929 | |
---|
| 930 | /* |
---|
| 931 | * Process the input ordering file. |
---|
| 932 | */ |
---|
| 933 | if (suppliedOrderType == Ord_Unassigned_c) { |
---|
| 934 | if (argc - util_optind > 0) { |
---|
| 935 | (void) fprintf(vis_stderr, "must specify -s if supplying order file\n"); |
---|
| 936 | goto usage; |
---|
| 937 | } |
---|
| 938 | } |
---|
| 939 | else { |
---|
| 940 | if (argc - util_optind == 0) { |
---|
| 941 | (void) fprintf(vis_stderr, "order file not provided\n"); |
---|
| 942 | goto usage; |
---|
| 943 | } |
---|
| 944 | else if (argc - util_optind > 1) { |
---|
| 945 | (void) fprintf(vis_stderr, "too many arguments\n"); |
---|
| 946 | goto usage; |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | fp = Cmd_FileOpen(argv[util_optind], "r", NIL(char *), 0); |
---|
| 950 | if (fp == NIL(FILE)) { |
---|
| 951 | (void) fprintf(vis_stderr, "File %s is not readable, please check if it exists\n", argv[util_optind]); |
---|
| 952 | return 1; |
---|
| 953 | } |
---|
| 954 | else { |
---|
| 955 | boolean status; |
---|
| 956 | |
---|
| 957 | error_init(); |
---|
| 958 | status = Ord_FileReadNodeList(fp, network, &suppliedNodeList, verbose); |
---|
| 959 | if (status == FALSE) { |
---|
| 960 | (void) fprintf(vis_stderr, "Error reading ordering file:\n"); |
---|
| 961 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
| 962 | (void) fprintf(vis_stderr, "Cannot perform static ordering.\n"); |
---|
| 963 | (void) fclose(fp); |
---|
| 964 | return 1; |
---|
| 965 | } |
---|
| 966 | else if (NetworkCheckSuppliedNodeList(network, suppliedNodeList, |
---|
| 967 | suppliedOrderType) == FALSE) { |
---|
| 968 | (void) fprintf(vis_stderr, "Incorrect nodes supplied:\n"); |
---|
| 969 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
| 970 | (void) fprintf(vis_stderr, "Cannot perform static ordering.\n"); |
---|
| 971 | (void) fclose(fp); |
---|
| 972 | (void) lsDestroy(suppliedNodeList, (void (*) (lsGeneric)) NULL); |
---|
| 973 | return 1; |
---|
| 974 | } |
---|
| 975 | else { |
---|
| 976 | (void) fclose(fp); |
---|
| 977 | if (verbose > 0) { |
---|
| 978 | (void) fprintf(vis_stdout, "\nNodes supplied in ordering file, "); |
---|
| 979 | (void) fprintf(vis_stdout, "according to -s option: \n"); |
---|
| 980 | OrdNodeListWrite(vis_stdout, suppliedNodeList); |
---|
| 981 | } |
---|
| 982 | } |
---|
| 983 | } |
---|
| 984 | } |
---|
| 985 | |
---|
| 986 | |
---|
| 987 | /* |
---|
| 988 | * In order for static ordering to proceed, network must not have any |
---|
| 989 | * combinational cycles. |
---|
| 990 | */ |
---|
| 991 | error_init(); |
---|
| 992 | if(Ntk_NetworkTestIsAcyclic(network) == 0) { |
---|
| 993 | (void) fprintf(vis_stderr, "Combinational cycle found: "); |
---|
| 994 | (void) fprintf(vis_stderr, "%s\n", error_string()); |
---|
| 995 | (void) fprintf(vis_stderr, "cannot perform static ordering\n"); |
---|
| 996 | if (suppliedOrderType != Ord_Unassigned_c) { |
---|
| 997 | (void) lsDestroy(suppliedNodeList, (void (*) (lsGeneric)) NULL); |
---|
| 998 | } |
---|
| 999 | return 1; |
---|
| 1000 | } |
---|
| 1001 | |
---|
| 1002 | /* Start the timer before calling the variable ordering routine. */ |
---|
| 1003 | if (timeOutPeriod > 0){ |
---|
| 1004 | (void) signal(SIGALRM, (void(*)(int))TimeOutHandle); |
---|
| 1005 | (void) alarm(timeOutPeriod); |
---|
| 1006 | if (setjmp(timeOutEnv) > 0) { |
---|
| 1007 | (void) fprintf(vis_stderr, "Timeout occurred after %d seconds.\n", timeOutPeriod); |
---|
| 1008 | alarm(0); |
---|
| 1009 | return 1; |
---|
| 1010 | } |
---|
| 1011 | } |
---|
| 1012 | |
---|
| 1013 | /* |
---|
| 1014 | * Order the variables. |
---|
| 1015 | */ |
---|
| 1016 | Ord_NetworkOrderVariables(network, rootMethod, nodeMethod, nsAfterSupport, |
---|
| 1017 | generatedOrderType, suppliedOrderType, |
---|
| 1018 | suppliedNodeList, verbose); |
---|
| 1019 | |
---|
| 1020 | if (suppliedOrderType != Ord_Unassigned_c) { |
---|
| 1021 | (void) lsDestroy(suppliedNodeList, (void (*) (lsGeneric)) NULL); |
---|
| 1022 | } |
---|
| 1023 | |
---|
| 1024 | /* |
---|
| 1025 | * As a sanity check, make sure that all the variables in generatedOrderType |
---|
| 1026 | * have an MDD id. |
---|
| 1027 | */ |
---|
| 1028 | assert(Ord_NetworkTestAreVariablesOrdered(network, generatedOrderType)); |
---|
| 1029 | |
---|
| 1030 | alarm(0); |
---|
| 1031 | return 0; /* Everything okay */ |
---|
| 1032 | |
---|
| 1033 | usage: |
---|
| 1034 | (void) fprintf(vis_stderr, "usage: static_order [-a] [-h] [-n method] [-o type] [-r method] -s type [-t time] [-v #] file\n"); |
---|
| 1035 | (void) fprintf(vis_stderr, " -a order NS variables after support\n"); |
---|
| 1036 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
| 1037 | (void) fprintf(vis_stderr, " -n method node ordering method\n"); |
---|
| 1038 | (void) fprintf(vis_stderr, " (interleave (default), append, merge_left, merge_right)\n"); |
---|
| 1039 | (void) fprintf(vis_stderr, " -o type nodes to order (all, input_and_latch (default))\n"); |
---|
| 1040 | (void) fprintf(vis_stderr, " -r method root ordering method (depth, mincomm (default for < 30 latches))\n"); |
---|
| 1041 | (void) fprintf(vis_stderr, " -s type nodes in file (all, input_and_latch, next_state_node, partial)\n"); |
---|
| 1042 | (void) fprintf(vis_stderr, " -t time time out period (in seconds)\n"); |
---|
| 1043 | (void) fprintf(vis_stderr, " -v # verbosity level\n"); |
---|
| 1044 | (void) fprintf(vis_stderr, " file supplied ordering of nodes\n"); |
---|
| 1045 | |
---|
| 1046 | return 1; |
---|
| 1047 | |
---|
| 1048 | } |
---|
| 1049 | |
---|
| 1050 | |
---|
| 1051 | /**Function******************************************************************** |
---|
| 1052 | |
---|
| 1053 | Synopsis [] |
---|
| 1054 | |
---|
| 1055 | Description [Refer to 'static int CommandBuildPartitionMdds(Hrc_Manager_t ** |
---|
| 1056 | hmgr, int argc, char ** argv);' in partCmd.c] |
---|
| 1057 | |
---|
| 1058 | SideEffects [] |
---|
| 1059 | |
---|
| 1060 | SeeAlso [] |
---|
| 1061 | |
---|
| 1062 | ******************************************************************************/ |
---|
| 1063 | static int build_partition_mddsMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
| 1064 | { |
---|
| 1065 | |
---|
| 1066 | (void) fprintf(vis_stderr, "*** 'build_partition_mdds' begins. *** \n"); |
---|
| 1067 | |
---|
| 1068 | static Part_PartitionMethod method; |
---|
| 1069 | static boolean inTermsOfLeaves; |
---|
| 1070 | lsList nodeList = lsCreate(); |
---|
| 1071 | graph_t *partition; |
---|
| 1072 | static int verbose; |
---|
| 1073 | static int sanityCheck; |
---|
| 1074 | static int timeOutPeriod; |
---|
| 1075 | int c; |
---|
| 1076 | int length; |
---|
| 1077 | char *methodString; |
---|
| 1078 | char *modelName; |
---|
| 1079 | Hrc_Node_t *currentNode; |
---|
| 1080 | Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 1081 | char *nodeName; |
---|
| 1082 | char *tmpNodeName; |
---|
| 1083 | char *realName; |
---|
| 1084 | FILE *nodeFile; |
---|
| 1085 | static boolean fileUsed; |
---|
| 1086 | |
---|
| 1087 | fileUsed = FALSE; |
---|
| 1088 | inTermsOfLeaves = FALSE; |
---|
| 1089 | verbose = 0; |
---|
| 1090 | sanityCheck = 0; |
---|
| 1091 | timeOutPeriod = 0; |
---|
| 1092 | |
---|
| 1093 | nodeFile = NIL(FILE); |
---|
| 1094 | util_getopt_reset(); |
---|
| 1095 | while ((c = util_getopt(argc, argv, "f:hvin:s:t:")) != EOF) { |
---|
| 1096 | switch(c) { |
---|
| 1097 | case 'f': |
---|
| 1098 | fileUsed = TRUE; |
---|
| 1099 | nodeFile = Cmd_FileOpen(util_optarg, "r", &realName, 1); |
---|
| 1100 | FREE(realName); |
---|
| 1101 | if (nodeFile == NIL(FILE)){ |
---|
| 1102 | (void)fprintf(vis_stderr,"Cannot open %s\n", util_optarg); |
---|
| 1103 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
| 1104 | return 1; |
---|
| 1105 | } |
---|
| 1106 | else{ |
---|
| 1107 | tmpNodeName = ALLOC(char, 512); |
---|
| 1108 | while(fscanf(nodeFile, "%s\n", tmpNodeName) != EOF){ |
---|
| 1109 | if(*tmpNodeName != '#'){ |
---|
| 1110 | nodeName = ALLOC(char, strlen(tmpNodeName) + 2); |
---|
| 1111 | sprintf(nodeName, "%s", tmpNodeName); |
---|
| 1112 | lsNewEnd(nodeList, (lsGeneric)nodeName, NIL(lsHandle)); |
---|
| 1113 | } |
---|
| 1114 | } |
---|
| 1115 | FREE(tmpNodeName); |
---|
| 1116 | } |
---|
| 1117 | break; |
---|
| 1118 | case 'h': |
---|
| 1119 | goto usage; |
---|
| 1120 | case 'i': |
---|
| 1121 | inTermsOfLeaves = TRUE; |
---|
| 1122 | break; |
---|
| 1123 | case 'v': |
---|
| 1124 | verbose = 1; |
---|
| 1125 | break; |
---|
| 1126 | case 's': |
---|
| 1127 | sanityCheck = atoi(util_optarg); |
---|
| 1128 | break; |
---|
| 1129 | case 't': |
---|
| 1130 | timeOutPeriod = atoi(util_optarg); |
---|
| 1131 | break; |
---|
| 1132 | case 'n': |
---|
| 1133 | length = strlen(util_optarg); |
---|
| 1134 | for(c = 0; c < length; c++) { |
---|
| 1135 | if (util_optarg[c] == ',') { |
---|
| 1136 | util_optarg[c] = 0; |
---|
| 1137 | } /* End of if */ |
---|
| 1138 | } /* End of for */ |
---|
| 1139 | c = 0; |
---|
| 1140 | while (c < length) { |
---|
| 1141 | lsNewEnd(nodeList, &util_optarg[c], NIL(lsHandle)); |
---|
| 1142 | while (util_optarg[c++] != 0); |
---|
| 1143 | } /* End of while */ |
---|
| 1144 | break; |
---|
| 1145 | default: |
---|
| 1146 | goto usage; |
---|
| 1147 | } |
---|
| 1148 | } |
---|
| 1149 | |
---|
| 1150 | if (argc == util_optind) { |
---|
| 1151 | /* No method specified. Choosing default */ |
---|
| 1152 | methodString = Cmd_FlagReadByName("partition_method"); |
---|
| 1153 | if (methodString == NIL(char)) { |
---|
| 1154 | methodString = "default"; |
---|
| 1155 | } |
---|
| 1156 | } |
---|
| 1157 | else { |
---|
| 1158 | methodString = argv[util_optind]; |
---|
| 1159 | } |
---|
| 1160 | |
---|
| 1161 | if (strcmp(methodString,"inout") == 0) { |
---|
| 1162 | method = Part_InOut_c; |
---|
| 1163 | if (lsLength(nodeList) != 0) { |
---|
| 1164 | (void) fprintf(vis_stderr, "Ignoring provided list of nodes in <inout>"); |
---|
| 1165 | (void) fprintf(vis_stderr, " method\n"); |
---|
| 1166 | } /* End of if */ |
---|
| 1167 | if (inTermsOfLeaves) { |
---|
| 1168 | (void) fprintf(vis_stderr, "Ignoring -i flag in the <inout> method\n"); |
---|
| 1169 | } /* End of if */ |
---|
| 1170 | } |
---|
| 1171 | else if (strcmp(methodString,"partial") == 0) { |
---|
| 1172 | method = Part_Partial_c; |
---|
| 1173 | /* Make sure a list of nodes has been provided */ |
---|
| 1174 | if (lsLength(nodeList) == 0) { |
---|
| 1175 | (void) fprintf(vis_stderr, "Method <partial> requires a non-empty list"); |
---|
| 1176 | (void) fprintf(vis_stderr, " of nodes\n"); |
---|
| 1177 | |
---|
| 1178 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
| 1179 | goto usage; |
---|
| 1180 | } /* End of if */ |
---|
| 1181 | } |
---|
| 1182 | else if (strcmp(methodString,"total") == 0) { |
---|
| 1183 | method = Part_Total_c; |
---|
| 1184 | if (lsLength(nodeList) != 0) { |
---|
| 1185 | (void) fprintf(vis_stderr, "Ignoring provided list of nodes in <total>"); |
---|
| 1186 | (void) fprintf(vis_stderr, " method\n"); |
---|
| 1187 | } /* End of if */ |
---|
| 1188 | } |
---|
| 1189 | else if (strcmp(methodString,"frontier") == 0) { |
---|
| 1190 | method = Part_Frontier_c; |
---|
| 1191 | } |
---|
| 1192 | else if (strcmp(methodString,"boundary") == 0) { |
---|
| 1193 | method = Part_Boundary_c; |
---|
| 1194 | } |
---|
| 1195 | else if (strcmp(methodString, "fine") == 0) { |
---|
| 1196 | method = Part_Fine_c; |
---|
| 1197 | } |
---|
| 1198 | else if (strcmp(methodString, "default") == 0) { |
---|
| 1199 | method = Part_Default_c; |
---|
| 1200 | } |
---|
| 1201 | else { |
---|
| 1202 | goto usage; |
---|
| 1203 | } |
---|
| 1204 | |
---|
| 1205 | |
---|
| 1206 | /* Check if the network has been read in */ |
---|
| 1207 | if (network == NIL(Ntk_Network_t)) { |
---|
| 1208 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
| 1209 | return 1; |
---|
| 1210 | } |
---|
| 1211 | |
---|
| 1212 | /* Check if the network has the variables ordered */ |
---|
| 1213 | if (Ord_NetworkTestAreVariablesOrdered(network, Ord_InputAndLatch_c) == |
---|
| 1214 | FALSE) { |
---|
| 1215 | (void) fprintf(vis_stdout, "The MDD variables have not been ordered. Use static_order.\n"); |
---|
| 1216 | |
---|
| 1217 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
| 1218 | return 1; |
---|
| 1219 | } |
---|
| 1220 | |
---|
| 1221 | /* Check if there is already a partition attached to the network */ |
---|
| 1222 | partition = (graph_t *) Ntk_NetworkReadApplInfo(network, |
---|
| 1223 | PART_NETWORK_APPL_KEY); |
---|
| 1224 | |
---|
| 1225 | /* If there is, just return. */ |
---|
| 1226 | if (partition != NIL(graph_t)) { |
---|
| 1227 | (void) fprintf(vis_stderr, "partition already built; reinvoke "); |
---|
| 1228 | (void) fprintf(vis_stderr, "flatten_hierarchy to remove the current partition\n"); |
---|
| 1229 | return 1; |
---|
| 1230 | } |
---|
| 1231 | |
---|
| 1232 | /* Read the name of the model to be passed to Part_NetworkCreatePartition */ |
---|
| 1233 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 1234 | modelName = Hrc_NodeReadModelName(currentNode); |
---|
| 1235 | |
---|
| 1236 | /* Set the timeout */ |
---|
| 1237 | if (timeOutPeriod > 0) { |
---|
| 1238 | (void) signal(SIGALRM, (void(*)(int))TimeOutHandle); |
---|
| 1239 | (void) alarm(timeOutPeriod); |
---|
| 1240 | if (setjmp(timeOutEnv) > 0) { |
---|
| 1241 | (void) fprintf(vis_stdout, "Partition: timeout occurred after "); |
---|
| 1242 | (void) fprintf(vis_stdout, "%d seconds\n", timeOutPeriod); |
---|
| 1243 | alarm(0); |
---|
| 1244 | |
---|
| 1245 | /* Partial clean up */ |
---|
| 1246 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
| 1247 | return 1; |
---|
| 1248 | } |
---|
| 1249 | } |
---|
| 1250 | |
---|
| 1251 | /* |
---|
| 1252 | * Execute the partition algorithm. The two nil pointers is to indicate |
---|
| 1253 | * that the graph must represent the complete network. |
---|
| 1254 | */ |
---|
| 1255 | partition = Part_NetworkCreatePartition(network, currentNode, modelName, (lsList)0, |
---|
| 1256 | (lsList)0, NIL(mdd_t), method, nodeList, |
---|
| 1257 | inTermsOfLeaves, verbose, |
---|
| 1258 | sanityCheck); |
---|
| 1259 | |
---|
| 1260 | /* Register the partition in the network if any */ |
---|
| 1261 | Ntk_NetworkAddApplInfo(network, PART_NETWORK_APPL_KEY, |
---|
| 1262 | (Ntk_ApplInfoFreeFn) Part_PartitionFreeCallback, |
---|
| 1263 | (void *) partition); |
---|
| 1264 | |
---|
| 1265 | /* Deactivate the alarm */ |
---|
| 1266 | alarm(0); |
---|
| 1267 | |
---|
| 1268 | /* Clean up */ |
---|
| 1269 | if(fileUsed){ |
---|
| 1270 | lsDestroy(nodeList, PartNameFree); |
---|
| 1271 | } |
---|
| 1272 | else{ |
---|
| 1273 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
| 1274 | } |
---|
| 1275 | return 0; |
---|
| 1276 | |
---|
| 1277 | usage: |
---|
| 1278 | (void) fprintf(vis_stderr, "usage: build_partition_mdds [options] [method]\n"); |
---|
| 1279 | (void) fprintf(vis_stderr, "Options:\n"); |
---|
| 1280 | (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); |
---|
| 1281 | (void) fprintf(vis_stderr, " -i\t\tBuild the functions in the partition in terms of the\n"); |
---|
| 1282 | (void) fprintf(vis_stderr, " \t\tcombinational inputs of the system. This option is redundant if\n"); |
---|
| 1283 | (void) fprintf(vis_stderr, " \t\tthe inout partition is chosen.\n"); |
---|
| 1284 | (void) fprintf(vis_stderr, " -n <list>\tComma separated list of network nodes to preserve in the\n"); |
---|
| 1285 | (void) fprintf(vis_stderr, " \tpartitioning. It only matters if the partial method has been\n"); |
---|
| 1286 | (void) fprintf(vis_stderr, " \tselected.\n"); |
---|
| 1287 | (void) fprintf(vis_stderr, " -f <file>\tSpecifies the file containing names of network nodes\n"); |
---|
| 1288 | (void) fprintf(vis_stderr, " \tto preserve while partitioning. This option matters only \n"); |
---|
| 1289 | (void) fprintf(vis_stderr, " \tif the partial method has been selected. Each node name must\n"); |
---|
| 1290 | (void) fprintf(vis_stderr, " \tbe listed on a new line. Comments in <file> must begin with '#'.\n"); |
---|
| 1291 | (void) fprintf(vis_stderr, " -s <num>\tLevel of severity check applied after computation. 0 being no\n"); |
---|
| 1292 | (void) fprintf(vis_stderr, " \t\tcheck, 1 begin simple check and >1 being exhaustive check.\n"); |
---|
| 1293 | (void) fprintf(vis_stderr, " -t <sec>\tTime in seconds allowed to build the partition. If the\n"); |
---|
| 1294 | (void) fprintf(vis_stderr, " \tcomputation time goes above that limit, the process of building\n"); |
---|
| 1295 | (void) fprintf(vis_stderr, " \tthe partition is aborted.\n"); |
---|
| 1296 | (void) fprintf(vis_stderr, " -v\t\tverbose\n"); |
---|
| 1297 | (void) fprintf(vis_stderr, "Methods\n"); |
---|
| 1298 | (void) fprintf(vis_stderr, " inout\tIt represents the network with one MDD for\n"); |
---|
| 1299 | (void) fprintf(vis_stderr, " \teach combinational output as a function of the combinational\n"); |
---|
| 1300 | (void) fprintf(vis_stderr, " \tinputs\n"); |
---|
| 1301 | (void) fprintf(vis_stderr, " total\tPartitions the network preserving its structure. Every node in\n"); |
---|
| 1302 | (void) fprintf(vis_stderr, " \tthe network will produce a vertex in the partition graph. The\n"); |
---|
| 1303 | (void) fprintf(vis_stderr, " \tflag -i explained above controls the support of\n"); |
---|
| 1304 | (void) fprintf(vis_stderr, " \tthe functions attached to the vertices.\n"); |
---|
| 1305 | (void) fprintf(vis_stderr, " frontier\tThe default method. Partitions the network creating vertices for intermediate nodes\n"); |
---|
| 1306 | (void) fprintf(vis_stderr, " \tas necessary to control the BDD size. The threshold value of the\n"); |
---|
| 1307 | (void) fprintf(vis_stderr, " \tBDD can be specified by partition_threshold.\n"); |
---|
| 1308 | (void) fprintf(vis_stderr, " partial\tPartitions the network preserving certain nodes specified with\n"); |
---|
| 1309 | (void) fprintf(vis_stderr, " \tthe option -n or -f.\n"); |
---|
| 1310 | (void) fprintf(vis_stderr, " boundary\tPartitions the network preserving all nodes that are \n"); |
---|
| 1311 | (void) fprintf(vis_stderr, " \tsubcircuit IOs.\n"); |
---|
| 1312 | |
---|
| 1313 | lsDestroy(nodeList, (void (*)(lsGeneric))0); |
---|
| 1314 | |
---|
| 1315 | return 1; /* Error exit */ |
---|
| 1316 | } /* End of CommandBuildPartitionMdds */ |
---|
| 1317 | |
---|
| 1318 | |
---|
| 1319 | /**Function******************************************************************** |
---|
| 1320 | |
---|
| 1321 | Synopsis [] |
---|
| 1322 | |
---|
| 1323 | Description [Refer to 'static int CommandBuildPartitionMAigs(Hrc_Manager_t |
---|
| 1324 | ** hmgr, int argc, char ** argv);' in ntmaigCmd.c] |
---|
| 1325 | |
---|
| 1326 | SideEffects [] |
---|
| 1327 | |
---|
| 1328 | SeeAlso [] |
---|
| 1329 | |
---|
| 1330 | ******************************************************************************/ |
---|
| 1331 | static int build_partition_maigsMine(Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
| 1332 | { |
---|
| 1333 | |
---|
| 1334 | (void) fprintf(vis_stderr, "*** 'build_partition_maigs' begins. *** \n"); |
---|
| 1335 | |
---|
| 1336 | Ntk_Node_t *node, *latch; |
---|
| 1337 | lsGen gen; |
---|
| 1338 | array_t *result; /* array of MvfAig_Function_t* */ |
---|
| 1339 | array_t *roots; |
---|
| 1340 | st_table *leaves; |
---|
| 1341 | array_t *inputs; |
---|
| 1342 | Ntk_Network_t *network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 1343 | mAig_Manager_t *manager; |
---|
| 1344 | MvfAig_Function_t *mvfAig; |
---|
| 1345 | st_table *nodeToMvfAigTable; /* mapes each node with its mvfAig */ |
---|
| 1346 | int c, sweepFlag, DFSFlag; |
---|
| 1347 | int i; |
---|
| 1348 | |
---|
| 1349 | sweepFlag = 1; |
---|
| 1350 | DFSFlag = 0; |
---|
| 1351 | util_getopt_reset(); |
---|
| 1352 | while ((c = util_getopt(argc,argv,"sdnh")) != EOF){ |
---|
| 1353 | switch(c){ |
---|
| 1354 | case 's': |
---|
| 1355 | sweepFlag = 1; |
---|
| 1356 | break; |
---|
| 1357 | case 'd': |
---|
| 1358 | DFSFlag = 1; |
---|
| 1359 | break; |
---|
| 1360 | case 'n': |
---|
| 1361 | sweepFlag = 0; |
---|
| 1362 | break; |
---|
| 1363 | case 'h': |
---|
| 1364 | goto usage; |
---|
| 1365 | default: |
---|
| 1366 | goto usage; |
---|
| 1367 | } |
---|
| 1368 | } |
---|
| 1369 | if (network == NIL(Ntk_Network_t)) { |
---|
| 1370 | return 1; |
---|
| 1371 | } |
---|
| 1372 | |
---|
| 1373 | manager = Ntk_NetworkReadMAigManager(network); |
---|
| 1374 | |
---|
| 1375 | if (manager == NIL(mAig_Manager_t)) { |
---|
| 1376 | manager = mAig_initAig(); |
---|
| 1377 | Ntk_NetworkSetMAigManager(network, manager); |
---|
| 1378 | /* |
---|
| 1379 | mAig_mAigSetNetwork(manager, network); |
---|
| 1380 | */ |
---|
| 1381 | } |
---|
| 1382 | |
---|
| 1383 | /* Check if there is already a MvfAigs Table attached to the network */ |
---|
| 1384 | nodeToMvfAigTable = (st_table *) Ntk_NetworkReadApplInfo(network, |
---|
| 1385 | MVFAIG_NETWORK_APPL_KEY); |
---|
| 1386 | |
---|
| 1387 | if (nodeToMvfAigTable != NIL(st_table)){ |
---|
| 1388 | /* |
---|
| 1389 | st_foreach_item(nodeToMvfAigTable, stGen, (char **) &node, (char **) &MvfAig) { |
---|
| 1390 | printf("\nNode name = %s :",Ntk_NodeReadName(node)); |
---|
| 1391 | for (j=0; j< array_n(MvfAig); j++){ |
---|
| 1392 | printf(" %d ",array_fetch(bAigEdge_t, (array_t *) MvfAig, j)); |
---|
| 1393 | } |
---|
| 1394 | } |
---|
| 1395 | */ |
---|
| 1396 | (void) fprintf(vis_stderr, "maig partition already built; reinvoke\n"); |
---|
| 1397 | (void) fprintf(vis_stderr, "flatten_hierarchy to remove the current maig partition\n"); |
---|
| 1398 | return 1; |
---|
| 1399 | } |
---|
| 1400 | |
---|
| 1401 | roots = array_alloc(Ntk_Node_t *, 0); |
---|
| 1402 | Ntk_NetworkForEachCombOutput(network, gen, node) { |
---|
| 1403 | array_insert_last(Ntk_Node_t *, roots, node); |
---|
| 1404 | } |
---|
| 1405 | Ntk_NetworkForEachNode(network, gen, node) { |
---|
| 1406 | if(Ntk_NodeTestIsShadow(node)) continue; |
---|
| 1407 | if(Ntk_NodeTestIsCombInput(node)) continue; |
---|
| 1408 | if(Ntk_NodeTestIsCombOutput(node))continue; |
---|
| 1409 | |
---|
| 1410 | if(Ntk_NodeReadNumFanouts(node) == 0 && Ntk_NodeReadNumFanins(node)) { |
---|
| 1411 | /** |
---|
| 1412 | fprintf(vis_stdout, "WARNING : dangling node %s\n", Ntk_NodeReadName(node)); |
---|
| 1413 | **/ |
---|
| 1414 | array_insert_last(Ntk_Node_t *, roots, node); |
---|
| 1415 | } |
---|
| 1416 | } |
---|
| 1417 | |
---|
| 1418 | leaves = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 1419 | |
---|
| 1420 | inputs = array_alloc(Ntk_Node_t *, 16); |
---|
| 1421 | Ntk_NetworkForEachCombInput(network, gen, node) { |
---|
| 1422 | array_insert_last(Ntk_Node_t *, inputs, node); |
---|
| 1423 | } |
---|
| 1424 | array_sort(inputs, nodenameCompare); |
---|
| 1425 | for(i=0; i<array_n(inputs); i++) { |
---|
| 1426 | node = array_fetch(Ntk_Node_t *, inputs, i); |
---|
| 1427 | st_insert(leaves, node, (char *) ntmaig_UNUSED); |
---|
| 1428 | Ntk_NodeSetMAigId(node, |
---|
| 1429 | mAig_CreateVar(manager, |
---|
| 1430 | Ntk_NodeReadName(node), |
---|
| 1431 | Var_VariableReadNumValues(Ntk_NodeReadVariable(node)))); |
---|
| 1432 | } |
---|
| 1433 | |
---|
| 1434 | if(DFSFlag == 0) |
---|
| 1435 | bAig_BuildAigBFSManner(network, manager, leaves, sweepFlag); |
---|
| 1436 | |
---|
| 1437 | result = ntmaig_NetworkBuildMvfAigs(network, roots, leaves); |
---|
| 1438 | |
---|
| 1439 | nodeToMvfAigTable = (st_table *) Ntk_NetworkReadApplInfo(network, |
---|
| 1440 | MVFAIG_NETWORK_APPL_KEY); |
---|
| 1441 | Ntk_NetworkForEachLatch(network, gen, latch) { |
---|
| 1442 | node = Ntk_LatchReadDataInput(latch); |
---|
| 1443 | st_lookup(nodeToMvfAigTable, node, &mvfAig); |
---|
| 1444 | Ntk_NodeSetMAigId(node, |
---|
| 1445 | mAig_CreateVarFromAig(manager, Ntk_NodeReadName(node), mvfAig)); |
---|
| 1446 | node = Ntk_LatchReadInitialInput(latch); |
---|
| 1447 | st_lookup(nodeToMvfAigTable, node, &mvfAig); |
---|
| 1448 | Ntk_NodeSetMAigId(node, |
---|
| 1449 | mAig_CreateVarFromAig(manager, Ntk_NodeReadName(node), mvfAig)); |
---|
| 1450 | } |
---|
| 1451 | |
---|
| 1452 | roots->num = 0; |
---|
| 1453 | Ntk_NetworkForEachLatch(network, gen, latch) { |
---|
| 1454 | if(!st_lookup(nodeToMvfAigTable, latch, &mvfAig)) |
---|
| 1455 | array_insert_last(Ntk_Node_t *, roots, latch); |
---|
| 1456 | } |
---|
| 1457 | result = ntmaig_NetworkBuildMvfAigs(network, roots, leaves); |
---|
| 1458 | |
---|
| 1459 | array_free(roots); |
---|
| 1460 | array_free(inputs); |
---|
| 1461 | st_free_table(leaves); |
---|
| 1462 | |
---|
| 1463 | /* |
---|
| 1464 | * Free the array of MvfAigs. |
---|
| 1465 | */ |
---|
| 1466 | MvfAig_FunctionArrayFree(result); |
---|
| 1467 | |
---|
| 1468 | if(sweepFlag) |
---|
| 1469 | bAig_BddSweepMain(network, 0); |
---|
| 1470 | |
---|
| 1471 | return 0; |
---|
| 1472 | |
---|
| 1473 | usage: |
---|
| 1474 | (void) fprintf(vis_stderr, "usage: build_partition_maig [-h]\n"); |
---|
| 1475 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
| 1476 | (void) fprintf(vis_stderr, " -n disable bdd sweeping\n"); |
---|
| 1477 | (void) fprintf(vis_stderr, " -d build AIG DFS manner\n"); |
---|
| 1478 | return 1; /* error exit */ |
---|
| 1479 | |
---|
| 1480 | } |
---|
| 1481 | |
---|
| 1482 | /**Function******************************************************************** |
---|
| 1483 | |
---|
| 1484 | Synopsis [] |
---|
| 1485 | |
---|
| 1486 | Description [Refer to 'static int CommandReadFairness(Hrc_Manager_t ** hmgr, |
---|
| 1487 | int argc, char ** argv)' in fsmCmd.c] |
---|
| 1488 | |
---|
| 1489 | SideEffects [] |
---|
| 1490 | |
---|
| 1491 | SeeAlso [] |
---|
| 1492 | |
---|
| 1493 | ******************************************************************************/ |
---|
| 1494 | |
---|
| 1495 | static int read_fairnessMine (Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
| 1496 | { |
---|
| 1497 | |
---|
| 1498 | (void) fprintf(vis_stderr, "*** 'read_fairness' begins. *** \n"); |
---|
| 1499 | |
---|
| 1500 | int c; |
---|
| 1501 | FILE *fp; |
---|
| 1502 | array_t *formulaArray; |
---|
| 1503 | Fsm_Fsm_t *fsm = Fsm_HrcManagerReadCurrentFsm(*hmgr); |
---|
| 1504 | |
---|
| 1505 | /* |
---|
| 1506 | * Parse command line options. |
---|
| 1507 | */ |
---|
| 1508 | util_getopt_reset(); |
---|
| 1509 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
| 1510 | switch(c) { |
---|
| 1511 | case 'h': |
---|
| 1512 | goto usage; |
---|
| 1513 | default: |
---|
| 1514 | goto usage; |
---|
| 1515 | } |
---|
| 1516 | /* NOT REACHED */ |
---|
| 1517 | } |
---|
| 1518 | |
---|
| 1519 | if (fsm == NIL(Fsm_Fsm_t)) { |
---|
| 1520 | (void) fprintf(vis_stderr, "** fair error: Fairness constraint not recorded.\n"); |
---|
| 1521 | return 1; |
---|
| 1522 | } |
---|
| 1523 | |
---|
| 1524 | /* |
---|
| 1525 | * Open the fairness file. |
---|
| 1526 | */ |
---|
| 1527 | if (argc - util_optind == 0) { |
---|
| 1528 | (void) fprintf(vis_stderr, "** fair error: fairness file not provided\n"); |
---|
| 1529 | goto usage; |
---|
| 1530 | } |
---|
| 1531 | else if (argc - util_optind > 1) { |
---|
| 1532 | (void) fprintf(vis_stderr, "** fair error: too many arguments\n"); |
---|
| 1533 | goto usage; |
---|
| 1534 | } |
---|
| 1535 | |
---|
| 1536 | fp = Cmd_FileOpen(argv[util_optind], "r", NIL(char *), 0); |
---|
| 1537 | if (fp == NIL(FILE)) { |
---|
| 1538 | return 1; |
---|
| 1539 | } |
---|
| 1540 | |
---|
| 1541 | /* |
---|
| 1542 | * Parse the formulas in the file. |
---|
| 1543 | */ |
---|
| 1544 | formulaArray = Ctlp_FileParseFormulaArray(fp); |
---|
| 1545 | (void) fclose(fp); |
---|
| 1546 | |
---|
| 1547 | if (formulaArray == NIL(array_t)) { |
---|
| 1548 | (void) fprintf(vis_stderr, "** fair error: error reading fairness conditions.\n"); |
---|
| 1549 | return 1; |
---|
| 1550 | } |
---|
| 1551 | else if (array_n(formulaArray) == 0) { |
---|
| 1552 | (void) fprintf(vis_stderr, "** fair error: fairness file is empty.\n"); |
---|
| 1553 | (void) fprintf(vis_stderr, "** fair error: Use reset_fairness to reset the fairness constraint."); |
---|
| 1554 | return 1; |
---|
| 1555 | } |
---|
| 1556 | else { |
---|
| 1557 | int j; |
---|
| 1558 | Fsm_Fairness_t *fairness; |
---|
| 1559 | Ntk_Network_t *network = Fsm_FsmReadNetwork(fsm); |
---|
| 1560 | |
---|
| 1561 | /* |
---|
| 1562 | * First check that each formula is semantically correct wrt the network. |
---|
| 1563 | */ |
---|
| 1564 | error_init(); |
---|
| 1565 | for (j = 0; j < array_n(formulaArray); j++) { |
---|
| 1566 | Ctlp_Formula_t *formula; |
---|
| 1567 | boolean status; |
---|
| 1568 | |
---|
| 1569 | formula = array_fetch(Ctlp_Formula_t *, formulaArray, j); |
---|
| 1570 | status = Mc_FormulaStaticSemanticCheckOnNetwork(formula, network, FALSE); |
---|
| 1571 | |
---|
| 1572 | if (status == FALSE) { |
---|
| 1573 | (void) fprintf(vis_stderr, |
---|
| 1574 | "** fair error: error reading fairness constraint "); |
---|
| 1575 | Ctlp_FormulaPrint(vis_stderr, formula); |
---|
| 1576 | (void) fprintf(vis_stderr, ":\n"); |
---|
| 1577 | (void) fprintf(vis_stderr, "%s", error_string()); |
---|
| 1578 | (void) fprintf(vis_stderr, "\n"); |
---|
| 1579 | return 1; |
---|
| 1580 | } |
---|
| 1581 | } |
---|
| 1582 | |
---|
| 1583 | |
---|
| 1584 | /* |
---|
| 1585 | * Interpret the array of CTL formulas as a set of Buchi conditions. |
---|
| 1586 | * Hence, create a single disjunct, consisting of k conjuncts, where k is |
---|
| 1587 | * the number of CTL formulas read in. The jth conjunct has the jth |
---|
| 1588 | * formula as its finallyInf component, and NULL as its globallyInf |
---|
| 1589 | * component. |
---|
| 1590 | */ |
---|
| 1591 | fairness = FsmFairnessAlloc(fsm); |
---|
| 1592 | for (j = 0; j < array_n(formulaArray); j++) { |
---|
| 1593 | Ctlp_Formula_t *formula = array_fetch(Ctlp_Formula_t *, formulaArray, j); |
---|
| 1594 | |
---|
| 1595 | FsmFairnessAddConjunct(fairness, formula, NIL(Ctlp_Formula_t), 0, j); |
---|
| 1596 | } |
---|
| 1597 | array_free(formulaArray); /* Don't free the formulas themselves. */ |
---|
| 1598 | |
---|
| 1599 | /* |
---|
| 1600 | * Remove any existing fairnessInfo associated with the FSM, and update |
---|
| 1601 | * the fairnessInfo.constraint with the new fairness just read. |
---|
| 1602 | */ |
---|
| 1603 | FsmFsmFairnessInfoUpdate(fsm, NIL(mdd_t), fairness, NIL(array_t)); |
---|
| 1604 | |
---|
| 1605 | return 0; |
---|
| 1606 | } |
---|
| 1607 | |
---|
| 1608 | usage: |
---|
| 1609 | (void) fprintf(vis_stderr, "usage: read_fairness [-h] file\n"); |
---|
| 1610 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
| 1611 | (void) fprintf(vis_stderr, " file file containing the list of conditions\n"); |
---|
| 1612 | return 1; |
---|
| 1613 | |
---|
| 1614 | } |
---|
| 1615 | |
---|
| 1616 | /**Function******************************************************************** |
---|
| 1617 | |
---|
| 1618 | Synopsis [] |
---|
| 1619 | |
---|
| 1620 | Description [Refer to 'static int CommandPrintFairness(Hrc_Manager_t ** hmgr, |
---|
| 1621 | int argc, char ** argv)' in fsmCmd.c] |
---|
| 1622 | |
---|
| 1623 | SideEffects [] |
---|
| 1624 | |
---|
| 1625 | SeeAlso [] |
---|
| 1626 | |
---|
| 1627 | ******************************************************************************/ |
---|
| 1628 | |
---|
| 1629 | static int print_fairnessMine(Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
| 1630 | { |
---|
| 1631 | |
---|
| 1632 | (void) fprintf(vis_stderr, "*** 'print_fairness' begins. *** \n"); |
---|
| 1633 | |
---|
| 1634 | int c; |
---|
| 1635 | Fsm_Fairness_t *constraint; |
---|
| 1636 | int numDisjuncts; |
---|
| 1637 | Fsm_Fsm_t *fsm = Fsm_HrcManagerReadCurrentFsm(*hmgr); |
---|
| 1638 | |
---|
| 1639 | /* |
---|
| 1640 | * Parse command line options. |
---|
| 1641 | */ |
---|
| 1642 | util_getopt_reset(); |
---|
| 1643 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
| 1644 | switch(c) { |
---|
| 1645 | case 'h': |
---|
| 1646 | goto usage; |
---|
| 1647 | default: |
---|
| 1648 | goto usage; |
---|
| 1649 | } |
---|
| 1650 | /* NOT REACHED */ |
---|
| 1651 | } |
---|
| 1652 | |
---|
| 1653 | if (fsm == NIL(Fsm_Fsm_t)) { |
---|
| 1654 | return 1; |
---|
| 1655 | } |
---|
| 1656 | |
---|
| 1657 | /* |
---|
| 1658 | * Print the fairness constraint. It is assumed that there is at least one |
---|
| 1659 | * disjunct present. Currently, only Buchi constraints can be printed out. |
---|
| 1660 | */ |
---|
| 1661 | constraint = Fsm_FsmReadFairnessConstraint(fsm); |
---|
| 1662 | assert(constraint != NIL(Fsm_Fairness_t)); |
---|
| 1663 | numDisjuncts = Fsm_FairnessReadNumDisjuncts(constraint); |
---|
| 1664 | assert(numDisjuncts != 0); |
---|
| 1665 | |
---|
| 1666 | if (numDisjuncts > 1) { |
---|
| 1667 | (void) fprintf(vis_stdout, "Fairness constraint not Buchi..."); |
---|
| 1668 | (void) fprintf(vis_stdout, "don't know how to print.\n"); |
---|
| 1669 | } |
---|
| 1670 | else { |
---|
| 1671 | int i; |
---|
| 1672 | int numConjuncts = Fsm_FairnessReadNumConjunctsOfDisjunct(constraint, 0); |
---|
| 1673 | |
---|
| 1674 | (void) fprintf(vis_stdout, "Fairness constraint:\n"); |
---|
| 1675 | for (i = 0; i < numConjuncts; i++) { |
---|
| 1676 | if (Fsm_FairnessReadGloballyInfFormula(constraint, 0, i) != |
---|
| 1677 | NIL(Ctlp_Formula_t)) { |
---|
| 1678 | (void) fprintf(vis_stdout, "Fairness constraint not Buchi..."); |
---|
| 1679 | (void) fprintf(vis_stdout, "don't know how to print.\n"); |
---|
| 1680 | } |
---|
| 1681 | |
---|
| 1682 | Ctlp_FormulaPrint(vis_stdout, |
---|
| 1683 | Fsm_FairnessReadFinallyInfFormula(constraint, 0, i)); |
---|
| 1684 | (void) fprintf(vis_stdout, ";\n"); |
---|
| 1685 | } |
---|
| 1686 | } |
---|
| 1687 | |
---|
| 1688 | return 0; |
---|
| 1689 | |
---|
| 1690 | usage: |
---|
| 1691 | (void) fprintf(vis_stderr, "usage: print_fairness [-h]\n"); |
---|
| 1692 | (void) fprintf(vis_stderr, " -h print the command usage\n"); |
---|
| 1693 | return 1; |
---|
| 1694 | |
---|
| 1695 | } |
---|
| 1696 | |
---|
| 1697 | |
---|
| 1698 | /**Function******************************************************************** |
---|
| 1699 | |
---|
| 1700 | Synopsis [] |
---|
| 1701 | |
---|
| 1702 | Description [Refer to 'static int CommandPrintIo(Hrc_Manager_t **hmgr, int |
---|
| 1703 | argc, char **argv);' in hrcCmd.c] |
---|
| 1704 | |
---|
| 1705 | SideEffects [] |
---|
| 1706 | |
---|
| 1707 | SeeAlso [] |
---|
| 1708 | |
---|
| 1709 | ******************************************************************************/ |
---|
| 1710 | |
---|
| 1711 | static int print_ioMine (Hrc_Manager_t **hmgr, int argc, char **argv) |
---|
| 1712 | { |
---|
| 1713 | |
---|
| 1714 | (void) fprintf(vis_stderr, "*** 'print_io' begins. *** \n"); |
---|
| 1715 | |
---|
| 1716 | int c, i; |
---|
| 1717 | Hrc_Node_t *node; |
---|
| 1718 | Var_Variable_t *var; |
---|
| 1719 | array_t *tmpArray; |
---|
| 1720 | |
---|
| 1721 | util_getopt_reset(); |
---|
| 1722 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
| 1723 | switch(c){ |
---|
| 1724 | case 'h': |
---|
| 1725 | goto usage; |
---|
| 1726 | default: |
---|
| 1727 | goto usage; |
---|
| 1728 | } |
---|
| 1729 | } |
---|
| 1730 | /* if there are some arguments left */ |
---|
| 1731 | if (argc != util_optind){ |
---|
| 1732 | goto usage; |
---|
| 1733 | } |
---|
| 1734 | node = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 1735 | if (node == NIL(Hrc_Node_t)){ |
---|
| 1736 | (void)fprintf(vis_stderr,"No file has been read in.\n"); |
---|
| 1737 | return 1; |
---|
| 1738 | } |
---|
| 1739 | |
---|
| 1740 | if (Hrc_NodeReadNumFormalInputs(node) == 0){ |
---|
| 1741 | fprintf(vis_stdout,"No inputs\n"); |
---|
| 1742 | } |
---|
| 1743 | else { |
---|
| 1744 | tmpArray = array_alloc(char *,0); |
---|
| 1745 | Hrc_NodeForEachFormalInput(node,i,var){ |
---|
| 1746 | array_insert_last(char *,tmpArray,Var_VariableReadName(var)); |
---|
| 1747 | } |
---|
| 1748 | array_sort(tmpArray,_HrcStringCmp); |
---|
| 1749 | fprintf(vis_stdout,"inputs:"); |
---|
| 1750 | for (i=0; i < array_n(tmpArray); i++){ |
---|
| 1751 | fprintf(vis_stdout," %s",array_fetch(char *,tmpArray,i)); |
---|
| 1752 | } |
---|
| 1753 | fprintf(vis_stdout,"\n"); |
---|
| 1754 | array_free(tmpArray); |
---|
| 1755 | } |
---|
| 1756 | |
---|
| 1757 | if (Hrc_NodeReadNumFormalOutputs(node) == 0){ |
---|
| 1758 | fprintf(vis_stdout,"No outputs\n"); |
---|
| 1759 | } |
---|
| 1760 | else { |
---|
| 1761 | tmpArray = array_alloc(char *,0); |
---|
| 1762 | Hrc_NodeForEachFormalOutput(node,i,var){ |
---|
| 1763 | array_insert_last(char *,tmpArray,Var_VariableReadName(var)); |
---|
| 1764 | } |
---|
| 1765 | array_sort(tmpArray,_HrcStringCmp); |
---|
| 1766 | fprintf(vis_stdout,"outputs:"); |
---|
| 1767 | for (i=0; i < array_n(tmpArray); i++){ |
---|
| 1768 | fprintf(vis_stdout," %s",array_fetch(char *,tmpArray,i)); |
---|
| 1769 | } |
---|
| 1770 | fprintf(vis_stdout,"\n"); |
---|
| 1771 | array_free(tmpArray); |
---|
| 1772 | } |
---|
| 1773 | return 0; |
---|
| 1774 | |
---|
| 1775 | usage: |
---|
| 1776 | (void) fprintf(vis_stderr,"usage: print_io [-h]\n"); |
---|
| 1777 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
| 1778 | return 1; |
---|
| 1779 | |
---|
| 1780 | } |
---|
| 1781 | |
---|
| 1782 | |
---|
| 1783 | /**Function******************************************************************** |
---|
| 1784 | |
---|
| 1785 | Synopsis [] |
---|
| 1786 | |
---|
| 1787 | Description [Refer to 'static int CommandMc (Hrc_Manager_t **hmgr, int argc, |
---|
| 1788 | char **argv)' function in mcCmd.c] |
---|
| 1789 | |
---|
| 1790 | SideEffects [] |
---|
| 1791 | |
---|
| 1792 | SeeAlso [] |
---|
| 1793 | |
---|
| 1794 | ******************************************************************************/ |
---|
| 1795 | static int model_checkMine (Hrc_Manager_t **hmgr, int argc, char **argv) |
---|
| 1796 | { |
---|
| 1797 | |
---|
| 1798 | (void) fprintf(vis_stderr, "*** 'model_check' begins. *** \n"); |
---|
| 1799 | |
---|
| 1800 | /* options */ |
---|
| 1801 | McOptions_t *options; |
---|
| 1802 | Mc_VerbosityLevel verbosity; |
---|
| 1803 | Mc_DcLevel dcLevel; |
---|
| 1804 | FILE *ctlFile; |
---|
| 1805 | int timeOutPeriod = 0; |
---|
| 1806 | Mc_FwdBwdAnalysis traversalDirection; |
---|
| 1807 | int buildOnionRings = 0; |
---|
| 1808 | FILE *guideFile; |
---|
| 1809 | FILE *systemFile; |
---|
| 1810 | Mc_GuidedSearch_t guidedSearchType = Mc_None_c; |
---|
| 1811 | Ctlp_FormulaArray_t *hintsArray = NIL(Fsm_HintsArray_t); |
---|
| 1812 | array_t *hintsStatesArray = NIL(array_t); /* array of mdd_t* */ |
---|
| 1813 | st_table *systemVarBddIdTable; |
---|
| 1814 | boolean noShare = 0; |
---|
| 1815 | Mc_GSHScheduleType GSHschedule; |
---|
| 1816 | boolean checkVacuity; |
---|
| 1817 | boolean performCoverageHoskote; |
---|
| 1818 | boolean performCoverageImproved; |
---|
| 1819 | |
---|
| 1820 | /* CTL formulae */ |
---|
| 1821 | array_t *ctlArray; |
---|
| 1822 | array_t *ctlNormalFormulaArray; |
---|
| 1823 | int i; |
---|
| 1824 | int numFormulae; |
---|
| 1825 | /* FSM, network and image */ |
---|
| 1826 | Fsm_Fsm_t *totalFsm = NIL(Fsm_Fsm_t); |
---|
| 1827 | Fsm_Fsm_t *modelFsm = NIL(Fsm_Fsm_t); |
---|
| 1828 | Fsm_Fsm_t *reducedFsm = NIL(Fsm_Fsm_t); |
---|
| 1829 | Ntk_Network_t *network; |
---|
| 1830 | mdd_t *modelCareStates = NIL(mdd_t); |
---|
| 1831 | array_t *modelCareStatesArray = NIL(array_t); |
---|
| 1832 | mdd_t *modelInitialStates; |
---|
| 1833 | mdd_t *fairStates; |
---|
| 1834 | Fsm_Fairness_t *fairCond; |
---|
| 1835 | mdd_manager *mddMgr; |
---|
| 1836 | array_t *bddIdArray; |
---|
| 1837 | Img_ImageInfo_t *imageInfo; |
---|
| 1838 | Mc_EarlyTermination_t *earlyTermination; |
---|
| 1839 | /* Coverage estimation */ |
---|
| 1840 | mdd_t *totalcoveredstates = NIL(mdd_t); |
---|
| 1841 | array_t *signalTypeList = array_alloc(int,0); |
---|
| 1842 | array_t *signalList = array_alloc(char *,0); |
---|
| 1843 | array_t *statesCoveredList = array_alloc(mdd_t *,0); |
---|
| 1844 | array_t *newCoveredStatesList = array_alloc(mdd_t *,0); |
---|
| 1845 | array_t *statesToRemoveList = array_alloc(mdd_t *,0); |
---|
| 1846 | |
---|
| 1847 | /* Early termination is only partially implemented right now. It needs |
---|
| 1848 | distribution over all operators, including limited cases of temporal |
---|
| 1849 | operators. That should be relatively easy to implement. */ |
---|
| 1850 | |
---|
| 1851 | /* time keeping */ |
---|
| 1852 | long totalInitialTime; /* for model checking */ |
---|
| 1853 | long initialTime, finalTime; /* for model checking */ |
---|
| 1854 | |
---|
| 1855 | error_init(); |
---|
| 1856 | Img_ResetNumberOfImageComputation(Img_Both_c); |
---|
| 1857 | |
---|
| 1858 | /* read options */ |
---|
| 1859 | if (!(options = ParseMcOptions(argc, argv))) { |
---|
| 1860 | return 1; |
---|
| 1861 | } |
---|
| 1862 | verbosity = McOptionsReadVerbosityLevel(options); |
---|
| 1863 | dcLevel = McOptionsReadDcLevel(options); |
---|
| 1864 | ctlFile = McOptionsReadCtlFile(options); |
---|
| 1865 | timeOutPeriod = McOptionsReadTimeOutPeriod(options); |
---|
| 1866 | traversalDirection = McOptionsReadTraversalDirection(options); |
---|
| 1867 | buildOnionRings = |
---|
| 1868 | (McOptionsReadDbgLevel(options) != McDbgLevelNone_c || verbosity); |
---|
| 1869 | noShare = McOptionsReadUseFormulaTree(options); |
---|
| 1870 | GSHschedule = McOptionsReadSchedule(options); |
---|
| 1871 | checkVacuity = McOptionsReadVacuityDetect(options); |
---|
| 1872 | /* for the command mc -C foo.ctl */ |
---|
| 1873 | performCoverageHoskote = McOptionsReadCoverageHoskote(options); |
---|
| 1874 | /* for the command mc -I foo.ctl */ |
---|
| 1875 | performCoverageImproved = McOptionsReadCoverageImproved(options); |
---|
| 1876 | |
---|
| 1877 | /* Check for incompatible options and do some option-specific |
---|
| 1878 | * intializations. |
---|
| 1879 | */ |
---|
| 1880 | |
---|
| 1881 | if (traversalDirection == McFwd_c) { |
---|
| 1882 | if (checkVacuity) { |
---|
| 1883 | fprintf(vis_stderr, "** mc error: -V and -B are incompatible with -F\n"); |
---|
| 1884 | McOptionsFree(options); |
---|
| 1885 | return 1; |
---|
| 1886 | } |
---|
| 1887 | if (performCoverageHoskote || performCoverageImproved) { |
---|
| 1888 | fprintf(vis_stderr, "** mc error: -I and -C are incompatible with -F\n"); |
---|
| 1889 | McOptionsFree(options); |
---|
| 1890 | return 1; |
---|
| 1891 | } |
---|
| 1892 | } |
---|
| 1893 | |
---|
| 1894 | if (checkVacuity) { |
---|
| 1895 | if (performCoverageHoskote || performCoverageImproved) { |
---|
| 1896 | fprintf(vis_stderr, "** mc error: -I and -C are incompatible with -V and -B\n"); |
---|
| 1897 | McOptionsFree(options); |
---|
| 1898 | return 1; |
---|
| 1899 | } |
---|
| 1900 | } |
---|
| 1901 | |
---|
| 1902 | guideFile = McOptionsReadGuideFile(options); |
---|
| 1903 | |
---|
| 1904 | if(guideFile != NIL(FILE) ){ |
---|
| 1905 | guidedSearchType = Mc_ReadGuidedSearchType(); |
---|
| 1906 | if(guidedSearchType == Mc_None_c){ /* illegal setting */ |
---|
| 1907 | fprintf(vis_stderr, "** mc error: Unknown hint type\n"); |
---|
| 1908 | fclose(guideFile); |
---|
| 1909 | McOptionsFree(options); |
---|
| 1910 | return 1; |
---|
| 1911 | } |
---|
| 1912 | |
---|
| 1913 | if(traversalDirection == McFwd_c){ /* illegal combination */ |
---|
| 1914 | fprintf(vis_stderr, "** mc error: -g is incompatible with -F\n"); |
---|
| 1915 | fclose(guideFile); |
---|
| 1916 | McOptionsFree(options); |
---|
| 1917 | return 1; |
---|
| 1918 | } |
---|
| 1919 | |
---|
| 1920 | if(Img_UserSpecifiedMethod() != Img_Iwls95_c && |
---|
| 1921 | Img_UserSpecifiedMethod() != Img_Monolithic_c && |
---|
| 1922 | Img_UserSpecifiedMethod() != Img_Mlp_c){ |
---|
| 1923 | fprintf(vis_stderr, "** mc error: -g only works with iwls95, MLP, or monolithic image methods.\n"); |
---|
| 1924 | fclose(guideFile); |
---|
| 1925 | McOptionsFree(options); |
---|
| 1926 | return 1; |
---|
| 1927 | } |
---|
| 1928 | |
---|
| 1929 | hintsArray = Mc_ReadHints(guideFile); |
---|
| 1930 | fclose(guideFile); guideFile = NIL(FILE); |
---|
| 1931 | if( hintsArray == NIL(array_t) ){ |
---|
| 1932 | McOptionsFree(options); |
---|
| 1933 | return 1; |
---|
| 1934 | } |
---|
| 1935 | |
---|
| 1936 | } /* if guided search */ |
---|
| 1937 | |
---|
| 1938 | /* If don't-cares are used, -r implies -c. Note that the satisfying |
---|
| 1939 | sets of a subformula are only in terms of propositions therein |
---|
| 1940 | and their cone of influence. Hence, we can share satisfying sets |
---|
| 1941 | among formulae. I don't quite understand what the problem with |
---|
| 1942 | don't-cares is (RB) */ |
---|
| 1943 | if (McOptionsReadReduceFsm(options)) |
---|
| 1944 | if (dcLevel != McDcLevelNone_c) |
---|
| 1945 | McOptionsSetUseFormulaTree(options, TRUE); |
---|
| 1946 | |
---|
| 1947 | if (traversalDirection == McFwd_c && |
---|
| 1948 | McOptionsReadDbgLevel(options) != McDbgLevelNone_c) { |
---|
| 1949 | McOptionsSetDbgLevel(options, McDbgLevelNone_c); |
---|
| 1950 | (void)fprintf(vis_stderr, "** mc warning : option -d is ignored.\n"); |
---|
| 1951 | } |
---|
| 1952 | |
---|
| 1953 | /* Read CTL formulae */ |
---|
| 1954 | ctlArray = Ctlsp_FileParseCTLFormulaArray(ctlFile); |
---|
| 1955 | fclose(ctlFile); ctlFile = NIL(FILE); |
---|
| 1956 | if (ctlArray == NIL(array_t)) { |
---|
| 1957 | (void) fprintf(vis_stderr, |
---|
| 1958 | "** mc error: error in parsing formulas from file\n"); |
---|
| 1959 | McOptionsFree(options); |
---|
| 1960 | return 1; |
---|
| 1961 | } |
---|
| 1962 | |
---|
| 1963 | /* read network */ |
---|
| 1964 | network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 1965 | if (network == NIL(Ntk_Network_t)) { |
---|
| 1966 | fprintf(vis_stdout, "%s\n", error_string()); |
---|
| 1967 | error_init(); |
---|
| 1968 | Ctlp_FormulaArrayFree(ctlArray); |
---|
| 1969 | McOptionsFree(options); |
---|
| 1970 | return 1; |
---|
| 1971 | } |
---|
| 1972 | |
---|
| 1973 | /* read fsm */ |
---|
| 1974 | totalFsm = Fsm_NetworkReadOrCreateFsm(network); |
---|
| 1975 | if (totalFsm == NIL(Fsm_Fsm_t)) { |
---|
| 1976 | fprintf(vis_stdout, "%s\n", error_string()); |
---|
| 1977 | error_init(); |
---|
| 1978 | Ctlp_FormulaArrayFree(ctlArray); |
---|
| 1979 | McOptionsFree(options); |
---|
| 1980 | return 1; |
---|
| 1981 | } |
---|
| 1982 | |
---|
| 1983 | /* Assign variables to system if doing FAFW */ |
---|
| 1984 | systemVarBddIdTable = NIL(st_table); |
---|
| 1985 | systemFile = McOptionsReadSystemFile(options); |
---|
| 1986 | if (systemFile != NIL(FILE)) { |
---|
| 1987 | systemVarBddIdTable = Mc_ReadSystemVariablesFAFW(totalFsm, systemFile); |
---|
| 1988 | fclose(systemFile); systemFile = NIL(FILE); |
---|
| 1989 | if (systemVarBddIdTable == (st_table *)-1 ) { /* FS: error message? */ |
---|
| 1990 | Ctlp_FormulaArrayFree(ctlArray); |
---|
| 1991 | McOptionsFree(options); |
---|
| 1992 | return 1; |
---|
| 1993 | } |
---|
| 1994 | } /* if FAFW */ |
---|
| 1995 | |
---|
| 1996 | if(options->FAFWFlag && systemVarBddIdTable == 0) { |
---|
| 1997 | systemVarBddIdTable = Mc_SetAllInputToSystem(totalFsm); |
---|
| 1998 | } |
---|
| 1999 | |
---|
| 2000 | if (verbosity > McVerbosityNone_c) |
---|
| 2001 | totalInitialTime = util_cpu_time(); |
---|
| 2002 | else /* to remove uninitialized variable warning */ |
---|
| 2003 | totalInitialTime = 0; |
---|
| 2004 | |
---|
| 2005 | if(traversalDirection == McFwd_c){ |
---|
| 2006 | mdd_t *totalInitialStates; |
---|
| 2007 | double nInitialStates; |
---|
| 2008 | |
---|
| 2009 | totalInitialStates = Fsm_FsmComputeInitialStates(totalFsm); |
---|
| 2010 | nInitialStates = mdd_count_onset(Fsm_FsmReadMddManager(totalFsm), |
---|
| 2011 | totalInitialStates, |
---|
| 2012 | Fsm_FsmReadPresentStateVars(totalFsm)); |
---|
| 2013 | mdd_free(totalInitialStates); |
---|
| 2014 | |
---|
| 2015 | /* If the number of initial states is only one, we can use both |
---|
| 2016 | * conversion formulas(init ^ f != FALSE and init ^ !f == FALSE), |
---|
| 2017 | * however, if we have multiple initial states, we should use |
---|
| 2018 | * p0 ^ !f == FALSE. |
---|
| 2019 | */ |
---|
| 2020 | ctlNormalFormulaArray = |
---|
| 2021 | Ctlp_FormulaArrayConvertToForward(ctlArray, (nInitialStates == 1.0), |
---|
| 2022 | noShare); |
---|
| 2023 | /* end conversion for forward traversal */ |
---|
| 2024 | } else if (noShare) { /* conversion for backward, no sharing */ |
---|
| 2025 | ctlNormalFormulaArray = |
---|
| 2026 | Ctlp_FormulaArrayConvertToExistentialFormTree(ctlArray); |
---|
| 2027 | }else{ /* conversion for backward, with sharing */ |
---|
| 2028 | /* Note that converting to DAG after converting to existential form would |
---|
| 2029 | lead to more sharing, but it cannot be done since equal subformula that |
---|
| 2030 | are converted from different formulae need different pointers back to |
---|
| 2031 | their originals */ |
---|
| 2032 | if (checkVacuity) { |
---|
| 2033 | ctlNormalFormulaArray = |
---|
| 2034 | Ctlp_FormulaArrayConvertToExistentialFormTree(ctlArray); |
---|
| 2035 | } |
---|
| 2036 | else { |
---|
| 2037 | array_t *temp = Ctlp_FormulaArrayConvertToDAG( ctlArray ); |
---|
| 2038 | array_free( ctlArray ); |
---|
| 2039 | ctlArray = temp; |
---|
| 2040 | ctlNormalFormulaArray = |
---|
| 2041 | Ctlp_FormulaDAGConvertToExistentialFormDAG(ctlArray); |
---|
| 2042 | } |
---|
| 2043 | } |
---|
| 2044 | /* At this point, ctlNormalFormulaArray contains the formulas that are |
---|
| 2045 | actually going to be checked, and ctlArray contains the formulas from |
---|
| 2046 | which the conversion has been done. Both need to be kept around until the |
---|
| 2047 | end, for debugging purposes. */ |
---|
| 2048 | |
---|
| 2049 | numFormulae = array_n(ctlNormalFormulaArray); |
---|
| 2050 | |
---|
| 2051 | /* time out */ |
---|
| 2052 | if (timeOutPeriod > 0) { |
---|
| 2053 | /* Set the static variables used by the signal handler. */ |
---|
| 2054 | mcTimeOut = timeOutPeriod; |
---|
| 2055 | alarmLapTime = util_cpu_ctime(); |
---|
| 2056 | (void) signal(SIGALRM, (void(*)(int))TimeOutHandle); |
---|
| 2057 | (void) alarm(timeOutPeriod); |
---|
| 2058 | if (setjmp(timeOutEnv) > 0) { |
---|
| 2059 | (void) fprintf(vis_stdout, |
---|
| 2060 | "# MC: timeout occurred after %d seconds.\n", timeOutPeriod); |
---|
| 2061 | (void) fprintf(vis_stdout, "# MC: data may be corrupted.\n"); |
---|
| 2062 | if (verbosity > McVerbosityNone_c) { |
---|
| 2063 | fprintf(vis_stdout, "-- total %d image computations and %d preimage computations\n", |
---|
| 2064 | Img_GetNumberOfImageComputation(Img_Forward_c), |
---|
| 2065 | Img_GetNumberOfImageComputation(Img_Backward_c)); |
---|
| 2066 | } |
---|
| 2067 | alarm(0); |
---|
| 2068 | return 1; |
---|
| 2069 | } |
---|
| 2070 | } |
---|
| 2071 | |
---|
| 2072 | |
---|
| 2073 | /* Create reduced fsm, if necessary */ |
---|
| 2074 | if (!McOptionsReadReduceFsm(options)){ |
---|
| 2075 | /* We want to minimize only when "-r" option is not specified */ |
---|
| 2076 | /* reduceFsm would be NIL, if there is no reduction observed */ |
---|
| 2077 | assert (reducedFsm == NIL(Fsm_Fsm_t)); |
---|
| 2078 | reducedFsm = McConstructReducedFsm(network, ctlNormalFormulaArray); |
---|
| 2079 | if (reducedFsm != NIL(Fsm_Fsm_t) && verbosity != McVerbosityNone_c) { |
---|
| 2080 | mddMgr = Fsm_FsmReadMddManager(reducedFsm); |
---|
| 2081 | bddIdArray = mdd_id_array_to_bdd_id_array(mddMgr, |
---|
| 2082 | Fsm_FsmReadPresentStateVars(reducedFsm)); |
---|
| 2083 | (void)fprintf(vis_stdout,"Local system includes "); |
---|
| 2084 | (void)fprintf(vis_stdout,"%d (%d) multi-value (boolean) variables.\n", |
---|
| 2085 | array_n(Fsm_FsmReadPresentStateVars(reducedFsm)), |
---|
| 2086 | array_n(bddIdArray)); |
---|
| 2087 | array_free(bddIdArray); |
---|
| 2088 | } |
---|
| 2089 | } |
---|
| 2090 | |
---|
| 2091 | /************** for all formulae **********************************/ |
---|
| 2092 | for(i = 0; i < numFormulae; i++) { |
---|
| 2093 | int nImgComps, nPreComps; |
---|
| 2094 | boolean result; |
---|
| 2095 | Ctlp_Formula_t *ctlFormula = array_fetch(Ctlp_Formula_t *, |
---|
| 2096 | ctlNormalFormulaArray, i); |
---|
| 2097 | |
---|
| 2098 | modelFsm = NIL(Fsm_Fsm_t); |
---|
| 2099 | |
---|
| 2100 | /* do a check */ |
---|
| 2101 | if (!Mc_FormulaStaticSemanticCheckOnNetwork(ctlFormula, network, FALSE)) { |
---|
| 2102 | (void) fprintf(vis_stdout, |
---|
| 2103 | "** mc error: error in parsing Atomic Formula:\n%s\n", |
---|
| 2104 | error_string()); |
---|
| 2105 | error_init(); |
---|
| 2106 | Ctlp_FormulaFree(ctlFormula); |
---|
| 2107 | continue; |
---|
| 2108 | } |
---|
| 2109 | |
---|
| 2110 | /* Create reduced fsm */ |
---|
| 2111 | if (McOptionsReadReduceFsm(options)) { |
---|
| 2112 | /* We have not done top level reduction. */ |
---|
| 2113 | /* Using the same variable reducedFsm here */ |
---|
| 2114 | array_t *oneFormulaArray = array_alloc(Ctlp_Formula_t *, 1); |
---|
| 2115 | |
---|
| 2116 | assert(reducedFsm == NIL(Fsm_Fsm_t)); |
---|
| 2117 | array_insert_last(Ctlp_Formula_t *, oneFormulaArray, ctlFormula); |
---|
| 2118 | reducedFsm = McConstructReducedFsm(network, oneFormulaArray); |
---|
| 2119 | array_free(oneFormulaArray); |
---|
| 2120 | |
---|
| 2121 | if (reducedFsm && verbosity != McVerbosityNone_c) { |
---|
| 2122 | mddMgr = Fsm_FsmReadMddManager(reducedFsm); |
---|
| 2123 | bddIdArray = mdd_id_array_to_bdd_id_array(mddMgr, |
---|
| 2124 | Fsm_FsmReadPresentStateVars(reducedFsm)); |
---|
| 2125 | (void)fprintf(vis_stdout,"Local system includes "); |
---|
| 2126 | (void)fprintf(vis_stdout,"%d (%d) multi-value (boolean) variables.\n", |
---|
| 2127 | array_n(Fsm_FsmReadPresentStateVars(reducedFsm)), |
---|
| 2128 | array_n(bddIdArray)); |
---|
| 2129 | array_free(bddIdArray); |
---|
| 2130 | } |
---|
| 2131 | }/* if readreducefsm */ |
---|
| 2132 | |
---|
| 2133 | /* Let us see if we got any reduction via top level or via "-r" */ |
---|
| 2134 | if (reducedFsm == NIL(Fsm_Fsm_t)) |
---|
| 2135 | modelFsm = totalFsm; /* no reduction */ |
---|
| 2136 | else |
---|
| 2137 | modelFsm = reducedFsm; /* some reduction at some point */ |
---|
| 2138 | |
---|
| 2139 | /* compute initial states */ |
---|
| 2140 | modelInitialStates = Fsm_FsmComputeInitialStates(modelFsm); |
---|
| 2141 | if (modelInitialStates == NIL(mdd_t)) { |
---|
| 2142 | int j; |
---|
| 2143 | (void) fprintf(vis_stdout, |
---|
| 2144 | "** mc error: Cannot build init states (mutual latch dependency?)\n%s\n", |
---|
| 2145 | error_string()); |
---|
| 2146 | if (modelFsm != totalFsm) |
---|
| 2147 | Fsm_FsmFree(reducedFsm); |
---|
| 2148 | |
---|
| 2149 | alarm(0); |
---|
| 2150 | |
---|
| 2151 | for(j = i; j < numFormulae; j++) |
---|
| 2152 | Ctlp_FormulaFree( |
---|
| 2153 | array_fetch( Ctlp_Formula_t *, ctlNormalFormulaArray, j ) ); |
---|
| 2154 | array_free( ctlNormalFormulaArray ); |
---|
| 2155 | |
---|
| 2156 | Ctlp_FormulaArrayFree( ctlArray ); |
---|
| 2157 | |
---|
| 2158 | McOptionsFree(options); |
---|
| 2159 | |
---|
| 2160 | return 1; |
---|
| 2161 | } |
---|
| 2162 | |
---|
| 2163 | earlyTermination = Mc_EarlyTerminationAlloc(McAll_c, modelInitialStates); |
---|
| 2164 | |
---|
| 2165 | if(hintsArray != NIL(Ctlp_FormulaArray_t)) { |
---|
| 2166 | hintsStatesArray = Mc_EvaluateHints(modelFsm, hintsArray); |
---|
| 2167 | if( hintsStatesArray == NIL(array_t) || |
---|
| 2168 | (guidedSearchType == Mc_Global_c && |
---|
| 2169 | Ctlp_CheckClassOfExistentialFormula(ctlFormula) == Ctlp_Mixed_c)) { |
---|
| 2170 | int j; |
---|
| 2171 | |
---|
| 2172 | if( guidedSearchType == Mc_Global_c && |
---|
| 2173 | Ctlp_CheckClassOfExistentialFormula(ctlFormula) == Ctlp_Mixed_c) |
---|
| 2174 | fprintf(vis_stderr, "** mc error: global hints incompatible with " |
---|
| 2175 | "mixed formulae\n"); |
---|
| 2176 | |
---|
| 2177 | Mc_EarlyTerminationFree(earlyTermination); |
---|
| 2178 | mdd_free(modelInitialStates); |
---|
| 2179 | if (modelFsm != totalFsm) |
---|
| 2180 | Fsm_FsmFree(reducedFsm); |
---|
| 2181 | alarm(0); |
---|
| 2182 | for(j = i; j < numFormulae; j++) |
---|
| 2183 | Ctlp_FormulaFree( |
---|
| 2184 | array_fetch( Ctlp_Formula_t *, ctlNormalFormulaArray, j ) ); |
---|
| 2185 | array_free( ctlNormalFormulaArray ); |
---|
| 2186 | Ctlp_FormulaArrayFree( ctlArray ); |
---|
| 2187 | McOptionsFree(options); |
---|
| 2188 | return 1; |
---|
| 2189 | } /* problem with hints */ |
---|
| 2190 | } /* hints exist */ |
---|
| 2191 | |
---|
| 2192 | /* stats */ |
---|
| 2193 | if (verbosity > McVerbosityNone_c) { |
---|
| 2194 | initialTime = util_cpu_time(); |
---|
| 2195 | nImgComps = Img_GetNumberOfImageComputation(Img_Forward_c); |
---|
| 2196 | nPreComps = Img_GetNumberOfImageComputation(Img_Backward_c); |
---|
| 2197 | } else { /* to remove uninitialized variable warnings */ |
---|
| 2198 | initialTime = 0; |
---|
| 2199 | nImgComps = 0; |
---|
| 2200 | nPreComps = 0; |
---|
| 2201 | } |
---|
| 2202 | mddMgr = Fsm_FsmReadMddManager(modelFsm); |
---|
| 2203 | |
---|
| 2204 | /* compute don't cares. */ |
---|
| 2205 | if (modelCareStatesArray == NIL(array_t)) { |
---|
| 2206 | long iTime; /* starting time for reachability analysis */ |
---|
| 2207 | if (verbosity > McVerbosityNone_c && i == 0) |
---|
| 2208 | iTime = util_cpu_time(); |
---|
| 2209 | else /* to remove uninitialized variable warnings */ |
---|
| 2210 | iTime = 0; |
---|
| 2211 | |
---|
| 2212 | /* ardc */ |
---|
| 2213 | if (dcLevel == McDcLevelArdc_c) { |
---|
| 2214 | Fsm_ArdcOptions_t *ardcOptions = McOptionsReadArdcOptions(options); |
---|
| 2215 | |
---|
| 2216 | modelCareStatesArray = Fsm_ArdcComputeOverApproximateReachableStates( |
---|
| 2217 | modelFsm, 0, verbosity, 0, 0, 0, 0, 0, 0, ardcOptions); |
---|
| 2218 | if (verbosity > McVerbosityNone_c && i == 0) |
---|
| 2219 | Fsm_ArdcPrintReachabilityResults(modelFsm, util_cpu_time() - iTime); |
---|
| 2220 | |
---|
| 2221 | /* rch dc */ |
---|
| 2222 | } else if (dcLevel >= McDcLevelRch_c) { |
---|
| 2223 | modelCareStates = |
---|
| 2224 | Fsm_FsmComputeReachableStates(modelFsm, 0, 1, 0, 0, 0, 0, 0, |
---|
| 2225 | Fsm_Rch_Default_c, 0, 0, |
---|
| 2226 | NIL(array_t), FALSE, NIL(array_t)); |
---|
| 2227 | if (verbosity > McVerbosityNone_c && i == 0) { |
---|
| 2228 | Fsm_FsmReachabilityPrintResults(modelFsm, util_cpu_time() - iTime, |
---|
| 2229 | Fsm_Rch_Default_c); |
---|
| 2230 | } |
---|
| 2231 | |
---|
| 2232 | modelCareStatesArray = array_alloc(mdd_t *, 0); |
---|
| 2233 | array_insert(mdd_t *, modelCareStatesArray, 0, modelCareStates); |
---|
| 2234 | } else { |
---|
| 2235 | modelCareStates = mdd_one(mddMgr); |
---|
| 2236 | modelCareStatesArray = array_alloc(mdd_t *, 0); |
---|
| 2237 | array_insert(mdd_t *, modelCareStatesArray, 0, modelCareStates); |
---|
| 2238 | } |
---|
| 2239 | } |
---|
| 2240 | |
---|
| 2241 | Fsm_MinimizeTransitionRelationWithReachabilityInfo( |
---|
| 2242 | modelFsm, (traversalDirection == McFwd_c) ? Img_Both_c : Img_Backward_c, |
---|
| 2243 | verbosity > 1); |
---|
| 2244 | |
---|
| 2245 | /* fairness conditions */ |
---|
| 2246 | fairStates = Fsm_FsmComputeFairStates(modelFsm, modelCareStatesArray, |
---|
| 2247 | verbosity, dcLevel, GSHschedule, |
---|
| 2248 | McBwd_c, FALSE); |
---|
| 2249 | fairCond = Fsm_FsmReadFairnessConstraint(modelFsm); |
---|
| 2250 | |
---|
| 2251 | if (mdd_lequal(modelInitialStates, fairStates, 1, 0)) { |
---|
| 2252 | (void)fprintf(vis_stdout, |
---|
| 2253 | "** mc warning: There are no fair initial states\n"); |
---|
| 2254 | } |
---|
| 2255 | else if (!mdd_lequal(modelInitialStates, fairStates, 1, 1)) { |
---|
| 2256 | (void)fprintf(vis_stdout, |
---|
| 2257 | "** mc warning: Some initial states are not fair\n"); |
---|
| 2258 | } |
---|
| 2259 | |
---|
| 2260 | /* some user feedback */ |
---|
| 2261 | if (verbosity != McVerbosityNone_c) { |
---|
| 2262 | (void)fprintf(vis_stdout, "Checking formula[%d] : ", i + 1); |
---|
| 2263 | Ctlp_FormulaPrint(vis_stdout, |
---|
| 2264 | Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 2265 | (void)fprintf (vis_stdout, "\n"); |
---|
| 2266 | if (traversalDirection == McFwd_c) { |
---|
| 2267 | (void)fprintf(vis_stdout, "Forward formula : "); |
---|
| 2268 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 2269 | (void)fprintf(vis_stdout, "\n"); |
---|
| 2270 | } |
---|
| 2271 | } |
---|
| 2272 | |
---|
| 2273 | /************** the actual computation **********************************/ |
---|
| 2274 | if (checkVacuity) { |
---|
| 2275 | McVacuityDetection(modelFsm, ctlFormula, i, |
---|
| 2276 | fairStates, fairCond, modelCareStatesArray, |
---|
| 2277 | earlyTermination, hintsStatesArray, |
---|
| 2278 | guidedSearchType, modelInitialStates, |
---|
| 2279 | options); |
---|
| 2280 | } |
---|
| 2281 | else { /* Normal Model Checking */ |
---|
| 2282 | mdd_t *ctlFormulaStates = |
---|
| 2283 | Mc_FsmEvaluateFormula(modelFsm, ctlFormula, fairStates, |
---|
| 2284 | fairCond, modelCareStatesArray, |
---|
| 2285 | earlyTermination, hintsStatesArray, |
---|
| 2286 | guidedSearchType, verbosity, dcLevel, |
---|
| 2287 | buildOnionRings, GSHschedule); |
---|
| 2288 | |
---|
| 2289 | McEstimateCoverage(modelFsm, ctlFormula, i, fairStates, fairCond, |
---|
| 2290 | modelCareStatesArray, earlyTermination, |
---|
| 2291 | hintsStatesArray, guidedSearchType, verbosity, |
---|
| 2292 | dcLevel, buildOnionRings, GSHschedule, |
---|
| 2293 | traversalDirection, modelInitialStates, |
---|
| 2294 | ctlFormulaStates, &totalcoveredstates, |
---|
| 2295 | signalTypeList, signalList, statesCoveredList, |
---|
| 2296 | newCoveredStatesList, statesToRemoveList, |
---|
| 2297 | performCoverageHoskote, performCoverageImproved); |
---|
| 2298 | |
---|
| 2299 | Mc_EarlyTerminationFree(earlyTermination); |
---|
| 2300 | if(hintsStatesArray != NIL(array_t)) |
---|
| 2301 | mdd_array_free(hintsStatesArray); |
---|
| 2302 | /* Set up things for possible FAFW analysis of counterexample. */ |
---|
| 2303 | Fsm_FsmSetFAFWFlag(modelFsm, options->FAFWFlag); |
---|
| 2304 | Fsm_FsmSetSystemVariableFAFW(modelFsm, systemVarBddIdTable); |
---|
| 2305 | /* user feedback on succes/fail */ |
---|
| 2306 | result = McPrintPassFailMine(mddMgr, modelFsm, traversalDirection, |
---|
| 2307 | ctlFormula, ctlFormulaStates, |
---|
| 2308 | modelInitialStates, modelCareStatesArray, |
---|
| 2309 | options, verbosity); |
---|
| 2310 | Fsm_FsmSetFAFWFlag(modelFsm, 0); |
---|
| 2311 | Fsm_FsmSetSystemVariableFAFW(modelFsm, NULL); |
---|
| 2312 | mdd_free(ctlFormulaStates); |
---|
| 2313 | } |
---|
| 2314 | |
---|
| 2315 | if (verbosity > McVerbosityNone_c) { |
---|
| 2316 | finalTime = util_cpu_time(); |
---|
| 2317 | fprintf(vis_stdout, "-- mc time = %10g\n", |
---|
| 2318 | (double)(finalTime - initialTime) / 1000.0); |
---|
| 2319 | fprintf(vis_stdout, |
---|
| 2320 | "-- %d image computations and %d preimage computations\n", |
---|
| 2321 | Img_GetNumberOfImageComputation(Img_Forward_c) - nImgComps, |
---|
| 2322 | Img_GetNumberOfImageComputation(Img_Backward_c) - nPreComps); |
---|
| 2323 | } |
---|
| 2324 | mdd_free(modelInitialStates); |
---|
| 2325 | mdd_free(fairStates); |
---|
| 2326 | Ctlp_FormulaFree(ctlFormula); |
---|
| 2327 | |
---|
| 2328 | if ((McOptionsReadReduceFsm(options)) && |
---|
| 2329 | (reducedFsm != NIL(Fsm_Fsm_t))) { |
---|
| 2330 | /* |
---|
| 2331 | ** We need to free the reducedFsm only if it was created under "-r" |
---|
| 2332 | ** option and was non-NIL. |
---|
| 2333 | */ |
---|
| 2334 | Fsm_FsmFree(reducedFsm); |
---|
| 2335 | reducedFsm = NIL(Fsm_Fsm_t); |
---|
| 2336 | modelFsm = NIL(Fsm_Fsm_t); |
---|
| 2337 | if (modelCareStates) { |
---|
| 2338 | mdd_array_free(modelCareStatesArray); |
---|
| 2339 | modelCareStates = NIL(mdd_t); |
---|
| 2340 | modelCareStatesArray = NIL(array_t); |
---|
| 2341 | } else if (modelCareStatesArray) { |
---|
| 2342 | modelCareStatesArray = NIL(array_t); |
---|
| 2343 | } |
---|
| 2344 | } |
---|
| 2345 | }/* for all formulae */ |
---|
| 2346 | |
---|
| 2347 | if (verbosity > McVerbosityNone_c) { |
---|
| 2348 | finalTime = util_cpu_time(); |
---|
| 2349 | fprintf(vis_stdout, "-- total mc time = %10g\n", |
---|
| 2350 | (double)(finalTime - totalInitialTime) / 1000.0); |
---|
| 2351 | fprintf(vis_stdout, |
---|
| 2352 | "-- total %d image computations and %d preimage computations\n", |
---|
| 2353 | Img_GetNumberOfImageComputation(Img_Forward_c), |
---|
| 2354 | Img_GetNumberOfImageComputation(Img_Backward_c)); |
---|
| 2355 | /* Print tfm options if we have a global fsm. */ |
---|
| 2356 | if (!McOptionsReadReduceFsm(options) && modelFsm != NIL(Fsm_Fsm_t)) { |
---|
| 2357 | imageInfo = Fsm_FsmReadImageInfo(modelFsm); |
---|
| 2358 | if (Img_ImageInfoObtainMethodType(imageInfo) == Img_Tfm_c || |
---|
| 2359 | Img_ImageInfoObtainMethodType(imageInfo) == Img_Hybrid_c) { |
---|
| 2360 | Img_TfmPrintStatistics(imageInfo, Img_Both_c); |
---|
| 2361 | } |
---|
| 2362 | } |
---|
| 2363 | } |
---|
| 2364 | |
---|
| 2365 | /* Print results of coverage computation */ |
---|
| 2366 | McPrintCoverageSummary(modelFsm, dcLevel, |
---|
| 2367 | options, modelCareStatesArray, |
---|
| 2368 | modelCareStates, totalcoveredstates, |
---|
| 2369 | signalTypeList, signalList, statesCoveredList, |
---|
| 2370 | performCoverageHoskote, performCoverageImproved); |
---|
| 2371 | mdd_array_free(newCoveredStatesList); |
---|
| 2372 | mdd_array_free(statesToRemoveList); |
---|
| 2373 | array_free(signalTypeList); |
---|
| 2374 | array_free(signalList); |
---|
| 2375 | mdd_array_free(statesCoveredList); |
---|
| 2376 | if (totalcoveredstates != NIL(mdd_t)) |
---|
| 2377 | mdd_free(totalcoveredstates); |
---|
| 2378 | |
---|
| 2379 | if (modelCareStates) { |
---|
| 2380 | mdd_array_free(modelCareStatesArray); |
---|
| 2381 | } |
---|
| 2382 | |
---|
| 2383 | if(hintsArray) |
---|
| 2384 | Ctlp_FormulaArrayFree(hintsArray); |
---|
| 2385 | |
---|
| 2386 | if ((McOptionsReadReduceFsm(options) == FALSE) && |
---|
| 2387 | (reducedFsm != NIL(Fsm_Fsm_t))) { |
---|
| 2388 | /* If "-r" was not specified and we did some reduction at top |
---|
| 2389 | level, we need to free it */ |
---|
| 2390 | Fsm_FsmFree(reducedFsm); |
---|
| 2391 | reducedFsm = NIL(Fsm_Fsm_t); |
---|
| 2392 | modelFsm = NIL(Fsm_Fsm_t); |
---|
| 2393 | } |
---|
| 2394 | |
---|
| 2395 | if(systemVarBddIdTable) |
---|
| 2396 | st_free_table(systemVarBddIdTable); |
---|
| 2397 | array_free(ctlNormalFormulaArray); |
---|
| 2398 | (void) fprintf(vis_stdout, "\n"); |
---|
| 2399 | |
---|
| 2400 | Ctlp_FormulaArrayFree(ctlArray); |
---|
| 2401 | McOptionsFree(options); |
---|
| 2402 | alarm(0); |
---|
| 2403 | return 0; |
---|
| 2404 | |
---|
| 2405 | } |
---|
| 2406 | |
---|
| 2407 | |
---|
| 2408 | /**Function******************************************************************** |
---|
| 2409 | |
---|
| 2410 | Synopsis [Parse command line options for mc.] |
---|
| 2411 | |
---|
| 2412 | SideEffects [] |
---|
| 2413 | |
---|
| 2414 | ******************************************************************************/ |
---|
| 2415 | static McOptions_t * |
---|
| 2416 | ParseMcOptions( |
---|
| 2417 | int argc, |
---|
| 2418 | char **argv) |
---|
| 2419 | { |
---|
| 2420 | unsigned int i; |
---|
| 2421 | int c; |
---|
| 2422 | char *guideFileName = NIL(char); |
---|
| 2423 | char *variablesForSystem = NIL(char); |
---|
| 2424 | FILE *guideFile = NIL(FILE); |
---|
| 2425 | FILE *systemFile = NIL(FILE); |
---|
| 2426 | boolean doCoverageHoskote = FALSE; |
---|
| 2427 | boolean doCoverageImproved = FALSE; |
---|
| 2428 | boolean useMore = FALSE; |
---|
| 2429 | boolean reduceFsm = FALSE; |
---|
| 2430 | boolean printInputs = FALSE; |
---|
| 2431 | boolean useFormulaTree = FALSE; |
---|
| 2432 | boolean vd = FALSE; |
---|
| 2433 | boolean beer = FALSE; |
---|
| 2434 | boolean FAFWFlag = FALSE; |
---|
| 2435 | boolean GFAFWFlag = FALSE; |
---|
| 2436 | FILE *inputFp=NIL(FILE); |
---|
| 2437 | FILE *debugOut=NIL(FILE); |
---|
| 2438 | char *debugOutName=NIL(char); |
---|
| 2439 | Mc_DcLevel dcLevel = McDcLevelRch_c; |
---|
| 2440 | McDbgLevel dbgLevel = McDbgLevelNone_c; |
---|
| 2441 | Mc_VerbosityLevel verbosityLevel = McVerbosityNone_c; |
---|
| 2442 | Mc_FwdBwdAnalysis fwdBwd = McFwd_c; |
---|
| 2443 | McOptions_t *options = McOptionsAlloc(); |
---|
| 2444 | int timeOutPeriod = 0; |
---|
| 2445 | Mc_FwdBwdAnalysis traversalDirection = McBwd_c; |
---|
| 2446 | Fsm_ArdcOptions_t *ardcOptions; |
---|
| 2447 | Mc_GSHScheduleType schedule = McGSH_EL_c; |
---|
| 2448 | |
---|
| 2449 | /* |
---|
| 2450 | * Parse command line options. |
---|
| 2451 | */ |
---|
| 2452 | |
---|
| 2453 | util_getopt_reset(); |
---|
| 2454 | while ((c = util_getopt(argc, argv, "bcirmg:hv:d:D:VBf:t:CIFR:S:GWw:")) != EOF) { |
---|
| 2455 | switch(c) { |
---|
| 2456 | case 'g': |
---|
| 2457 | guideFileName = util_strsav(util_optarg); |
---|
| 2458 | break; |
---|
| 2459 | case 'h': |
---|
| 2460 | goto usage; |
---|
| 2461 | case 'v': |
---|
| 2462 | for (i = 0; i < strlen(util_optarg); i++) { |
---|
| 2463 | if (!isdigit((int)util_optarg[i])) { |
---|
| 2464 | goto usage; |
---|
| 2465 | } |
---|
| 2466 | } |
---|
| 2467 | verbosityLevel = (Mc_VerbosityLevel) atoi(util_optarg); |
---|
| 2468 | break; |
---|
| 2469 | case 'd': |
---|
| 2470 | for (i = 0; i < strlen(util_optarg); i++) { |
---|
| 2471 | if (!isdigit((int)util_optarg[i])) { |
---|
| 2472 | goto usage; |
---|
| 2473 | } |
---|
| 2474 | } |
---|
| 2475 | dbgLevel = (McDbgLevel) atoi(util_optarg); |
---|
| 2476 | break; |
---|
| 2477 | case 'D': |
---|
| 2478 | for (i = 0; i < strlen(util_optarg); i++) { |
---|
| 2479 | if (!isdigit((int)util_optarg[i])) { |
---|
| 2480 | goto usage; |
---|
| 2481 | } |
---|
| 2482 | } |
---|
| 2483 | dcLevel = (Mc_DcLevel) atoi(util_optarg); |
---|
| 2484 | break; |
---|
| 2485 | case 'b': |
---|
| 2486 | fwdBwd = McBwd_c; |
---|
| 2487 | break; |
---|
| 2488 | case 'V': /*Vacuity detection option*/ |
---|
| 2489 | vd = TRUE; |
---|
| 2490 | break; |
---|
| 2491 | case 'B': /*Vacuity detection Beer et al method option*/ |
---|
| 2492 | vd = TRUE; |
---|
| 2493 | beer = TRUE; |
---|
| 2494 | break; |
---|
| 2495 | case 'f': |
---|
| 2496 | debugOutName = util_strsav(util_optarg); |
---|
| 2497 | break; |
---|
| 2498 | case 'm': |
---|
| 2499 | useMore = TRUE; |
---|
| 2500 | break; |
---|
| 2501 | case 'r' : |
---|
| 2502 | reduceFsm = TRUE; |
---|
| 2503 | break; |
---|
| 2504 | case 'c': |
---|
| 2505 | useFormulaTree = TRUE; |
---|
| 2506 | break; |
---|
| 2507 | case 't' : |
---|
| 2508 | timeOutPeriod = atoi(util_optarg); |
---|
| 2509 | break; |
---|
| 2510 | case 'i' : |
---|
| 2511 | printInputs = TRUE; |
---|
| 2512 | break; |
---|
| 2513 | case 'F' : |
---|
| 2514 | traversalDirection = McFwd_c; |
---|
| 2515 | break; |
---|
| 2516 | case 'S' : |
---|
| 2517 | schedule = McStringConvertToScheduleType(util_optarg); |
---|
| 2518 | break; |
---|
| 2519 | case 'w': |
---|
| 2520 | variablesForSystem = util_strsav(util_optarg); |
---|
| 2521 | case 'W': |
---|
| 2522 | FAFWFlag = 1; |
---|
| 2523 | break; |
---|
| 2524 | case 'G': |
---|
| 2525 | GFAFWFlag = 1; |
---|
| 2526 | break; |
---|
| 2527 | case 'C' : |
---|
| 2528 | doCoverageHoskote = TRUE; |
---|
| 2529 | break; |
---|
| 2530 | case 'I' : |
---|
| 2531 | doCoverageImproved = TRUE; |
---|
| 2532 | break; |
---|
| 2533 | default: |
---|
| 2534 | goto usage; |
---|
| 2535 | } |
---|
| 2536 | } |
---|
| 2537 | |
---|
| 2538 | /* |
---|
| 2539 | * Open the ctl file. |
---|
| 2540 | */ |
---|
| 2541 | if (argc - util_optind == 0) { |
---|
| 2542 | (void) fprintf(vis_stderr, "** mc error: file containing ctl formulas not provided\n"); |
---|
| 2543 | goto usage; |
---|
| 2544 | } |
---|
| 2545 | else if (argc - util_optind > 1) { |
---|
| 2546 | (void) fprintf(vis_stderr, "** mc error: too many arguments\n"); |
---|
| 2547 | goto usage; |
---|
| 2548 | } |
---|
| 2549 | |
---|
| 2550 | McOptionsSetFwdBwd(options, fwdBwd); |
---|
| 2551 | McOptionsSetUseMore(options, useMore); |
---|
| 2552 | McOptionsSetReduceFsm(options, reduceFsm); |
---|
| 2553 | McOptionsSetVacuityDetect(options, vd); |
---|
| 2554 | McOptionsSetBeerMethod(options, beer); |
---|
| 2555 | McOptionsSetUseFormulaTree(options, useFormulaTree); |
---|
| 2556 | McOptionsSetPrintInputs(options, printInputs); |
---|
| 2557 | McOptionsSetTimeOutPeriod(options, timeOutPeriod); |
---|
| 2558 | McOptionsSetFAFWFlag(options, FAFWFlag + GFAFWFlag); |
---|
| 2559 | McOptionsSetCoverageHoskote(options, doCoverageHoskote); |
---|
| 2560 | McOptionsSetCoverageImproved(options, doCoverageImproved); |
---|
| 2561 | |
---|
| 2562 | if((FAFWFlag > 0 || GFAFWFlag > 0) && dbgLevel == 0) { |
---|
| 2563 | fprintf(vis_stderr, "** mc warning : -w and -W options are ignored without -d option\n"); |
---|
| 2564 | } |
---|
| 2565 | |
---|
| 2566 | if((FAFWFlag > 0 || GFAFWFlag > 0) && printInputs == 0) { |
---|
| 2567 | fprintf(vis_stderr, "** mc warning : -i is recommended with -w or -W option\n"); |
---|
| 2568 | } |
---|
| 2569 | if(FAFWFlag) { |
---|
| 2570 | if (bdd_get_package_name() != CUDD) { |
---|
| 2571 | fprintf(vis_stderr, "** mc warning : -w and -W option is only available with CUDD\n"); |
---|
| 2572 | FAFWFlag = 0; |
---|
| 2573 | FREE(variablesForSystem); |
---|
| 2574 | variablesForSystem = NIL(char); |
---|
| 2575 | } |
---|
| 2576 | } |
---|
| 2577 | |
---|
| 2578 | |
---|
| 2579 | if (schedule == McGSH_Unassigned_c) { |
---|
| 2580 | (void) fprintf(vis_stderr, "unknown schedule: %s\n", util_optarg); |
---|
| 2581 | goto usage; |
---|
| 2582 | } else { |
---|
| 2583 | McOptionsSetSchedule(options, schedule); |
---|
| 2584 | } |
---|
| 2585 | inputFp = Cmd_FileOpen(argv[util_optind], "r", NIL(char *), 0); |
---|
| 2586 | if (inputFp == NIL(FILE)) { |
---|
| 2587 | McOptionsFree(options); |
---|
| 2588 | if (guideFileName != NIL(char)) FREE(guideFileName); |
---|
| 2589 | return NIL(McOptions_t); |
---|
| 2590 | } |
---|
| 2591 | McOptionsSetCtlFile(options, inputFp); |
---|
| 2592 | |
---|
| 2593 | if (debugOutName != NIL(char)) { |
---|
| 2594 | debugOut = Cmd_FileOpen(debugOutName, "w", NIL(char *), 0); |
---|
| 2595 | FREE(debugOutName); |
---|
| 2596 | if (debugOut == NIL(FILE)) { |
---|
| 2597 | McOptionsFree(options); |
---|
| 2598 | if (guideFileName != NIL(char)) FREE(guideFileName); |
---|
| 2599 | return NIL(McOptions_t); |
---|
| 2600 | } |
---|
| 2601 | } |
---|
| 2602 | McOptionsSetDebugFile(options, debugOut); |
---|
| 2603 | |
---|
| 2604 | |
---|
| 2605 | if (guideFileName != NIL(char)) { |
---|
| 2606 | guideFile = Cmd_FileOpen(guideFileName, "r", NIL(char *), 0); |
---|
| 2607 | if (guideFile == NIL(FILE)) { |
---|
| 2608 | fprintf(vis_stderr, "** mc error: cannot open guided search file %s.\n", |
---|
| 2609 | guideFileName); |
---|
| 2610 | FREE(guideFileName); |
---|
| 2611 | guideFileName = NIL(char); |
---|
| 2612 | McOptionsFree(options); |
---|
| 2613 | return NIL(McOptions_t); |
---|
| 2614 | } |
---|
| 2615 | FREE(guideFileName); |
---|
| 2616 | guideFileName = NIL(char); |
---|
| 2617 | } |
---|
| 2618 | McOptionsSetGuideFile(options, guideFile); |
---|
| 2619 | |
---|
| 2620 | if (variablesForSystem != NIL(char)) { |
---|
| 2621 | systemFile = Cmd_FileOpen(variablesForSystem, "r", NIL(char *), 0); |
---|
| 2622 | if (systemFile == NIL(FILE)) { |
---|
| 2623 | fprintf(vis_stderr, "** mc error: cannot open system variables file for FAFW %s.\n", |
---|
| 2624 | variablesForSystem); |
---|
| 2625 | FREE(variablesForSystem); |
---|
| 2626 | variablesForSystem = NIL(char); |
---|
| 2627 | McOptionsFree(options); |
---|
| 2628 | return NIL(McOptions_t); |
---|
| 2629 | } |
---|
| 2630 | FREE(variablesForSystem); |
---|
| 2631 | variablesForSystem = NIL(char); |
---|
| 2632 | } |
---|
| 2633 | McOptionsSetVariablesForSystem(options, systemFile); |
---|
| 2634 | |
---|
| 2635 | if ((verbosityLevel != McVerbosityNone_c) && |
---|
| 2636 | (verbosityLevel != McVerbosityLittle_c) && |
---|
| 2637 | (verbosityLevel != McVerbositySome_c) && |
---|
| 2638 | (verbosityLevel != McVerbosityMax_c)) { |
---|
| 2639 | goto usage; |
---|
| 2640 | } |
---|
| 2641 | else { |
---|
| 2642 | McOptionsSetVerbosityLevel(options, verbosityLevel); |
---|
| 2643 | } |
---|
| 2644 | |
---|
| 2645 | if ((dbgLevel != McDbgLevelNone_c) && |
---|
| 2646 | (dbgLevel != McDbgLevelMin_c) && |
---|
| 2647 | (dbgLevel != McDbgLevelMinVerbose_c) && |
---|
| 2648 | (dbgLevel != McDbgLevelMax_c) && |
---|
| 2649 | (dbgLevel != McDbgLevelInteractive_c)) { |
---|
| 2650 | goto usage; |
---|
| 2651 | } |
---|
| 2652 | else { |
---|
| 2653 | McOptionsSetDbgLevel(options, dbgLevel); |
---|
| 2654 | } |
---|
| 2655 | |
---|
| 2656 | if ((dcLevel != McDcLevelNone_c) && |
---|
| 2657 | (dcLevel != McDcLevelRch_c ) && |
---|
| 2658 | (dcLevel != McDcLevelRchFrontier_c ) && |
---|
| 2659 | (dcLevel != McDcLevelArdc_c )) { |
---|
| 2660 | goto usage; |
---|
| 2661 | } |
---|
| 2662 | else { |
---|
| 2663 | McOptionsSetDcLevel(options, dcLevel); |
---|
| 2664 | } |
---|
| 2665 | |
---|
| 2666 | McOptionsSetTraversalDirection(options, traversalDirection); |
---|
| 2667 | if (dcLevel == McDcLevelArdc_c) { |
---|
| 2668 | ardcOptions = Fsm_ArdcAllocOptionsStruct(); |
---|
| 2669 | Fsm_ArdcGetDefaultOptions(ardcOptions); |
---|
| 2670 | } else |
---|
| 2671 | ardcOptions = NIL(Fsm_ArdcOptions_t); |
---|
| 2672 | McOptionsSetArdcOptions(options, ardcOptions); |
---|
| 2673 | |
---|
| 2674 | return options; |
---|
| 2675 | |
---|
| 2676 | usage: |
---|
| 2677 | (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"); |
---|
| 2678 | (void) fprintf(vis_stderr, " -b \tUse backward analysis in debugging\n"); |
---|
| 2679 | (void) fprintf(vis_stderr, " -c \tNo sharing of CTL parse tree. This option does not matter for vacuity detection.\n"); |
---|
| 2680 | (void) fprintf(vis_stderr, " -d <dbg_level>\n"); |
---|
| 2681 | (void) fprintf(vis_stderr, " debug_level = 0 => no debugging (Default)\n"); |
---|
| 2682 | (void) fprintf(vis_stderr, " debug_level = 1 => automatic minimal debugging\n"); |
---|
| 2683 | (void) fprintf(vis_stderr, " debug_level = 2 => automatic minimal debugging with extra verbosity\n"); |
---|
| 2684 | (void) fprintf(vis_stderr, " debug_level = 3 => automatic maximal debugging\n"); |
---|
| 2685 | (void) fprintf(vis_stderr, " debug_level = 4 => interactive debugging\n"); |
---|
| 2686 | (void) fprintf(vis_stderr, " -f <dbg_out>\n"); |
---|
| 2687 | (void) fprintf(vis_stderr, " write error trace to dbg_out\n"); |
---|
| 2688 | (void) fprintf(vis_stderr, " -g <hint_file> \tSpecify file for guided search.\n"); |
---|
| 2689 | (void) fprintf(vis_stderr, " -h \tPrints this usage message.\n"); |
---|
| 2690 | (void) fprintf(vis_stderr, " -i \tPrint input values in debug traces.\n"); |
---|
| 2691 | (void) fprintf(vis_stderr, " -m \tPipe debug output through more.\n"); |
---|
| 2692 | (void) fprintf(vis_stderr, " -r reduce FSM with respect to formula being verified\n"); |
---|
| 2693 | (void) fprintf(vis_stderr, " -t <period> time out period\n"); |
---|
| 2694 | (void) fprintf(vis_stderr, " -v <verbosity_level>\n"); |
---|
| 2695 | (void) fprintf(vis_stderr, " verbosity_level = 0 => no feedback (Default)\n"); |
---|
| 2696 | (void) fprintf(vis_stderr, " verbosity_level = 1 => code status\n"); |
---|
| 2697 | (void) fprintf(vis_stderr, " verbosity_level = 2 => code status and CPU usage profile\n"); |
---|
| 2698 | (void) fprintf(vis_stderr, " -w <node file> \tSpecify variables controlled by system.\n"); |
---|
| 2699 | (void) fprintf(vis_stderr, " -B vacuity detection for w-ACTL formulae using method of Beer et al \n"); |
---|
| 2700 | (void) fprintf(vis_stderr, " -C Compute coverage of all observable signals using Hoskote et.al's implementation\n"); |
---|
| 2701 | (void) fprintf(vis_stderr, " -D <dc_level>\n"); |
---|
| 2702 | (void) fprintf(vis_stderr, " dc_level = 0 => no use of don't cares\n"); |
---|
| 2703 | (void) fprintf(vis_stderr, " dc_level = 1 => use unreached states as don't cares (Default)\n"); |
---|
| 2704 | (void) fprintf(vis_stderr, " dc_level = 2 => use unreached states as don't cares\n"); |
---|
| 2705 | |
---|
| 2706 | (void) fprintf(vis_stderr, " and aggressive use of DC's to simplify MDD's\n"); |
---|
| 2707 | (void) fprintf(vis_stderr, " dc_level = 3 => use over-approximate unreached states as don't cares\n"); |
---|
| 2708 | (void) fprintf(vis_stderr, " and aggressive use of DC's to simplify MDD's\n"); |
---|
| 2709 | (void) fprintf(vis_stderr, " -F \tUse forward model checking.\n"); |
---|
| 2710 | (void) fprintf(vis_stderr, " -G \tUse general fate and free will algorithm.\n"); |
---|
| 2711 | (void) fprintf(vis_stderr, " -I Compute coverage of all observable signals using improved coverage implementation\n"); |
---|
| 2712 | (void) fprintf(vis_stderr, " -S <schedule>\n"); |
---|
| 2713 | (void) fprintf(vis_stderr, " schedule is one of {EL,EL1,EL2,budget,random,off}\n"); |
---|
| 2714 | (void) fprintf(vis_stderr, " -V thorough vacuity detection\n"); |
---|
| 2715 | (void) fprintf(vis_stderr, " -W \tUse fate and free will algorithm when all the variables are controlled by system.\n"); |
---|
| 2716 | (void) fprintf(vis_stderr, " <ctl_file> The input file containing CTL formula to be checked.\n"); |
---|
| 2717 | |
---|
| 2718 | if (guideFileName != NIL(char)) FREE(guideFileName); |
---|
| 2719 | McOptionsFree(options); |
---|
| 2720 | |
---|
| 2721 | return NIL(McOptions_t); |
---|
| 2722 | } |
---|
| 2723 | |
---|
| 2724 | |
---|
| 2725 | /**Function******************************************************************** |
---|
| 2726 | |
---|
| 2727 | Synopsis [] |
---|
| 2728 | |
---|
| 2729 | Description [Refer to 'static int CommandPrintModels (Hrc_Manager_t **hmgr, |
---|
| 2730 | int argc, char **argv)' function in hrcCmd.c] |
---|
| 2731 | |
---|
| 2732 | SideEffects [] |
---|
| 2733 | |
---|
| 2734 | SeeAlso [] |
---|
| 2735 | |
---|
| 2736 | ******************************************************************************/ |
---|
| 2737 | |
---|
| 2738 | static int print_modelsMine(Hrc_Manager_t **hmgr, int argc, char **argv) |
---|
| 2739 | { |
---|
| 2740 | |
---|
| 2741 | (void) fprintf(vis_stderr, "*** 'print_models' begins. *** \n"); |
---|
| 2742 | |
---|
| 2743 | st_generator *gen; |
---|
| 2744 | char *name; |
---|
| 2745 | Hrc_Model_t *model; |
---|
| 2746 | Hrc_Node_t *node; |
---|
| 2747 | int c; |
---|
| 2748 | |
---|
| 2749 | util_getopt_reset(); |
---|
| 2750 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
| 2751 | switch(c){ |
---|
| 2752 | case 'h': |
---|
| 2753 | goto usage; |
---|
| 2754 | default: |
---|
| 2755 | goto usage; |
---|
| 2756 | } |
---|
| 2757 | } |
---|
| 2758 | if(argc != 1) { |
---|
| 2759 | goto usage; |
---|
| 2760 | } |
---|
| 2761 | |
---|
| 2762 | node = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 2763 | if (node == NIL(Hrc_Node_t)){ |
---|
| 2764 | (void)fprintf(vis_stderr,"No file has been read in.\n"); |
---|
| 2765 | return 1; |
---|
| 2766 | } |
---|
| 2767 | |
---|
| 2768 | Hrc_ManagerForEachModel(*hmgr, gen, name, model) { |
---|
| 2769 | PrintNodeStats(Hrc_ModelReadMasterNode(model), FALSE); |
---|
| 2770 | (void) fprintf(vis_stdout, "subckts = %d\n", |
---|
| 2771 | st_count(Hrc_ModelReadSubcktTable(model))); |
---|
| 2772 | } |
---|
| 2773 | return 0; |
---|
| 2774 | |
---|
| 2775 | usage: |
---|
| 2776 | (void) fprintf(vis_stderr, "usage: print_models [-h]\n"); |
---|
| 2777 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
| 2778 | return 1; |
---|
| 2779 | |
---|
| 2780 | } |
---|
| 2781 | |
---|
| 2782 | /**Function******************************************************************** |
---|
| 2783 | |
---|
| 2784 | Synopsis [This function prints the statistics of a node.] |
---|
| 2785 | |
---|
| 2786 | SideEffects [] |
---|
| 2787 | |
---|
| 2788 | SeeAlso [] |
---|
| 2789 | |
---|
| 2790 | ******************************************************************************/ |
---|
| 2791 | static void |
---|
| 2792 | PrintNodeStats( |
---|
| 2793 | Hrc_Node_t *node, |
---|
| 2794 | boolean isHnode) |
---|
| 2795 | { |
---|
| 2796 | (void) fprintf(vis_stdout, "Model name = %s", Hrc_NodeReadModelName(node)); |
---|
| 2797 | if(isHnode) { |
---|
| 2798 | (void) fprintf(vis_stdout, ", Instance name = %s\n", |
---|
| 2799 | Hrc_NodeReadInstanceName(node)); |
---|
| 2800 | } |
---|
| 2801 | else { |
---|
| 2802 | (void) fprintf(vis_stdout, "\n"); |
---|
| 2803 | } |
---|
| 2804 | (void) fprintf(vis_stdout, "inputs = %d,", Hrc_NodeReadNumFormalInputs(node)); |
---|
| 2805 | (void) fprintf(vis_stdout, " outputs = %d,", Hrc_NodeReadNumFormalOutputs(node)); |
---|
| 2806 | (void) fprintf(vis_stdout, " variables = %d,", Hrc_NodeReadNumVariables(node)); |
---|
| 2807 | (void) fprintf(vis_stdout, " tables = %d,", Hrc_NodeReadNumTables(node)); |
---|
| 2808 | (void) fprintf(vis_stdout, " latches = %d", Hrc_NodeReadNumLatches(node)); |
---|
| 2809 | if(isHnode) { |
---|
| 2810 | (void) fprintf(vis_stdout, ", children = %d\n", Hrc_NodeReadNumChildren(node)); |
---|
| 2811 | } |
---|
| 2812 | else { |
---|
| 2813 | (void) fprintf(vis_stdout, "\n"); |
---|
| 2814 | } |
---|
| 2815 | } |
---|
| 2816 | |
---|
| 2817 | /**Function******************************************************************** |
---|
| 2818 | |
---|
| 2819 | Synopsis [returns child or parent node (it is actually the current node)] |
---|
| 2820 | |
---|
| 2821 | Description [Refer to 'static int CommandCd (Hrc_Manager_t **hmgr, |
---|
| 2822 | int argc, char **argv)' function in hrcCmd.c] |
---|
| 2823 | |
---|
| 2824 | SideEffects [] |
---|
| 2825 | |
---|
| 2826 | SeeAlso [] |
---|
| 2827 | |
---|
| 2828 | ******************************************************************************/ |
---|
| 2829 | static Hrc_Node_t *cdMine(Hrc_Manager_t **hmgr, int argc, char **argv) |
---|
| 2830 | { |
---|
| 2831 | |
---|
| 2832 | (void) fprintf(vis_stderr, "*** 'cd' begins. *** \n"); |
---|
| 2833 | |
---|
| 2834 | Hrc_Node_t *currentNode, *parent, *child; |
---|
| 2835 | int c; |
---|
| 2836 | |
---|
| 2837 | util_getopt_reset(); |
---|
| 2838 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
| 2839 | switch(c){ |
---|
| 2840 | case 'h': |
---|
| 2841 | goto usage; |
---|
| 2842 | default: |
---|
| 2843 | goto usage; |
---|
| 2844 | } |
---|
| 2845 | } |
---|
| 2846 | |
---|
| 2847 | if (argc != 2){ |
---|
| 2848 | goto usage; |
---|
| 2849 | } |
---|
| 2850 | |
---|
| 2851 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 2852 | if (currentNode == NIL(Hrc_Node_t)){ |
---|
| 2853 | (void)fprintf(vis_stdout,"No file has been read in.\n"); |
---|
| 2854 | return NIL(Hrc_Node_t); |
---|
| 2855 | } |
---|
| 2856 | /* go to the parent node */ |
---|
| 2857 | if (strcmp(*(++argv),"..") == 0){ |
---|
| 2858 | if ((parent = Hrc_NodeReadParentNode(currentNode)) == NIL(Hrc_Node_t)){ |
---|
| 2859 | (void)fprintf(vis_stderr,"You are at the root node. Can't cd to a parent.\n"); |
---|
| 2860 | return currentNode; |
---|
| 2861 | } |
---|
| 2862 | Hrc_ManagerSetCurrentNode(*hmgr,parent); |
---|
| 2863 | return parent; |
---|
| 2864 | } |
---|
| 2865 | |
---|
| 2866 | if ((child = Hrc_NodeFindChildByName(currentNode,*argv)) == NIL(Hrc_Node_t)){ |
---|
| 2867 | (void)fprintf(vis_stderr,"No child node whose name is %s exists in the current node.\n",*argv); |
---|
| 2868 | return currentNode; |
---|
| 2869 | } |
---|
| 2870 | Hrc_ManagerSetCurrentNode(*hmgr,child); |
---|
| 2871 | return child; |
---|
| 2872 | |
---|
| 2873 | usage: |
---|
| 2874 | (void)fprintf(vis_stderr,"usage: cd [-h] child_name or cd ..\n"); |
---|
| 2875 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
| 2876 | return NIL(Hrc_Node_t); |
---|
| 2877 | } |
---|
| 2878 | |
---|
| 2879 | |
---|
| 2880 | /**Function******************************************************************** |
---|
| 2881 | |
---|
| 2882 | Synopsis [returns current node] |
---|
| 2883 | |
---|
| 2884 | Description [Refer to 'static int CommandLs (Hrc_Manager_t **hmgr, |
---|
| 2885 | int argc, char **argv)' function in hrcCmd.c] |
---|
| 2886 | |
---|
| 2887 | SideEffects [] |
---|
| 2888 | |
---|
| 2889 | SeeAlso [] |
---|
| 2890 | |
---|
| 2891 | ******************************************************************************/ |
---|
| 2892 | static Hrc_Node_t *lsMine(Hrc_Manager_t **hmgr, int argc, char **argv){ |
---|
| 2893 | |
---|
| 2894 | (void) fprintf(vis_stderr, "*** 'ls' begins. *** \n"); |
---|
| 2895 | |
---|
| 2896 | int recursiveFlag = 0; |
---|
| 2897 | int c; |
---|
| 2898 | Hrc_Node_t *currentNode; |
---|
| 2899 | |
---|
| 2900 | util_getopt_reset(); |
---|
| 2901 | while ((c = util_getopt(argc, argv, "hR")) != EOF) { |
---|
| 2902 | switch(c){ |
---|
| 2903 | case 'h': |
---|
| 2904 | goto usage; |
---|
| 2905 | case 'R': |
---|
| 2906 | recursiveFlag = 1; |
---|
| 2907 | break; |
---|
| 2908 | default: |
---|
| 2909 | goto usage; |
---|
| 2910 | } |
---|
| 2911 | } |
---|
| 2912 | /* if there are some arguments for ls */ |
---|
| 2913 | if (argc != util_optind){ |
---|
| 2914 | goto usage; |
---|
| 2915 | } |
---|
| 2916 | |
---|
| 2917 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 2918 | if (currentNode == NIL(Hrc_Node_t)){ |
---|
| 2919 | (void)fprintf(vis_stdout,"No file has been read in.\n"); |
---|
| 2920 | return NIL(Hrc_Node_t); |
---|
| 2921 | } |
---|
| 2922 | NodeListChildren(currentNode, recursiveFlag, 0); |
---|
| 2923 | return currentNode; |
---|
| 2924 | |
---|
| 2925 | usage: |
---|
| 2926 | (void)fprintf(vis_stderr,"usage: ls [-h] [-R]\n"); |
---|
| 2927 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
| 2928 | (void) fprintf(vis_stderr, " -R \t\tprint recursive tree\n"); |
---|
| 2929 | |
---|
| 2930 | return NIL(Hrc_Node_t); |
---|
| 2931 | |
---|
| 2932 | } |
---|
| 2933 | |
---|
| 2934 | |
---|
| 2935 | /**Function******************************************************************** |
---|
| 2936 | |
---|
| 2937 | Synopsis [] |
---|
| 2938 | |
---|
| 2939 | Description [Refer to 'static int CommandPwd (Hrc_Manager_t **hmgr, |
---|
| 2940 | int argc, char **argv)' function in hrcCmd.c] |
---|
| 2941 | |
---|
| 2942 | SideEffects [] |
---|
| 2943 | |
---|
| 2944 | SeeAlso [] |
---|
| 2945 | |
---|
| 2946 | ******************************************************************************/ |
---|
| 2947 | static char *pwdMine(Hrc_Manager_t **hmgr, int argc, char **argv){ |
---|
| 2948 | |
---|
| 2949 | (void) fprintf(vis_stderr, "*** 'pwd' begins. *** \n"); |
---|
| 2950 | |
---|
| 2951 | Hrc_Node_t *currentNode; |
---|
| 2952 | Hrc_Node_t *rootNode; |
---|
| 2953 | char *separator, *hierarchicalName; |
---|
| 2954 | int c; |
---|
| 2955 | |
---|
| 2956 | util_getopt_reset(); |
---|
| 2957 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
| 2958 | switch(c){ |
---|
| 2959 | case 'h': |
---|
| 2960 | goto usage; |
---|
| 2961 | default: |
---|
| 2962 | goto usage; |
---|
| 2963 | } |
---|
| 2964 | } |
---|
| 2965 | if (argc != 1){ |
---|
| 2966 | goto usage; |
---|
| 2967 | } |
---|
| 2968 | |
---|
| 2969 | currentNode = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 2970 | if (currentNode == NIL(Hrc_Node_t)){ |
---|
| 2971 | (void)fprintf(vis_stdout,"No file has been read in.\n"); |
---|
| 2972 | return NIL(char); |
---|
| 2973 | } |
---|
| 2974 | rootNode = Hrc_ManagerReadRootNode(*hmgr); |
---|
| 2975 | separator = (char *) ((rootNode == currentNode) ? "" : "."); |
---|
| 2976 | hierarchicalName = Hrc_NodeFindHierarchicalName(currentNode, FALSE); |
---|
| 2977 | (void)fprintf(vis_stdout,"%s%s%s\n", Hrc_NodeReadInstanceName(rootNode), |
---|
| 2978 | separator, hierarchicalName); |
---|
| 2979 | (void) sprintf(currentPath, "%s%s%s", Hrc_NodeReadInstanceName(rootNode), separator, hierarchicalName); |
---|
| 2980 | FREE(hierarchicalName); |
---|
| 2981 | return currentPath; |
---|
| 2982 | |
---|
| 2983 | usage: |
---|
| 2984 | (void)fprintf(vis_stderr,"usage: pwd [-h]\n"); |
---|
| 2985 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
| 2986 | return NIL(char); |
---|
| 2987 | |
---|
| 2988 | } |
---|
| 2989 | |
---|
| 2990 | |
---|
| 2991 | /**Function******************************************************************** |
---|
| 2992 | |
---|
| 2993 | Synopsis [] |
---|
| 2994 | |
---|
| 2995 | Description [Refer to 'static int CommandPrintLatches (Hrc_Manager_t **hmgr, |
---|
| 2996 | int argc, char **argv)' function in hrcCmd.c] |
---|
| 2997 | |
---|
| 2998 | SideEffects [] |
---|
| 2999 | |
---|
| 3000 | SeeAlso [] |
---|
| 3001 | |
---|
| 3002 | ******************************************************************************/ |
---|
| 3003 | static int print_latchesMine(Hrc_Manager_t **hmgr, int argc, char **argv){ |
---|
| 3004 | |
---|
| 3005 | (void) fprintf(vis_stderr, "*** 'print_latches' begins. *** \n"); |
---|
| 3006 | |
---|
| 3007 | int c, i; |
---|
| 3008 | Hrc_Node_t *node; |
---|
| 3009 | st_generator *gen; |
---|
| 3010 | char *latchName; |
---|
| 3011 | Hrc_Latch_t *latch; |
---|
| 3012 | array_t *tmpArray; |
---|
| 3013 | |
---|
| 3014 | util_getopt_reset(); |
---|
| 3015 | while ((c = util_getopt(argc, argv, "h")) != EOF) { |
---|
| 3016 | switch(c){ |
---|
| 3017 | case 'h': |
---|
| 3018 | goto usage; |
---|
| 3019 | default: |
---|
| 3020 | goto usage; |
---|
| 3021 | } |
---|
| 3022 | } |
---|
| 3023 | /* if there are some arguments left */ |
---|
| 3024 | if (argc != util_optind){ |
---|
| 3025 | goto usage; |
---|
| 3026 | } |
---|
| 3027 | node = Hrc_ManagerReadCurrentNode(*hmgr); |
---|
| 3028 | if (node == NIL(Hrc_Node_t)){ |
---|
| 3029 | (void)fprintf(vis_stderr,"No file has been read in.\n"); |
---|
| 3030 | return 1; |
---|
| 3031 | } |
---|
| 3032 | |
---|
| 3033 | if (Hrc_NodeReadNumLatches(node) == 0){ |
---|
| 3034 | fprintf(vis_stdout,"No latches\n"); |
---|
| 3035 | } |
---|
| 3036 | else { |
---|
| 3037 | tmpArray = array_alloc(char *,0); |
---|
| 3038 | Hrc_NodeForEachLatch(node,gen,latchName,latch){ |
---|
| 3039 | array_insert_last(char *,tmpArray,latchName); |
---|
| 3040 | } |
---|
| 3041 | array_sort(tmpArray,_HrcStringCmp); |
---|
| 3042 | for (i=0; i < array_n(tmpArray); i++){ |
---|
| 3043 | fprintf(vis_stdout,"%s ",array_fetch(char *,tmpArray,i)); |
---|
| 3044 | } |
---|
| 3045 | fprintf(vis_stdout,"\n"); |
---|
| 3046 | array_free(tmpArray); |
---|
| 3047 | } |
---|
| 3048 | return 0; |
---|
| 3049 | |
---|
| 3050 | usage: |
---|
| 3051 | (void) fprintf(vis_stderr,"usage: print_latches [-h]\n"); |
---|
| 3052 | (void) fprintf(vis_stderr, " -h \t\tprint the command usage\n"); |
---|
| 3053 | return 1; |
---|
| 3054 | } |
---|
| 3055 | |
---|
| 3056 | /**Function******************************************************************** |
---|
| 3057 | |
---|
| 3058 | Synopsis [Converts a string to an order type.] |
---|
| 3059 | |
---|
| 3060 | Description [Converts a string to an order type. If string does not refer to |
---|
| 3061 | one of the allowed order types, then returns Ord_Unassigned_c.] |
---|
| 3062 | |
---|
| 3063 | SideEffects [] |
---|
| 3064 | |
---|
| 3065 | ******************************************************************************/ |
---|
| 3066 | static Ord_OrderType |
---|
| 3067 | StringConvertToOrderType( |
---|
| 3068 | char *string) |
---|
| 3069 | { |
---|
| 3070 | if (strcmp("all", string) == 0) { |
---|
| 3071 | return Ord_All_c; |
---|
| 3072 | } |
---|
| 3073 | else if (strcmp("input_and_latch", string) == 0) { |
---|
| 3074 | return Ord_InputAndLatch_c; |
---|
| 3075 | } |
---|
| 3076 | else if (strcmp("next_state_node", string) == 0) { |
---|
| 3077 | return Ord_NextStateNode_c; |
---|
| 3078 | } |
---|
| 3079 | else if (strcmp("partial", string) == 0) { |
---|
| 3080 | return Ord_Partial_c; |
---|
| 3081 | } |
---|
| 3082 | else { |
---|
| 3083 | return Ord_Unassigned_c; |
---|
| 3084 | } |
---|
| 3085 | } |
---|
| 3086 | |
---|
| 3087 | |
---|
| 3088 | /**Function******************************************************************** |
---|
| 3089 | |
---|
| 3090 | Synopsis [The core routine for the command ls.] |
---|
| 3091 | |
---|
| 3092 | Description [The core routine for the command ls. If the second argument |
---|
| 3093 | is set to 1, it calls the ls routine recursively all the way down to leaves.] |
---|
| 3094 | |
---|
| 3095 | SideEffects [] |
---|
| 3096 | |
---|
| 3097 | SeeAlso [] |
---|
| 3098 | |
---|
| 3099 | ******************************************************************************/ |
---|
| 3100 | static void |
---|
| 3101 | NodeListChildren( |
---|
| 3102 | Hrc_Node_t *hnode, |
---|
| 3103 | boolean recursiveFlag, |
---|
| 3104 | int depth) |
---|
| 3105 | { |
---|
| 3106 | st_generator *gen; |
---|
| 3107 | char *childName; |
---|
| 3108 | Hrc_Node_t *child; |
---|
| 3109 | int newDepth, i; |
---|
| 3110 | array_t *tmpArray; |
---|
| 3111 | |
---|
| 3112 | newDepth = depth + 1; |
---|
| 3113 | tmpArray = array_alloc(char *,0); |
---|
| 3114 | Hrc_NodeForEachChild(hnode,gen,childName,child){ |
---|
| 3115 | array_insert_last(char *,tmpArray,childName); |
---|
| 3116 | } |
---|
| 3117 | array_sort(tmpArray,_HrcStringCmp); |
---|
| 3118 | for (i=0; i < array_n(tmpArray); i++){ |
---|
| 3119 | PrintSpace(depth); |
---|
| 3120 | childName = array_fetch(char *,tmpArray,i); |
---|
| 3121 | (void)fprintf(vis_stdout,"%s\n",childName); |
---|
| 3122 | if (recursiveFlag == 1){ |
---|
| 3123 | NodeListChildren(Hrc_NodeFindChildByName(hnode,childName),recursiveFlag,newDepth); |
---|
| 3124 | } |
---|
| 3125 | } |
---|
| 3126 | array_free(tmpArray); |
---|
| 3127 | } |
---|
| 3128 | |
---|
| 3129 | /**Function******************************************************************** |
---|
| 3130 | |
---|
| 3131 | Synopsis [The core routine for the command ls. Returns array_t] |
---|
| 3132 | |
---|
| 3133 | Description [The core routine for the command ls. If the second argument |
---|
| 3134 | is set to 1, it calls the ls routine recursively all the way down to leaves.] |
---|
| 3135 | |
---|
| 3136 | SideEffects [] |
---|
| 3137 | |
---|
| 3138 | SeeAlso [] |
---|
| 3139 | |
---|
| 3140 | ******************************************************************************/ |
---|
| 3141 | static array_t *NodeListChildrenMine(Hrc_Node_t *hnode, boolean recursiveFlag, int depth){ |
---|
| 3142 | |
---|
| 3143 | st_generator *gen; |
---|
| 3144 | char *childName; |
---|
| 3145 | Hrc_Node_t *child; |
---|
| 3146 | int newDepth, i; |
---|
| 3147 | array_t *tmpArray; |
---|
| 3148 | |
---|
| 3149 | newDepth = depth + 1; |
---|
| 3150 | tmpArray = array_alloc(char *,0); |
---|
| 3151 | Hrc_NodeForEachChild(hnode,gen,childName,child){ |
---|
| 3152 | array_insert_last(char *,tmpArray,childName); |
---|
| 3153 | } |
---|
| 3154 | array_sort(tmpArray,_HrcStringCmp); |
---|
| 3155 | for (i=0; i < array_n(tmpArray); i++){ |
---|
| 3156 | PrintSpace(depth); |
---|
| 3157 | childName = array_fetch(char *,tmpArray,i); |
---|
| 3158 | (void)fprintf(vis_stdout,"%s\n",childName); |
---|
| 3159 | if (recursiveFlag == 1){ |
---|
| 3160 | NodeListChildren(Hrc_NodeFindChildByName(hnode,childName),recursiveFlag,newDepth); |
---|
| 3161 | } |
---|
| 3162 | } |
---|
| 3163 | // array_free(tmpArray); |
---|
| 3164 | return tmpArray; |
---|
| 3165 | } |
---|
| 3166 | |
---|
| 3167 | /**Function******************************************************************** |
---|
| 3168 | |
---|
| 3169 | Synopsis [Prints out spaces.] |
---|
| 3170 | |
---|
| 3171 | SideEffects [] |
---|
| 3172 | |
---|
| 3173 | SeeAlso [] |
---|
| 3174 | |
---|
| 3175 | ******************************************************************************/ |
---|
| 3176 | static void |
---|
| 3177 | PrintSpace(int depth) |
---|
| 3178 | { |
---|
| 3179 | int i; |
---|
| 3180 | for (i=0; i < depth; i++){ |
---|
| 3181 | (void)fprintf(vis_stdout," "); |
---|
| 3182 | } |
---|
| 3183 | } |
---|
| 3184 | |
---|
| 3185 | |
---|
| 3186 | /**Function******************************************************************** |
---|
| 3187 | |
---|
| 3188 | Synopsis [Verifies that suppliedNodeList has the correct nodes.] |
---|
| 3189 | |
---|
| 3190 | Description [Returns TRUE if the set of nodes in suppliedNodeList matches |
---|
| 3191 | the set of nodes in network specified by orderType; else returns FALSE and |
---|
| 3192 | writes a message to error_string. OrderType should be one of the following: |
---|
| 3193 | 1) Ord_All_c: should match the set of all nodes in network; 2) |
---|
| 3194 | Ord_InputAndLatch_c: should match the set of inputs (primary + pseudo), |
---|
| 3195 | latches, and next state nodes; 3) Ord_NextStateNode_c: should match the set |
---|
| 3196 | of next state nodes; number should be the number of latches; 4) |
---|
| 3197 | Ord_Partial_c: returns TRUE automatically.] |
---|
| 3198 | |
---|
| 3199 | SideEffects [] |
---|
| 3200 | |
---|
| 3201 | ******************************************************************************/ |
---|
| 3202 | static boolean |
---|
| 3203 | NetworkCheckSuppliedNodeList( |
---|
| 3204 | Ntk_Network_t * network, |
---|
| 3205 | lsList suppliedNodeList, |
---|
| 3206 | Ord_OrderType orderType) |
---|
| 3207 | { |
---|
| 3208 | lsGen gen; |
---|
| 3209 | st_generator *stGen; |
---|
| 3210 | Ntk_Node_t *node; |
---|
| 3211 | st_table *requiredNodes; |
---|
| 3212 | st_table *suppliedNodes; |
---|
| 3213 | char *dummy; |
---|
| 3214 | boolean returnFlag = TRUE; |
---|
| 3215 | |
---|
| 3216 | assert(orderType != Ord_Unassigned_c); |
---|
| 3217 | |
---|
| 3218 | if (orderType == Ord_Partial_c) { |
---|
| 3219 | return TRUE; |
---|
| 3220 | } |
---|
| 3221 | |
---|
| 3222 | /* At this point, orderType must be one of the these. */ |
---|
| 3223 | assert((orderType == Ord_All_c) || (orderType == Ord_InputAndLatch_c) |
---|
| 3224 | || (orderType == Ord_NextStateNode_c)); |
---|
| 3225 | |
---|
| 3226 | |
---|
| 3227 | /* |
---|
| 3228 | * Build up the table of required nodes. Next state nodes are included by |
---|
| 3229 | * all 3 order types. |
---|
| 3230 | */ |
---|
| 3231 | requiredNodes = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 3232 | Ntk_NetworkForEachNode(network, gen, node) { |
---|
| 3233 | if ((orderType == Ord_All_c) || Ntk_NodeTestIsNextStateNode(node)) { |
---|
| 3234 | st_insert(requiredNodes, (char *) node, NIL(char)); |
---|
| 3235 | } |
---|
| 3236 | else if ((orderType == Ord_InputAndLatch_c) |
---|
| 3237 | && Ntk_NodeTestIsCombInput(node)) { |
---|
| 3238 | st_insert(requiredNodes, (char *) node, NIL(char)); |
---|
| 3239 | } |
---|
| 3240 | /* else, this node is not included by orderType */ |
---|
| 3241 | } |
---|
| 3242 | |
---|
| 3243 | /* |
---|
| 3244 | * Convert suppliedNodeList to the table of supplied nodes. |
---|
| 3245 | */ |
---|
| 3246 | suppliedNodes = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 3247 | lsForEachItem(suppliedNodeList, gen, node) { |
---|
| 3248 | int status = st_insert(suppliedNodes, (char *) node, NIL(char)); |
---|
| 3249 | if (status) { |
---|
| 3250 | error_append("node "); |
---|
| 3251 | error_append(Ntk_NodeReadName(node)); |
---|
| 3252 | error_append(" appears more than once in ordering file\n"); |
---|
| 3253 | returnFlag = FALSE; |
---|
| 3254 | } |
---|
| 3255 | } |
---|
| 3256 | |
---|
| 3257 | /* |
---|
| 3258 | * Check that suppliedNodes is contained in requiredNodes. |
---|
| 3259 | */ |
---|
| 3260 | st_foreach_item(suppliedNodes, stGen, &node, &dummy) { |
---|
| 3261 | if (!st_is_member(requiredNodes, node)) { |
---|
| 3262 | error_append("node "); |
---|
| 3263 | error_append(Ntk_NodeReadName(node)); |
---|
| 3264 | error_append(" supplied but not required\n"); |
---|
| 3265 | returnFlag = FALSE; |
---|
| 3266 | } |
---|
| 3267 | } |
---|
| 3268 | |
---|
| 3269 | /* |
---|
| 3270 | * Check that suppliedNodes is contained in requiredNodes. |
---|
| 3271 | */ |
---|
| 3272 | st_foreach_item(requiredNodes, stGen, &node, &dummy) { |
---|
| 3273 | if (!st_is_member(suppliedNodes, node)) { |
---|
| 3274 | error_append("node "); |
---|
| 3275 | error_append(Ntk_NodeReadName(node)); |
---|
| 3276 | error_append(" required but not supplied\n"); |
---|
| 3277 | returnFlag = FALSE; |
---|
| 3278 | } |
---|
| 3279 | } |
---|
| 3280 | |
---|
| 3281 | st_free_table(requiredNodes); |
---|
| 3282 | st_free_table(suppliedNodes); |
---|
| 3283 | return returnFlag; |
---|
| 3284 | } |
---|
| 3285 | |
---|
| 3286 | /**Function******************************************************************** |
---|
| 3287 | |
---|
| 3288 | Synopsis [Returns a list of names corresponding to the names in a file.] |
---|
| 3289 | |
---|
| 3290 | Description [Parses a file and builds a name list corresponding to the names |
---|
| 3291 | found in the first "column" of each line of the file. Any line starting |
---|
| 3292 | with the comment character '#' or white space is ignored. No checks are |
---|
| 3293 | made to see if the names are well-formed in any respect. If a problem is |
---|
| 3294 | found while parsing the file (e.g. name length exceeded), then a message is |
---|
| 3295 | written to error_string, the partial name list is freed, and the function |
---|
| 3296 | returns FALSE; otherwise, it returns TRUE, and a pointer to a list is |
---|
| 3297 | returned.] |
---|
| 3298 | |
---|
| 3299 | Comment [The parser consists of 3 states. See the documentation |
---|
| 3300 | accompanying the #defines defining the state names. This code was adapted |
---|
| 3301 | from Ord_FileReadNodeList.] |
---|
| 3302 | |
---|
| 3303 | SideEffects [] |
---|
| 3304 | |
---|
| 3305 | ******************************************************************************/ |
---|
| 3306 | static boolean |
---|
| 3307 | FileReadNameList( |
---|
| 3308 | FILE * fp, |
---|
| 3309 | lsList * nameList /* of char *, for return */, |
---|
| 3310 | int verbose) |
---|
| 3311 | { |
---|
| 3312 | int c; |
---|
| 3313 | int state; |
---|
| 3314 | int curPosition = 0; |
---|
| 3315 | char *name; |
---|
| 3316 | char string[MAX_NAME_LENGTH]; |
---|
| 3317 | boolean returnFlag = TRUE; |
---|
| 3318 | |
---|
| 3319 | *nameList = lsCreate(); |
---|
| 3320 | |
---|
| 3321 | state = STATE_TEST; |
---|
| 3322 | while ((c = fgetc(fp)) != EOF) { |
---|
| 3323 | |
---|
| 3324 | switch (state) { |
---|
| 3325 | case STATE_TEST: |
---|
| 3326 | /* At start of a new line. */ |
---|
| 3327 | if (c == '#') { |
---|
| 3328 | /* Line starting with comment character; wait for newline */ |
---|
| 3329 | state = STATE_WAIT; |
---|
| 3330 | } |
---|
| 3331 | else if ((c == ' ') || (c == '\t')) { |
---|
| 3332 | /* Line starting with white space; wait for newline */ |
---|
| 3333 | state = STATE_WAIT; |
---|
| 3334 | } |
---|
| 3335 | else if (c == '\n') { |
---|
| 3336 | /* Line starting with newline; go to next line */ |
---|
| 3337 | state = STATE_TEST; |
---|
| 3338 | } |
---|
| 3339 | else { |
---|
| 3340 | /* Assume starting a name. */ |
---|
| 3341 | curPosition = 0; |
---|
| 3342 | string[curPosition++] = c; |
---|
| 3343 | state = STATE_IN; |
---|
| 3344 | } |
---|
| 3345 | break; |
---|
| 3346 | case STATE_WAIT: |
---|
| 3347 | /* |
---|
| 3348 | * Waiting for the newline character. |
---|
| 3349 | */ |
---|
| 3350 | state = (c == '\n') ? STATE_TEST : STATE_WAIT; |
---|
| 3351 | break; |
---|
| 3352 | case STATE_IN: |
---|
| 3353 | /* |
---|
| 3354 | * Parsing a name. If white space reached, then terminate the |
---|
| 3355 | * name and process it. Else, continue parsing. |
---|
| 3356 | */ |
---|
| 3357 | if ((c == ' ') || (c == '\n') || (c == '\t')) { |
---|
| 3358 | string[curPosition] = '\0'; |
---|
| 3359 | name = util_strsav(string); |
---|
| 3360 | if (verbose > 1) { |
---|
| 3361 | (void) fprintf(vis_stdout, "Reading name: %s\n", name); |
---|
| 3362 | } |
---|
| 3363 | (void) lsNewEnd(*nameList, (lsGeneric) name, LS_NH); |
---|
| 3364 | |
---|
| 3365 | state = (c == '\n') ? STATE_TEST : STATE_WAIT; |
---|
| 3366 | } |
---|
| 3367 | else { |
---|
| 3368 | string[curPosition++] = c; |
---|
| 3369 | if (curPosition >= MAX_NAME_LENGTH) { |
---|
| 3370 | error_append("maximum name length exceeded"); |
---|
| 3371 | returnFlag = FALSE; |
---|
| 3372 | } |
---|
| 3373 | state = STATE_IN; /* redundant, but be explicit */ |
---|
| 3374 | } |
---|
| 3375 | break; |
---|
| 3376 | default: |
---|
| 3377 | fail("unrecognized state"); |
---|
| 3378 | } |
---|
| 3379 | } |
---|
| 3380 | |
---|
| 3381 | /* |
---|
| 3382 | * Handle case where EOF terminates a name. |
---|
| 3383 | */ |
---|
| 3384 | if (state == STATE_IN) { |
---|
| 3385 | string[curPosition] = '\0'; |
---|
| 3386 | name = util_strsav(string); |
---|
| 3387 | if (verbose > 1) { |
---|
| 3388 | (void) fprintf(vis_stdout, "Reading name: %s\n", name); |
---|
| 3389 | } |
---|
| 3390 | (void) lsNewEnd(*nameList, (lsGeneric) name, LS_NH); |
---|
| 3391 | |
---|
| 3392 | } |
---|
| 3393 | |
---|
| 3394 | if (returnFlag) { |
---|
| 3395 | return TRUE; |
---|
| 3396 | } |
---|
| 3397 | else { |
---|
| 3398 | (void) lsDestroy(*nameList, (void (*) (lsGeneric)) NULL); |
---|
| 3399 | return FALSE; |
---|
| 3400 | } |
---|
| 3401 | } |
---|
| 3402 | |
---|
| 3403 | /**Function******************************************************************** |
---|
| 3404 | |
---|
| 3405 | Synopsis [Initilizes all the global variables used in the parser.] |
---|
| 3406 | |
---|
| 3407 | Description [] |
---|
| 3408 | |
---|
| 3409 | SideEffects [] |
---|
| 3410 | |
---|
| 3411 | SeeAlso [] |
---|
| 3412 | |
---|
| 3413 | ******************************************************************************/ |
---|
| 3414 | static void |
---|
| 3415 | _IoGlobalVariablesInitialize(void) |
---|
| 3416 | { |
---|
| 3417 | globalLineNumber = 1; |
---|
| 3418 | globalModel = NIL(Hrc_Model_t); |
---|
| 3419 | globalHnode = NIL(Hrc_Node_t); |
---|
| 3420 | globalFirstModel = NIL(Hrc_Model_t); /* set once */ |
---|
| 3421 | globalRootModel = NIL(Hrc_Model_t); /* set once */ |
---|
| 3422 | globalRootInstanceName = NIL(char); /* set once */ |
---|
| 3423 | globalMvNameArray = NIL(array_t); |
---|
| 3424 | globalSymValueArray = NIL(array_t); |
---|
| 3425 | globalTableInputArray = NIL(array_t); |
---|
| 3426 | globalTableOutputArray = NIL(array_t); |
---|
| 3427 | globalTableDefaultArray = NIL(array_t); |
---|
| 3428 | globalTableSymCubeArray = NIL(array_t); |
---|
| 3429 | globalFormalNameArray = NIL(array_t); |
---|
| 3430 | globalActualNameArray = NIL(array_t); |
---|
| 3431 | |
---|
| 3432 | globalSubcktArray = NIL(array_t); |
---|
| 3433 | globalResetArray = NIL(array_t); |
---|
| 3434 | |
---|
| 3435 | globalNewModelArray = array_alloc(Hrc_Model_t *,0); |
---|
| 3436 | |
---|
| 3437 | globalCurrentStackDepth = 0; |
---|
| 3438 | |
---|
| 3439 | /* a hash table from a model name to an array of resets/subcircuits in the model */ |
---|
| 3440 | globalParserResetInfo = st_init_table(st_ptrcmp,st_ptrhash); |
---|
| 3441 | globalParserSubcktInfo = st_init_table(st_ptrcmp,st_ptrhash); |
---|
| 3442 | } |
---|
| 3443 | |
---|
| 3444 | /**Function******************************************************************** |
---|
| 3445 | |
---|
| 3446 | Synopsis [Frees all the global data structures used in the parser.] |
---|
| 3447 | |
---|
| 3448 | Description [] |
---|
| 3449 | |
---|
| 3450 | SideEffects [] |
---|
| 3451 | |
---|
| 3452 | SeeAlso [] |
---|
| 3453 | |
---|
| 3454 | ******************************************************************************/ |
---|
| 3455 | static void |
---|
| 3456 | _IoGlobalVariablesFree(void) |
---|
| 3457 | { |
---|
| 3458 | array_free(globalNewModelArray); |
---|
| 3459 | _IoGlobalResetInfoFree(); |
---|
| 3460 | _IoGlobalSubcktInfoFree(); |
---|
| 3461 | } |
---|
| 3462 | |
---|
| 3463 | |
---|
| 3464 | /**Function******************************************************************** |
---|
| 3465 | |
---|
| 3466 | Synopsis [Frees the subckt information only used by the parser.] |
---|
| 3467 | |
---|
| 3468 | Description [] |
---|
| 3469 | |
---|
| 3470 | SideEffects [] |
---|
| 3471 | |
---|
| 3472 | SeeAlso [] |
---|
| 3473 | |
---|
| 3474 | ******************************************************************************/ |
---|
| 3475 | static void |
---|
| 3476 | _IoGlobalSubcktInfoFree(void) |
---|
| 3477 | { |
---|
| 3478 | st_generator *gen; |
---|
| 3479 | char *key, *val; |
---|
| 3480 | |
---|
| 3481 | st_foreach_item(globalParserSubcktInfo,gen,&key,&val){ |
---|
| 3482 | if ((array_t *)val != NIL(array_t)){ |
---|
| 3483 | _IoSubcktArrayFree((array_t *)val); |
---|
| 3484 | } |
---|
| 3485 | } |
---|
| 3486 | st_free_table(globalParserSubcktInfo); |
---|
| 3487 | } |
---|
| 3488 | |
---|
| 3489 | |
---|
| 3490 | /**Function******************************************************************** |
---|
| 3491 | |
---|
| 3492 | Synopsis [Frees an array of the subckt data structure only used by the parser.] |
---|
| 3493 | |
---|
| 3494 | Description [] |
---|
| 3495 | |
---|
| 3496 | SideEffects [] |
---|
| 3497 | |
---|
| 3498 | SeeAlso [] |
---|
| 3499 | |
---|
| 3500 | ******************************************************************************/ |
---|
| 3501 | static void |
---|
| 3502 | _IoSubcktArrayFree(array_t *array) |
---|
| 3503 | { |
---|
| 3504 | int i; |
---|
| 3505 | |
---|
| 3506 | for (i=0; i < array_n(array); i++){ |
---|
| 3507 | _IoSubcktFree(array_fetch(IoSubckt_t *,array,i)); |
---|
| 3508 | } |
---|
| 3509 | array_free(array); |
---|
| 3510 | } |
---|
| 3511 | |
---|
| 3512 | /**Function******************************************************************** |
---|
| 3513 | |
---|
| 3514 | Synopsis [Frees the subckt data structure used by the parser.] |
---|
| 3515 | |
---|
| 3516 | Description [] |
---|
| 3517 | |
---|
| 3518 | SideEffects [] |
---|
| 3519 | |
---|
| 3520 | SeeAlso [] |
---|
| 3521 | |
---|
| 3522 | ******************************************************************************/ |
---|
| 3523 | static void |
---|
| 3524 | _IoSubcktFree(IoSubckt_t *subckt) |
---|
| 3525 | { |
---|
| 3526 | FREE(subckt->modelName); |
---|
| 3527 | FREE(subckt->instanceName); |
---|
| 3528 | IoStringArrayFree(subckt->formalNameArray); |
---|
| 3529 | IoStringArrayFree(subckt->actualNameArray); |
---|
| 3530 | FREE(subckt); |
---|
| 3531 | } |
---|
| 3532 | |
---|
| 3533 | |
---|
| 3534 | /**Function******************************************************************** |
---|
| 3535 | |
---|
| 3536 | Synopsis [Frees the reset data structure used only by the parser.] |
---|
| 3537 | |
---|
| 3538 | Description [] |
---|
| 3539 | |
---|
| 3540 | SideEffects [] |
---|
| 3541 | |
---|
| 3542 | SeeAlso [] |
---|
| 3543 | |
---|
| 3544 | ******************************************************************************/ |
---|
| 3545 | static void |
---|
| 3546 | _IoGlobalResetInfoFree(void) |
---|
| 3547 | { |
---|
| 3548 | st_generator *gen; |
---|
| 3549 | char *key, *val; |
---|
| 3550 | int i; |
---|
| 3551 | Tbl_Table_t *resetTable; |
---|
| 3552 | |
---|
| 3553 | st_foreach_item(globalParserResetInfo,gen,&key,&val){ |
---|
| 3554 | if ((array_t *)val != NIL(array_t)){ |
---|
| 3555 | for (i=0; i < array_n((array_t *)val); i++){ |
---|
| 3556 | resetTable = array_fetch(Tbl_Table_t *,(array_t *)val,i); |
---|
| 3557 | if (resetTable != NIL(Tbl_Table_t)){ |
---|
| 3558 | Tbl_TableFree(resetTable); |
---|
| 3559 | } |
---|
| 3560 | } |
---|
| 3561 | array_free((array_t *)val); |
---|
| 3562 | } |
---|
| 3563 | } |
---|
| 3564 | st_free_table(globalParserResetInfo); |
---|
| 3565 | } |
---|
| 3566 | |
---|
| 3567 | |
---|
| 3568 | /**Function******************************************************************** |
---|
| 3569 | |
---|
| 3570 | Synopsis [Checks if two hnodes are compatible with respect to their input |
---|
| 3571 | or output interface depending on the last boolean flag.] |
---|
| 3572 | |
---|
| 3573 | Description [Checks if two hnodes are compatible with respect to their input |
---|
| 3574 | or output interface depending on the last boolean flag. 0 for input and 1 |
---|
| 3575 | for output.] |
---|
| 3576 | |
---|
| 3577 | SideEffects [] |
---|
| 3578 | |
---|
| 3579 | SeeAlso [] |
---|
| 3580 | |
---|
| 3581 | ******************************************************************************/ |
---|
| 3582 | static boolean |
---|
| 3583 | _IoNodeTestCompatibilityAux( |
---|
| 3584 | Hrc_Manager_t *hmgr, |
---|
| 3585 | Hrc_Node_t *hnode1, |
---|
| 3586 | Hrc_Node_t *hnode2, |
---|
| 3587 | boolean mode) |
---|
| 3588 | { |
---|
| 3589 | int i, n; |
---|
| 3590 | array_t *formalVars1, *formalVars2; |
---|
| 3591 | Var_Variable_t *var1, *var2; |
---|
| 3592 | |
---|
| 3593 | if (mode == 0){ |
---|
| 3594 | formalVars1 = Hrc_NodeReadFormalInputs(hnode1); |
---|
| 3595 | formalVars2 = Hrc_NodeReadFormalInputs(hnode2); |
---|
| 3596 | } |
---|
| 3597 | else { |
---|
| 3598 | formalVars1 = Hrc_NodeReadFormalOutputs(hnode1); |
---|
| 3599 | formalVars2 = Hrc_NodeReadFormalOutputs(hnode2); |
---|
| 3600 | } |
---|
| 3601 | if ((n = array_n(formalVars1)) != array_n(formalVars2)){ |
---|
| 3602 | error_append("Two hnodes have different number of formal "); |
---|
| 3603 | if (mode == 0){ |
---|
| 3604 | error_append("inputs.\n"); |
---|
| 3605 | } |
---|
| 3606 | else { |
---|
| 3607 | error_append("outputs.\n"); |
---|
| 3608 | } |
---|
| 3609 | return 0; |
---|
| 3610 | } |
---|
| 3611 | for (i=0; i < n; i++){ |
---|
| 3612 | var1 = array_fetch(Var_Variable_t *,formalVars1,i); |
---|
| 3613 | var2 = array_fetch(Var_Variable_t *,formalVars2,i); |
---|
| 3614 | if (strcmp(Var_VariableReadName(var1),Var_VariableReadName(var2)) != 0){ |
---|
| 3615 | error_append("Two hnodes have different ports, "); |
---|
| 3616 | error_append(Var_VariableReadName(var1)); |
---|
| 3617 | error_append(" and "); |
---|
| 3618 | error_append(Var_VariableReadName(var2)); |
---|
| 3619 | error_append("\n"); |
---|
| 3620 | return 0; |
---|
| 3621 | } |
---|
| 3622 | if (Var_VariablesTestHaveSameDomain(var1,var2) == 0){ |
---|
| 3623 | error_append("Two hnodes have ports defined over different domains, "); |
---|
| 3624 | error_append(Var_VariableReadName(var1)); |
---|
| 3625 | error_append(" and "); |
---|
| 3626 | error_append(Var_VariableReadName(var2)); |
---|
| 3627 | error_append("\n"); |
---|
| 3628 | return 0; |
---|
| 3629 | } |
---|
| 3630 | } |
---|
| 3631 | return 1; |
---|
| 3632 | } |
---|
| 3633 | |
---|
| 3634 | |
---|
| 3635 | /**Function******************************************************************** |
---|
| 3636 | |
---|
| 3637 | Synopsis [Canonicalizes all the tables in a given manager using |
---|
| 3638 | Tbl_TableCanonicalize().] |
---|
| 3639 | |
---|
| 3640 | SideEffects [The original tables will be overwritten.] |
---|
| 3641 | |
---|
| 3642 | SeeAlso [] |
---|
| 3643 | |
---|
| 3644 | ******************************************************************************/ |
---|
| 3645 | static void |
---|
| 3646 | _IoManagerCanonicalize( |
---|
| 3647 | Hrc_Manager_t *hmgr) |
---|
| 3648 | { |
---|
| 3649 | int i; |
---|
| 3650 | Hrc_Model_t *model; |
---|
| 3651 | Hrc_Node_t *node; |
---|
| 3652 | Tbl_Table_t *table; |
---|
| 3653 | st_generator *gen, *gen2; |
---|
| 3654 | char *modelName, *latchName; |
---|
| 3655 | Hrc_Latch_t *latch; |
---|
| 3656 | |
---|
| 3657 | Hrc_ManagerForEachModel(hmgr,gen,modelName,model){ |
---|
| 3658 | node = Hrc_ModelReadMasterNode(model); |
---|
| 3659 | Hrc_NodeForEachNameTable(node,i,table){ |
---|
| 3660 | Tbl_TableCanonicalize(table); |
---|
| 3661 | } |
---|
| 3662 | Hrc_NodeForEachLatch(node,gen2,latchName,latch){ |
---|
| 3663 | Tbl_TableCanonicalize(Hrc_LatchReadResetTable(latch)); |
---|
| 3664 | } |
---|
| 3665 | } |
---|
| 3666 | } |
---|
| 3667 | |
---|
| 3668 | |
---|
| 3669 | /**Function******************************************************************** |
---|
| 3670 | |
---|
| 3671 | Synopsis [Handle function for timeout.] |
---|
| 3672 | |
---|
| 3673 | Description [This function is called when the time out occurs. |
---|
| 3674 | Since alarm is set with an elapsed time, this function checks if the |
---|
| 3675 | CPU time corresponds to the timeout of the command. If not, it |
---|
| 3676 | reprograms the alarm to fire again later.] |
---|
| 3677 | |
---|
| 3678 | SideEffects [] |
---|
| 3679 | |
---|
| 3680 | ******************************************************************************/ |
---|
| 3681 | static void |
---|
| 3682 | TimeOutHandle(void) |
---|
| 3683 | { |
---|
| 3684 | int seconds = (int) ((util_cpu_ctime() - alarmLapTime) / 1000); |
---|
| 3685 | |
---|
| 3686 | if (seconds < mcTimeOut) { |
---|
| 3687 | unsigned slack = (unsigned) (mcTimeOut - seconds); |
---|
| 3688 | (void) signal(SIGALRM, (void(*)(int)) TimeOutHandle); |
---|
| 3689 | (void) alarm(slack); |
---|
| 3690 | } else { |
---|
| 3691 | longjmp(timeOutEnv, 1); |
---|
| 3692 | } |
---|
| 3693 | } /* TimeOutHandle */ |
---|
| 3694 | |
---|
| 3695 | |
---|
| 3696 | /**Function******************************************************************** |
---|
| 3697 | |
---|
| 3698 | Synopsis [] |
---|
| 3699 | |
---|
| 3700 | Description [] |
---|
| 3701 | |
---|
| 3702 | SideEffects [] |
---|
| 3703 | |
---|
| 3704 | SeeAlso [] |
---|
| 3705 | |
---|
| 3706 | ******************************************************************************/ |
---|
| 3707 | static int |
---|
| 3708 | nodenameCompare( |
---|
| 3709 | const void * node1, |
---|
| 3710 | const void * node2) |
---|
| 3711 | { |
---|
| 3712 | Ntk_Node_t *v1, *v2; |
---|
| 3713 | char *name1, *name2; |
---|
| 3714 | |
---|
| 3715 | v1 = *(Ntk_Node_t **)(node1); |
---|
| 3716 | v2 = *(Ntk_Node_t **)(node2); |
---|
| 3717 | name1 = Ntk_NodeReadName(v1); |
---|
| 3718 | name2 = Ntk_NodeReadName(v2); |
---|
| 3719 | |
---|
| 3720 | return (strcmp(name1, name2)); |
---|
| 3721 | } |
---|
| 3722 | |
---|
| 3723 | |
---|
| 3724 | /**Function******************************************************************** |
---|
| 3725 | |
---|
| 3726 | Synopsis [This function is used for string comparison in array_sort.] |
---|
| 3727 | |
---|
| 3728 | Description [This function is used for string comparison in array_sort.] |
---|
| 3729 | |
---|
| 3730 | SideEffects [] |
---|
| 3731 | |
---|
| 3732 | SeeAlso [] |
---|
| 3733 | |
---|
| 3734 | ******************************************************************************/ |
---|
| 3735 | static int |
---|
| 3736 | _HrcStringCmp( |
---|
| 3737 | const void * s1, |
---|
| 3738 | const void * s2) |
---|
| 3739 | { |
---|
| 3740 | return(strcmp(*(char **)s1, *(char **)s2)); |
---|
| 3741 | } |
---|
| 3742 | |
---|
| 3743 | |
---|
| 3744 | /**Function******************************************************************** |
---|
| 3745 | |
---|
| 3746 | Synopsis [Prints whether model checking passed or failed] |
---|
| 3747 | |
---|
| 3748 | Description [Prints whether model checking passed or failed, and if |
---|
| 3749 | requested, a debug trace.] |
---|
| 3750 | |
---|
| 3751 | SideEffects [] |
---|
| 3752 | |
---|
| 3753 | ******************************************************************************/ |
---|
| 3754 | static boolean |
---|
| 3755 | McPrintPassFailMine( |
---|
| 3756 | mdd_manager *mddMgr, |
---|
| 3757 | Fsm_Fsm_t *modelFsm, |
---|
| 3758 | Mc_FwdBwdAnalysis traversalDirection, |
---|
| 3759 | Ctlp_Formula_t *ctlFormula, |
---|
| 3760 | mdd_t *ctlFormulaStates, |
---|
| 3761 | mdd_t *modelInitialStates, |
---|
| 3762 | array_t *modelCareStatesArray, |
---|
| 3763 | McOptions_t *options, |
---|
| 3764 | Mc_VerbosityLevel verbosity) |
---|
| 3765 | { |
---|
| 3766 | (void) fprintf(vis_stdout, "![McPrintPassFailMine] Original CTL Formula : "); |
---|
| 3767 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 3768 | (void) fprintf(vis_stdout, "\n![McPrintPassFailMine] MC CTL Formula : "); |
---|
| 3769 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 3770 | fprintf(vis_stdout, "\n"); |
---|
| 3771 | if (mdd_lequal(modelInitialStates, ctlFormulaStates, 1, 1)) { |
---|
| 3772 | fprintf(vis_stdout, "# MC: formula passed --- "); |
---|
| 3773 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 3774 | fprintf(vis_stdout, "\n"); |
---|
| 3775 | return TRUE; |
---|
| 3776 | } |
---|
| 3777 | else { |
---|
| 3778 | fprintf(vis_stdout, "# MC: formula failed --- "); |
---|
| 3779 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 3780 | fprintf(vis_stdout, "\n"); |
---|
| 3781 | if (McOptionsReadDbgLevel(options) != McDbgLevelNone_c) { |
---|
| 3782 | McFsmDebugFormulaMine(options, ctlFormula,modelFsm, modelCareStatesArray); |
---|
| 3783 | } |
---|
| 3784 | return FALSE; |
---|
| 3785 | } |
---|
| 3786 | } |
---|
| 3787 | |
---|
| 3788 | |
---|
| 3789 | /**Function******************************************************************** |
---|
| 3790 | |
---|
| 3791 | Synopsis [Debug CTL formula in existential normal form] |
---|
| 3792 | |
---|
| 3793 | Description [Debug CTL formula in existential normal form. The extent to |
---|
| 3794 | which debug information is generated is a function of options settings. |
---|
| 3795 | |
---|
| 3796 | The debugger works with ctlFormula, but uses the pointers back to |
---|
| 3797 | the original formula that it was converted from, to give the user |
---|
| 3798 | more sensible feedback. To do this, it relies on a specific |
---|
| 3799 | translation: only EF, AU, AF, AG, and AX are converted. Hence, the |
---|
| 3800 | only times that the converted bit is set, we have a conversion of |
---|
| 3801 | one of these formulas, and the operator is either EU, or negation. |
---|
| 3802 | in the latter case, we can conclude from the child of the negation |
---|
| 3803 | what formula we converted from: EX means AX, EG means AF, EU means AG, |
---|
| 3804 | and OR means AU. |
---|
| 3805 | ] |
---|
| 3806 | |
---|
| 3807 | SideEffects [Affects vis_stdpipe] |
---|
| 3808 | |
---|
| 3809 | SeeAlso [Ctlp_FormulaConvertToExistentialForm] |
---|
| 3810 | |
---|
| 3811 | ******************************************************************************/ |
---|
| 3812 | static int |
---|
| 3813 | McFsmDebugFormulaMine( |
---|
| 3814 | McOptions_t *options, |
---|
| 3815 | Ctlp_Formula_t *ctlFormula, |
---|
| 3816 | Fsm_Fsm_t *modelFsm, |
---|
| 3817 | array_t *careSetArray) |
---|
| 3818 | { |
---|
| 3819 | (void) fprintf(vis_stdout, "![McFsmDebugFormulaMine] Original CTL Formula : "); |
---|
| 3820 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 3821 | (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] MC CTL Formula : "); |
---|
| 3822 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 3823 | fprintf(vis_stdout, "\n"); |
---|
| 3824 | mdd_t *modelInitialStates = Fsm_FsmComputeInitialStates(modelFsm); |
---|
| 3825 | mdd_t *goodStates = Ctlp_FormulaObtainLatestApprox(ctlFormula); |
---|
| 3826 | mdd_t *badStates = mdd_and(modelInitialStates, goodStates, 1, 0); |
---|
| 3827 | mdd_t *witnessSuccState; |
---|
| 3828 | FILE *debugFile = McOptionsReadDebugFile(options); |
---|
| 3829 | FILE *oldStdOut; |
---|
| 3830 | FILE *oldStdErr; |
---|
| 3831 | extern FILE *vis_stdpipe; |
---|
| 3832 | char *nrOfTracesString; |
---|
| 3833 | int nrOfTraces; /* nr of debug traces that we output */ |
---|
| 3834 | int i; /* counts debug traces */ |
---|
| 3835 | array_t *completeCExArray; |
---|
| 3836 | array_t *initCExArray; |
---|
| 3837 | initCExArray = array_alloc(mdd_t *, 0); |
---|
| 3838 | |
---|
| 3839 | mdd_free(modelInitialStates); |
---|
| 3840 | |
---|
| 3841 | oldStdOut = vis_stdout; |
---|
| 3842 | oldStdErr = vis_stderr; |
---|
| 3843 | |
---|
| 3844 | nrOfTracesString = Cmd_FlagReadByName("nr_counterexamples"); |
---|
| 3845 | if(nrOfTracesString == NIL(char)) |
---|
| 3846 | nrOfTraces = 1; |
---|
| 3847 | else |
---|
| 3848 | nrOfTraces = atoi(nrOfTracesString); |
---|
| 3849 | |
---|
| 3850 | (void) fprintf(vis_stderr, "[McFsmDebugFormulaMine] Number of debug traces = %d \n", nrOfTraces); |
---|
| 3851 | |
---|
| 3852 | if (debugFile) { |
---|
| 3853 | vis_stdpipe = debugFile; |
---|
| 3854 | vis_stdout = vis_stdpipe; |
---|
| 3855 | (void)fprintf(vis_stdpipe, "# MC: formula failed --- "); |
---|
| 3856 | Ctlp_FormulaPrint(vis_stdpipe,Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 3857 | (void)fprintf(vis_stdpipe, "\n"); |
---|
| 3858 | } else if (McOptionsReadUseMore(options)){ |
---|
| 3859 | vis_stdpipe = popen("more", "w"); |
---|
| 3860 | vis_stdout = vis_stdpipe; |
---|
| 3861 | vis_stderr = vis_stdpipe; |
---|
| 3862 | } |
---|
| 3863 | else |
---|
| 3864 | vis_stdpipe = vis_stdout; |
---|
| 3865 | |
---|
| 3866 | for(i = 0; i < nrOfTraces; i++){ |
---|
| 3867 | (void)fprintf(vis_stdout, "# MC: Calling debugger for trace %d\n", |
---|
| 3868 | i+1); |
---|
| 3869 | witnessSuccState = McComputeACloseState(badStates, goodStates, modelFsm); |
---|
| 3870 | |
---|
| 3871 | completeCExArray = McFsmStateDebugFormulaMine(options, ctlFormula, witnessSuccState, modelFsm, |
---|
| 3872 | careSetArray, initCExArray); |
---|
| 3873 | (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] -> nb completeCExArray : %d \n", array_n(completeCExArray)); |
---|
| 3874 | // (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] -> nb initCExArray : %d \n", array_n(initCExArray)); |
---|
| 3875 | |
---|
| 3876 | (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] START xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n"); |
---|
| 3877 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 3878 | Mc_PrintPathMine( completeCExArray, modelFsm, printInputs ); |
---|
| 3879 | (void) fprintf(vis_stdout, "\n![McFsmDebugFormulaMine] END xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \n"); |
---|
| 3880 | |
---|
| 3881 | (void)fprintf(vis_stdout, "\n"); |
---|
| 3882 | |
---|
| 3883 | mdd_free(witnessSuccState); |
---|
| 3884 | } |
---|
| 3885 | mdd_free(badStates); |
---|
| 3886 | mdd_free(goodStates); |
---|
| 3887 | |
---|
| 3888 | if (vis_stdout != oldStdOut && vis_stdout != debugFile) |
---|
| 3889 | (void)pclose(vis_stdpipe); |
---|
| 3890 | |
---|
| 3891 | vis_stdout = oldStdOut; |
---|
| 3892 | vis_stderr = oldStdErr; |
---|
| 3893 | |
---|
| 3894 | return 1; |
---|
| 3895 | } |
---|
| 3896 | |
---|
| 3897 | |
---|
| 3898 | /**Function******************************************************************** |
---|
| 3899 | |
---|
| 3900 | Synopsis [Debug CTL formula in existential normal form at state aState] |
---|
| 3901 | |
---|
| 3902 | Description [Debug CTL formula in existential normal form at state |
---|
| 3903 | aState. Formula is assumed to have been CONVERTED to existential normal |
---|
| 3904 | form.] |
---|
| 3905 | |
---|
| 3906 | SideEffects [] |
---|
| 3907 | |
---|
| 3908 | ******************************************************************************/ |
---|
| 3909 | static array_t * |
---|
| 3910 | McFsmStateDebugFormulaMine( |
---|
| 3911 | McOptions_t *options, |
---|
| 3912 | Ctlp_Formula_t *ctlFormula, |
---|
| 3913 | mdd_t *aState, |
---|
| 3914 | Fsm_Fsm_t *modelFsm, |
---|
| 3915 | array_t *careSetArray, |
---|
| 3916 | array_t *prevCExArray) |
---|
| 3917 | { |
---|
| 3918 | (void) fprintf(vis_stdout, "![McFsmStateDebugFormulaMine] Original CTL Formula : "); |
---|
| 3919 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 3920 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] MC CTL Formula : "); |
---|
| 3921 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 0 --> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 3922 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 3923 | fprintf(vis_stdout, "\n"); |
---|
| 3924 | |
---|
| 3925 | |
---|
| 3926 | Ctlp_Formula_t *originalFormula; |
---|
| 3927 | array_t *cExampleArray; |
---|
| 3928 | // array_t *preCExArray; |
---|
| 3929 | array_t *fullCExArray; |
---|
| 3930 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 3931 | |
---|
| 3932 | //prevCExArray = array_alloc(mdd_t *, 0); |
---|
| 3933 | // fullCExArray = prevCExArray; |
---|
| 3934 | if ( ctlFormula == NIL(Ctlp_Formula_t) ) { |
---|
| 3935 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] * END * \n"); |
---|
| 3936 | fullCExArray = prevCExArray; |
---|
| 3937 | return fullCExArray; |
---|
| 3938 | } |
---|
| 3939 | if ( Ctlp_FormulaTestIsConverted( ctlFormula ) ) { |
---|
| 3940 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> FsmStateDebugConvertedFormulaMine \n"); |
---|
| 3941 | cExampleArray = FsmStateDebugConvertedFormulaMine(options, ctlFormula, aState, modelFsm, |
---|
| 3942 | careSetArray, &prevCExArray); |
---|
| 3943 | |
---|
| 3944 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 1 --> nb cExampleArray : %d ", array_n(cExampleArray )); |
---|
| 3945 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 1 --> nb prevCExArray : %d ", array_n(prevCExArray)); |
---|
| 3946 | |
---|
| 3947 | // boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 3948 | // Mc_PrintPathMine( cExampleArray, modelFsm, printInputs ); |
---|
| 3949 | |
---|
| 3950 | if (array_n(prevCExArray)==0 ) { |
---|
| 3951 | fullCExArray = cExampleArray; |
---|
| 3952 | } |
---|
| 3953 | else { |
---|
| 3954 | fullCExArray = McCreateMergedPath(cExampleArray, prevCExArray); |
---|
| 3955 | } |
---|
| 3956 | |
---|
| 3957 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 1 --> nb fullCExArray : %d ", array_n(fullCExArray )); |
---|
| 3958 | prevCExArray = fullCExArray; |
---|
| 3959 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 1 --> nb prevCExArray End : %d ", array_n(prevCExArray)); |
---|
| 3960 | |
---|
| 3961 | /* (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] START OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00000000O\n"); |
---|
| 3962 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 3963 | Mc_PrintPathMine( fullCExArray, modelFsm, printInputs ); |
---|
| 3964 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] END 0OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00000000O\n"); |
---|
| 3965 | */ |
---|
| 3966 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] * END * \n"); |
---|
| 3967 | return fullCExArray; |
---|
| 3968 | } |
---|
| 3969 | |
---|
| 3970 | originalFormula = Ctlp_FormulaReadOriginalFormula( ctlFormula ); |
---|
| 3971 | |
---|
| 3972 | switch ( Ctlp_FormulaReadType( ctlFormula ) ) { |
---|
| 3973 | |
---|
| 3974 | case Ctlp_ID_c : |
---|
| 3975 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugIDMine \n"); |
---|
| 3976 | DebugIDMine( options, ctlFormula, aState, modelFsm ); |
---|
| 3977 | fullCExArray = prevCExArray; |
---|
| 3978 | break; |
---|
| 3979 | |
---|
| 3980 | case Ctlp_TRUE_c: |
---|
| 3981 | case Ctlp_FALSE_c: |
---|
| 3982 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugTrueFalseMine \n"); |
---|
| 3983 | DebugTrueFalseMine( ctlFormula, aState, modelFsm ); |
---|
| 3984 | fullCExArray = prevCExArray; |
---|
| 3985 | break; |
---|
| 3986 | |
---|
| 3987 | case Ctlp_EQ_c: |
---|
| 3988 | case Ctlp_XOR_c: |
---|
| 3989 | case Ctlp_THEN_c: |
---|
| 3990 | case Ctlp_NOT_c: |
---|
| 3991 | case Ctlp_AND_c: |
---|
| 3992 | case Ctlp_OR_c: |
---|
| 3993 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugBooleanMine \n"); |
---|
| 3994 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 2 --> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 3995 | cExampleArray = DebugBooleanMine(options, ctlFormula, aState, modelFsm, careSetArray, &prevCExArray); |
---|
| 3996 | |
---|
| 3997 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 2 --> nb cExampleArray : %d ", array_n(cExampleArray )); |
---|
| 3998 | |
---|
| 3999 | |
---|
| 4000 | /* if (array_n(prevCExArray)==0 ) { |
---|
| 4001 | fullCExArray = cExampleArray; |
---|
| 4002 | } |
---|
| 4003 | else { |
---|
| 4004 | fullCExArray = McCreateMergedPath(cExampleArray, prevCExArray); |
---|
| 4005 | } |
---|
| 4006 | */ |
---|
| 4007 | |
---|
| 4008 | fullCExArray = cExampleArray; |
---|
| 4009 | prevCExArray = fullCExArray; |
---|
| 4010 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 2 --> nb prevCExArray after DB : %d ", array_n(prevCExArray)); |
---|
| 4011 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 2 --> nb fullCExArray : %d ", array_n(fullCExArray )); |
---|
| 4012 | |
---|
| 4013 | break; |
---|
| 4014 | |
---|
| 4015 | case Ctlp_EX_c: |
---|
| 4016 | case Ctlp_EU_c: |
---|
| 4017 | case Ctlp_EG_c: |
---|
| 4018 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> Ctlp_EG_c\n"); |
---|
| 4019 | if ( !McStateSatisfiesFormula( ctlFormula, aState ) ) { |
---|
| 4020 | mdd_t *passStates = Ctlp_FormulaObtainLatestApprox(ctlFormula); |
---|
| 4021 | mdd_t *closeState; |
---|
| 4022 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork(modelFsm); |
---|
| 4023 | array_t *PSVars = Fsm_FsmReadPresentStateVars(modelFsm); |
---|
| 4024 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> McStateFailsFormulaMine \n"); |
---|
| 4025 | |
---|
| 4026 | McStateFailsFormulaMine(aState, originalFormula, debugLevel, modelFsm); |
---|
| 4027 | if (mdd_is_tautology(passStates, 0)) { |
---|
| 4028 | fprintf(vis_stdout, |
---|
| 4029 | "--No state satisfies the formula\n"); |
---|
| 4030 | mdd_free(passStates); |
---|
| 4031 | |
---|
| 4032 | fullCExArray = prevCExArray; |
---|
| 4033 | break; |
---|
| 4034 | } |
---|
| 4035 | fprintf(vis_stdout, |
---|
| 4036 | "--A simple counter example does not exist since it\n"); |
---|
| 4037 | fprintf(vis_stdout, |
---|
| 4038 | " requires generating all paths from the state\n"); |
---|
| 4039 | fprintf(vis_stdout, |
---|
| 4040 | "--A state at minimum distance satisfying the formula is\n"); |
---|
| 4041 | closeState = McComputeACloseState(passStates, aState, modelFsm); |
---|
| 4042 | mdd_free(passStates); |
---|
| 4043 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> Mc_MintermPrintMine \n"); |
---|
| 4044 | Mc_MintermPrintMine(closeState, PSVars, modelNetwork); |
---|
| 4045 | mdd_free(closeState); |
---|
| 4046 | |
---|
| 4047 | fullCExArray = prevCExArray; |
---|
| 4048 | |
---|
| 4049 | break; |
---|
| 4050 | } |
---|
| 4051 | else { |
---|
| 4052 | McPath_t *witnessPath = NIL(McPath_t); |
---|
| 4053 | if ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EX_c ) { |
---|
| 4054 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugEXMine \n"); |
---|
| 4055 | witnessPath = DebugEXMine(ctlFormula, aState, modelFsm, careSetArray); |
---|
| 4056 | } |
---|
| 4057 | else if ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EU_c ) { |
---|
| 4058 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugEUMine \n"); |
---|
| 4059 | witnessPath = DebugEUMine(ctlFormula, aState, modelFsm, careSetArray); |
---|
| 4060 | } |
---|
| 4061 | else { |
---|
| 4062 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> DebugEGMine \n"); |
---|
| 4063 | witnessPath = DebugEGMine(ctlFormula, aState, modelFsm, careSetArray, |
---|
| 4064 | options); |
---|
| 4065 | } |
---|
| 4066 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] >> FsmPathDebugFormulaMine \n"); |
---|
| 4067 | cExampleArray = FsmPathDebugFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
| 4068 | careSetArray, &prevCExArray); |
---|
| 4069 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 3 --> nb cExampleArray : %d ", array_n(cExampleArray )); |
---|
| 4070 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 3 --> nb prevCExArray : %d ", array_n(prevCExArray)); |
---|
| 4071 | |
---|
| 4072 | /* if (array_n(prevCExArray)==0 ) { |
---|
| 4073 | fullCExArray = cExampleArray; |
---|
| 4074 | } |
---|
| 4075 | else { |
---|
| 4076 | fullCExArray = McCreateMergedPath(cExampleArray, prevCExArray); |
---|
| 4077 | } |
---|
| 4078 | */ |
---|
| 4079 | fullCExArray = prevCExArray; |
---|
| 4080 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] 3 --> nb fullCExArray : %d ", array_n(fullCExArray )); |
---|
| 4081 | |
---|
| 4082 | // McPathFree( witnessPath ); //NOTE: INITIALLY FREED |
---|
| 4083 | } |
---|
| 4084 | break; |
---|
| 4085 | |
---|
| 4086 | case Ctlp_Cmp_c: |
---|
| 4087 | case Ctlp_Init_c: |
---|
| 4088 | case Ctlp_FwdU_c: |
---|
| 4089 | case Ctlp_FwdG_c: |
---|
| 4090 | case Ctlp_EY_c: |
---|
| 4091 | case Ctlp_EH_c: |
---|
| 4092 | fullCExArray = prevCExArray; |
---|
| 4093 | break; |
---|
| 4094 | |
---|
| 4095 | default: { |
---|
| 4096 | fail("Bad switch in debugging normal formula\n"); |
---|
| 4097 | fullCExArray = prevCExArray; |
---|
| 4098 | } |
---|
| 4099 | } |
---|
| 4100 | // *prevCExArray = fullCExArray; |
---|
| 4101 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] LAST --> nb prevCExArray End: %d ", array_n(prevCExArray)); |
---|
| 4102 | /* (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] START OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00000000O\n"); |
---|
| 4103 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 4104 | Mc_PrintPathMine( prevCExArray, modelFsm, printInputs ); |
---|
| 4105 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] END 0OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO00000000O\n"); |
---|
| 4106 | */ |
---|
| 4107 | (void) fprintf(vis_stdout, "\n![McFsmStateDebugFormulaMine] * END * \n"); |
---|
| 4108 | return fullCExArray; |
---|
| 4109 | |
---|
| 4110 | } |
---|
| 4111 | |
---|
| 4112 | /**Function******************************************************************** |
---|
| 4113 | |
---|
| 4114 | Synopsis [Debug a converted formula] |
---|
| 4115 | |
---|
| 4116 | Comment [There are five kinds of formula that are converted: EF, AU, AF, AG, |
---|
| 4117 | AX. The Ctlp_Formula_t structure has a pointer back to the original formula |
---|
| 4118 | (where one exists). For the non-trivial cases (AU, AF, AG, AX) if the |
---|
| 4119 | formula is false, we create a counter example, i.e. a fair path which fails |
---|
| 4120 | the property. The AG, AX, AF cases are simple; the AU case is tricky because |
---|
| 4121 | this can be failed on two ways.] |
---|
| 4122 | |
---|
| 4123 | SideEffects [] |
---|
| 4124 | |
---|
| 4125 | ******************************************************************************/ |
---|
| 4126 | static array_t * |
---|
| 4127 | FsmStateDebugConvertedFormulaMine( |
---|
| 4128 | McOptions_t *options, |
---|
| 4129 | Ctlp_Formula_t *ctlFormula, |
---|
| 4130 | mdd_t *aState, |
---|
| 4131 | Fsm_Fsm_t *modelFsm, |
---|
| 4132 | array_t *careSetArray, |
---|
| 4133 | array_t **preCExArray) |
---|
| 4134 | { |
---|
| 4135 | (void) fprintf(vis_stdout, "![FsmStateDebugConvertedFormulaMine] Original CTL Formula : "); |
---|
| 4136 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 4137 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] MC CTL Formula : "); |
---|
| 4138 | // (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 4139 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 4140 | fprintf(vis_stdout, "\n"); |
---|
| 4141 | |
---|
| 4142 | McPath_t *witnessPath; |
---|
| 4143 | McPath_t *counterExamplePath; |
---|
| 4144 | |
---|
| 4145 | array_t *cExArray; |
---|
| 4146 | |
---|
| 4147 | Ctlp_Formula_t *originalFormula =Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
| 4148 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
| 4149 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 4150 | |
---|
| 4151 | if ( Ctlp_FormulaReadType( ctlFormula ) == Ctlp_EU_c ) { |
---|
| 4152 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> Ctlp_EU_c \n"); |
---|
| 4153 | if ( !McStateSatisfiesFormula( ctlFormula, aState ) ) { |
---|
| 4154 | mdd_t *passStates = Ctlp_FormulaObtainLatestApprox(ctlFormula); |
---|
| 4155 | mdd_t *closeState; |
---|
| 4156 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork(modelFsm); |
---|
| 4157 | array_t *PSVars = Fsm_FsmReadPresentStateVars(modelFsm); |
---|
| 4158 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> McStateFailsFormulaMine \n"); |
---|
| 4159 | McStateFailsFormulaMine( aState, originalFormula, debugLevel, modelFsm ); |
---|
| 4160 | if (mdd_is_tautology(passStates, 0)) { |
---|
| 4161 | fprintf(vis_stdout, |
---|
| 4162 | "--No state satisfies the formula\n"); |
---|
| 4163 | } else { |
---|
| 4164 | fprintf(vis_stdout, |
---|
| 4165 | "\n--A simple counter example does not exist since it\n"); |
---|
| 4166 | fprintf(vis_stdout, |
---|
| 4167 | " requires generating all paths from the state\n"); |
---|
| 4168 | fprintf(vis_stdout, |
---|
| 4169 | "--A state at minimum distance satisfying the formula is\n"); |
---|
| 4170 | closeState = McComputeACloseState(passStates, aState, modelFsm); |
---|
| 4171 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> Mc_MintermPrintMine \n"); |
---|
| 4172 | Mc_MintermPrintMine(closeState, PSVars, modelNetwork); |
---|
| 4173 | mdd_free(closeState); |
---|
| 4174 | } |
---|
| 4175 | mdd_free(passStates); |
---|
| 4176 | } |
---|
| 4177 | else { |
---|
| 4178 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> DebugEUMine \n"); |
---|
| 4179 | witnessPath = DebugEUMine(ctlFormula, aState, modelFsm, careSetArray); |
---|
| 4180 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugEFFormulaMine\n"); |
---|
| 4181 | cExArray = FsmPathDebugEFFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
| 4182 | careSetArray, preCExArray); |
---|
| 4183 | // McPathFree( witnessPath ); |
---|
| 4184 | } |
---|
| 4185 | cExArray = *preCExArray; |
---|
| 4186 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] ** END ** \n"); |
---|
| 4187 | return cExArray; |
---|
| 4188 | //return cExArray; // EF Formula not yet treated |
---|
| 4189 | } |
---|
| 4190 | |
---|
| 4191 | /* |
---|
| 4192 | * The original formula must be an AX,AF,AG, or AU formula |
---|
| 4193 | */ |
---|
| 4194 | if ( McStateSatisfiesFormula( ctlFormula, aState ) ) { |
---|
| 4195 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> McStatePassesFormulaMine\n"); |
---|
| 4196 | McStatePassesFormulaMine( aState, originalFormula, debugLevel, modelFsm ); |
---|
| 4197 | fprintf(vis_stdout, |
---|
| 4198 | "--A simple witness does not exist since it requires\n"); |
---|
| 4199 | fprintf(vis_stdout, " generating all paths from the state\n"); |
---|
| 4200 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] ** END ** \n"); |
---|
| 4201 | cExArray = *preCExArray; //Added to avoid seg fault |
---|
| 4202 | return cExArray; // maybe aState gotta checkout later!! |
---|
| 4203 | } |
---|
| 4204 | |
---|
| 4205 | switch ( Ctlp_FormulaReadType( lFormula ) ) { |
---|
| 4206 | case Ctlp_EX_c: { |
---|
| 4207 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> DebugEXMine\n"); |
---|
| 4208 | counterExamplePath = DebugEXMine(lFormula, aState, modelFsm, careSetArray); |
---|
| 4209 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugAXFormulaMine\n"); |
---|
| 4210 | cExArray = FsmPathDebugAXFormulaMine(options, ctlFormula, modelFsm, counterExamplePath, careSetArray, preCExArray); |
---|
| 4211 | // McPathFree( counterExamplePath ); //NOTE: INITIALLY FREED |
---|
| 4212 | break; |
---|
| 4213 | } |
---|
| 4214 | |
---|
| 4215 | case Ctlp_EG_c: { |
---|
| 4216 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> DebugEGMine\n"); |
---|
| 4217 | counterExamplePath = DebugEGMine(lFormula, aState, modelFsm, careSetArray, |
---|
| 4218 | options); |
---|
| 4219 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugAFFormulaMine\n"); |
---|
| 4220 | cExArray = FsmPathDebugAFFormulaMine(options, ctlFormula, modelFsm, counterExamplePath, |
---|
| 4221 | careSetArray, preCExArray); |
---|
| 4222 | // McPathFree( counterExamplePath ); //NOTE: INITIALLY FREED |
---|
| 4223 | break; |
---|
| 4224 | } |
---|
| 4225 | |
---|
| 4226 | case Ctlp_EU_c: { |
---|
| 4227 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> DebugEUMine\n"); |
---|
| 4228 | counterExamplePath = DebugEUMine(lFormula, aState, modelFsm, careSetArray); |
---|
| 4229 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugAGFormulaMine\n"); |
---|
| 4230 | cExArray = FsmPathDebugAGFormulaMine(options, ctlFormula, modelFsm, counterExamplePath, |
---|
| 4231 | careSetArray, preCExArray); |
---|
| 4232 | // McPathFree( counterExamplePath ); //NOTE: INITIALLY FREED |
---|
| 4233 | break; |
---|
| 4234 | } |
---|
| 4235 | |
---|
| 4236 | case Ctlp_OR_c: { |
---|
| 4237 | /* |
---|
| 4238 | * need special functions bcoz of two possibilities |
---|
| 4239 | */ |
---|
| 4240 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] >> FsmPathDebugAUFormulaMine\n"); |
---|
| 4241 | cExArray = FsmPathDebugAUFormulaMine(options, aState, ctlFormula, modelFsm, |
---|
| 4242 | careSetArray, preCExArray); |
---|
| 4243 | |
---|
| 4244 | break; |
---|
| 4245 | } |
---|
| 4246 | |
---|
| 4247 | default: fail("Bad formula type in handling converted operator\n"); |
---|
| 4248 | } |
---|
| 4249 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] LAST ---> nb preCExArray : %d", array_n(*preCExArray)); |
---|
| 4250 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] LAST ---> nb cExArray : %d", array_n(cExArray )); |
---|
| 4251 | |
---|
| 4252 | // boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 4253 | // (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] printInputs = %s \n", (printInputs==TRUE)? "TRUE":"FALSE"); |
---|
| 4254 | // Mc_PrintPathMine(cExArray, modelFsm, printInputs ); |
---|
| 4255 | (void) fprintf(vis_stdout, "\n![FsmStateDebugConvertedFormulaMine] ** END ** \n"); |
---|
| 4256 | return cExArray; |
---|
| 4257 | } |
---|
| 4258 | |
---|
| 4259 | |
---|
| 4260 | /**Function******************************************************************** |
---|
| 4261 | |
---|
| 4262 | Synopsis [Debug a formula of the form EX, EG, EU, EF.] |
---|
| 4263 | |
---|
| 4264 | SideEffects [] |
---|
| 4265 | |
---|
| 4266 | ******************************************************************************/ |
---|
| 4267 | static array_t * |
---|
| 4268 | FsmPathDebugFormulaMine( |
---|
| 4269 | McOptions_t *options, |
---|
| 4270 | Ctlp_Formula_t *ctlFormula, |
---|
| 4271 | Fsm_Fsm_t *modelFsm, |
---|
| 4272 | McPath_t *witnessPath, |
---|
| 4273 | array_t *careSetArray, |
---|
| 4274 | array_t **preCExArray) |
---|
| 4275 | { |
---|
| 4276 | (void) fprintf(vis_stdout, "![FsmPathDebugFormulaMine] Original CTL Formula : "); |
---|
| 4277 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 4278 | (void) fprintf(vis_stdout, "\n![FsmPathDebugFormulaMine] MC CTL Formula : "); |
---|
| 4279 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 4280 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 4281 | fprintf(vis_stdout, "\n"); |
---|
| 4282 | |
---|
| 4283 | array_t *witnessArray; |
---|
| 4284 | switch ( Ctlp_FormulaReadType( ctlFormula ) ) { |
---|
| 4285 | case Ctlp_EX_c: { |
---|
| 4286 | witnessArray = FsmPathDebugEXFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
| 4287 | careSetArray, preCExArray); |
---|
| 4288 | break; |
---|
| 4289 | } |
---|
| 4290 | |
---|
| 4291 | case Ctlp_EU_c: { |
---|
| 4292 | witnessArray = FsmPathDebugEUFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
| 4293 | careSetArray, preCExArray); |
---|
| 4294 | break; |
---|
| 4295 | } |
---|
| 4296 | |
---|
| 4297 | case Ctlp_EG_c: { |
---|
| 4298 | witnessArray = FsmPathDebugEGFormulaMine(options, ctlFormula, modelFsm, witnessPath, |
---|
| 4299 | careSetArray, preCExArray); |
---|
| 4300 | break; |
---|
| 4301 | } |
---|
| 4302 | default: { |
---|
| 4303 | fail("bad switch in converting converted formula\n"); |
---|
| 4304 | } |
---|
| 4305 | } |
---|
| 4306 | |
---|
| 4307 | (void) fprintf(vis_stdout, "\n![FsmPathDebugFormulaMine] ---> witnessArray : %d *END*\n", array_n(witnessArray)); |
---|
| 4308 | |
---|
| 4309 | return witnessArray; |
---|
| 4310 | } |
---|
| 4311 | |
---|
| 4312 | |
---|
| 4313 | /**Function******************************************************************** |
---|
| 4314 | |
---|
| 4315 | Synopsis [Debug an Atomic Formula] |
---|
| 4316 | |
---|
| 4317 | Description [Debug an Atomic Formula. As per the semantics of fair CTL, a |
---|
| 4318 | state satisfies an Atomic Formula just in case the given wire computes the |
---|
| 4319 | appropriate Boolean function on that state as input. The state has to be |
---|
| 4320 | fair; however we do NOT justify the fairness by printing a path to a fair |
---|
| 4321 | cycle. THe user can achieve this effect by adding ANDing in a formula EG |
---|
| 4322 | TRUE.] |
---|
| 4323 | |
---|
| 4324 | SideEffects [] |
---|
| 4325 | |
---|
| 4326 | ******************************************************************************/ |
---|
| 4327 | static void |
---|
| 4328 | DebugIDMine( |
---|
| 4329 | McOptions_t *options, |
---|
| 4330 | Ctlp_Formula_t *aFormula, |
---|
| 4331 | mdd_t *aState, |
---|
| 4332 | Fsm_Fsm_t *modelFsm) |
---|
| 4333 | { |
---|
| 4334 | |
---|
| 4335 | (void) fprintf(vis_stdout, "![DebugIDMine] Original CTL Formula : "); |
---|
| 4336 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
| 4337 | (void) fprintf(vis_stdout, "\n![DebugIDMine] MC CTL Formula : "); |
---|
| 4338 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
| 4339 | fprintf(vis_stdout, "\n"); |
---|
| 4340 | |
---|
| 4341 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(aFormula); |
---|
| 4342 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 4343 | |
---|
| 4344 | if ( McStateSatisfiesFormula( aFormula, aState ) ) { |
---|
| 4345 | McStatePassesFormulaMine( aState, originalFormula, debugLevel, modelFsm ); |
---|
| 4346 | } |
---|
| 4347 | else { |
---|
| 4348 | McStateFailsFormulaMine( aState, originalFormula, debugLevel, modelFsm ); |
---|
| 4349 | } |
---|
| 4350 | } |
---|
| 4351 | |
---|
| 4352 | /**Function******************************************************************** |
---|
| 4353 | |
---|
| 4354 | Synopsis [Debug a TRUE/FALSE formula] |
---|
| 4355 | |
---|
| 4356 | SideEffects [] |
---|
| 4357 | |
---|
| 4358 | ******************************************************************************/ |
---|
| 4359 | static void |
---|
| 4360 | DebugTrueFalseMine( |
---|
| 4361 | Ctlp_Formula_t *aFormula, |
---|
| 4362 | mdd_t *aState, |
---|
| 4363 | Fsm_Fsm_t *modelFsm) |
---|
| 4364 | { |
---|
| 4365 | (void) fprintf(vis_stdout, "![DebugTrueFalseMine] Original CTL Formula : "); |
---|
| 4366 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
| 4367 | (void) fprintf(vis_stdout, "\n![[DebugTrueFalseMine] MC CTL Formula : "); |
---|
| 4368 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
| 4369 | |
---|
| 4370 | fprintf(vis_stdout, "\n"); |
---|
| 4371 | fprintf(vis_stdout, "--Nothing to debug for %s\n", |
---|
| 4372 | ((Ctlp_FormulaReadType(aFormula) == Ctlp_TRUE_c) ? "TRUE\n" : "FALSE\n")); |
---|
| 4373 | } |
---|
| 4374 | |
---|
| 4375 | /**Function******************************************************************** |
---|
| 4376 | |
---|
| 4377 | Synopsis [Debug a Boolean formula] |
---|
| 4378 | |
---|
| 4379 | Desciption [Debug a Boolean formula. For Boolean formula built out of binary |
---|
| 4380 | connective, we may debug only one branch, if say the formula is an AND and |
---|
| 4381 | the left branch is fails.] |
---|
| 4382 | |
---|
| 4383 | SideEffects [] |
---|
| 4384 | |
---|
| 4385 | ******************************************************************************/ |
---|
| 4386 | static array_t * |
---|
| 4387 | DebugBooleanMine( |
---|
| 4388 | McOptions_t *options, |
---|
| 4389 | Ctlp_Formula_t *aFormula, |
---|
| 4390 | mdd_t *aState, |
---|
| 4391 | Fsm_Fsm_t *modelFsm, |
---|
| 4392 | array_t *careSetArray, |
---|
| 4393 | array_t **preCExArray) |
---|
| 4394 | { |
---|
| 4395 | (void) fprintf(vis_stdout, "![DebugBooleanMine] Original CTL Formula : "); |
---|
| 4396 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
| 4397 | (void) fprintf(vis_stdout, "\n![DebugBooleanMine] MC CTL Formula : "); |
---|
| 4398 | (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 0 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
| 4399 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
| 4400 | fprintf(vis_stdout, "\n"); |
---|
| 4401 | |
---|
| 4402 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(aFormula); |
---|
| 4403 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( aFormula ); |
---|
| 4404 | Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( aFormula ); |
---|
| 4405 | McDbgLevel debugLevel = McOptionsReadDbgLevel(options); |
---|
| 4406 | |
---|
| 4407 | if (McStateSatisfiesFormula(aFormula, aState)) { |
---|
| 4408 | McStatePassesFormulaMine(aState, originalFormula, debugLevel, modelFsm); |
---|
| 4409 | } else { |
---|
| 4410 | McStateFailsFormulaMine(aState, originalFormula, debugLevel, modelFsm); |
---|
| 4411 | } |
---|
| 4412 | |
---|
| 4413 | /* We always debug the first (left) child. */ |
---|
| 4414 | array_t *cExArray; |
---|
| 4415 | // array_t *prevCExArray; |
---|
| 4416 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 4417 | cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
| 4418 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 1 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
| 4419 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 1 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
| 4420 | /* What we do for the second child depends on the type of the formula. |
---|
| 4421 | * For Ctlp_AND_c, Ctlp_OR_c, Ctlp_THEN_c the right child may not be |
---|
| 4422 | * needed. With early termination, the right child may not have the |
---|
| 4423 | * information required to produce a counterexample; hence, its debugging |
---|
| 4424 | * is not optional. (We may get incorrect answers.) |
---|
| 4425 | */ |
---|
| 4426 | if (Ctlp_FormulaReadType(aFormula) == Ctlp_AND_c) { |
---|
| 4427 | /* If aFormula fails and aState does not satisfy lFormula |
---|
| 4428 | * 1. The information about aState at the right child is not |
---|
| 4429 | * necessarilty correct. (aState was a don't care state.) |
---|
| 4430 | * 2. A counterexample to lFormula is a counterexample to |
---|
| 4431 | * aFormula. |
---|
| 4432 | * So, if aFormula fails, we should debug the right child only if |
---|
| 4433 | * aState satisfies lFormula. |
---|
| 4434 | * If, on the other hand, aFormula passes, then aState must satisfy |
---|
| 4435 | * lFormula, and we need to witness both lFormula and rFormula. |
---|
| 4436 | */ |
---|
| 4437 | if (McStateSatisfiesFormula(lFormula, aState)) { |
---|
| 4438 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, aState, modelFsm, |
---|
| 4439 | careSetArray, *preCExArray); |
---|
| 4440 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 2 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
| 4441 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 2 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
| 4442 | } |
---|
| 4443 | } else if (Ctlp_FormulaReadType(aFormula) == Ctlp_OR_c) { |
---|
| 4444 | /* if aFormula passes, we should debug the right child only if |
---|
| 4445 | * aState does not satisfy lFormula. |
---|
| 4446 | * If, on the other hand, aFormula fails, then aState may not satisfy |
---|
| 4447 | * lFormula, and we need to produce counterexamples for both lFormula |
---|
| 4448 | * and rFormula. |
---|
| 4449 | */ |
---|
| 4450 | if (!McStateSatisfiesFormula(lFormula, aState)) { |
---|
| 4451 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, aState, modelFsm, |
---|
| 4452 | careSetArray, *preCExArray); |
---|
| 4453 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 3 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
| 4454 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 3 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
| 4455 | } |
---|
| 4456 | } else if (Ctlp_FormulaReadType(aFormula) == Ctlp_THEN_c) { |
---|
| 4457 | /* This case is like the OR, with the polarity of the left |
---|
| 4458 | * left child reversed. |
---|
| 4459 | */ |
---|
| 4460 | if (McStateSatisfiesFormula(lFormula, aState)) { |
---|
| 4461 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, aState, modelFsm, |
---|
| 4462 | careSetArray, *preCExArray); |
---|
| 4463 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 4 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
| 4464 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 4 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
| 4465 | } |
---|
| 4466 | } else if (Ctlp_FormulaReadType(aFormula) != Ctlp_NOT_c) { |
---|
| 4467 | /* For Ctlp_EQ_c and Ctlp_XOR_c both children must be debugged. */ |
---|
| 4468 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
| 4469 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 5 ---> nb prevCExArray : %d \n", array_n(*preCExArray)); |
---|
| 4470 | // (void) fprintf(vis_stdout, "\n![DebugBooleanMine] 5 ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
| 4471 | } |
---|
| 4472 | (void) fprintf(vis_stdout, "\n![DebugBooleanMine] LAST ---> nb prevCExArray : %d ", array_n(*preCExArray)); |
---|
| 4473 | (void) fprintf(vis_stdout, "\n![DebugBooleanMine] LAST ---> nb cExArray : %d *END*\n", array_n(cExArray)); |
---|
| 4474 | return cExArray; |
---|
| 4475 | } |
---|
| 4476 | |
---|
| 4477 | |
---|
| 4478 | /**Function******************************************************************** |
---|
| 4479 | |
---|
| 4480 | Synopsis [Debug a formula of type EX.] |
---|
| 4481 | |
---|
| 4482 | Description [Debug a formula of type EX at specified state. It is assumed |
---|
| 4483 | that aState satisfies the EX formula.] |
---|
| 4484 | |
---|
| 4485 | SideEffects [] |
---|
| 4486 | |
---|
| 4487 | ******************************************************************************/ |
---|
| 4488 | static McPath_t * |
---|
| 4489 | DebugEXMine( |
---|
| 4490 | Ctlp_Formula_t *aFormula, |
---|
| 4491 | mdd_t *aState, |
---|
| 4492 | Fsm_Fsm_t *modelFsm, |
---|
| 4493 | array_t *careSetArray) |
---|
| 4494 | { |
---|
| 4495 | (void) fprintf(vis_stdout, "![DebugEXMine] Original CTL Formula : "); |
---|
| 4496 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
| 4497 | (void) fprintf(vis_stdout, "\n![DebugEXMine] MC CTL Formula : "); |
---|
| 4498 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
| 4499 | fprintf(vis_stdout, "\n"); |
---|
| 4500 | |
---|
| 4501 | mdd_t *aDupState = mdd_dup( aState ); |
---|
| 4502 | mdd_t *aStateSuccs; |
---|
| 4503 | mdd_t *statesSatisfyingLeftFormula; |
---|
| 4504 | mdd_t *targetStates; |
---|
| 4505 | mdd_t *witnessSuccState; |
---|
| 4506 | Ctlp_Formula_t *lFormula; |
---|
| 4507 | McPath_t *witnessPath = McPathAlloc(); |
---|
| 4508 | array_t *stemArray = array_alloc( mdd_t *, 0 ); |
---|
| 4509 | Img_ImageInfo_t * imageInfo = Fsm_FsmReadOrCreateImageInfo(modelFsm, 0, 1); |
---|
| 4510 | |
---|
| 4511 | /* |
---|
| 4512 | * By using careSet here, can end up with unreachable successors |
---|
| 4513 | */ |
---|
| 4514 | aStateSuccs = Img_ImageInfoComputeImageWithDomainVars(imageInfo, |
---|
| 4515 | aState, aState, careSetArray); |
---|
| 4516 | |
---|
| 4517 | lFormula = Ctlp_FormulaReadLeftChild( aFormula ); |
---|
| 4518 | statesSatisfyingLeftFormula = Ctlp_FormulaObtainLatestApprox( lFormula ); |
---|
| 4519 | |
---|
| 4520 | targetStates = mdd_and( aStateSuccs, statesSatisfyingLeftFormula, 1, 1 ); |
---|
| 4521 | mdd_free( aStateSuccs ); mdd_free( statesSatisfyingLeftFormula ); |
---|
| 4522 | |
---|
| 4523 | witnessSuccState = Mc_ComputeACloseState( targetStates, aState, modelFsm ); |
---|
| 4524 | mdd_free( targetStates ); |
---|
| 4525 | |
---|
| 4526 | array_insert_last( mdd_t *, stemArray, aDupState ); |
---|
| 4527 | array_insert_last( mdd_t *, stemArray, witnessSuccState ); |
---|
| 4528 | |
---|
| 4529 | McPathSetStemArray( witnessPath, stemArray ); |
---|
| 4530 | |
---|
| 4531 | return witnessPath; |
---|
| 4532 | } |
---|
| 4533 | |
---|
| 4534 | /**Function******************************************************************** |
---|
| 4535 | |
---|
| 4536 | Synopsis [Debug a formula of type EU.] |
---|
| 4537 | |
---|
| 4538 | Description [Debug a formula of type EU at specified state. It is assumed that |
---|
| 4539 | state fails formula.] |
---|
| 4540 | |
---|
| 4541 | SideEffects [] |
---|
| 4542 | |
---|
| 4543 | ******************************************************************************/ |
---|
| 4544 | static McPath_t * |
---|
| 4545 | DebugEUMine( |
---|
| 4546 | Ctlp_Formula_t *aFormula, |
---|
| 4547 | mdd_t *aState, |
---|
| 4548 | Fsm_Fsm_t *modelFsm, |
---|
| 4549 | array_t *careSetArray) |
---|
| 4550 | { |
---|
| 4551 | (void) fprintf(vis_stdout, "![DebugEUMine] Original CTL Formula : "); |
---|
| 4552 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
| 4553 | (void) fprintf(vis_stdout, "\n![DebugEUMine] MC CTL Formula : "); |
---|
| 4554 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
| 4555 | fprintf(vis_stdout, "\n"); |
---|
| 4556 | |
---|
| 4557 | McPath_t *witnessPath = McPathAlloc(); |
---|
| 4558 | array_t *OnionRings = (array_t *) Ctlp_FormulaReadDebugData( aFormula ); |
---|
| 4559 | array_t *pathToCore = Mc_BuildPathToCore(aState, OnionRings, |
---|
| 4560 | modelFsm, |
---|
| 4561 | McGreaterOrEqualZero_c ); |
---|
| 4562 | |
---|
| 4563 | McPathSetStemArray( witnessPath, pathToCore ); |
---|
| 4564 | |
---|
| 4565 | return witnessPath; |
---|
| 4566 | } |
---|
| 4567 | |
---|
| 4568 | /**Function******************************************************************** |
---|
| 4569 | |
---|
| 4570 | Synopsis [Debug a formula of type EG.] |
---|
| 4571 | |
---|
| 4572 | Description [Debug a formula of type EG at specified state. It is assumed |
---|
| 4573 | that state fails formula. Refer to Clarke et al DAC 1995 for details of the |
---|
| 4574 | algorithm.] |
---|
| 4575 | |
---|
| 4576 | SideEffects [] |
---|
| 4577 | |
---|
| 4578 | ******************************************************************************/ |
---|
| 4579 | static McPath_t * |
---|
| 4580 | DebugEGMine( |
---|
| 4581 | Ctlp_Formula_t *aFormula, |
---|
| 4582 | mdd_t *aState, |
---|
| 4583 | Fsm_Fsm_t *modelFsm, |
---|
| 4584 | array_t *careSetArray, |
---|
| 4585 | McOptions_t *options) |
---|
| 4586 | { |
---|
| 4587 | (void) fprintf(vis_stdout, "![DebugEGMine] Original CTL Formula : "); |
---|
| 4588 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(aFormula)); |
---|
| 4589 | (void) fprintf(vis_stdout, "\n![DebugEGMine] MC CTL Formula : "); |
---|
| 4590 | Ctlp_FormulaPrint(vis_stdout, aFormula); |
---|
| 4591 | fprintf(vis_stdout, "\n"); |
---|
| 4592 | |
---|
| 4593 | array_t *arrayOfOnionRings = (array_t *) Ctlp_FormulaReadDebugData(aFormula); |
---|
| 4594 | mdd_t *invariantMdd = Ctlp_FormulaObtainLatestApprox( aFormula ); |
---|
| 4595 | McPath_t *fairPath = McBuildFairPath(aState, invariantMdd, arrayOfOnionRings, |
---|
| 4596 | modelFsm, careSetArray, |
---|
| 4597 | McOptionsReadVerbosityLevel(options), |
---|
| 4598 | McOptionsReadDcLevel(options), |
---|
| 4599 | McOptionsReadFwdBwd(options)); |
---|
| 4600 | mdd_free( invariantMdd ); |
---|
| 4601 | |
---|
| 4602 | return fairPath; |
---|
| 4603 | } |
---|
| 4604 | |
---|
| 4605 | |
---|
| 4606 | /**Function******************************************************************** |
---|
| 4607 | |
---|
| 4608 | Synopsis [Debug a path for EX type formula.] |
---|
| 4609 | |
---|
| 4610 | SideEffects [] |
---|
| 4611 | |
---|
| 4612 | ******************************************************************************/ |
---|
| 4613 | static array_t * |
---|
| 4614 | FsmPathDebugEXFormulaMine( |
---|
| 4615 | McOptions_t *options, |
---|
| 4616 | Ctlp_Formula_t *ctlFormula, |
---|
| 4617 | Fsm_Fsm_t *modelFsm, |
---|
| 4618 | McPath_t *witnessPath, |
---|
| 4619 | array_t *careSetArray, |
---|
| 4620 | array_t **preCExArray) |
---|
| 4621 | { |
---|
| 4622 | |
---|
| 4623 | (void) fprintf(vis_stdout, "![FsmPathDebugEXFormulaMine] Original CTL Formula : "); |
---|
| 4624 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 4625 | (void) fprintf(vis_stdout, "\n![FsmPathDebugEXFormulaMine] MC CTL Formula : "); |
---|
| 4626 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEXFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 4627 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 4628 | fprintf(vis_stdout, "\n"); |
---|
| 4629 | |
---|
| 4630 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 4631 | array_t *witnessArray = McPathReadStemArray( witnessPath ); |
---|
| 4632 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
| 4633 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
| 4634 | Fsm_FsmReadNetwork(modelFsm)); |
---|
| 4635 | Ctlp_Formula_t *lChild = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
| 4636 | char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula ); |
---|
| 4637 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 4638 | mdd_t *secondlastState; |
---|
| 4639 | if(array_n(witnessArray)<2) |
---|
| 4640 | { |
---|
| 4641 | fprintf(vis_stdout,"witnessArray has less than two elements, return\n"); |
---|
| 4642 | if (array_n(witnessArray) > 0) return witnessArray; |
---|
| 4643 | else return NIL(array_t); |
---|
| 4644 | } |
---|
| 4645 | secondlastState= array_fetch( mdd_t *, witnessArray, (array_n(witnessArray)-1) ); |
---|
| 4646 | |
---|
| 4647 | (void) fprintf(vis_stderr, "-[FsmPathDebugEXFormulaMine] array_n(witnessArrayEX) = %d\n",array_n(witnessArray)); |
---|
| 4648 | |
---|
| 4649 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
| 4650 | fprintf(vis_stdout, "--State\n%spasses EX formula\n\n", |
---|
| 4651 | firstStateName); |
---|
| 4652 | else |
---|
| 4653 | fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName, |
---|
| 4654 | ctlFormulaText ); |
---|
| 4655 | |
---|
| 4656 | FREE(firstStateName); |
---|
| 4657 | FREE(ctlFormulaText); |
---|
| 4658 | |
---|
| 4659 | array_t *cExArray; |
---|
| 4660 | // array_t *prevCExArray; |
---|
| 4661 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 4662 | |
---|
| 4663 | switch ( McOptionsReadDbgLevel( options ) ) { |
---|
| 4664 | case McDbgLevelMin_c: |
---|
| 4665 | case McDbgLevelMinVerbose_c: |
---|
| 4666 | case McDbgLevelMax_c: |
---|
| 4667 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 4668 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
| 4669 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 4670 | // cExArray = McFsmStateDebugFormulaMine(options, lChild, secondlastState, modelFsm, careSetArray, prevCExArray); |
---|
| 4671 | cExArray = McFsmStateDebugFormulaMine(options, lChild, secondlastState, modelFsm, careSetArray, *preCExArray); |
---|
| 4672 | break; |
---|
| 4673 | case McDbgLevelInteractive_c: |
---|
| 4674 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 4675 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
| 4676 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 4677 | if (McQueryContinue("Continue debugging EX formula? (1-yes,0-no)\n")) |
---|
| 4678 | // cExArray = McFsmStateDebugFormulaMine(options, lChild, secondlastState, modelFsm, careSetArray, prevCExArray); |
---|
| 4679 | cExArray = McFsmStateDebugFormulaMine(options, lChild, secondlastState, modelFsm, careSetArray, *preCExArray); |
---|
| 4680 | break; |
---|
| 4681 | default: |
---|
| 4682 | fail("Reached bad switch in FsmPathDebugEXFormulaMine\n"); |
---|
| 4683 | } |
---|
| 4684 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEXFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
| 4685 | // array_free(prevCExArray); |
---|
| 4686 | return witnessArray; |
---|
| 4687 | } |
---|
| 4688 | |
---|
| 4689 | |
---|
| 4690 | /**Function******************************************************************** |
---|
| 4691 | |
---|
| 4692 | Synopsis [Debug a path for EU type formula.] |
---|
| 4693 | |
---|
| 4694 | SideEffects [] |
---|
| 4695 | |
---|
| 4696 | ******************************************************************************/ |
---|
| 4697 | static array_t * |
---|
| 4698 | FsmPathDebugEUFormulaMine( |
---|
| 4699 | McOptions_t *options, |
---|
| 4700 | Ctlp_Formula_t *ctlFormula, |
---|
| 4701 | Fsm_Fsm_t *modelFsm, |
---|
| 4702 | McPath_t *witnessPath, |
---|
| 4703 | array_t *careSetArray, |
---|
| 4704 | array_t **preCExArray) |
---|
| 4705 | { |
---|
| 4706 | (void) fprintf(vis_stdout, "![FsmPathDebugEUFormulaMine] Original CTL Formula : "); |
---|
| 4707 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 4708 | (void) fprintf(vis_stdout, "\n![FsmPathDebugEUFormulaMine] MC CTL Formula : "); |
---|
| 4709 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEUFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 4710 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 4711 | fprintf(vis_stdout, "\n"); |
---|
| 4712 | array_t *cExArray; |
---|
| 4713 | // array_t *prevCExArray; |
---|
| 4714 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 4715 | |
---|
| 4716 | char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula ); |
---|
| 4717 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
| 4718 | Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( ctlFormula ); |
---|
| 4719 | char *lFormulaText = Ctlp_FormulaConvertToString( lFormula ); |
---|
| 4720 | char *rFormulaText = Ctlp_FormulaConvertToString( rFormula ); |
---|
| 4721 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 4722 | array_t *witnessArray = McPathReadStemArray( witnessPath ); |
---|
| 4723 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
| 4724 | mdd_t *lastState = GET_NORMAL_PT(array_fetch_last( mdd_t *, witnessArray )); |
---|
| 4725 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
| 4726 | Fsm_FsmReadNetwork(modelFsm)); |
---|
| 4727 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 4728 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 4729 | |
---|
| 4730 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
| 4731 | fprintf(vis_stdout, "--State\n%spasses EU formula\n\n", |
---|
| 4732 | firstStateName); |
---|
| 4733 | else |
---|
| 4734 | fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName, |
---|
| 4735 | ctlFormulaText ); |
---|
| 4736 | |
---|
| 4737 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 4738 | (void) fprintf(vis_stderr, "-[FsmPathDebugEUFormulaMine] *VERIFICATION REQUIRED!* CEx n_state = %d \n", array_n(witnessArray)); |
---|
| 4739 | Mc_PrintPath(witnessArray, modelFsm, printInputs); // added |
---|
| 4740 | } |
---|
| 4741 | |
---|
| 4742 | (void) fprintf(vis_stderr, "-[FsmPathDebugEUFormulaMine] array_n(witnessArrayEU) = %d\n",array_n(witnessArray)); |
---|
| 4743 | |
---|
| 4744 | FREE(firstStateName); |
---|
| 4745 | FREE(ctlFormulaText); |
---|
| 4746 | |
---|
| 4747 | switch ( debugLevel ) { |
---|
| 4748 | case McDbgLevelMin_c: |
---|
| 4749 | case McDbgLevelMinVerbose_c: |
---|
| 4750 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 4751 | if( debugLevel != McDbgLevelMin_c ) |
---|
| 4752 | fprintf(vis_stdout, "since %s is true at this state", rFormulaText); |
---|
| 4753 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 4754 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 4755 | } |
---|
| 4756 | else { |
---|
| 4757 | if( debugLevel != McDbgLevelMin_c ) |
---|
| 4758 | fprintf(vis_stdout, "--Path on which %s is true till %s is true\n", |
---|
| 4759 | lFormulaText, rFormulaText); |
---|
| 4760 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 4761 | Mc_PrintPath(witnessArray, modelFsm, printInputs); |
---|
| 4762 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 4763 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 4764 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 4765 | } |
---|
| 4766 | break; |
---|
| 4767 | case McDbgLevelMax_c: |
---|
| 4768 | case McDbgLevelInteractive_c: |
---|
| 4769 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 4770 | fprintf(vis_stdout, "since %s is true at this state", rFormulaText); |
---|
| 4771 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 4772 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 4773 | } |
---|
| 4774 | else { |
---|
| 4775 | int i; |
---|
| 4776 | fprintf(vis_stdout, "--Path on which %s is true till %s is true\n", |
---|
| 4777 | lFormulaText, rFormulaText); |
---|
| 4778 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 4779 | Mc_PrintPath(witnessArray,modelFsm,printInputs); |
---|
| 4780 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 4781 | for( i=0 ; i < ( array_n( witnessArray ) - 1 ); i++ ) { |
---|
| 4782 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
| 4783 | |
---|
| 4784 | if (debugLevel == McDbgLevelMax_c || |
---|
| 4785 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 4786 | McQueryContinue( |
---|
| 4787 | "Continue debugging EU formula? (1-yes,0-no)\n"))) { |
---|
| 4788 | // cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
| 4789 | cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
| 4790 | } |
---|
| 4791 | } |
---|
| 4792 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 4793 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 4794 | } |
---|
| 4795 | break; |
---|
| 4796 | default: |
---|
| 4797 | fail("Should not be here - bad switch in debugging EU formula\n"); |
---|
| 4798 | } |
---|
| 4799 | |
---|
| 4800 | FREE(lFormulaText); |
---|
| 4801 | FREE(rFormulaText); |
---|
| 4802 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEUFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
| 4803 | // array_free(prevCExArray); |
---|
| 4804 | return witnessArray; |
---|
| 4805 | } |
---|
| 4806 | |
---|
| 4807 | /**Function******************************************************************** |
---|
| 4808 | |
---|
| 4809 | Synopsis [Debug a path for EG type formula.] |
---|
| 4810 | |
---|
| 4811 | SideEffects [] |
---|
| 4812 | |
---|
| 4813 | ******************************************************************************/ |
---|
| 4814 | static array_t * |
---|
| 4815 | FsmPathDebugEGFormulaMine( |
---|
| 4816 | McOptions_t *options, |
---|
| 4817 | Ctlp_Formula_t *ctlFormula, |
---|
| 4818 | Fsm_Fsm_t *modelFsm, |
---|
| 4819 | McPath_t *witnessPath, |
---|
| 4820 | array_t *careSetArray, |
---|
| 4821 | array_t **preCExArray) |
---|
| 4822 | { |
---|
| 4823 | (void) fprintf(vis_stdout, "![FsmPathDebugEGFormulaMine] Original CTL Formula : "); |
---|
| 4824 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 4825 | (void) fprintf(vis_stdout, "\n![FsmPathDebugEGFormulaMine] MC CTL Formula : "); |
---|
| 4826 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEGFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 4827 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 4828 | fprintf(vis_stdout, "\n"); |
---|
| 4829 | array_t *cExArray; |
---|
| 4830 | // array_t *prevCExArray; |
---|
| 4831 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 4832 | |
---|
| 4833 | mdd_t *firstState; |
---|
| 4834 | char *firstStateName; |
---|
| 4835 | array_t *witnessArray; |
---|
| 4836 | array_t *witness; |
---|
| 4837 | char *ctlFormulaText = Ctlp_FormulaConvertToString( ctlFormula ); |
---|
| 4838 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 4839 | array_t *stemArray = McPathReadStemArray( witnessPath ); |
---|
| 4840 | array_t *cycleArray = McPathReadCycleArray( witnessPath ); |
---|
| 4841 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
| 4842 | char *lFormulaText = Ctlp_FormulaConvertToString( lFormula ); |
---|
| 4843 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 4844 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 4845 | |
---|
| 4846 | witnessArray = McCreateMergedPath( stemArray, cycleArray ); |
---|
| 4847 | firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
| 4848 | firstStateName = Mc_MintermToString(firstState, PSVars,Fsm_FsmReadNetwork(modelFsm)); |
---|
| 4849 | |
---|
| 4850 | |
---|
| 4851 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(stemArrayEG) = %d\n",array_n(stemArray)); |
---|
| 4852 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(cycleArrayEG) = %d\n",array_n(cycleArray)); |
---|
| 4853 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(witnessArrayEG) = %d\n",array_n(witnessArray)); |
---|
| 4854 | |
---|
| 4855 | |
---|
| 4856 | |
---|
| 4857 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
| 4858 | fprintf(vis_stdout, "--State\n%spasses EG formula\n\n", |
---|
| 4859 | firstStateName); |
---|
| 4860 | else |
---|
| 4861 | fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName, |
---|
| 4862 | ctlFormulaText ); |
---|
| 4863 | |
---|
| 4864 | FREE(firstStateName); |
---|
| 4865 | FREE(ctlFormulaText); |
---|
| 4866 | |
---|
| 4867 | switch ( debugLevel ) { |
---|
| 4868 | case McDbgLevelMin_c: |
---|
| 4869 | case McDbgLevelMinVerbose_c: { |
---|
| 4870 | McPath_t *normalPath = McPathNormalize( witnessPath ); |
---|
| 4871 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
| 4872 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
| 4873 | |
---|
| 4874 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
| 4875 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
| 4876 | witness = McCreateMergedPath( stem, cycle ); |
---|
| 4877 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
| 4878 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 4879 | Mc_PrintPath( witness, modelFsm, printInputs ); |
---|
| 4880 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 4881 | |
---|
| 4882 | if(debugLevel != McDbgLevelMin_c) |
---|
| 4883 | fprintf(vis_stdout, "--Witness is a fair path where %s is always true\n", |
---|
| 4884 | lFormulaText); |
---|
| 4885 | |
---|
| 4886 | FREE( lFormulaText ); |
---|
| 4887 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 4888 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
| 4889 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
| 4890 | |
---|
| 4891 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
| 4892 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
| 4893 | fprintf(vis_stdout, "\n"); |
---|
| 4894 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 4895 | McPathFree( normalPath ); |
---|
| 4896 | break; |
---|
| 4897 | } |
---|
| 4898 | case McDbgLevelMax_c: |
---|
| 4899 | case McDbgLevelInteractive_c: { |
---|
| 4900 | McPath_t *normalPath = McPathNormalize( witnessPath ); |
---|
| 4901 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
| 4902 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
| 4903 | int i; |
---|
| 4904 | |
---|
| 4905 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
| 4906 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
| 4907 | witness = McCreateMergedPath( stem, cycle ); |
---|
| 4908 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
| 4909 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 4910 | Mc_PrintPath( witness, modelFsm, printInputs ); |
---|
| 4911 | (void) fprintf(vis_stderr, "-[FsmPathDebugEGFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 4912 | |
---|
| 4913 | fprintf(vis_stdout, "--Witness is a fair path where %s is always true\n", |
---|
| 4914 | lFormulaText); |
---|
| 4915 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 4916 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
| 4917 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
| 4918 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
| 4919 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
| 4920 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 4921 | for( i=0 ; i < ( array_n( witnessArray )-1 ); i++ ) { |
---|
| 4922 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
| 4923 | |
---|
| 4924 | if (debugLevel == McDbgLevelMax_c || |
---|
| 4925 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 4926 | McQueryContinue( |
---|
| 4927 | "--Continue debugging EG formula? (1-yes,0-no)\n"))) { |
---|
| 4928 | // cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
| 4929 | cExArray = McFsmStateDebugFormulaMine(options, lFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
| 4930 | } |
---|
| 4931 | } |
---|
| 4932 | break; |
---|
| 4933 | } |
---|
| 4934 | default: |
---|
| 4935 | fail("Bad switch in FsmPathDebugEGFormulaMine\n"); |
---|
| 4936 | witness = NIL(array_t); |
---|
| 4937 | } |
---|
| 4938 | |
---|
| 4939 | McNormalizeBddPointer(witnessArray); |
---|
| 4940 | mdd_array_free( witnessArray ); |
---|
| 4941 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEGFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
| 4942 | // array_free(prevCExArray); |
---|
| 4943 | return witness; |
---|
| 4944 | } |
---|
| 4945 | |
---|
| 4946 | /**Function******************************************************************** |
---|
| 4947 | |
---|
| 4948 | Synopsis [Debug a EF formula] |
---|
| 4949 | |
---|
| 4950 | SideEffects [] |
---|
| 4951 | |
---|
| 4952 | ******************************************************************************/ |
---|
| 4953 | static array_t * |
---|
| 4954 | FsmPathDebugEFFormulaMine( |
---|
| 4955 | McOptions_t *options, |
---|
| 4956 | Ctlp_Formula_t *ctlFormula, |
---|
| 4957 | Fsm_Fsm_t *modelFsm, |
---|
| 4958 | McPath_t *witnessPath, |
---|
| 4959 | array_t *careSetArray, |
---|
| 4960 | array_t **preCExArray) |
---|
| 4961 | { |
---|
| 4962 | (void) fprintf(vis_stdout, "![FsmPathDebugEFFormulaMine] Original CTL Formula : "); |
---|
| 4963 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 4964 | (void) fprintf(vis_stdout, "\n![FsmPathDebugEFFormulaMine] MC CTL Formula : "); |
---|
| 4965 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEFFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 4966 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 4967 | fprintf(vis_stdout, "\n"); |
---|
| 4968 | array_t *cExArray; |
---|
| 4969 | // array_t *prevCExArray; |
---|
| 4970 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 4971 | |
---|
| 4972 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
| 4973 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
| 4974 | |
---|
| 4975 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 4976 | array_t *witnessArray = McPathReadStemArray( witnessPath ); |
---|
| 4977 | |
---|
| 4978 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
| 4979 | mdd_t *lastState = array_fetch_last( mdd_t *, witnessArray ); |
---|
| 4980 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
| 4981 | Fsm_FsmReadNetwork(modelFsm)); |
---|
| 4982 | |
---|
| 4983 | Ctlp_Formula_t *rFormula = Ctlp_FormulaReadRightChild( ctlFormula ); |
---|
| 4984 | Ctlp_Formula_t *rOriginalFormula = Ctlp_FormulaReadOriginalFormula(rFormula); |
---|
| 4985 | char *rOriginalFormulaText = Ctlp_FormulaConvertToString( rOriginalFormula ); |
---|
| 4986 | char *rFormulaText = Ctlp_FormulaConvertToString( rFormula ); |
---|
| 4987 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 4988 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 4989 | |
---|
| 4990 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
| 4991 | fprintf(vis_stdout, "--State\n%spasses EF formula\n\n", |
---|
| 4992 | firstStateName); |
---|
| 4993 | else |
---|
| 4994 | fprintf(vis_stdout, "--State\n%spasses formula %s\n\n", firstStateName, |
---|
| 4995 | originalFormulaText ); |
---|
| 4996 | |
---|
| 4997 | // Added in case if there's no counter example => CTL fails at initial state |
---|
| 4998 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAGFormulaMine] 1) CEx n_state = %d \n", array_n(witnessArray)); |
---|
| 4999 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 5000 | (void) fprintf(vis_stderr, "-[FsmPathDebugEFFormulaMine] *VERIFICATION REQUIRED!* CEx n_state = %d \n", array_n(witnessArray)); |
---|
| 5001 | Mc_PrintPath(witnessArray, modelFsm, printInputs); // added |
---|
| 5002 | } |
---|
| 5003 | (void) fprintf(vis_stderr, "-[FsmPathDebugEFFormulaMine] array_n(witnessArrayEF) = %d\n",array_n(witnessArray)); |
---|
| 5004 | |
---|
| 5005 | FREE(firstStateName); |
---|
| 5006 | FREE(originalFormulaText); |
---|
| 5007 | |
---|
| 5008 | switch ( debugLevel ) { |
---|
| 5009 | case McDbgLevelMin_c: |
---|
| 5010 | case McDbgLevelMinVerbose_c: |
---|
| 5011 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 5012 | if( debugLevel != McDbgLevelMin_c) |
---|
| 5013 | fprintf(vis_stdout, "since %s is true at this state\n", |
---|
| 5014 | rOriginalFormulaText); |
---|
| 5015 | |
---|
| 5016 | FREE( rOriginalFormulaText ); |
---|
| 5017 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5018 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5019 | } |
---|
| 5020 | else { |
---|
| 5021 | if( debugLevel != McDbgLevelMin_c) |
---|
| 5022 | fprintf(vis_stdout, |
---|
| 5023 | "--Witness is a path to a state where %s is finally true\n", |
---|
| 5024 | rOriginalFormulaText); |
---|
| 5025 | (void) fprintf( vis_stdout, "\n--Fair path stem:\n"); |
---|
| 5026 | FREE( rOriginalFormulaText ); |
---|
| 5027 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5028 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
| 5029 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5030 | } |
---|
| 5031 | break; |
---|
| 5032 | case McDbgLevelMax_c: |
---|
| 5033 | case McDbgLevelInteractive_c: |
---|
| 5034 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 5035 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5036 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5037 | } |
---|
| 5038 | else |
---|
| 5039 | { |
---|
| 5040 | fprintf(vis_stdout, |
---|
| 5041 | "--Witness is a path to a state where %s is finally true\n", |
---|
| 5042 | rOriginalFormulaText); |
---|
| 5043 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5044 | Mc_PrintPath( witnessArray, modelFsm, printInputs); |
---|
| 5045 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5046 | if (debugLevel == McDbgLevelMax_c || |
---|
| 5047 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 5048 | McQueryContinue( |
---|
| 5049 | "--Continue debugging EF formula? (1-yes,0-no)\n"))) |
---|
| 5050 | { |
---|
| 5051 | // cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5052 | cExArray = McFsmStateDebugFormulaMine(options, rFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5053 | } |
---|
| 5054 | } |
---|
| 5055 | break; |
---|
| 5056 | default: |
---|
| 5057 | fail("bad switch in debugging EF\n"); |
---|
| 5058 | } |
---|
| 5059 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugEFFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
| 5060 | // array_free(prevCExArray); |
---|
| 5061 | FREE(rFormulaText); |
---|
| 5062 | return witnessArray; |
---|
| 5063 | } |
---|
| 5064 | |
---|
| 5065 | |
---|
| 5066 | /**Function******************************************************************** |
---|
| 5067 | |
---|
| 5068 | Synopsis [Debug a AX formula] |
---|
| 5069 | |
---|
| 5070 | SideEffects [] |
---|
| 5071 | |
---|
| 5072 | ******************************************************************************/ |
---|
| 5073 | static array_t * |
---|
| 5074 | FsmPathDebugAXFormulaMine( |
---|
| 5075 | McOptions_t *options, |
---|
| 5076 | Ctlp_Formula_t *ctlFormula, |
---|
| 5077 | Fsm_Fsm_t *modelFsm, |
---|
| 5078 | McPath_t *counterExamplePath, |
---|
| 5079 | array_t *careSetArray, |
---|
| 5080 | array_t **preCExArray) |
---|
| 5081 | { |
---|
| 5082 | (void) fprintf(vis_stdout, "![FsmPathDebugAXFormulaMine] Original CTL Formula : "); |
---|
| 5083 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 5084 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAXFormulaMine] MC CTL Formula : "); |
---|
| 5085 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAXFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 5086 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 5087 | fprintf(vis_stdout, "\n"); |
---|
| 5088 | array_t *cExArray; |
---|
| 5089 | // array_t *prevCExArray; |
---|
| 5090 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 5091 | |
---|
| 5092 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
| 5093 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
| 5094 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
| 5095 | Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula ); |
---|
| 5096 | Ctlp_Formula_t *lllFormula = Ctlp_FormulaReadLeftChild( llFormula ); |
---|
| 5097 | |
---|
| 5098 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 5099 | array_t *witnessArray = McPathReadStemArray( counterExamplePath ); |
---|
| 5100 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
| 5101 | mdd_t *lastState = array_fetch( mdd_t *, witnessArray, 1 ); |
---|
| 5102 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
| 5103 | Fsm_FsmReadNetwork(modelFsm)); |
---|
| 5104 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 5105 | |
---|
| 5106 | (void) fprintf(vis_stderr, "-[FsmPathDebugAXFormulaMine] array_n(witnessArrayAX) = %d\n",array_n(witnessArray)); |
---|
| 5107 | |
---|
| 5108 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
| 5109 | fprintf(vis_stdout, "--State\n%sfails AX formula\n\n", |
---|
| 5110 | firstStateName); |
---|
| 5111 | else |
---|
| 5112 | fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName, |
---|
| 5113 | originalFormulaText ); |
---|
| 5114 | |
---|
| 5115 | FREE(firstStateName); |
---|
| 5116 | FREE(originalFormulaText); |
---|
| 5117 | |
---|
| 5118 | switch ( McOptionsReadDbgLevel( options ) ) { |
---|
| 5119 | case McDbgLevelMin_c: |
---|
| 5120 | case McDbgLevelMinVerbose_c: |
---|
| 5121 | case McDbgLevelMax_c: |
---|
| 5122 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5123 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
| 5124 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5125 | fprintf(vis_stdout, "\n"); |
---|
| 5126 | // cExArray = McFsmStateDebugFormulaMine(options, lllFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5127 | cExArray = McFsmStateDebugFormulaMine(options, lllFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5128 | break; |
---|
| 5129 | case McDbgLevelInteractive_c: |
---|
| 5130 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5131 | Mc_PrintPath( witnessArray, modelFsm, printInputs ); |
---|
| 5132 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5133 | if ( McQueryContinue("Continue debugging EX formula? (1-yes,0-no)\n") ) { |
---|
| 5134 | // cExArray = McFsmStateDebugFormulaMine(options, lllFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5135 | cExArray = McFsmStateDebugFormulaMine(options, lllFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5136 | } |
---|
| 5137 | break; |
---|
| 5138 | default: |
---|
| 5139 | fail("Bad switch in FsmPathDebugAXFormulaMine\n"); |
---|
| 5140 | } |
---|
| 5141 | |
---|
| 5142 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAXFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
| 5143 | // array_free(prevCExArray); |
---|
| 5144 | return witnessArray; |
---|
| 5145 | } |
---|
| 5146 | |
---|
| 5147 | /**Function******************************************************************** |
---|
| 5148 | |
---|
| 5149 | Synopsis [Debug a AF formula] |
---|
| 5150 | |
---|
| 5151 | SideEffects [] |
---|
| 5152 | |
---|
| 5153 | ******************************************************************************/ |
---|
| 5154 | static array_t * |
---|
| 5155 | FsmPathDebugAFFormulaMine( |
---|
| 5156 | McOptions_t *options, |
---|
| 5157 | Ctlp_Formula_t *ctlFormula, |
---|
| 5158 | Fsm_Fsm_t *modelFsm, |
---|
| 5159 | McPath_t *counterExamplePath, |
---|
| 5160 | array_t *careSetArray, |
---|
| 5161 | array_t **preCExArray) |
---|
| 5162 | { |
---|
| 5163 | (void) fprintf(vis_stdout, "![FsmPathDebugAFFormulaMine] Original CTL Formula : "); |
---|
| 5164 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 5165 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAFFormulaMine] MC CTL Formula : "); |
---|
| 5166 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAFFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 5167 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 5168 | fprintf(vis_stdout, "\n"); |
---|
| 5169 | array_t *cExArray; |
---|
| 5170 | // array_t *prevCExArray; |
---|
| 5171 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 5172 | |
---|
| 5173 | |
---|
| 5174 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
| 5175 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
| 5176 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
| 5177 | Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula ); |
---|
| 5178 | Ctlp_Formula_t *lllFormula = Ctlp_FormulaReadLeftChild( llFormula ); |
---|
| 5179 | Ctlp_Formula_t *lllOriginalFormula = Ctlp_FormulaReadOriginalFormula( |
---|
| 5180 | lllFormula); |
---|
| 5181 | char *lllOriginalFormulaText = Ctlp_FormulaConvertToString( |
---|
| 5182 | lllOriginalFormula); |
---|
| 5183 | |
---|
| 5184 | mdd_t *firstState; |
---|
| 5185 | array_t *witnessArray; |
---|
| 5186 | array_t *witness; |
---|
| 5187 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 5188 | array_t *stemArray = McPathReadStemArray( counterExamplePath ); |
---|
| 5189 | array_t *cycleArray = McPathReadCycleArray( counterExamplePath ); |
---|
| 5190 | char *firstStateName; |
---|
| 5191 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 5192 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 5193 | |
---|
| 5194 | witnessArray = McCreateMergedPath( stemArray, cycleArray ); |
---|
| 5195 | firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
| 5196 | firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
| 5197 | Fsm_FsmReadNetwork(modelFsm)); |
---|
| 5198 | |
---|
| 5199 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(stemArrayEG) = %d\n",array_n(stemArray)); |
---|
| 5200 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(cycleArrayEG) = %d\n",array_n(cycleArray)); |
---|
| 5201 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(witnessArrayEG) = %d\n",array_n(witnessArray)); |
---|
| 5202 | |
---|
| 5203 | |
---|
| 5204 | |
---|
| 5205 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
| 5206 | fprintf(vis_stdout, "--State\n%sfails AF formula\n\n", |
---|
| 5207 | firstStateName); |
---|
| 5208 | else |
---|
| 5209 | fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName, |
---|
| 5210 | originalFormulaText ); |
---|
| 5211 | FREE(firstStateName); |
---|
| 5212 | FREE(originalFormulaText); |
---|
| 5213 | |
---|
| 5214 | switch ( debugLevel ) { |
---|
| 5215 | case McDbgLevelMin_c: |
---|
| 5216 | case McDbgLevelMinVerbose_c: { |
---|
| 5217 | McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
| 5218 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
| 5219 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
| 5220 | |
---|
| 5221 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
| 5222 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
| 5223 | witness = McCreateMergedPath( stem, cycle ); |
---|
| 5224 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
| 5225 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 5226 | Mc_PrintPath( witness, modelFsm, printInputs ); |
---|
| 5227 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 5228 | |
---|
| 5229 | if( debugLevel != McDbgLevelMin_c) |
---|
| 5230 | fprintf(vis_stdout, "--A fair path on which %s is always false:\n", |
---|
| 5231 | lllOriginalFormulaText ); |
---|
| 5232 | |
---|
| 5233 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5234 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
| 5235 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
| 5236 | |
---|
| 5237 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
| 5238 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
| 5239 | fprintf(vis_stdout, "\n"); |
---|
| 5240 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5241 | McPathFree( normalPath ); |
---|
| 5242 | break; |
---|
| 5243 | } |
---|
| 5244 | case McDbgLevelMax_c: |
---|
| 5245 | case McDbgLevelInteractive_c: { |
---|
| 5246 | int i; |
---|
| 5247 | McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
| 5248 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
| 5249 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
| 5250 | |
---|
| 5251 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
| 5252 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
| 5253 | witness = McCreateMergedPath( stem, cycle ); |
---|
| 5254 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
| 5255 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 5256 | Mc_PrintPath( witness, modelFsm, printInputs ); |
---|
| 5257 | (void) fprintf(vis_stderr, "-[FsmPathDebugAFFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 5258 | |
---|
| 5259 | |
---|
| 5260 | fprintf(vis_stdout, "--A fair path on which %s is always false:\n", |
---|
| 5261 | lllOriginalFormulaText ); |
---|
| 5262 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5263 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
| 5264 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
| 5265 | |
---|
| 5266 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
| 5267 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
| 5268 | fprintf(vis_stdout, "\n"); |
---|
| 5269 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5270 | McPathFree( normalPath ); |
---|
| 5271 | for( i=0 ; i < ( array_n( witnessArray )-1 ); i++ ) { |
---|
| 5272 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
| 5273 | |
---|
| 5274 | if (debugLevel == McDbgLevelMax_c || |
---|
| 5275 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 5276 | McQueryContinue( |
---|
| 5277 | "--Continue debugging AF formula? (1-yes,0-no)\n"))) { |
---|
| 5278 | // cExArray = McFsmStateDebugFormulaMine(options, lllFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
| 5279 | cExArray = McFsmStateDebugFormulaMine(options, lllFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
| 5280 | } |
---|
| 5281 | } |
---|
| 5282 | |
---|
| 5283 | break; |
---|
| 5284 | } |
---|
| 5285 | default: { |
---|
| 5286 | fail("Bad case in switch for debugging AF formula\n"); |
---|
| 5287 | witness = NIL(array_t); |
---|
| 5288 | } |
---|
| 5289 | } |
---|
| 5290 | |
---|
| 5291 | // array_free(prevCExArray); |
---|
| 5292 | McNormalizeBddPointer(witnessArray); |
---|
| 5293 | mdd_array_free( witnessArray ); |
---|
| 5294 | FREE(lllOriginalFormulaText); |
---|
| 5295 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAFFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
| 5296 | return witness; |
---|
| 5297 | } |
---|
| 5298 | |
---|
| 5299 | /**Function******************************************************************** |
---|
| 5300 | |
---|
| 5301 | Synopsis [Debug an AG formula.] |
---|
| 5302 | |
---|
| 5303 | Description [Debugs an AG formula. What it really wants is a formula of the |
---|
| 5304 | form !EF! phi, that was converted from the formula AG phi, with all the |
---|
| 5305 | converted pointers set as required: the top ! points to the original AG |
---|
| 5306 | formula, and top node of phi points to the original phi.] |
---|
| 5307 | |
---|
| 5308 | SideEffects [] |
---|
| 5309 | |
---|
| 5310 | ******************************************************************************/ |
---|
| 5311 | static array_t * |
---|
| 5312 | FsmPathDebugAGFormulaMine( |
---|
| 5313 | McOptions_t *options, |
---|
| 5314 | Ctlp_Formula_t *ctlFormula, |
---|
| 5315 | Fsm_Fsm_t *modelFsm, |
---|
| 5316 | McPath_t *counterExamplePath, |
---|
| 5317 | array_t *careSetArray, |
---|
| 5318 | array_t **preCExArray) |
---|
| 5319 | { |
---|
| 5320 | (void) fprintf(vis_stdout, "![FsmPathDebugAGFormulaMine] Original CTL Formula : "); |
---|
| 5321 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 5322 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAGFormulaMine] MC CTL Formula : "); |
---|
| 5323 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAGFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 5324 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 5325 | fprintf(vis_stdout, "\n"); |
---|
| 5326 | array_t *cExArray; |
---|
| 5327 | // array_t *prevCExArray; |
---|
| 5328 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 5329 | |
---|
| 5330 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
| 5331 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
| 5332 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
| 5333 | Ctlp_Formula_t *lrFormula = Ctlp_FormulaReadRightChild( lFormula ); |
---|
| 5334 | Ctlp_Formula_t *lrlFormula = Ctlp_FormulaReadLeftChild( lrFormula ); |
---|
| 5335 | Ctlp_Formula_t *lrlOriginalFormula = Ctlp_FormulaReadOriginalFormula( |
---|
| 5336 | lrlFormula); |
---|
| 5337 | char *lrlOriginalFormulaText = Ctlp_FormulaConvertToString( |
---|
| 5338 | lrlOriginalFormula); |
---|
| 5339 | |
---|
| 5340 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 5341 | array_t *witnessArray = McPathReadStemArray( counterExamplePath ); |
---|
| 5342 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
| 5343 | mdd_t *lastState = GET_NORMAL_PT(array_fetch_last( mdd_t *, witnessArray )); |
---|
| 5344 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
| 5345 | Fsm_FsmReadNetwork(modelFsm)); |
---|
| 5346 | |
---|
| 5347 | // CEXStruct CEXPath [array_n( aPath )]; |
---|
| 5348 | // *Mc_MintermToStringMine( mdd_t *aMinterm, array_t *aSupport, Ntk_Network_t *aNetwork, CEXStruct *CEXPath, int seqNumber, boolean inOutIndicator, BmcCnfClauses_t *cnfClauses); |
---|
| 5349 | (void) fprintf(vis_stderr, "-[FsmPathDebugAGFormulaMine] array_n(witnessArrayAG) = %d\n",array_n(witnessArray)); |
---|
| 5350 | |
---|
| 5351 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 5352 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 5353 | |
---|
| 5354 | assert( Ctlp_FormulaReadType(ctlFormula) == Ctlp_NOT_c ); |
---|
| 5355 | assert( Ctlp_FormulaTestIsConverted(ctlFormula) ); |
---|
| 5356 | assert( Ctlp_FormulaReadType(originalFormula) == Ctlp_AG_c ); |
---|
| 5357 | assert( originalFormulaText != NIL(char) ); |
---|
| 5358 | assert( Ctlp_FormulaReadType(lFormula) == Ctlp_EU_c ); |
---|
| 5359 | assert( Ctlp_FormulaReadType(Ctlp_FormulaReadLeftChild(lFormula)) == |
---|
| 5360 | Ctlp_TRUE_c ); |
---|
| 5361 | assert( Ctlp_FormulaReadType(lrFormula) == Ctlp_NOT_c ); |
---|
| 5362 | assert( lrlOriginalFormula != NIL(Ctlp_Formula_t) ); |
---|
| 5363 | |
---|
| 5364 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
| 5365 | fprintf(vis_stdout, "--State\n%sfails AG formula\n\n", |
---|
| 5366 | firstStateName); |
---|
| 5367 | else |
---|
| 5368 | fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName, |
---|
| 5369 | originalFormulaText ); |
---|
| 5370 | |
---|
| 5371 | // Added in case if there's no counter example => CTL fails at initial state |
---|
| 5372 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAGFormulaMine] 1) CEx n_state = %d \n", array_n(witnessArray)); |
---|
| 5373 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 5374 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAGFormulaMine] 2) CEx n_state = %d \n", array_n(witnessArray)); |
---|
| 5375 | Mc_PrintPath(witnessArray, modelFsm, printInputs); // added |
---|
| 5376 | } |
---|
| 5377 | FREE(firstStateName); |
---|
| 5378 | FREE(originalFormulaText); |
---|
| 5379 | |
---|
| 5380 | switch ( debugLevel ) { |
---|
| 5381 | case McDbgLevelMin_c: |
---|
| 5382 | case McDbgLevelMinVerbose_c:{ |
---|
| 5383 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 5384 | if( debugLevel != McDbgLevelMin_c) |
---|
| 5385 | fprintf(vis_stdout, "since %s is false at this state\n", |
---|
| 5386 | lrlOriginalFormulaText ); |
---|
| 5387 | // cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5388 | cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5389 | } |
---|
| 5390 | else { |
---|
| 5391 | if( debugLevel != McDbgLevelMin_c) |
---|
| 5392 | fprintf(vis_stdout, |
---|
| 5393 | "--Counter example is a path to a state where %s is false\n", |
---|
| 5394 | lrlOriginalFormulaText); |
---|
| 5395 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5396 | Mc_PrintPath(witnessArray, modelFsm, printInputs); |
---|
| 5397 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5398 | // cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5399 | cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5400 | } |
---|
| 5401 | break; |
---|
| 5402 | } |
---|
| 5403 | case McDbgLevelMax_c: |
---|
| 5404 | case McDbgLevelInteractive_c: { |
---|
| 5405 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 5406 | if( debugLevel != McDbgLevelMin_c) |
---|
| 5407 | fprintf(vis_stdout, "since %s is false at this state\n", |
---|
| 5408 | lrlOriginalFormulaText ); |
---|
| 5409 | // cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5410 | cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5411 | } |
---|
| 5412 | else { |
---|
| 5413 | fprintf(vis_stdout, |
---|
| 5414 | "--Counter example is a path to a state where %s is false\n", |
---|
| 5415 | lrlOriginalFormulaText); |
---|
| 5416 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5417 | Mc_PrintPath( witnessArray, modelFsm, printInputs); |
---|
| 5418 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5419 | if (debugLevel == McDbgLevelMax_c || |
---|
| 5420 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 5421 | McQueryContinue( |
---|
| 5422 | "--Continue debugging AG formula? (1-yes,0-no)\n"))) |
---|
| 5423 | { |
---|
| 5424 | // cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5425 | cExArray = McFsmStateDebugFormulaMine(options, lrlFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5426 | } |
---|
| 5427 | } |
---|
| 5428 | break; |
---|
| 5429 | } |
---|
| 5430 | default: { |
---|
| 5431 | fail("bad switch in debugging AG\n"); |
---|
| 5432 | } |
---|
| 5433 | } |
---|
| 5434 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAGFormulaMine] ---> nb prevCExArray : %d *END*\n", array_n(prevCExArray)); |
---|
| 5435 | // array_free(prevCExArray); |
---|
| 5436 | FREE(lrlOriginalFormulaText); |
---|
| 5437 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAGFormulaMine] *** Mc_PrintPathMine STARTS ----------------------\n"); |
---|
| 5438 | // Mc_PrintPathMine(witnessArray, modelFsm, printInputs); |
---|
| 5439 | // (void) fprintf(vis_stdout, "![FsmPathDebugAGFormulaMine] Mc_PrintPathMine ENDS *** -------------------------\n"); |
---|
| 5440 | return witnessArray; |
---|
| 5441 | } |
---|
| 5442 | |
---|
| 5443 | /**Function******************************************************************** |
---|
| 5444 | |
---|
| 5445 | Synopsis [Debug a AU formula] |
---|
| 5446 | |
---|
| 5447 | SideEffects [] |
---|
| 5448 | |
---|
| 5449 | ******************************************************************************/ |
---|
| 5450 | static array_t * |
---|
| 5451 | FsmPathDebugAUFormulaMine( |
---|
| 5452 | McOptions_t *options, |
---|
| 5453 | mdd_t *aState, |
---|
| 5454 | Ctlp_Formula_t *ctlFormula, |
---|
| 5455 | Fsm_Fsm_t *modelFsm, |
---|
| 5456 | array_t *careSetArray, |
---|
| 5457 | array_t **preCExArray) |
---|
| 5458 | { |
---|
| 5459 | (void) fprintf(vis_stdout, "![FsmPathDebugAUFormulaMine] Original CTL Formula : "); |
---|
| 5460 | Ctlp_FormulaPrint(vis_stdout, Ctlp_FormulaReadOriginalFormula(ctlFormula)); |
---|
| 5461 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] MC CTL Formula : "); |
---|
| 5462 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 0 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
| 5463 | Ctlp_FormulaPrint(vis_stdout, ctlFormula); |
---|
| 5464 | fprintf(vis_stdout, "\n"); |
---|
| 5465 | array_t *cExArray; |
---|
| 5466 | // array_t *prevCExArray; |
---|
| 5467 | // prevCExArray = array_alloc(mdd_t *, 0); //Note: added just to respect arg requirements but not used |
---|
| 5468 | |
---|
| 5469 | Ctlp_Formula_t *originalFormula = Ctlp_FormulaReadOriginalFormula(ctlFormula); |
---|
| 5470 | char *originalFormulaText = Ctlp_FormulaConvertToString( originalFormula ); |
---|
| 5471 | Ctlp_Formula_t *lFormula = Ctlp_FormulaReadLeftChild( ctlFormula ); |
---|
| 5472 | Ctlp_Formula_t *lrFormula = Ctlp_FormulaReadRightChild( lFormula ); |
---|
| 5473 | Ctlp_Formula_t *lrlFormula = Ctlp_FormulaReadLeftChild( lrFormula ); |
---|
| 5474 | Ctlp_Formula_t *lrllFormula = Ctlp_FormulaReadLeftChild( lrlFormula ); |
---|
| 5475 | Ctlp_Formula_t *llFormula = Ctlp_FormulaReadLeftChild( lFormula ); |
---|
| 5476 | Ctlp_Formula_t *llrFormula = Ctlp_FormulaReadRightChild( llFormula ); |
---|
| 5477 | Ctlp_Formula_t *llrlFormula = Ctlp_FormulaReadLeftChild( llrFormula ); |
---|
| 5478 | Ctlp_Formula_t *llrllFormula = Ctlp_FormulaReadLeftChild( llrlFormula ); |
---|
| 5479 | Ctlp_Formula_t *fFormula = llrllFormula; |
---|
| 5480 | Ctlp_Formula_t *gFormula = lrllFormula; |
---|
| 5481 | Ctlp_Formula_t *fOriginalFormula = Ctlp_FormulaReadOriginalFormula(fFormula); |
---|
| 5482 | Ctlp_Formula_t *gOriginalFormula = Ctlp_FormulaReadOriginalFormula(gFormula); |
---|
| 5483 | char *fText = Ctlp_FormulaConvertToString( fOriginalFormula ); |
---|
| 5484 | char *gText = Ctlp_FormulaConvertToString( gOriginalFormula ); |
---|
| 5485 | |
---|
| 5486 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 5487 | char *firstStateName = Mc_MintermToString(aState, PSVars, |
---|
| 5488 | Fsm_FsmReadNetwork(modelFsm)); |
---|
| 5489 | McDbgLevel debugLevel = McOptionsReadDbgLevel( options ); |
---|
| 5490 | boolean printInputs = McOptionsReadPrintInputs( options ); |
---|
| 5491 | |
---|
| 5492 | if( McOptionsReadDbgLevel( options ) == McDbgLevelMin_c) |
---|
| 5493 | fprintf(vis_stdout, "--State\n%sfails AU formula\n\n", |
---|
| 5494 | firstStateName); |
---|
| 5495 | else |
---|
| 5496 | fprintf(vis_stdout, "--State\n%sfails %s\n\n", firstStateName, |
---|
| 5497 | originalFormulaText ); |
---|
| 5498 | FREE(firstStateName); |
---|
| 5499 | FREE(originalFormulaText); |
---|
| 5500 | |
---|
| 5501 | /* orginal formula is A(fUg) => converted is !((E[!g U (!f*!g)]) + (EG!g)) */ |
---|
| 5502 | |
---|
| 5503 | if ( McStateSatisfiesFormula( llFormula, aState ) ) { |
---|
| 5504 | /* |
---|
| 5505 | * the case E[!g U (!f*!g)] is true |
---|
| 5506 | */ |
---|
| 5507 | McPath_t *counterExamplePath = DebugEUMine(llFormula, aState, modelFsm, |
---|
| 5508 | careSetArray); |
---|
| 5509 | |
---|
| 5510 | array_t *stemArray = McPathReadStemArray( counterExamplePath ); |
---|
| 5511 | array_t *witnessArray = stemArray; |
---|
| 5512 | mdd_t *firstState = array_fetch( mdd_t *, witnessArray, 0 ); |
---|
| 5513 | mdd_t *lastState = array_fetch_last( mdd_t *, witnessArray ); |
---|
| 5514 | char *firstStateName = Mc_MintermToString(firstState, PSVars, |
---|
| 5515 | Fsm_FsmReadNetwork(modelFsm)); |
---|
| 5516 | |
---|
| 5517 | // Added in case if there's no counter example => CTL fails at initial state |
---|
| 5518 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] 1) CEx n_state = %d \n", array_n(witnessArray)); |
---|
| 5519 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 5520 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] *VERIFICATION REQUIRED!* CEx n_state = %d \n", array_n(witnessArray)); |
---|
| 5521 | Mc_PrintPath(witnessArray, modelFsm, printInputs); // added |
---|
| 5522 | } |
---|
| 5523 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(witnessArrayEU) = %d\n",array_n(witnessArray)); |
---|
| 5524 | |
---|
| 5525 | switch ( debugLevel ) { |
---|
| 5526 | case McDbgLevelMinVerbose_c: |
---|
| 5527 | fprintf(vis_stdout, |
---|
| 5528 | "--Counter example is a fair path where %s is false until %s is also false\n", |
---|
| 5529 | gText, fText); |
---|
| 5530 | case McDbgLevelMin_c: |
---|
| 5531 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5532 | Mc_PrintPath(witnessArray, modelFsm, printInputs); |
---|
| 5533 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5534 | // cExArray = McFsmStateDebugFormulaMine(options, llrFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5535 | cExArray = McFsmStateDebugFormulaMine(options, llrFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5536 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 1 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
| 5537 | break; |
---|
| 5538 | |
---|
| 5539 | case McDbgLevelMax_c: |
---|
| 5540 | case McDbgLevelInteractive_c: { |
---|
| 5541 | if ( array_n(witnessArray ) == 1 ) { |
---|
| 5542 | fprintf(vis_stdout, |
---|
| 5543 | "--At state %s\nformula %s is false and\nformula %s is also false\n", |
---|
| 5544 | firstStateName, fText, gText); |
---|
| 5545 | if (debugLevel == McDbgLevelMax_c || |
---|
| 5546 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 5547 | McQueryContinue( |
---|
| 5548 | "Continue debugging AU formula? (1-yes,0-no)\n"))) { |
---|
| 5549 | // cExArray = McFsmStateDebugFormulaMine(options, fFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
| 5550 | // cExArray = McFsmStateDebugFormulaMine(options, gFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
| 5551 | cExArray = McFsmStateDebugFormulaMine(options, fFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
| 5552 | cExArray = McFsmStateDebugFormulaMine(options, gFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
| 5553 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 2 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
| 5554 | } |
---|
| 5555 | } |
---|
| 5556 | else { |
---|
| 5557 | int i; |
---|
| 5558 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5559 | Mc_PrintPath(witnessArray,modelFsm,printInputs); |
---|
| 5560 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5561 | for( i=0 ; i < ( array_n( witnessArray ) - 1 ); i++ ) { |
---|
| 5562 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
| 5563 | |
---|
| 5564 | if (debugLevel == McDbgLevelMax_c || |
---|
| 5565 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 5566 | McQueryContinue( |
---|
| 5567 | "Continue debugging AU formula? (1-yes,0-no)\n"))) { |
---|
| 5568 | // cExArray = McFsmStateDebugFormulaMine(options, gFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
| 5569 | cExArray = McFsmStateDebugFormulaMine(options, llrFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5570 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 3 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
| 5571 | } |
---|
| 5572 | } |
---|
| 5573 | |
---|
| 5574 | if (debugLevel == McDbgLevelMax_c || |
---|
| 5575 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 5576 | McQueryContinue( |
---|
| 5577 | "Continue debugging AU formula? (1-yes,0-no)\n"))) { |
---|
| 5578 | // cExArray = McFsmStateDebugFormulaMine(options, fFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5579 | // cExArray = McFsmStateDebugFormulaMine(options, gFormula, lastState, modelFsm, careSetArray, prevCExArray); |
---|
| 5580 | cExArray = McFsmStateDebugFormulaMine(options, fFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5581 | cExArray = McFsmStateDebugFormulaMine(options, gFormula, lastState, modelFsm, careSetArray, *preCExArray); |
---|
| 5582 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] 4 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
| 5583 | } |
---|
| 5584 | } |
---|
| 5585 | break; |
---|
| 5586 | } |
---|
| 5587 | |
---|
| 5588 | default: { |
---|
| 5589 | fail("Unknown case in debugging AU\n"); |
---|
| 5590 | } |
---|
| 5591 | }/* case */ |
---|
| 5592 | // McPathFree( counterExamplePath ); NOTE: INITIALLY FREED |
---|
| 5593 | |
---|
| 5594 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 5595 | |
---|
| 5596 | // array_free(prevCExArray); |
---|
| 5597 | FREE( fText ); |
---|
| 5598 | FREE( gText ); |
---|
| 5599 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] *** Mc_PrintPathMine WA STARTS ------------------\n"); |
---|
| 5600 | // Mc_PrintPathMine(witnessArray, modelFsm, printInputs); |
---|
| 5601 | // (void) fprintf(vis_stdout, "![FsmPathDebugAUFormulaMine] Mc_PrintPathMine WA ENDS *** -------------------\n"); |
---|
| 5602 | |
---|
| 5603 | *preCExArray = cExArray; |
---|
| 5604 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] LAST ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
| 5605 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] LAST ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
| 5606 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] ---> nb witnessArray : %d *END*\n", array_n(witnessArray)); |
---|
| 5607 | return witnessArray; |
---|
| 5608 | } |
---|
| 5609 | else { |
---|
| 5610 | /* |
---|
| 5611 | * must be the case that EG!g |
---|
| 5612 | */ |
---|
| 5613 | McPath_t *counterExamplePath = DebugEGMine(lrFormula, aState, modelFsm, |
---|
| 5614 | careSetArray, |
---|
| 5615 | options); |
---|
| 5616 | |
---|
| 5617 | assert( McStateSatisfiesFormula( lrFormula, aState ) ); |
---|
| 5618 | |
---|
| 5619 | array_t *stemArray = McPathReadStemArray( counterExamplePath ); |
---|
| 5620 | array_t *cycleArray = McPathReadCycleArray( counterExamplePath ); |
---|
| 5621 | array_t *witnessArray = McCreateMergedPath( stemArray, cycleArray ); |
---|
| 5622 | McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
| 5623 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
| 5624 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
| 5625 | |
---|
| 5626 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(stemArrayEG) = %d\n",array_n(stemArray)); |
---|
| 5627 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(cycleArrayEG) = %d\n",array_n(cycleArray)); |
---|
| 5628 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(witnessArrayEG) = %d\n",array_n(witnessArray)); |
---|
| 5629 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(stemNormEG) = %d\n",array_n(stem)); |
---|
| 5630 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(cycleNormEG) = %d\n",array_n(cycle)); |
---|
| 5631 | array_t *witness = McCreateMergedPath( stem, cycle ); |
---|
| 5632 | (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] array_n(witnessNormEG) = %d\n",array_n(witness)); |
---|
| 5633 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 5634 | // Mc_PrintPathMine( witness, modelFsm, printInputs ); |
---|
| 5635 | // (void) fprintf(vis_stderr, "-[FsmPathDebugAUFormulaMine] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"); |
---|
| 5636 | |
---|
| 5637 | |
---|
| 5638 | |
---|
| 5639 | if( debugLevel != McDbgLevelMin_c) |
---|
| 5640 | fprintf(vis_stdout, |
---|
| 5641 | "--Counter example is a fair path where %s is always false\n", |
---|
| 5642 | gText); |
---|
| 5643 | |
---|
| 5644 | switch ( debugLevel ) { |
---|
| 5645 | case McDbgLevelMin_c: |
---|
| 5646 | case McDbgLevelMinVerbose_c:{ |
---|
| 5647 | /* McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
| 5648 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
| 5649 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
| 5650 | */ |
---|
| 5651 | |
---|
| 5652 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5653 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
| 5654 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
| 5655 | |
---|
| 5656 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
| 5657 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
| 5658 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5659 | McPathFree( normalPath ); |
---|
| 5660 | |
---|
| 5661 | break; |
---|
| 5662 | } |
---|
| 5663 | |
---|
| 5664 | case McDbgLevelMax_c: |
---|
| 5665 | case McDbgLevelInteractive_c: |
---|
| 5666 | { |
---|
| 5667 | int i; |
---|
| 5668 | /* array_t *stemArray = McPathReadStemArray( counterExamplePath ); |
---|
| 5669 | array_t *cycleArray = McPathReadCycleArray( counterExamplePath ); |
---|
| 5670 | array_t *witnessArray = McCreateMergedPath( stemArray, cycleArray ); |
---|
| 5671 | McPath_t *normalPath = McPathNormalize( counterExamplePath ); |
---|
| 5672 | array_t *stem = McPathReadStemArray( normalPath ); |
---|
| 5673 | array_t *cycle = McPathReadCycleArray( normalPath ); |
---|
| 5674 | */ |
---|
| 5675 | fprintf(vis_stdout, " --Counter example begins\n"); |
---|
| 5676 | (void) fprintf( vis_stdout, "--Fair path stem:\n"); |
---|
| 5677 | Mc_PrintPath( stem, modelFsm, printInputs ); |
---|
| 5678 | |
---|
| 5679 | (void) fprintf( vis_stdout, "--Fair path cycle:\n"); |
---|
| 5680 | Mc_PrintPath( cycle, modelFsm, printInputs ); |
---|
| 5681 | fprintf(vis_stdout, " --Counter example ends\n\n"); |
---|
| 5682 | McPathFree( normalPath ); |
---|
| 5683 | for( i=0 ; i < ( array_n( witnessArray )-1 ); i++ ) { |
---|
| 5684 | mdd_t *aState = array_fetch( mdd_t *, witnessArray, i ); |
---|
| 5685 | |
---|
| 5686 | if (debugLevel == McDbgLevelMax_c || |
---|
| 5687 | (debugLevel == McDbgLevelInteractive_c && |
---|
| 5688 | McQueryContinue( |
---|
| 5689 | "--Continue debugging AU formula? (1-yes,0-no)\n"))) { |
---|
| 5690 | // cExArray = McFsmStateDebugFormulaMine(options, lrllFormula, aState, modelFsm, careSetArray, prevCExArray); |
---|
| 5691 | cExArray = McFsmStateDebugFormulaMine(options, lrllFormula, aState, modelFsm, careSetArray, *preCExArray); |
---|
| 5692 | *preCExArray = cExArray; |
---|
| 5693 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] EG 1 ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
| 5694 | } |
---|
| 5695 | } |
---|
| 5696 | break; |
---|
| 5697 | } |
---|
| 5698 | |
---|
| 5699 | default: { |
---|
| 5700 | fail("Bad switch in debugging AU formula\n"); |
---|
| 5701 | } |
---|
| 5702 | }/* case */ |
---|
| 5703 | |
---|
| 5704 | // McPathFree( counterExamplePath ); NOTE: INITIALLY FREED |
---|
| 5705 | // array_free(prevCExArray); |
---|
| 5706 | FREE( fText ); |
---|
| 5707 | FREE( gText ); |
---|
| 5708 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] ---> nb prevCExArray : %d \n", array_n(prevCExArray)); |
---|
| 5709 | |
---|
| 5710 | // *preCExArray = cExArray; // preCExArray = &cExArray; |
---|
| 5711 | |
---|
| 5712 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] LAST ---> nb cExArray : %d \n", array_n(cExArray)); |
---|
| 5713 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] LAST ---> nb preCExArray : %d \n", array_n(*preCExArray)); |
---|
| 5714 | (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] ---> nb witness : %d *END*\n", array_n(witness)); |
---|
| 5715 | |
---|
| 5716 | // (void) fprintf(vis_stdout, "\n![FsmPathDebugAUFormulaMine] *** Mc_PrintPathMine STARTS ------------------ \n"); |
---|
| 5717 | // Mc_PrintPathMine(witness, modelFsm, printInputs); |
---|
| 5718 | // (void) fprintf(vis_stdout, "![FsmPathDebugAUFormulaMine] Mc_PrintPathMine ENDS *** --------------------- \n"); |
---|
| 5719 | return witness; |
---|
| 5720 | } |
---|
| 5721 | |
---|
| 5722 | } |
---|
| 5723 | |
---|
| 5724 | |
---|
| 5725 | |
---|
| 5726 | /**Function******************************************************************** |
---|
| 5727 | |
---|
| 5728 | Synopsis [Utility function - prints states on path, inputs for transitions] |
---|
| 5729 | |
---|
| 5730 | SideEffects [] |
---|
| 5731 | |
---|
| 5732 | ******************************************************************************/ |
---|
| 5733 | static int |
---|
| 5734 | Mc_PrintPathMine( |
---|
| 5735 | array_t *aPath, |
---|
| 5736 | Fsm_Fsm_t *modelFsm, |
---|
| 5737 | boolean printInput) |
---|
| 5738 | { |
---|
| 5739 | (void) fprintf(vis_stderr, "![Mc_PrintPathMine] \n"); |
---|
| 5740 | int check, forced, i; |
---|
| 5741 | int numForced; |
---|
| 5742 | mdd_t *inputSet=NIL(mdd_t); |
---|
| 5743 | mdd_t *uInput = NIL(mdd_t); |
---|
| 5744 | mdd_t *vInput = NIL(mdd_t); |
---|
| 5745 | |
---|
| 5746 | array_t *psVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 5747 | array_t *inputVars = Fsm_FsmReadInputVars( modelFsm ); |
---|
| 5748 | mdd_manager *mddMgr = Fsm_FsmReadMddManager( modelFsm ); |
---|
| 5749 | |
---|
| 5750 | forced = 0; |
---|
| 5751 | check = 1; |
---|
| 5752 | numForced = 0; |
---|
| 5753 | |
---|
| 5754 | |
---|
| 5755 | (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] NUMBER OF STEPS IN THE COUNTER EXAMPLE PATH = %d \n", array_n( aPath )); |
---|
| 5756 | |
---|
| 5757 | CEXStruct CEXPath [array_n( aPath )]; |
---|
| 5758 | //CEXStruct *testCEX; |
---|
| 5759 | //testCEX = (CEXStruct *)malloc(sizeof(CEXStruct)*array_n( aPath )); |
---|
| 5760 | |
---|
| 5761 | // --- SAT Solver File Generation --- |
---|
| 5762 | BmcOption_t *options = BmcOptionAlloc(); |
---|
| 5763 | int steps = (array_n( aPath ) - 1); // taille du contre exemple |
---|
| 5764 | // SATSolverFileGen (&hmgr, CNF_FILE, steps, options); |
---|
| 5765 | BmcCnfClauses_t *cnfClauses = NIL(BmcCnfClauses_t); |
---|
| 5766 | cnfClauses = BmcCnfClausesAlloc(); |
---|
| 5767 | Ntk_Network_t * ntk = Ntk_HrcManagerReadCurrentNetwork(hmgrGlobalC); |
---|
| 5768 | build_unroll_circuit(ntk,steps,options,cnfClauses); |
---|
| 5769 | (void) fprintf(vis_stderr, "*** CNF clauses for current network generated. *** \n\n"); |
---|
| 5770 | |
---|
| 5771 | (void) fprintf(vis_stderr, "*** Generating CNF clauses for Counter Example... *** \n\n"); |
---|
| 5772 | |
---|
| 5773 | for( i = -1 ; i < (array_n( aPath )-1); i++ ) { |
---|
| 5774 | |
---|
| 5775 | CEXPath[i+1].pathIndex = i+1; |
---|
| 5776 | CEXPath[i+1].n_outputVar = array_n( psVars ); |
---|
| 5777 | |
---|
| 5778 | (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] CEX PATH INDEX: CEXPath[%d].pathIndex = %d \n", i+1, CEXPath[i+1].pathIndex); |
---|
| 5779 | (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] NUMBER OF OUTPUTS: CEXPath[%d].n_outputVar = %d \n", i+1, CEXPath[i+1].n_outputVar); |
---|
| 5780 | |
---|
| 5781 | //deviceInfo = (deviceStruct *)malloc(sizeof(deviceStruct)*diagInfo.n_failures); |
---|
| 5782 | CEXPath[i+1].outputVar = (CEXVarStruct *)malloc(sizeof(CEXVarStruct)*CEXPath[i+1].n_outputVar); |
---|
| 5783 | //deviceInfo[i].dData = (dataStruct *)malloc(sizeof(dataStruct)*(deviceInfo[i].nb_d_data)); |
---|
| 5784 | |
---|
| 5785 | mdd_t *aState = ( i == -1 ) ? NIL(mdd_t) : array_fetch( mdd_t *, aPath, i ); |
---|
| 5786 | mdd_t *bState = array_fetch( mdd_t *, aPath, (i+1) ); |
---|
| 5787 | |
---|
| 5788 | // (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] aState = %ld \n", aState); |
---|
| 5789 | // (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] bState = %ld \n", bState); |
---|
| 5790 | |
---|
| 5791 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork(modelFsm); |
---|
| 5792 | |
---|
| 5793 | char *aStateString = aState ? Mc_MintermToString( aState, psVars, modelNetwork ) : NIL(char); |
---|
| 5794 | char *bStateString = Mc_MintermToStringMine( bState, psVars, modelNetwork, CEXPath, (i+1), FALSE, cnfClauses); |
---|
| 5795 | // (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] aState = %s \n", aStateString); |
---|
| 5796 | // (void) fprintf(vis_stderr, " --- [Mc_PrintPathMine] bState = %s \n", bStateString); |
---|
| 5797 | |
---|
| 5798 | |
---|
| 5799 | if((long)aState%2) { |
---|
| 5800 | aState = (mdd_t *)((long)aState -1); |
---|
| 5801 | forced++; |
---|
| 5802 | } |
---|
| 5803 | else forced = 0; |
---|
| 5804 | |
---|
| 5805 | if((long)bState%2) { |
---|
| 5806 | bState = (mdd_t *)((long)bState -1); |
---|
| 5807 | } |
---|
| 5808 | |
---|
| 5809 | if ( printInput == TRUE && i != -1) { |
---|
| 5810 | inputSet = Mc_FsmComputeDrivingInputMinterms( modelFsm, aState, bState ); |
---|
| 5811 | vInput = Mc_ComputeACloseMinterm( inputSet, uInput, inputVars, mddMgr ); |
---|
| 5812 | } |
---|
| 5813 | if(forced) { |
---|
| 5814 | fprintf(vis_stdout, "---- Forced %d\n", forced); |
---|
| 5815 | numForced ++; |
---|
| 5816 | } |
---|
| 5817 | McPrintTransitionMine( aState, bState, uInput, vInput, psVars, inputVars, |
---|
| 5818 | printInput, modelFsm, CEXPath, (i+1), cnfClauses); |
---|
| 5819 | |
---|
| 5820 | |
---|
| 5821 | |
---|
| 5822 | if ( uInput != NIL(mdd_t) ) { |
---|
| 5823 | mdd_free(uInput); |
---|
| 5824 | } |
---|
| 5825 | uInput = vInput; |
---|
| 5826 | |
---|
| 5827 | if ( inputSet != NIL(mdd_t) ) { |
---|
| 5828 | mdd_free(inputSet); |
---|
| 5829 | } |
---|
| 5830 | } |
---|
| 5831 | |
---|
| 5832 | if ( vInput != NIL(mdd_t) ) { |
---|
| 5833 | mdd_free(uInput); |
---|
| 5834 | } |
---|
| 5835 | |
---|
| 5836 | if(Fsm_FsmReadFAFWFlag(modelFsm) > 0) { |
---|
| 5837 | fprintf(vis_stdout, |
---|
| 5838 | "# MC: the number of non-trivial forced segments %d\n", |
---|
| 5839 | numForced); |
---|
| 5840 | } |
---|
| 5841 | |
---|
| 5842 | FILE *cnfFile = fopen(CNF_FILE_C1,"w"); |
---|
| 5843 | mAig_Manager_t * maigManager = Ntk_NetworkReadMAigManager(ntk); |
---|
| 5844 | BmcWriteClausesMine(maigManager, cnfFile, cnfClauses, options); |
---|
| 5845 | fclose(cnfFile); |
---|
| 5846 | |
---|
| 5847 | (void) fprintf(vis_stderr, "*** Generation of CNF clauses for Counter Example completed. *** \n\n"); |
---|
| 5848 | // --- SAT Solver --- |
---|
| 5849 | options->satInFile= CNF_FILE_C1; |
---|
| 5850 | options->verbosityLevel=BmcVerbositySome_c; |
---|
| 5851 | |
---|
| 5852 | SATSolver (steps, options); |
---|
| 5853 | (void) fprintf(vis_stderr, "*** SAT Solver completed. *** \n"); |
---|
| 5854 | |
---|
| 5855 | return 1; |
---|
| 5856 | } |
---|
| 5857 | |
---|
| 5858 | |
---|
| 5859 | /**Function******************************************************************** |
---|
| 5860 | |
---|
| 5861 | Synopsis [Print a transition to vis_stdout.] |
---|
| 5862 | |
---|
| 5863 | Description [Print a transition to vis_stdout. The transition is supposed to be |
---|
| 5864 | from aState to bState on input vInput. If uInput is not NIL, instead of |
---|
| 5865 | printing vInput, we only print the places where it differs from uInput. If there |
---|
| 5866 | is no difference anywhere, we print "-Unchanged-". Similarly, we print only the |
---|
| 5867 | incremental difference from aState to bState; if there is none, we print "-Unchanged-". |
---|
| 5868 | If aState is NIL we simply print bState and return.] |
---|
| 5869 | |
---|
| 5870 | SideEffects [] |
---|
| 5871 | |
---|
| 5872 | ******************************************************************************/ |
---|
| 5873 | static void |
---|
| 5874 | McPrintTransitionMine( |
---|
| 5875 | mdd_t *aState, |
---|
| 5876 | mdd_t *bState, |
---|
| 5877 | mdd_t *uInput, |
---|
| 5878 | mdd_t *vInput, |
---|
| 5879 | array_t *stateSupport, |
---|
| 5880 | array_t *inputSupport, |
---|
| 5881 | boolean printInputs, |
---|
| 5882 | Fsm_Fsm_t *modelFsm, |
---|
| 5883 | CEXStruct *CEXPath, |
---|
| 5884 | int seqNumber, |
---|
| 5885 | BmcCnfClauses_t *cnfClauses) |
---|
| 5886 | { |
---|
| 5887 | (void) fprintf(vis_stderr, "![McPrintTransitionMine] \n"); |
---|
| 5888 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork( modelFsm ); |
---|
| 5889 | char *aString = aState ? Mc_MintermToString( aState, stateSupport, modelNetwork ) : NIL(char); |
---|
| 5890 | char *bString = Mc_MintermToString( bState, stateSupport, modelNetwork ); |
---|
| 5891 | |
---|
| 5892 | char *tmp1String = aString; |
---|
| 5893 | char *tmp2String = bString; |
---|
| 5894 | char *ptr1; |
---|
| 5895 | char *ptr2; |
---|
| 5896 | st_table *node2MvfAigTable; |
---|
| 5897 | |
---|
| 5898 | node2MvfAigTable = |
---|
| 5899 | (st_table *)Ntk_NetworkReadApplInfo(modelNetwork, MVFAIG_NETWORK_APPL_KEY); |
---|
| 5900 | |
---|
| 5901 | if ( aState == NIL(mdd_t) ) { |
---|
| 5902 | fprintf( vis_stdout, "--State %d:\n%s\n", seqNumber, bString ); |
---|
| 5903 | FREE(bString); |
---|
| 5904 | return; |
---|
| 5905 | } |
---|
| 5906 | |
---|
| 5907 | fprintf(vis_stdout, "--Goes to state %d:\n", seqNumber ); |
---|
| 5908 | |
---|
| 5909 | { |
---|
| 5910 | boolean unchanged=TRUE; |
---|
| 5911 | while ( (tmp1String != NIL(char)) && ((ptr1 = strchr( tmp1String, '\n' ) ) != NIL(char) ) ) { |
---|
| 5912 | ptr2 = strchr( tmp2String, '\n' ); |
---|
| 5913 | *ptr1 = 0; |
---|
| 5914 | *ptr2 = 0; |
---|
| 5915 | if ( (strcmp( tmp1String, tmp2String ) ) ) { |
---|
| 5916 | fprintf( vis_stdout, "%s\n", tmp2String ); |
---|
| 5917 | unchanged = FALSE; |
---|
| 5918 | } |
---|
| 5919 | tmp1String = & (ptr1[1]); |
---|
| 5920 | tmp2String = & (ptr2[1]); |
---|
| 5921 | } |
---|
| 5922 | if (unchanged == TRUE) { |
---|
| 5923 | fprintf( vis_stdout, "<Unchanged>\n"); |
---|
| 5924 | } |
---|
| 5925 | } |
---|
| 5926 | |
---|
| 5927 | if ( array_n( inputSupport ) > 0 ) { |
---|
| 5928 | CEXPath[seqNumber].n_inputVar = array_n( inputSupport ); |
---|
| 5929 | } |
---|
| 5930 | else CEXPath[seqNumber].n_inputVar = 0; |
---|
| 5931 | |
---|
| 5932 | (void) fprintf(vis_stderr, " ---- [McPrintTransitionMine] NUMBER OF INPUTS: CEXPath[%d].n_inputVar = %d \n", seqNumber, CEXPath[seqNumber].n_inputVar); |
---|
| 5933 | CEXPath[seqNumber].inputVar = (CEXVarStruct *)malloc(sizeof(CEXVarStruct)*CEXPath[seqNumber].n_inputVar); |
---|
| 5934 | |
---|
| 5935 | if ( printInputs == TRUE ) { |
---|
| 5936 | |
---|
| 5937 | // (void) fprintf(vis_stderr, " ---- [McPrintTransitionMine] NUMBER OF INPUTS = %d \n", array_n( inputSupport )); |
---|
| 5938 | |
---|
| 5939 | |
---|
| 5940 | /* first test that there are inputs */ |
---|
| 5941 | if ( array_n( inputSupport ) > 0 ) { |
---|
| 5942 | fprintf(vis_stdout, "--On input:\n"); |
---|
| 5943 | |
---|
| 5944 | if ( uInput == NIL(mdd_t) ) { |
---|
| 5945 | char *vString = Mc_MintermToStringMine( vInput, inputSupport, modelNetwork, CEXPath, seqNumber, TRUE, cnfClauses); |
---|
| 5946 | fprintf(vis_stdout, "%s", vString ); |
---|
| 5947 | FREE(vString); |
---|
| 5948 | } |
---|
| 5949 | else { |
---|
| 5950 | boolean unchanged=TRUE; |
---|
| 5951 | char *uString = Mc_MintermToString( uInput, inputSupport, modelNetwork ); |
---|
| 5952 | char *vString = Mc_MintermToStringMine( vInput, inputSupport, modelNetwork, CEXPath, seqNumber, TRUE, cnfClauses); |
---|
| 5953 | tmp1String = uString; |
---|
| 5954 | tmp2String = vString; |
---|
| 5955 | // (void) fprintf(vis_stderr, " ---- [McPrintTransitionMine] uString = %s \n", uString); |
---|
| 5956 | // (void) fprintf(vis_stderr, " ---- [McPrintTransitionMine] vString = %s \n", vString); |
---|
| 5957 | |
---|
| 5958 | while ( (tmp1String != NIL(char)) && ((ptr1 = strchr( tmp1String, '\n' ) ) != NIL(char) ) ) { |
---|
| 5959 | ptr2 = strchr( tmp2String, '\n' ); |
---|
| 5960 | *ptr1 = 0; |
---|
| 5961 | *ptr2 = 0; |
---|
| 5962 | if ( (strcmp( tmp1String, tmp2String ) ) ) { |
---|
| 5963 | fprintf( vis_stdout, "%s\n", tmp2String ); |
---|
| 5964 | unchanged = FALSE; |
---|
| 5965 | } |
---|
| 5966 | tmp1String = & (ptr1[1]); |
---|
| 5967 | tmp2String = & (ptr2[1]); |
---|
| 5968 | } |
---|
| 5969 | if (unchanged == TRUE) { |
---|
| 5970 | fprintf( vis_stdout, "<Unchanged>\n"); |
---|
| 5971 | } |
---|
| 5972 | FREE(uString); |
---|
| 5973 | FREE(vString); |
---|
| 5974 | } |
---|
| 5975 | } |
---|
| 5976 | } |
---|
| 5977 | |
---|
| 5978 | FREE( aString ); |
---|
| 5979 | FREE( bString ); |
---|
| 5980 | fprintf (vis_stdout, "\n"); |
---|
| 5981 | } |
---|
| 5982 | |
---|
| 5983 | |
---|
| 5984 | /**Function******************************************************************** |
---|
| 5985 | |
---|
| 5986 | Synopsis [Print a minterm.] |
---|
| 5987 | |
---|
| 5988 | SideEffects [] |
---|
| 5989 | |
---|
| 5990 | ******************************************************************************/ |
---|
| 5991 | static void |
---|
| 5992 | Mc_MintermPrintMine( |
---|
| 5993 | mdd_t *aMinterm, |
---|
| 5994 | array_t *support, |
---|
| 5995 | Ntk_Network_t *aNetwork) |
---|
| 5996 | { |
---|
| 5997 | char *tmpString = Mc_MintermToString( aMinterm, support, aNetwork ); // to be modified!! |
---|
| 5998 | fprintf( vis_stdout, "%s", tmpString ); |
---|
| 5999 | FREE(tmpString); |
---|
| 6000 | } |
---|
| 6001 | |
---|
| 6002 | |
---|
| 6003 | /**Function******************************************************************** |
---|
| 6004 | |
---|
| 6005 | Synopsis [Return a string for a minterm. Only used in 'Mc_PrintPathMine' |
---|
| 6006 | function] |
---|
| 6007 | |
---|
| 6008 | SideEffects [] |
---|
| 6009 | |
---|
| 6010 | ******************************************************************************/ |
---|
| 6011 | static char * |
---|
| 6012 | Mc_MintermToStringMine( |
---|
| 6013 | mdd_t *aMinterm, |
---|
| 6014 | array_t *aSupport, |
---|
| 6015 | Ntk_Network_t *aNetwork, |
---|
| 6016 | CEXStruct *CEXPath, |
---|
| 6017 | int seqNumber, |
---|
| 6018 | boolean inOutIndicator, // TRUE = input Variables, FALSE = output Variables (independent printInput option) |
---|
| 6019 | BmcCnfClauses_t *cnfClauses) |
---|
| 6020 | { |
---|
| 6021 | (void) fprintf(vis_stderr, "![Mc_MintermToStringMine] \n"); |
---|
| 6022 | int i; |
---|
| 6023 | char *tmp1String; |
---|
| 6024 | char *tmp2String; |
---|
| 6025 | char bodyString[McMaxStringLength_c]; |
---|
| 6026 | char *mintermString = NIL(char); |
---|
| 6027 | mdd_manager *mddMgr = Ntk_NetworkReadMddManager( aNetwork ); |
---|
| 6028 | array_t *valueArray; |
---|
| 6029 | array_t *stringArray = array_alloc( char *, 0 ); |
---|
| 6030 | char *symbolicValue; |
---|
| 6031 | |
---|
| 6032 | aMinterm = GET_NORMAL_PT(aMinterm); |
---|
| 6033 | valueArray = McConvertMintermToValueArrayMine(aMinterm, aSupport, mddMgr); |
---|
| 6034 | // (void) fprintf(vis_stderr, " ---- [Mc_MintermToStringMine] CEX n outputs = %d \n", array_n( aSupport )); |
---|
| 6035 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] Number of variables = %d \n", array_n( aSupport )); |
---|
| 6036 | |
---|
| 6037 | // CEXVarStruct testBB [array_n( aSupport)]; |
---|
| 6038 | |
---|
| 6039 | for ( i = 0 ; i < array_n( aSupport ); i++ ) { |
---|
| 6040 | |
---|
| 6041 | int mddId = array_fetch( int, aSupport, i ); |
---|
| 6042 | int value = array_fetch( int, valueArray, i ); |
---|
| 6043 | Ntk_Node_t *node = Ntk_NetworkFindNodeByMddId( aNetwork, mddId ); |
---|
| 6044 | char *nodeName = Ntk_NodeReadName( node ); |
---|
| 6045 | Var_Variable_t *nodeVar = Ntk_NodeReadVariable( node ); |
---|
| 6046 | |
---|
| 6047 | // (void) fprintf(vis_stderr, "\n ----- [Mc_MintermToStringMine] VARIABLE %d: \n", i+1 ); |
---|
| 6048 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] nodeName = %s \n", nodeName); |
---|
| 6049 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] mddId = %d \n", mddId); |
---|
| 6050 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] value = %d \n", value); |
---|
| 6051 | |
---|
| 6052 | if ( Var_VariableTestIsSymbolic( nodeVar ) ) { |
---|
| 6053 | symbolicValue = Var_VariableReadSymbolicValueFromIndex(nodeVar, value ); |
---|
| 6054 | // (void) fprintf(vis_stderr, " ----- [Mc_MintermToStringMine] symbolic value = %s \n", symbolicValue); |
---|
| 6055 | sprintf( bodyString, "%s:%s", nodeName, symbolicValue ); |
---|
| 6056 | //testBB[i].symbolicValue = symbolicValue; |
---|
| 6057 | // sprintf(testBB[i].symbolicValue, "%s", symbolicValue); |
---|
| 6058 | } |
---|
| 6059 | else { |
---|
| 6060 | sprintf( bodyString, "%s:%d", nodeName, value ); |
---|
| 6061 | //testBB[i].symbolicValue = NIL(char); |
---|
| 6062 | symbolicValue = "NIL"; |
---|
| 6063 | // sprintf(testBB[i].symbolicValue, "%s", "NIL"); |
---|
| 6064 | } |
---|
| 6065 | |
---|
| 6066 | |
---|
| 6067 | if (inOutIndicator == TRUE) { |
---|
| 6068 | CEXPath[seqNumber].inputVar[i].varIndex = i; |
---|
| 6069 | CEXPath[seqNumber].inputVar[i].varId = mddId; |
---|
| 6070 | CEXPath[seqNumber].inputVar[i].varValue = value; |
---|
| 6071 | sprintf(CEXPath[seqNumber].inputVar[i].varName, "%s", nodeName); |
---|
| 6072 | sprintf(CEXPath[seqNumber].inputVar[i].symbolicValue, "%s", symbolicValue); |
---|
| 6073 | } |
---|
| 6074 | else{ |
---|
| 6075 | CEXPath[seqNumber].outputVar[i].varIndex = i; |
---|
| 6076 | CEXPath[seqNumber].outputVar[i].varId = mddId; |
---|
| 6077 | CEXPath[seqNumber].outputVar[i].varValue = value; |
---|
| 6078 | sprintf(CEXPath[seqNumber].outputVar[i].varName, "%s", nodeName); |
---|
| 6079 | sprintf(CEXPath[seqNumber].outputVar[i].symbolicValue, "%s", symbolicValue); |
---|
| 6080 | } |
---|
| 6081 | |
---|
| 6082 | // testBB[i].varIndex = i; |
---|
| 6083 | // testBB[i].varId = mddId; |
---|
| 6084 | // testBB[i].varValue = value; |
---|
| 6085 | // sprintf(testBB[i].varName, "%s", nodeName); |
---|
| 6086 | // testBB[i].varName = nodeName; |
---|
| 6087 | |
---|
| 6088 | |
---|
| 6089 | |
---|
| 6090 | tmp1String = util_strsav( bodyString ); |
---|
| 6091 | array_insert_last( char *, stringArray, tmp1String ); |
---|
| 6092 | } |
---|
| 6093 | array_free(valueArray); |
---|
| 6094 | |
---|
| 6095 | array_sort( stringArray, cmp); |
---|
| 6096 | |
---|
| 6097 | for ( i = 0 ; i < array_n( stringArray ); i++ ) { |
---|
| 6098 | tmp1String = array_fetch( char *, stringArray, i ); |
---|
| 6099 | if( i == 0 ) { |
---|
| 6100 | mintermString = util_strcat3(tmp1String, "", "" ); |
---|
| 6101 | } |
---|
| 6102 | else { |
---|
| 6103 | tmp2String = util_strcat3(mintermString, "\n", tmp1String ); |
---|
| 6104 | FREE(mintermString); |
---|
| 6105 | mintermString = tmp2String; |
---|
| 6106 | } |
---|
| 6107 | FREE(tmp1String); |
---|
| 6108 | } |
---|
| 6109 | array_free( stringArray ); |
---|
| 6110 | |
---|
| 6111 | tmp1String = util_strcat3(mintermString, "\n", ""); |
---|
| 6112 | FREE(mintermString); |
---|
| 6113 | mintermString = tmp1String; |
---|
| 6114 | |
---|
| 6115 | int j, k; |
---|
| 6116 | boolean indexFound; |
---|
| 6117 | int lookUpResult; |
---|
| 6118 | int n_bitValue; // number of bit - 1 = highest bit number representing the value of the variable |
---|
| 6119 | int *cnfIndex= malloc(sizeof(int)*SIZE_1); |
---|
| 6120 | int newIndex; |
---|
| 6121 | array_t * newClause; |
---|
| 6122 | char *tempCNFString; |
---|
| 6123 | |
---|
| 6124 | for ( i = 0 ; i < array_n( aSupport ); i++ ) { |
---|
| 6125 | |
---|
| 6126 | j=0; |
---|
| 6127 | indexFound = TRUE; |
---|
| 6128 | |
---|
| 6129 | if (inOutIndicator == TRUE) { |
---|
| 6130 | /* (void) fprintf(vis_stderr, "\n CEXPath[%d].inputVar[%d].varIndex = %d \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].varIndex); |
---|
| 6131 | (void) fprintf(vis_stderr, " CEXPath[%d].inputVar[%d].varId = %d \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].varId); |
---|
| 6132 | (void) fprintf(vis_stderr, "\n"); |
---|
| 6133 | (void) fprintf(vis_stderr, " CEXPath[%d].inputVar[%d].varValue = %d \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].varValue); |
---|
| 6134 | (void) fprintf(vis_stderr, " CEXPath[%d].inputVar[%d].varName = %s \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].varName); |
---|
| 6135 | (void) fprintf(vis_stderr, " CEXPath[%d].inputVar[%d].symbolicValue = %s \n", seqNumber, i, CEXPath[seqNumber].inputVar[i].symbolicValue); |
---|
| 6136 | */ |
---|
| 6137 | |
---|
| 6138 | // insertion of cnf clauses related to the input in Counter Example at each state |
---|
| 6139 | do{ |
---|
| 6140 | tempCNFString = CNFVariableNameConstructor(CEXPath[seqNumber].inputVar[i].varName, j, seqNumber-1); // the sequence of input begins at -1 and ends at (last sequence-1) |
---|
| 6141 | lookUpResult = st_lookup(cnfClauses->cnfIndexTable, tempCNFString, &cnfIndex[j]); |
---|
| 6142 | // (void) fprintf(vis_stderr, "[SeqNumber: %d][i: %d][j: %d] tempCNFString = %s; lookUpResult = %d; cnfIndex = %d;\n", seqNumber, i, j, tempCNFString, lookUpResult, cnfIndex); |
---|
| 6143 | if (lookUpResult == 0) { |
---|
| 6144 | indexFound = FALSE; |
---|
| 6145 | } |
---|
| 6146 | else { |
---|
| 6147 | indexFound = TRUE; |
---|
| 6148 | (void) fprintf(vis_stderr, " [CNF Index Search] Variable bit name = %s => CNF Index = %d \n", tempCNFString, cnfIndex[j]); |
---|
| 6149 | j++; |
---|
| 6150 | } |
---|
| 6151 | }while ((indexFound == TRUE)&&(j<SIZE_1)); |
---|
| 6152 | |
---|
| 6153 | if ((indexFound == FALSE)&&(j<SIZE_1)){ |
---|
| 6154 | n_bitValue = j-1; |
---|
| 6155 | // (void) fprintf(vis_stderr, " [Counter] n_bitValue = %d ::: j = %d. \n", n_bitValue, j); |
---|
| 6156 | if (n_bitValue > 0){ |
---|
| 6157 | // Value decomposition en binary. Then affectation of the value of each bit of the variable in CNF format for each index of the variable |
---|
| 6158 | |
---|
| 6159 | int *binaryValue = malloc (sizeof(int)*(n_bitValue+1)); |
---|
| 6160 | binaryValue = DecBinConverter (CEXPath[seqNumber].inputVar[i].varValue, (n_bitValue+1), binaryValue); |
---|
| 6161 | |
---|
| 6162 | // (void) fprintf(vis_stderr, "---- Decimal Value = %d ==> Binary Value = ", CEXPath[seqNumber].inputVar[i].varValue); |
---|
| 6163 | // for (k=0; k < n_bitValue+1; k++){ |
---|
| 6164 | // (void) fprintf(vis_stderr, "%d ", binaryValue[n_bitValue-k]); |
---|
| 6165 | // } |
---|
| 6166 | |
---|
| 6167 | for (k=0; k<(n_bitValue+1); k++){ |
---|
| 6168 | |
---|
| 6169 | newClause = array_alloc(int,1); |
---|
| 6170 | // if varValue = 1 => cnfIndex; if varValue = 0 => -cnfIndex |
---|
| 6171 | // (void) fprintf(vis_stderr, "CNF Index = %d : Value = %d \n", cnfIndex[k], binaryValue[k]); |
---|
| 6172 | // if (binaryValue[k] == 0) array_insert(int,newClause,0,-cnfIndex[k]); |
---|
| 6173 | // else array_insert(int, newClause, 0, cnfIndex[k]); |
---|
| 6174 | |
---|
| 6175 | // NOTE: MSB is on lowest bit encoding |
---|
| 6176 | // (void) fprintf(vis_stderr, "CNF Index = %d : Value = %d \n", cnfIndex[k], binaryValue[n_bitValue-k]); |
---|
| 6177 | if (binaryValue[n_bitValue-k] == 0) array_insert(int,newClause,0,-cnfIndex[k]); |
---|
| 6178 | else array_insert(int, newClause, 0, cnfIndex[k]); |
---|
| 6179 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
| 6180 | array_free(newClause); |
---|
| 6181 | } |
---|
| 6182 | free (binaryValue); |
---|
| 6183 | // (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); |
---|
| 6184 | |
---|
| 6185 | } |
---|
| 6186 | else{ |
---|
| 6187 | if (n_bitValue == 0){ |
---|
| 6188 | newClause = array_alloc(int,1); |
---|
| 6189 | // if varValue = 1 => cnfIndex; if varValue = 0 => -cnfIndex |
---|
| 6190 | if (CEXPath[seqNumber].inputVar[i].varValue == 0) array_insert(int,newClause,0,-cnfIndex[0]); |
---|
| 6191 | else array_insert(int, newClause, 0, cnfIndex[0]); |
---|
| 6192 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
| 6193 | array_free(newClause); |
---|
| 6194 | } |
---|
| 6195 | else { // n_bitValue = -1 or <0 |
---|
| 6196 | (void) fprintf(vis_stderr, "![WARNING] Variable CNF index not found. Verification required. \n", CEXPath[seqNumber].outputVar[i].varName, seqNumber); |
---|
| 6197 | } |
---|
| 6198 | } |
---|
| 6199 | } |
---|
| 6200 | else { |
---|
| 6201 | (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" ); |
---|
| 6202 | } |
---|
| 6203 | |
---|
| 6204 | |
---|
| 6205 | } |
---|
| 6206 | else{ |
---|
| 6207 | /* (void) fprintf(vis_stderr, "\n CEXPath[%d].outputVar[%d].varIndex = %d \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].varIndex); |
---|
| 6208 | (void) fprintf(vis_stderr, " CEXPath[%d].outputVar[%d].varId = %d \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].varId); |
---|
| 6209 | (void) fprintf(vis_stderr, " CEXPath[%d].outputVar[%d].varValue = %d \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].varValue); |
---|
| 6210 | (void) fprintf(vis_stderr, " CEXPath[%d].outputVar[%d].varName = %s \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].varName); |
---|
| 6211 | (void) fprintf(vis_stderr, " CEXPath[%d].outputVar[%d].symbolicValue = %s \n", seqNumber, i, CEXPath[seqNumber].outputVar[i].symbolicValue); |
---|
| 6212 | */ |
---|
| 6213 | |
---|
| 6214 | //--- CNF: insertion of cnf clauses related to Counter Example output at each state |
---|
| 6215 | // if (i>0){ // to exclude the states in CNF |
---|
| 6216 | |
---|
| 6217 | do{ |
---|
| 6218 | tempCNFString = CNFVariableNameConstructor(CEXPath[seqNumber].outputVar[i].varName, j, seqNumber); |
---|
| 6219 | //int findIndex(BmcCnfClauses_t* cnfClauses , char * nodeName) |
---|
| 6220 | //propIndex = findIndex(cnfClauses, tempCNFString); |
---|
| 6221 | lookUpResult = st_lookup(cnfClauses->cnfIndexTable, tempCNFString, &cnfIndex[j]); |
---|
| 6222 | // (void) fprintf(vis_stderr, "[SeqNumber: %d][i: %d][j: %d] tempCNFString = %s; lookUpResult = %d; cnfIndex = %d;\n", seqNumber, i, j, tempCNFString, lookUpResult, cnfIndex); |
---|
| 6223 | if (lookUpResult == 0) { |
---|
| 6224 | indexFound = FALSE; |
---|
| 6225 | } |
---|
| 6226 | else { |
---|
| 6227 | indexFound = TRUE; |
---|
| 6228 | (void) fprintf(vis_stderr, " [CNF Index Search] Variable bit name = %s => CNF Index = %d \n", tempCNFString, cnfIndex[j]); |
---|
| 6229 | j++; |
---|
| 6230 | } |
---|
| 6231 | }while ((indexFound == TRUE)&&(j<SIZE_1)); |
---|
| 6232 | |
---|
| 6233 | if ((indexFound == FALSE)&&(j<SIZE_1)){ |
---|
| 6234 | n_bitValue = j-1; |
---|
| 6235 | // (void) fprintf(vis_stderr, " [Counter] n_bitValue = %d ::: j = %d. \n", n_bitValue, j); |
---|
| 6236 | if (n_bitValue > 0){ |
---|
| 6237 | // Value decomposition en binary. Then affectation of the value of each bit of the variable in CNF format for each index of the variable |
---|
| 6238 | |
---|
| 6239 | int *binaryValue = malloc (sizeof(int)*(n_bitValue+1)); |
---|
| 6240 | binaryValue = DecBinConverter (CEXPath[seqNumber].outputVar[i].varValue, (n_bitValue+1), binaryValue); |
---|
| 6241 | |
---|
| 6242 | // (void) fprintf(vis_stderr, "####### Decimal Value = %d ==> Binary Value = ", CEXPath[seqNumber].outputVar[i].varValue); |
---|
| 6243 | // for (k=0; k<(n_bitValue+1); k++){ |
---|
| 6244 | // (void) fprintf(vis_stderr, "%d ", binaryValue[n_bitValue-k]); |
---|
| 6245 | // } |
---|
| 6246 | // (void) fprintf(vis_stderr, "\n"); |
---|
| 6247 | |
---|
| 6248 | for (k=0; k<(n_bitValue+1); k++){ |
---|
| 6249 | // for (k=(n_bitValue); k>=0; k--){ |
---|
| 6250 | newClause = array_alloc(int,1); |
---|
| 6251 | // if varValue = 1 => cnfIndex; if varValue = 0 => -cnfIndex |
---|
| 6252 | // (void) fprintf(vis_stderr, "CNF Index = %d : Value = %d \n", cnfIndex[k], binaryValue[k]); |
---|
| 6253 | // if (binaryValue[k] == 0) array_insert(int,newClause,0,-cnfIndex[k]); |
---|
| 6254 | // else array_insert(int, newClause, 0, cnfIndex[k]); |
---|
| 6255 | // NOTE: MSB is on lowest bit encoding |
---|
| 6256 | // (void) fprintf(vis_stderr, "CNF Index = %d : Value = %d \n", cnfIndex[k], binaryValue[n_bitValue-k]); |
---|
| 6257 | if (binaryValue[n_bitValue-k] == 0) array_insert(int,newClause,0,-cnfIndex[k]); |
---|
| 6258 | else array_insert(int, newClause, 0, cnfIndex[k]); |
---|
| 6259 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
| 6260 | array_free(newClause); |
---|
| 6261 | |
---|
| 6262 | } |
---|
| 6263 | free (binaryValue); |
---|
| 6264 | // (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); |
---|
| 6265 | |
---|
| 6266 | } |
---|
| 6267 | else{ |
---|
| 6268 | if (n_bitValue == 0){ |
---|
| 6269 | newClause = array_alloc(int,1); |
---|
| 6270 | // if varValue = 1 => cnfIndex; if varValue = 0 => -cnfIndex |
---|
| 6271 | if (CEXPath[seqNumber].outputVar[i].varValue == 0) array_insert(int,newClause,0,-cnfIndex[0]); |
---|
| 6272 | else array_insert(int, newClause, 0, cnfIndex[0]); |
---|
| 6273 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
| 6274 | array_free(newClause); |
---|
| 6275 | } |
---|
| 6276 | else { // n_bitValue = -1 or <0 |
---|
| 6277 | (void) fprintf(vis_stderr, "![WARNING] Variable CNF index not found. Verification required. \n", CEXPath[seqNumber].outputVar[i].varName, seqNumber); |
---|
| 6278 | } |
---|
| 6279 | } |
---|
| 6280 | } |
---|
| 6281 | else { |
---|
| 6282 | (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" ); |
---|
| 6283 | } |
---|
| 6284 | // } |
---|
| 6285 | } |
---|
| 6286 | } |
---|
| 6287 | |
---|
| 6288 | return mintermString; |
---|
| 6289 | } |
---|
| 6290 | |
---|
| 6291 | |
---|
| 6292 | |
---|
| 6293 | /**Function******************************************************************** |
---|
| 6294 | |
---|
| 6295 | Synopsis [Convert a minterm to an array of integers] |
---|
| 6296 | |
---|
| 6297 | SideEffects [] |
---|
| 6298 | |
---|
| 6299 | ******************************************************************************/ |
---|
| 6300 | static array_t * |
---|
| 6301 | McConvertMintermToValueArrayMine( |
---|
| 6302 | mdd_t *aMinterm, |
---|
| 6303 | array_t *aSupport, |
---|
| 6304 | mdd_manager *mddMgr) |
---|
| 6305 | { |
---|
| 6306 | (void) fprintf(vis_stderr, "![McConvertMintermToValueArrayMine] \n"); |
---|
| 6307 | array_t *resultValueArray; |
---|
| 6308 | |
---|
| 6309 | /* this will be performed only in v0s-g executables */ |
---|
| 6310 | assert( MintermCheckWellFormed( aMinterm, aSupport, mddMgr )); |
---|
| 6311 | |
---|
| 6312 | resultValueArray = array_alloc( int, 0 ); |
---|
| 6313 | { |
---|
| 6314 | int i; |
---|
| 6315 | for( i = 0 ; i < array_n( aSupport ); i++ ) { |
---|
| 6316 | int aSupportVar = array_fetch( int, aSupport, i ); |
---|
| 6317 | int j; |
---|
| 6318 | for( j = 0 ; TRUE ; j++) { |
---|
| 6319 | |
---|
| 6320 | mdd_t *faceMdd, *tmpMdd; |
---|
| 6321 | array_t *tmpArray = array_alloc( int, 0 ); |
---|
| 6322 | |
---|
| 6323 | array_insert_last( int, tmpArray, j ); |
---|
| 6324 | faceMdd = mdd_literal( mddMgr, aSupportVar, tmpArray ); |
---|
| 6325 | array_free( tmpArray ); |
---|
| 6326 | |
---|
| 6327 | tmpMdd = mdd_and( faceMdd, aMinterm, 1, 1 ); |
---|
| 6328 | mdd_free( faceMdd ); |
---|
| 6329 | if ( !mdd_is_tautology( tmpMdd, 0 ) ) { |
---|
| 6330 | mdd_free( tmpMdd ); |
---|
| 6331 | array_insert_last( int, resultValueArray, j ); |
---|
| 6332 | break; |
---|
| 6333 | } |
---|
| 6334 | mdd_free( tmpMdd ); |
---|
| 6335 | } |
---|
| 6336 | } |
---|
| 6337 | } |
---|
| 6338 | |
---|
| 6339 | return resultValueArray; |
---|
| 6340 | } |
---|
| 6341 | |
---|
| 6342 | /**Function******************************************************************** |
---|
| 6343 | |
---|
| 6344 | Synopsis [Print message saying given state passes formula.] |
---|
| 6345 | |
---|
| 6346 | SideEffects [] |
---|
| 6347 | |
---|
| 6348 | ******************************************************************************/ |
---|
| 6349 | static void |
---|
| 6350 | McStatePassesFormulaMine( |
---|
| 6351 | mdd_t *aState, |
---|
| 6352 | Ctlp_Formula_t *formula, |
---|
| 6353 | McDbgLevel debugLevel, |
---|
| 6354 | Fsm_Fsm_t *modelFsm) |
---|
| 6355 | { |
---|
| 6356 | McStatePassesOrFailsFormulaMine( aState, formula, 1, debugLevel, modelFsm ); |
---|
| 6357 | } |
---|
| 6358 | |
---|
| 6359 | |
---|
| 6360 | /**Function******************************************************************** |
---|
| 6361 | |
---|
| 6362 | Synopsis [Print message saying given state fails formula.] |
---|
| 6363 | |
---|
| 6364 | SideEffects [] |
---|
| 6365 | |
---|
| 6366 | ******************************************************************************/ |
---|
| 6367 | static void |
---|
| 6368 | McStateFailsFormulaMine( |
---|
| 6369 | mdd_t *aState, |
---|
| 6370 | Ctlp_Formula_t *formula, |
---|
| 6371 | McDbgLevel debugLevel, |
---|
| 6372 | Fsm_Fsm_t *modelFsm) |
---|
| 6373 | { |
---|
| 6374 | McStatePassesOrFailsFormulaMine( aState, formula, 0, debugLevel, modelFsm ); |
---|
| 6375 | } |
---|
| 6376 | |
---|
| 6377 | |
---|
| 6378 | /**Function******************************************************************** |
---|
| 6379 | |
---|
| 6380 | Synopsis [Utility function - prints state passes or fails formula] |
---|
| 6381 | |
---|
| 6382 | SideEffects [] |
---|
| 6383 | |
---|
| 6384 | ******************************************************************************/ |
---|
| 6385 | static void |
---|
| 6386 | McStatePassesOrFailsFormulaMine ( |
---|
| 6387 | mdd_t *aState, |
---|
| 6388 | Ctlp_Formula_t *formula, |
---|
| 6389 | int pass, |
---|
| 6390 | McDbgLevel debugLevel, |
---|
| 6391 | Fsm_Fsm_t *modelFsm) |
---|
| 6392 | { |
---|
| 6393 | |
---|
| 6394 | (void) fprintf(vis_stderr, "![McStatePassesOrFailsFormulaMine] \n"); |
---|
| 6395 | array_t *PSVars = Fsm_FsmReadPresentStateVars( modelFsm ); |
---|
| 6396 | char *formulaText = Ctlp_FormulaConvertToString( formula ); |
---|
| 6397 | Ntk_Network_t *modelNetwork = Fsm_FsmReadNetwork( modelFsm ); |
---|
| 6398 | |
---|
| 6399 | /* Nodes created in converting formulae like AU may not have text |
---|
| 6400 | * attached to them. */ |
---|
| 6401 | if (formulaText == NIL(char)) |
---|
| 6402 | return; |
---|
| 6403 | |
---|
| 6404 | fprintf( vis_stdout, "--State\n"); |
---|
| 6405 | Mc_MintermPrintMine( aState, PSVars, modelNetwork ); |
---|
| 6406 | if ( pass ) |
---|
| 6407 | fprintf( vis_stdout, "passes "); |
---|
| 6408 | else |
---|
| 6409 | fprintf( vis_stdout, "fails "); |
---|
| 6410 | |
---|
| 6411 | if( debugLevel > McDbgLevelMin_c) |
---|
| 6412 | fprintf(vis_stdout, "%s.\n\n", formulaText); |
---|
| 6413 | else |
---|
| 6414 | fprintf(vis_stdout, "\n\n"); |
---|
| 6415 | |
---|
| 6416 | FREE(formulaText); |
---|
| 6417 | } |
---|
| 6418 | |
---|
| 6419 | |
---|
| 6420 | /**Function******************************************************************** |
---|
| 6421 | |
---|
| 6422 | Synopsis [Compare two strings in the from of char **] |
---|
| 6423 | |
---|
| 6424 | SideEffects [] |
---|
| 6425 | |
---|
| 6426 | ******************************************************************************/ |
---|
| 6427 | static int |
---|
| 6428 | cmp( |
---|
| 6429 | const void * s1, |
---|
| 6430 | const void * s2) |
---|
| 6431 | { |
---|
| 6432 | return(strcmp(*(char **)s1, *(char **)s2)); |
---|
| 6433 | } |
---|
| 6434 | |
---|
| 6435 | |
---|
| 6436 | |
---|
| 6437 | /**Function******************************************************************** |
---|
| 6438 | |
---|
| 6439 | Synopsis [Test that given mdd is a minterm.] |
---|
| 6440 | |
---|
| 6441 | SideEffects [] |
---|
| 6442 | |
---|
| 6443 | ******************************************************************************/ |
---|
| 6444 | static boolean |
---|
| 6445 | MintermCheckWellFormed( |
---|
| 6446 | mdd_t *aMinterm, |
---|
| 6447 | array_t *aSupport, |
---|
| 6448 | mdd_manager *mddMgr) |
---|
| 6449 | { |
---|
| 6450 | |
---|
| 6451 | /* first check its support */ |
---|
| 6452 | if (!SetCheckSupport(aMinterm, aSupport, mddMgr)) { |
---|
| 6453 | return FALSE; |
---|
| 6454 | } |
---|
| 6455 | |
---|
| 6456 | /* now check its a minterm */ |
---|
| 6457 | { |
---|
| 6458 | float cardinality = mdd_count_onset( mddMgr, aMinterm, aSupport ); |
---|
| 6459 | if ( cardinality != 1 ) { |
---|
| 6460 | fprintf( vis_stderr, "-- onset is not one\n"); |
---|
| 6461 | return FALSE; |
---|
| 6462 | } |
---|
| 6463 | } |
---|
| 6464 | return TRUE; |
---|
| 6465 | } |
---|
| 6466 | |
---|
| 6467 | |
---|
| 6468 | /**Function******************************************************************** |
---|
| 6469 | |
---|
| 6470 | Synopsis [Test that given mdd is a minterm.] |
---|
| 6471 | |
---|
| 6472 | SideEffects [] |
---|
| 6473 | |
---|
| 6474 | ******************************************************************************/ |
---|
| 6475 | static boolean |
---|
| 6476 | SetCheckSupport( |
---|
| 6477 | mdd_t *aMinterm, |
---|
| 6478 | array_t *aSupport, |
---|
| 6479 | mdd_manager *mddMgr) |
---|
| 6480 | { |
---|
| 6481 | if (!mdd_check_support(mddMgr, aMinterm, aSupport)) { |
---|
| 6482 | fprintf(vis_stderr, |
---|
| 6483 | "** mc error: support of minterm is not contained in claimed support\n"); |
---|
| 6484 | return FALSE; |
---|
| 6485 | } |
---|
| 6486 | return TRUE; |
---|
| 6487 | } |
---|
| 6488 | |
---|
| 6489 | |
---|
| 6490 | /**Function******************************************************************** |
---|
| 6491 | |
---|
| 6492 | Synopsis [CNF Clause generator - variable name contruction] |
---|
| 6493 | |
---|
| 6494 | SideEffects [] |
---|
| 6495 | |
---|
| 6496 | ******************************************************************************/ |
---|
| 6497 | static char *CNFVariableNameConstructor(char *varName, int varEncoding, int pathIndex) |
---|
| 6498 | { |
---|
| 6499 | char tempStr [LENGTH_1]; |
---|
| 6500 | char *cnfVarName; |
---|
| 6501 | int nChar; |
---|
| 6502 | |
---|
| 6503 | nChar = sprintf(tempStr, "%s_%d_%d", varName, varEncoding, pathIndex); // value sign has to be added later |
---|
| 6504 | cnfVarName = tempStr; |
---|
| 6505 | //(void) fprintf(vis_stderr, "[TEST] CNF Variable Name : %s [number of characters = %d] >> return : %s\n", tempStr, nChar, cnfVarName); |
---|
| 6506 | |
---|
| 6507 | return cnfVarName; |
---|
| 6508 | } |
---|
| 6509 | |
---|
| 6510 | /**Function******************************************************************** |
---|
| 6511 | |
---|
| 6512 | Synopsis [ |
---|
| 6513 | c = a <-> b = (a=0)*(b=0) + (a=1)*(b=1) .... |
---|
| 6514 | For a given term (a=i)*(b=i), if either is Zero, don't generate |
---|
| 6515 | clauses for this term. |
---|
| 6516 | if both are One, don't generate clauses |
---|
| 6517 | for c. |
---|
| 6518 | ] |
---|
| 6519 | |
---|
| 6520 | SideEffects [] |
---|
| 6521 | |
---|
| 6522 | ******************************************************************************/ |
---|
| 6523 | static void |
---|
| 6524 | BmcGenerateClausesFromStateTostateMine( |
---|
| 6525 | bAig_Manager_t *manager, |
---|
| 6526 | bAigEdge_t *fromAigArray, |
---|
| 6527 | bAigEdge_t *toAigArray, |
---|
| 6528 | int mvfSize, |
---|
| 6529 | int fromState, |
---|
| 6530 | int toState, |
---|
| 6531 | BmcCnfClauses_t *cnfClauses, |
---|
| 6532 | int outIndex) |
---|
| 6533 | { |
---|
| 6534 | array_t *clause, *tmpclause; |
---|
| 6535 | int toIndex, fromIndex, cnfIndex; |
---|
| 6536 | int i; |
---|
| 6537 | |
---|
| 6538 | /* used to turn off the warning messages: might be left uninitialized. |
---|
| 6539 | We are sure that these two variables will not be used uninitialized. |
---|
| 6540 | */ |
---|
| 6541 | toIndex =0; |
---|
| 6542 | fromIndex = 0; |
---|
| 6543 | |
---|
| 6544 | for(i=0; i< mvfSize; i++){ |
---|
| 6545 | if ((fromAigArray[i] == bAig_One) && (toAigArray[i] == bAig_One)){ |
---|
| 6546 | return; /* the clause is always true */ |
---|
| 6547 | } |
---|
| 6548 | } |
---|
| 6549 | clause = array_alloc(int, 0); |
---|
| 6550 | for(i=0; i< mvfSize; i++){ |
---|
| 6551 | if ((fromAigArray[i] != bAig_Zero) && (toAigArray[i] != bAig_Zero)){ |
---|
| 6552 | if (toAigArray[i] != bAig_One){ |
---|
| 6553 | /* to State */ |
---|
| 6554 | |
---|
| 6555 | toIndex = BmcGenerateCnfFormulaForAigFunction(manager,toAigArray[i], |
---|
| 6556 | toState,cnfClauses); |
---|
| 6557 | } |
---|
| 6558 | if (fromAigArray[i] != bAig_One){ |
---|
| 6559 | /* from State */ |
---|
| 6560 | fromIndex = BmcGenerateCnfFormulaForAigFunction(manager, |
---|
| 6561 | fromAigArray[i], |
---|
| 6562 | fromState, |
---|
| 6563 | cnfClauses); |
---|
| 6564 | } |
---|
| 6565 | /* |
---|
| 6566 | Create new var for the output of this node. We don't create variable for this node, we only |
---|
| 6567 | use its index number. |
---|
| 6568 | */ |
---|
| 6569 | cnfIndex = cnfClauses->cnfGlobalIndex++; /* index of the output of the OR of T(from, to) */ |
---|
| 6570 | |
---|
| 6571 | assert(abs(cnfIndex) <= cnfClauses->cnfGlobalIndex); |
---|
| 6572 | assert(abs(fromIndex) <= cnfClauses->cnfGlobalIndex); |
---|
| 6573 | assert(abs(toIndex) <= cnfClauses->cnfGlobalIndex); |
---|
| 6574 | |
---|
| 6575 | if (toAigArray[i] == bAig_One){ |
---|
| 6576 | tmpclause = array_alloc(int, 2); |
---|
| 6577 | array_insert(int, tmpclause, 0, -fromIndex); |
---|
| 6578 | array_insert(int, tmpclause, 1, cnfIndex); |
---|
| 6579 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
| 6580 | array_free(tmpclause); |
---|
| 6581 | |
---|
| 6582 | tmpclause = array_alloc(int, 2); |
---|
| 6583 | array_insert(int, tmpclause, 0, fromIndex); |
---|
| 6584 | array_insert(int, tmpclause, 1, -cnfIndex); |
---|
| 6585 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
| 6586 | array_free(tmpclause); |
---|
| 6587 | |
---|
| 6588 | } else if (fromAigArray[i] == bAig_One){ |
---|
| 6589 | tmpclause = array_alloc(int, 2); |
---|
| 6590 | array_insert(int, tmpclause, 0, -toIndex); |
---|
| 6591 | array_insert(int, tmpclause, 1, cnfIndex); |
---|
| 6592 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
| 6593 | array_free(tmpclause); |
---|
| 6594 | |
---|
| 6595 | tmpclause = array_alloc(int, 2); |
---|
| 6596 | array_insert(int, tmpclause, 0, toIndex); |
---|
| 6597 | array_insert(int, tmpclause, 1, -cnfIndex); |
---|
| 6598 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
| 6599 | array_free(tmpclause); |
---|
| 6600 | |
---|
| 6601 | } else { |
---|
| 6602 | tmpclause = array_alloc(int, 3); |
---|
| 6603 | array_insert(int, tmpclause, 0, -toIndex); |
---|
| 6604 | array_insert(int, tmpclause, 1, -fromIndex); |
---|
| 6605 | array_insert(int, tmpclause, 2, cnfIndex); |
---|
| 6606 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
| 6607 | array_free(tmpclause); |
---|
| 6608 | |
---|
| 6609 | tmpclause = array_alloc(int, 2); |
---|
| 6610 | array_insert(int, tmpclause, 0, toIndex); |
---|
| 6611 | array_insert(int, tmpclause, 1, -cnfIndex); |
---|
| 6612 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
| 6613 | array_free(tmpclause); |
---|
| 6614 | |
---|
| 6615 | tmpclause = array_alloc(int, 2); |
---|
| 6616 | array_insert(int, tmpclause, 0, fromIndex); |
---|
| 6617 | array_insert(int, tmpclause, 1, -cnfIndex); |
---|
| 6618 | BmcCnfInsertClause(cnfClauses, tmpclause); |
---|
| 6619 | array_free(tmpclause); |
---|
| 6620 | } |
---|
| 6621 | array_insert_last(int, clause, cnfIndex); |
---|
| 6622 | } /* if */ |
---|
| 6623 | // (void) fprintf(vis_stderr, "[CNF] (%d) > To : %d; From : %d; cnfIndex : %d \n", i, toIndex, fromIndex, cnfIndex); |
---|
| 6624 | } /* for i loop */ |
---|
| 6625 | if (outIndex != 0 ){ |
---|
| 6626 | array_insert_last(int, clause, -outIndex); |
---|
| 6627 | } |
---|
| 6628 | BmcCnfInsertClause(cnfClauses, clause); |
---|
| 6629 | array_free(clause); |
---|
| 6630 | |
---|
| 6631 | return; |
---|
| 6632 | } |
---|
| 6633 | |
---|
| 6634 | |
---|
| 6635 | /**Function******************************************************************** |
---|
| 6636 | |
---|
| 6637 | Synopsis [Generate CNF formula for a path from state 'from' to state 'to'] |
---|
| 6638 | |
---|
| 6639 | Description [Unfold the transition relation 'k' states (k = to-from +1), and |
---|
| 6640 | generate clauses for each state. |
---|
| 6641 | |
---|
| 6642 | For a multi-valued latch of 4 vlaues. Two binary variables are used |
---|
| 6643 | to rpresent X, x1 and x0. For this latch, there exist three multi-valued |
---|
| 6644 | functions. |
---|
| 6645 | One for the binary reoresentation of the variable. For example the |
---|
| 6646 | second entry of the mvf = 1, iff ~x1 and x0. |
---|
| 6647 | The second mfv is for the data input of the latch. If the And/Inv graph |
---|
| 6648 | attached to an entry of this mvf equal to 1, X equal to the binary |
---|
| 6649 | representation corresponding to this entry. For example, if the And/ |
---|
| 6650 | INV graph attached to the first entry =1, then X = ~x1 & ~x0. |
---|
| 6651 | To generate the CNF to the transition relation, first generate CNF to |
---|
| 6652 | next state varaible using mvf of the latch. Then, generate CNF for |
---|
| 6653 | latch data input using current state variavles. Finaly, generate CNF |
---|
| 6654 | for the AND of these two MVF. This for every entry of the MVF. Then |
---|
| 6655 | OR the results. |
---|
| 6656 | The third MVF is for the initial value of the latch. It is treat the |
---|
| 6657 | same as the latch data input except if the initial value is constant. |
---|
| 6658 | |
---|
| 6659 | The initialState value may be either BMC_INITIAL_STATES to generate the clause for the intial states. |
---|
| 6660 | BMC_NO_INITIAL_STATES otherwise. |
---|
| 6661 | ] |
---|
| 6662 | |
---|
| 6663 | SideEffects [] |
---|
| 6664 | |
---|
| 6665 | SeeAlso [] |
---|
| 6666 | |
---|
| 6667 | ******************************************************************************/ |
---|
| 6668 | static void |
---|
| 6669 | BmcCnfGenerateClausesForPathMine( |
---|
| 6670 | Ntk_Network_t *network, |
---|
| 6671 | int from, |
---|
| 6672 | int to, |
---|
| 6673 | int initialState, |
---|
| 6674 | BmcCnfClauses_t *cnfClauses, |
---|
| 6675 | st_table *nodeToMvfAigTable, |
---|
| 6676 | st_table *CoiTable) |
---|
| 6677 | { |
---|
| 6678 | mAig_Manager_t *manager = Ntk_NetworkReadMAigManager(network); |
---|
| 6679 | st_generator *stGen; |
---|
| 6680 | |
---|
| 6681 | Ntk_Node_t *latch, *latchData, *latchInit; |
---|
| 6682 | MvfAig_Function_t *initMvfAig, *dataMvfAig, *latchMvfAig; |
---|
| 6683 | bAigEdge_t *initBAig, *latchBAig, *dataBAig; |
---|
| 6684 | |
---|
| 6685 | int i, k, mvfSize; |
---|
| 6686 | |
---|
| 6687 | st_foreach_item(CoiTable, stGen, &latch, NULL) { |
---|
| 6688 | |
---|
| 6689 | |
---|
| 6690 | latchInit = Ntk_LatchReadInitialInput(latch); |
---|
| 6691 | latchData = Ntk_LatchReadDataInput(latch); |
---|
| 6692 | |
---|
| 6693 | /* Get the multi-valued function for each node*/ |
---|
| 6694 | initMvfAig = Bmc_ReadMvfAig(latchInit, nodeToMvfAigTable); |
---|
| 6695 | if (initMvfAig == NIL(MvfAig_Function_t)){ |
---|
| 6696 | (void) fprintf(vis_stderr, "No multi-valued function for this node %s \n", Ntk_NodeReadName(latchInit)); |
---|
| 6697 | return; |
---|
| 6698 | } |
---|
| 6699 | dataMvfAig = Bmc_ReadMvfAig(latchData, nodeToMvfAigTable); |
---|
| 6700 | if (dataMvfAig == NIL(MvfAig_Function_t)){ |
---|
| 6701 | (void) fprintf(vis_stderr, "No multi-valued function for this node %s \n", Ntk_NodeReadName(latchData)); |
---|
| 6702 | return; |
---|
| 6703 | } |
---|
| 6704 | latchMvfAig = Bmc_ReadMvfAig(latch, nodeToMvfAigTable); |
---|
| 6705 | if (latchMvfAig == NIL(MvfAig_Function_t)){ |
---|
| 6706 | latchMvfAig = Bmc_NodeBuildMVF(network, latch); |
---|
| 6707 | array_free(latchMvfAig); |
---|
| 6708 | latchMvfAig = Bmc_ReadMvfAig(latch, nodeToMvfAigTable); |
---|
| 6709 | } |
---|
| 6710 | |
---|
| 6711 | mvfSize = array_n(initMvfAig); |
---|
| 6712 | initBAig = ALLOC(bAigEdge_t, mvfSize); |
---|
| 6713 | dataBAig = ALLOC(bAigEdge_t, mvfSize); |
---|
| 6714 | latchBAig = ALLOC(bAigEdge_t, mvfSize); |
---|
| 6715 | |
---|
| 6716 | for(i=0; i< mvfSize; i++){ |
---|
| 6717 | dataBAig[i] = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(dataMvfAig, i)); |
---|
| 6718 | latchBAig[i] = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(latchMvfAig, i)); |
---|
| 6719 | initBAig[i] = bAig_GetCanonical(manager, MvfAig_FunctionReadComponent(initMvfAig, i)); |
---|
| 6720 | } |
---|
| 6721 | /* |
---|
| 6722 | if (from == 0){ |
---|
| 6723 | */ |
---|
| 6724 | if (initialState == BMC_INITIAL_STATES){ |
---|
| 6725 | /* Generate the CNF for the initial state of the latch */ |
---|
| 6726 | BmcGenerateClausesFromStateTostateMine(manager, initBAig, latchBAig, mvfSize, -1, 0, cnfClauses, 0); |
---|
| 6727 | } |
---|
| 6728 | /* Generate the CNF for the transition functions */ |
---|
| 6729 | for (k=from; k < to; k++){ |
---|
| 6730 | BmcGenerateClausesFromStateTostateMine(manager, dataBAig, latchBAig, mvfSize, k, k+1, cnfClauses, 0); |
---|
| 6731 | } /* for k state loop */ |
---|
| 6732 | |
---|
| 6733 | FREE(initBAig); |
---|
| 6734 | FREE(dataBAig); |
---|
| 6735 | FREE(latchBAig); |
---|
| 6736 | }/* For each latch loop*/ |
---|
| 6737 | |
---|
| 6738 | return; |
---|
| 6739 | } |
---|
| 6740 | |
---|
| 6741 | |
---|
| 6742 | |
---|
| 6743 | /**Function******************************************************************** |
---|
| 6744 | |
---|
| 6745 | Synopsis [Write the set of clauses in diamacs format to the output file.] |
---|
| 6746 | |
---|
| 6747 | SideEffects [] |
---|
| 6748 | |
---|
| 6749 | ******************************************************************************/ |
---|
| 6750 | static void |
---|
| 6751 | BmcWriteClausesMine( |
---|
| 6752 | mAig_Manager_t *maigManager, |
---|
| 6753 | FILE *cnfFile, |
---|
| 6754 | BmcCnfClauses_t *cnfClauses, |
---|
| 6755 | BmcOption_t *options) |
---|
| 6756 | { |
---|
| 6757 | st_generator *stGen; |
---|
| 6758 | char *name; |
---|
| 6759 | int cnfIndex, i, k; |
---|
| 6760 | |
---|
| 6761 | if (options->verbosityLevel == BmcVerbosityMax_c) { |
---|
| 6762 | fprintf(vis_stderr, |
---|
| 6763 | "\n--- [CNF] Number of Variables = %d Number of Clauses = %d\n", |
---|
| 6764 | cnfClauses->cnfGlobalIndex-1, cnfClauses->noOfClauses); |
---|
| 6765 | } |
---|
| 6766 | st_foreach_item_int(cnfClauses->cnfIndexTable, stGen, &name, &cnfIndex) { |
---|
| 6767 | fprintf(cnfFile, "c %s %d\n",name, cnfIndex); |
---|
| 6768 | } |
---|
| 6769 | (void) fprintf(cnfFile, "p cnf %d %d\n", cnfClauses->cnfGlobalIndex-1, |
---|
| 6770 | cnfClauses->noOfClauses); |
---|
| 6771 | if (cnfClauses->clauseArray != NIL(array_t)) { |
---|
| 6772 | for (i = 0; i < cnfClauses->nextIndex; i++) { |
---|
| 6773 | k = array_fetch(int, cnfClauses->clauseArray, i); |
---|
| 6774 | (void) fprintf(cnfFile, "%d%c", k, (k == 0) ? '\n' : ' '); |
---|
| 6775 | } |
---|
| 6776 | } |
---|
| 6777 | return; |
---|
| 6778 | } |
---|
| 6779 | |
---|
| 6780 | |
---|
| 6781 | /**Function******************************************************************** |
---|
| 6782 | |
---|
| 6783 | Synopsis [Decimal value to binary converter - Done by Me] |
---|
| 6784 | |
---|
| 6785 | SideEffects [] |
---|
| 6786 | |
---|
| 6787 | ******************************************************************************/ |
---|
| 6788 | |
---|
| 6789 | static int *DecBinConverter (int decValue, int size, int *binValue){ |
---|
| 6790 | |
---|
| 6791 | int i; |
---|
| 6792 | // int tempVal; |
---|
| 6793 | // int *binValue = malloc (sizeof(int)*size); |
---|
| 6794 | |
---|
| 6795 | // tempVal = decValue; |
---|
| 6796 | for (i=0; i<size; i++){ |
---|
| 6797 | // (void) fprintf(vis_stderr, " ***** tempVal = %d \n", tempVal); |
---|
| 6798 | binValue[i] = decValue & 1; |
---|
| 6799 | decValue = decValue >> 1; |
---|
| 6800 | } |
---|
| 6801 | |
---|
| 6802 | return binValue; |
---|
| 6803 | } |
---|
| 6804 | |
---|
| 6805 | |
---|
| 6806 | /**Function******************************************************************** |
---|
| 6807 | |
---|
| 6808 | Synopsis [] |
---|
| 6809 | |
---|
| 6810 | Description [- Done by Cecile Braunstein] |
---|
| 6811 | |
---|
| 6812 | SideEffects [] |
---|
| 6813 | |
---|
| 6814 | SeeAlso [] |
---|
| 6815 | |
---|
| 6816 | ******************************************************************************/ |
---|
| 6817 | static void printSATAssig( array_t* result) |
---|
| 6818 | { |
---|
| 6819 | int k; |
---|
| 6820 | printf("RESULT : \n"); |
---|
| 6821 | for(k=0; k< array_n(result); k++){ |
---|
| 6822 | printf("%d\n",array_fetch(int, result, k)); |
---|
| 6823 | } |
---|
| 6824 | } |
---|
| 6825 | |
---|
| 6826 | /**Function******************************************************************** |
---|
| 6827 | |
---|
| 6828 | Synopsis [] |
---|
| 6829 | |
---|
| 6830 | Description [- Done by Cecile Braunstein] |
---|
| 6831 | |
---|
| 6832 | SideEffects [] |
---|
| 6833 | |
---|
| 6834 | SeeAlso [] |
---|
| 6835 | |
---|
| 6836 | ******************************************************************************/ |
---|
| 6837 | static int findIndex(BmcCnfClauses_t* cnfClauses , char * nodeName) |
---|
| 6838 | { |
---|
| 6839 | int index; |
---|
| 6840 | |
---|
| 6841 | st_lookup(cnfClauses->cnfIndexTable,nodeName,&index); |
---|
| 6842 | return index; |
---|
| 6843 | |
---|
| 6844 | } |
---|
| 6845 | |
---|
| 6846 | |
---|
| 6847 | /**Function******************************************************************** |
---|
| 6848 | |
---|
| 6849 | Synopsis [] |
---|
| 6850 | |
---|
| 6851 | Description [- Done by Cecile Braunstein] |
---|
| 6852 | |
---|
| 6853 | SideEffects [] |
---|
| 6854 | |
---|
| 6855 | SeeAlso [] |
---|
| 6856 | |
---|
| 6857 | ******************************************************************************/ |
---|
| 6858 | static st_table * generateAllLatches(Ntk_Network_t * ntk) |
---|
| 6859 | { |
---|
| 6860 | st_table *CoiTable = st_init_table(st_ptrcmp, st_ptrhash); |
---|
| 6861 | lsGen gen ; |
---|
| 6862 | Ntk_Node_t *node; |
---|
| 6863 | |
---|
| 6864 | Ntk_NetworkForEachNode(ntk,gen, node){ |
---|
| 6865 | if (Ntk_NodeTestIsLatch(node)){ |
---|
| 6866 | st_insert(CoiTable, (char *) node, (char *) 0); |
---|
| 6867 | } |
---|
| 6868 | } |
---|
| 6869 | return CoiTable; |
---|
| 6870 | } |
---|
| 6871 | |
---|
| 6872 | |
---|
| 6873 | /**Function******************************************************************** |
---|
| 6874 | |
---|
| 6875 | Synopsis [] |
---|
| 6876 | |
---|
| 6877 | Description [- Done by Cecile Braunstein] |
---|
| 6878 | |
---|
| 6879 | SideEffects [] |
---|
| 6880 | |
---|
| 6881 | SeeAlso [] |
---|
| 6882 | |
---|
| 6883 | ******************************************************************************/ |
---|
| 6884 | static void build_unroll_circuit(Ntk_Network_t * ntk, int bound, BmcOption_t * options,BmcCnfClauses_t* cnfClauses) |
---|
| 6885 | { |
---|
| 6886 | (void) fprintf(vis_stderr, "\n*** Generating CNF clauses for current network. *** \n"); |
---|
| 6887 | |
---|
| 6888 | st_table *CoiTable = generateAllLatches(ntk); |
---|
| 6889 | lsGen gen ; |
---|
| 6890 | Ntk_Node_t *node; |
---|
| 6891 | |
---|
| 6892 | |
---|
| 6893 | |
---|
| 6894 | Ntk_NetworkForEachNode(ntk,gen, node){ |
---|
| 6895 | if (Ntk_NodeTestIsLatch(node)){ |
---|
| 6896 | st_insert(CoiTable, (char *) node, (char *) 0); |
---|
| 6897 | } |
---|
| 6898 | } |
---|
| 6899 | |
---|
| 6900 | options->verbosityLevel = BmcVerbosityMax_c; |
---|
| 6901 | options->satSolver = CirCUs; |
---|
| 6902 | options->timeOutPeriod = 0; |
---|
| 6903 | options->printInputs = TRUE; |
---|
| 6904 | options->minK = bound; |
---|
| 6905 | options->maxK = bound; |
---|
| 6906 | options->step = bound; |
---|
| 6907 | options->dbgLevel = 1; |
---|
| 6908 | |
---|
| 6909 | //nodeToMvfAigTable Maps each node to its Multi-function And/Inv graph |
---|
| 6910 | st_table* nodeToMvfAigTable = (st_table *) Ntk_NetworkReadApplInfo(ntk, MVFAIG_NETWORK_APPL_KEY); |
---|
| 6911 | assert(nodeToMvfAigTable != NIL(st_table)); |
---|
| 6912 | |
---|
| 6913 | // Create clauses database |
---|
| 6914 | int initState = BMC_INITIAL_STATES; |
---|
| 6915 | BmcCnfGenerateClausesForPathMine(ntk, 0, bound, initState, cnfClauses, nodeToMvfAigTable, CoiTable); |
---|
| 6916 | |
---|
| 6917 | } |
---|
| 6918 | |
---|
| 6919 | |
---|
| 6920 | /**Function******************************************************************** |
---|
| 6921 | |
---|
| 6922 | Synopsis [SAT Solver CNF File generator - Done by Cecile Braunstein] |
---|
| 6923 | |
---|
| 6924 | Description [ OBSOLETE!!! ] |
---|
| 6925 | |
---|
| 6926 | SideEffects [] |
---|
| 6927 | |
---|
| 6928 | ******************************************************************************/ |
---|
| 6929 | |
---|
| 6930 | static int SATSolverFileGen (Hrc_Manager_t ** hmgr, char *fileName, int steps, BmcOption_t *options) |
---|
| 6931 | { |
---|
| 6932 | |
---|
| 6933 | (void) fprintf(vis_stderr, "\n*** Generating CNF File for SAT Solver. *** \n"); |
---|
| 6934 | |
---|
| 6935 | // BmcOption_t *options = BmcOptionAlloc(); |
---|
| 6936 | BmcCnfClauses_t *cnfClauses = NIL(BmcCnfClauses_t); |
---|
| 6937 | cnfClauses = BmcCnfClausesAlloc(); |
---|
| 6938 | Ntk_Network_t * ntk = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 6939 | build_unroll_circuit(ntk,steps,options,cnfClauses); |
---|
| 6940 | |
---|
| 6941 | int propIndex; |
---|
| 6942 | int newIndex; |
---|
| 6943 | array_t * newClause; |
---|
| 6944 | char *tempCNFString; |
---|
| 6945 | |
---|
| 6946 | tempCNFString = CNFVariableNameConstructor("o2", 0, 0); |
---|
| 6947 | propIndex = findIndex(cnfClauses, tempCNFString); |
---|
| 6948 | newClause = array_alloc(int,1); |
---|
| 6949 | array_insert(int,newClause,0,-propIndex); |
---|
| 6950 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
| 6951 | array_free(newClause); |
---|
| 6952 | |
---|
| 6953 | tempCNFString = CNFVariableNameConstructor("o2", 0, 1); |
---|
| 6954 | propIndex = findIndex(cnfClauses, tempCNFString); |
---|
| 6955 | newClause = array_alloc(int,1); |
---|
| 6956 | array_insert(int,newClause,0,-propIndex); |
---|
| 6957 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
| 6958 | array_free(newClause); |
---|
| 6959 | |
---|
| 6960 | tempCNFString = CNFVariableNameConstructor("o2", 0, 2); |
---|
| 6961 | propIndex = findIndex(cnfClauses, tempCNFString); |
---|
| 6962 | newClause = array_alloc(int,1); |
---|
| 6963 | array_insert(int,newClause,0, -propIndex); |
---|
| 6964 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
| 6965 | array_free(newClause); |
---|
| 6966 | |
---|
| 6967 | tempCNFString = CNFVariableNameConstructor("o2", 0, 3); |
---|
| 6968 | propIndex = findIndex(cnfClauses, tempCNFString); |
---|
| 6969 | newClause = array_alloc(int,1); |
---|
| 6970 | array_insert(int,newClause,0, propIndex); |
---|
| 6971 | BmcCnfInsertClause(cnfClauses, newClause); |
---|
| 6972 | array_free(newClause); |
---|
| 6973 | |
---|
| 6974 | |
---|
| 6975 | FILE *cnfFile = fopen(fileName,"w"); |
---|
| 6976 | mAig_Manager_t * maigManager = Ntk_NetworkReadMAigManager(ntk); |
---|
| 6977 | BmcWriteClausesMine(maigManager, cnfFile, cnfClauses, options); |
---|
| 6978 | fclose(cnfFile); |
---|
| 6979 | |
---|
| 6980 | return 0; |
---|
| 6981 | } |
---|
| 6982 | |
---|
| 6983 | |
---|
| 6984 | /**Function******************************************************************** |
---|
| 6985 | |
---|
| 6986 | Synopsis [- Done by Cecile Braunstein] |
---|
| 6987 | |
---|
| 6988 | Description [] |
---|
| 6989 | |
---|
| 6990 | SideEffects [] |
---|
| 6991 | |
---|
| 6992 | SeeAlso [] |
---|
| 6993 | |
---|
| 6994 | ******************************************************************************/ |
---|
| 6995 | |
---|
| 6996 | static array_t * checkSATCircus( satManager_t *cm,BmcOption_t * options, boolean unsatcore, satArray_t *clauseIndexInCore) |
---|
| 6997 | { |
---|
| 6998 | |
---|
| 6999 | satOption_t *satOption; |
---|
| 7000 | array_t *result = NIL(array_t); |
---|
| 7001 | int maxSize; |
---|
| 7002 | |
---|
| 7003 | satOption = sat_InitOption(); |
---|
| 7004 | satOption->verbose = options->verbosityLevel; |
---|
| 7005 | //satOption->unsatCoreFileName = "Ucore.txt"; |
---|
| 7006 | satOption->clauseDeletionHeuristic = 0; |
---|
| 7007 | satOption->coreGeneration = unsatcore; |
---|
| 7008 | satOption->minimizeConflictClause = 1; |
---|
| 7009 | |
---|
| 7010 | cm->comment = ALLOC(char, 2); |
---|
| 7011 | cm->comment[0] = ' '; |
---|
| 7012 | cm->comment[1] = '\0'; |
---|
| 7013 | cm->stdOut = stdout; |
---|
| 7014 | cm->stdErr = stderr; |
---|
| 7015 | |
---|
| 7016 | cm->option = satOption; |
---|
| 7017 | cm->each = sat_InitStatistics(); |
---|
| 7018 | |
---|
| 7019 | cm->unitLits = sat_ArrayAlloc(16); |
---|
| 7020 | cm->pureLits = sat_ArrayAlloc(16); |
---|
| 7021 | |
---|
| 7022 | maxSize = 10000 << (bAigNodeSize-4); |
---|
| 7023 | cm->nodesArray = ALLOC(bAigEdge_t, maxSize); |
---|
| 7024 | cm->maxNodesArraySize = maxSize; |
---|
| 7025 | cm->nodesArraySize = bAigNodeSize; |
---|
| 7026 | |
---|
| 7027 | sat_AllocLiteralsDB(cm); |
---|
| 7028 | |
---|
| 7029 | sat_ReadCNF(cm, options->satInFile); |
---|
| 7030 | sat_Main(cm); |
---|
| 7031 | if(cm->status == SAT_UNSAT) { |
---|
| 7032 | if (options->verbosityLevel != BmcVerbosityNone_c){ |
---|
| 7033 | (void) fprintf(vis_stderr, "# UNSAT\n"); |
---|
| 7034 | } |
---|
| 7035 | if(unsatcore) |
---|
| 7036 | { |
---|
| 7037 | clauseIndexInCore = cm->clauseIndexInCore; |
---|
| 7038 | } |
---|
| 7039 | fflush(cm->stdOut); |
---|
| 7040 | |
---|
| 7041 | }else if(cm->status == SAT_SAT) { |
---|
| 7042 | if (options->verbosityLevel != BmcVerbosityNone_c){ |
---|
| 7043 | (void) fprintf(vis_stderr, "# SAT\n"); |
---|
| 7044 | } |
---|
| 7045 | fflush(cm->stdOut); |
---|
| 7046 | result = array_alloc(int, 0); |
---|
| 7047 | { |
---|
| 7048 | int i, size, value; |
---|
| 7049 | |
---|
| 7050 | size = cm->initNumVariables * bAigNodeSize; |
---|
| 7051 | for(i=bAigNodeSize; i<=size; i+=bAigNodeSize) { |
---|
| 7052 | value = SATvalue(i); |
---|
| 7053 | if(value == 1) { |
---|
| 7054 | array_insert_last(int, result, SATnodeID(i)); |
---|
| 7055 | } |
---|
| 7056 | else if(value == 0) { |
---|
| 7057 | array_insert_last(int, result, -(SATnodeID(i))); |
---|
| 7058 | } |
---|
| 7059 | } |
---|
| 7060 | } |
---|
| 7061 | } |
---|
| 7062 | return result; |
---|
| 7063 | } |
---|
| 7064 | |
---|
| 7065 | |
---|
| 7066 | /**Function******************************************************************** |
---|
| 7067 | |
---|
| 7068 | Synopsis [SAT Solver - Done by Cecile Braunstein] |
---|
| 7069 | |
---|
| 7070 | SideEffects [] |
---|
| 7071 | |
---|
| 7072 | ******************************************************************************/ |
---|
| 7073 | |
---|
| 7074 | static int SATSolver (int steps, BmcOption_t *options) |
---|
| 7075 | { |
---|
| 7076 | |
---|
| 7077 | (void) fprintf(vis_stderr, "*** SAT Solver begins. *** \n"); |
---|
| 7078 | |
---|
| 7079 | // Read another design and build new clauses |
---|
| 7080 | satManager_t *cm; |
---|
| 7081 | cm = sat_InitManager(0); |
---|
| 7082 | array_t * result = NIL(array_t); |
---|
| 7083 | satArray_t * coreArray= sat_ArrayAlloc(1024); |
---|
| 7084 | result = checkSATCircus(cm,options,steps,coreArray); |
---|
| 7085 | |
---|
| 7086 | return 0; |
---|
| 7087 | } |
---|
| 7088 | |
---|
| 7089 | |
---|
| 7090 | |
---|
| 7091 | |
---|