wrstabs.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,416 行 · 第 1/4 页

C
2,416
字号
{  struct stab_write_handle *info = (struct stab_write_handle *) p;  /* We don't call stab_void_type if the type is not yet defined,     because that might screw up the typedef.  */  if (info->type_cache.void_type != 0)    return stab_push_defined_type (info, info->type_cache.void_type, 0);  else    {      long index;      char buf[40];      index = info->type_index;      ++info->type_index;      sprintf (buf, "%ld=%ld", index, index);      return stab_push_string (info, buf, index, false, 0);    }}/* Push a void type.  */static booleanstab_void_type (p)     PTR p;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  if (info->type_cache.void_type != 0)    return stab_push_defined_type (info, info->type_cache.void_type, 0);  else    {      long index;      char buf[40];      index = info->type_index;      ++info->type_index;      info->type_cache.void_type = index;      sprintf (buf, "%ld=%ld", index, index);      return stab_push_string (info, buf, index, true, 0);    }}/* Push an integer type.  */static booleanstab_int_type (p, size, unsignedp)     PTR p;     unsigned int size;     boolean unsignedp;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  long *cache;  if (size <= 0 || (size > sizeof (long) && size != 8))    {      non_fatal (_("stab_int_type: bad size %u"), size);      return false;    }  if (unsignedp)    cache = info->type_cache.signed_integer_types;  else    cache = info->type_cache.unsigned_integer_types;  if (cache[size - 1] != 0)    return stab_push_defined_type (info, cache[size - 1], size);  else    {      long index;      char buf[100];      index = info->type_index;      ++info->type_index;      cache[size - 1] = index;      sprintf (buf, "%ld=r%ld;", index, index);      if (unsignedp)	{	  strcat (buf, "0;");	  if (size < sizeof (long))	    sprintf (buf + strlen (buf), "%ld;", ((long) 1 << (size * 8)) - 1);	  else if (size == sizeof (long))	    strcat (buf, "-1;");	  else if (size == 8)	    strcat (buf, "01777777777777777777777;");	  else	    abort ();	}      else	{	  if (size <= sizeof (long))	    sprintf (buf + strlen (buf), "%ld;%ld;",		     (long) - ((unsigned long) 1 << (size * 8 - 1)),		     (long) (((unsigned long) 1 << (size * 8 - 1)) - 1));	  else if (size == 8)	    strcat (buf, "01000000000000000000000;0777777777777777777777;");	  else	    abort ();	}      return stab_push_string (info, buf, index, true, size);    }}/* Push a floating point type.  */static booleanstab_float_type (p, size)     PTR p;     unsigned int size;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  if (size > 0      && size - 1 < (sizeof info->type_cache.float_types		     / sizeof info->type_cache.float_types[0])      && info->type_cache.float_types[size - 1] != 0)    return stab_push_defined_type (info,				   info->type_cache.float_types[size - 1],				   size);  else    {      long index;      char *int_type;      char buf[50];      /* Floats are defined as a subrange of int.  */      if (! stab_int_type (info, 4, false))	return false;      int_type = stab_pop_type (info);      index = info->type_index;      ++info->type_index;      if (size > 0	  && size - 1 < (sizeof info->type_cache.float_types			 / sizeof info->type_cache.float_types[0]))	info->type_cache.float_types[size - 1] = index;      sprintf (buf, "%ld=r%s;%u;0;", index, int_type, size);      free (int_type);      return stab_push_string (info, buf, index, true, size);    }}/* Push a complex type.  */static booleanstab_complex_type (p, size)     PTR p;     unsigned int size;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  char buf[50];  long index;  index = info->type_index;  ++info->type_index;  sprintf (buf, "%ld=r%ld;%u;0;", index, index, size);  return stab_push_string (info, buf, index, true, size * 2);}/* Push a boolean type.  We use an XCOFF predefined type, since gdb   always recognizes them.  */static booleanstab_bool_type (p, size)     PTR p;     unsigned int size;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  long index;  switch (size)    {    case 1:      index = -21;      break;    case 2:      index = -22;      break;          default:    case 4:      index = -16;      break;    case 8:      index = -33;      break;    }  return stab_push_defined_type (info, index, size);}/* Push an enum type.  */static booleanstab_enum_type (p, tag, names, vals)     PTR p;     const char *tag;     const char **names;     bfd_signed_vma *vals;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  size_t len;  const char **pn;  char *buf;  long index = 0;  bfd_signed_vma *pv;  if (names == NULL)    {      assert (tag != NULL);      buf = (char *) xmalloc (10 + strlen (tag));      sprintf (buf, "xe%s:", tag);      /* FIXME: The size is just a guess.  */      if (! stab_push_string (info, buf, 0, false, 4))	return false;      free (buf);      return true;    }  len = 10;  if (tag != NULL)    len += strlen (tag);  for (pn = names; *pn != NULL; pn++)    len += strlen (*pn) + 20;  buf = (char *) xmalloc (len);  if (tag == NULL)    strcpy (buf, "e");  else    {      index = info->type_index;      ++info->type_index;      sprintf (buf, "%s:T%ld=e", tag, index);    }  for (pn = names, pv = vals; *pn != NULL; pn++, pv++)    sprintf (buf + strlen (buf), "%s:%ld,", *pn, (long) *pv);  strcat (buf, ";");  if (tag == NULL)    {      /* FIXME: The size is just a guess.  */      if (! stab_push_string (info, buf, 0, false, 4))	return false;    }  else    {      /* FIXME: The size is just a guess.  */      if (! stab_write_symbol (info, N_LSYM, 0, 0, buf)	  || ! stab_push_defined_type (info, index, 4))	return false;    }  free (buf);  return true;}/* Push a modification of the top type on the stack.  Cache the   results in CACHE and CACHE_ALLOC.  */static booleanstab_modify_type (info, mod, size, cache, cache_alloc)     struct stab_write_handle *info;     int mod;     unsigned int size;     long **cache;     size_t *cache_alloc;{  long targindex;  long index;  char *s, *buf;  assert (info->type_stack != NULL);  targindex = info->type_stack->index;  if (targindex <= 0      || cache == NULL)    {      boolean definition;      /* Either the target type has no index, or we aren't caching         this modifier.  Either way we have no way of recording the         new type, so we don't bother to define one.  */      definition = info->type_stack->definition;      s = stab_pop_type (info);      buf = (char *) xmalloc (strlen (s) + 2);      sprintf (buf, "%c%s", mod, s);      free (s);      if (! stab_push_string (info, buf, 0, definition, size))	return false;      free (buf);    }  else    {      if ((size_t) targindex >= *cache_alloc)	{	  size_t alloc;	  alloc = *cache_alloc;	  if (alloc == 0)	    alloc = 10;	  while ((size_t) targindex >= alloc)	    alloc *= 2;	  *cache = (long *) xrealloc (*cache, alloc * sizeof (long));	  memset (*cache + *cache_alloc, 0,		  (alloc - *cache_alloc) * sizeof (long));	  *cache_alloc = alloc;	}      index = (*cache)[targindex];      if (index != 0 && ! info->type_stack->definition)	{	  /* We have already defined a modification of this type, and             the entry on the type stack is not a definition, so we             can safely discard it (we may have a definition on the             stack, even if we already defined a modification, if it             is a struct which we did not define at the time it was             referenced).  */	  free (stab_pop_type (info));	  if (! stab_push_defined_type (info, index, size))	    return false;	}      else	{	  index = info->type_index;	  ++info->type_index;	  s = stab_pop_type (info);	  buf = (char *) xmalloc (strlen (s) + 20);	  sprintf (buf, "%ld=%c%s", index, mod, s);	  free (s);	  (*cache)[targindex] = index;	  if (! stab_push_string (info, buf, index, true, size))	    return false;	  free (buf);	}    }  return true;}  /* Push a pointer type.  */static booleanstab_pointer_type (p)     PTR p;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  /* FIXME: The size should depend upon the architecture.  */  return stab_modify_type (info, '*', 4, &info->type_cache.pointer_types,			   &info->type_cache.pointer_types_alloc);}/* Push a function type.  */static booleanstab_function_type (p, argcount, varargs)     PTR p;     int argcount;     boolean varargs ATTRIBUTE_UNUSED;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  int i;  /* We have no way to represent the argument types, so we just     discard them.  However, if they define new types, we must output     them.  We do this by producing empty typedefs.  */  for (i = 0; i < argcount; i++)    {      if (! info->type_stack->definition)	free (stab_pop_type (info));      else	{	  char *s, *buf;	  s = stab_pop_type (info);	  buf = (char *) xmalloc (strlen (s) + 3);	  sprintf (buf, ":t%s", s);	  free (s);	  if (! stab_write_symbol (info, N_LSYM, 0, 0, buf))	    return false;	  free (buf);	}    }  return stab_modify_type (info, 'f', 0, &info->type_cache.function_types,			   &info->type_cache.function_types_alloc);}/* Push a reference type.  */static booleanstab_reference_type (p)     PTR p;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  /* FIXME: The size should depend upon the architecture.  */  return stab_modify_type (info, '&', 4, &info->type_cache.reference_types,			   &info->type_cache.reference_types_alloc);}/* Push a range type.  */static booleanstab_range_type (p, low, high)     PTR p;     bfd_signed_vma low;     bfd_signed_vma high;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  boolean definition;  unsigned int size;  char *s, *buf;  definition = info->type_stack->definition;  size = info->type_stack->size;  s = stab_pop_type (info);  buf = (char *) xmalloc (strlen (s) + 100);  sprintf (buf, "r%s;%ld;%ld;", s, (long) low, (long) high);  free (s);  if (! stab_push_string (info, buf, 0, definition, size))    return false;  free (buf);  return true;}/* Push an array type.  */static booleanstab_array_type (p, low, high, stringp)     PTR p;     bfd_signed_vma low;     bfd_signed_vma high;     boolean stringp;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  boolean definition;  unsigned int element_size;  char *range, *element, *buf;  long index;  unsigned int size;  definition = info->type_stack->definition;  range = stab_pop_type (info);  definition = definition || info->type_stack->definition;  element_size = info->type_stack->size;  element = stab_pop_type (info);  buf = (char *) xmalloc (strlen (range) + strlen (element) + 100);  if (! stringp)    {      index = 0;      *buf = '\0';    }  else    {      /* We need to define a type in order to include the string         attribute.  */      index = info->type_index;      ++info->type_index;      definition = true;      sprintf (buf, "%ld=@S;", index);    }  sprintf (buf + strlen (buf), "ar%s;%ld;%ld;%s",	   range, (long) low, (long) high, element);  free (range);  free (element);  if (high < low)    size = 0;  else    size = element_size * ((high - low) + 1);  if (! stab_push_string (info, buf, index, definition, size))    return false;  free (buf);  return true;}/* Push a set type.  */static booleanstab_set_type (p, bitstringp)     PTR p;     boolean bitstringp;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  boolean definition;  char *s, *buf;  long index;  definition = info->type_stack->definition;  s = stab_pop_type (info);  buf = (char *) xmalloc (strlen (s) + 30);  if (! bitstringp)    {      *buf = '\0';      index = 0;    }  else    {      /* We need to define a type in order to include the string         attribute.  */      index = info->type_index;      ++info->type_index;      definition = true;      sprintf (buf, "%ld=@S;", index);    }  sprintf (buf + strlen (buf), "S%s", s);  free (s);  if (! stab_push_string (info, buf, index, definition, 0))    return false;  free (buf);  return true;}/* Push an offset type.  */static booleanstab_offset_type (p)     PTR p;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  boolean definition;  char *target, *base, *buf;  definition = info->type_stack->definition;  target = stab_pop_type (info);  definition = definition || info->type_stack->definition;  base = stab_pop_type (info);  buf = (char *) xmalloc (strlen (target) + strlen (base) + 3);  sprintf (buf, "@%s,%s", base, target);  free (base);  free (target);  if (! stab_push_string (info, buf, 0, definition, 0))    return false;  free (buf);  return true;}/* Push a method type.  */static booleanstab_method_type (p, domainp, argcount, varargs)     PTR p;     boolean domainp;     int argcount;     boolean varargs;{  struct stab_write_handle *info = (struct stab_write_handle *) p;  boolean definition;  char *domain, *return_type, *buf;  char **args;  int i;  size_t len;  /* We don't bother with stub method types, because that would     require a mangler for C++ argument types.  This will waste space

⌨️ 快捷键说明

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