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

Last change on this file since 40 was 40, checked in by cecile, 12 years ago

abnormal structure in network

File size: 8.3 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 Ntk_NetworkAddApplInfo(ntk, DBG_NETWORK_APPL_KEY,
117 (Ntk_ApplInfoFreeFn) Dbg_AbnormalFreeCallback,
118 (void *) abnormal);
119}
120/**Function********************************************************************
121 
122  Synopsis    [Allocate a new abnormal structure]
123
124  Description [The structure contains the network with abnormal predicate,
125  and two sets of Ntk_Node_t for the abnormal and the free inputs]
126
127  SideEffects [Allocate the abnormal structure]
128
129  SeeAlso     []
130
131******************************************************************************/
132
133Dbg_Abnormal_t * Dbg_DebugAbnormalAlloc(Ntk_Network_t * network)
134{
135         Dbg_Abnormal_t * abn = ALLOC(Dbg_Abnormal_t, 1);
136
137         abn->network = network;
138         abn->abnormal = array_alloc(Ntk_Node_t*,0);
139         abn->freeInputs = array_alloc(Ntk_Node_t*,0);
140         abn->verbose = 0;
141         return abn;
142}       
143
144/**Function********************************************************************
145 
146  Synopsis    [Deallocate a new abnormal structure]
147
148  Description [Free the arrays not the network]
149
150  SideEffects [free the abnormal structure]
151
152  SeeAlso     []
153
154******************************************************************************/
155
156void  Dbg_DebugAbnormalFree(Dbg_Abnormal_t * abn)
157{
158         array_free(abn->abnormal);
159         array_free(abn->freeInputs);
160         FREE(abn);
161}       
162/**Function********************************************************************
163
164  Synopsis    [Call-back function to free an abnormal structure.]
165
166  Description [This function will be stored in the network together with the
167  pointer to the structure. Whenever the network deletes the partitioning
168  information, this function is called and it will deallocate the abnormal and
169  the information attached to it.]
170
171  SideEffects []
172
173  SeeAlso     [Ntk_NetworkAddApplInfo]
174
175******************************************************************************/
176void
177Dbg_AbnormalFreeCallback(
178   void *data)
179{
180  Dbg_DebugAbnormalFree((Dbg_Abnormal_t *) data);
181} /* End of Part_PartitionFreeCallback */
182
183
184/**Function********************************************************************
185 
186  Synopsis    [Add abnormal predicate]
187
188  Description [add a node to the predicates array, it should not be already
189  present by construction of abnormal predicate]
190
191  SideEffects []
192
193  SeeAlso     []
194
195******************************************************************************/
196
197void  Dbg_AddAbnormalPredicate(Dbg_Abnormal_t * abn, Ntk_Node_t* abnNode)
198{
199        assert(abnNode != NIL(Ntk_Node_t*));
200        array_insert_last(Ntk_Node_t*,abn->abnormal, abnNode);
201}
202/**Function********************************************************************
203 
204  Synopsis    [Add free inputs]
205
206  Description [add a node to the free inputs, it should not be already
207  present by construction of abnormal predicate]
208
209  SideEffects []
210
211  SeeAlso     []
212
213******************************************************************************/
214void  Dbg_AddFreeInput(Dbg_Abnormal_t * abn, Ntk_Node_t* fNode)
215{
216        assert(fNode != NIL(Ntk_Node_t*));
217        array_insert_last(Ntk_Node_t*,abn->freeInputs, fNode);
218}
219
220/**Function********************************************************************
221 
222  Synopsis    [returns a free inputs]
223
224  Description [returns the array of freeinputs]
225
226  SideEffects []
227
228  SeeAlso     [Dbg_ReadAbn]
229
230******************************************************************************/
231array_t* Dbg_ReadFreeInputs(Dbg_Abnormal_t *abnormal)
232{
233        assert(abnormal != NIL(Dbg_Abnormal_t));
234        return abnormal->freeInputs;
235}
236/**Function********************************************************************
237 
238  Synopsis    [returns a abnormal predicates]
239
240  Description [returns the array of abnormal predicates]
241
242  SideEffects []
243
244  SeeAlso     [Dbg_ReadFreeInputs]
245
246******************************************************************************/
247array_t* Dbg_ReadAbn(Dbg_Abnormal_t *abnormal)
248{
249        assert(abnormal != NIL(Dbg_Abnormal_t));
250        return abnormal->abnormal;
251}
252/**Function********************************************************************
253 
254  Synopsis    [returns the abnormal structure]
255
256  Description [returns the abnormal structure associated to the network]
257
258  SideEffects []
259
260  SeeAlso     []
261
262******************************************************************************/
263Dbg_Abnormal_t * Dbg_NetworkReadAbnormal(Ntk_Network_t * network)
264{
265        Dbg_Abnormal_t * abn = (Dbg_Abnormal_t *) Ntk_NetworkReadApplInfo(network, DBG_NETWORK_APPL_KEY);
266
267        return abn;
268}
Note: See TracBrowser for help on using the repository browser.