VIS

src/truesim/truesimSim.c

Go to the documentation of this file.
00001 
00017 #include "truesimInt.h"
00018 
00019 /*---------------------------------------------------------------------------*/
00020 /* Constant declarations                                                     */
00021 /*---------------------------------------------------------------------------*/
00022 
00023 
00024 /*---------------------------------------------------------------------------*/
00025 /* Type declarations                                                         */
00026 /*---------------------------------------------------------------------------*/
00027 
00028 
00029 /*---------------------------------------------------------------------------*/
00030 /* Structure declarations                                                    */
00031 /*---------------------------------------------------------------------------*/
00032 
00033 
00034 /*---------------------------------------------------------------------------*/
00035 /* Variable declarations                                                     */
00036 /*---------------------------------------------------------------------------*/
00037 
00038 /* Global variable from truesimCmd.c. */
00039 extern int truesimRptHeader;
00040 extern int truesimVerbose;
00041 
00044 /*---------------------------------------------------------------------------*/
00045 /* Static function prototypes                                                */
00046 /*---------------------------------------------------------------------------*/
00047 
00048 
00052 /*---------------------------------------------------------------------------*/
00053 /* Definition of exported functions                                          */
00054 /*---------------------------------------------------------------------------*/
00055 
00056 
00057 /*---------------------------------------------------------------------------*/
00058 /* Definition of internal functions                                          */
00059 /*---------------------------------------------------------------------------*/
00078 int
00079 TruesimSimulateNetwork(
00080   Ntk_Network_t *network,
00081   char *simFile,
00082   char *probFile,
00083   char *delayFile,
00084   char *dumpFile,
00085   boolean trueDelay,
00086   int genVectors,
00087   int N)
00088 {
00089   array_t *inputArray,*patternArray;
00090   int i,status;
00091   char *str;
00092   
00093   /* inputArray stores the names of primary input nodes and patternArray stores
00094      the simulation vectors as char strings. One could use bit packing, but
00095      this is fast and simple. */
00096   inputArray = array_alloc(Ntk_Node_t *,0);
00097   patternArray = array_alloc(char *,0);
00098 
00099   if (genVectors == 0) { /* Read simulation file */
00100     Truesim_ReadSimulationVectors(network,simFile,inputArray,patternArray);
00101   } else { /* Generate random vectors */
00102     array_t *probArray;
00103     int numInputs;
00104     
00105     probArray = array_alloc(float,0);
00106     Truesim_ReadInputProbabilities(network,probFile,inputArray,probArray);
00107 
00108     if(array_n(probArray) == 0) {
00109       array_free(inputArray);
00110       array_free(patternArray);
00111       array_free(probArray);
00112       return 0;
00113     }
00114     numInputs = array_n(inputArray);
00115     Truesim_GenerateRandomVectors(network,probArray,patternArray,
00116                                   numInputs,N);
00117     array_free(probArray);
00118 
00119     /* Output pattern vectors */
00120     if (dumpFile) {
00121       Truesim_DumpSimulationVectors(network,inputArray,patternArray,dumpFile);
00122     }
00123   }
00124 
00125   /* Initialize the simulation data structures */
00126   Truesim_InitializeSimulation(network,delayFile,trueDelay,truesimRptHeader,
00127                                truesimVerbose,NIL(st_table));
00128 
00129   /* Now perform true delay simulation or zero delay simulation
00130      according to 'trueDelay' */  
00131   if (trueDelay) { /* Perform event driven simulation */
00132     status = Truesim_RealDelayPatternSimulate(network,inputArray,patternArray);
00133   } else { /* Perform zero-delay simulation */
00134     status = Truesim_ZeroDelayPatternSimulate(network,inputArray,patternArray);
00135   }
00136 
00137   /* End the simulation */
00138   Truesim_QuitSimulation(network);
00139 
00140   /* Free the space used to store the input nodes */
00141   array_free(inputArray);
00142   /* Free the pattern vectors */
00143   arrayForEachItem(char *, patternArray,i,str) {
00144     FREE(str);
00145   }
00146   array_free(patternArray);
00147 
00148   return status;
00149 
00150 } /* End of TruesimSimulateNetwork */
00151 
00152 /*---------------------------------------------------------------------------*/
00153 /* Definition of static functions                                            */
00154 /*---------------------------------------------------------------------------*/
00155