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