[27] | 1 | /**CFile*********************************************************************** |
---|
| 2 | |
---|
| 3 | FileName [debug.c] |
---|
| 4 | |
---|
| 5 | PackageName [debug] |
---|
| 6 | |
---|
[30] | 7 | Synopsis [Debug package initialization, ending, and the command debug] |
---|
[27] | 8 | |
---|
[35] | 9 | Author [Cecile B.] |
---|
[27] | 10 | |
---|
| 11 | Copyright [Copyright (c) 1994-1996 The Regents of the Univ. of California. |
---|
| 12 | All rights reserved. |
---|
| 13 | |
---|
| 14 | Permission is hereby granted, without written agreement and without license |
---|
| 15 | or royalty fees, to use, copy, modify, and distribute this software and its |
---|
| 16 | documentation for any purpose, provided that the above copyright notice and |
---|
| 17 | the following two paragraphs appear in all copies of this software. |
---|
| 18 | |
---|
| 19 | IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR |
---|
| 20 | DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT |
---|
| 21 | OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF |
---|
| 22 | CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 23 | |
---|
| 24 | THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, |
---|
| 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
---|
| 26 | FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN |
---|
| 27 | "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE |
---|
| 28 | MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.] |
---|
| 29 | |
---|
| 30 | ******************************************************************************/ |
---|
| 31 | |
---|
| 32 | #include "debugInt.h" |
---|
[30] | 33 | #include "imgInt.h" |
---|
| 34 | #include "partInt.h" |
---|
[27] | 35 | static char rcsid[] UNUSED = "$Id: debug.c,v 1.6 2011/04/12 braun Exp $"; |
---|
| 36 | |
---|
| 37 | /*---------------------------------------------------------------------------*/ |
---|
| 38 | /* Constant declarations */ |
---|
| 39 | /*---------------------------------------------------------------------------*/ |
---|
| 40 | |
---|
| 41 | /*---------------------------------------------------------------------------*/ |
---|
| 42 | /* Structure declarations */ |
---|
| 43 | /*---------------------------------------------------------------------------*/ |
---|
| 44 | |
---|
| 45 | /*---------------------------------------------------------------------------*/ |
---|
| 46 | /* Type declarations */ |
---|
| 47 | /*---------------------------------------------------------------------------*/ |
---|
| 48 | |
---|
| 49 | /*---------------------------------------------------------------------------*/ |
---|
| 50 | /* Variable declarations */ |
---|
| 51 | /*---------------------------------------------------------------------------*/ |
---|
| 52 | |
---|
| 53 | /*---------------------------------------------------------------------------*/ |
---|
| 54 | /* Macro declarations */ |
---|
| 55 | /*---------------------------------------------------------------------------*/ |
---|
| 56 | |
---|
| 57 | /**AutomaticStart*************************************************************/ |
---|
| 58 | |
---|
| 59 | /*---------------------------------------------------------------------------*/ |
---|
| 60 | /* Static function prototypes */ |
---|
| 61 | /*---------------------------------------------------------------------------*/ |
---|
| 62 | |
---|
[35] | 63 | static int CommandSatDebug(Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
[27] | 64 | static int CommandDebug(Hrc_Manager_t ** hmgr, int argc, char ** argv); |
---|
[30] | 65 | static int CommandTransition(Hrc_Manager_t ** hmgr,int argc, char ** argv); |
---|
[35] | 66 | static int CommandCreateAbnormal(Hrc_Manager_t ** hmgr,int argc, char ** argv); |
---|
[41] | 67 | static int CommandGenerateNetworkCNF(Hrc_Manager_t ** hmgr,int argc, char ** argv); |
---|
[45] | 68 | static int CommandBuildCexBdd(Hrc_Manager_t ** hmgr,int argc, char ** argv); |
---|
[104] | 69 | static int CommandComposeWithCex(Hrc_Manager_t ** hmgr,int argc, char ** argv); |
---|
[27] | 70 | |
---|
| 71 | |
---|
[104] | 72 | |
---|
[27] | 73 | /**AutomaticEnd***************************************************************/ |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | /*---------------------------------------------------------------------------*/ |
---|
| 77 | /* Definition of exported functions */ |
---|
| 78 | /*---------------------------------------------------------------------------*/ |
---|
| 79 | |
---|
| 80 | /**Function******************************************************************** |
---|
| 81 | |
---|
| 82 | Synopsis [Initializes the test package.] |
---|
| 83 | |
---|
| 84 | SideEffects [] |
---|
| 85 | |
---|
| 86 | SeeAlso [Debug_End] |
---|
| 87 | |
---|
| 88 | ******************************************************************************/ |
---|
| 89 | void |
---|
| 90 | Debug_Init(void) |
---|
| 91 | { |
---|
| 92 | /* |
---|
| 93 | * Add a command to the global command table. By using the leading |
---|
| 94 | * underscore, the command will be listed under "help -a" but not "help". |
---|
| 95 | */ |
---|
[35] | 96 | Cmd_CommandAdd("_debug_test", CommandDebug, /* doesn't changes_network */ 0); |
---|
| 97 | Cmd_CommandAdd("_transition", CommandTransition, 1); |
---|
| 98 | Cmd_CommandAdd("_sat_debug", CommandSatDebug, 0); |
---|
| 99 | Cmd_CommandAdd("_createAbn", CommandCreateAbnormal, 1); |
---|
[45] | 100 | Cmd_CommandAdd("_cexbdd", CommandBuildCexBdd, 0); |
---|
[41] | 101 | Cmd_CommandAdd("print_network_cnf", CommandGenerateNetworkCNF, 0); |
---|
[104] | 102 | Cmd_CommandAdd("_compose", CommandComposeWithCex, 1); |
---|
[27] | 103 | |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | /**Function******************************************************************** |
---|
| 108 | |
---|
| 109 | Synopsis [Ends the test package.] |
---|
| 110 | |
---|
| 111 | SideEffects [] |
---|
| 112 | |
---|
| 113 | SeeAlso [Debug_Init] |
---|
| 114 | |
---|
| 115 | ******************************************************************************/ |
---|
| 116 | void |
---|
| 117 | Debug_End(void) |
---|
| 118 | { |
---|
| 119 | /* |
---|
| 120 | * For example, free any global memory (if any) which the test package is |
---|
| 121 | * responsible for. |
---|
| 122 | */ |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | /*---------------------------------------------------------------------------*/ |
---|
| 127 | /* Definition of internal functions */ |
---|
| 128 | /*---------------------------------------------------------------------------*/ |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | /*---------------------------------------------------------------------------*/ |
---|
| 132 | /* Definition of static functions */ |
---|
| 133 | /*---------------------------------------------------------------------------*/ |
---|
| 134 | |
---|
[35] | 135 | |
---|
[36] | 136 | static int CommandCreateAbnormal(Hrc_Manager_t ** hmgr, int argc, char ** argv) |
---|
[35] | 137 | { |
---|
| 138 | Ntk_Network_t * ntk; |
---|
[44] | 139 | int c,verbose = 0; |
---|
| 140 | array_t * excludes = NIL(array_t); |
---|
[36] | 141 | Dbg_Abnormal_t * abnormal; |
---|
[35] | 142 | ntk = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
[44] | 143 | char * subs; |
---|
[35] | 144 | if (ntk == NIL(Ntk_Network_t)) { |
---|
| 145 | (void) fprintf(vis_stdout, "** abn error: No network\n"); |
---|
| 146 | return 1; |
---|
| 147 | } |
---|
[44] | 148 | while ((c = util_getopt(argc, argv, "vhs:")) != EOF) { |
---|
[36] | 149 | switch(c) { |
---|
[44] | 150 | case 'h': |
---|
| 151 | goto usage; |
---|
[36] | 152 | case 'v': |
---|
| 153 | verbose = 1; |
---|
| 154 | break; |
---|
[44] | 155 | case 's': |
---|
| 156 | subs = util_strsav(util_optarg); |
---|
| 157 | excludes = array_alloc(char*,0); |
---|
| 158 | array_insert_last(char*,excludes,subs); |
---|
| 159 | break; |
---|
| 160 | default : |
---|
| 161 | goto usage; |
---|
[35] | 162 | } |
---|
[36] | 163 | } |
---|
| 164 | abnormal = Dbg_DebugAbnormalAlloc(ntk); |
---|
| 165 | abnormal->verbose = verbose; |
---|
[44] | 166 | printf("SUBS %s \n",subs); |
---|
| 167 | Dbg_AddAbnormalPredicatetoNetwork(abnormal,excludes); |
---|
| 168 | printf("\t # Abnormal predicate created %d\n", array_n(abnormal->abnormal)); |
---|
| 169 | return 0; |
---|
| 170 | usage : |
---|
| 171 | (void) fprintf(vis_stderr, "usage: _createAbn [-h] [-v verboseLevel] [-s substystem excludes\n"); |
---|
| 172 | (void) fprintf(vis_stderr, " -h \tprint the command usage\n"); |
---|
| 173 | (void) fprintf(vis_stderr, " -v \t verbosity\n"); |
---|
| 174 | (void) fprintf(vis_stderr, " -s <subsystemName> \texclude the abnormal predicate\ |
---|
| 175 | for this subssytem\n"); |
---|
| 176 | return 1; |
---|
[35] | 177 | } |
---|
[44] | 178 | |
---|
[27] | 179 | /**Function******************************************************************** |
---|
| 180 | |
---|
[35] | 181 | Synopsis [Implements the _sat_debug command.] |
---|
| 182 | |
---|
| 183 | CommandName [_sat_debug] |
---|
| 184 | |
---|
| 185 | CommandSynopsis [locate faulty candidates] |
---|
| 186 | |
---|
| 187 | CommandArguments [\[-h\] \[-v\]] |
---|
| 188 | |
---|
| 189 | CommandDescription [This command compute the fault candidates of a given |
---|
| 190 | properties.<p> |
---|
| 191 | |
---|
| 192 | Command options:<p> |
---|
| 193 | |
---|
| 194 | <dl> |
---|
| 195 | <dt> -h |
---|
| 196 | <dd> Print the command usage. |
---|
| 197 | </dl> |
---|
| 198 | |
---|
| 199 | <dt> -v |
---|
| 200 | <dd> Verbose mode. |
---|
| 201 | </dl> |
---|
| 202 | ] |
---|
| 203 | |
---|
| 204 | SideEffects [] |
---|
| 205 | |
---|
| 206 | ******************************************************************************/ |
---|
| 207 | static int |
---|
| 208 | CommandSatDebug( |
---|
| 209 | Hrc_Manager_t ** hmgr, |
---|
| 210 | int argc, |
---|
| 211 | char ** argv){ |
---|
| 212 | int c,i; |
---|
| 213 | int verbose = 0; /* default value */ |
---|
[41] | 214 | BmcOption_t * options = BmcOptionAlloc(); |
---|
| 215 | Ntk_Network_t * network; |
---|
| 216 | bAig_Manager_t * manager; |
---|
| 217 | array_t * formulaArray; |
---|
| 218 | array_t * LTLformulaArray; |
---|
[42] | 219 | array_t * faultNodes = array_alloc(Ntk_Node_t*,0); |
---|
[35] | 220 | |
---|
| 221 | /* |
---|
| 222 | * Parse command line options. |
---|
| 223 | */ |
---|
[41] | 224 | if ((options = ParseBmcOptions(argc, argv)) == NIL(BmcOption_t)) { |
---|
| 225 | return 1; |
---|
| 226 | } |
---|
[35] | 227 | |
---|
[41] | 228 | |
---|
[35] | 229 | |
---|
| 230 | if (verbose) { |
---|
| 231 | (void) fprintf(vis_stdout, "The _sat_debug command is under construction.\n"); |
---|
| 232 | } |
---|
[41] | 233 | /* |
---|
| 234 | * Read the network |
---|
| 235 | */ |
---|
| 236 | network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 237 | if (network == NIL(Ntk_Network_t)) { |
---|
| 238 | (void) fprintf(vis_stdout, "** _sat_debug error: No network\n"); |
---|
| 239 | BmcOptionFree(options); |
---|
| 240 | return 1; |
---|
[35] | 241 | } |
---|
[41] | 242 | manager = Ntk_NetworkReadMAigManager(network); |
---|
| 243 | if (manager == NIL(mAig_Manager_t)) { |
---|
| 244 | (void) fprintf(vis_stdout, "** _sat_debug error: run build_partition_maigs command first\n"); |
---|
[35] | 245 | BmcOptionFree(options); |
---|
| 246 | return 1; |
---|
| 247 | } |
---|
| 248 | |
---|
[40] | 249 | Dbg_Abnormal_t * abn = Dbg_NetworkReadAbnormal(network); |
---|
[41] | 250 | if(abn == NIL(Dbg_Abnormal_t)){ |
---|
| 251 | (void) fprintf(vis_stdout, "_sat_debug error: Build Abnormal predicate.\n"); |
---|
| 252 | return 1; |
---|
| 253 | } |
---|
| 254 | if(verbose) |
---|
| 255 | printf("abnormal %d \n",array_n(Dbg_ReadAbn(abn))); |
---|
[38] | 256 | |
---|
| 257 | |
---|
[41] | 258 | formulaArray = Ctlsp_FileParseFormulaArray(options->ltlFile); |
---|
| 259 | if (formulaArray == NIL(array_t)) { |
---|
| 260 | (void) fprintf(vis_stderr, |
---|
| 261 | "** bmc error: error in parsing CTL* Fromula from file\n"); |
---|
| 262 | BmcOptionFree(options); |
---|
| 263 | return 1; |
---|
| 264 | } |
---|
| 265 | if (array_n(formulaArray) == 0) { |
---|
| 266 | (void) fprintf(vis_stderr, "** bmc error: No formula in file\n"); |
---|
| 267 | BmcOptionFree(options); |
---|
[38] | 268 | Ctlsp_FormulaArrayFree(formulaArray); |
---|
[41] | 269 | return 1; |
---|
| 270 | } |
---|
| 271 | LTLformulaArray = Ctlsp_FormulaArrayConvertToLTL(formulaArray); |
---|
| 272 | Ctlsp_FormulaArrayFree(formulaArray); |
---|
| 273 | if (LTLformulaArray == NIL(array_t)){ |
---|
| 274 | (void) fprintf(vis_stdout, "** bmc error: Invalid LTL formula\n"); |
---|
| 275 | BmcOptionFree(options); |
---|
| 276 | return 1; |
---|
| 277 | } |
---|
| 278 | Ctlsp_Formula_t *ltlFormula = array_fetch(Ctlsp_Formula_t *, LTLformulaArray, 0); |
---|
[38] | 279 | |
---|
| 280 | |
---|
[35] | 281 | /* |
---|
| 282 | Compute the cone of influence |
---|
[38] | 283 | here : a list of state variables (latches) |
---|
[41] | 284 | TODO refine to COI of the property |
---|
[35] | 285 | */ |
---|
| 286 | st_table *CoiTable = generateAllLatches(network); |
---|
| 287 | /* |
---|
| 288 | Generate clauses for each time frame. This is the old way of generating |
---|
| 289 | clauses in BMC. |
---|
| 290 | */ |
---|
[41] | 291 | if(verbose) |
---|
[35] | 292 | { |
---|
| 293 | (void) fprintf(vis_stdout, "------ COI ----\n"); |
---|
| 294 | printLatch(CoiTable); |
---|
| 295 | (void) fprintf(vis_stdout, "--------------------------\n"); |
---|
| 296 | } |
---|
[41] | 297 | BmcCnfClauses_t* cnfClauses = Dbg_GenerateCNF(network,options,CoiTable); |
---|
[38] | 298 | |
---|
[41] | 299 | |
---|
[38] | 300 | //Generate ltl CNF |
---|
| 301 | // BmcGenerateCnfForLtl Génére la formule borné et retourne un index |
---|
| 302 | // aprÚs il faut ajouter l'objectif de l'index avec boucle ou pas ... |
---|
| 303 | // cf. BmcLtlVerifyGeneralLtl |
---|
[41] | 304 | Ctlsp_FormulaPrint(vis_stdout, ltlFormula); |
---|
| 305 | fprintf(vis_stdout, "\n"); |
---|
[38] | 306 | int k = options->maxK; |
---|
| 307 | int l; |
---|
| 308 | // return the clause number |
---|
[44] | 309 | int noLoopIndex = BmcGenerateCnfForLtl(network, ltlFormula, 0, k, k, cnfClauses); printf("LTL %d \n",noLoopIndex); |
---|
[38] | 310 | |
---|
[41] | 311 | |
---|
[42] | 312 | array_t *objClause = NIL(array_t); |
---|
[40] | 313 | objClause = array_alloc(int, 0); |
---|
| 314 | array_insert_last(int, objClause, noLoopIndex); |
---|
| 315 | BmcCnfInsertClause(cnfClauses, objClause); |
---|
| 316 | array_free(objClause); |
---|
[38] | 317 | |
---|
[41] | 318 | //Add Abnormal |
---|
| 319 | st_table * nodeToMvfAigTable = NIL(st_table); |
---|
| 320 | nodeToMvfAigTable = |
---|
[42] | 321 | (st_table *) Ntk_NetworkReadApplInfo(network, MVFAIG_NETWORK_APPL_KEY); |
---|
| 322 | assert(nodeToMvfAigTable != NIL(st_table)); |
---|
[38] | 323 | |
---|
[44] | 324 | Dbg_InitAbn(abn,manager, nodeToMvfAigTable,k,cnfClauses); |
---|
[38] | 325 | |
---|
[42] | 326 | //loop abnormal |
---|
[41] | 327 | int aIndex; |
---|
| 328 | Ntk_Node_t * abnNode; |
---|
[42] | 329 | Dbg_ForEachAbnormal(abn,aIndex,abnNode){ |
---|
| 330 | char * nodeName = Ntk_NodeReadName(abnNode); |
---|
[44] | 331 | //set abnormal for each step |
---|
| 332 | array_t * cnfIndexArray = array_fetch(array_t*,abn->abnCnfIndexArray,aIndex); |
---|
| 333 | int cnfIndex; |
---|
| 334 | int step; |
---|
[41] | 335 | bAigEdge_t* abnBAig = array_fetch(bAigEdge_t*,abn->abnAigArray, aIndex); |
---|
[44] | 336 | array_t * cnfVal = array_alloc(int,0); |
---|
| 337 | arrayForEachItem(int, cnfIndexArray, step, cnfIndex){ |
---|
| 338 | int abnIndex = BmcGenerateCnfFormulaForAigFunction(manager,abnBAig[1],step,cnfClauses); |
---|
| 339 | array_insert(int,cnfClauses->clauseArray,cnfIndex,abnIndex); |
---|
| 340 | array_insert_last(int,cnfVal,abnIndex); |
---|
| 341 | FILE *cnfFile = Cmd_FileOpen(options->satInFile, "w", NIL(char *), 0); |
---|
| 342 | BmcWriteClauses(manager, cnfFile, cnfClauses, options); |
---|
| 343 | fclose(cnfFile); |
---|
| 344 | printf("AINDEX %d\n",aIndex); |
---|
| 345 | if(aIndex == 0) |
---|
| 346 | { |
---|
| 347 | FILE *cnfFile = Cmd_FileOpen("test_aks.cnf", "w", NIL(char *), 0); |
---|
| 348 | BmcWriteClauses(manager, cnfFile, cnfClauses, options); |
---|
| 349 | fclose(cnfFile); |
---|
| 350 | |
---|
| 351 | } |
---|
| 352 | }//end for each step |
---|
| 353 | |
---|
[41] | 354 | //SAT procedure |
---|
[42] | 355 | //assig assig input from cex |
---|
| 356 | //TODO build cex correctly |
---|
[44] | 357 | int res = Dbg_SatCheck("assig",options->satInFile,options->verbosityLevel); |
---|
[42] | 358 | // Build set of FaultCandidates |
---|
| 359 | if (res == SAT_SAT) |
---|
| 360 | { |
---|
| 361 | char * realNodeName = util_strsav(nodeName); |
---|
[44] | 362 | realNodeName[strlen(nodeName)-3] = '\0'; |
---|
| 363 | printf("Real = %s\n", realNodeName); |
---|
[42] | 364 | Ntk_Node_t * realNode = Ntk_NetworkFindNodeByName(network,realNodeName); |
---|
| 365 | array_insert_last(Ntk_Node_t*,faultNodes,realNode); |
---|
| 366 | } |
---|
[38] | 367 | |
---|
[44] | 368 | arrayForEachItem(int, cnfIndexArray, step, cnfIndex){ |
---|
| 369 | int abnIndex = array_fetch(int,cnfVal,step); |
---|
| 370 | array_insert(int,cnfClauses->clauseArray,cnfIndex,-abnIndex); |
---|
| 371 | } |
---|
[42] | 372 | } |
---|
| 373 | |
---|
[35] | 374 | if(verbose) |
---|
| 375 | (void) fprintf(vis_stdout, "The _sat_debug generates %d clauses with %d\ |
---|
[100] | 376 | latches \n",cnfClauses->noOfClauses,st_count(CoiTable)); |
---|
[42] | 377 | |
---|
[44] | 378 | |
---|
[42] | 379 | (void) fprintf(vis_stdout,"Number of Fault candidates %d\n", |
---|
| 380 | array_n(faultNodes)); |
---|
| 381 | (void) fprintf(vis_stdout,"gates : \n"); |
---|
[44] | 382 | |
---|
| 383 | |
---|
[42] | 384 | printNodeArray(faultNodes); |
---|
| 385 | |
---|
| 386 | |
---|
[41] | 387 | Ctlsp_FormulaArrayFree(LTLformulaArray); |
---|
[35] | 388 | BmcCnfClausesFree(cnfClauses); |
---|
| 389 | BmcOptionFree(options); |
---|
[42] | 390 | array_free(faultNodes); |
---|
[35] | 391 | return 0; |
---|
[41] | 392 | } |
---|
[44] | 393 | |
---|
[41] | 394 | /**Function******************************************************************** |
---|
| 395 | |
---|
| 396 | Synopsis [Implements the generate_network_cnf.] |
---|
| 397 | |
---|
| 398 | CommandName [generate_network_cnf] |
---|
| 399 | |
---|
| 400 | CommandSynopsis [generate a CNF view of the network] |
---|
| 401 | |
---|
| 402 | CommandArguments [\[-h\] \[-v\] \[-k\] [fileName] ] |
---|
| 403 | |
---|
[98] | 404 | CommandDescription [This command generate a CNF of the network in DMACS form. |
---|
[41] | 405 | The network may be unroll within k steps. |
---|
| 406 | <p> |
---|
| 407 | |
---|
| 408 | Command options:<p> |
---|
| 409 | |
---|
| 410 | <dl> |
---|
| 411 | <dt> -h |
---|
| 412 | <dd> Print the command usage. |
---|
| 413 | </dl> |
---|
| 414 | |
---|
| 415 | <dt> -v |
---|
| 416 | <dd> Verbose mode. |
---|
| 417 | </dl> |
---|
| 418 | |
---|
| 419 | <dt> -k |
---|
| 420 | <dd> number of steps (default 1). |
---|
| 421 | </dl> |
---|
| 422 | ] |
---|
| 423 | |
---|
| 424 | SideEffects [] |
---|
| 425 | |
---|
| 426 | ******************************************************************************/ |
---|
| 427 | |
---|
| 428 | static int CommandGenerateNetworkCNF(Hrc_Manager_t ** hmgr,int argc, char ** argv) |
---|
| 429 | { |
---|
| 430 | BmcOption_t *options = BmcOptionAlloc(); |
---|
| 431 | int c; |
---|
| 432 | unsigned int i; |
---|
| 433 | Ntk_Network_t * network; |
---|
| 434 | bAig_Manager_t * manager; |
---|
| 435 | char * outName = NIL(char); |
---|
| 436 | FILE *cnfFile; |
---|
| 437 | if (!options){ |
---|
| 438 | return 1; |
---|
| 439 | } |
---|
| 440 | options->dbgOut = 0; |
---|
| 441 | /* |
---|
| 442 | * Parse command line options. |
---|
| 443 | */ |
---|
| 444 | util_getopt_reset(); |
---|
| 445 | while ((c = util_getopt(argc, argv, "hv:k:")) != EOF) { |
---|
| 446 | switch(c) { |
---|
| 447 | case 'h': |
---|
| 448 | goto usage; |
---|
| 449 | case 'k': |
---|
| 450 | options->maxK = atoi(util_optarg); |
---|
| 451 | break; |
---|
| 452 | case 'v': |
---|
| 453 | for (i = 0; i < strlen(util_optarg); i++) { |
---|
| 454 | if (!isdigit((int)util_optarg[i])) { |
---|
| 455 | goto usage; |
---|
| 456 | } |
---|
| 457 | } |
---|
| 458 | options->verbosityLevel = (Bmc_VerbosityLevel) atoi(util_optarg); |
---|
| 459 | break; |
---|
| 460 | default: |
---|
| 461 | goto usage; |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | if (argc - util_optind != 0) |
---|
| 465 | { |
---|
[44] | 466 | outName = util_strsav(argv[util_optind]); |
---|
| 467 | /* create SAT Solver input file */ |
---|
[41] | 468 | options->cnfFileName= outName; |
---|
[44] | 469 | options->satInFile = options->cnfFileName; |
---|
| 470 | cnfFile = Cmd_FileOpen(options->satInFile, "w", NIL(char *), 0); |
---|
[41] | 471 | } |
---|
| 472 | |
---|
| 473 | |
---|
| 474 | /* |
---|
| 475 | * Read the network |
---|
| 476 | */ |
---|
| 477 | network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 478 | if (network == NIL(Ntk_Network_t)) { |
---|
| 479 | (void) fprintf(vis_stdout, "** generate_network_cnf error: No network\n"); |
---|
| 480 | BmcOptionFree(options); |
---|
| 481 | return 1; |
---|
| 482 | } |
---|
| 483 | manager = Ntk_NetworkReadMAigManager(network); |
---|
| 484 | if (manager == NIL(mAig_Manager_t)) { |
---|
| 485 | (void) fprintf(vis_stdout, "** generate_network_cnf error: run build_partition_maigs command first\n"); |
---|
| 486 | BmcOptionFree(options); |
---|
| 487 | return 1; |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | /* |
---|
| 491 | Compute the cone of influence |
---|
| 492 | here : a list of state variables (latches) |
---|
| 493 | */ |
---|
| 494 | st_table *CoiTable = generateAllLatches(network); |
---|
| 495 | |
---|
| 496 | if(options->verbosityLevel) |
---|
| 497 | { |
---|
| 498 | (void) fprintf(vis_stdout, "------ COI ----\n"); |
---|
| 499 | printLatch(CoiTable); |
---|
| 500 | (void) fprintf(vis_stdout, "--------------------------\n"); |
---|
| 501 | } |
---|
| 502 | BmcCnfClauses_t* cnfClauses = Dbg_GenerateCNF(network,options,CoiTable); |
---|
| 503 | if(outName != NIL(char)) |
---|
| 504 | { |
---|
| 505 | BmcWriteClauses(manager, cnfFile, cnfClauses, options); |
---|
| 506 | fclose(cnfFile); |
---|
| 507 | } |
---|
| 508 | else |
---|
| 509 | BmcWriteClauses(manager, vis_stdout, cnfClauses, options); |
---|
| 510 | |
---|
| 511 | if(options->verbosityLevel) |
---|
| 512 | { |
---|
| 513 | (void) fprintf(vis_stdout, "CNF generated for %d steps", options->maxK); |
---|
| 514 | (void) fprintf(vis_stdout, " %d clauses with %d latche(s).\n",cnfClauses->noOfClauses, |
---|
| 515 | st_count(CoiTable)); |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | BmcOptionFree(options); |
---|
| 519 | return 0; |
---|
| 520 | usage: |
---|
| 521 | (void) fprintf(vis_stderr, "usage: bmc [-h][-k maximum_length][-v verbosity_level] <cnf_file>\n"); |
---|
| 522 | (void) fprintf(vis_stderr, " -h \tprint the command usage\n"); |
---|
[35] | 523 | (void) fprintf(vis_stderr, " -k \tmaximum length of counterexample to be checked (default is 1)\n"); |
---|
[41] | 524 | (void) fprintf(vis_stderr, " -v <verbosity_level>\n"); |
---|
| 525 | (void) fprintf(vis_stderr, " verbosity_level = 0 => no feedback (Default)\n"); |
---|
| 526 | (void) fprintf(vis_stderr, " verbosity_level = 1 => code status\n"); |
---|
| 527 | (void) fprintf(vis_stderr, " verbosity_level = 2 => code status and CPU usage profile\n"); |
---|
| 528 | (void) fprintf(vis_stderr, " <cnf_file> The output file containing CNF of the network.\n"); |
---|
[35] | 529 | |
---|
[41] | 530 | BmcOptionFree(options); |
---|
| 531 | return 1; |
---|
[35] | 532 | } |
---|
[41] | 533 | |
---|
[35] | 534 | /**Function******************************************************************** |
---|
| 535 | |
---|
[27] | 536 | Synopsis [Implements the _Debug_test command.] |
---|
| 537 | |
---|
| 538 | CommandName [_Debug_test] |
---|
| 539 | |
---|
| 540 | CommandSynopsis [template for implementing commands] |
---|
| 541 | |
---|
| 542 | CommandArguments [\[-h\] \[-v\]] |
---|
| 543 | |
---|
| 544 | CommandDescription [This command does nothing useful. It merely serves as a |
---|
| 545 | template for the implementation of new commands.<p> |
---|
| 546 | |
---|
| 547 | Command options:<p> |
---|
| 548 | |
---|
| 549 | <dl> |
---|
| 550 | <dt> -h |
---|
| 551 | <dd> Print the command usage. |
---|
| 552 | </dl> |
---|
| 553 | |
---|
| 554 | <dt> -v |
---|
| 555 | <dd> Verbose mode. |
---|
| 556 | </dl> |
---|
| 557 | ] |
---|
| 558 | |
---|
| 559 | SideEffects [] |
---|
| 560 | |
---|
| 561 | ******************************************************************************/ |
---|
| 562 | static int |
---|
| 563 | CommandDebug( |
---|
| 564 | Hrc_Manager_t ** hmgr, |
---|
| 565 | int argc, |
---|
| 566 | char ** argv) |
---|
| 567 | { |
---|
| 568 | int c; |
---|
| 569 | int verbose = 0; /* default value */ |
---|
| 570 | |
---|
| 571 | /* |
---|
| 572 | * Parse command line options. |
---|
| 573 | */ |
---|
| 574 | util_getopt_reset(); |
---|
| 575 | while ((c = util_getopt(argc, argv, "vh")) != EOF) { |
---|
| 576 | switch(c) { |
---|
| 577 | case 'v': |
---|
| 578 | verbose = 1; |
---|
| 579 | break; |
---|
| 580 | case 'h': |
---|
| 581 | goto usage; |
---|
| 582 | default: |
---|
| 583 | goto usage; |
---|
| 584 | } |
---|
| 585 | } |
---|
| 586 | |
---|
| 587 | if (verbose) { |
---|
| 588 | (void) fprintf(vis_stdout, "The _Debug_test is under construction.\n"); |
---|
| 589 | } |
---|
| 590 | |
---|
| 591 | Fsm_Fsm_t *fsm = Fsm_HrcManagerReadCurrentFsm(*hmgr); |
---|
| 592 | mdd_manager *mddManager = Fsm_FsmReadMddManager(fsm); |
---|
| 593 | printf("** DEBUG MODE **\n"); |
---|
| 594 | Hrc_Node_t * n = Hrc_ManagerReadRootNode(*hmgr); |
---|
| 595 | printf("model : %s\n", Hrc_NodeReadModelName(n)); |
---|
| 596 | |
---|
| 597 | mdd_t * safe = getSafe(fsm); |
---|
| 598 | mdd_t * forbid = getForbidden(fsm); |
---|
| 599 | mdd_t * reach = getReach(fsm); |
---|
| 600 | |
---|
| 601 | if(safe == NIL(mdd_t)) |
---|
| 602 | { |
---|
| 603 | printf("call command set_safe before\n"); |
---|
| 604 | return 1; |
---|
| 605 | } |
---|
| 606 | if(forbid == NIL(mdd_t)) |
---|
| 607 | { |
---|
| 608 | printf("call command set_forbidden before\n"); |
---|
| 609 | return 1; |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | FILE* oFile; |
---|
| 613 | oFile = Cmd_FileOpen("safe_prop", "w", NIL(char *), 0); |
---|
| 614 | // mdd_FunctionPrintMain(mddManager, safe, "SAFE", oFile); |
---|
| 615 | // mdd_FunctionPrintMain(mddManager, reach, "REACH", oFile); |
---|
| 616 | |
---|
| 617 | mdd_t * EFState = mdd_and(reach,safe,1,1); |
---|
| 618 | // mdd_t * errorState = mdd_and(reach,forbid,1,1); |
---|
| 619 | |
---|
| 620 | mdd_t *mddOne = mdd_one(Fsm_FsmReadMddManager(fsm)); |
---|
| 621 | array_t *careStatesArray = array_alloc(mdd_t *, 0); |
---|
| 622 | array_insert(mdd_t *, careStatesArray, 0,mddOne); |
---|
| 623 | |
---|
| 624 | mdd_t * tmp_EXEFState = Mc_FsmEvaluateEXFormula( fsm, |
---|
| 625 | EFState, |
---|
| 626 | fsm->fairnessInfo.states, |
---|
| 627 | careStatesArray, |
---|
| 628 | 0, |
---|
| 629 | McDcLevelNone_c); |
---|
| 630 | |
---|
| 631 | mdd_t * EXEFState = mdd_and(reach,tmp_EXEFState,1,1); |
---|
| 632 | mdd_FunctionPrintMain(mddManager, EXEFState, "EXEF", oFile); |
---|
| 633 | |
---|
| 634 | tmp_EXEFState = Mc_FsmEvaluateEXFormula( fsm, |
---|
| 635 | EXEFState, |
---|
| 636 | fsm->fairnessInfo.states, |
---|
| 637 | careStatesArray, |
---|
| 638 | 0, |
---|
| 639 | McDcLevelNone_c); |
---|
| 640 | mdd_t * EXEFState2 = mdd_and(reach,tmp_EXEFState,1,1); |
---|
| 641 | mdd_FunctionPrintMain(mddManager, EXEFState2, "EXEF2", oFile); |
---|
| 642 | mdd_t * andState = mdd_xor(EXEFState2,EXEFState); |
---|
| 643 | mdd_FunctionPrintMain(mddManager, andState, "XOR2", oFile); |
---|
| 644 | tmp_EXEFState = Mc_FsmEvaluateEXFormula( fsm, |
---|
| 645 | andState, |
---|
| 646 | fsm->fairnessInfo.states, |
---|
| 647 | careStatesArray, |
---|
| 648 | 0, |
---|
| 649 | McDcLevelNone_c); |
---|
| 650 | EXEFState2 = mdd_and(reach,tmp_EXEFState,1,1); |
---|
| 651 | mdd_FunctionPrintMain(mddManager, EXEFState2, "EXEF2", oFile); |
---|
| 652 | andState = mdd_xor(EXEFState2,andState); |
---|
| 653 | mdd_FunctionPrintMain(mddManager, andState, "XOR", oFile); |
---|
| 654 | tmp_EXEFState = Mc_FsmEvaluateEXFormula( fsm, |
---|
| 655 | andState, |
---|
| 656 | fsm->fairnessInfo.states, |
---|
| 657 | careStatesArray, |
---|
| 658 | 0, |
---|
| 659 | McDcLevelNone_c); |
---|
| 660 | EXEFState2 = mdd_and(reach,tmp_EXEFState,1,1); |
---|
| 661 | mdd_FunctionPrintMain(mddManager, EXEFState2, "EXEF2", oFile); |
---|
| 662 | andState = mdd_xor(EXEFState2,andState); |
---|
| 663 | mdd_FunctionPrintMain(mddManager, andState, "XOR", oFile); |
---|
| 664 | |
---|
| 665 | |
---|
| 666 | |
---|
| 667 | //mdd_FunctionPrintMain(mddManager, errorState, "ERROR", oFile); |
---|
| 668 | //mdd_GetState_Values(mddManager , EFState, stdout); |
---|
| 669 | fclose(oFile); |
---|
| 670 | |
---|
| 671 | |
---|
| 672 | |
---|
| 673 | |
---|
| 674 | |
---|
| 675 | return 0; /* normal exit */ |
---|
| 676 | |
---|
| 677 | usage: |
---|
| 678 | (void) fprintf(vis_stderr, "usage: _Debug_test [-h] [-v]\n"); |
---|
| 679 | (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); |
---|
| 680 | (void) fprintf(vis_stderr, " -v\t\tverbose\n"); |
---|
| 681 | return 1; /* error exit */ |
---|
| 682 | } |
---|
| 683 | |
---|
[30] | 684 | /******************************************/ |
---|
| 685 | /* function that build a bdd for the */ |
---|
| 686 | /* simple example : */ |
---|
| 687 | /* (state = 0) -> !(state = 1) */ |
---|
| 688 | /******************************************/ |
---|
| 689 | mdd_t * buildDummyBdd(mdd_manager *mddManager) |
---|
[27] | 690 | { |
---|
[30] | 691 | /** state0 = 0 **/ |
---|
| 692 | mdd_t * s0 = mdd_eq_c(mddManager,0, 0); |
---|
| 693 | mdd_t * s1 = mdd_eq_c(mddManager,2, 0); |
---|
| 694 | mdd_t * state0 = mdd_one(mddManager); |
---|
| 695 | state0 = mdd_and(s0,s1,1,1); |
---|
| 696 | /** state1 = 1 **/ |
---|
| 697 | mdd_t * ns0 = mdd_eq_c(mddManager,1, 1); |
---|
| 698 | mdd_t * ns1 = mdd_eq_c(mddManager,3, 0); |
---|
| 699 | mdd_t * state1 = mdd_one(mddManager); |
---|
| 700 | state1 = mdd_and(ns0,ns1,1,1); |
---|
| 701 | /** state = 0) -> !(state = 1) **/ |
---|
| 702 | mdd_t * rel = mdd_one(mddManager); |
---|
| 703 | rel = mdd_or(state0,state1,0,0); |
---|
| 704 | |
---|
| 705 | return rel; |
---|
| 706 | } |
---|
[45] | 707 | mdd_t * buildDummy2(mdd_manager * mddManager) |
---|
| 708 | { |
---|
| 709 | mdd_t * rel = NIL(mdd_t); |
---|
| 710 | mdd_t * state0 = mdd_one(mddManager); |
---|
| 711 | mdd_t * state2 = mdd_one(mddManager); |
---|
| 712 | mdd_t * state3 = mdd_one(mddManager); |
---|
| 713 | // state0 = s0 |
---|
| 714 | mdd_t * s0 = mdd_eq_c(mddManager,0, 0); |
---|
| 715 | mdd_t * s1 = mdd_eq_c(mddManager,2, 0); |
---|
| 716 | state0 = mdd_and(s0,s1,1,1); |
---|
| 717 | // state2 = s2 |
---|
| 718 | s0 = mdd_eq_c(mddManager,0, 0); |
---|
| 719 | s1 = mdd_eq_c(mddManager,2, 1); |
---|
| 720 | state2 = mdd_and(s0,s1,1,1); |
---|
| 721 | // state3 = s3 |
---|
| 722 | s0 = mdd_eq_c(mddManager,0, 1); |
---|
| 723 | s1 = mdd_eq_c(mddManager,2, 1); |
---|
| 724 | state3 = mdd_and(s0,s1,1,1); |
---|
| 725 | // Build transition relation |
---|
[27] | 726 | |
---|
[45] | 727 | array_t * mvarVal = array_alloc(int,0); |
---|
| 728 | array_insert_last(int, mvarVal,2); |
---|
| 729 | array_t * val = array_alloc(int,0); |
---|
| 730 | array_t * mvarName = array_alloc(char*,0); |
---|
| 731 | array_insert_last(char*, mvarName,"S1"); |
---|
| 732 | int e1Id = mdd_create_variables(mddManager,mvarVal,mvarName,NIL(array_t)); |
---|
| 733 | array_insert(char*, mvarName,0,"I"); |
---|
| 734 | int e0Id = mdd_create_variables(mddManager,mvarVal,mvarName,NIL(array_t)); |
---|
| 735 | array_insert_last(int, val,1); |
---|
| 736 | mdd_t * e1 = mdd_literal(mddManager, e1Id,val); |
---|
| 737 | mdd_t * e0 = mdd_literal(mddManager, e0Id,val); |
---|
| 738 | mdd_t * tmp2 = mdd_and(e1,e0,0,0); |
---|
| 739 | mdd_t * ne2_1 = mdd_or(e1,tmp2,1,1); |
---|
| 740 | mdd_t * ne2_0 = mdd_and(e1,e0,0,1); |
---|
[27] | 741 | |
---|
[45] | 742 | array_insert(char*, mvarName,0,"Next_SI"); |
---|
| 743 | int id = mdd_create_variables(mddManager,mvarVal,mvarName,NIL(array_t)); |
---|
| 744 | Mvf_Function_t * mvf = Mvf_FunctionAlloc(mddManager, 2); |
---|
| 745 | Mvf_FunctionAddMintermsToComponent(mvf,1,ne2_1); |
---|
| 746 | Mvf_FunctionAddMintermsToComponent(mvf,0,ne2_0); |
---|
| 747 | mdd_t *relation = Mvf_FunctionBuildRelationWithVariable(mvf, id); |
---|
| 748 | |
---|
| 749 | //bdd_print(relation); |
---|
| 750 | mdd_FunctionPrintMain (mddManager ,relation,"news",vis_stdout); |
---|
| 751 | //bdd_ite |
---|
| 752 | return rel; |
---|
| 753 | |
---|
| 754 | } |
---|
| 755 | |
---|
[27] | 756 | /**Function******************************************************************** |
---|
| 757 | |
---|
[30] | 758 | Synopsis [Implements the transtion command.] |
---|
[27] | 759 | |
---|
[30] | 760 | CommandName [_transition] |
---|
[27] | 761 | |
---|
[30] | 762 | CommandSynopsis [compute new transition relation] |
---|
[27] | 763 | |
---|
[30] | 764 | CommandArguments [\[-h\] \[-v\]] |
---|
| 765 | |
---|
| 766 | CommandDescription [This command create a new transition relation that is a |
---|
[45] | 767 | and of the Bdd of the old one and another bdd. |
---|
[30] | 768 | <p> |
---|
[27] | 769 | |
---|
[30] | 770 | Command options:<p> |
---|
[27] | 771 | |
---|
[30] | 772 | <dl> |
---|
| 773 | <dt> -h |
---|
| 774 | <dd> Print the command usage. |
---|
| 775 | </dl> |
---|
[27] | 776 | |
---|
[30] | 777 | <dt> -v |
---|
| 778 | <dd> Verbose mode. |
---|
| 779 | </dl> |
---|
| 780 | ] |
---|
[27] | 781 | |
---|
[30] | 782 | SideEffects [Change the fsm] |
---|
[27] | 783 | |
---|
| 784 | ******************************************************************************/ |
---|
| 785 | |
---|
| 786 | static int |
---|
[30] | 787 | CommandTransition (Hrc_Manager_t ** hmgr, |
---|
[27] | 788 | int argc, char ** argv){ |
---|
[30] | 789 | int c; |
---|
| 790 | int verbose = 0; /* default value */ |
---|
[27] | 791 | |
---|
[30] | 792 | /* |
---|
| 793 | * Parse command line options. |
---|
| 794 | */ |
---|
| 795 | util_getopt_reset(); |
---|
| 796 | while ((c = util_getopt(argc, argv, "vh")) != EOF) { |
---|
| 797 | switch(c) { |
---|
| 798 | case 'v': |
---|
| 799 | verbose = 1; |
---|
| 800 | break; |
---|
| 801 | case 'h': |
---|
| 802 | goto usage; |
---|
| 803 | default: |
---|
| 804 | goto usage; |
---|
[27] | 805 | } |
---|
[30] | 806 | } |
---|
[27] | 807 | |
---|
[30] | 808 | if (verbose) { |
---|
| 809 | (void) fprintf(vis_stdout, "The _transition is under construction.\n"); |
---|
| 810 | } |
---|
[27] | 811 | |
---|
[30] | 812 | Fsm_Fsm_t *fsm = NIL(Fsm_Fsm_t); |
---|
| 813 | Ntk_Network_t *network = NIL(Ntk_Network_t); |
---|
| 814 | mdd_manager *mddManager; |
---|
| 815 | mdd_t *rel = NIL(mdd_t); |
---|
| 816 | graph_t *partition; |
---|
| 817 | int i; |
---|
| 818 | /******************/ |
---|
| 819 | network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 820 | if(network == NIL(Ntk_Network_t)) |
---|
| 821 | return 1; |
---|
| 822 | fsm = Fsm_HrcManagerReadCurrentFsm(*hmgr); |
---|
| 823 | if(fsm == NIL(Fsm_Fsm_t)) |
---|
| 824 | return 1; |
---|
| 825 | mddManager = Fsm_FsmReadMddManager(fsm); |
---|
[27] | 826 | |
---|
| 827 | |
---|
| 828 | |
---|
[30] | 829 | /********** Build cex ***********/ |
---|
| 830 | /* Here add the function */ |
---|
| 831 | /* that build the Bdd to and */ |
---|
| 832 | /* with the transtion relation */ |
---|
| 833 | /***********************************/ |
---|
[96] | 834 | rel = buildDummyBdd(mddManager); |
---|
[30] | 835 | if(rel == NIL(mdd_t)) |
---|
| 836 | { |
---|
[45] | 837 | fprintf(vis_stdout,"Problem when building the new relation bdd\n"); |
---|
[30] | 838 | return 1; |
---|
[27] | 839 | } |
---|
[37] | 840 | if (verbose) |
---|
| 841 | mdd_FunctionPrintMain (mddManager ,rel,"REL",vis_stdout); |
---|
[27] | 842 | |
---|
[37] | 843 | |
---|
[30] | 844 | /** Get image_info **/ |
---|
| 845 | Img_ImageInfo_t * imageInfo = Fsm_FsmReadOrCreateImageInfo(fsm,1,0); |
---|
| 846 | partition = Part_PartitionDuplicate(Fsm_FsmReadPartition(fsm)); |
---|
| 847 | /**** The complete transtion relation ****/ |
---|
| 848 | // array_t * transRelation = Img_GetPartitionedTransitionRelation(imageInfo, 0); |
---|
| 849 | /*****************************************/ |
---|
| 850 | /*** For each latch rebuild the transition function ***/ |
---|
| 851 | /*** mvf table is composed of mdd for each possible ***/ |
---|
| 852 | /*** value of the latch ***/ |
---|
| 853 | ImgFunctionData_t * functionData = &(imageInfo->functionData); |
---|
| 854 | array_t *roots = functionData->roots; |
---|
| 855 | array_t *rangeVarMddIdArray = functionData->rangeVars; |
---|
| 856 | char * nodeName; |
---|
| 857 | arrayForEachItem(char *, roots, i, nodeName) { |
---|
[96] | 858 | |
---|
[30] | 859 | /* The new relation */ |
---|
| 860 | vertex_t *vertex = Part_PartitionFindVertexByName(partition, nodeName); |
---|
| 861 | Mvf_Function_t *mvf = Part_VertexReadFunction(vertex); |
---|
| 862 | int mddId = array_fetch(int, rangeVarMddIdArray, i); |
---|
| 863 | mdd_t *relation = Mvf_FunctionBuildRelationWithVariable(mvf, mddId); |
---|
[96] | 864 | if(verbose){ |
---|
| 865 | int x; |
---|
| 866 | mdd_t * comp; |
---|
[45] | 867 | |
---|
[96] | 868 | Mvf_FunctionForEachComponent( mvf, x, comp){ |
---|
[101] | 869 | printf("%s,%d mdd %d ",nodeName,x,mddId); |
---|
[96] | 870 | mdd_FunctionPrintMain (mddManager ,comp,"MVF",vis_stdout); |
---|
| 871 | } |
---|
| 872 | } |
---|
| 873 | |
---|
[30] | 874 | mdd_t * n_relation = mdd_and(relation,rel,1,1); |
---|
| 875 | /* Build for each possible value */ |
---|
| 876 | int nbValue = Mvf_FunctionReadNumComponents(mvf) ; |
---|
| 877 | int v ; |
---|
| 878 | Mvf_Function_t * newMvf = Mvf_FunctionAlloc(mddManager,nbValue); |
---|
| 879 | for(v = 0; v<nbValue;v++) |
---|
| 880 | { |
---|
| 881 | mdd_t * n_s1 = mdd_eq_c(mddManager,mddId, v); |
---|
| 882 | mdd_t * n_rel_s1 = mdd_and(n_relation,n_s1,1,1); |
---|
| 883 | mdd_t * n_relation_s1 = mdd_cofactor_minterm(n_rel_s1,n_s1); |
---|
| 884 | Mvf_FunctionAddMintermsToComponent(newMvf,v,n_relation_s1); |
---|
[27] | 885 | |
---|
[45] | 886 | |
---|
[30] | 887 | } |
---|
| 888 | /* Replace the function for the latch */ |
---|
| 889 | Part_VertexSetFunction(vertex, newMvf); |
---|
| 890 | // printf("vertex %s changed % d\n",PartVertexReadName(vertex)); |
---|
[27] | 891 | } |
---|
| 892 | |
---|
[37] | 893 | /** Change the fsm and the network with a new partition and the new fsm **/ |
---|
| 894 | Ntk_NetworkSetApplInfo(network, PART_NETWORK_APPL_KEY, |
---|
| 895 | (Ntk_ApplInfoFreeFn) Part_PartitionFreeCallback, |
---|
| 896 | (void *) partition); |
---|
| 897 | fsm = Fsm_FsmCreateFromNetworkWithPartition(network, NIL(graph_t)); |
---|
[30] | 898 | mdd_t * init = Fsm_FsmComputeInitialStates(fsm); |
---|
[37] | 899 | mdd_t * reach = Fsm_FsmComputeReachableStates(fsm,0,verbose, |
---|
[30] | 900 | 0,0, 0, |
---|
| 901 | 0, 0, Fsm_Rch_Default_c, |
---|
| 902 | 0,1, NIL(array_t), |
---|
| 903 | (verbose > 0), NIL(array_t)); |
---|
[37] | 904 | fsm->reachabilityInfo.initialStates = init; |
---|
| 905 | fsm->reachabilityInfo.reachableStates = reach; |
---|
[30] | 906 | if(verbose) |
---|
| 907 | Fsm_FsmReachabilityPrintResults(fsm,3, 0); |
---|
[27] | 908 | |
---|
[37] | 909 | Ntk_NetworkSetApplInfo(network, FSM_NETWORK_APPL_KEY, |
---|
| 910 | (Ntk_ApplInfoFreeFn) Fsm_FsmFreeCallback, |
---|
| 911 | (void *) fsm); |
---|
[27] | 912 | |
---|
[30] | 913 | return 0; /* normal exit */ |
---|
[27] | 914 | |
---|
[30] | 915 | usage: |
---|
[96] | 916 | (void) fprintf(vis_stderr, "usage: _transition [-h] [-v]\n"); |
---|
[30] | 917 | (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); |
---|
| 918 | (void) fprintf(vis_stderr, " -v\t\tverbose\n"); |
---|
| 919 | return 1; /* error exit */ |
---|
[27] | 920 | |
---|
| 921 | } |
---|
| 922 | |
---|
[45] | 923 | static int |
---|
| 924 | CommandBuildCexBdd(Hrc_Manager_t ** hmgr, |
---|
| 925 | int argc, char ** argv){ |
---|
| 926 | int c; |
---|
| 927 | int verbose = 0; /* default value */ |
---|
[27] | 928 | |
---|
[45] | 929 | /* |
---|
| 930 | * Parse command line options. |
---|
| 931 | */ |
---|
| 932 | util_getopt_reset(); |
---|
| 933 | while ((c = util_getopt(argc, argv, "vh")) != EOF) { |
---|
| 934 | switch(c) { |
---|
| 935 | case 'v': |
---|
| 936 | verbose = 1; |
---|
| 937 | break; |
---|
| 938 | case 'h': |
---|
| 939 | goto usage; |
---|
| 940 | default: |
---|
| 941 | goto usage; |
---|
| 942 | } |
---|
| 943 | } |
---|
| 944 | |
---|
| 945 | if (verbose) { |
---|
| 946 | (void) fprintf(vis_stdout, "The _cexBdd is under construction.\n"); |
---|
| 947 | } |
---|
| 948 | |
---|
| 949 | Fsm_Fsm_t *fsm = NIL(Fsm_Fsm_t); |
---|
| 950 | Ntk_Network_t *network = NIL(Ntk_Network_t); |
---|
| 951 | mdd_manager *mddManager; |
---|
[98] | 952 | Hrc_Manager_t *hmgrCex = NIL(Hrc_Manager_t); |
---|
| 953 | Fsm_Fsm_t *fsmCex = NIL(Fsm_Fsm_t); |
---|
| 954 | Ntk_Network_t *networkCex = NIL(Ntk_Network_t); |
---|
| 955 | mdd_t *rel = NIL(mdd_t); |
---|
[45] | 956 | int i; |
---|
| 957 | /******************/ |
---|
| 958 | network = Ntk_HrcManagerReadCurrentNetwork(*hmgr); |
---|
| 959 | if(network == NIL(Ntk_Network_t)) |
---|
| 960 | return 1; |
---|
| 961 | fsm = Fsm_HrcManagerReadCurrentFsm(*hmgr); |
---|
| 962 | if(fsm == NIL(Fsm_Fsm_t)) |
---|
| 963 | return 1; |
---|
| 964 | mddManager = Fsm_FsmReadMddManager(fsm); |
---|
| 965 | |
---|
[98] | 966 | mdd_t * initOrig = Fsm_FsmComputeInitialStates(fsm); |
---|
| 967 | mdd_FunctionPrintMain (mddManager ,initOrig,"INIT_ORG",vis_stdout); |
---|
[45] | 968 | |
---|
| 969 | /********** Build cex ***********/ |
---|
| 970 | /* Here add the function */ |
---|
| 971 | /* that build the Bdd to and */ |
---|
| 972 | /* with the transtion relation */ |
---|
| 973 | /***********************************/ |
---|
| 974 | //rel = buildDummyBdd(mddManager); |
---|
[98] | 975 | graph_t * part = Part_PartitionDuplicate(Fsm_FsmReadPartition(fsm)); |
---|
[100] | 976 | vertex_t * v_s2 = Part_PartitionFindVertexByName(part, "cex.s2"); |
---|
[98] | 977 | Mvf_Function_t * newMvf = Mvf_FunctionAlloc( mddManager,2); |
---|
| 978 | mdd_t * s0 = mdd_eq_c(mddManager,20, 0); |
---|
| 979 | mdd_t * s1 = mdd_eq_c(mddManager,22, 0); |
---|
[45] | 980 | mdd_t * state0 = mdd_one(mddManager); |
---|
[98] | 981 | mdd_t * state1 = mdd_one(mddManager); |
---|
[45] | 982 | state0 = mdd_and(s0,s1,1,1); |
---|
[100] | 983 | mdd_t * state12 = mdd_and(s0,s1,0,1); |
---|
[98] | 984 | state1 = mdd_not(state0); |
---|
| 985 | array_insert(mdd_t *, newMvf, 1, state0); |
---|
| 986 | array_insert(mdd_t *, newMvf, 0, state1); |
---|
[100] | 987 | mdd_t * ns1 = mdd_eq_c(mddManager,17, 1); |
---|
| 988 | Mvf_Function_t * newNS = Mvf_FunctionAlloc( mddManager,2); |
---|
| 989 | Mvf_FunctionAddMintermsToComponent(newNS,1, mdd_and(state0,ns1,1,1)); |
---|
| 990 | Mvf_FunctionAddMintermsToComponent(newNS,0, mdd_and(state1,ns1,1,0)); |
---|
[45] | 991 | |
---|
[100] | 992 | mdd_FunctionPrintMain(mddManager,Mvf_FunctionComputeDomain(newNS),"NS",vis_stdout); |
---|
| 993 | vertex_t * vert; |
---|
| 994 | vert = Part_PartitionFindVertexByName(part,"cex.s2"); |
---|
| 995 | Part_VertexSetFunction(vert, newNS); |
---|
[45] | 996 | |
---|
[100] | 997 | vert = Part_PartitionFindVertexByName(part,"cex.s3"); |
---|
| 998 | mdd_t * ns1S3 = mdd_eq_c(mddManager,14, 1); |
---|
| 999 | Mvf_Function_t * newS3 = Mvf_FunctionAlloc( mddManager,2); |
---|
| 1000 | Mvf_FunctionAddMintermsToComponent(newS3,1, mdd_and(state12,ns1S3,1,1)); |
---|
| 1001 | Mvf_FunctionAddMintermsToComponent(newS3,0, mdd_and(state12,ns1S3,0,0)); |
---|
| 1002 | Part_VertexSetFunction(vert, newS3); |
---|
[45] | 1003 | |
---|
[100] | 1004 | // Initial state |
---|
| 1005 | mdd_t * ns1Init = mdd_eq_c(mddManager,3, 1); |
---|
[45] | 1006 | |
---|
[100] | 1007 | Mvf_Function_t * newNSInit = Mvf_FunctionAlloc(mddManager,2); |
---|
| 1008 | Mvf_FunctionAddMintermsToComponent(newNSInit,1, mdd_and(state0,ns1Init,1,1)); |
---|
| 1009 | Mvf_FunctionAddMintermsToComponent(newNSInit,0, mdd_and(state1,ns1Init,1,0)); |
---|
| 1010 | mdd_FunctionPrintMain(mddManager,Mvf_FunctionComputeDomain(newNSInit),"NSINIT",vis_stdout); |
---|
| 1011 | Part_VertexSetFunction(Part_PartitionFindVertexByName(part,"cex.s2$INIT"), |
---|
| 1012 | newNSInit); |
---|
[45] | 1013 | |
---|
[98] | 1014 | |
---|
| 1015 | |
---|
| 1016 | |
---|
| 1017 | /** Change the fsm and the network with a new partition and the new fsm **/ |
---|
| 1018 | Ntk_NetworkSetApplInfo(network, PART_NETWORK_APPL_KEY, |
---|
| 1019 | (Ntk_ApplInfoFreeFn) Part_PartitionFreeCallback, |
---|
| 1020 | (void *) part); |
---|
[100] | 1021 | fsm = Fsm_FsmCreateFromNetworkWithPartition(network, part); |
---|
| 1022 | |
---|
| 1023 | |
---|
[98] | 1024 | mdd_t * init = Fsm_FsmComputeInitialStates(fsm); |
---|
| 1025 | //mdd_t * n_init = Mvf_MddComposeWithFunction(init, 17 , newMvf); |
---|
| 1026 | mdd_t * reach = Fsm_FsmComputeReachableStates(fsm,0,verbose, |
---|
| 1027 | 0,0, 0, |
---|
| 1028 | 0, 0, Fsm_Rch_Default_c, |
---|
| 1029 | 0,1, NIL(array_t), |
---|
| 1030 | (verbose > 0), NIL(array_t)); |
---|
[100] | 1031 | fsm->reachabilityInfo.initialStates = init; |
---|
| 1032 | fsm->reachabilityInfo.reachableStates = reach; |
---|
| 1033 | |
---|
| 1034 | |
---|
[98] | 1035 | |
---|
| 1036 | Ntk_NetworkSetApplInfo(network, FSM_NETWORK_APPL_KEY, |
---|
| 1037 | (Ntk_ApplInfoFreeFn) Fsm_FsmFreeCallback, |
---|
| 1038 | (void *) fsm); |
---|
| 1039 | |
---|
[100] | 1040 | Img_ImageInfoUpdateVariables(fsm->imageInfo, |
---|
| 1041 | fsm->partition, |
---|
| 1042 | fsm->fsmData.presentStateVars, |
---|
| 1043 | fsm->fsmData.inputVars, |
---|
| 1044 | fsm->fsmData.presentStateCube, |
---|
| 1045 | fsm->fsmData.inputCube); |
---|
[98] | 1046 | Fsm_FsmReachabilityPrintResults(fsm,3, 0); |
---|
| 1047 | // |
---|
| 1048 | // |
---|
| 1049 | mdd_FunctionPrintMain (mddManager ,init,"INIT",vis_stdout); |
---|
| 1050 | |
---|
[104] | 1051 | return 0; /* normal exit */ |
---|
| 1052 | |
---|
| 1053 | usage: |
---|
| 1054 | (void) fprintf(vis_stderr, "usage: _BddCex [-h] [-v]\n"); |
---|
| 1055 | (void) fprintf(vis_stderr, " -h\t\tprint the command usage\n"); |
---|
| 1056 | (void) fprintf(vis_stderr, " -v\t\tverbose\n"); |
---|
| 1057 | return 1; /* error exit */ |
---|
| 1058 | |
---|
| 1059 | } |
---|
| 1060 | |
---|
| 1061 | |
---|
| 1062 | static int CommandComposeWithCex(Hrc_Manager_t ** hmgr,int argc, char ** argv) |
---|
| 1063 | { |
---|
| 1064 | |
---|
| 1065 | char * cexName; |
---|
| 1066 | char * cexModelName; |
---|
| 1067 | char * rootName; |
---|
| 1068 | char * newName; |
---|
| 1069 | FILE * cexFile; |
---|
| 1070 | Hrc_Node_t * rootNode; |
---|
| 1071 | Hrc_Node_t * cexNode; |
---|
| 1072 | Hrc_Model_t * rootModel; |
---|
| 1073 | Hrc_Model_t * cexModel; |
---|
| 1074 | Hrc_Model_t * newModel; |
---|
| 1075 | Hrc_Manager_t * hmgrCex; |
---|
| 1076 | // Ntk_Network_t * networkCex; |
---|
| 1077 | array_t *cexActualInputArray, *cexActualOutputArray; |
---|
| 1078 | array_t *actualInputArray, *actualOutputArray; |
---|
| 1079 | |
---|
| 1080 | rootNode = Hrc_ManagerReadRootNode(*hmgr); |
---|
| 1081 | if(rootNode == NIL(Hrc_Node_t)){ |
---|
| 1082 | printf("Please build the network first\n"); |
---|
| 1083 | return 1; |
---|
| 1084 | } |
---|
| 1085 | rootName = Hrc_NodeReadModelName(rootNode); |
---|
| 1086 | rootModel = Hrc_ManagerFindModelByName(*hmgr,rootName); |
---|
| 1087 | if (argc - util_optind > 0) |
---|
| 1088 | { |
---|
| 1089 | cexName = util_strsav(argv[util_optind]); |
---|
| 1090 | cexFile = Cmd_FileOpen(cexName, "r", NIL(char *), 0); |
---|
| 1091 | if(cexFile == NULL) |
---|
| 1092 | (void) fprintf(vis_stderr, "%s not Found\n",cexName); |
---|
| 1093 | |
---|
| 1094 | } |
---|
| 1095 | else |
---|
| 1096 | goto usage; |
---|
| 1097 | |
---|
| 1098 | |
---|
| 1099 | |
---|
| 1100 | // Read_blif_mv |
---|
| 1101 | hmgrCex = Io_BlifMvRead(cexFile,hmgrCex,0,0,0); |
---|
| 1102 | if(hmgrCex == NIL(Hrc_Manager_t)){ |
---|
| 1103 | fprintf(vis_stderr, "cannot open the hierrachy %\n",cexName); |
---|
| 1104 | return 1; |
---|
| 1105 | } |
---|
| 1106 | st_table * modelTable = Hrc_ManagerReadModelTable(hmgrCex); |
---|
| 1107 | if( st_count(modelTable) != 1){ |
---|
| 1108 | fprintf(vis_stderr, "cannot open more than one cex model\n"); |
---|
| 1109 | return 1; |
---|
| 1110 | } |
---|
| 1111 | st_generator * gen; |
---|
| 1112 | Hrc_ManagerForEachModel( hmgrCex,gen,cexModelName,cexModel){} |
---|
| 1113 | fprintf(vis_stderr, "Compose %s with %s\n",rootName, cexModelName); |
---|
| 1114 | |
---|
| 1115 | cexNode = Hrc_ManagerReadRootNode(hmgrCex); |
---|
| 1116 | actualInputArray = array_dup(Hrc_NodeReadFormalInputs(rootNode)); |
---|
| 1117 | actualOutputArray = array_dup(Hrc_NodeReadFormalOutputs(rootNode)); |
---|
| 1118 | Hrc_ModelAddSubckt(rootModel,cexModel,cexModelName,actualInputArray, actualOutputArray); |
---|
| 1119 | |
---|
| 1120 | |
---|
| 1121 | |
---|
| 1122 | |
---|
| 1123 | |
---|
| 1124 | |
---|
| 1125 | |
---|
[98] | 1126 | /* |
---|
[104] | 1127 | modelName = Hrc_NodeReadModelName(rootNode); |
---|
| 1128 | newRootName = ALLOC(char, strlen(cexName)+ strlen(modelName) + 2); |
---|
| 1129 | sprintf(newRootName,"%s_%s",modelName,cexName); |
---|
| 1130 | Hrc_Model_t * newRootModel = Hrc_ModelAlloc(*hmgr,rootName); |
---|
| 1131 | */ |
---|
| 1132 | |
---|
| 1133 | fclose(cexFile); |
---|
| 1134 | return 0; /* normal exit */ |
---|
| 1135 | |
---|
| 1136 | usage: |
---|
| 1137 | (void) fprintf(vis_stderr, "usage: _compose <cexFileName>\n"); |
---|
| 1138 | return 1; /* error exit */ |
---|
| 1139 | |
---|
| 1140 | |
---|
| 1141 | /* |
---|
[98] | 1142 | // Read_blif_mv |
---|
| 1143 | FILE *fpC; |
---|
| 1144 | fpC = Cmd_FileOpen("cex.mv", "r", NIL(char *), 1); |
---|
| 1145 | boolean isCanonicalC = 0; |
---|
| 1146 | boolean isIncrementalC = 0; |
---|
| 1147 | boolean isVerboseC = 0; |
---|
| 1148 | hmgrCex = Io_BlifMvRead(fpC,hmgrCex,isCanonicalC,isIncrementalC,isVerboseC); |
---|
| 1149 | |
---|
| 1150 | //flatten_hier |
---|
| 1151 | lsList varNameList = (lsList) NULL; |
---|
| 1152 | Hrc_Node_t *currentNode = Hrc_ManagerReadCurrentNode(hmgrCex); |
---|
| 1153 | networkCex = Ntk_HrcNodeConvertToNetwork(currentNode, TRUE, varNameList); |
---|
| 1154 | Ntk_NetworkSetMddManager(networkCex, mddManager); |
---|
| 1155 | //static_order |
---|
| 1156 | static Ord_NodeMethod nodeMethod = Ord_NodesByDefault_c;; |
---|
| 1157 | static Ord_RootMethod rootMethod = Ord_RootsByDefault_c; |
---|
| 1158 | static Ord_OrderType suppliedOrderType = Ord_Unassigned_c; |
---|
| 1159 | static Ord_OrderType generatedOrderType = Ord_InputAndLatch_c; |
---|
| 1160 | static boolean nsAfterSupport = FALSE; |
---|
| 1161 | lsList suppliedNodeList = (lsList) NULL; |
---|
| 1162 | |
---|
| 1163 | Ord_NetworkOrderVariables(networkCex, rootMethod, nodeMethod, nsAfterSupport, |
---|
| 1164 | generatedOrderType, suppliedOrderType, |
---|
| 1165 | suppliedNodeList, isVerboseC); |
---|
| 1166 | //build_partition_mdd |
---|
| 1167 | char * modelName = Hrc_NodeReadModelName(currentNode); |
---|
| 1168 | static Part_PartitionMethod method = Part_Default_c; |
---|
| 1169 | graph_t *partition; |
---|
| 1170 | lsList nodeList = lsCreate(); |
---|
| 1171 | boolean inTermsOfLeaves = FALSE; |
---|
| 1172 | partition = Part_NetworkCreatePartition(networkCex, currentNode, modelName, (lsList)0, |
---|
| 1173 | (lsList)0, NIL(mdd_t), method, nodeList, |
---|
| 1174 | inTermsOfLeaves, isVerboseC, 0); |
---|
| 1175 | // PartPartitionPrint(vis_stdout, partition); |
---|
| 1176 | printf(" Cex loaded \n"); |
---|
| 1177 | fsmCex = Fsm_FsmCreateFromNetworkWithPartition(networkCex, partition); |
---|
| 1178 | array_t * nextNamesCex = Fsm_FsmReadNextStateFunctionNames(fsmCex); |
---|
| 1179 | array_t * nextIdsCex = Fsm_FsmReadNextStateVars(fsmCex); |
---|
| 1180 | printf("Next Names\n"); |
---|
| 1181 | printStringArray(nextNamesCex); |
---|
| 1182 | printf("Next Ids\n"); |
---|
| 1183 | printIntArray(nextIdsCex); |
---|
| 1184 | |
---|
| 1185 | mddManager = Fsm_FsmReadMddManager(fsm); |
---|
| 1186 | mdd_manager * mddManagerCex = Fsm_FsmReadMddManager(fsmCex); |
---|
| 1187 | |
---|
| 1188 | array_t *mvar_list, *bvar_list; |
---|
| 1189 | mvar_list = mdd_ret_mvar_list(mddManager); |
---|
| 1190 | bvar_list = mdd_ret_bvar_list(mddManager); |
---|
| 1191 | printf("Number of mdd %d , %d\n", array_n(mvar_list),array_n(bvar_list)); |
---|
| 1192 | printf("mddManager = %p mddMangerCex %p \n",mddManager,mddManagerCex); |
---|
| 1193 | //mdd_t * init = Fsm_FsmComputeInitialStates(fsmCex); |
---|
| 1194 | // mdd_FunctionPrintMain (mddManagerCex ,init,"REL",vis_stdout); |
---|
| 1195 | graph_t * part = Fsm_FsmReadPartition(fsm); |
---|
| 1196 | printf(" modele %s , cex %s \n",Part_PartitionReadName(part), Part_PartitionReadName(partition)); |
---|
| 1197 | */ |
---|
[45] | 1198 | |
---|
[104] | 1199 | |
---|
[45] | 1200 | } |
---|