104 #ifndef LISTING_HEADER
105 #define LISTING_HEADER "GAS LISTING"
107 #ifndef LISTING_WORD_SIZE
108 #define LISTING_WORD_SIZE 4
110 #ifndef LISTING_LHS_WIDTH
111 #define LISTING_LHS_WIDTH ((LISTING_WORD_SIZE) > 4 ? 1 : 4 / (LISTING_WORD_SIZE))
113 #ifndef LISTING_LHS_WIDTH_SECOND
114 #define LISTING_LHS_WIDTH_SECOND LISTING_LHS_WIDTH
116 #ifndef LISTING_RHS_WIDTH
117 #define LISTING_RHS_WIDTH 100
119 #ifndef LISTING_LHS_CONT_LINES
120 #define LISTING_LHS_CONT_LINES 4
122 #define MAX_DATELEN 30
202 static FILE * last_open_file;
204 static int paper_width = 200;
205 static int paper_height = 60;
210 static FILE *list_file;
216 (((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width \
217 + ((((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second) \
218 * listing_lhs_cont_lines) \
221 static char *data_buffer;
224 static void listing_message (
const char *,
const char *);
226 static void new_frag (
void);
229 static void print_lines (
list_info_type *,
unsigned int,
char *,
unsigned int);
230 static void list_symbol_table (
void);
232 static void listing_listing (
char *);
235 listing_message (
const char *
name,
const char *message)
258 listing_message (
_(
"Warning:"), message);
264 listing_message (
_(
"Error:"), message);
268 file_info (
const char *file_name)
282 p->
next = file_info_head;
304 static unsigned int last_line = 0xffff;
305 static char *last_file =
NULL;
320 && listing_tail !=
NULL
326 if (
strncmp (segname,
".debug",
sizeof ".debug" - 1) == 0
327 ||
strncmp (segname,
".line",
sizeof ".line" - 1) == 0)
335 if (line == last_line
336 && !(last_file && file &&
filename_cmp (file, last_file)))
352 if (strcmp (file,
_(
"{standard input}")) == 0
367 else if (*copy ==
'\\')
369 else if (*copy ==
'"')
370 seen_quote = !seen_quote;
384 unsigned char c = *src++;
411 listing_tail->
next = new_i;
415 listing_tail = new_i;
419 new_i->
file = file_info (file);
433 if ((
listing & LISTING_NODEBUG) != 0)
438 if (
strncmp (segname,
".debug",
sizeof ".debug" - 1) == 0
439 ||
strncmp (segname,
".line",
sizeof ".line" - 1) == 0)
458 || head == listing_tail)
467 if (f->
line == listing_tail)
481 unsigned int count = 0;
490 if (!last_open_file_info || file != last_open_file_info)
494 last_open_file_info->
pos = ftell (last_open_file);
495 fclose (last_open_file);
500 last_open_file_info = file;
502 if (last_open_file ==
NULL)
516 c = fgetc (last_open_file);
518 while (c != EOF && c !=
'\n' && c !=
'\r')
524 c = fgetc (last_open_file);
529 if (c ==
'\r' || c ==
'\n')
531 int next = fgetc (last_open_file);
533 if ((c ==
'\r' && next !=
'\n')
534 || (c ==
'\n' && next !=
'\r'))
535 ungetc (next, last_open_file);
541 if (count + 2 < size)
560 unsigned int linenum,
564 unsigned int count = 0;
565 unsigned int current_line = 1;
571 if (file ==
NULL || buffer ==
NULL || size == 0 || file->
linenum <= linenum)
575 if (last_open_file_info ==
NULL || file != last_open_file_info)
579 last_open_file_info->
pos = ftell (last_open_file);
580 fclose (last_open_file);
585 last_open_file_info = file;
587 if (last_open_file ==
NULL)
599 pos = ftell (last_open_file);
602 fseek (last_open_file, 0,
SEEK_SET);
605 while (current_line < linenum)
611 c = fgetc (last_open_file);
613 while (c != EOF && c !=
'\n' && c !=
'\r');
617 if (c ==
'\r' || c ==
'\n')
619 int next = fgetc (last_open_file);
623 if ((c ==
'\r' && next !=
'\n')
624 || (c ==
'\n' && next !=
'\r'))
625 ungetc (next, last_open_file);
633 c = fgetc (last_open_file);
635 while (c != EOF && c !=
'\n' && c !=
'\r')
641 c = fgetc (last_open_file);
646 if (c ==
'\r' || c ==
'\n')
648 int next = fgetc (last_open_file);
650 if ((c ==
'\r' && next !=
'\n')
651 || (c ==
'\n' && next !=
'\r'))
652 ungetc (next, last_open_file);
659 fseek (last_open_file, pos,
SEEK_SET);
664 static const char *fn;
666 static unsigned int eject;
667 static unsigned int page;
669 static char *subtitle;
670 static unsigned int on_page;
677 if ((eject || (on_page >= (
unsigned int) paper_height))
678 && paper_height != 0)
682 int had_subtitle = 0;
686 while (c != 0 && list)
708 fprintf (list_file,
"%s\n", title);
709 fprintf (list_file,
"%s\n", subtitle);
723 va_start (args, format);
735 int data_buffer_size;
740 unsigned int octet_in_frag;
744 while (frag && frag->
line != list)
749 data_buffer_size = 0;
752 while (frag_ptr != (
fragS *)
NULL && frag_ptr->
line == first)
759 if (address == ~(
unsigned int) 0)
762 sprintf (data_buffer + data_buffer_size,
764 (frag_ptr->
fr_literal[octet_in_frag]) & 0xff);
765 data_buffer_size += 2;
770 unsigned int var_rep_max = octet_in_frag;
771 unsigned int var_rep_idx = octet_in_frag;
774 while (((
offsetT) octet_in_frag
778 if (address == ~(
unsigned int) 0)
781 sprintf (data_buffer + data_buffer_size,
784 data_buffer_size += 2;
790 var_rep_idx = var_rep_max;
796 data_buffer[data_buffer_size] =
'\0';
802 char *
string,
unsigned int address)
807 unsigned int octet_in_word = 0;
808 char *
src = data_buffer;
817 if (address == ~(
unsigned int) 0)
819 fprintf (list_file,
"% 4d ", lineno);
820 for (idx = 0; idx < nchars; idx++)
823 emit_line (
NULL,
"\t%s\n",
string ?
string :
"");
828 fprintf (list_file,
"% 4d ???? ", lineno);
830 fprintf (list_file,
"% 4d %04x ", lineno, address);
835 while (src[cur] && idx < nchars)
839 fprintf (list_file,
"%c%c", src[offset], src[offset + 1]);
853 for (; idx < nchars; idx++)
856 emit_line (list,
"\t%s\n",
string ?
string :
"");
859 emit_line (list,
"**** %s\n", msg->
message);
870 fprintf (list_file,
"% 4d ", lineno);
872 while (src[cur] && idx < nchars)
876 fprintf (list_file,
"%c%c", src[offset], src[offset + 1]);
889 emit_line (list,
"\n");
894 list_symbol_table (
void)
914 char buf[30], fmt[8];
919 if (
sizeof (val) == 4 &&
sizeof (
int) == 4)
920 sprintf (buf,
"%08lx", (
unsigned long) val);
921 else if (
sizeof (val) <=
sizeof (
unsigned long))
923 sprintf (fmt,
"%%0%lulx",
924 (
unsigned long) (
sizeof (val) * 2));
925 sprintf (buf, fmt, (
unsigned long) val);
928 else if (
sizeof (val) > 4)
936 fprintf (list_file,
"DEFINED SYMBOLS\n");
943 fprintf (list_file,
"%20s:%-5d %s:%s %s\n",
951 fprintf (list_file,
"%33s:%s %s\n",
964 fprintf (list_file,
"NO DEFINED SYMBOLS\n");
967 emit_line (
NULL,
"\n");
981 emit_line (
NULL,
"UNDEFINED SYMBOLS\n");
990 emit_line (
NULL,
"NO UNDEFINED SYMBOLS\n");
1005 #define NUM_CACHE_LINES 3
1007 static int next_free_line = 0;
1033 if (cached_lines[i].file == current_file
1034 && cached_lines[i].line == list->
hll_line)
1036 cache = cached_lines +
i;
1040 if (i == NUM_CACHE_LINES)
1042 cache = cached_lines + next_free_line;
1044 if (next_free_line == NUM_CACHE_LINES)
1047 cache->
file = current_file;
1050 rebuffer_line (current_file, cache->
line, cache->
buffer, width);
1053 emit_line (list,
"%4u:%-13s **** %s\n",
1058 if (!current_file->
at_end)
1060 int num_lines_shown = 0;
1063 && !current_file->
at_end)
1067 cache = cached_lines + next_free_line;
1068 cache->
file = current_file;
1071 p = buffer_line (current_file, cache->
buffer, width);
1075 if (num_lines_shown == 0)
1078 if (next_free_line == NUM_CACHE_LINES)
1082 emit_line (list,
"%4u:%-13s **** %s\n",
1096 static int in_debug;
1108 was_debug = in_debug;
1138 if (
strncmp (line,
"def", 3) == 0)
1140 if (
strncmp (line,
"val", 3) == 0)
1142 if (
strncmp (line,
"scl", 3) == 0)
1144 if (
strncmp (line,
"line", 4) == 0)
1146 if (
strncmp (line,
"endef", 5) == 0)
1148 if (
strncmp (line,
"ln", 2) == 0)
1150 if (
strncmp (line,
"type", 4) == 0)
1152 if (
strncmp (line,
"size", 4) == 0)
1154 if (
strncmp (line,
"dim", 3) == 0)
1156 if (
strncmp (line,
"tag", 3) == 0)
1158 if (
strncmp (line,
"stabs", 5) == 0)
1160 if (
strncmp (line,
"stabn", 5) == 0)
1173 int show_listing = 1;
1183 unsigned int list_line;
1188 list_line = list->
line;
1189 switch (list->
edict)
1199 if (show_listing == 0)
1216 if (show_listing <= 0)
1220 p = buffer_line (list->
file, buffer, width);
1231 if (show_listing > 0)
1239 print_source (current_hll_file, list, width);
1259 p = buffer_line (list->
file, buffer, width);
1262 address = ~(
unsigned int) 0;
1264 address = calc_hex (list);
1266 if (!((
listing & LISTING_NODEBUG)
1267 && debugging_pseudo (list, p)))
1268 print_lines (list, list->
file->
linenum, p, address);
1290 print_timestamp (
void)
1293 struct tm * timestamp;
1297 timestamp = localtime (&now);
1298 strftime (stampstr,
MAX_DATELEN,
"%Y-%m-%dT%H:%M:%S.000%z", timestamp);
1299 fprintf (list_file,
_(
"\n time stamp \t: %s\n\n"), stampstr);
1303 print_single_option (
char * opt,
int *pos)
1305 int opt_len =
strlen (opt);
1307 if ((*pos + opt_len) < paper_width)
1309 fprintf (list_file,
_(
"%s "), opt);
1310 *pos = *pos + opt_len;
1314 fprintf (list_file,
_(
"\n\t%s "), opt);
1322 print_options (
char ** argv)
1324 const char *field_name =
_(
"\n options passed\t: ");
1325 int pos =
strlen (field_name);
1328 fputs (field_name, list_file);
1329 for (p = &argv[1]; *p !=
NULL; p++)
1333 if (strcmp (*p,
"-o") == 0)
1339 if (strcmp (*p,
"-v") == 0)
1342 print_single_option (*p, &pos);
1356 listing_general_info (
char ** argv)
1360 listing_page (
NULL);
1363 _(
" GNU assembler version %s (%s)\n\t using BFD version %s."),
1365 print_options (argv);
1366 fprintf (list_file,
_(
"\n input file \t: %s"), fn);
1368 fprintf (list_file,
_(
"\n target \t: %s"), TARGET_CANONICAL);
1387 list_file = fopen (name,
FOPEN_WT);
1388 if (list_file !=
NULL)
1402 listing_general_info (argv);
1405 listing_listing (name);
1408 list_symbol_table ();
1412 if (fclose (list_file) == EOF)
1417 fclose (last_open_file);
1474 if (paper_height < 0 || paper_height > 1000)
1477 as_warn (
_(
"strange paper height, set to no form"));
1527 length = input_line_pointer - start;
1528 ttl = (
char *)
xmalloc (length + 1);
1529 memcpy (ttl, start, length);
1535 input_line_pointer++;
1539 else if (*input_line_pointer ==
'\n')
1541 as_bad (
_(
"new line in title"));
1547 input_line_pointer++;
1567 listing_tail->
hll_file = file_info (file);