source: vis_dev/vis-2.3/src/debug/debugAbnormal.c @ 39

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

Add Abnormal predicate structures

File size: 7.0 KB
Line 
1#include "debugInt.h"
2/**Function********************************************************************
3 
4  Synopsis    [create New node]
5
6  Description [Create new primary input in the current network at a given
7  output node.  Return the variable created]
8
9  SideEffects [Modify the network]
10
11  SeeAlso     []
12
13******************************************************************************/
14Ntk_Node_t * Dbg_CreateNewNode(Ntk_Network_t * ntk,Ntk_Node_t*
15node, char * varName  )
16{
17        array_t * fanin = array_dup(Ntk_NodeReadFanins(node));
18        array_t * fanout = array_alloc(Ntk_Node_t*,0);
19        char * nodeName = util_strsav(Ntk_NodeReadName(node));
20        //Create var Name
21        char * newVarName = (char *) malloc(strlen(nodeName) + strlen(varName) +1);
22        sprintf(newVarName,"%s_%s",nodeName,varName);
23        Var_Variable_t * var = Var_VariableAlloc(NIL(Hrc_Node_t),newVarName);
24        //Create new Node
25        Ntk_Node_t * newNode = Ntk_NodeCreateInNetwork(ntk, newVarName,var);
26        Ntk_NodeDeclareAsPrimaryInput(newNode);
27        //Add in the fanin of the node
28    array_insert_last(Ntk_Node_t*,fanin,newNode);
29        Ntk_NodeSetFanins(node,fanin);
30        //Add Fanout to the newNode
31    array_insert_last(Ntk_Node_t*,fanout,node);
32        Ntk_NodeSetFanouts(newNode,fanout);
33        free(newVarName);
34
35        return newNode;
36
37}
38/**Function********************************************************************
39 
40  Synopsis    [Add abnormal predicates to the network]
41
42  Description [Given a network after flatten the hierarchy,
43  change the table of each combinatorial node
44  with a new table including the abnormal predicate.
45  For a combinatorial node n is tranformed into (abn_n)?i_n:n
46  If the abnormal predicate is activ then n is replaced by a free input]
47
48  SideEffects [fill the abnormal structure]
49
50  SeeAlso     []
51
52******************************************************************************/
53
54void Dbg_AddAbnormalPredicatetoNetwork(Dbg_Abnormal_t* abnormal ) /*abnormal struct*/
55{
56
57  Ntk_Network_t * ntk = abnormal->network;
58  lsGen gen;
59  Ntk_Node_t* node;
60  Ntk_NetworkForEachNode(ntk,gen,node){
61  //For each combinatorial node
62  if(Ntk_NodeTestIsCombinational(node)){
63        if(Ntk_NodeReadNumFanins(node) > 1 && Ntk_NodeReadNumFanouts(node)> 0)
64        {
65                char * nodeName = util_strsav(Ntk_NodeReadName(node));
66        printf("%s \n",  nodeName); 
67
68                Tbl_Table_t    *table =  Ntk_NodeReadTable(node);
69                (void) fprintf(vis_stdout, "** old table\n");
70                Tbl_TableWriteBlifMvToFile(table,2,vis_stdout);
71                // Build new variables abnormal  and  input
72                Ntk_Node_t * abnNode = Dbg_CreateNewNode(ntk,node,"abn");
73                Ntk_Node_t * iNode   = Dbg_CreateNewNode(ntk,node,"i");
74                Dbg_AddFreeInput(abnormal,iNode);
75                Dbg_AddAbnormalPredicate(abnormal,abnNode);
76                Var_Variable_t * abn = Ntk_NodeReadVariable(abnNode);
77                Var_Variable_t * i   = Ntk_NodeReadVariable(iNode);
78                //Add in the table
79                Tbl_TableAddColumn(table,abn,0);
80                int abnIndex = Tbl_TableReadVarIndex(table, abn, 0);
81                Tbl_TableAddColumn(table,i,0);
82                int iIndex = Tbl_TableReadVarIndex(table, i, 0);
83
84                //For each row already there in the table
85                int rowNum;
86                for(rowNum = 0; rowNum <  Tbl_TableReadNumRows(table);rowNum++){
87                        Tbl_Entry_t *abnEntry = Tbl_EntryAlloc(Tbl_EntryNormal_c);
88                        Tbl_EntrySetValue(abnEntry,0,0);
89                        Tbl_TableSetEntry(table, abnEntry, rowNum, abnIndex, 0);
90                        Tbl_Entry_t *iEntry = Tbl_EntryAlloc(Tbl_EntryNormal_c);
91                        Tbl_EntrySetValue(iEntry,0,1);
92                        Tbl_TableSetEntry(table, iEntry, rowNum, iIndex, 0);
93                }
94                //the new row
95                int r = Tbl_TableAddRow(table);
96
97                int colNum;
98            for (colNum = 0; colNum < Tbl_TableReadNumInputs(table); colNum++) {
99                        Tbl_Entry_t * entry = Tbl_EntryAlloc(Tbl_EntryNormal_c);
100                        if(colNum == abnIndex || colNum == iIndex)
101                                Tbl_EntrySetValue(entry,1,1);
102                        else
103                                Tbl_EntrySetValue(entry,0,1);
104                    Tbl_TableSetEntry(table, entry, r, colNum, 0);
105                }
106                for (colNum = 0; colNum < Tbl_TableReadNumOutputs(table); colNum++){
107                        Tbl_Entry_t * entry = Tbl_EntryAlloc(Tbl_EntryNormal_c);
108                        Tbl_EntrySetValue(entry,1,1);
109                    Tbl_TableSetEntry(table, entry, r, colNum, 1);
110                }
111                 printf("---------------\n");
112                 Tbl_TableWriteBlifMvToFile(table,0,vis_stdout);
113          }
114        }
115}
116}
117/**Function********************************************************************
118 
119  Synopsis    [Allocate a new abnormal structure]
120
121  Description [The structure contains the network with abnormal predicate,
122  and two sets of Ntk_Node_t for the abnormal and the free inputs]
123
124  SideEffects [Allocate the abnormal structure]
125
126  SeeAlso     []
127
128******************************************************************************/
129
130Dbg_Abnormal_t * Dbg_DebugAbnormalAlloc(Ntk_Network_t * network)
131{
132         Dbg_Abnormal_t * abn = ALLOC(Dbg_Abnormal_t, 1);
133
134         abn->network = network;
135         abn->abnormal = array_alloc(Ntk_Node_t*,0);
136         abn->freeInputs = array_alloc(Ntk_Node_t*,0);
137         abn->verbose = 0;
138         return abn;
139}       
140
141/**Function********************************************************************
142 
143  Synopsis    [Deallocate a new abnormal structure]
144
145  Description [Free the arrays not the network]
146
147  SideEffects [free the abnormal structure]
148
149  SeeAlso     []
150
151******************************************************************************/
152
153void  Dbg_DebugAbnormalFree(Dbg_Abnormal_t * abn)
154{
155         array_free(abn->abnormal);
156         array_free(abn->freeInputs);
157         FREE(abn);
158}       
159
160
161/**Function********************************************************************
162 
163  Synopsis    [Add abnormal predicate]
164
165  Description [add a node to the predicates array, it should not be already
166  present by construction of abnormal predicate]
167
168  SideEffects []
169
170  SeeAlso     []
171
172******************************************************************************/
173
174void  Dbg_AddAbnormalPredicate(Dbg_Abnormal_t * abn, Ntk_Node_t* abnNode)
175{
176        assert(abnNode != NIL(Ntk_Node_t*));
177        array_insert_last(Ntk_Node_t*,abn->abnormal, abnNode);
178}
179/**Function********************************************************************
180 
181  Synopsis    [Add free inputs]
182
183  Description [add a node to the free inputs, it should not be already
184  present by construction of abnormal predicate]
185
186  SideEffects []
187
188  SeeAlso     []
189
190******************************************************************************/
191void  Dbg_AddFreeInput(Dbg_Abnormal_t * abn, Ntk_Node_t* fNode)
192{
193        assert(fNode != NIL(Ntk_Node_t*));
194        array_insert_last(Ntk_Node_t*,abn->freeInputs, fNode);
195}
196
197/**Function********************************************************************
198 
199  Synopsis    [returns a free inputs]
200
201  Description [returns the array of freeinputs]
202
203  SideEffects []
204
205  SeeAlso     [Dbg_ReadAbn]
206
207******************************************************************************/
208array_t* Dbg_ReadFreeInputs(Dbg_Abnormal_t *abnormal)
209{
210        assert(abnormal != NIL(Dbg_Abnormal_t));
211        return abnormal->freeInputs;
212}
213/**Function********************************************************************
214 
215  Synopsis    [returns a abnormal predicates]
216
217  Description [returns the array of abnormal predicates]
218
219  SideEffects []
220
221  SeeAlso     [Dbg_ReadFreeInputs]
222
223******************************************************************************/
224array_t* Dbg_ReadAbn(Dbg_Abnormal_t *abnormal)
225{
226        assert(abnormal != NIL(Dbg_Abnormal_t));
227        return abnormal->abnormal;
228}
229
Note: See TracBrowser for help on using the repository browser.