source: vis_dev/vis-2.3/src/debug/debugUtilities.c @ 41

Last change on this file since 41 was 41, checked in by cecile, 13 years ago

new command generate cnf from network

File size: 4.5 KB
Line 
1#include "debug.h"
2void printLatch(st_table* CoiTable)
3{
4// COI contents
5   printf("*** COI ***\n");
6   st_generator    *stGen;
7   Ntk_Node_t * latch;
8   st_foreach_item(CoiTable, stGen, &latch, NULL) {
9        printf("%s\n",Ntk_NodeReadName(latch)); 
10  }
11}
12
13
14st_table * generateAllLatches(Ntk_Network_t * ntk)
15{
16    st_table        *CoiTable = st_init_table(st_ptrcmp, st_ptrhash);
17        lsGen           gen ;
18        Ntk_Node_t              *node;
19
20        Ntk_NetworkForEachNode(ntk,gen, node){
21                if (Ntk_NodeTestIsLatch(node)){
22                        st_insert(CoiTable, (char *) node, Ntk_NodeReadName(node));
23                }
24        }
25        return CoiTable;
26
27}
28
29
30void mdd_GetState_Values(
31mdd_manager *mgr ,
32mdd_t *  top, 
33FILE  * f) 
34{
35  mdd_t * T;
36  mdd_t * E;
37  int    id;
38  array_t * val = array_alloc(int, 4); 
39  static int level;
40  char c = ' ' ;
41
42  level++;
43
44  id = bdd_top_var_id(top);
45
46  mvar_type mv = 
47array_fetch(mvar_type, mdd_ret_mvar_list((mgr)),(id));
48 // fprintf(f,"(");
49
50  // Pour le Then
51  T=bdd_then(top);
52 
53 //variable belongs to what we are looking for
54// if(strstr(mv.name,var_name) !=NULL)
55  if(bdd_is_tautology(T,1)){
56    //array_insert(type, array, position, object)
57    fprintf(f,"%s = 1 ",mv.name);
58    //c = '+';
59  } else
60    if(!bdd_is_tautology(T,0)){
61      fprintf(f,"%s = 1 * ",mv.name);
62      //mdd_FunctionPrint(mgr, T,f);
63     // c = '+';
64    }
65
66  mdd_free(T);
67 
68  //pour le Else
69  E=bdd_else(top);
70  if(bdd_is_tautology(E,0)){
71    goto fin;
72  }
73 
74  if(bdd_is_tautology(E,1)){
75    fprintf(f,"%c %s = 0",c, mv.name);
76    goto fin;
77  }
78 
79  fprintf(f,"%c %s = 0 * ",c, mv.name);
80  /*
81  mdd_FunctionPrint(mgr, E,f);
82  mdd_free(E);
83*/
84 fin:
85  fprintf(f,")");
86  level--;
87  return;
88}
89/**Function********************************************************************
90 
91  Synopsis    [Performs the sat call]
92
93  Description [Retrun the result of SAT call, avec positionnement des options]
94  SideEffects []
95
96  SeeAlso     []
97
98******************************************************************************/
99
100int Dbg_SatCheck(char * forceAssigName, char * cnfFileName
101)
102{
103 satManager_t *cm;
104 cm = sat_InitManager(0);
105 cm->comment = ALLOC(char, 2);
106 cm->comment[0] = ' ';
107 cm->comment[1] = '\0';
108 cm->stdOut = stdout;
109 cm->stdErr = stderr;
110
111 
112  satOption_t  *satOption;
113  array_t      *result = NIL(array_t);
114  int          maxSize;
115
116  satOption = sat_InitOption();
117  satOption->verbose = 2;
118  //satOption->unsatCoreFileName = "Ucore.txt";
119  satOption->clauseDeletionHeuristic = 0;
120  //satOption->coreGeneration = 1 ;
121  //satOption->minimizeConflictClause = 1;
122  if(forceAssigName != NULL)
123    satOption->forcedAssignArr = sat_ReadForcedAssignment(forceAssigName);
124   cm->option = satOption;
125   cm->each = sat_InitStatistics();
126
127  cm->unitLits = sat_ArrayAlloc(16);
128  cm->pureLits = sat_ArrayAlloc(16);
129
130  maxSize = 1024 << 8;
131  cm->nodesArray = ALLOC(long, maxSize);
132  cm->maxNodesArraySize = maxSize;
133  cm->nodesArraySize = satNodeSize;
134
135  sat_AllocLiteralsDB(cm);
136
137   sat_ReadCNF(cm,cnfFileName);
138   sat_Main(cm);
139
140   if(cm->status == SAT_UNSAT) {
141    if(cm->option->forcedAssignArr)
142      fprintf(cm->stdOut, "%s UNSAT under given assignment\n",
143              cm->comment);
144    fprintf(cm->stdOut, "%s UNSATISFIABLE\n", cm->comment);
145    fflush(cm->stdOut);
146    sat_ReportStatistics(cm, cm->each);
147    sat_FreeManager(cm);
148  }
149  else if(cm->status == SAT_SAT) {
150    fprintf(cm->stdOut, "%s SATISFIABLE\n", cm->comment);
151    fflush(cm->stdOut);
152    sat_PrintSatisfyingAssignment(cm);
153    sat_ReportStatistics(cm, cm->each);
154    sat_FreeManager(cm);
155  }
156return cm->status;
157}
158/**Function********************************************************************
159 
160  Synopsis    [Generate a CNF of the network]
161
162  Description [Generate the set of clauses of the unroll network for a given
163  length and for a given cone of influence]
164  SideEffects []
165
166  SeeAlso     []
167
168******************************************************************************/
169BmcCnfClauses_t*
170Dbg_GenerateCNF(Ntk_Network_t * network, 
171BmcOption_t * options,
172st_table  *CoiTable
173){
174st_table          *nodeToMvfAigTable = NIL(st_table);  /* node to mvfAig */
175BmcCnfClauses_t   *cnfClauses = NIL(BmcCnfClauses_t);
176/*
177 *nodeToMvfAigTable maps each node to its multi-function And/Inv graph
178 */
179nodeToMvfAigTable =
180(st_table *) Ntk_NetworkReadApplInfo(network, MVFAIG_NETWORK_APPL_KEY);
181assert(nodeToMvfAigTable != NIL(st_table));
182/*
183 * Create a clause database
184 */
185cnfClauses = BmcCnfClausesAlloc();
186/*
187 * Generate clauses for an initialized path of length k
188 */
189BmcCnfGenerateClausesForPath(network, 0, options->maxK, BMC_INITIAL_STATES,
190                         cnfClauses, nodeToMvfAigTable, CoiTable);
191return cnfClauses;
192
193}
Note: See TracBrowser for help on using the repository browser.