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

📄 read.c

📁 用C实现的基于O-tree的ic设计布图布线工具源代码,有相关文档
💻 C
字号:
#include "struct.h"/* local data types */struct node {  char *name;  int x,y,w,h,n,type;  struct pin *head, *tail;  struct node *next;}; struct pin {  char *name;  int x,y;  struct pin *next;}; struct net {  char *name;  int n;  struct net *next, *uniq_next, *uniq;  struct E *index;}; struct inst {  char *lib, *name;  int n;  struct net *head, *tail;  struct inst *next;};struct pairname{  char *a, *b;  struct pairname *next;  };/* local variables */FILE *fp;char *buf0, *buf1, *buf2;struct node *node_head=NULL, *node_tail=NULL;struct inst *inst_head=NULL, *inst_tail=NULL;struct net *net_head=NULL, *net_tail=NULL;struct pairname *pairhead=NULL;/* local prototypes */void module();void general(int);void dimension();void iolist();void pins();void network();void instance();void build_netlist();void build_L_LP();void build_V();void build_E();void build_VP_EP();void free_input_buf();void report_netlist();void Lpair();void build_Lpair();void read(char *fn) {  fp=fopen(fn,"r");  if (!fp) {    printf("Error: input file %s not found\n", fn);    exit(0);  }  buf0=(char *)malloc(MAXLINE);  xybound=0;  buf1=(char *)malloc(MAXLINE);  buf2=(char *)malloc(MAXLINE);  while (!feof(fp)) {    if (fscanf(fp,"%s",buf0)<0) break;    //DEBUG_READ printf("read: %s\n",buf0);    if (!strcmp(buf0,"MODULE")) module();    else if (!strcmp(buf0, "L_PAIR")) Lpair();    else {      printf("Error: not module definition %s\n",buf0);      exit(0);    }  }  free(buf0);  free(buf1);  free(buf2);  fclose(fp);  build_netlist();  build_Lpair();  // report_netlist();}void module() {  do {    fscanf(fp,"%s%s%s",buf0,buf1,buf2);    //DEBUG_READ printf("module: %s %s %s\n",buf0,buf1,buf2);    if (!strcmp(buf2,"GENERAL;")) general(0);    else if (!strcmp(buf2,"PARENT;")) general(1);    else {      printf("Error: unknow module type %s\n",buf2);      exit(0);    }  } while (strcmp(buf0,"ENDMODULE;"));}void general(int isparent) {  int len=strlen(buf0);  struct node *p;  p=(struct node *)malloc(sizeof(struct node));  lib_count++;  if (buf0[len-1]==';') buf0[--len]=0;  p->name=(char *)malloc(len+1);  strcpy(p->name, buf0);  if (node_head) node_tail->next=p, node_tail=p;  else node_head=node_tail=p;  p->type=isparent;  p->head=p->tail=NULL;  p->next=NULL;  p->n=0;  do {    fscanf(fp,"%s",buf0);    //DEBUG_READ if (isparent) printf("parent: %s\n",buf0);    //DEBUG_READ else printf("general: %s\n",buf0);    if (!strcmp(buf0,"DIMENSIONS")) dimension();    else if (!strcmp(buf0,"IOLIST;")) iolist();    else if (!strcmp(buf0,"NETWORK;")) network();    else if (strcmp(buf0,"ENDMODULE;")) {      printf("Error: unknow keyword %s\n",buf0);      exit(0);    }  } while (strcmp(buf0,"ENDMODULE;"));}void dimension() {  int minx=MAXINT, miny=MAXINT, maxx=MININT, maxy=MININT, x, y;  struct node *p=node_tail;  do {    fscanf(fp,"%s %s",buf0,buf1);    //DEBUG_READ printf("dimension: %s %s\n",buf0,buf1);    x=atoi(buf0); y=atoi(buf1);    if (x>maxx) maxx=x;    if (x<minx) minx=x;    if (y>maxy) maxy=y;    if (y<miny) miny=y;  } while (buf1[strlen(buf1)-1]!=';');  p->x=minx;  p->y=miny;  p->w=maxx-minx;  p->h=maxy-miny;}void iolist() {  do {    fscanf(fp,"%s",buf0);    //DEBUG_READ printf("iolist: %s\n",buf0);    if (strcmp(buf0,"ENDIOLIST;")) pins();  } while (strcmp(buf0,"ENDIOLIST;"));}void pins() {  int len=strlen(buf0);  struct pin *p;  struct node *q=node_tail;  p=(struct pin *)malloc(sizeof(struct pin));  p->name=(char *)malloc(len+1);  strcpy(p->name, buf0);  if (q->head) q->tail->next=p, q->tail=p;  else q->head=q->tail=p;  p->next=NULL;  fscanf(fp,"%s %s %s",buf0,buf1,buf2);  //DEBUG_READ printf("pin: %s %s %s\n",buf0,buf1,buf2);  p->x=atoi(buf1)-q->x;  p->y=atoi(buf2)-q->y;  q->n=q->n+1;  do {    fscanf(fp,"%s",buf0);    //DEBUG_READ printf("pin: %s\n",buf0);  } while (buf0[strlen(buf0)-1]!=';');}void network() {  do {    fscanf(fp,"%s",buf0);    //DEBUG_READ printf("network: %s\n",buf0);    if (strcmp(buf0,"ENDNETWORK;")) instance();  } while (strcmp(buf0,"ENDNETWORK;"));}void instance() {  struct inst *p;  cell_count++;  p=(struct inst *)malloc(sizeof(struct inst));  p->name=(char *)malloc(strlen(buf0)+1);  strcpy(p->name, buf0);  fscanf(fp,"%s",buf0);  //DEBUG_READ printf("lib: %s\n",buf0);  p->lib=(char *)malloc(strlen(buf0)+1);  strcpy(p->lib, buf0);  if (inst_head) inst_tail->next=p, inst_tail=p;  else inst_head=inst_tail=p;  p->head=p->tail=NULL;  p->next=NULL;  p->n=0;  do {    struct net *q;    q=(struct net *)malloc(sizeof(struct net));    p->n=p->n+1;    if (p->head) p->tail->next=q, p->tail=q;    else p->head=p->tail=q;    q->n=0;    q->uniq=q->uniq_next=q->next=NULL;    q->index=NULL;    fscanf(fp,"%s",buf0);    //DEBUG_READ printf("instance: %s\n",buf0);    q->name=(char *)malloc(strlen(buf0)+1);    strcpy(q->name, buf0);    if (buf0[strlen(buf0)-1]==';') q->name[strlen(buf0)-1]=0;  } while (buf0[strlen(buf0)-1]!=';');}void build_netlist() {  build_L_LP();  build_V();  build_E();  build_VP_EP();  free_input_buf();}void build_L_LP() {  int i, j, lp_count=0,lp_index=0;  struct node *p=node_head;  lib=(struct L *)malloc(lib_count*sizeof(struct L));  printf("#lib = %d\n",lib_count);  while (p) lp_count+=p->n, p=p->next;  lpin=(struct LP *)malloc(lp_count*sizeof(struct LP));  printf("#lp_count = %d\n",lp_count);  for (i=0,p=node_head;i<lib_count;i++) {    struct L *q=&lib[i];    struct pin *pp=p->head;    if (p->type) parent=q;    q->name=p->name;    q->w=p->w;    q->h=p->h;    q->n=p->n;    q->lp=&lpin[lp_index];    for (j=0;j<p->n;j++) {      struct LP *lp=&lpin[lp_index++];      lp->name=pp->name;      lp->x=pp->x;      lp->y=pp->y;      pp=pp->next;    }    p=p->next;  }  printf("#pad = %d\n",parent->n);}void build_V() {  int i, j;  struct inst *p=inst_head;  ver=(struct V *)calloc(cell_count,sizeof(struct V));  printf("#cell = %d\n",cell_count);  for (i=0;i<cell_count;i++) {    struct V *q=&ver[i];    q->name=p->name;    q->type=(char *)malloc(3);    q->type[0]='R';    q->type[1]='\0';    q->x=q->y=q->orient=0;    q->placed=0;    q->n=p->n;    pin_count+=p->n;    q->ot_child=q->ot_tail=q->ot_sibling=NULL;    q->contour_next=q->contour_prev=NULL;    /* find lib */    for (j=0;j<lib_count;j++) if (!strcmp(p->lib,lib[j].name)) break;    if (j==lib_count) {      printf("Error: undefine library name %s\n",p->lib);      exit(0);    }    if (p->n!=lib[j].n) {      printf("Error: pin number not matched with library %s\n",p->lib);      exit(0);    }    q->l=&lib[j];    q->w=lib[j].w;    q->h=lib[j].h;  xybound=xybound+q->h+q->w;    p=p->next;  }  printf("#pin = %d\n",pin_count);}void build_E() {  int i;  struct inst *p=inst_head;  struct net *np;  /* build net name database */  while (p) {    struct net *q=p->head;    while (q) {      if (!net_head) net_head=net_tail=q, q->uniq=q, q->n++, net_count++;      else {        struct net *pp=net_head;        for (;pp;pp=pp->uniq_next) if (!strcmp(q->name,pp->name)) break;        if (pp) q->uniq=pp, pp->n++;        else net_tail->uniq_next=q, net_tail=q, q->uniq=q, q->n++, net_count++;      }      q=q->next;    }    p=p->next;  }  edg=(struct E *)malloc(net_count*sizeof(struct E));  printf("#net = %d\n",net_count);  /* build E */  for (i=0,np=net_head;i<net_count;i++) {    struct E *pp=&edg[i];    pp->name=(char *)malloc(strlen(np->name)+1);    strcpy(pp->name,np->name);    pp->n=np->n;    np->index=pp;    np=np->uniq_next;  }}void build_VP_EP() {  int i, j, index, vindex;  struct inst *p=inst_head;  ep=(struct P *)malloc((pin_count+parent->n)*sizeof(struct P));  vp=(struct P **)malloc((pin_count+parent->n)*sizeof(struct P *));  for (i=vindex=0;i<cell_count;i++) ver[i].p=&vp[vindex], vindex+=ver[i].n,ver[i].n=0;  printf("vp count = %d\n",vindex);  for (i=index=0;i<net_count;i++) {    struct E *q=&edg[i];    q->p=&ep[index];    index+=q->n, q->n=0;    for (j=0;j<parent->n;j++) if (!strcmp(parent->lp[j].name,q->name)) { /* io pad */      index++, q->n++;      q->p->lp=&parent->lp[j];      vp[vindex++]=q->p;      q->p->e=q;    }  }  printf("ep count = %d\n",index);  printf("vp new count = %d\n",vindex);  /* build VP/EP */  for (i=0;i<cell_count;i++) {    struct net *q=p->head;    struct V *r=&ver[i];    while (q) {      struct E *pp=q->uniq->index;      struct P *qq=&(pp->p[pp->n]);      pp->n++;      r->p[r->n]=qq; //vp      qq->e=pp;      qq->v=r;      qq->lp=&(r->l->lp[r->n]);      r->n++;      q=q->next;    }    p=p->next;  }  /* check io pad for net */}void free_input_buf() {}void build_Lpair(){  struct pairname *p=pairhead;  int i=0,j; if (LL_count>0) {  LL=(struct Lshape *)calloc(LL_count, sizeof(struct Lshape));  while(p)   {     for (j=0; j<cell_count; j++)      {          struct V *q=&ver[j];          if (!strcmp(q->name, p->a))           { LL[i].a=j;             q->type[0]='L';}          if (!strcmp(q->name, p->b))            { LL[i].b=j;              q->type[0]='L';}       }     p=p->next;   i++;   }}}void report_netlist() {  int i,j;  printf("============================================================\n");  printf("lib_count=%d\n",lib_count);  for (i=0;i<lib_count;i++) {    struct L *p=&lib[i];    printf("name=%s w=%d h=%d n=%d\n",p->name,p->w,p->h,p->n);    for (j=0;j<p->n;j++) printf("lib pin %d %s\n",j,p->lp[j].name);  }  printf("============================================================\n");  printf("cell_count=%d\n",cell_count);  for (i=0;i<cell_count;i++) {    struct V *p=&ver[i];    printf("name=%s n=%d lib=%s\n",p->name,p->n,p->l->name);    for (j=0;j<p->n;j++) printf("pin %d v=%s e=%s lp=%s\n",j,p->p[j]->v->name,p->p[j]->e->name,p->p[j]->lp->name);  }  printf("net_count=%d\n",net_count);  printf("pin_count=%d\n",pin_count);  printf("============================================================\n");}void Lpair(){  struct pairname *pairtail;  struct pairname *temp;  LL_count=0;  do {      fscanf(fp, "%s", buf0 );      if (strcmp(buf0, "ENDL_PAIR"))      {        fscanf(fp, "%s", buf1);        temp=(struct pairname *)malloc(sizeof(struct pairname));        temp->a=(char *)malloc(strlen(buf0)+1);        strcpy(temp->a, buf0);        temp->b=(char *)malloc(strlen(buf1)+1);        strcpy(temp->b, buf1);        temp->next=NULL;        if (pairhead) {pairtail->next=temp; pairtail=temp;}         else pairhead=pairtail=temp;       LL_count++;      }     }  while(strcmp(buf0,"ENDL_PAIR"));}

⌨️ 快捷键说明

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