* listing.c (listing_psize): Treat argument as indicating whether
[deliverable/binutils-gdb.git] / gas / listing.c
CommitLineData
5d9f0ecf
SC
1/* listing.c - mainting assembly listings
2 Copyright (C) 1991, 1992 Free Software Foundation, Inc.
c593cf41
SC
3
4This file is part of GAS, the GNU Assembler.
5
6GAS is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GAS is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GAS; see the file COPYING. If not, write to
51a3bc15 18the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
5d9f0ecf
SC
19
20/*
c593cf41
SC
21 Contributed by Steve Chamberlain
22 sac@cygnus.com
23
24
25 A listing page looks like:
58d4951d 26
c593cf41
SC
27 LISTING_HEADER sourcefilename pagenumber
28 TITLE LINE
29 SUBTITLE LINE
30 linenumber address data source
31 linenumber address data source
32 linenumber address data source
33 linenumber address data source
34
35 If not overridden, the listing commands are:
36
58d4951d
ILT
37 .title "stuff"
38 Put "stuff" onto the title line
c593cf41
SC
39 .sbttl "stuff"
40 Put stuff onto the subtitle line
41
5d9f0ecf
SC
42 If these commands come within 10 lines of the top of the page, they
43 will affect the page they are on, as well as any subsequent page
c593cf41
SC
44
45 .eject
46 Thow a page
47 .list
48 Increment the enable listing counter
49 .nolist
50 Decrement the enable listing counter
51
52 .psize Y[,X]
53 Set the paper size to X wide and Y high. Setting a psize Y of
54 zero will suppress form feeds except where demanded by .eject
55
58d4951d 56 If the counter goes below zero, listing is suppressed.
c593cf41
SC
57
58
59 Listings are a maintained by read calling various listing_<foo>
60 functions. What happens most is that the macro NO_LISTING is not
61 defined (from the Makefile), then the macro LISTING_NEWLINE expands
62 into a call to listing_newline. The call is done from read.c, every
63 time it sees a newline, and -l is on the command line.
64
65 The function listing_newline remembers the frag associated with the
66 newline, and creates a new frag - note that this is wasteful, but not
67 a big deal, since listing slows things down a lot anyway. The
68 function also rememebers when the filename changes.
69
70 When all the input has finished, and gas has had a chance to settle
71 down, the listing is output. This is done by running down the list of
72 frag/source file records, and opening the files as needed and printing
73 out the bytes and chars associated with them.
74
75 The only things which the architecture can change about the listing
76 are defined in these macros:
77
78 LISTING_HEADER The name of the architecture
79 LISTING_WORD_SIZE The make of the number of bytes in a word, this determines
80 the clumping of the output data. eg a value of
81 2 makes words look like 1234 5678, whilst 1
82 would make the same value look like 12 34 56
83 78
84 LISTING_LHS_WIDTH Number of words of above size for the lhs
85
86 LISTING_LHS_WIDTH_SECOND Number of words for the data on the lhs
87 for the second line
88
89 LISTING_LHS_CONT_LINES Max number of lines to use up for a continutation
90 LISTING_RHS_WIDTH Number of chars from the input file to print
91 on a line
92*/
5d9f0ecf 93
58d4951d
ILT
94#include <ctype.h>
95
5d9f0ecf
SC
96#include "as.h"
97#include <obstack.h>
98#include "input-file.h"
e860dfd0 99#include "subsegs.h"
7143f43c 100
5d9f0ecf
SC
101#ifndef NO_LISTING
102#ifndef LISTING_HEADER
103#define LISTING_HEADER "GAS LISTING"
104#endif
105#ifndef LISTING_WORD_SIZE
106#define LISTING_WORD_SIZE 4
107#endif
108#ifndef LISTING_LHS_WIDTH
109#define LISTING_LHS_WIDTH 1
110#endif
111#ifndef LISTING_LHS_WIDTH_SECOND
112#define LISTING_LHS_WIDTH_SECOND 1
113#endif
114#ifndef LISTING_RHS_WIDTH
115#define LISTING_RHS_WIDTH 100
116#endif
58d4951d 117#ifndef LISTING_LHS_CONT_LINES
5d9f0ecf
SC
118#define LISTING_LHS_CONT_LINES 4
119#endif
120
121
c593cf41
SC
122
123
b3ca913f 124/* This structure remembers which .s were used */
58d4951d 125typedef struct file_info_struct
c593cf41
SC
126{
127 char *filename;
128 int linenum;
129 FILE *file;
130 struct file_info_struct *next;
bcaa9b05 131 int at_end;
58d4951d
ILT
132}
133
134file_info_type;
135
136
c593cf41
SC
137/* this structure rememebrs which line from which file goes into which
138 frag */
139typedef struct list_info_struct
140{
141 /* Frag which this line of source is nearest to */
142 fragS *frag;
143 /* The actual line in the source file */
144 unsigned int line;
145 /* Pointer to the file info struct for the file which this line
146 belongs to */
147 file_info_type *file;
148
149 /* Next in list */
150 struct list_info_struct *next;
a39116f1 151
c593cf41
SC
152
153 /* Pointer to the file info struct for the high level language
154 source line that belongs here */
155 file_info_type *hll_file;
58d4951d 156
c593cf41
SC
157 /* High level language source line */
158 int hll_line;
58d4951d 159
c593cf41
SC
160
161 /* Pointer to any error message associated with this line */
162 char *message;
58d4951d
ILT
163
164 enum
165 {
166 EDICT_NONE,
167 EDICT_SBTTL,
168 EDICT_TITLE,
169 EDICT_NOLIST,
170 EDICT_LIST,
171 EDICT_EJECT
172 } edict;
c593cf41 173 char *edict_arg;
58d4951d
ILT
174
175}
176
177list_info_type;
5d9f0ecf 178
c593cf41 179
5d9f0ecf
SC
180static struct list_info_struct *head;
181struct list_info_struct *listing_tail;
182extern int listing;
5d9f0ecf
SC
183extern fragS *frag_now;
184
c593cf41 185
5d9f0ecf
SC
186static int paper_width = 200;
187static int paper_height = 60;
188
85a961c6
ILT
189/* File to output listings to. */
190static FILE *list_file;
c593cf41 191
5d9f0ecf 192/* this static array is used to keep the text of data to be printed
c593cf41
SC
193 before the start of the line.
194 It is stored so we can give a bit more info on the next line. To much, and large
195 initialized arrays will use up lots of paper.
196 */
5d9f0ecf
SC
197
198static char data_buffer[100];
199static unsigned int data_buffer_size;
200
58d4951d
ILT
201
202/* Prototypes. */
203static void listing_message PARAMS ((const char *name, const char *message));
204static file_info_type *file_info PARAMS ((const char *file_name));
205static void new_frag PARAMS ((void));
206static char *buffer_line PARAMS ((file_info_type *file,
207 char *line, unsigned int size));
208static void listing_page PARAMS ((list_info_type *list));
209static unsigned int calc_hex PARAMS ((list_info_type *list));
210static void print_lines PARAMS ((list_info_type *list,
211 char *string,
212 unsigned int address));
213static void list_symbol_table PARAMS ((void));
214static void print_source PARAMS ((file_info_type *current_file,
215 list_info_type *list,
216 char *buffer,
217 unsigned int width));
218static int debugging_pseudo PARAMS ((char *line));
219static void listing_listing PARAMS ((char *name));
220
221
5d9f0ecf 222static void
58d4951d
ILT
223listing_message (name, message)
224 const char *name;
225 const char *message;
c593cf41 226{
58d4951d
ILT
227 unsigned int l = strlen (name) + strlen (message) + 1;
228 char *n = (char *) xmalloc (l);
229 strcpy (n, name);
230 strcat (n, message);
231 if (listing_tail != (list_info_type *) NULL)
232 {
233 listing_tail->message = n;
234 }
c593cf41
SC
235}
236
58d4951d
ILT
237void
238listing_warning (message)
239 const char *message;
5d9f0ecf 240{
58d4951d 241 listing_message ("Warning:", message);
5d9f0ecf
SC
242}
243
58d4951d
ILT
244void
245listing_error (message)
246 const char *message;
5d9f0ecf 247{
58d4951d 248 listing_message ("Error:", message);
5d9f0ecf
SC
249}
250
c593cf41
SC
251
252
253
5d9f0ecf
SC
254static file_info_type *file_info_head;
255
256static file_info_type *
58d4951d
ILT
257file_info (file_name)
258 const char *file_name;
5d9f0ecf 259{
c593cf41
SC
260 /* Find an entry with this file name */
261 file_info_type *p = file_info_head;
58d4951d
ILT
262
263 while (p != (file_info_type *) NULL)
264 {
265 if (strcmp (p->filename, file_name) == 0)
266 return p;
267 p = p->next;
268 }
c593cf41
SC
269
270 /* Make new entry */
271
58d4951d 272 p = (file_info_type *) xmalloc (sizeof (file_info_type));
c593cf41
SC
273 p->next = file_info_head;
274 file_info_head = p;
e860dfd0 275 p->filename = xmalloc ((unsigned long) strlen (file_name) + 1);
58d4951d 276 strcpy (p->filename, file_name);
c593cf41 277 p->linenum = 0;
bcaa9b05 278 p->at_end = 0;
7143f43c 279
f949f7b8 280 p->file = fopen (p->filename, "r");
58d4951d
ILT
281 if (p->file)
282 fgetc (p->file);
7143f43c 283
c593cf41 284 return p;
c593cf41 285}
5d9f0ecf
SC
286
287
58d4951d
ILT
288static void
289new_frag ()
b3ca913f 290{
58d4951d
ILT
291
292 frag_wane (frag_now);
293 frag_new (0);
c593cf41 294
b3ca913f
SC
295}
296
58d4951d
ILT
297void
298listing_newline (ps)
299 char *ps;
5d9f0ecf 300{
e860dfd0
KR
301 char *file;
302 unsigned int line;
58d4951d 303 static unsigned int last_line = 0xffff;
f949f7b8 304 static char *last_file = NULL;
c593cf41 305 list_info_type *new;
e860dfd0
KR
306
307 as_where (&file, &line);
bcaa9b05 308 if (line != last_line || (last_file && file && strcmp(file, last_file)))
c593cf41 309 {
e860dfd0 310 last_line = line;
f949f7b8 311 last_file = file;
58d4951d
ILT
312 new_frag ();
313
314 new = (list_info_type *) xmalloc (sizeof (list_info_type));
315 new->frag = frag_now;
e860dfd0
KR
316 new->line = line;
317 new->file = file_info (file);
58d4951d
ILT
318
319 if (listing_tail)
320 {
321 listing_tail->next = new;
322 }
323 else
324 {
325 head = new;
326 }
327 listing_tail = new;
328 new->next = (list_info_type *) NULL;
329 new->message = (char *) NULL;
330 new->edict = EDICT_NONE;
331 new->hll_file = (file_info_type *) NULL;
332 new->hll_line = 0;
333 new_frag ();
c593cf41 334 }
c593cf41 335}
5d9f0ecf 336
e860dfd0
KR
337/* Attach all current frags to the previous line instead of the
338 current line. This is called by the MIPS backend when it discovers
339 that it needs to add some NOP instructions; the added NOP
340 instructions should go with the instruction that has the delay, not
341 with the new instruction. */
342
343void
344listing_prev_line ()
345{
346 list_info_type *l;
347 fragS *f;
348
349 if (head == (list_info_type *) NULL
350 || head == listing_tail)
351 return;
352
353 new_frag ();
354
355 for (l = head; l->next != listing_tail; l = l->next)
356 ;
357
358 for (f = frchain_now->frch_root; f != (fragS *) NULL; f = f->fr_next)
359 if (f->line == listing_tail)
360 f->line = l;
361
362 listing_tail->frag = frag_now;
363 new_frag ();
364}
3340f7e5 365
58d4951d 366/*
c593cf41
SC
367 This function returns the next source line from the file supplied,
368 truncated to size. It appends a fake line to the end of each input
369 file to make
370*/
5d9f0ecf
SC
371
372static char *
58d4951d
ILT
373buffer_line (file, line, size)
374 file_info_type * file;
375 char *line;
376 unsigned int size;
5d9f0ecf 377{
c593cf41
SC
378 unsigned int count = 0;
379 int c;
58d4951d 380
c593cf41
SC
381 char *p = line;
382
383 /* If we couldn't open the file, return an empty line */
bcaa9b05 384 if (file->file == (FILE *) NULL || file->at_end)
58d4951d
ILT
385 {
386 return "";
387 }
c593cf41 388
ab737e51 389 if (file->linenum == 0)
58d4951d 390 rewind (file->file);
ab737e51 391
58d4951d
ILT
392 c = fgetc (file->file);
393
c593cf41
SC
394 size -= 1; /* leave room for null */
395
58d4951d
ILT
396 while (c != EOF && c != '\n')
397 {
398 if (count < size)
399 *p++ = c;
400 count++;
401
402 c = fgetc (file->file);
403
404 }
405 if (c == EOF)
406 {
bcaa9b05 407 file->at_end = 1;
58d4951d
ILT
408 *p++ = '.';
409 *p++ = '.';
410 *p++ = '.';
411 }
412 file->linenum++;
c593cf41
SC
413 *p++ = 0;
414 return line;
415}
416
5d9f0ecf 417
58d4951d 418static const char *fn;
5d9f0ecf
SC
419
420static unsigned int eject; /* Eject pending */
58d4951d
ILT
421static unsigned int page; /* Current page number */
422static char *title; /* current title */
5d9f0ecf 423static char *subtitle; /* current subtitle */
58d4951d 424static unsigned int on_page; /* number of lines printed on current page */
5d9f0ecf 425
3340f7e5 426
c593cf41 427static void
58d4951d
ILT
428listing_page (list)
429 list_info_type *list;
c593cf41
SC
430{
431 /* Grope around, see if we can see a title or subtitle edict coming up
432 soon (we look down 10 lines of the page and see if it's there)*/
58d4951d 433 if ((eject || (on_page >= paper_height)) && paper_height != 0)
c593cf41 434 {
58d4951d
ILT
435 unsigned int c = 10;
436 int had_title = 0;
437 int had_subtitle = 0;
c593cf41 438
58d4951d
ILT
439 page++;
440
441 while (c != 0 && list)
442 {
443 if (list->edict == EDICT_SBTTL && !had_subtitle)
444 {
445 had_subtitle = 1;
446 subtitle = list->edict_arg;
447 }
448 if (list->edict == EDICT_TITLE && !had_title)
449 {
450 had_title = 1;
451 title = list->edict_arg;
452 }
453 list = list->next;
454 c--;
455 }
456
457
458 if (page > 1)
459 {
85a961c6 460 fprintf (list_file, "\f");
58d4951d
ILT
461 }
462
85a961c6
ILT
463 fprintf (list_file, "%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);
464 fprintf (list_file, "%s\n", title);
465 fprintf (list_file, "%s\n", subtitle);
58d4951d
ILT
466 on_page = 3;
467 eject = 0;
c593cf41 468 }
c593cf41 469}
5d9f0ecf
SC
470
471
58d4951d
ILT
472static unsigned int
473calc_hex (list)
474 list_info_type * list;
5d9f0ecf 475{
c593cf41 476 list_info_type *first = list;
e860dfd0 477 unsigned int address = (unsigned int) ~0;
58d4951d 478
c593cf41
SC
479 fragS *frag;
480 fragS *frag_ptr;
481
e860dfd0 482 unsigned int byte_in_frag;
58d4951d 483
c593cf41
SC
484
485 /* Find first frag which says it belongs to this line */
58d4951d
ILT
486 frag = list->frag;
487 while (frag && frag->line != list)
488 frag = frag->fr_next;
c593cf41
SC
489
490 frag_ptr = frag;
491
492 data_buffer_size = 0;
58d4951d 493
c593cf41 494 /* Dump all the frags which belong to this line */
58d4951d 495 while (frag_ptr != (fragS *) NULL && frag_ptr->line == first)
c593cf41 496 {
58d4951d 497 /* Print as many bytes from the fixed part as is sensible */
e860dfd0 498 byte_in_frag = 0;
58d4951d
ILT
499 while (byte_in_frag < frag_ptr->fr_fix && data_buffer_size < sizeof (data_buffer) - 10)
500 {
501 if (address == ~0)
502 {
503 address = frag_ptr->fr_address;
504 }
505
506 sprintf (data_buffer + data_buffer_size,
507 "%02X",
508 (frag_ptr->fr_literal[byte_in_frag]) & 0xff);
509 data_buffer_size += 2;
510 byte_in_frag++;
511 }
c593cf41 512 {
58d4951d
ILT
513 unsigned int var_rep_max = byte_in_frag;
514 unsigned int var_rep_idx = byte_in_frag;
515
516 /* Print as many bytes from the variable part as is sensible */
517 while (byte_in_frag < frag_ptr->fr_var * frag_ptr->fr_offset
518 && data_buffer_size < sizeof (data_buffer) - 10)
519 {
520 if (address == ~0)
521 {
522 address = frag_ptr->fr_address;
523 }
524 sprintf (data_buffer + data_buffer_size,
525 "%02X",
526 (frag_ptr->fr_literal[var_rep_idx]) & 0xff);
527#if 0
528 data_buffer[data_buffer_size++] = '*';
529 data_buffer[data_buffer_size++] = '*';
c593cf41 530#endif
58d4951d
ILT
531 data_buffer_size += 2;
532
533 var_rep_idx++;
534 byte_in_frag++;
535
536 if (var_rep_idx >= frag_ptr->fr_var)
537 var_rep_idx = var_rep_max;
538 }
539 }
540
541 frag_ptr = frag_ptr->fr_next;
c593cf41 542 }
c593cf41
SC
543 data_buffer[data_buffer_size++] = 0;
544 return address;
545}
546
547
548
549
550
5d9f0ecf
SC
551
552static void
58d4951d
ILT
553print_lines (list, string, address)
554 list_info_type *list;
555 char *string;
556 unsigned int address;
c593cf41
SC
557{
558 unsigned int idx;
559 unsigned int nchars;
560 unsigned int lines;
58d4951d 561 unsigned int byte_in_word = 0;
c593cf41 562 char *src = data_buffer;
58d4951d 563
c593cf41 564 /* Print the stuff on the first line */
58d4951d
ILT
565 listing_page (list);
566 nchars = (LISTING_WORD_SIZE * 2 + 1) * LISTING_LHS_WIDTH;
c593cf41 567 /* Print the hex for the first line */
58d4951d 568 if (address == ~0)
c593cf41 569 {
85a961c6 570 fprintf (list_file, "% 4d ", list->line);
58d4951d 571 for (idx = 0; idx < nchars; idx++)
85a961c6 572 fprintf (list_file, " ");
58d4951d 573
85a961c6 574 fprintf (list_file, "\t%s\n", string ? string : "");
c593cf41 575 on_page++;
58d4951d
ILT
576 listing_page (0);
577
c593cf41 578 }
58d4951d
ILT
579 else
580 {
581 if (had_errors ())
582 {
85a961c6 583 fprintf (list_file, "% 4d ???? ", list->line);
58d4951d
ILT
584 }
585 else
586 {
85a961c6 587 fprintf (list_file, "% 4d %04x ", list->line, address);
58d4951d 588 }
c593cf41 589
58d4951d
ILT
590 /* And the data to go along with it */
591 idx = 0;
592
593 while (*src && idx < nchars)
c593cf41 594 {
85a961c6 595 fprintf (list_file, "%c%c", src[0], src[1]);
58d4951d 596 src += 2;
c593cf41 597 byte_in_word++;
58d4951d
ILT
598 if (byte_in_word == LISTING_WORD_SIZE)
599 {
85a961c6 600 fprintf (list_file, " ");
58d4951d
ILT
601 idx++;
602 byte_in_word = 0;
603 }
604 idx += 2;
c593cf41 605 }
c593cf41 606
58d4951d 607 for (; idx < nchars; idx++)
85a961c6 608 fprintf (list_file, " ");
58d4951d 609
85a961c6 610 fprintf (list_file, "\t%s\n", string ? string : "");
58d4951d
ILT
611 on_page++;
612 listing_page (list);
613 if (list->message)
614 {
85a961c6 615 fprintf (list_file, "**** %s\n", list->message);
58d4951d
ILT
616 listing_page (list);
617 on_page++;
618 }
c593cf41 619
58d4951d
ILT
620 for (lines = 0;
621 lines < LISTING_LHS_CONT_LINES
622 && *src;
623 lines++)
624 {
625 nchars = ((LISTING_WORD_SIZE * 2) + 1) * LISTING_LHS_WIDTH_SECOND - 1;
626 idx = 0;
627 /* Print any more lines of data, but more compactly */
85a961c6 628 fprintf (list_file, "% 4d ", list->line);
58d4951d
ILT
629
630 while (*src && idx < nchars)
631 {
85a961c6 632 fprintf (list_file, "%c%c", src[0], src[1]);
58d4951d
ILT
633 src += 2;
634 idx += 2;
635 byte_in_word++;
636 if (byte_in_word == LISTING_WORD_SIZE)
637 {
85a961c6 638 fprintf (list_file, " ");
58d4951d
ILT
639 idx++;
640 byte_in_word = 0;
641 }
642 }
643
85a961c6 644 fprintf (list_file, "\n");
58d4951d
ILT
645 on_page++;
646 listing_page (list);
647
648 }
649
650
651 }
652}
5d9f0ecf
SC
653
654
655static void
58d4951d 656list_symbol_table ()
5d9f0ecf 657{
c593cf41 658 extern symbolS *symbol_rootP;
f949f7b8 659 int got_some = 0;
58d4951d
ILT
660
661 symbolS *ptr;
c593cf41 662 eject = 1;
58d4951d 663 listing_page (0);
58d4951d
ILT
664
665 for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
c593cf41 666 {
58d4951d
ILT
667 if (ptr->sy_frag->line)
668 {
669 if (S_GET_NAME (ptr))
670 {
f949f7b8 671 char buf[30], fmt[8];
58d4951d
ILT
672 valueT val = S_GET_VALUE (ptr);
673
674 /* @@ Note that this is dependent on the compilation options,
675 not solely on the target characteristics. */
676 if (sizeof (val) == 4 && sizeof (int) == 4)
677 sprintf (buf, "%08lx", (unsigned long) val);
f949f7b8
KR
678 else if (sizeof (val) <= sizeof (unsigned long))
679 {
bcaa9b05
ILT
680 sprintf (fmt, "%%0%lulx",
681 (unsigned long) (sizeof (val) * 2));
f949f7b8
KR
682 sprintf (buf, fmt, (unsigned long) val);
683 }
684#if defined (BFD64)
58d4951d
ILT
685 else if (sizeof (val) > 4)
686 {
687 char buf1[30];
688 sprintf_vma (buf1, val);
689 strcpy (buf, "00000000");
690 strcpy (buf + 8 - strlen (buf1), buf1);
691 }
692#endif
693 else
694 abort ();
695
f949f7b8
KR
696 if (!got_some)
697 {
85a961c6 698 fprintf (list_file, "DEFINED SYMBOLS\n");
f949f7b8
KR
699 on_page++;
700 got_some = 1;
701 }
702
85a961c6
ILT
703 fprintf (list_file, "%20s:%-5d %s:%s %s\n",
704 ptr->sy_frag->line->file->filename,
705 ptr->sy_frag->line->line,
706 segment_name (S_GET_SEGMENT (ptr)),
707 buf, S_GET_NAME (ptr));
58d4951d
ILT
708
709 on_page++;
710 listing_page (0);
711 }
712 }
c593cf41 713
c593cf41 714 }
f949f7b8
KR
715 if (!got_some)
716 {
85a961c6 717 fprintf (list_file, "NO DEFINED SYMBOLS\n");
f949f7b8
KR
718 on_page++;
719 }
85a961c6 720 fprintf (list_file, "\n");
c593cf41 721 on_page++;
58d4951d 722 listing_page (0);
f949f7b8
KR
723
724 got_some = 0;
58d4951d
ILT
725
726 for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
c593cf41 727 {
58d4951d
ILT
728 if (S_GET_NAME (ptr) && strlen (S_GET_NAME (ptr)) != 0)
729 {
e860dfd0 730 if (ptr->sy_frag->line == 0
f949f7b8
KR
731#ifdef S_IS_REGISTER
732 && !S_IS_REGISTER (ptr)
733#endif
e860dfd0 734 && S_GET_SEGMENT (ptr) != reg_section)
58d4951d 735 {
f949f7b8
KR
736 if (!got_some)
737 {
738 got_some = 1;
85a961c6 739 fprintf (list_file, "UNDEFINED SYMBOLS\n");
f949f7b8
KR
740 on_page++;
741 listing_page (0);
742 }
85a961c6 743 fprintf (list_file, "%s\n", S_GET_NAME (ptr));
58d4951d
ILT
744 on_page++;
745 listing_page (0);
746 }
747 }
c593cf41 748 }
f949f7b8
KR
749 if (!got_some)
750 {
85a961c6 751 fprintf (list_file, "NO UNDEFINED SYMBOLS\n");
f949f7b8
KR
752 on_page++;
753 listing_page (0);
754 }
c593cf41 755}
5d9f0ecf 756
58d4951d
ILT
757static void
758print_source (current_file, list, buffer, width)
759 file_info_type *current_file;
760 list_info_type *list;
761 char *buffer;
762 unsigned int width;
c593cf41 763{
58d4951d
ILT
764 if (current_file->file)
765 {
f949f7b8 766 while (current_file->linenum < list->hll_line
bcaa9b05 767 && !current_file->at_end)
58d4951d
ILT
768 {
769 char *p = buffer_line (current_file, buffer, width);
85a961c6
ILT
770 fprintf (list_file, "%4d:%-13s **** %s\n", current_file->linenum,
771 current_file->filename, p);
58d4951d
ILT
772 on_page++;
773 listing_page (list);
774 }
c593cf41
SC
775 }
776}
b3ca913f 777
a39116f1 778/* Sometimes the user doesn't want to be bothered by the debugging
58d4951d 779 records inserted by the compiler, see if the line is suspicious */
5d9f0ecf 780
a39116f1 781static int
58d4951d
ILT
782debugging_pseudo (line)
783 char *line;
a39116f1 784{
58d4951d
ILT
785 while (isspace (*line))
786 line++;
787
788 if (*line != '.')
789 return 0;
c593cf41 790
c593cf41
SC
791 line++;
792
58d4951d
ILT
793 if (strncmp (line, "def", 3) == 0)
794 return 1;
795 if (strncmp (line, "val", 3) == 0)
796 return 1;
797 if (strncmp (line, "scl", 3) == 0)
798 return 1;
799 if (strncmp (line, "line", 4) == 0)
800 return 1;
801 if (strncmp (line, "endef", 5) == 0)
802 return 1;
803 if (strncmp (line, "ln", 2) == 0)
804 return 1;
805 if (strncmp (line, "type", 4) == 0)
806 return 1;
807 if (strncmp (line, "size", 4) == 0)
808 return 1;
809 if (strncmp (line, "dim", 3) == 0)
810 return 1;
811 if (strncmp (line, "tag", 3) == 0)
812 return 1;
813
814 if (strncmp (line, "stabs", 5) == 0)
815 return 1;
816 if (strncmp (line, "stabn", 5) == 0)
817 return 1;
818
c593cf41
SC
819 return 0;
820
821}
5d9f0ecf 822
58d4951d
ILT
823static void
824listing_listing (name)
825 char *name;
c593cf41
SC
826{
827 list_info_type *list = head;
58d4951d 828 file_info_type *current_hll_file = (file_info_type *) NULL;
c593cf41
SC
829 char *message;
830 char *buffer;
831 char *p;
c593cf41
SC
832 int show_listing = 1;
833 unsigned int width;
58d4951d
ILT
834
835 buffer = xmalloc (LISTING_RHS_WIDTH);
c593cf41
SC
836 eject = 1;
837 list = head;
838
58d4951d
ILT
839 while (list != (list_info_type *) NULL && 0)
840 {
841 if (list->next)
842 list->frag = list->next->frag;
843 list = list->next;
844
845 }
c593cf41 846
c593cf41
SC
847 list = head->next;
848
849
58d4951d 850 while (list)
c593cf41 851 {
58d4951d
ILT
852 width = LISTING_RHS_WIDTH > paper_width ? paper_width :
853 LISTING_RHS_WIDTH;
c593cf41 854
58d4951d
ILT
855 switch (list->edict)
856 {
857 case EDICT_LIST:
858 show_listing++;
859 break;
860 case EDICT_NOLIST:
861 show_listing--;
862 break;
863 case EDICT_EJECT:
864 break;
865 case EDICT_NONE:
866 break;
867 case EDICT_TITLE:
868 title = list->edict_arg;
869 break;
870 case EDICT_SBTTL:
871 subtitle = list->edict_arg;
872 break;
873 default:
874 abort ();
875 }
c593cf41 876
58d4951d
ILT
877 if (show_listing > 0)
878 {
879 /* Scan down the list and print all the stuff which can be done
880 with this line (or lines). */
881 message = 0;
882
883 if (list->hll_file)
884 {
885 current_hll_file = list->hll_file;
886 }
887
888 if (current_hll_file && list->hll_line && listing & LISTING_HLL)
889 {
890 print_source (current_hll_file, list, buffer, width);
891 }
892
f949f7b8
KR
893 while (list->file->file
894 && list->file->linenum < list->line
bcaa9b05 895 && !list->file->at_end)
58d4951d 896 {
f949f7b8
KR
897 p = buffer_line (list->file, buffer, width);
898
899 if (!((listing & LISTING_NODEBUG) && debugging_pseudo (p)))
900 {
901 print_lines (list, p, calc_hex (list));
902 }
58d4951d
ILT
903 }
904
905 if (list->edict == EDICT_EJECT)
906 {
907 eject = 1;
908 }
909 }
910 else
911 {
f949f7b8
KR
912 while (list->file->file
913 && list->file->linenum < list->line
bcaa9b05 914 && !list->file->at_end)
f949f7b8 915 p = buffer_line (list->file, buffer, width);
58d4951d 916 }
c593cf41 917
58d4951d 918 list = list->next;
c593cf41 919 }
58d4951d 920 free (buffer);
c593cf41 921}
5d9f0ecf 922
58d4951d
ILT
923void
924listing_print (name)
925 char *name;
5d9f0ecf 926{
c593cf41 927 title = "";
58d4951d
ILT
928 subtitle = "";
929
85a961c6
ILT
930 if (name == NULL)
931 list_file = stdout;
932 else
933 {
934 list_file = fopen (name, "w");
935 if (list_file == NULL)
936 {
937 as_perror ("can't open list file: %s", name);
938 list_file = stdout;
939 }
940 }
941
58d4951d
ILT
942 if (listing & LISTING_NOFORM)
943 {
944 paper_height = 0;
945 }
946
947 if (listing & LISTING_LISTING)
948 {
949 listing_listing (name);
950
951 }
952 if (listing & LISTING_SYMBOLS)
953 {
954 list_symbol_table ();
955 }
956}
5d9f0ecf
SC
957
958
959void
58d4951d
ILT
960listing_file (name)
961 const char *name;
5d9f0ecf 962{
58d4951d 963 fn = name;
5d9f0ecf
SC
964}
965
58d4951d 966void
e860dfd0
KR
967listing_eject (ignore)
968 int ignore;
5d9f0ecf 969{
58d4951d 970 listing_tail->edict = EDICT_EJECT;
5d9f0ecf
SC
971}
972
973void
e860dfd0
KR
974listing_flags (ignore)
975 int ignore;
5d9f0ecf 976{
58d4951d
ILT
977 while ((*input_line_pointer++) && (*input_line_pointer != '\n'))
978 input_line_pointer++;
979
c593cf41 980}
58d4951d 981
c593cf41 982void
58d4951d 983listing_list (on)
e860dfd0 984 int on;
c593cf41
SC
985{
986 listing_tail->edict = on ? EDICT_LIST : EDICT_NOLIST;
5d9f0ecf 987}
3340f7e5 988
c593cf41 989
5d9f0ecf 990void
51a3bc15
ILT
991listing_psize (width_only)
992 int width_only;
5d9f0ecf 993{
51a3bc15 994 if (! width_only)
58d4951d 995 {
51a3bc15
ILT
996 paper_height = get_absolute_expression ();
997
998 if (paper_height < 0 || paper_height > 1000)
999 {
1000 paper_height = 0;
1001 as_warn ("strange paper height, set to no form");
1002 }
1003
1004 if (*input_line_pointer != ',')
1005 {
1006 demand_empty_rest_of_line ();
1007 return;
1008 }
1009
1010 ++input_line_pointer;
58d4951d 1011 }
5d9f0ecf 1012
51a3bc15
ILT
1013 paper_width = get_absolute_expression ();
1014
1015 demand_empty_rest_of_line ();
1016}
5d9f0ecf
SC
1017
1018void
58d4951d 1019listing_title (depth)
e860dfd0 1020 int depth;
a39116f1 1021{
c593cf41 1022 char *start;
e860dfd0 1023 char *ttl;
c593cf41 1024 unsigned int length;
58d4951d
ILT
1025
1026 SKIP_WHITESPACE ();
1027 if (*input_line_pointer == '\"')
1028 {
c593cf41
SC
1029 input_line_pointer++;
1030 start = input_line_pointer;
58d4951d
ILT
1031
1032 while (*input_line_pointer)
c593cf41 1033 {
58d4951d
ILT
1034 if (*input_line_pointer == '\"')
1035 {
1036 length = input_line_pointer - start;
e860dfd0
KR
1037 ttl = xmalloc (length + 1);
1038 memcpy (ttl, start, length);
1039 ttl[length] = 0;
58d4951d 1040 listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE;
e860dfd0 1041 listing_tail->edict_arg = ttl;
58d4951d
ILT
1042 input_line_pointer++;
1043 demand_empty_rest_of_line ();
1044 return;
1045 }
1046 else if (*input_line_pointer == '\n')
1047 {
1048 as_bad ("New line in title");
1049 demand_empty_rest_of_line ();
1050 return;
1051 }
1052 else
1053 {
1054 input_line_pointer++;
1055 }
c593cf41 1056 }
c593cf41 1057 }
58d4951d
ILT
1058 else
1059 {
1060 as_bad ("expecting title in quotes");
1061 }
c593cf41
SC
1062}
1063
5d9f0ecf
SC
1064
1065
1066void
58d4951d
ILT
1067listing_source_line (line)
1068 unsigned int line;
5d9f0ecf 1069{
58d4951d 1070 new_frag ();
c593cf41 1071 listing_tail->hll_line = line;
58d4951d
ILT
1072 new_frag ();
1073
c593cf41 1074}
5d9f0ecf 1075
c593cf41 1076void
58d4951d
ILT
1077listing_source_file (file)
1078 const char *file;
c593cf41 1079{
e860dfd0
KR
1080 if (listing_tail)
1081 listing_tail->hll_file = file_info (file);
c593cf41 1082}
5d9f0ecf 1083
b3ca913f 1084
58d4951d 1085
c593cf41
SC
1086#else
1087
1088
1089/* Dummy functions for when compiled without listing enabled */
1090
58d4951d 1091void
e860dfd0
KR
1092listing_flags (ignore)
1093 int ignore;
c593cf41 1094{
58d4951d 1095 s_ignore (0);
c593cf41
SC
1096}
1097
58d4951d
ILT
1098void
1099listing_list (on)
e860dfd0 1100 int on;
b3ca913f 1101{
58d4951d 1102 s_ignore (0);
c593cf41
SC
1103}
1104
58d4951d 1105void
e860dfd0
KR
1106listing_eject (ignore)
1107 int ignore;
c593cf41 1108{
58d4951d 1109 s_ignore (0);
c593cf41 1110}
58d4951d
ILT
1111
1112void
e860dfd0
KR
1113listing_psize (ignore)
1114 int ignore;
c593cf41 1115{
58d4951d 1116 s_ignore (0);
c593cf41 1117}
b3ca913f 1118
58d4951d
ILT
1119void
1120listing_title (depth)
e860dfd0 1121 int depth;
c593cf41 1122{
58d4951d 1123 s_ignore (0);
c593cf41 1124}
58d4951d 1125
b3ca913f 1126void
58d4951d
ILT
1127listing_file (name)
1128 const char *name;
b3ca913f 1129{
c593cf41
SC
1130
1131}
1132
58d4951d
ILT
1133void
1134listing_newline (name)
1135 char *name;
c593cf41 1136{
58d4951d 1137
b3ca913f
SC
1138}
1139
58d4951d
ILT
1140void
1141listing_source_line (n)
1142 unsigned int n;
c593cf41 1143{
58d4951d 1144
c593cf41 1145}
58d4951d
ILT
1146void
1147listing_source_file (n)
1148 const char *n;
c593cf41 1149{
c593cf41 1150
58d4951d 1151}
c593cf41
SC
1152
1153#endif
This page took 0.206833 seconds and 4 git commands to generate.