listing.c

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

C
1,404
字号
  unsigned int count = 0;  int c;  char *p = line;  /* If we couldn't open the file, return an empty line.  */  if (file->at_end)    return "";  /* Check the cache and see if we last used this file.  */  if (!last_open_file_info || file != last_open_file_info)    {      if (last_open_file)	{	  last_open_file_info->pos = ftell (last_open_file);	  fclose (last_open_file);	}      last_open_file_info = file;      last_open_file = fopen (file->filename, "r");      if (last_open_file == NULL)	{	  file->at_end = 1;	  return "";	}      /* Seek to where we were last time this file was open.  */      if (file->pos)	fseek (last_open_file, file->pos, SEEK_SET);    }  c = fgetc (last_open_file);  /* Leave room for null.  */  size -= 1;  while (c != EOF && c != '\n')    {      if (count < size)	*p++ = c;      count++;      c = fgetc (last_open_file);    }  if (c == EOF)    {      file->at_end = 1;      *p++ = '.';      *p++ = '.';      *p++ = '.';    }  file->linenum++;  *p++ = 0;  return line;}static const char *fn;static unsigned int eject;	/* Eject pending */static unsigned int page;	/* Current page number */static char *title;		/* Current title */static char *subtitle;		/* Current subtitle */static unsigned int on_page;	/* Number of lines printed on current page */static voidlisting_page (list)     list_info_type *list;{  /* Grope around, see if we can see a title or subtitle edict coming up     soon.  (we look down 10 lines of the page and see if it's there)  */  if ((eject || (on_page >= (unsigned int) paper_height))      && paper_height != 0)    {      unsigned int c = 10;      int had_title = 0;      int had_subtitle = 0;      page++;      while (c != 0 && list)	{	  if (list->edict == EDICT_SBTTL && !had_subtitle)	    {	      had_subtitle = 1;	      subtitle = list->edict_arg;	    }	  if (list->edict == EDICT_TITLE && !had_title)	    {	      had_title = 1;	      title = list->edict_arg;	    }	  list = list->next;	  c--;	}      if (page > 1)	{	  fprintf (list_file, "\f");	}      fprintf (list_file, "%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);      fprintf (list_file, "%s\n", title);      fprintf (list_file, "%s\n", subtitle);      on_page = 3;      eject = 0;    }}static unsigned intcalc_hex (list)     list_info_type *list;{  int data_buffer_size;  list_info_type *first = list;  unsigned int address = ~(unsigned int) 0;  fragS *frag;  fragS *frag_ptr;  unsigned int octet_in_frag;  /* Find first frag which says it belongs to this line.  */  frag = list->frag;  while (frag && frag->line != list)    frag = frag->fr_next;  frag_ptr = frag;  data_buffer_size = 0;  /* Dump all the frags which belong to this line.  */  while (frag_ptr != (fragS *) NULL && frag_ptr->line == first)    {      /* Print as many bytes from the fixed part as is sensible.  */      octet_in_frag = 0;      while ((offsetT) octet_in_frag < frag_ptr->fr_fix	     && data_buffer_size < MAX_BYTES - 3)	{	  if (address == ~(unsigned int) 0)	    {	      address = frag_ptr->fr_address / OCTETS_PER_BYTE;	    }	  sprintf (data_buffer + data_buffer_size,		   "%02X",		   (frag_ptr->fr_literal[octet_in_frag]) & 0xff);	  data_buffer_size += 2;	  octet_in_frag++;	}    if (frag_ptr->fr_type == rs_fill)      {	unsigned int var_rep_max = octet_in_frag;	unsigned int var_rep_idx = octet_in_frag;	/* Print as many bytes from the variable part as is sensible.  */	while (((offsetT) octet_in_frag		< (frag_ptr->fr_fix + frag_ptr->fr_var * frag_ptr->fr_offset))	       && data_buffer_size < MAX_BYTES - 3)	  {	    if (address == ~(unsigned int) 0)	      {		address = frag_ptr->fr_address / OCTETS_PER_BYTE;	      }	    sprintf (data_buffer + data_buffer_size,		     "%02X",		     (frag_ptr->fr_literal[var_rep_idx]) & 0xff);#if 0	    data_buffer[data_buffer_size++] = '*';	    data_buffer[data_buffer_size++] = '*';#endif	    data_buffer_size += 2;	    var_rep_idx++;	    octet_in_frag++;	    if ((offsetT) var_rep_idx >= frag_ptr->fr_fix + frag_ptr->fr_var)	      var_rep_idx = var_rep_max;	  }      }      frag_ptr = frag_ptr->fr_next;    }  data_buffer[data_buffer_size] = '\0';  return address;}static voidprint_lines (list, lineno, string, address)     list_info_type *list;     unsigned int lineno;     char *string;     unsigned int address;{  unsigned int idx;  unsigned int nchars;  unsigned int lines;  unsigned int octet_in_word = 0;  char *src = data_buffer;  int cur;  /* Print the stuff on the first line.  */  listing_page (list);  nchars = (LISTING_WORD_SIZE * 2 + 1) * listing_lhs_width;  /* Print the hex for the first line.  */  if (address == ~(unsigned int) 0)    {      fprintf (list_file, "% 4d     ", lineno);      for (idx = 0; idx < nchars; idx++)	fprintf (list_file, " ");      fprintf (list_file, "\t%s\n", string ? string : "");      on_page++;      listing_page (0);      return;    }  if (had_errors ())    fprintf (list_file, "% 4d ???? ", lineno);  else    fprintf (list_file, "% 4d %04x ", lineno, address);  /* And the data to go along with it.  */  idx = 0;  cur = 0;  while (src[cur] && idx < nchars)    {      int offset;      offset = cur;      fprintf (list_file, "%c%c", src[offset], src[offset + 1]);      cur += 2;      octet_in_word++;      if (octet_in_word == LISTING_WORD_SIZE)	{	  fprintf (list_file, " ");	  idx++;	  octet_in_word = 0;	}      idx += 2;    }  for (; idx < nchars; idx++)    fprintf (list_file, " ");  fprintf (list_file, "\t%s\n", string ? string : "");  on_page++;  listing_page (list);  if (list->message)    {      fprintf (list_file, "****  %s\n", list->message);      listing_page (list);      on_page++;    }  for (lines = 0;       lines < (unsigned int) listing_lhs_cont_lines	 && src[cur];       lines++)    {      nchars = ((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second - 1;      idx = 0;      /* Print any more lines of data, but more compactly.  */      fprintf (list_file, "% 4d      ", lineno);      while (src[cur] && idx < nchars)	{	  int offset;	  offset = cur;	  fprintf (list_file, "%c%c", src[offset], src[offset + 1]);	  cur += 2;	  idx += 2;	  octet_in_word++;	  if (octet_in_word == LISTING_WORD_SIZE)	    {	      fprintf (list_file, " ");	      idx++;	      octet_in_word = 0;	    }	}      fprintf (list_file, "\n");      on_page++;      listing_page (list);    }}static voidlist_symbol_table (){  extern symbolS *symbol_rootP;  int got_some = 0;  symbolS *ptr;  eject = 1;  listing_page (0);  for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))    {      if (SEG_NORMAL (S_GET_SEGMENT (ptr))	  || S_GET_SEGMENT (ptr) == absolute_section)	{#ifdef BFD_ASSEMBLER	  /* Don't report section symbols.  They are not interesting.  */	  if (symbol_section_p (ptr))	    continue;#endif	  if (S_GET_NAME (ptr))	    {	      char buf[30], fmt[8];	      valueT val = S_GET_VALUE (ptr);	      /* @@ Note that this is dependent on the compilation options,		 not solely on the target characteristics.  */	      if (sizeof (val) == 4 && sizeof (int) == 4)		sprintf (buf, "%08lx", (unsigned long) val);	      else if (sizeof (val) <= sizeof (unsigned long))		{		  sprintf (fmt, "%%0%lulx",			   (unsigned long) (sizeof (val) * 2));		  sprintf (buf, fmt, (unsigned long) val);		}#if defined (BFD64)	      else if (sizeof (val) > 4)		sprintf_vma (buf, val);#endif	      else		abort ();	      if (!got_some)		{		  fprintf (list_file, "DEFINED SYMBOLS\n");		  on_page++;		  got_some = 1;		}	      if (symbol_get_frag (ptr) && symbol_get_frag (ptr)->line)		{		  fprintf (list_file, "%20s:%-5d  %s:%s %s\n",			   symbol_get_frag (ptr)->line->file->filename,			   symbol_get_frag (ptr)->line->line,			   segment_name (S_GET_SEGMENT (ptr)),			   buf, S_GET_NAME (ptr));		}	      else		{		  fprintf (list_file, "%33s:%s %s\n",			   segment_name (S_GET_SEGMENT (ptr)),			   buf, S_GET_NAME (ptr));		}	      on_page++;	      listing_page (0);	    }	}    }  if (!got_some)    {      fprintf (list_file, "NO DEFINED SYMBOLS\n");      on_page++;    }  fprintf (list_file, "\n");  on_page++;  listing_page (0);  got_some = 0;  for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))    {      if (S_GET_NAME (ptr) && strlen (S_GET_NAME (ptr)) != 0)	{	  if (S_GET_SEGMENT (ptr) == undefined_section)	    {	      if (!got_some)		{		  got_some = 1;		  fprintf (list_file, "UNDEFINED SYMBOLS\n");		  on_page++;		  listing_page (0);		}	      fprintf (list_file, "%s\n", S_GET_NAME (ptr));	      on_page++;	      listing_page (0);	    }	}    }  if (!got_some)    {      fprintf (list_file, "NO UNDEFINED SYMBOLS\n");      on_page++;      listing_page (0);    }}static voidprint_source (current_file, list, buffer, width)     file_info_type *current_file;     list_info_type *list;     char *buffer;     unsigned int width;{  if (!current_file->at_end)    {      while (current_file->linenum < list->hll_line	     && !current_file->at_end)	{	  char *p = buffer_line (current_file, buffer, width);	  fprintf (list_file, "%4u:%-13s **** %s\n", current_file->linenum,		   current_file->filename, p);	  on_page++;	  listing_page (list);	}    }}/* Sometimes the user doesn't want to be bothered by the debugging   records inserted by the compiler, see if the line is suspicious.  */static intdebugging_pseudo (list, line)     list_info_type *list;     const char *line;{  static int in_debug;  int was_debug;  if (list->debugging)    {      in_debug = 1;      return 1;    }  was_debug = in_debug;  in_debug = 0;  while (isspace ((unsigned char) *line))    line++;  if (*line != '.')    {#ifdef OBJ_ELF      /* The ELF compiler sometimes emits blank lines after switching         out of a debugging section.  If the next line drops us back         into debugging information, then don't print the blank line.         This is a hack for a particular compiler behaviour, not a         general case.  */      if (was_debug	  && *line == '\0'	  && list->next != NULL	  && list->next->debugging)	{	  in_debug = 1;	  return 1;	}#endif      return 0;    }  line++;

⌨️ 快捷键说明

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