⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readgate.cpp

📁 Static Timing Analyzer
💻 CPP
字号:
#include "datadef.h"main (int argc, char *argv[]){   FILE *fp;   GateList *inlist;   Gate *outg;   if (argc != 2) {   // unmatched argument numbers      printf("\aUsage: show_delay Gate_file\n");      return 1;   }   else if ((fp=fopen(argv[1],"r")) == NULL) {      printf("\aWrong Filename %s.\n",argv[1]);      return 1;   }   else {      inlist = NULL;      idAVLTree pool;      if ((readgate(fp,&inlist,&pool)) == TRUE) {         outg = pool.Find(0);   // get the pseudo destination node         if (outg==NULL) printf("No output node!!\n");         else sdelay(inlist,outg);      }      else printf("Error on reading file !!\n");      fclose(fp);      pool.DeleteTree();   }   return 0;}Boolean readgate(FILE *fp, GateList **inlist, idAVLTree *pool){   int i,stleng;   char temp[256], ctemp[256];   GateId idtemp;   Gate *newg,*tmpg,*outg;   GateList *clist,*newlist,*itail;   if (fp == NULL) return FALSE;   if ((*inlist) == NULL) itail = NULL;   else {   // find the tail of the link list      itail = (*inlist);      while (itail->next) itail = itail->next;   }   while ((fgets(temp,256,fp)) != NULL) {      stleng=strlen(temp);      for (i=0; i<stleng; i++)   // skip space and tab         if (temp[i]!=' ' && temp[i]!=9) break;      if (temp[i]=='!' || temp[i]=='\n') continue;      else if (temp[i]<'0' || temp[i]>'9') {         sscanf(temp+i,"%s",ctemp);         if ((strcmp(ctemp,"IN")) == 0) {            while (1) {               for (; i<stleng; i++)   // skip the words                  if (temp[i]==' ' || temp[i]==9) break;               for (; i<stleng; i++)   // skip space and tab after words                  if (temp[i]!=' ' && temp[i]!=9) break;               if (i>=stleng || temp[i]=='\n') break;               else if (temp[i]<'0' || temp[i]>'9') {                  printf("Wrong Format on Input Node !!\n");                  return FALSE;               }               else {                  /* initialize a new node */                  sscanf(temp+i,"%d",&idtemp);                  newg = new Gate;                  newg->id = idtemp;                  newg->type = InGate;                  newg->inno = 0;                  newg->outno = 0;                  newg->fanout = NULL;                  newg->inready = 0;                  newg->bdelay = 0;                  newg->sdelay = 0;                  newg->bpath = NULL;                  newg->spath = NULL;                  /* add new node into search pool and input list */                  if ((pool->Insert(newg)) == FALSE) delete newg;                  else {                     newlist = new GateList;                     newlist->cgate = newg;                     newlist->next = NULL;                     if (itail == NULL) (*inlist) = newlist;                     else itail->next = newlist;                     itail = newlist;                  }               }            }         }         else if ((strcmp(ctemp,"OUT")) == 0) {            while (1) {               for (; i<stleng; i++)   // skip the words                  if (temp[i]==' ' || temp[i]==9) break;               for (; i<stleng; i++)   // skip space and tab after words                  if (temp[i]!=' ' && temp[i]!=9) break;               if (i>=stleng || temp[i]=='\n') break;               else if (temp[i]<'0' || temp[i]>'9') {                  printf("Wrong Format on Output Node !!\n");                  return FALSE;               }               else {                  sscanf(temp+i,"%d",&idtemp);                  tmpg = pool->Find(idtemp);                  if (tmpg == NULL) {                     printf("Gate %d not declared !!\n",idtemp);                     return FALSE;                  }                  else {                     outg = pool->Find(0);                     if (outg == NULL) {   // create pseudo destination node                        outg = new Gate;                        outg->id = 0;                        outg->type = OutGate;                        outg->inno = 0;                        outg->outno = 0;                        outg->fanout = NULL;                        outg->inready = 0;                        outg->bdelay = 0;                        outg->sdelay = 0;                        outg->bpath = NULL;                        outg->spath = NULL;                        pool->Insert(outg);                     }                     (outg->inno)++;                        /* add to output list */                     if (tmpg->fanout == NULL) clist = NULL;                     else {                        clist = tmpg->fanout;                        while (clist->next) clist = clist->next;                     }                     newlist = new GateList;                     newlist->cgate = outg;                     newlist->next = NULL;                     if (clist == NULL) tmpg->fanout = newlist;                     else clist->next = newlist;                     (tmpg->outno)++;                  }               }            }         }         else if ((strcmp(ctemp,"END")) == 0) break;         else {            printf("Unknown keyword `%s` !!\n",ctemp);            return FALSE;         }      }      else {   /* read gate description */         sscanf(temp+i,"%d",&idtemp);         newg = new Gate;         newg->id = idtemp;         newg->type = Unknown;         newg->inno = 0;         newg->outno = 0;         newg->fanout = NULL;         newg->inready = 0;         newg->bdelay = 0;         newg->sdelay = 0;         newg->bpath = NULL;         newg->spath = NULL;         for (; i<stleng; i++)   // skip the words            if (temp[i]==' ' || temp[i]==9) break;         for (; i<stleng; i++)   // skip space and tab after words            if (temp[i]!=' ' && temp[i]!=9) break;         if ((temp[i]>='0' && temp[i]<='9') || temp[i] == '\n') {            printf("No gate type information !! (%d)\n",newg->id);            delete newg;            return FALSE;         }         sscanf(temp+i,"%s",ctemp);         if ((strcmp(ctemp,"INV")) == 0) newg->type = InvGate;         else if ((strcmp(ctemp,"AND")) == 0)  newg->type = AndGate;         else if ((strcmp(ctemp,"OR")) == 0)   newg->type = OrGate;         else if ((strcmp(ctemp,"NAND")) == 0) newg->type = NandGate;         else if ((strcmp(ctemp,"NOR")) == 0)  newg->type = NorGate;         else if ((strcmp(ctemp,"XOR")) == 0)  newg->type = XorGate;         else if ((strcmp(ctemp,"XNOR")) == 0) newg->type = XnorGate;         else {            delete newg;            printf("Unknown gate type `%s` !!\n",ctemp);            return FALSE;         }         while (1) {   // get the input node of this gate            for (; i<stleng; i++)   // skip the words               if (temp[i]==' ' || temp[i]==9) break;            for (; i<stleng; i++)   // skip space and tab after words               if (temp[i]!=' ' && temp[i]!=9) break;            if (i>=stleng || temp[i]=='\n') break;            else if (temp[i]<'0' || temp[i]>'9') {               printf("Wrong Format on Gate Inputs !!\n");               return FALSE;            }            else {               sscanf(temp+i,"%d",&idtemp);               tmpg = pool->Find(idtemp);               if (tmpg == NULL) {                  printf("Gate %d not declared !!\n",newg->id);                  delete newg;                  return FALSE;               }               else {   // link this gate as the fanout of previous gates                  if (tmpg->fanout == NULL) clist = NULL;                  else {                     clist = tmpg->fanout;                     while (clist->next) clist = clist->next;                  }                  newlist = new GateList;                  newlist->cgate = newg;                  newlist->next = NULL;                  if (clist == NULL) tmpg->fanout = newlist;                  else clist->next = newlist;                  (tmpg->outno)++;               }               (newg->inno)++;            }         }         if (newg->inno == 0) {            printf("Define a gate without input !! (%d)\n",newg->id);            delete newg;            return FALSE;         }         else if (newg->inno > 1 && newg->type == InvGate) {            printf("Inverter has only one input !! (%d)\n",newg->id);            delete newg;            return FALSE;         }         else if ((pool->Insert(newg)) == FALSE) {            delete newg;            printf("Duplicate Gate declaration !! (%d)\n",idtemp);            return FALSE;         }      }   }   return TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -