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 | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
5d9f0ecf SC |
19 | |
20 | /* | |
c593cf41 SC |
21 | Contributed by Steve Chamberlain |
22 | sac@cygnus.com | |
23 | ||
24 | ||
25 | A listing page looks like: | |
26 | ||
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 | ||
37 | .title "stuff" | |
38 | Put "stuff" onto the title line | |
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 | ||
56 | If the counter goes below zero, listing is suppressed. | |
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 SC |
93 | |
94 | #include "as.h" | |
20a88218 SC |
95 | <<<<<<< listing.c |
96 | #include <ansidecl.h> | |
97 | ======= | |
7143f43c | 98 | |
20a88218 | 99 | >>>>>>> 1.13 |
5d9f0ecf SC |
100 | #include <obstack.h> |
101 | #include "input-file.h" | |
102 | #include "targ-cpu.h" | |
103 | ||
7143f43c SC |
104 | char *malloc(); |
105 | ||
5d9f0ecf SC |
106 | #ifndef NO_LISTING |
107 | #ifndef LISTING_HEADER | |
108 | #define LISTING_HEADER "GAS LISTING" | |
109 | #endif | |
110 | #ifndef LISTING_WORD_SIZE | |
111 | #define LISTING_WORD_SIZE 4 | |
112 | #endif | |
113 | #ifndef LISTING_LHS_WIDTH | |
114 | #define LISTING_LHS_WIDTH 1 | |
115 | #endif | |
116 | #ifndef LISTING_LHS_WIDTH_SECOND | |
117 | #define LISTING_LHS_WIDTH_SECOND 1 | |
118 | #endif | |
119 | #ifndef LISTING_RHS_WIDTH | |
120 | #define LISTING_RHS_WIDTH 100 | |
121 | #endif | |
122 | #ifndef LISTING_LHS_CONT_LINES | |
123 | #define LISTING_LHS_CONT_LINES 4 | |
124 | #endif | |
125 | ||
126 | ||
c593cf41 SC |
127 | |
128 | ||
b3ca913f | 129 | /* This structure remembers which .s were used */ |
c593cf41 SC |
130 | typedef struct file_info_struct |
131 | { | |
132 | char *filename; | |
133 | int linenum; | |
134 | FILE *file; | |
135 | struct file_info_struct *next; | |
136 | int end_pending; | |
137 | ||
5d9f0ecf SC |
138 | } file_info_type ; |
139 | ||
c593cf41 SC |
140 | |
141 | /* this structure rememebrs which line from which file goes into which | |
142 | frag */ | |
143 | typedef struct list_info_struct | |
144 | { | |
145 | /* Frag which this line of source is nearest to */ | |
146 | fragS *frag; | |
147 | /* The actual line in the source file */ | |
148 | unsigned int line; | |
149 | /* Pointer to the file info struct for the file which this line | |
150 | belongs to */ | |
151 | file_info_type *file; | |
152 | ||
153 | /* Next in list */ | |
154 | struct list_info_struct *next; | |
a39116f1 | 155 | |
c593cf41 SC |
156 | |
157 | /* Pointer to the file info struct for the high level language | |
158 | source line that belongs here */ | |
159 | file_info_type *hll_file; | |
160 | ||
161 | /* High level language source line */ | |
162 | int hll_line; | |
163 | ||
164 | ||
165 | /* Pointer to any error message associated with this line */ | |
166 | char *message; | |
167 | ||
168 | enum | |
169 | { | |
170 | EDICT_NONE, | |
171 | EDICT_SBTTL, | |
172 | EDICT_TITLE, | |
173 | EDICT_NOLIST, | |
174 | EDICT_LIST, | |
175 | EDICT_EJECT | |
176 | } edict; | |
177 | char *edict_arg; | |
178 | ||
5d9f0ecf SC |
179 | } list_info_type; |
180 | ||
c593cf41 | 181 | |
5d9f0ecf SC |
182 | static struct list_info_struct *head; |
183 | struct list_info_struct *listing_tail; | |
184 | extern int listing; | |
185 | extern unsigned int physical_input_line; | |
186 | extern fragS *frag_now; | |
187 | ||
c593cf41 | 188 | |
5d9f0ecf SC |
189 | static int paper_width = 200; |
190 | static int paper_height = 60; | |
191 | ||
c593cf41 | 192 | |
5d9f0ecf | 193 | /* this static array is used to keep the text of data to be printed |
c593cf41 SC |
194 | before the start of the line. |
195 | It is stored so we can give a bit more info on the next line. To much, and large | |
196 | initialized arrays will use up lots of paper. | |
197 | */ | |
5d9f0ecf SC |
198 | |
199 | static char data_buffer[100]; | |
200 | static unsigned int data_buffer_size; | |
201 | ||
c593cf41 | 202 | |
5d9f0ecf | 203 | static void |
c593cf41 SC |
204 | DEFUN(listing_message,(name, message), |
205 | char *name AND | |
206 | char *message) | |
207 | { | |
208 | unsigned int l = strlen(name) + strlen(message)+1; | |
7143f43c | 209 | char *n = (char*)malloc(l); |
c593cf41 SC |
210 | strcpy(n,name); |
211 | strcat(n,message); | |
212 | if(listing_tail != (list_info_type *)NULL) | |
213 | { | |
214 | listing_tail->message = n; | |
215 | } | |
216 | ||
217 | } | |
218 | ||
219 | ||
5d9f0ecf SC |
220 | |
221 | ||
222 | void | |
c593cf41 SC |
223 | DEFUN(listing_warning,(message), |
224 | char *message) | |
5d9f0ecf | 225 | { |
c593cf41 | 226 | listing_message("Warning:", message); |
5d9f0ecf SC |
227 | } |
228 | ||
c593cf41 SC |
229 | void |
230 | DEFUN(listing_error,(message), | |
231 | char *message) | |
5d9f0ecf | 232 | { |
c593cf41 | 233 | listing_message("Error:", message); |
5d9f0ecf SC |
234 | } |
235 | ||
c593cf41 SC |
236 | |
237 | ||
238 | ||
5d9f0ecf SC |
239 | static file_info_type *file_info_head; |
240 | ||
241 | static file_info_type * | |
c593cf41 SC |
242 | DEFUN(file_info, (file_name), |
243 | char *file_name) | |
5d9f0ecf | 244 | { |
c593cf41 SC |
245 | /* Find an entry with this file name */ |
246 | file_info_type *p = file_info_head; | |
247 | ||
248 | while (p != (file_info_type *)NULL) | |
249 | { | |
250 | if (strcmp(p->filename, file_name) == 0) | |
251 | return p; | |
252 | p = p->next; | |
253 | } | |
254 | ||
255 | /* Make new entry */ | |
256 | ||
257 | p = (file_info_type *)xmalloc(sizeof(file_info_type)); | |
258 | p->next = file_info_head; | |
259 | file_info_head = p; | |
260 | p->filename = xmalloc(strlen(file_name)+1); | |
261 | strcpy(p->filename, file_name); | |
262 | p->linenum = 0; | |
263 | p->end_pending = 0; | |
264 | ||
7143f43c SC |
265 | p->file = fopen(p->filename,"rb"); |
266 | if (p->file) fgetc(p->file); | |
267 | ||
268 | ||
269 | ||
c593cf41 SC |
270 | return p; |
271 | ||
272 | } | |
5d9f0ecf SC |
273 | |
274 | ||
b3ca913f | 275 | static void |
c593cf41 | 276 | DEFUN_VOID(new_frag) |
b3ca913f | 277 | { |
c593cf41 SC |
278 | |
279 | frag_wane(frag_now); | |
280 | frag_new(0); | |
281 | ||
b3ca913f SC |
282 | } |
283 | ||
5d9f0ecf | 284 | void |
c593cf41 SC |
285 | DEFUN(listing_newline,(ps), |
286 | char *ps) | |
5d9f0ecf | 287 | { |
c593cf41 SC |
288 | char *s = ps; |
289 | extern char *file_name; | |
290 | static unsigned int last_line =0xffff ; | |
5d9f0ecf | 291 | |
c593cf41 SC |
292 | |
293 | list_info_type *new; | |
294 | if (physical_input_line != last_line) | |
295 | { | |
296 | last_line = physical_input_line; | |
297 | new_frag(); | |
298 | ||
299 | new = (list_info_type *)malloc(sizeof(list_info_type)); | |
300 | new->frag = frag_now; | |
301 | new->line = physical_input_line ; | |
302 | new->file = file_info(file_name); | |
303 | ||
304 | if (listing_tail) | |
305 | { | |
306 | listing_tail->next = new; | |
307 | } | |
308 | else | |
309 | { | |
310 | head = new; | |
311 | } | |
312 | listing_tail = new; | |
313 | new->next = (list_info_type *)NULL; | |
314 | new->message = (char *)NULL; | |
315 | new->edict = EDICT_NONE; | |
316 | new->hll_file = (file_info_type*)NULL; | |
317 | new->hll_line = 0; | |
318 | new_frag(); | |
319 | } | |
320 | } | |
5d9f0ecf | 321 | |
3340f7e5 | 322 | |
c593cf41 SC |
323 | /* |
324 | This function returns the next source line from the file supplied, | |
325 | truncated to size. It appends a fake line to the end of each input | |
326 | file to make | |
327 | */ | |
5d9f0ecf SC |
328 | |
329 | static char * | |
c593cf41 SC |
330 | DEFUN(buffer_line,(file, line, size), |
331 | file_info_type *file AND | |
332 | char *line AND | |
333 | unsigned int size) | |
5d9f0ecf | 334 | { |
c593cf41 SC |
335 | unsigned int count = 0; |
336 | int c; | |
337 | ||
338 | char *p = line; | |
339 | ||
340 | /* If we couldn't open the file, return an empty line */ | |
341 | if (file->file == (FILE*)NULL) | |
342 | { | |
343 | return ""; | |
344 | } | |
345 | ||
346 | if (file->end_pending == 10) { | |
347 | *p ++ = '\n'; | |
7143f43c | 348 | fseek(file->file, 0,0 ); |
c593cf41 SC |
349 | file->linenum = 0; |
350 | file->end_pending = 0; | |
351 | } | |
352 | c = fgetc(file->file); | |
7143f43c SC |
353 | |
354 | ||
c593cf41 SC |
355 | size -= 1; /* leave room for null */ |
356 | ||
357 | while (c != EOF && c != '\n') | |
358 | { | |
359 | if (count < size) | |
360 | *p++ = c; | |
361 | count++; | |
362 | ||
363 | c= fgetc(file->file); | |
7143f43c | 364 | |
c593cf41 SC |
365 | } |
366 | if (c == EOF) | |
367 | { | |
368 | file->end_pending ++; | |
7143f43c SC |
369 | *p++ = '.'; |
370 | *p++ = '.'; | |
371 | *p++ = '.'; | |
c593cf41 SC |
372 | } |
373 | file->linenum++; | |
374 | *p++ = 0; | |
375 | return line; | |
376 | } | |
377 | ||
5d9f0ecf SC |
378 | |
379 | static char *fn; | |
380 | ||
381 | static unsigned int eject; /* Eject pending */ | |
382 | static unsigned int page; /* Current page number */ | |
383 | static char *title; /* current title */ | |
384 | static char *subtitle; /* current subtitle */ | |
385 | static unsigned int on_page; /* number of lines printed on current page */ | |
386 | ||
3340f7e5 | 387 | |
c593cf41 SC |
388 | static void |
389 | DEFUN(listing_page,(list), | |
390 | list_info_type *list) | |
391 | { | |
392 | /* Grope around, see if we can see a title or subtitle edict coming up | |
393 | soon (we look down 10 lines of the page and see if it's there)*/ | |
394 | if ((eject || (on_page >= paper_height)) && paper_height != 0) | |
395 | { | |
396 | unsigned int c = 10; | |
397 | int had_title = 0; | |
398 | int had_subtitle = 0; | |
399 | ||
400 | page++; | |
401 | ||
402 | while (c != 0 && list) | |
403 | { | |
404 | if (list->edict == EDICT_SBTTL && !had_subtitle) | |
405 | { | |
406 | had_subtitle = 1; | |
407 | subtitle = list->edict_arg; | |
408 | } | |
409 | if (list->edict == EDICT_TITLE && !had_title) | |
410 | { | |
411 | had_title = 1; | |
412 | title = list->edict_arg; | |
413 | } | |
414 | list = list->next; | |
415 | c--; | |
416 | } | |
417 | ||
418 | ||
419 | if (page > 1) | |
420 | { | |
421 | printf("\f"); | |
422 | } | |
423 | ||
424 | printf("%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page); | |
425 | printf("%s\n", title); | |
426 | printf("%s\n", subtitle); | |
427 | on_page = 3; | |
428 | eject = 0; | |
429 | } | |
430 | } | |
5d9f0ecf SC |
431 | |
432 | ||
433 | static unsigned int | |
c593cf41 SC |
434 | DEFUN(calc_hex,(list), |
435 | list_info_type *list) | |
5d9f0ecf | 436 | { |
c593cf41 SC |
437 | list_info_type *first = list; |
438 | list_info_type *last = first; | |
439 | unsigned int address = ~0; | |
440 | ||
441 | fragS *frag; | |
442 | fragS *frag_ptr; | |
443 | ||
444 | unsigned int byte_in_frag = 0; | |
445 | ||
446 | int anything = 0; | |
447 | ||
448 | /* Find first frag which says it belongs to this line */ | |
449 | frag = list->frag; | |
450 | while (frag && frag->line != list) | |
451 | frag = frag->fr_next; | |
452 | ||
453 | frag_ptr = frag; | |
454 | ||
455 | data_buffer_size = 0; | |
456 | ||
457 | /* Dump all the frags which belong to this line */ | |
458 | while (frag_ptr != (fragS *)NULL && frag_ptr->line == first) | |
459 | { | |
460 | /* Print as many bytes from the fixed part as is sensible */ | |
461 | while(byte_in_frag < frag_ptr->fr_fix && data_buffer_size < sizeof(data_buffer)-10) | |
462 | { | |
463 | if (address == ~0) | |
464 | { | |
465 | address = frag_ptr->fr_address; | |
466 | } | |
467 | ||
468 | sprintf(data_buffer + data_buffer_size, | |
469 | "%02X", | |
470 | (frag_ptr->fr_literal[byte_in_frag]) & 0xff); | |
471 | data_buffer_size += 2; | |
472 | byte_in_frag++; | |
473 | } | |
474 | { | |
475 | unsigned int var_rep_max = byte_in_frag; | |
476 | unsigned int var_rep_idx = byte_in_frag; | |
477 | ||
478 | /* Print as many bytes from the variable part as is sensible */ | |
479 | while (byte_in_frag < frag_ptr->fr_var * frag_ptr->fr_offset | |
480 | && data_buffer_size < sizeof(data_buffer)-10) | |
481 | { | |
482 | if (address == ~0) | |
483 | { | |
484 | address = frag_ptr->fr_address; | |
485 | } | |
486 | sprintf(data_buffer + data_buffer_size, | |
487 | "%02X", | |
488 | (frag_ptr->fr_literal[var_rep_idx]) & 0xff); | |
489 | #if 0 | |
490 | data_buffer[data_buffer_size++] = '*'; | |
491 | data_buffer[data_buffer_size++] = '*'; | |
492 | #endif | |
493 | data_buffer_size +=2; | |
494 | ||
495 | var_rep_idx ++; | |
496 | byte_in_frag++; | |
497 | ||
498 | if (var_rep_idx >= frag_ptr->fr_var) | |
499 | var_rep_idx = var_rep_max; | |
500 | } | |
501 | } | |
502 | ||
503 | frag_ptr = frag_ptr->fr_next; | |
504 | } | |
505 | data_buffer[data_buffer_size++] = 0; | |
506 | return address; | |
507 | } | |
508 | ||
509 | ||
510 | ||
511 | ||
512 | ||
5d9f0ecf SC |
513 | |
514 | static void | |
c593cf41 SC |
515 | DEFUN(print_lines,(list, string, address), |
516 | list_info_type *list AND | |
517 | char *string AND | |
518 | unsigned int address) | |
519 | { | |
520 | unsigned int idx; | |
521 | unsigned int nchars; | |
522 | unsigned int lines; | |
523 | unsigned int byte_in_word =0; | |
524 | char *src = data_buffer; | |
525 | ||
526 | /* Print the stuff on the first line */ | |
527 | listing_page(list); | |
528 | nchars = (LISTING_WORD_SIZE*2 +1) * LISTING_LHS_WIDTH ; | |
529 | /* Print the hex for the first line */ | |
530 | if (address == ~0) | |
531 | { | |
532 | printf("% 4d ", list->line); | |
533 | for (idx = 0; idx < nchars; idx++) | |
534 | printf(" "); | |
535 | ||
536 | printf("\t%s\n", string ? string : ""); | |
537 | on_page++; | |
538 | listing_page(0); | |
539 | ||
540 | } | |
541 | else | |
542 | { | |
543 | if (had_errors()) | |
544 | { | |
545 | printf("% 4d ???? ", list->line); | |
546 | } | |
547 | else | |
548 | { | |
549 | printf("% 4d %04x ", list->line, address); | |
550 | } | |
551 | ||
552 | /* And the data to go along with it */ | |
553 | idx = 0; | |
554 | ||
555 | while (*src && idx < nchars) | |
556 | { | |
557 | printf("%c%c", src[0], src[1]); | |
558 | src += 2; | |
559 | byte_in_word++; | |
560 | if (byte_in_word == LISTING_WORD_SIZE) | |
561 | { | |
562 | printf(" "); | |
563 | idx++; | |
564 | byte_in_word = 0; | |
565 | } | |
566 | idx+=2; | |
567 | } | |
568 | ||
569 | for (;idx < nchars; idx++) | |
570 | printf(" "); | |
571 | ||
572 | printf("\t%s\n", string ? string : ""); | |
573 | on_page++; | |
574 | listing_page(list); | |
575 | if (list->message) | |
576 | { | |
577 | printf("**** %s\n",list->message); | |
578 | listing_page(list); | |
579 | on_page++; | |
580 | } | |
581 | ||
582 | for (lines = 0; | |
583 | lines < LISTING_LHS_CONT_LINES | |
584 | && *src; | |
585 | lines++) { | |
586 | nchars = ((LISTING_WORD_SIZE*2) +1) * LISTING_LHS_WIDTH_SECOND -1; | |
587 | idx = 0; | |
588 | /* Print any more lines of data, but more compactly */ | |
589 | printf("% 4d ", list->line); | |
590 | ||
591 | while (*src && idx < nchars) | |
592 | { | |
593 | printf("%c%c", src[0], src[1]); | |
594 | src+=2; | |
595 | idx+=2; | |
596 | byte_in_word++; | |
597 | if (byte_in_word == LISTING_WORD_SIZE) | |
598 | { | |
599 | printf(" "); | |
600 | idx++; | |
601 | byte_in_word = 0; | |
602 | } | |
603 | } | |
5d9f0ecf | 604 | |
c593cf41 SC |
605 | printf("\n"); |
606 | on_page++; | |
5d9f0ecf | 607 | listing_page(list); |
3340f7e5 | 608 | |
c593cf41 SC |
609 | } |
610 | ||
611 | ||
612 | } | |
613 | } | |
614 | ||
615 | ||
616 | ||
617 | ||
5d9f0ecf SC |
618 | |
619 | ||
620 | static void | |
c593cf41 | 621 | DEFUN_VOID(list_symbol_table) |
5d9f0ecf | 622 | { |
c593cf41 SC |
623 | extern symbolS *symbol_rootP; |
624 | ||
625 | symbolS *ptr ; | |
626 | eject = 1; | |
627 | listing_page(0); | |
628 | printf("DEFINED SYMBOLS\n"); | |
629 | on_page++; | |
630 | ||
631 | for (ptr = symbol_rootP; ptr != (symbolS*)NULL; ptr = symbol_next(ptr)) | |
632 | { | |
633 | if (ptr->sy_frag->line) | |
634 | { | |
7143f43c SC |
635 | if (S_GET_NAME(ptr)) |
636 | { | |
637 | ||
c593cf41 SC |
638 | if (strlen(S_GET_NAME(ptr))) |
639 | { | |
640 | printf("%20s:%-5d %2d:%08x %s \n", | |
641 | ptr->sy_frag->line->file->filename, | |
642 | ptr->sy_frag->line->line, | |
643 | S_GET_SEGMENT(ptr), | |
644 | S_GET_VALUE(ptr), | |
645 | S_GET_NAME(ptr)); | |
7143f43c SC |
646 | } |
647 | ||
648 | else | |
649 | { | |
650 | printf("%20s:%-5d %2d:%08x\n", | |
651 | ptr->sy_frag->line->file->filename, | |
652 | ptr->sy_frag->line->line, | |
653 | S_GET_SEGMENT(ptr), | |
654 | S_GET_VALUE(ptr)); | |
655 | ||
c593cf41 | 656 | |
7143f43c SC |
657 | } |
658 | ||
3d38ac61 SC |
659 | on_page++; |
660 | listing_page(0); | |
c593cf41 SC |
661 | } |
662 | } | |
663 | ||
664 | } | |
665 | printf("\n"); | |
666 | on_page++; | |
667 | listing_page(0); | |
668 | printf("UNDEFINED SYMBOLS\n"); | |
669 | on_page++; | |
670 | listing_page(0); | |
671 | ||
672 | for (ptr = symbol_rootP; ptr != (symbolS*)NULL; ptr = symbol_next(ptr)) | |
673 | { | |
7143f43c | 674 | if (S_GET_NAME(ptr) && strlen(S_GET_NAME(ptr)) != 0) |
c593cf41 SC |
675 | { |
676 | if (ptr->sy_frag->line == 0) | |
677 | { | |
678 | printf("%s\n", S_GET_NAME(ptr)); | |
b3ca913f SC |
679 | on_page++; |
680 | listing_page(0); | |
c593cf41 SC |
681 | } |
682 | } | |
683 | } | |
684 | } | |
5d9f0ecf | 685 | |
b3ca913f | 686 | void |
c593cf41 SC |
687 | DEFUN(print_source,(current_file, list, buffer, width), |
688 | file_info_type *current_file AND | |
689 | list_info_type *list AND | |
690 | char *buffer AND | |
691 | unsigned int width) | |
692 | { | |
693 | if (current_file->file) { | |
694 | while (current_file->linenum < list->hll_line) | |
695 | { | |
696 | char * p = buffer_line(current_file, buffer, width); | |
697 | printf("%4d:%-13s **** %s\n", current_file->linenum, current_file->filename, p); | |
698 | on_page++; | |
699 | listing_page(list); | |
700 | } | |
701 | } | |
702 | } | |
b3ca913f | 703 | |
a39116f1 RP |
704 | /* Sometimes the user doesn't want to be bothered by the debugging |
705 | records inserted by the compiler, see if the line is suspicioous */ | |
5d9f0ecf | 706 | |
a39116f1 | 707 | static int |
c593cf41 SC |
708 | DEFUN(debugging_pseudo,(line), |
709 | char *line) | |
a39116f1 | 710 | { |
c593cf41 SC |
711 | while (isspace(*line)) |
712 | line++; | |
713 | ||
714 | if(*line != '.') return 0; | |
715 | ||
716 | line++; | |
717 | ||
718 | if (strncmp(line, "def",3) == 0) return 1; | |
719 | if (strncmp(line, "val",3) == 0) return 1; | |
720 | if (strncmp(line, "scl",3) == 0) return 1; | |
721 | if (strncmp(line, "line",4) == 0) return 1; | |
722 | if (strncmp(line, "endef",5) == 0) return 1; | |
723 | if (strncmp(line, "ln",2) ==0) return 1; | |
724 | if (strncmp(line, "type",4) ==0) return 1; | |
725 | if (strncmp(line, "size",4) == 0) return 1; | |
726 | if (strncmp(line, "dim",3) ==0) return 1; | |
727 | if (strncmp(line, "tag",3) == 0) return 1; | |
728 | ||
729 | return 0; | |
730 | ||
731 | } | |
5d9f0ecf | 732 | |
a39116f1 | 733 | void |
c593cf41 SC |
734 | DEFUN(listing_listing,(name), |
735 | char *name) | |
736 | { | |
737 | list_info_type *list = head; | |
738 | file_info_type *current_hll_file = (file_info_type *)NULL; | |
739 | ||
740 | unsigned int page= 1; | |
741 | unsigned int prev = 0; | |
742 | char *message; | |
743 | char *buffer; | |
744 | char *p; | |
745 | unsigned int addr = 0; | |
746 | int on_page = 0; | |
747 | int show_listing = 1; | |
748 | unsigned int width; | |
749 | ||
750 | buffer = malloc(LISTING_RHS_WIDTH); | |
751 | eject = 1; | |
752 | list = head; | |
753 | ||
754 | while (list != (list_info_type *)NULL && 0) | |
755 | { | |
756 | if (list->next) | |
757 | list->frag = list->next->frag; | |
758 | list = list->next; | |
759 | ||
760 | } | |
761 | ||
762 | list = head->next; | |
763 | ||
764 | ||
765 | while ( list) | |
766 | { | |
767 | width = LISTING_RHS_WIDTH > paper_width ? paper_width : | |
768 | LISTING_RHS_WIDTH; | |
769 | ||
770 | switch (list->edict) { | |
771 | case EDICT_LIST: | |
772 | show_listing++; | |
773 | break; | |
774 | case EDICT_NOLIST: | |
775 | show_listing--; | |
776 | break; | |
777 | case EDICT_EJECT: | |
778 | break; | |
779 | case EDICT_NONE: | |
780 | break; | |
781 | case EDICT_TITLE: | |
782 | title = list->edict_arg; | |
783 | break; | |
784 | case EDICT_SBTTL: | |
785 | subtitle = list->edict_arg; | |
786 | break; | |
787 | default: | |
788 | abort(); | |
789 | } | |
790 | ||
791 | if (show_listing > 0) | |
792 | { | |
793 | /* Scan down the list and print all the stuff which can be done | |
794 | with this line (or lines) */ | |
795 | message = 0; | |
796 | ||
797 | if (list->hll_file) | |
798 | { | |
799 | current_hll_file = list->hll_file; | |
800 | } | |
801 | ||
802 | if (current_hll_file && list->hll_line && listing & LISTING_HLL) | |
803 | { | |
804 | print_source(current_hll_file, list, buffer, width); | |
805 | } | |
806 | ||
807 | p = buffer_line(list->file, buffer, width); | |
808 | ||
809 | if (! ((listing & LISTING_NODEBUG) && debugging_pseudo(p))) | |
810 | { | |
811 | print_lines(list, p, calc_hex(list)); | |
812 | } | |
813 | ||
814 | if (list->edict == EDICT_EJECT) | |
815 | { | |
5d9f0ecf | 816 | eject = 1; |
c593cf41 SC |
817 | } |
818 | } | |
819 | else | |
820 | { | |
821 | ||
822 | p = buffer_line(list->file, buffer, width); | |
823 | } | |
824 | ||
825 | list = list->next; | |
826 | } | |
827 | free(buffer); | |
828 | } | |
5d9f0ecf SC |
829 | |
830 | void | |
c593cf41 SC |
831 | DEFUN(listing_print,(name), |
832 | char *name) | |
5d9f0ecf | 833 | { |
c593cf41 SC |
834 | title = ""; |
835 | subtitle = ""; | |
836 | ||
837 | if (listing & LISTING_NOFORM) | |
838 | { | |
839 | paper_height = 0; | |
840 | } | |
841 | ||
842 | if (listing & LISTING_LISTING) | |
843 | { | |
844 | listing_listing(name); | |
845 | ||
846 | } | |
847 | if (listing & LISTING_SYMBOLS) | |
848 | { | |
849 | list_symbol_table(); | |
850 | } | |
851 | } | |
5d9f0ecf SC |
852 | |
853 | ||
854 | void | |
c593cf41 SC |
855 | DEFUN(listing_file,(name), |
856 | char *name) | |
5d9f0ecf | 857 | { |
c593cf41 | 858 | fn = name; |
5d9f0ecf SC |
859 | } |
860 | ||
861 | void | |
c593cf41 | 862 | DEFUN_VOID(listing_eject) |
5d9f0ecf | 863 | { |
c593cf41 | 864 | listing_tail->edict = EDICT_EJECT; |
5d9f0ecf SC |
865 | } |
866 | ||
867 | void | |
c593cf41 | 868 | DEFUN_VOID(listing_flags) |
5d9f0ecf | 869 | { |
c593cf41 SC |
870 | |
871 | } | |
872 | void | |
873 | DEFUN(listing_list,(on), | |
874 | unsigned int on) | |
875 | { | |
876 | listing_tail->edict = on ? EDICT_LIST : EDICT_NOLIST; | |
5d9f0ecf | 877 | } |
3340f7e5 | 878 | |
c593cf41 | 879 | |
5d9f0ecf | 880 | void |
c593cf41 | 881 | DEFUN_VOID(listing_psize) |
5d9f0ecf | 882 | { |
c593cf41 SC |
883 | paper_height = get_absolute_expression(); |
884 | ||
885 | if (paper_height < 0 || paper_height > 1000) | |
886 | { | |
887 | paper_height = 0; | |
7143f43c | 888 | as_warn("strange paper height, set to no form"); |
c593cf41 SC |
889 | } |
890 | if (*input_line_pointer == ',') | |
891 | { | |
892 | input_line_pointer++; | |
893 | paper_width = get_absolute_expression(); | |
894 | } | |
5d9f0ecf SC |
895 | } |
896 | ||
897 | ||
898 | void | |
c593cf41 SC |
899 | DEFUN(listing_title,(depth), |
900 | unsigned int depth) | |
a39116f1 | 901 | { |
c593cf41 SC |
902 | char *start; |
903 | char *title; | |
904 | unsigned int length; | |
905 | ||
906 | SKIP_WHITESPACE(); | |
907 | if (*input_line_pointer=='\"') { | |
908 | input_line_pointer++; | |
909 | start = input_line_pointer; | |
910 | ||
911 | while (*input_line_pointer) | |
912 | { | |
913 | if (*input_line_pointer == '\"') | |
914 | { | |
915 | length = input_line_pointer - start; | |
916 | title = malloc(length + 1); | |
917 | memcpy(title, start, length); | |
918 | title[length] = 0; | |
919 | listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE; | |
920 | listing_tail->edict_arg = title; | |
921 | input_line_pointer++; | |
922 | demand_empty_rest_of_line(); | |
923 | return; | |
3340f7e5 | 924 | } |
c593cf41 SC |
925 | else if (*input_line_pointer == '\n') |
926 | { | |
927 | as_bad("New line in title"); | |
928 | demand_empty_rest_of_line(); | |
929 | return; | |
3340f7e5 | 930 | } |
c593cf41 SC |
931 | else |
932 | { | |
933 | input_line_pointer++; | |
934 | } | |
935 | } | |
936 | } | |
937 | else | |
938 | { | |
939 | as_bad("expecting title in quotes"); | |
940 | } | |
941 | } | |
942 | ||
5d9f0ecf SC |
943 | |
944 | ||
945 | void | |
c593cf41 SC |
946 | DEFUN(listing_source_line,(line), |
947 | unsigned int line) | |
5d9f0ecf | 948 | { |
c593cf41 SC |
949 | new_frag(); |
950 | listing_tail->hll_line = line; | |
951 | new_frag(); | |
952 | ||
953 | } | |
5d9f0ecf | 954 | |
c593cf41 SC |
955 | void |
956 | DEFUN(listing_source_file,(file), | |
957 | char *file) | |
958 | { | |
959 | listing_tail->hll_file = file_info(file); | |
960 | } | |
5d9f0ecf | 961 | |
b3ca913f | 962 | |
c593cf41 SC |
963 | |
964 | #else | |
965 | ||
966 | ||
967 | /* Dummy functions for when compiled without listing enabled */ | |
968 | ||
969 | void | |
970 | DEFUN_VOID(listing_flags) | |
971 | { | |
972 | s_ignore(); | |
973 | } | |
974 | ||
975 | void DEFUN_VOID(listing_list) | |
b3ca913f | 976 | { |
c593cf41 SC |
977 | s_ignore(); |
978 | } | |
979 | ||
980 | void DEFUN_VOID(listing_eject) | |
981 | { | |
982 | s_ignore(); | |
983 | } | |
20a88218 | 984 | void DEFUN_VOID(listing_psize) |
c593cf41 SC |
985 | { |
986 | s_ignore(); | |
987 | } | |
b3ca913f | 988 | |
c593cf41 SC |
989 | void DEFUN(listing_title, (depth), |
990 | unsigned int depth) | |
991 | { | |
992 | s_ignore(); | |
993 | } | |
b3ca913f | 994 | void |
c593cf41 SC |
995 | DEFUN(listing_file,(name), |
996 | char *name) | |
b3ca913f | 997 | { |
c593cf41 SC |
998 | |
999 | } | |
1000 | ||
1001 | void DEFUN(listing_newline,(name), | |
1002 | char *name) | |
1003 | { | |
1004 | ||
b3ca913f SC |
1005 | } |
1006 | ||
c593cf41 SC |
1007 | void DEFUN(listing_source_line,(n), |
1008 | unsigned int n) | |
1009 | { | |
1010 | ||
1011 | } | |
1012 | void DEFUN(listing_source_file, (n), | |
1013 | char *n) | |
1014 | { | |
1015 | ||
1016 | } | |
1017 | ||
1018 | ||
1019 | ||
1020 | #endif | |
b3ca913f | 1021 |