You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*
Contributed by Steve Chamberlain
#include "as.h"
#include <obstack.h>
#include "input-file.h"
+#include "subsegs.h"
#ifndef NO_LISTING
#ifndef LISTING_HEADER
int linenum;
FILE *file;
struct file_info_struct *next;
- int end_pending;
-
+ int at_end;
}
file_info_type;
static struct list_info_struct *head;
struct list_info_struct *listing_tail;
extern int listing;
-extern unsigned int physical_input_line;
extern fragS *frag_now;
static int paper_width = 200;
static int paper_height = 60;
+/* 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.
{
listing_tail->message = n;
}
-
}
-
-
-
void
listing_warning (message)
const char *message;
p = (file_info_type *) xmalloc (sizeof (file_info_type));
p->next = file_info_head;
file_info_head = p;
- p->filename = xmalloc (strlen (file_name) + 1);
+ p->filename = xmalloc ((unsigned long) strlen (file_name) + 1);
strcpy (p->filename, file_name);
p->linenum = 0;
- p->end_pending = 0;
+ p->at_end = 0;
- p->file = fopen (p->filename, "rb");
+ p->file = fopen (p->filename, "r");
if (p->file)
fgetc (p->file);
listing_newline (ps)
char *ps;
{
- extern char *file_name;
+ char *file;
+ unsigned int line;
static unsigned int last_line = 0xffff;
-
-
+ static char *last_file = NULL;
list_info_type *new;
- if (physical_input_line != last_line)
+
+ as_where (&file, &line);
+ if (line != last_line || (last_file && file && strcmp(file, last_file)))
{
- last_line = physical_input_line;
+ last_line = line;
+ last_file = file;
new_frag ();
new = (list_info_type *) xmalloc (sizeof (list_info_type));
new->frag = frag_now;
- new->line = physical_input_line;
- new->file = file_info (file_name);
+ new->line = line;
+ new->file = file_info (file);
if (listing_tail)
{
}
}
+/* 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. */
+
+void
+listing_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,
char *p = line;
/* If we couldn't open the file, return an empty line */
- if (file->file == (FILE *) NULL)
+ if (file->file == (FILE *) NULL || file->at_end)
{
return "";
}
if (file->linenum == 0)
rewind (file->file);
- if (file->end_pending == 10)
- {
- *p++ = '\n';
- fseek (file->file, 0, 0);
- file->linenum = 0;
- file->end_pending = 0;
- }
c = fgetc (file->file);
-
size -= 1; /* leave room for null */
while (c != EOF && c != '\n')
}
if (c == EOF)
{
- file->end_pending++;
+ file->at_end = 1;
*p++ = '.';
*p++ = '.';
*p++ = '.';
if (page > 1)
{
- printf ("\f");
+ fprintf (list_file, "\f");
}
- printf ("%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);
- printf ("%s\n", title);
- printf ("%s\n", subtitle);
+ 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;
}
list_info_type * list;
{
list_info_type *first = list;
- unsigned int address = ~0;
+ unsigned int address = (unsigned int) ~0;
fragS *frag;
fragS *frag_ptr;
- unsigned int byte_in_frag = 0;
+ unsigned int byte_in_frag;
/* Find first frag which says it belongs to this line */
while (frag_ptr != (fragS *) NULL && frag_ptr->line == first)
{
/* Print as many bytes from the fixed part as is sensible */
+ byte_in_frag = 0;
while (byte_in_frag < frag_ptr->fr_fix && data_buffer_size < sizeof (data_buffer) - 10)
{
if (address == ~0)
/* Print the hex for the first line */
if (address == ~0)
{
- printf ("% 4d ", list->line);
+ fprintf (list_file, "% 4d ", list->line);
for (idx = 0; idx < nchars; idx++)
- printf (" ");
+ fprintf (list_file, " ");
- printf ("\t%s\n", string ? string : "");
+ fprintf (list_file, "\t%s\n", string ? string : "");
on_page++;
listing_page (0);
{
if (had_errors ())
{
- printf ("% 4d ???? ", list->line);
+ fprintf (list_file, "% 4d ???? ", list->line);
}
else
{
- printf ("% 4d %04x ", list->line, address);
+ fprintf (list_file, "% 4d %04x ", list->line, address);
}
/* And the data to go along with it */
while (*src && idx < nchars)
{
- printf ("%c%c", src[0], src[1]);
+ fprintf (list_file, "%c%c", src[0], src[1]);
src += 2;
byte_in_word++;
if (byte_in_word == LISTING_WORD_SIZE)
{
- printf (" ");
+ fprintf (list_file, " ");
idx++;
byte_in_word = 0;
}
}
for (; idx < nchars; idx++)
- printf (" ");
+ fprintf (list_file, " ");
- printf ("\t%s\n", string ? string : "");
+ fprintf (list_file, "\t%s\n", string ? string : "");
on_page++;
listing_page (list);
if (list->message)
{
- printf ("**** %s\n", list->message);
+ fprintf (list_file, "**** %s\n", list->message);
listing_page (list);
on_page++;
}
nchars = ((LISTING_WORD_SIZE * 2) + 1) * LISTING_LHS_WIDTH_SECOND - 1;
idx = 0;
/* Print any more lines of data, but more compactly */
- printf ("% 4d ", list->line);
+ fprintf (list_file, "% 4d ", list->line);
while (*src && idx < nchars)
{
- printf ("%c%c", src[0], src[1]);
+ fprintf (list_file, "%c%c", src[0], src[1]);
src += 2;
idx += 2;
byte_in_word++;
if (byte_in_word == LISTING_WORD_SIZE)
{
- printf (" ");
+ fprintf (list_file, " ");
idx++;
byte_in_word = 0;
}
}
- printf ("\n");
+ fprintf (list_file, "\n");
on_page++;
listing_page (list);
list_symbol_table ()
{
extern symbolS *symbol_rootP;
+ int got_some = 0;
symbolS *ptr;
eject = 1;
listing_page (0);
- printf ("DEFINED SYMBOLS\n");
- on_page++;
for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
{
{
if (S_GET_NAME (ptr))
{
- char buf[30];
+ 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);
-#if defined (BFD_ASSEMBLER) && defined (BFD64)
+ 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)
{
char buf1[30];
else
abort ();
- printf ("%20s:%-5d %s:%s %s\n",
- ptr->sy_frag->line->file->filename,
- ptr->sy_frag->line->line,
- segment_name (S_GET_SEGMENT (ptr)),
- buf, S_GET_NAME (ptr));
+ if (!got_some)
+ {
+ fprintf (list_file, "DEFINED SYMBOLS\n");
+ on_page++;
+ got_some = 1;
+ }
+
+ fprintf (list_file, "%20s:%-5d %s:%s %s\n",
+ ptr->sy_frag->line->file->filename,
+ ptr->sy_frag->line->line,
+ segment_name (S_GET_SEGMENT (ptr)),
+ buf, S_GET_NAME (ptr));
on_page++;
listing_page (0);
}
}
- printf ("\n");
- on_page++;
- listing_page (0);
- printf ("UNDEFINED SYMBOLS\n");
+ 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 (ptr->sy_frag->line == 0)
+ if (ptr->sy_frag->line == 0
+#ifdef S_IS_REGISTER
+ && !S_IS_REGISTER (ptr)
+#endif
+ && S_GET_SEGMENT (ptr) != reg_section)
{
- printf ("%s\n", S_GET_NAME (ptr));
+ 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 void
{
if (current_file->file)
{
- while (current_file->linenum < list->hll_line)
+ while (current_file->linenum < list->hll_line
+ && !current_file->at_end)
{
char *p = buffer_line (current_file, buffer, width);
- printf ("%4d:%-13s **** %s\n", current_file->linenum, current_file->filename, p);
+ fprintf (list_file, "%4d:%-13s **** %s\n", current_file->linenum,
+ current_file->filename, p);
on_page++;
listing_page (list);
}
print_source (current_hll_file, list, buffer, width);
}
- p = buffer_line (list->file, buffer, width);
-
- if (!((listing & LISTING_NODEBUG) && debugging_pseudo (p)))
+ while (list->file->file
+ && list->file->linenum < list->line
+ && !list->file->at_end)
{
- print_lines (list, p, calc_hex (list));
+ p = buffer_line (list->file, buffer, width);
+
+ if (!((listing & LISTING_NODEBUG) && debugging_pseudo (p)))
+ {
+ print_lines (list, p, calc_hex (list));
+ }
}
if (list->edict == EDICT_EJECT)
}
else
{
-
- p = buffer_line (list->file, buffer, width);
+ while (list->file->file
+ && list->file->linenum < list->line
+ && !list->file->at_end)
+ p = buffer_line (list->file, buffer, width);
}
list = list->next;
title = "";
subtitle = "";
+ if (name == NULL)
+ list_file = stdout;
+ else
+ {
+ list_file = fopen (name, "w");
+ if (list_file == NULL)
+ {
+ as_perror ("can't open list file: %s", name);
+ list_file = stdout;
+ }
+ }
+
if (listing & LISTING_NOFORM)
{
paper_height = 0;
}
void
-listing_eject ()
+listing_eject (ignore)
+ int ignore;
{
listing_tail->edict = EDICT_EJECT;
}
void
-listing_flags ()
+listing_flags (ignore)
+ int ignore;
{
while ((*input_line_pointer++) && (*input_line_pointer != '\n'))
input_line_pointer++;
void
listing_list (on)
- unsigned int on;
+ int on;
{
listing_tail->edict = on ? EDICT_LIST : EDICT_NOLIST;
}
void
-listing_psize ()
+listing_psize (width_only)
+ int width_only;
{
- paper_height = get_absolute_expression ();
-
- if (paper_height < 0 || paper_height > 1000)
+ if (! width_only)
{
- paper_height = 0;
- as_warn ("strange paper height, set to no form");
- }
- if (*input_line_pointer == ',')
- {
- input_line_pointer++;
- paper_width = get_absolute_expression ();
+ paper_height = get_absolute_expression ();
+
+ if (paper_height < 0 || paper_height > 1000)
+ {
+ paper_height = 0;
+ as_warn ("strange paper height, set to no form");
+ }
+
+ if (*input_line_pointer != ',')
+ {
+ demand_empty_rest_of_line ();
+ return;
+ }
+
+ ++input_line_pointer;
}
-}
+ paper_width = get_absolute_expression ();
+
+ demand_empty_rest_of_line ();
+}
void
listing_title (depth)
- unsigned int depth;
+ int depth;
{
char *start;
- char *title;
+ char *ttl;
unsigned int length;
SKIP_WHITESPACE ();
if (*input_line_pointer == '\"')
{
length = input_line_pointer - start;
- title = xmalloc (length + 1);
- memcpy (title, start, length);
- title[length] = 0;
+ ttl = xmalloc (length + 1);
+ memcpy (ttl, start, length);
+ ttl[length] = 0;
listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE;
- listing_tail->edict_arg = title;
+ listing_tail->edict_arg = ttl;
input_line_pointer++;
demand_empty_rest_of_line ();
return;
listing_source_file (file)
const char *file;
{
- listing_tail->hll_file = file_info (file);
+ if (listing_tail)
+ listing_tail->hll_file = file_info (file);
}
/* Dummy functions for when compiled without listing enabled */
void
-listing_flags ()
+listing_flags (ignore)
+ int ignore;
{
s_ignore (0);
}
void
listing_list (on)
- unsigned int on;
+ int on;
{
s_ignore (0);
}
void
-listing_eject ()
+listing_eject (ignore)
+ int ignore;
{
s_ignore (0);
}
void
-listing_psize ()
+listing_psize (ignore)
+ int ignore;
{
s_ignore (0);
}
void
listing_title (depth)
- unsigned int depth;
+ int depth;
{
s_ignore (0);
}