#include "debugInt.h" /**Function******************************************************************** Synopsis [create New node] Description [Create new primary input in the current network at a given output node. Return the variable created] SideEffects [Modify the network] SeeAlso [] ******************************************************************************/ Ntk_Node_t * Dbg_CreateNewNode(Ntk_Network_t * ntk,Ntk_Node_t* node, char * varName ) { array_t * fanin = array_dup(Ntk_NodeReadFanins(node)); array_t * fanout = array_alloc(Ntk_Node_t*,0); char * nodeName = util_strsav(Ntk_NodeReadName(node)); //Create var Name char * newVarName = (char *) malloc(strlen(nodeName) + strlen(varName) +1); sprintf(newVarName,"%s_%s",nodeName,varName); Var_Variable_t * var = Var_VariableAlloc(NIL(Hrc_Node_t),newVarName); //Create new Node Ntk_Node_t * newNode = Ntk_NodeCreateInNetwork(ntk, newVarName,var); Ntk_NodeDeclareAsPrimaryInput(newNode); //Add in the fanin of the node array_insert_last(Ntk_Node_t*,fanin,newNode); Ntk_NodeSetFanins(node,fanin); //Add Fanout to the newNode array_insert_last(Ntk_Node_t*,fanout,node); Ntk_NodeSetFanouts(newNode,fanout); free(newVarName); return newNode; } /**Function******************************************************************** Synopsis [Add abnormal predicates to the network] Description [Given a network after flatten the hierarchy, change the table of each combinatorial node with a new table including the abnormal predicate. For a combinatorial node n is tranformed into (abn_n)?i_n:n If the abnormal predicate is activ then n is replaced by a free input] SideEffects [fill the abnormal structure] SeeAlso [] ******************************************************************************/ void Dbg_AddAbnormalPredicatetoNetwork(Dbg_Abnormal_t* abnormal ) /*abnormal struct*/ { Ntk_Network_t * ntk = abnormal->network; lsGen gen; Ntk_Node_t* node; Ntk_NetworkForEachNode(ntk,gen,node){ //For each combinatorial node if(Ntk_NodeTestIsCombinational(node)){ if(Ntk_NodeReadNumFanins(node) > 1 && Ntk_NodeReadNumFanouts(node)> 0) { char * nodeName = util_strsav(Ntk_NodeReadName(node)); printf("%s \n", nodeName); Tbl_Table_t *table = Ntk_NodeReadTable(node); (void) fprintf(vis_stdout, "** old table\n"); Tbl_TableWriteBlifMvToFile(table,2,vis_stdout); // Build new variables abnormal and input Ntk_Node_t * abnNode = Dbg_CreateNewNode(ntk,node,"abn"); Ntk_Node_t * iNode = Dbg_CreateNewNode(ntk,node,"i"); Dbg_AddFreeInput(abnormal,iNode); Dbg_AddAbnormalPredicate(abnormal,abnNode); Var_Variable_t * abn = Ntk_NodeReadVariable(abnNode); Var_Variable_t * i = Ntk_NodeReadVariable(iNode); //Add in the table Tbl_TableAddColumn(table,abn,0); int abnIndex = Tbl_TableReadVarIndex(table, abn, 0); Tbl_TableAddColumn(table,i,0); int iIndex = Tbl_TableReadVarIndex(table, i, 0); //For each row already there in the table int rowNum; for(rowNum = 0; rowNum < Tbl_TableReadNumRows(table);rowNum++){ Tbl_Entry_t *abnEntry = Tbl_EntryAlloc(Tbl_EntryNormal_c); Tbl_EntrySetValue(abnEntry,0,0); Tbl_TableSetEntry(table, abnEntry, rowNum, abnIndex, 0); Tbl_Entry_t *iEntry = Tbl_EntryAlloc(Tbl_EntryNormal_c); Tbl_EntrySetValue(iEntry,0,1); Tbl_TableSetEntry(table, iEntry, rowNum, iIndex, 0); } //the new row int r = Tbl_TableAddRow(table); int colNum; for (colNum = 0; colNum < Tbl_TableReadNumInputs(table); colNum++) { Tbl_Entry_t * entry = Tbl_EntryAlloc(Tbl_EntryNormal_c); if(colNum == abnIndex || colNum == iIndex) Tbl_EntrySetValue(entry,1,1); else Tbl_EntrySetValue(entry,0,1); Tbl_TableSetEntry(table, entry, r, colNum, 0); } for (colNum = 0; colNum < Tbl_TableReadNumOutputs(table); colNum++){ Tbl_Entry_t * entry = Tbl_EntryAlloc(Tbl_EntryNormal_c); Tbl_EntrySetValue(entry,1,1); Tbl_TableSetEntry(table, entry, r, colNum, 1); } printf("---------------\n"); Tbl_TableWriteBlifMvToFile(table,0,vis_stdout); } } } } /**Function******************************************************************** Synopsis [Allocate a new abnormal structure] Description [The structure contains the network with abnormal predicate, and two sets of Ntk_Node_t for the abnormal and the free inputs] SideEffects [Allocate the abnormal structure] SeeAlso [] ******************************************************************************/ Dbg_Abnormal_t * Dbg_DebugAbnormalAlloc(Ntk_Network_t * network) { Dbg_Abnormal_t * abn = ALLOC(Dbg_Abnormal_t, 1); abn->network = network; abn->abnormal = array_alloc(Ntk_Node_t*,0); abn->freeInputs = array_alloc(Ntk_Node_t*,0); abn->verbose = 0; return abn; } /**Function******************************************************************** Synopsis [Deallocate a new abnormal structure] Description [Free the arrays not the network] SideEffects [free the abnormal structure] SeeAlso [] ******************************************************************************/ void Dbg_DebugAbnormalFree(Dbg_Abnormal_t * abn) { array_free(abn->abnormal); array_free(abn->freeInputs); FREE(abn); } /**Function******************************************************************** Synopsis [Add abnormal predicate] Description [add a node to the predicates array, it should not be already present by construction of abnormal predicate] SideEffects [] SeeAlso [] ******************************************************************************/ void Dbg_AddAbnormalPredicate(Dbg_Abnormal_t * abn, Ntk_Node_t* abnNode) { assert(abnNode != NIL(Ntk_Node_t*)); array_insert_last(Ntk_Node_t*,abn->abnormal, abnNode); } /**Function******************************************************************** Synopsis [Add free inputs] Description [add a node to the free inputs, it should not be already present by construction of abnormal predicate] SideEffects [] SeeAlso [] ******************************************************************************/ void Dbg_AddFreeInput(Dbg_Abnormal_t * abn, Ntk_Node_t* fNode) { assert(fNode != NIL(Ntk_Node_t*)); array_insert_last(Ntk_Node_t*,abn->freeInputs, fNode); } /**Function******************************************************************** Synopsis [returns a free inputs] Description [returns the array of freeinputs] SideEffects [] SeeAlso [Dbg_ReadAbn] ******************************************************************************/ array_t* Dbg_ReadFreeInputs(Dbg_Abnormal_t *abnormal) { assert(abnormal != NIL(Dbg_Abnormal_t)); return abnormal->freeInputs; } /**Function******************************************************************** Synopsis [returns a abnormal predicates] Description [returns the array of abnormal predicates] SideEffects [] SeeAlso [Dbg_ReadFreeInputs] ******************************************************************************/ array_t* Dbg_ReadAbn(Dbg_Abnormal_t *abnormal) { assert(abnormal != NIL(Dbg_Abnormal_t)); return abnormal->abnormal; }