listing.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,404 行 · 第 1/3 页
C
1,404 行
/* listing.c - mainting assembly listings Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.This file is part of GAS, the GNU Assembler.GAS is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GAS is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with GAS; see the file COPYING. If not, write to the FreeSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA02111-1307, USA. *//* Contributed by Steve Chamberlain <sac@cygnus.com> A listing page looks like: LISTING_HEADER sourcefilename pagenumber TITLE LINE SUBTITLE LINE linenumber address data source linenumber address data source linenumber address data source linenumber address data source If not overridden, the listing commands are: .title "stuff" Put "stuff" onto the title line .sbttl "stuff" Put stuff onto the subtitle line If these commands come within 10 lines of the top of the page, they will affect the page they are on, as well as any subsequent page .eject Thow a page .list Increment the enable listing counter .nolist Decrement the enable listing counter .psize Y[,X] Set the paper size to X wide and Y high. Setting a psize Y of zero will suppress form feeds except where demanded by .eject If the counter goes below zero, listing is suppressed. Listings are a maintained by read calling various listing_<foo> functions. What happens most is that the macro NO_LISTING is not defined (from the Makefile), then the macro LISTING_NEWLINE expands into a call to listing_newline. The call is done from read.c, every time it sees a newline, and -l is on the command line. The function listing_newline remembers the frag associated with the newline, and creates a new frag - note that this is wasteful, but not a big deal, since listing slows things down a lot anyway. The function also rememebers when the filename changes. When all the input has finished, and gas has had a chance to settle down, the listing is output. This is done by running down the list of frag/source file records, and opening the files as needed and printing out the bytes and chars associated with them. The only things which the architecture can change about the listing are defined in these macros: LISTING_HEADER The name of the architecture LISTING_WORD_SIZE The make of the number of bytes in a word, this determines the clumping of the output data. eg a value of 2 makes words look like 1234 5678, whilst 1 would make the same value look like 12 34 56 78 LISTING_LHS_WIDTH Number of words of above size for the lhs LISTING_LHS_WIDTH_SECOND Number of words for the data on the lhs for the second line LISTING_LHS_CONT_LINES Max number of lines to use up for a continutation LISTING_RHS_WIDTH Number of chars from the input file to print on a line*/#include <ctype.h>#include "as.h"#include <obstack.h>#include "input-file.h"#include "subsegs.h"#ifndef NO_LISTING#ifndef LISTING_HEADER#define LISTING_HEADER "GAS LISTING"#endif#ifndef LISTING_WORD_SIZE#define LISTING_WORD_SIZE 4#endif#ifndef LISTING_LHS_WIDTH#define LISTING_LHS_WIDTH ((LISTING_WORD_SIZE) > 4 ? 1 : 4 / (LISTING_WORD_SIZE))#endif#ifndef LISTING_LHS_WIDTH_SECOND#define LISTING_LHS_WIDTH_SECOND LISTING_LHS_WIDTH#endif#ifndef LISTING_RHS_WIDTH#define LISTING_RHS_WIDTH 100#endif#ifndef LISTING_LHS_CONT_LINES#define LISTING_LHS_CONT_LINES 4#endif/* This structure remembers which .s were used. */typedef struct file_info_struct { struct file_info_struct * next; char * filename; long pos; unsigned int linenum; int at_end;} file_info_type;/* This structure rememebrs which line from which file goes into which frag. */struct list_info_struct { /* Frag which this line of source is nearest to. */ fragS *frag; /* The actual line in the source file. */ unsigned int line; /* Pointer to the file info struct for the file which this line belongs to. */ file_info_type *file; /* The expanded text of any macro that may have been executing. */ char *line_contents; /* Next in list. */ struct list_info_struct *next; /* Pointer to the file info struct for the high level language source line that belongs here. */ file_info_type *hll_file; /* High level language source line. */ unsigned int hll_line; /* Pointer to any error message associated with this line. */ char *message; enum { EDICT_NONE, EDICT_SBTTL, EDICT_TITLE, EDICT_NOLIST, EDICT_LIST, EDICT_NOLIST_NEXT, EDICT_EJECT } edict; char *edict_arg; /* Nonzero if this line is to be omitted because it contains debugging information. This can become a flags field if we come up with more information to store here. */ int debugging;};typedef struct list_info_struct list_info_type;int listing_lhs_width = LISTING_LHS_WIDTH;int listing_lhs_width_second = LISTING_LHS_WIDTH_SECOND;int listing_lhs_cont_lines = LISTING_LHS_CONT_LINES;int listing_rhs_width = LISTING_RHS_WIDTH;struct list_info_struct * listing_tail;static file_info_type * file_info_head;static file_info_type * last_open_file_info;static FILE * last_open_file;static struct list_info_struct * head;static int paper_width = 200;static int paper_height = 60;extern int listing;/* File to output listings to. */static FILE *list_file;/* This static array is used to keep the text of data to be printed before the start of the line. */#define MAX_BYTES \ (((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width \ + ((((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second) \ * listing_lhs_cont_lines) \ + 20)static char *data_buffer;/* Prototypes. */static void listing_message PARAMS ((const char *name, const char *message));static file_info_type *file_info PARAMS ((const char *file_name));static void new_frag PARAMS ((void));static char *buffer_line PARAMS ((file_info_type *file, char *line, unsigned int size));static void listing_page PARAMS ((list_info_type *list));static unsigned int calc_hex PARAMS ((list_info_type *list));static void print_lines PARAMS ((list_info_type *, unsigned int, char *, unsigned int));static void list_symbol_table PARAMS ((void));static void print_source PARAMS ((file_info_type *current_file, list_info_type *list, char *buffer, unsigned int width));static int debugging_pseudo PARAMS ((list_info_type *, const char *));static void listing_listing PARAMS ((char *name));static voidlisting_message (name, message) const char *name; const char *message;{ if (listing_tail != (list_info_type *) NULL) { unsigned int l = strlen (name) + strlen (message) + 1; char *n = (char *) xmalloc (l); strcpy (n, name); strcat (n, message); listing_tail->message = n; }}voidlisting_warning (message) const char *message;{ listing_message (_("Warning:"), message);}voidlisting_error (message) const char *message;{ listing_message (_("Error:"), message);}static file_info_type *file_info (file_name) const char *file_name;{ /* Find an entry with this file name. */ file_info_type *p = file_info_head; while (p != (file_info_type *) NULL) { if (strcmp (p->filename, file_name) == 0) return p; p = p->next; } /* Make new entry. */ p = (file_info_type *) xmalloc (sizeof (file_info_type)); p->next = file_info_head; file_info_head = p; p->filename = xmalloc ((unsigned long) strlen (file_name) + 1); strcpy (p->filename, file_name); p->pos = 0; p->linenum = 0; p->at_end = 0; return p;}static voidnew_frag (){ frag_wane (frag_now); frag_new (0);}voidlisting_newline (ps) char *ps;{ char *file; unsigned int line; static unsigned int last_line = 0xffff; static char *last_file = NULL; list_info_type *new = NULL; if (listing == 0) return; if (now_seg == absolute_section) return;#ifdef OBJ_ELF /* In ELF, anything in a section beginning with .debug or .line is considered to be debugging information. This includes the statement which switches us into the debugging section, which we can only set after we are already in the debugging section. */ if ((listing & LISTING_NODEBUG) != 0 && listing_tail != NULL && ! listing_tail->debugging) { const char *segname; segname = segment_name (now_seg); if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0 || strncmp (segname, ".line", sizeof ".line" - 1) == 0) listing_tail->debugging = 1; }#endif as_where (&file, &line); if (ps == NULL) { if (line == last_line && !(last_file && file && strcmp (file, last_file))) return; new = (list_info_type *) xmalloc (sizeof (list_info_type)); /* Detect if we are reading from stdin by examining the file name returned by as_where(). [FIXME: We rely upon the name in the strcmp below being the same as the one used by input_scrub_new_file(), if that is not true, then this code will fail]. If we are reading from stdin, then we need to save each input line here (assuming of course that we actually have a line of input to read), so that it can be displayed in the listing that is produced at the end of the assembly. */ if (strcmp (file, _("{standard input}")) == 0 && input_line_pointer != NULL) { char *copy; int len; int seen_quote = 0; for (copy = input_line_pointer - 1; *copy && (seen_quote || (! is_end_of_line [(unsigned char) *copy])); copy++) if (*copy == '"' && copy[-1] != '\\') seen_quote = ! seen_quote; len = (copy - input_line_pointer) + 2; copy = xmalloc (len); if (copy != NULL) { char *src = input_line_pointer - 1; char *dest = copy; while (--len) { unsigned char c = *src++; /* Omit control characters in the listing. */ if (isascii (c) && ! iscntrl (c)) *dest++ = c; } *dest = 0; } new->line_contents = copy; } else new->line_contents = NULL; } else { new = (list_info_type *) xmalloc (sizeof (list_info_type)); new->line_contents = ps; } last_line = line; last_file = file; new_frag (); if (listing_tail) listing_tail->next = new; else head = new; listing_tail = new; new->frag = frag_now; new->line = line; new->file = file_info (file); new->next = (list_info_type *) NULL; new->message = (char *) NULL; new->edict = EDICT_NONE; new->hll_file = (file_info_type *) NULL; new->hll_line = 0; new->debugging = 0; new_frag ();#ifdef OBJ_ELF /* In ELF, anything in a section beginning with .debug or .line is considered to be debugging information. */ if ((listing & LISTING_NODEBUG) != 0) { const char *segname; segname = segment_name (now_seg); if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0 || strncmp (segname, ".line", sizeof ".line" - 1) == 0) new->debugging = 1; }#endif}/* Attach all current frags to the previous line instead of the current line. This is called by the MIPS backend when it discovers that it needs to add some NOP instructions; the added NOP instructions should go with the instruction that has the delay, not with the new instruction. */voidlisting_prev_line (){ list_info_type *l; fragS *f; if (head == (list_info_type *) NULL || head == listing_tail) return; new_frag (); for (l = head; l->next != listing_tail; l = l->next) ; for (f = frchain_now->frch_root; f != (fragS *) NULL; f = f->fr_next) if (f->line == listing_tail) f->line = l; listing_tail->frag = frag_now; new_frag ();}/* This function returns the next source line from the file supplied, truncated to size. It appends a fake line to the end of each input file to make. */static char *buffer_line (file, line, size) file_info_type *file; char *line; unsigned int size;{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?