VIS
|
00001 00031 #include "simInt.h" 00032 00033 static char rcsid[] UNUSED = "$Id: simIo.c,v 1.5 2005/05/10 15:50:43 hhkim Exp $"; 00034 00035 /*---------------------------------------------------------------------------*/ 00036 /* Constant declarations */ 00037 /*---------------------------------------------------------------------------*/ 00038 00039 /* 00040 * Maximum permissible length of a line in the simulation file. 00041 */ 00042 #define MAX_LINE_LENGTH 500000 00043 00044 00047 /*---------------------------------------------------------------------------*/ 00048 /* Static function prototypes */ 00049 /*---------------------------------------------------------------------------*/ 00050 00051 static array_t * SimObtainInputsArray(Sim_Sim_t * sim); 00052 static void FreeArrays(array_t *array1, array_t *array2, array_t *array3, array_t *array4); 00053 static array_t * BufferBuildInputsNodeArray(char * buffer, Ntk_Network_t * network); 00054 static array_t * BufferBuildLatchesNodeArray(char * buffer, Ntk_Network_t * network); 00055 static array_t * BufferBuildOutputsNodeArray(char * buffer, Ntk_Network_t * network); 00056 static array_t * BufferBuildValuesArray(char * buffer, array_t * nodesArray); 00057 static void SimAddVector(Sim_Sim_t * sim, array_t * vector); 00058 static void BufferSkipWhiteSpace(char * buffer, int * position); 00059 static char * BufferObtainStringAtPosition(char * buffer, int * position); 00060 static void PrintValue(array_t *nodesArray, array_t *vector, int vectorIndex, int strSize, FILE *file); 00061 00065 /*---------------------------------------------------------------------------*/ 00066 /* Definition of exported functions */ 00067 /*---------------------------------------------------------------------------*/ 00068 00085 void 00086 Sim_SimPrint( 00087 Sim_Sim_t * sim, 00088 FILE * of, 00089 boolean printMode, 00090 int printInputsFlag, 00091 int printOutputsFlag, 00092 int printPseudoInputsFlag, 00093 int printStatesFlag 00094 ) 00095 00096 { 00097 int i, j; 00098 char *str; 00099 array_t *vector = NIL(array_t); 00100 array_t *formatArray; 00101 Ntk_Node_t *node; 00102 Var_Variable_t *var; 00103 int index; 00104 int strSize = 0; 00105 int numNodes = array_n(sim->nodesArray); 00106 int inputWidth = sim->currentStateHead; 00107 00108 if(sim->verbose) { 00109 (void) printf("Printing %d vectors...\n", array_n(sim->vectorArray)); 00110 } 00111 00112 formatArray = SimSimInitDataFormat(sim); 00113 00114 if (printMode) { 00115 (void) fprintf(of, "# %s\n", Vm_VisReadVersion()); 00116 (void) fprintf(of, "# Network: %s\n", Ntk_NetworkReadName(sim->network)); 00117 00118 if (sim->inputFile != NIL(char)) { 00119 (void) fprintf(of, "# Input Vectors File: %s\n", sim->inputFile); 00120 } 00121 else { 00122 (void) fprintf(of, "# Simulation vectors have been randomly generated\n"); 00123 } 00124 (void) fprintf(of, "\n\n"); 00125 (void) fprintf(of, ".inputs "); 00126 for (i = 0; i < inputWidth; i++) { 00127 node = array_fetch(Ntk_Node_t *, sim->nodesArray, i); 00128 (void) fprintf(of, "%s ", Ntk_NodeReadName(node)); 00129 } 00130 (void) fprintf(of, "\n"); 00131 (void) fprintf(of, ".latches "); 00132 for (i = sim->currentStateHead; i < sim->internalPartitionHead; i++) { 00133 node = array_fetch(Ntk_Node_t *, sim->nodesArray, i); 00134 (void) fprintf(of, "%s ", Ntk_NodeReadName(node)); 00135 } 00136 (void) fprintf(of, "\n"); 00137 00138 (void) fprintf(of, ".outputs "); 00139 for (i = sim->outputHead; i < numNodes; i++) { 00140 node = array_fetch(Ntk_Node_t *, sim->nodesArray, i); 00141 (void) fprintf(of, "%s ", Ntk_NodeReadName(node)); 00142 } 00143 (void) fprintf(of, "\n"); 00144 00145 /* Reset State is the current state of the first vector */ 00146 (void) fprintf(of, ".initial "); 00147 vector = array_fetch(array_t *, sim->vectorArray, 0); 00148 for (i = sim->currentStateHead; i < sim->internalPartitionHead; i++) { 00149 if(i >= array_n(vector)) {/* If currentState is not specified '*' is printed */ 00150 (void) fprintf(of, "* "); 00151 } 00152 else { 00153 node = array_fetch(Ntk_Node_t *, sim->nodesArray, i); 00154 var = Ntk_NodeReadVariable(node); 00155 index = array_fetch(int, vector, i); 00156 if (Var_VariableTestIsSymbolic(var)) { 00157 (void) fprintf(of, "%s ", Var_VariableReadSymbolicValueFromIndex(var, index)); 00158 } 00159 else { /* Binary or enumerative type */ 00160 str = SimInteger2ASCII(index); 00161 (void) fprintf(of, "%s ", str); 00162 FREE(str); 00163 } 00164 } 00165 } 00166 00167 (void) fprintf(of, "\n\n.start_vectors"); 00168 00169 (void) fprintf(of, "\n\n"); 00170 00171 /* 00172 * Print the order of variables for which values 00173 * are printed in the next lines. 00174 */ 00175 00176 (void) fprintf(of, "# "); 00177 /* 00178 * If either printInputsFlag or printPseudoInputsFlag is zero, we 00179 * cannot use the output as the input for simulation. Print a 00180 * warning message regarding that. 00181 */ 00182 if ((printInputsFlag == 0) || (printPseudoInputsFlag == 0)){ 00183 (void) fprintf(vis_stderr,"Warning - print flag of some inputs is set to zero.\n"); 00184 (void) fprintf(vis_stderr,"Hence the output file you specified cannot be used as an input\n"); 00185 (void) fprintf(vis_stderr,"file for a subsequent simulation run.\n"); 00186 } 00187 00188 if (printInputsFlag || printPseudoInputsFlag){ 00189 for (i = 0; i < inputWidth; i++) { 00190 node = array_fetch(Ntk_Node_t *, sim->nodesArray, i); 00191 if (Ntk_NodeTestIsPrimaryInput(node)){ 00192 if (printInputsFlag){ 00193 (void) fprintf(of, "%s ", Ntk_NodeReadName(node)); 00194 } 00195 } 00196 else{ 00197 if (printPseudoInputsFlag){ 00198 (void) fprintf(of, "%s ", Ntk_NodeReadName(node)); 00199 } 00200 } 00201 } 00202 (void) fprintf(of, "; "); 00203 } 00204 00205 if (printStatesFlag) { 00206 for (i = sim->currentStateHead; i < sim->internalPartitionHead; i++) { 00207 node = array_fetch(Ntk_Node_t *, sim->nodesArray, i); 00208 (void) fprintf(of, "%s ", Ntk_NodeReadName(node)); 00209 } 00210 (void) fprintf(of, "; "); 00211 } 00212 if (printOutputsFlag){ 00213 for (i = sim->outputHead; i < numNodes; i++) { 00214 node = array_fetch(Ntk_Node_t *, sim->nodesArray, i); 00215 (void) fprintf(of, "%s ", Ntk_NodeReadName(node)); 00216 } 00217 (void) fprintf(of, "\n\n"); 00218 } 00219 } 00220 00221 for (i = 0; i < array_n(sim->vectorArray); i++) { 00222 vector = array_fetch(array_t *, sim->vectorArray, i); 00223 if ((printInputsFlag) || (printPseudoInputsFlag)){ 00224 for (j = 0; j < sim->currentStateHead; j++) { 00225 strSize = array_fetch(int, formatArray, j); 00226 node = array_fetch(Ntk_Node_t *, sim->nodesArray, j); 00227 if (Ntk_NodeTestIsPrimaryInput(node)){ 00228 if(printInputsFlag){ 00229 PrintValue(sim->nodesArray, vector, j, strSize, of); 00230 } 00231 } 00232 else { 00233 if (printPseudoInputsFlag){ 00234 PrintValue(sim->nodesArray, vector, j, strSize, of); 00235 } 00236 } 00237 } 00238 } 00239 if (printStatesFlag){ 00240 (void) fprintf(of,"; "); 00241 for (j = sim->currentStateHead; j < sim->internalPartitionHead; j++){ 00242 strSize = array_fetch(int, formatArray, j); 00243 node = array_fetch(Ntk_Node_t *, sim->nodesArray, j); 00244 PrintValue(sim->nodesArray, vector, j, strSize, of); 00245 } 00246 } 00247 if (printOutputsFlag){ 00248 (void) fprintf(of,"; "); 00249 for (j = sim->outputHead; j < numNodes; j++){ 00250 strSize = array_fetch(int, formatArray, j); 00251 node = array_fetch(Ntk_Node_t *, sim->nodesArray, j); 00252 PrintValue(sim->nodesArray, vector, j, strSize, of); 00253 } 00254 } 00255 (void) fprintf(of, "\n"); 00256 } 00257 if (printStatesFlag){ 00258 /* 00259 * Need to print the final state on a separate line. 00260 */ 00261 (void) fprintf(of,"# Final State : "); 00262 for (j = sim->currentStateHead; j < sim->internalPartitionHead; j++){ 00263 strSize = array_fetch(int, formatArray, j); 00264 node = array_fetch(Ntk_Node_t *, sim->nodesArray, j); 00265 PrintValue(sim->nodesArray, vector, j, strSize, of); 00266 } 00267 (void) fprintf(of, "\n"); 00268 } 00269 array_free(formatArray); 00270 } 00271 00272 00273 00295 Sim_Sim_t * 00296 Sim_FileParseDeclaration( 00297 Ntk_Network_t * network, 00298 FILE * fp, 00299 char * inputFile, 00300 boolean verbose) 00301 { 00302 int i; 00303 Ntk_Node_t *node; 00304 char buffer[MAX_LINE_LENGTH]; 00305 char *buffer2; 00306 int currentStateHead; 00307 int internalPartitionHead; 00308 int nextStateHead; 00309 int outputHead; 00310 st_table *nodeToMvfTable; 00311 array_t *nodesArray; 00312 int lineNumber = 0; 00313 array_t *inputsArray = NIL(array_t); 00314 array_t *latchesArray = NIL(array_t); 00315 array_t *internalPartitionArray = NIL(array_t); 00316 array_t *outputsArray = NIL(array_t); 00317 array_t *initState = NIL(array_t); 00318 Sim_Sim_t *sim = NIL(Sim_Sim_t); 00319 graph_t *partition; 00320 vertex_t *vertex; 00321 array_t *dfsarray; 00322 00323 internalPartitionArray = array_alloc(Ntk_Node_t *, 0); 00324 00325 /* Add internal partition nodes */ 00326 partition = Part_NetworkReadPartition(network); 00327 dfsarray = g_dfs(partition); 00328 for(i=0; i< array_n(dfsarray); i++){ 00329 vertex = array_fetch(vertex_t *, dfsarray, i); 00330 node = Ntk_NetworkFindNodeByName(network, Part_VertexReadName(vertex)); 00331 if(!(Ntk_NodeTestIsCombInput(node) || Ntk_NodeTestIsCombOutput(node))){ 00332 array_insert_last(Ntk_Node_t *, internalPartitionArray, node); 00333 } 00334 } 00335 array_free(dfsarray); 00336 00337 while (fgets(buffer, MAX_LINE_LENGTH -1, fp) != NULL) { 00338 int position = 0; 00339 lineNumber++; 00340 00341 /* Every line must end by '\n' */ 00342 if (buffer[strlen(buffer) -1] != '\n') { 00343 SimAppendErrorMsg("Simulate: Line ", 00344 SimInteger2ASCII(lineNumber), "istoolong!\n"); 00345 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00346 return(sim); 00347 } 00348 00349 00350 /* Eliminate spaces */ 00351 BufferSkipWhiteSpace(buffer, &position); 00352 /* buffer2 will contain buffer without space in the begining */ 00353 buffer2 = buffer + position; 00354 /* Avoid comment and empty lines */ 00355 if (buffer[position] != '#' && buffer[position] != '\n') { 00356 if (!strncmp(buffer2, ".inputs", 7)) { 00357 inputsArray = BufferBuildInputsNodeArray(buffer2 + 7, network); 00358 if (inputsArray == NIL(array_t)) { 00359 SimAppendErrorMsg("Simulate: Error line ", 00360 SimInteger2ASCII(lineNumber), ".\n"); 00361 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00362 return(sim); 00363 } 00364 } 00365 else if (!strncmp(buffer2, ".latches", 8)) { 00366 latchesArray = BufferBuildLatchesNodeArray(buffer2 + 8, network); 00367 if (latchesArray == NIL(array_t)) { 00368 SimAppendErrorMsg("Simulate: Error line ", 00369 SimInteger2ASCII(lineNumber), ".\n"); 00370 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00371 return(sim); 00372 } 00373 } 00374 else if (!strncmp(buffer2, ".outputs", 8)) { 00375 outputsArray = BufferBuildOutputsNodeArray(buffer2 + 8, network); 00376 if (outputsArray == NIL(array_t)) { 00377 SimAppendErrorMsg("Simulate: Error line ", SimInteger2ASCII(lineNumber), 00378 ".\n"); 00379 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00380 return(sim); 00381 } 00382 } 00383 else if (!strncmp(buffer2, ".initial", 8)) { 00384 /* Error if latches are not already read before initial-state */ 00385 if (latchesArray == NIL(array_t)) { 00386 error_append("Simulate: Latches must be declared before initial state declaration.\n"); 00387 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00388 return(sim); 00389 } 00390 initState = BufferBuildValuesArray(buffer2 + 8, latchesArray); 00391 if (initState == NIL(array_t)) { 00392 SimAppendErrorMsg("Simulate: Error line ", 00393 SimInteger2ASCII(lineNumber), ".\n"); 00394 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00395 return(sim); 00396 } 00397 } 00398 else if (!strncmp(buffer2, ".start_vectors", 14)) { 00399 /* Verification of the declarations */ 00400 if (inputsArray == NIL(array_t)) { 00401 error_append("Simulate: Input file is missing inputs declaration.\n"); 00402 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00403 return(sim); 00404 } 00405 00406 currentStateHead = array_n(inputsArray); 00407 00408 nodesArray = array_dup(inputsArray); 00409 array_free(inputsArray); 00410 inputsArray = NIL(array_t); 00411 if(latchesArray == NIL(array_t)) { 00412 /* Verify if actually there is no latch in the network */ 00413 if (Ntk_NetworkReadNumLatches(network) > 0) { 00414 error_append("Simulate: Input file is missing latches declaration.\n"); 00415 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00416 return(0); 00417 } 00418 else { 00419 internalPartitionHead = currentStateHead; 00420 nextStateHead = internalPartitionHead + array_n(internalPartitionArray); 00421 outputHead = nextStateHead; 00422 } 00423 } 00424 else { 00425 internalPartitionHead = currentStateHead + array_n(latchesArray); 00426 nextStateHead = internalPartitionHead + array_n(internalPartitionArray); 00427 outputHead = nextStateHead + array_n(latchesArray); 00428 /* Add current states node */ 00429 array_append(nodesArray, latchesArray); 00430 array_append(nodesArray, internalPartitionArray); 00431 array_free(internalPartitionArray); 00432 /* Add next state node as data-input of current-state node */ 00433 for(i = 0; i < array_n(latchesArray); i++) { 00434 node = array_fetch(Ntk_Node_t *, latchesArray, i); 00435 node = Ntk_LatchReadDataInput(node); 00436 array_insert_last(Ntk_Node_t *, nodesArray, node); 00437 } 00438 array_free(latchesArray); 00439 } 00440 if (outputsArray != NIL(array_t)) { 00441 array_append(nodesArray, outputsArray); 00442 array_free(outputsArray); 00443 } 00444 /* Building nodeToMvfTable */ 00445 nodeToMvfTable = Sim_NetworkBuildNodeToMvfTable(network, nodesArray, 00446 internalPartitionHead, 00447 nextStateHead); 00448 sim = Sim_SimCreate(network, nodeToMvfTable, inputFile, lineNumber, 00449 nodesArray, currentStateHead, internalPartitionHead, 00450 nextStateHead, outputHead, initState, NULL, verbose); 00451 00452 return(sim); /* Normal end */ 00453 } 00454 00455 /* Unknown string in the declaration part */ 00456 else { 00457 SimAppendErrorMsg("Simulate: Syntax error in the declaration line: ", 00458 SimInteger2ASCII(lineNumber), 00459 " or missing .start_vectors statement.\n") ; 00460 FreeArrays(inputsArray, latchesArray, outputsArray, internalPartitionArray); 00461 return(sim); 00462 } 00463 } 00464 } 00465 array_free(internalPartitionArray); 00466 return(sim); 00467 } 00468 00489 int 00490 Sim_FileParseVectors( 00491 FILE * fp, 00492 Sim_Sim_t * sim, 00493 int num) 00494 { 00495 char buffer[MAX_LINE_LENGTH]; 00496 char *buffer2; 00497 array_t *vectorArray; 00498 int numberVector = 0; 00499 array_t *inputsArray = SimObtainInputsArray(sim); 00500 00501 sim->vectorArray = array_alloc(array_t *, 0); 00502 00503 while (fgets(buffer, MAX_LINE_LENGTH -1, fp) != NULL) { 00504 int position = 0; 00505 (sim->lineNumber)++; 00506 00507 /* Every line must end by '\n' */ 00508 if (buffer[strlen(buffer) -1] != '\n') { 00509 SimAppendErrorMsg("Simulate: Line ", SimInteger2ASCII(sim->lineNumber), 00510 " is too long!\n"); 00511 array_free(inputsArray); 00512 return(0); 00513 } 00514 00515 /* Eliminate spaces */ 00516 BufferSkipWhiteSpace(buffer, &position); 00517 /* buffer2 will contain buffer without space in the begining */ 00518 buffer2 = buffer + position; 00519 /* Avoid comment and empty lines */ 00520 if (buffer[position] != '#' && buffer[position] != '\n') { 00521 /* Read only "num" vectors */ 00522 if (numberVector >= num && num != 0) { 00523 array_free(inputsArray); 00524 return(1); /* Normal end before EOF */ 00525 } 00526 vectorArray = BufferBuildValuesArray(buffer2, inputsArray); 00527 if (vectorArray == NIL(array_t)) { 00528 SimAppendErrorMsg("Simulate: Error line ", 00529 SimInteger2ASCII(sim->lineNumber), ".\n"); 00530 array_free(inputsArray); 00531 return(0); 00532 } 00533 numberVector++; 00534 SimAddVector(sim, vectorArray); 00535 } 00536 } 00537 array_free(inputsArray); 00538 return(2); /* End of file */ 00539 } 00540 00541 /*---------------------------------------------------------------------------*/ 00542 /* Definition of internal functions */ 00543 /*---------------------------------------------------------------------------*/ 00544 00545 /*---------------------------------------------------------------------------*/ 00546 /* Definition of static functions */ 00547 /*---------------------------------------------------------------------------*/ 00558 static array_t * 00559 SimObtainInputsArray( 00560 Sim_Sim_t * sim) 00561 { 00562 int i; 00563 Ntk_Node_t * node; 00564 array_t * inputsArray = array_alloc(Ntk_Node_t *, 0); 00565 00566 for (i = 0; i < sim->currentStateHead; i++) { 00567 node = array_fetch(Ntk_Node_t *, sim->nodesArray, i); 00568 array_insert_last(Ntk_Node_t *, inputsArray, node); 00569 } 00570 return(inputsArray); 00571 } 00572 00582 static void 00583 FreeArrays( 00584 array_t *array1, 00585 array_t *array2, 00586 array_t *array3, 00587 array_t *array4) 00588 { 00589 if (array1 != NIL(array_t)) { 00590 array_free(array1); 00591 } 00592 if (array2 != NIL(array_t)) { 00593 array_free(array2); 00594 } 00595 if (array3 != NIL(array_t)) { 00596 array_free(array3); 00597 } 00598 if (array4 != NIL(array_t)) { 00599 array_free(array4); 00600 } 00601 } 00602 00603 00617 static array_t * 00618 BufferBuildInputsNodeArray( 00619 char * buffer, 00620 Ntk_Network_t * network) 00621 { 00622 char *str; 00623 Ntk_Node_t *node; 00624 int position = 0; 00625 array_t *array = array_alloc(Ntk_Node_t *, 0); 00626 00627 while((str = BufferObtainStringAtPosition(buffer, &position)) != NULL) { 00628 node = Ntk_NetworkFindNodeByActualName(network, str); 00629 if (node == NIL(Ntk_Node_t) || !Ntk_NodeTestIsInput(node)) { 00630 SimAppendErrorMsg("Simulate: ", str, " is not a valid input name.\n"); 00631 array_free(array); 00632 FREE(str); 00633 return(NIL(array_t)); 00634 } 00635 FREE(str); 00636 array_insert_last(Ntk_Node_t *, array, node); 00637 } 00638 /* Verification of number of values */ 00639 if (array_n(array) != Ntk_NetworkReadNumInputs(network)) { 00640 error_append("Simulate: All inputs and pseudo-inputs must be specified.\n"); 00641 array_free(array); 00642 return(NIL(array_t)); 00643 } 00644 return(array); 00645 } 00646 00647 00661 static array_t * 00662 BufferBuildLatchesNodeArray( 00663 char * buffer, 00664 Ntk_Network_t * network) 00665 { 00666 char *str; 00667 Ntk_Node_t *node; 00668 int position = 0; 00669 array_t *array = array_alloc(Ntk_Node_t *, 0); 00670 00671 while ((str = BufferObtainStringAtPosition(buffer, &position)) != NULL) { 00672 node = Ntk_NetworkFindNodeByActualName(network, str); 00673 if (node == NIL(Ntk_Node_t) || !Ntk_NodeTestIsLatch(node)) { 00674 SimAppendErrorMsg("Simulate: ", str, " is not a valid latch name\n"); 00675 array_free(array); 00676 FREE(str); 00677 return(NIL(array_t)); 00678 } 00679 FREE(str); 00680 array_insert_last(Ntk_Node_t *, array, node); 00681 } 00682 /* Verification of number of items */ 00683 if (array_n(array) != Ntk_NetworkReadNumLatches(network)) { 00684 error_append("Simulate: All latches must be specified.\n"); 00685 array_free(array); 00686 return(NIL(array_t)); 00687 } 00688 return(array); 00689 } 00690 00704 static array_t * 00705 BufferBuildOutputsNodeArray( 00706 char * buffer, 00707 Ntk_Network_t * network) 00708 { 00709 char *str; 00710 Ntk_Node_t *node; 00711 int position = 0; 00712 array_t *array = array_alloc(Ntk_Node_t *, 0); 00713 00714 while((str = BufferObtainStringAtPosition(buffer, &position)) != NULL) { 00715 node = Ntk_NetworkFindNodeByActualName(network, str); 00716 if (node == NIL(Ntk_Node_t) || !Ntk_NodeTestIsPrimaryOutput(node)) { 00717 SimAppendErrorMsg("Simulate: ", str, " is not a valid output name\n"); 00718 FREE(str); 00719 array_free(array); 00720 return(NIL(array_t)); 00721 } 00722 FREE(str); 00723 array_insert_last(Ntk_Node_t *, array, node); 00724 } 00725 return(array); 00726 } 00727 00745 static array_t * 00746 BufferBuildValuesArray( 00747 char * buffer, 00748 array_t * nodesArray) 00749 { 00750 char *str; 00751 Ntk_Node_t *node; 00752 int index; 00753 int i = 0; 00754 int arraySize = array_n(nodesArray); 00755 int position = 0; 00756 array_t *array = array_alloc(int, 0); 00757 00758 while((str = BufferObtainStringAtPosition(buffer, &position)) != NULL) { 00759 if (i >= arraySize) { 00760 SimAppendErrorMsg("Simulate: Too many values(", str, " invalid value).\n"); 00761 array_free(array); 00762 FREE(str); 00763 return(NIL(array_t)); 00764 } 00765 node = array_fetch(Ntk_Node_t *, nodesArray, i); 00766 i++; 00767 index = SimNodeReadValueCode(node, str); 00768 if (index == -1) { 00769 SimAppendErrorMsg("Simulate: ", str, ": invalid value.\n"); 00770 array_free(array); 00771 FREE(str); 00772 return(NIL(array_t)); 00773 } 00774 00775 FREE(str); 00776 array_insert_last(int, array, index); 00777 } 00778 00779 /* Verification of number of items */ 00780 if (array_n(array) != array_n(nodesArray)) { 00781 error_append("Simulate: incomplete number of values.\n"); 00782 array_free(array); 00783 return(NIL(array_t)); 00784 } 00785 return(array); 00786 } 00787 00788 00800 static void 00801 SimAddVector( 00802 Sim_Sim_t * sim, 00803 array_t * vector) 00804 { 00805 array_insert_last(array_t *, sim->vectorArray, vector); 00806 } 00807 00818 static void 00819 BufferSkipWhiteSpace( 00820 char * buffer, 00821 int * position) 00822 { 00823 for (; buffer[*position] == ' ' || buffer[*position] == '\t'; (*position)++); 00824 } 00825 00838 static char * 00839 BufferObtainStringAtPosition( 00840 char * buffer, 00841 int * position) 00842 { 00843 char *str; 00844 int strPosition; 00845 int len; 00846 00847 /* Traverse Space */ 00848 BufferSkipWhiteSpace(buffer, position); 00849 00850 strPosition = *position; 00851 for (;buffer[*position] != ' ' && buffer[*position] != '\t' && 00852 buffer[*position] != ';' && buffer[*position] != '\n'; (*position)++); 00853 00854 if (strPosition == *position) { 00855 return(NIL(char)); 00856 } 00857 len = *position - strPosition + 1; 00858 str = ALLOC(char, len); 00859 strncpy(str, buffer + strPosition, len - 1); 00860 str[len-1] = '\0'; 00861 return(str); 00862 } 00863 00879 static void 00880 PrintValue(array_t *nodesArray, array_t *vector, int vectorIndex, 00881 int strSize, FILE *file) 00882 { 00883 int index; 00884 Var_Variable_t *var; 00885 char *str; 00886 Ntk_Node_t *node; 00887 00888 if (array_n(vector) > vectorIndex) { 00889 node = array_fetch(Ntk_Node_t *, nodesArray, vectorIndex); 00890 var = Ntk_NodeReadVariable(node); 00891 index = array_fetch(int, vector, vectorIndex); 00892 if (Var_VariableTestIsSymbolic(var)) { 00893 SimStringPrint(file, Var_VariableReadSymbolicValueFromIndex(var, index), 00894 strSize); 00895 } 00896 else { /* Binary or enumerative type */ 00897 str = SimInteger2ASCII(index); 00898 SimStringPrint(file, str, strSize); 00899 FREE(str); 00900 } 00901 } 00902 else { 00903 error_append("Warning: Value is missing in vector.\n"); 00904 SimStringPrint(file, "*", strSize); 00905 } 00906 }