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

📄 ghwlib.c

📁 vhdl集成电路设计软件.需要用gcc-4.0.2版本编译.
💻 C
📖 第 1 页 / 共 3 页
字号:
	  break;	case ghdl_rtik_type_record:	  {	    struct ghw_type_record *rec;	    int j;	    int nbr_el;	    rec = malloc (sizeof (struct ghw_type_record));	    rec->kind = t;	    rec->name = ghw_read_strid (h);	    if (ghw_read_uleb128 (h, &rec->nbr_fields) != 0)	      return -1;	    rec->el = malloc	      (rec->nbr_fields * sizeof (struct ghw_record_element));	    nbr_el = 0;	    for (j = 0; j < rec->nbr_fields; j++)	      {		rec->el[j].name = ghw_read_strid (h);		rec->el[j].type = ghw_read_typeid (h);		nbr_el += get_nbr_elements (rec->el[j].type);	      }	    rec->nbr_el = nbr_el;	    if (h->flag_verbose > 1)	      printf ("record type: %s (nbr_el=%d)\n", rec->name, rec->nbr_el);	    h->types[i] = (union ghw_type *)rec;	  }	  break;	default:	  fprintf (stderr, "ghw_read_type: unknown type %d\n", t);	  return -1;	}    }  if (fgetc (h->stream) != 0)    return -1;  return 0;}intghw_read_wk_types (struct ghw_handler *h){  char hdr[4];  if (fread (hdr, sizeof (hdr), 1, h->stream) != 1)    return -1;  if (hdr[0] != 0 || hdr[1] != 0 || hdr[2] != 0 || hdr[3] != 0)    return -1;  while (1)    {      int t;      union ghw_type *tid;      t = fgetc (h->stream);      if (t == EOF)	return -1;      else if (t == 0)	break;      tid = ghw_read_typeid (h);      if (tid->kind == ghdl_rtik_type_b2	  || tid->kind == ghdl_rtik_type_e8)	{	  if (h->flag_verbose > 0)	    printf ("%s: wkt=%d\n", tid->en.name, t);	  tid->en.wkt = t;	}    }  return 0;}voidghw_disp_typename (struct ghw_handler *h, union ghw_type *t){  printf ("%s", t->common.name);}/* Read a signal composed of severals elements.  */intghw_read_signal (struct ghw_handler *h, unsigned int *sigs, union ghw_type *t){  switch (t->kind)    {    case ghdl_rtik_type_b2:    case ghdl_rtik_type_e8:    case ghdl_rtik_type_e32:    case ghdl_rtik_subtype_scalar:      {	unsigned int sig_el;	if (ghw_read_uleb128 (h, &sig_el) < 0)	  return -1;	*sigs = sig_el;	if (sig_el >= h->nbr_sigs)	  abort ();	if (h->sigs[sig_el].type == NULL)	  h->sigs[sig_el].type = ghw_get_base_type (t);      }      return 0;    case ghdl_rtik_subtype_array:    case ghdl_rtik_subtype_array_ptr:      {	int i;	int stride;	int len;	len = t->sa.nbr_el;	stride = get_nbr_elements (t->sa.base->el);	for (i = 0; i < len; i += stride)	  if (ghw_read_signal (h, &sigs[i], t->sa.base->el) < 0)	    return -1;      }      return 0;    case ghdl_rtik_type_record:      {	int i;	int off;		off = 0;	for (i = 0; i < t->rec.nbr_fields; i++)	  {	    if (ghw_read_signal (h, &sigs[off], t->rec.el[i].type) < 0)	      return -1;	    off += get_nbr_elements (t->rec.el[i].type);	  }      }      return 0;    default:      fprintf (stderr, "ghw_read_signal: type kind %d unhandled\n", t->kind);      abort ();    }}intghw_read_value (struct ghw_handler *h,		union ghw_val *val, union ghw_type *type){  switch (ghw_get_base_type (type)->kind)    {    case ghdl_rtik_type_b2:      {	int v;	v = fgetc (h->stream);	if (v == EOF)	  return -1;	val->b2 = v;      }      break;    case ghdl_rtik_type_e8:      {	int v;	v = fgetc (h->stream);	if (v == EOF)	  return -1;	val->e8 = v;      }      break;    case ghdl_rtik_type_i32:    case ghdl_rtik_type_p32:      {	int32_t v;	if (ghw_read_sleb128 (h, &v) < 0)	  return -1;	val->i32 = v;      }      break;    case ghdl_rtik_type_f64:      {	double v;	if (ghw_read_f64 (h, &v) < 0)	  return -1;	val->f64 = v;      }      break;    case ghdl_rtik_type_p64:      {	int64_t v;	if (ghw_read_lsleb128 (h, &v) < 0)	  return -1;	val->i64 = v;      }      break;    default:      fprintf (stderr, "read_value: cannot handle format %d\n", type->kind);      abort ();    }  return 0;}intghw_read_hie (struct ghw_handler *h){  char hdr[16];  int nbr_scopes;  int nbr_sigs;  int i;  struct ghw_hie *blk;  struct ghw_hie **last;  if (fread (hdr, sizeof (hdr), 1, h->stream) != 1)    return -1;  if (hdr[0] != 0 || hdr[1] != 0 || hdr[2] != 0 || hdr[3] != 0)    return -1;  nbr_scopes = ghw_get_i32 (h, &hdr[4]);  /* Number of declared signals (which may be composite).  */  nbr_sigs = ghw_get_i32 (h, &hdr[8]);  /* Number of basic signals.  */  h->nbr_sigs = ghw_get_i32 (h, &hdr[12]);  blk = (struct ghw_hie *)malloc (sizeof (struct ghw_hie));  blk->kind = ghw_hie_design;  blk->name = NULL;  blk->parent = NULL;  blk->brother = NULL;  blk->u.blk.child = NULL;  last = &blk->u.blk.child;  h->hie = blk;  h->nbr_sigs++;  h->sigs = (struct ghw_sig *) malloc (h->nbr_sigs * sizeof (struct ghw_sig));  memset (h->sigs, 0, h->nbr_sigs * sizeof (struct ghw_sig));  while (1)    {      int t;      struct ghw_hie *el;      unsigned int str;      t = fgetc (h->stream);      if (t == EOF)	return -1;      if (t == 0)	break;      if (t == ghw_hie_eos)	{	  blk = blk->parent;	  if (blk->u.blk.child == NULL)	    last = &blk->u.blk.child;	  else	    {	      struct ghw_hie *l = blk->u.blk.child;	      while (l->brother != NULL)		l = l->brother;	      last = &l->brother;	    }	  continue;	}      el = (struct ghw_hie *) malloc (sizeof (struct ghw_hie));      el->kind = t;      el->parent = blk;      el->brother = NULL;      /* Link.  */      *last = el;      last = &el->brother;      /* Read name.  */      if (ghw_read_uleb128 (h, &str) != 0)	return -1;      el->name = h->str_table[str];      switch (t)	{	case ghw_hie_eoh:	case ghw_hie_design:	case ghw_hie_eos:	  /* Should not be here.  */	  abort ();	case ghw_hie_process:	  break;	case ghw_hie_block:	case ghw_hie_generate_if:	case ghw_hie_generate_for:	case ghw_hie_instance:	case ghw_hie_generic:	  /* Create a block.  */	  el->u.blk.child = NULL;	  if (t == ghw_hie_generate_for)	    {	      el->u.blk.iter_type = ghw_read_typeid (h);	      el->u.blk.iter_value = malloc (sizeof (union ghw_val));	      if (ghw_read_value (h, el->u.blk.iter_value,				  el->u.blk.iter_type) < 0)		return -1;	    }	  blk = el;	  last = &el->u.blk.child;	  break;	case ghw_hie_signal:	case ghw_hie_port_in:	case ghw_hie_port_out:	case ghw_hie_port_inout:	case ghw_hie_port_buffer:	case ghw_hie_port_linkage:	  /* For a signal, read type.  */	  {	    int nbr_el;	    unsigned int *sigs;	    el->u.sig.type = ghw_read_typeid (h);	    nbr_el = get_nbr_elements (el->u.sig.type);	    sigs = (unsigned int *) malloc	      ((nbr_el + 1) * sizeof (unsigned int));	    el->u.sig.sigs = sigs;	    /* Last element is NULL.  */	    sigs[nbr_el] = 0;	    if (h->flag_verbose > 1)	      printf ("signal %s: %d el\n", el->name, nbr_el);	    if (ghw_read_signal (h, sigs, el->u.sig.type) < 0)	      return -1;#if 0	    for (i = 0; i < nbr_el; i++)	      {		unsigned int sig_el;		if (ghw_read_uleb128 (h, &sig_el) < 0)		  return -1;		sigs[i] = sig_el;		if (sig_el >= h->nbr_sigs)		  abort ();		if (h->sigs[sig_el].type == NULL)		  {		    h->sigs[sig_el].type = ghw_get_base_type (el->u.sig.type);		  }	      }	    sigs[i] = 0;#endif	  }	  break;	default:	  fprintf (stderr, "ghw_read_hie: unhandled kind %d\n", t);	  abort ();	}    }  /* Allocate values.  */  for (i = 0; i < h->nbr_sigs; i++)    if (h->sigs[i].type != NULL)      h->sigs[i].val = (union ghw_val *) malloc (sizeof (union ghw_val));  return 0;}const char *ghw_get_hie_name (struct ghw_hie *h){  switch (h->kind)    {    case ghw_hie_eoh:      return "eoh";    case ghw_hie_design:      return "design";    case ghw_hie_block:      return "block";    case ghw_hie_generate_if:      return "generate-if";    case ghw_hie_generate_for:      return "generate-for";    case ghw_hie_instance:      return "instance";    case ghw_hie_process:      return "process";    case ghw_hie_generic:      return "generic";    case ghw_hie_eos:      return "eos";    case ghw_hie_signal:      return "signal";    case ghw_hie_port_in:      return "port-in";    case ghw_hie_port_out:      return "port-out";    case ghw_hie_port_inout:      return "port-inout";    case ghw_hie_port_buffer:      return "port-buffer";    case ghw_hie_port_linkage:      return "port-linkage";    default:      return "??";    }}voidghw_disp_value (union ghw_val *val, union ghw_type *type);voidghw_disp_hie (struct ghw_handler *h, struct ghw_hie *top){  int i;  int indent;  struct ghw_hie *hie;  struct ghw_hie *n;  hie = top;  indent = 0;    while (1)    {      for (i = 0; i < indent; i++)	fputc (' ', stdout);      printf ("%s", ghw_get_hie_name (hie));      switch (hie->kind)	{	case ghw_hie_design:	case ghw_hie_block:	case ghw_hie_generate_if:	case ghw_hie_generate_for:	case ghw_hie_instance:	case ghw_hie_process:	  if (hie->name)	    printf (" %s", hie->name);	  if (hie->kind == ghw_hie_generate_for)	    {	      printf ("(");	      ghw_disp_value (hie->u.blk.iter_value, hie->u.blk.iter_type);	      printf (")");	    }	  n = hie->u.blk.child;	  if (n == NULL)	    n = hie->brother;	  else	    indent++;	  break;	case ghw_hie_generic:	case ghw_hie_eos:	  abort ();	case ghw_hie_signal:	case ghw_hie_port_in:	case ghw_hie_port_out:	case ghw_hie_port_inout:	case ghw_hie_port_buffer:	case ghw_hie_port_linkage:	  {	    unsigned int *sigs;	    printf (" %s: ", hie->name);	    ghw_disp_typename (h, hie->u.sig.type);	    for (sigs = hie->u.sig.sigs; *sigs != 0; sigs++)	      printf (" #%u", *sigs);	    n = hie->brother;	  }	  break;	default:	  abort ();	}      printf ("\n");      while (n == NULL)	{	  if (hie->parent == NULL)	    return;	  hie = hie->parent;	  indent--;	  n = hie->brother;	}      hie = n;    }}intghw_read_eoh (struct ghw_handler *h){  return 0;}intghw_read_base (struct ghw_handler *h){  unsigned char hdr[4];  int res;  while (1)    {      if (fread (hdr, sizeof (hdr), 1, h->stream) != 1)	return -1;      if (memcmp (hdr, "STR", 4) == 0)	res = ghw_read_str (h);      else if (memcmp (hdr, "HIE", 4) == 0)	res = ghw_read_hie (h);      else if (memcmp (hdr, "TYP", 4) == 0)	res = ghw_read_type (h);      else if (memcmp (hdr, "WKT", 4) == 0)	res = ghw_read_wk_types (h);      else if (memcmp (hdr, "EOH", 4) == 0)	return 0;      else	{	  fprintf (stderr, "ghw_read_base: unknown GHW section %c%c%c%c\n",		   hdr[0], hdr[1], hdr[2], hdr[3]);	  return -1;	}      if (res != 0)	{	  fprintf (stderr, "ghw_read_base: error in section %s\n", hdr);	  return res;	}    }}intghw_read_signal_value (struct ghw_handler *h, struct ghw_sig *s){  return ghw_read_value (h, s->val, s->type);}intghw_read_snapshot (struct ghw_handler *h){  char hdr[12];  int i;  struct ghw_sig *s;  if (fread (hdr, sizeof (hdr), 1, h->stream) != 1)    return -1;  if (hdr[0] != 0 || hdr[1] != 0 || hdr[2] != 0 || hdr[3] != 0)    return -1;  h->snap_time = ghw_get_i64 (h, &hdr[4]);  if (h->flag_verbose > 1)    printf ("Time is %lld fs\n", h->snap_time);  for (i = 0; i < h->nbr_sigs; i++)    {      s = &h->sigs[i];      if (s->type != NULL)	{	  if (h->flag_verbose > 1)	    printf ("read type %d for sig %d\n", s->type->kind, i);	  if (ghw_read_signal_value (h, s) < 0)	    return -1;	}    }  if (fread (hdr, 4, 1, h->stream) != 1)    return -1;  if (memcmp (hdr, "ESN", 4))    return -1;  return 0;}void ghw_disp_values (struct ghw_handler *h);intghw_read_cycle_start (struct ghw_handler *h){  char hdr[8];  if (fread (hdr, sizeof (hdr), 1, h->stream) != 1)    return -1;  h->snap_time = ghw_get_i64 (h, hdr);  return 0;}intghw_read_cycle_cont (struct ghw_handler *h, int *list){  int i;  int *list_p;  i = 0;

⌨️ 快捷键说明

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