gcc lint. See ChangeLog for details. Also:
[deliverable/binutils-gdb.git] / gas / read.c
1 /* read.c - read a source file -
2 Copyright (C) 1986, 1987, 1990, 1991, 1993 Free Software Foundation, Inc.
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. */
19
20 #if 0
21 #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will
22 change this a bit. But then, GNU isn't
23 spozed to run on your machine anyway.
24 (RMS is so shortsighted sometimes.)
25 */
26 #else
27 #define MASK_CHAR ((int)(unsigned char)-1)
28 #endif
29
30
31 /* This is the largest known floating point format (for now). It will
32 grow when we do 4361 style flonums. */
33
34 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
35
36 /* Routines that read assembler source text to build spagetti in memory.
37 Another group of these functions is in the expr.c module. */
38
39 /* for isdigit() */
40 #include <ctype.h>
41
42 #include "as.h"
43 #include "subsegs.h"
44
45 #include "obstack.h"
46 #include "listing.h"
47
48 /* We need this, despite the apparent object format dependency, since
49 it defines stab types, which all object formats can use now. */
50
51 #include "aout/stab_gnu.h"
52
53 #ifndef TC_START_LABEL
54 #define TC_START_LABEL(x,y) (x==':')
55 #endif
56
57 /* The NOP_OPCODE is for the alignment fill value.
58 * fill it a nop instruction so that the disassembler does not choke
59 * on it
60 */
61 #ifndef NOP_OPCODE
62 #define NOP_OPCODE 0x00
63 #endif
64
65 char *input_line_pointer; /*->next char of source file to parse. */
66
67 #if BITS_PER_CHAR != 8
68 /* The following table is indexed by[(char)] and will break if
69 a char does not have exactly 256 states (hopefully 0:255!)! */
70 die horribly;
71 #endif
72
73 #ifndef LEX_AT
74 /* The m88k unfortunately uses @ as a label beginner. */
75 #define LEX_AT 0
76 #endif
77
78 /* used by is_... macros. our ctype[] */
79 const char lex_type[256] =
80 {
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */
83 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
84 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */
85 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */
86 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 3, /* PQRSTUVWXYZ[\]^_ */
87 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */
88 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, /* pqrstuvwxyz{|}~. */
89 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
92 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
93 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
96 };
97
98
99 /*
100 * In: a character.
101 * Out: 1 if this character ends a line.
102 */
103 #define _ (0)
104 char is_end_of_line[256] =
105 {
106 #ifdef CR_EOL
107 _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */
108 #else
109 _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */
110 #endif
111 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
112 #ifdef TC_HPPA
113 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */
114 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */
115 #else
116 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
117 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */
118 #endif
119 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
120 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
121 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
122 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
123 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
124 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
125 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
126 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
127 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */
128 };
129 #undef _
130
131 /* Functions private to this file. */
132
133 static char *buffer; /* 1st char of each buffer of lines is here. */
134 static char *buffer_limit; /*->1 + last char in buffer. */
135
136 static char *bignum_low; /* Lowest char of bignum. */
137 static char *bignum_limit; /* 1st illegal address of bignum. */
138 static char *bignum_high; /* Highest char of bignum. */
139 /* May point to (bignum_start-1). */
140 /* Never >= bignum_limit. */
141
142 int target_big_endian;
143
144 static char *old_buffer; /* JF a hack */
145 static char *old_input;
146 static char *old_limit;
147
148 /* Variables for handling include file directory list. */
149
150 char **include_dirs; /* List of pointers to directories to
151 search for .include's */
152 int include_dir_count; /* How many are in the list */
153 int include_dir_maxlen = 1;/* Length of longest in list */
154
155 #ifndef WORKING_DOT_WORD
156 struct broken_word *broken_words;
157 int new_broken_words;
158 #endif
159
160 static char *demand_copy_string PARAMS ((int *lenP));
161 int is_it_end_of_statement PARAMS ((void));
162 static segT get_segmented_expression PARAMS ((expressionS *expP));
163 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
164 static void grow_bignum PARAMS ((void));
165 static void pobegin PARAMS ((void));
166
167 extern int listing;
168 \f
169
170 void
171 read_begin ()
172 {
173 const char *p;
174
175 pobegin ();
176 obj_read_begin_hook ();
177
178 /* Something close -- but not too close -- to a multiple of 1024.
179 The debugging malloc I'm using has 24 bytes of overhead. */
180 obstack_begin (&notes, 5090);
181 obstack_begin (&cond_obstack, 990);
182
183 #define BIGNUM_BEGIN_SIZE (16)
184 bignum_low = xmalloc ((long) BIGNUM_BEGIN_SIZE);
185 bignum_limit = bignum_low + BIGNUM_BEGIN_SIZE;
186
187 /* Use machine dependent syntax */
188 for (p = line_separator_chars; *p; p++)
189 is_end_of_line[(unsigned char) *p] = 1;
190 /* Use more. FIXME-SOMEDAY. */
191 }
192 \f
193 /* set up pseudo-op tables */
194
195 struct hash_control *po_hash;
196
197 static const pseudo_typeS potable[] =
198 {
199 {"abort", s_abort, 0},
200 {"align", s_align_ptwo, 0},
201 {"ascii", stringer, 0},
202 {"asciz", stringer, 1},
203 /* block */
204 {"byte", cons, 1},
205 {"comm", s_comm, 0},
206 {"data", s_data, 0},
207 {"desc", s_desc, 0},
208 /* dim */
209 {"double", float_cons, 'd'},
210 /* dsect */
211 {"eject", listing_eject, 0}, /* Formfeed listing */
212 {"else", s_else, 0},
213 {"end", s_end, 0},
214 {"endif", s_endif, 0},
215 /* endef */
216 {"equ", s_set, 0},
217 /* err */
218 /* extend */
219 {"extern", s_ignore, 0}, /* We treat all undef as ext */
220 {"appfile", s_app_file, 1},
221 {"appline", s_app_line, 0},
222 {"file", s_app_file, 0},
223 {"fill", s_fill, 0},
224 {"float", float_cons, 'f'},
225 {"global", s_globl, 0},
226 {"globl", s_globl, 0},
227 {"hword", cons, 2},
228 {"if", s_if, 0},
229 {"ifdef", s_ifdef, 0},
230 {"ifeqs", s_ifeqs, 0},
231 {"ifndef", s_ifdef, 1},
232 {"ifnes", s_ifeqs, 1},
233 {"ifnotdef", s_ifdef, 1},
234 {"include", s_include, 0},
235 {"int", cons, 4},
236 {"lcomm", s_lcomm, 0},
237 {"lflags", listing_flags, 0}, /* Listing flags */
238 {"list", listing_list, 1}, /* Turn listing on */
239 {"long", cons, 4},
240 {"lsym", s_lsym, 0},
241 {"nolist", listing_list, 0}, /* Turn listing off */
242 {"octa", big_cons, 16},
243 {"org", s_org, 0},
244 {"psize", listing_psize, 0}, /* set paper size */
245 /* print */
246 {"quad", big_cons, 8},
247 {"sbttl", listing_title, 1}, /* Subtitle of listing */
248 /* scl */
249 /* sect */
250 {"set", s_set, 0},
251 {"short", cons, 2},
252 {"single", float_cons, 'f'},
253 /* size */
254 {"space", s_space, 0},
255 {"stabd", s_stab, 'd'},
256 {"stabn", s_stab, 'n'},
257 {"stabs", s_stab, 's'},
258 {"string", stringer, 1},
259 /* tag */
260 {"text", s_text, 0},
261 {"title", listing_title, 0}, /* Listing title */
262 /* type */
263 /* use */
264 /* val */
265 {"xstabs", s_xstab, 's'},
266 {"word", cons, 2},
267 {NULL} /* end sentinel */
268 };
269
270 static void
271 pobegin ()
272 {
273 char *errtxt; /* error text */
274 const pseudo_typeS *pop;
275
276 po_hash = hash_new ();
277
278 /* Do the target-specific pseudo ops. */
279 for (pop = md_pseudo_table; pop->poc_name; pop++)
280 {
281 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
282 if (errtxt && *errtxt)
283 {
284 as_fatal ("error constructing md pseudo-op table");
285 } /* on error */
286 } /* for each op */
287
288 /* Now object specific. Skip any that were in the target table. */
289 for (pop = obj_pseudo_table; pop->poc_name; pop++)
290 {
291 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
292 if (errtxt && *errtxt)
293 {
294 if (!strcmp (errtxt, "exists"))
295 {
296 #ifdef DIE_ON_OVERRIDES
297 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
298 #endif /* DIE_ON_OVERRIDES */
299 continue; /* OK if target table overrides. */
300 }
301 else
302 {
303 as_fatal ("error constructing obj pseudo-op table");
304 } /* if overridden */
305 } /* on error */
306 } /* for each op */
307
308 /* Now portable ones. Skip any that we've seen already. */
309 for (pop = potable; pop->poc_name; pop++)
310 {
311 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
312 if (errtxt && *errtxt)
313 {
314 if (!strcmp (errtxt, "exists"))
315 {
316 #ifdef DIE_ON_OVERRIDES
317 as_fatal ("pseudo op \".%s\" overridden.\n", pop->poc_name);
318 #endif /* DIE_ON_OVERRIDES */
319 continue; /* OK if target table overrides. */
320 }
321 else
322 {
323 as_fatal ("error constructing obj pseudo-op table");
324 } /* if overridden */
325 } /* on error */
326 } /* for each op */
327
328 return;
329 } /* pobegin() */
330 \f
331 #define HANDLE_CONDITIONAL_ASSEMBLY() \
332 if (ignore_input ()) \
333 { \
334 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \
335 if (input_line_pointer == buffer_limit) \
336 break; \
337 continue; \
338 }
339
340
341 /* read_a_source_file()
342 *
343 * We read the file, putting things into a web that
344 * represents what we have been reading.
345 */
346 void
347 read_a_source_file (name)
348 char *name;
349 {
350 register char c;
351 register char *s; /* string of symbol, '\0' appended */
352 register int temp;
353 pseudo_typeS *pop;
354
355 buffer = input_scrub_new_file (name);
356
357 listing_file (name);
358 listing_newline ("");
359
360 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
361 { /* We have another line to parse. */
362 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */
363 contin: /* JF this goto is my fault I admit it.
364 Someone brave please re-write the whole
365 input section here? Pleeze??? */
366 while (input_line_pointer < buffer_limit)
367 {
368 /* We have more of this buffer to parse. */
369
370 /*
371 * We now have input_line_pointer->1st char of next line.
372 * If input_line_pointer [-1] == '\n' then we just
373 * scanned another line: so bump line counters.
374 */
375 if (input_line_pointer[-1] == '\n')
376 {
377 bump_line_counters ();
378
379 #ifdef MRI
380 /* Text at the start of a line must be a label, we run down and stick a colon in */
381 if (is_name_beginner (*input_line_pointer))
382 {
383 char *line_start = input_line_pointer;
384 char c = get_symbol_end ();
385 colon (line_start);
386 *input_line_pointer = c;
387 if (c == ':')
388 input_line_pointer++;
389
390 }
391 #endif
392 }
393
394
395 /*
396 * We are at the begining of a line, or similar place.
397 * We expect a well-formed assembler statement.
398 * A "symbol-name:" is a statement.
399 *
400 * Depending on what compiler is used, the order of these tests
401 * may vary to catch most common case 1st.
402 * Each test is independent of all other tests at the (top) level.
403 * PLEASE make a compiler that doesn't use this assembler.
404 * It is crufty to waste a compiler's time encoding things for this
405 * assembler, which then wastes more time decoding it.
406 * (And communicating via (linear) files is silly!
407 * If you must pass stuff, please pass a tree!)
408 */
409 if ((c = *input_line_pointer++) == '\t'
410 || c == ' '
411 || c == '\f'
412 || c == 0)
413 {
414 c = *input_line_pointer++;
415 }
416 know (c != ' '); /* No further leading whitespace. */
417 LISTING_NEWLINE ();
418 /*
419 * C is the 1st significant character.
420 * Input_line_pointer points after that character.
421 */
422 if (is_name_beginner (c))
423 { /* want user-defined label or pseudo/opcode */
424 HANDLE_CONDITIONAL_ASSEMBLY ();
425
426 s = --input_line_pointer;
427 c = get_symbol_end (); /* name's delimiter */
428 /*
429 * C is character after symbol.
430 * That character's place in the input line is now '\0'.
431 * S points to the beginning of the symbol.
432 * [In case of pseudo-op, s->'.'.]
433 * Input_line_pointer->'\0' where c was.
434 */
435 if (TC_START_LABEL(c, input_line_pointer))
436 {
437 colon (s); /* user-defined label */
438 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */
439 /* Input_line_pointer->after ':'. */
440 SKIP_WHITESPACE ();
441
442
443 }
444 else if (c == '='
445 || (input_line_pointer[1] == '='
446 #ifdef TC_EQUAL_IN_INSN
447 && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
448 #endif
449 ))
450 {
451 equals (s);
452 demand_empty_rest_of_line ();
453 }
454 else
455 { /* expect pseudo-op or machine instruction */
456 #ifdef MRI
457 if (!done_pseudo (s))
458
459 #else
460
461 pop = NULL;
462
463 #ifdef NO_PSEUDO_DOT
464 /* The m88k uses pseudo-ops without a period. */
465 pop = (pseudo_typeS *) hash_find (po_hash, s);
466 if (pop != NULL && pop->poc_handler == NULL)
467 pop = NULL;
468 #endif
469
470 if (pop != NULL || *s == '.')
471 {
472 /*
473 * PSEUDO - OP.
474 *
475 * WARNING: c has next char, which may be end-of-line.
476 * We lookup the pseudo-op table with s+1 because we
477 * already know that the pseudo-op begins with a '.'.
478 */
479
480 if (pop == NULL)
481 pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
482
483 /* Print the error msg now, while we still can */
484 if (pop == NULL)
485 {
486 as_bad ("Unknown pseudo-op: `%s'", s);
487 *input_line_pointer = c;
488 s_ignore (0);
489 break;
490 }
491
492 /* Put it back for error messages etc. */
493 *input_line_pointer = c;
494 /* The following skip of whitespace is compulsory.
495 A well shaped space is sometimes all that separates
496 keyword from operands. */
497 if (c == ' ' || c == '\t')
498 {
499 input_line_pointer++;
500 } /* Skip seperator after keyword. */
501 /*
502 * Input_line is restored.
503 * Input_line_pointer->1st non-blank char
504 * after pseudo-operation.
505 */
506 if (!pop)
507 {
508 ignore_rest_of_line ();
509 break;
510 }
511 else
512 {
513 (*pop->poc_handler) (pop->poc_val);
514 } /* if we have one */
515 }
516 else
517 #endif
518 { /* machine instruction */
519 /* WARNING: c has char, which may be end-of-line. */
520 /* Also: input_line_pointer->`\0` where c was. */
521 *input_line_pointer = c;
522 while (!is_end_of_line[(unsigned char) *input_line_pointer]
523 #ifdef TC_EOL_IN_INSN
524 || TC_EOL_IN_INSN (input_line_pointer)
525 #endif
526 )
527 {
528 input_line_pointer++;
529 }
530
531 c = *input_line_pointer;
532 *input_line_pointer = '\0';
533
534 md_assemble (s); /* Assemble 1 instruction. */
535
536 *input_line_pointer++ = c;
537
538 /* We resume loop AFTER the end-of-line from this instruction */
539 } /* if (*s=='.') */
540
541 } /* if c==':' */
542 continue;
543 } /* if (is_name_beginner(c) */
544
545
546 if (is_end_of_line[(unsigned char) c])
547 {
548 continue;
549 } /* empty statement */
550
551
552 #if defined(LOCAL_LABELS_DOLLAR) || defined(LOCAL_LABELS_FB)
553 if (isdigit (c))
554 { /* local label ("4:") */
555 char *backup = input_line_pointer;
556
557 HANDLE_CONDITIONAL_ASSEMBLY ();
558
559 temp = c - '0';
560
561 while (isdigit (*input_line_pointer))
562 {
563 temp = (temp * 10) + *input_line_pointer - '0';
564 ++input_line_pointer;
565 } /* read the whole number */
566
567 #ifdef LOCAL_LABELS_DOLLAR
568 if (*input_line_pointer == '$'
569 && *(input_line_pointer + 1) == ':')
570 {
571 input_line_pointer += 2;
572
573 if (dollar_label_defined (temp))
574 {
575 as_fatal ("label \"%d$\" redefined", temp);
576 }
577
578 define_dollar_label (temp);
579 colon (dollar_label_name (temp, 0));
580 continue;
581 }
582 #endif /* LOCAL_LABELS_DOLLAR */
583
584 #ifdef LOCAL_LABELS_FB
585 if (*input_line_pointer++ == ':')
586 {
587 fb_label_instance_inc (temp);
588 colon (fb_label_name (temp, 0));
589 continue;
590 }
591 #endif /* LOCAL_LABELS_FB */
592
593 input_line_pointer = backup;
594 } /* local label ("4:") */
595 #endif /* LOCAL_LABELS_DOLLAR or LOCAL_LABELS_FB */
596
597 if (c && strchr (line_comment_chars, c))
598 { /* Its a comment. Better say APP or NO_APP */
599 char *ends;
600 char *new_buf;
601 char *new_tmp;
602 int new_length;
603 char *tmp_buf = 0;
604 extern char *scrub_string, *scrub_last_string;
605
606 bump_line_counters ();
607 s = input_line_pointer;
608 if (strncmp (s, "APP\n", 4))
609 continue; /* We ignore it */
610 s += 4;
611
612 ends = strstr (s, "#NO_APP\n");
613
614 if (!ends)
615 {
616 int tmp_len;
617 int num;
618
619 /* The end of the #APP wasn't in this buffer. We
620 keep reading in buffers until we find the #NO_APP
621 that goes with this #APP There is one. The specs
622 guarentee it. . . */
623 tmp_len = buffer_limit - s;
624 tmp_buf = xmalloc (tmp_len + 1);
625 memcpy (tmp_buf, s, tmp_len);
626 do
627 {
628 new_tmp = input_scrub_next_buffer (&buffer);
629 if (!new_tmp)
630 break;
631 else
632 buffer_limit = new_tmp;
633 input_line_pointer = buffer;
634 ends = strstr (buffer, "#NO_APP\n");
635 if (ends)
636 num = ends - buffer;
637 else
638 num = buffer_limit - buffer;
639
640 tmp_buf = xrealloc (tmp_buf, tmp_len + num);
641 memcpy (tmp_buf, buffer + tmp_len, num);
642 tmp_len += num;
643 }
644 while (!ends);
645
646 input_line_pointer = ends ? ends + 8 : NULL;
647
648 s = tmp_buf;
649 ends = s + tmp_len;
650
651 }
652 else
653 {
654 input_line_pointer = ends + 8;
655 }
656 new_buf = xmalloc (100);
657 new_length = 100;
658 new_tmp = new_buf;
659
660 scrub_string = s;
661 scrub_last_string = ends;
662 for (;;)
663 {
664 int ch;
665
666 ch = do_scrub_next_char (scrub_from_string, scrub_to_string);
667 if (ch == EOF)
668 break;
669 *new_tmp++ = ch;
670 if (new_tmp == new_buf + new_length)
671 {
672 new_buf = xrealloc (new_buf, new_length + 100);
673 new_tmp = new_buf + new_length;
674 new_length += 100;
675 }
676 }
677
678 if (tmp_buf)
679 free (tmp_buf);
680 old_buffer = buffer;
681 old_input = input_line_pointer;
682 old_limit = buffer_limit;
683 buffer = new_buf;
684 input_line_pointer = new_buf;
685 buffer_limit = new_tmp;
686 continue;
687 }
688
689 HANDLE_CONDITIONAL_ASSEMBLY ();
690
691 /* as_warn("Junk character %d.",c); Now done by ignore_rest */
692 input_line_pointer--; /* Report unknown char as ignored. */
693 ignore_rest_of_line ();
694 } /* while (input_line_pointer<buffer_limit) */
695 if (old_buffer)
696 {
697 bump_line_counters ();
698 if (old_input != 0)
699 {
700 buffer = old_buffer;
701 input_line_pointer = old_input;
702 buffer_limit = old_limit;
703 old_buffer = 0;
704 goto contin;
705 }
706 }
707 } /* while (more buffers to scan) */
708 input_scrub_close (); /* Close the input file */
709
710 } /* read_a_source_file() */
711
712 void
713 s_abort ()
714 {
715 as_fatal (".abort detected. Abandoning ship.");
716 } /* s_abort() */
717
718 /* For machines where ".align 4" means align to a 4 byte boundary. */
719 void
720 s_align_bytes (arg)
721 int arg;
722 {
723 register unsigned int temp;
724 register long temp_fill;
725 unsigned int i = 0;
726 unsigned long max_alignment = 1 << 15;
727
728 if (is_end_of_line[(unsigned char) *input_line_pointer])
729 temp = arg; /* Default value from pseudo-op table */
730 else
731 temp = get_absolute_expression ();
732
733 if (temp > max_alignment)
734 {
735 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
736 }
737
738 /*
739 * For the sparc, `.align (1<<n)' actually means `.align n'
740 * so we have to convert it.
741 */
742 if (temp != 0)
743 {
744 for (i = 0; (temp & 1) == 0; temp >>= 1, ++i)
745 ;
746 }
747 if (temp != 1)
748 as_bad ("Alignment not a power of 2");
749
750 temp = i;
751 if (*input_line_pointer == ',')
752 {
753 input_line_pointer++;
754 temp_fill = get_absolute_expression ();
755 }
756 else if (now_seg != data_section && now_seg != bss_section)
757 temp_fill = NOP_OPCODE;
758 else
759 temp_fill = 0;
760 /* Only make a frag if we HAVE to. . . */
761 if (temp && !need_pass_2)
762 frag_align (temp, (int) temp_fill);
763
764 record_alignment (now_seg, temp);
765
766 demand_empty_rest_of_line ();
767 } /* s_align_bytes() */
768
769 /* For machines where ".align 4" means align to 2**4 boundary. */
770 void
771 s_align_ptwo ()
772 {
773 register int temp;
774 register long temp_fill;
775 long max_alignment = 15;
776
777 temp = get_absolute_expression ();
778 if (temp > max_alignment)
779 as_bad ("Alignment too large: %d. assumed.", temp = max_alignment);
780 else if (temp < 0)
781 {
782 as_bad ("Alignment negative. 0 assumed.");
783 temp = 0;
784 }
785 if (*input_line_pointer == ',')
786 {
787 input_line_pointer++;
788 temp_fill = get_absolute_expression ();
789 }
790 /* @@ Fix this right for BFD! */
791 else if (now_seg != data_section && now_seg != bss_section)
792 temp_fill = NOP_OPCODE;
793 else
794 temp_fill = 0;
795 /* Only make a frag if we HAVE to. . . */
796 if (temp && !need_pass_2)
797 frag_align (temp, (int) temp_fill);
798
799 record_alignment (now_seg, temp);
800
801 demand_empty_rest_of_line ();
802 } /* s_align_ptwo() */
803
804 void
805 s_comm ()
806 {
807 register char *name;
808 register char c;
809 register char *p;
810 offsetT temp;
811 register symbolS *symbolP;
812
813 name = input_line_pointer;
814 c = get_symbol_end ();
815 /* just after name is now '\0' */
816 p = input_line_pointer;
817 *p = c;
818 SKIP_WHITESPACE ();
819 if (*input_line_pointer != ',')
820 {
821 as_bad ("Expected comma after symbol-name: rest of line ignored.");
822 ignore_rest_of_line ();
823 return;
824 }
825 input_line_pointer++; /* skip ',' */
826 if ((temp = get_absolute_expression ()) < 0)
827 {
828 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
829 ignore_rest_of_line ();
830 return;
831 }
832 *p = 0;
833 symbolP = symbol_find_or_make (name);
834 *p = c;
835 if (S_IS_DEFINED (symbolP))
836 {
837 as_bad ("Ignoring attempt to re-define symbol");
838 ignore_rest_of_line ();
839 return;
840 }
841 if (S_GET_VALUE (symbolP))
842 {
843 if (S_GET_VALUE (symbolP) != (valueT) temp)
844 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
845 S_GET_NAME (symbolP),
846 (long) S_GET_VALUE (symbolP),
847 (long) temp);
848 }
849 else
850 {
851 S_SET_VALUE (symbolP, (valueT) temp);
852 S_SET_EXTERNAL (symbolP);
853 }
854 #ifdef OBJ_VMS
855 if ( (!temp) || !flagseen['1'])
856 S_GET_OTHER(symbolP) = const_flag;
857 #endif /* not OBJ_VMS */
858 know (symbolP->sy_frag == &zero_address_frag);
859 demand_empty_rest_of_line ();
860 } /* s_comm() */
861
862 void
863 s_data ()
864 {
865 segT section;
866 register int temp;
867
868 temp = get_absolute_expression ();
869 if (flagseen['R'])
870 {
871 section = text_section;
872 temp += 1000;
873 }
874 else
875 section = data_section;
876
877 #ifdef BFD_ASSEMBLER
878 subseg_set (section, (subsegT) temp);
879 #else
880 subseg_new (section, (subsegT) temp);
881 #endif
882
883 #ifdef OBJ_VMS
884 const_flag = 0;
885 #endif
886 demand_empty_rest_of_line ();
887 }
888
889 /* Handle the .appfile pseudo-op. This is automatically generated by
890 do_scrub_next_char when a preprocessor # line comment is seen with
891 a file name. This default definition may be overridden by the
892 object or CPU specific pseudo-ops. This function is also the
893 default definition for .file; the APPFILE argument is 1 for
894 .appfile, 0 for .file. */
895
896 void
897 s_app_file (appfile)
898 int appfile;
899 {
900 register char *s;
901 int length;
902
903 /* Some assemblers tolerate immediately following '"' */
904 if ((s = demand_copy_string (&length)) != 0)
905 {
906 /* If this is a fake .appfile, a fake newline was inserted into
907 the buffer. Passing -2 to new_logical_line tells it to
908 account for it. */
909 new_logical_line (s, appfile ? -2 : -1);
910 demand_empty_rest_of_line ();
911 #ifdef LISTING
912 if (listing)
913 listing_source_file (s);
914 #endif
915 }
916 #ifdef OBJ_COFF
917 c_dot_file_symbol (s);
918 #endif /* OBJ_COFF */
919 #ifdef OBJ_ELF
920 elf_file_symbol (s);
921 #endif
922 }
923
924 /* Handle the .appline pseudo-op. This is automatically generated by
925 do_scrub_next_char when a preprocessor # line comment is seen.
926 This default definition may be overridden by the object or CPU
927 specific pseudo-ops. */
928
929 void
930 s_app_line ()
931 {
932 int l;
933
934 /* The given number is that of the next line. */
935 l = get_absolute_expression () - 1;
936 new_logical_line ((char *) NULL, l);
937 #ifdef LISTING
938 if (listing)
939 listing_source_line (l);
940 #endif
941 demand_empty_rest_of_line ();
942 }
943
944 void
945 s_fill ()
946 {
947 long temp_repeat = 0;
948 long temp_size = 1;
949 register long temp_fill = 0;
950 char *p;
951
952
953 temp_repeat = get_absolute_expression ();
954 if (*input_line_pointer == ',')
955 {
956 input_line_pointer++;
957 temp_size = get_absolute_expression ();
958 if (*input_line_pointer == ',')
959 {
960 input_line_pointer++;
961 temp_fill = get_absolute_expression ();
962 }
963 }
964 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */
965 #define BSD_FILL_SIZE_CROCK_8 (8)
966 if (temp_size > BSD_FILL_SIZE_CROCK_8)
967 {
968 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8);
969 temp_size = BSD_FILL_SIZE_CROCK_8;
970 }
971 if (temp_size < 0)
972 {
973 as_warn ("Size negative: .fill ignored.");
974 temp_size = 0;
975 }
976 else if (temp_repeat <= 0)
977 {
978 as_warn ("Repeat < 0, .fill ignored");
979 temp_size = 0;
980 }
981
982 if (temp_size && !need_pass_2)
983 {
984 p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0);
985 memset (p, 0, (int) temp_size);
986 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
987 * flavoured AS. The following bizzare behaviour is to be
988 * compatible with above. I guess they tried to take up to 8
989 * bytes from a 4-byte expression and they forgot to sign
990 * extend. Un*x Sux. */
991 #define BSD_FILL_SIZE_CROCK_4 (4)
992 md_number_to_chars (p, temp_fill,
993 (temp_size > BSD_FILL_SIZE_CROCK_4
994 ? BSD_FILL_SIZE_CROCK_4
995 : (int) temp_size));
996 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
997 * but emits no error message because it seems a legal thing to do.
998 * It is a degenerate case of .fill but could be emitted by a compiler.
999 */
1000 }
1001 demand_empty_rest_of_line ();
1002 }
1003
1004 void
1005 s_globl ()
1006 {
1007 char *name;
1008 int c;
1009 symbolS *symbolP;
1010
1011 do
1012 {
1013 name = input_line_pointer;
1014 c = get_symbol_end ();
1015 symbolP = symbol_find_or_make (name);
1016 *input_line_pointer = c;
1017 SKIP_WHITESPACE ();
1018 S_SET_EXTERNAL (symbolP);
1019 if (c == ',')
1020 {
1021 input_line_pointer++;
1022 SKIP_WHITESPACE ();
1023 if (*input_line_pointer == '\n')
1024 c = '\n';
1025 }
1026 }
1027 while (c == ',');
1028 demand_empty_rest_of_line ();
1029 }
1030
1031 void
1032 s_lcomm (needs_align)
1033 /* 1 if this was a ".bss" directive, which may require a 3rd argument
1034 (alignment); 0 if it was an ".lcomm" (2 args only) */
1035 int needs_align;
1036 {
1037 register char *name;
1038 register char c;
1039 register char *p;
1040 register int temp;
1041 register symbolS *symbolP;
1042 segT current_seg = now_seg;
1043 subsegT current_subseg = now_subseg;
1044 const int max_alignment = 15;
1045 int align = 0;
1046 segT bss_seg = bss_section;
1047
1048 name = input_line_pointer;
1049 c = get_symbol_end ();
1050 p = input_line_pointer;
1051 *p = c;
1052 SKIP_WHITESPACE ();
1053 if (*input_line_pointer != ',')
1054 {
1055 as_bad ("Expected comma after name");
1056 ignore_rest_of_line ();
1057 return;
1058 }
1059
1060 ++input_line_pointer;
1061
1062 if (*input_line_pointer == '\n')
1063 {
1064 as_bad ("Missing size expression");
1065 return;
1066 }
1067
1068 if ((temp = get_absolute_expression ()) < 0)
1069 {
1070 as_warn ("BSS length (%d.) <0! Ignored.", temp);
1071 ignore_rest_of_line ();
1072 return;
1073 }
1074
1075 #ifdef TC_MIPS
1076 #ifdef OBJ_ECOFF
1077 /* For MIPS ECOFF, small objects are put in .sbss. */
1078 if (temp <= bfd_get_gp_size (stdoutput))
1079 bss_seg = subseg_new (".sbss", 1);
1080 #endif
1081 #endif
1082
1083 if (needs_align)
1084 {
1085 align = 0;
1086 SKIP_WHITESPACE ();
1087 if (*input_line_pointer != ',')
1088 {
1089 as_bad ("Expected comma after size");
1090 ignore_rest_of_line ();
1091 return;
1092 }
1093 input_line_pointer++;
1094 SKIP_WHITESPACE ();
1095 if (*input_line_pointer == '\n')
1096 {
1097 as_bad ("Missing alignment");
1098 return;
1099 }
1100 align = get_absolute_expression ();
1101 if (align > max_alignment)
1102 {
1103 align = max_alignment;
1104 as_warn ("Alignment too large: %d. assumed.", align);
1105 }
1106 else if (align < 0)
1107 {
1108 align = 0;
1109 as_warn ("Alignment negative. 0 assumed.");
1110 }
1111 record_alignment (bss_seg, align);
1112 } /* if needs align */
1113
1114 *p = 0;
1115 symbolP = symbol_find_or_make (name);
1116 *p = c;
1117
1118 if (
1119 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1120 S_GET_OTHER (symbolP) == 0 &&
1121 S_GET_DESC (symbolP) == 0 &&
1122 #endif /* OBJ_AOUT or OBJ_BOUT */
1123 (S_GET_SEGMENT (symbolP) == bss_seg
1124 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
1125 {
1126 char *p;
1127
1128 #ifdef BFD_ASSEMBLER
1129 subseg_set (bss_seg, 1);
1130 #else
1131 subseg_new (bss_seg, 1);
1132 #endif
1133
1134 if (align)
1135 frag_align (align, 0);
1136 /* detach from old frag */
1137 if (S_GET_SEGMENT (symbolP) == bss_seg)
1138 symbolP->sy_frag->fr_symbol = NULL;
1139
1140 symbolP->sy_frag = frag_now;
1141 p = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
1142 temp, (char *)0);
1143 *p = 0;
1144
1145 S_SET_SEGMENT (symbolP, bss_seg);
1146
1147 #ifdef OBJ_COFF
1148 /* The symbol may already have been created with a preceding
1149 ".globl" directive -- be careful not to step on storage class
1150 in that case. Otherwise, set it to static. */
1151 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
1152 {
1153 S_SET_STORAGE_CLASS (symbolP, C_STAT);
1154 }
1155 #endif /* OBJ_COFF */
1156 }
1157 else
1158 {
1159 as_bad ("Ignoring attempt to re-define symbol %s.", name);
1160 }
1161
1162 #ifdef BFD_ASSEMBLER
1163 subseg_set (current_seg, current_subseg);
1164 #else
1165 subseg_new (current_seg, current_subseg);
1166 #endif
1167
1168 demand_empty_rest_of_line ();
1169 } /* s_lcomm() */
1170
1171 void
1172 s_long ()
1173 {
1174 cons (4);
1175 }
1176
1177 void
1178 s_int ()
1179 {
1180 cons (4);
1181 }
1182
1183 void
1184 s_lsym ()
1185 {
1186 register char *name;
1187 register char c;
1188 register char *p;
1189 expressionS exp;
1190 register symbolS *symbolP;
1191
1192 /* we permit ANY defined expression: BSD4.2 demands constants */
1193 name = input_line_pointer;
1194 c = get_symbol_end ();
1195 p = input_line_pointer;
1196 *p = c;
1197 SKIP_WHITESPACE ();
1198 if (*input_line_pointer != ',')
1199 {
1200 *p = 0;
1201 as_bad ("Expected comma after name \"%s\"", name);
1202 *p = c;
1203 ignore_rest_of_line ();
1204 return;
1205 }
1206 input_line_pointer++;
1207 expression (&exp);
1208 if (exp.X_op != O_constant
1209 && exp.X_op != O_register)
1210 {
1211 as_bad ("bad expression");
1212 ignore_rest_of_line ();
1213 return;
1214 }
1215 *p = 0;
1216 symbolP = symbol_find_or_make (name);
1217
1218 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
1219 symbolP->sy_desc == 0) out of this test because coff doesn't have
1220 those fields, and I can't see when they'd ever be tripped. I
1221 don't think I understand why they were here so I may have
1222 introduced a bug. As recently as 1.37 didn't have this test
1223 anyway. xoxorich. */
1224
1225 if (S_GET_SEGMENT (symbolP) == undefined_section
1226 && S_GET_VALUE (symbolP) == 0)
1227 {
1228 /* The name might be an undefined .global symbol; be sure to
1229 keep the "external" bit. */
1230 S_SET_SEGMENT (symbolP,
1231 (exp.X_op == O_constant
1232 ? absolute_section
1233 : reg_section));
1234 S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
1235 }
1236 else
1237 {
1238 as_bad ("Symbol %s already defined", name);
1239 }
1240 *p = c;
1241 demand_empty_rest_of_line ();
1242 } /* s_lsym() */
1243
1244 void
1245 s_org ()
1246 {
1247 register segT segment;
1248 expressionS exp;
1249 register long temp_fill;
1250 register char *p;
1251 /* Don't believe the documentation of BSD 4.2 AS. There is no such
1252 thing as a sub-segment-relative origin. Any absolute origin is
1253 given a warning, then assumed to be segment-relative. Any
1254 segmented origin expression ("foo+42") had better be in the right
1255 segment or the .org is ignored.
1256
1257 BSD 4.2 AS warns if you try to .org backwards. We cannot because
1258 we never know sub-segment sizes when we are reading code. BSD
1259 will crash trying to emit negative numbers of filler bytes in
1260 certain .orgs. We don't crash, but see as-write for that code.
1261
1262 Don't make frag if need_pass_2==1. */
1263 segment = get_known_segmented_expression (&exp);
1264 if (*input_line_pointer == ',')
1265 {
1266 input_line_pointer++;
1267 temp_fill = get_absolute_expression ();
1268 }
1269 else
1270 temp_fill = 0;
1271 if (!need_pass_2)
1272 {
1273 if (segment != now_seg && segment != absolute_section)
1274 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1275 segment_name (segment), segment_name (now_seg));
1276 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1277 exp.X_add_number, (char *) 0);
1278 *p = temp_fill;
1279 } /* if (ok to make frag) */
1280 demand_empty_rest_of_line ();
1281 } /* s_org() */
1282
1283 void
1284 s_set ()
1285 {
1286 register char *name;
1287 register char delim;
1288 register char *end_name;
1289 register symbolS *symbolP;
1290
1291 /*
1292 * Especial apologies for the random logic:
1293 * this just grew, and could be parsed much more simply!
1294 * Dean in haste.
1295 */
1296 name = input_line_pointer;
1297 delim = get_symbol_end ();
1298 end_name = input_line_pointer;
1299 *end_name = delim;
1300 SKIP_WHITESPACE ();
1301
1302 if (*input_line_pointer != ',')
1303 {
1304 *end_name = 0;
1305 as_bad ("Expected comma after name \"%s\"", name);
1306 *end_name = delim;
1307 ignore_rest_of_line ();
1308 return;
1309 }
1310
1311 input_line_pointer++;
1312 *end_name = 0;
1313
1314 if (name[0] == '.' && name[1] == '\0')
1315 {
1316 /* Turn '. = mumble' into a .org mumble */
1317 register segT segment;
1318 expressionS exp;
1319 register char *ptr;
1320
1321 segment = get_known_segmented_expression (&exp);
1322
1323 if (!need_pass_2)
1324 {
1325 if (segment != now_seg && segment != absolute_section)
1326 as_bad ("Invalid segment \"%s\". Segment \"%s\" assumed.",
1327 segment_name (segment),
1328 segment_name (now_seg));
1329 ptr = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
1330 exp.X_add_number, (char *) 0);
1331 *ptr = 0;
1332 } /* if (ok to make frag) */
1333
1334 *end_name = delim;
1335 return;
1336 }
1337
1338 if ((symbolP = symbol_find (name)) == NULL
1339 && (symbolP = md_undefined_symbol (name)) == NULL)
1340 {
1341 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
1342 #ifdef OBJ_COFF
1343 /* "set" symbols are local unless otherwise specified. */
1344 SF_SET_LOCAL (symbolP);
1345 #endif /* OBJ_COFF */
1346
1347 } /* make a new symbol */
1348
1349 symbol_table_insert (symbolP);
1350
1351 *end_name = delim;
1352 pseudo_set (symbolP);
1353 demand_empty_rest_of_line ();
1354 } /* s_set() */
1355
1356 void
1357 s_space (mult)
1358 int mult;
1359 {
1360 long temp_repeat;
1361 register long temp_fill;
1362 register char *p;
1363
1364 /* Just like .fill, but temp_size = 1 */
1365 if (get_absolute_expression_and_terminator (&temp_repeat) == ',')
1366 {
1367 temp_fill = get_absolute_expression ();
1368 }
1369 else
1370 {
1371 input_line_pointer--; /* Backup over what was not a ','. */
1372 temp_fill = 0;
1373 }
1374 if (mult)
1375 {
1376 temp_repeat *= mult;
1377 }
1378 if (temp_repeat <= 0)
1379 {
1380 as_warn ("Repeat < 0, .space ignored");
1381 ignore_rest_of_line ();
1382 return;
1383 }
1384 if (!need_pass_2)
1385 {
1386 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
1387 temp_repeat, (char *) 0);
1388 *p = temp_fill;
1389 }
1390 demand_empty_rest_of_line ();
1391 } /* s_space() */
1392
1393 void
1394 s_text ()
1395 {
1396 register int temp;
1397
1398 temp = get_absolute_expression ();
1399 #ifdef BFD_ASSEMBLER
1400 subseg_set (text_section, (subsegT) temp);
1401 #else
1402 subseg_new (text_section, (subsegT) temp);
1403 #endif
1404 demand_empty_rest_of_line ();
1405 } /* s_text() */
1406 \f
1407
1408 void
1409 demand_empty_rest_of_line ()
1410 {
1411 SKIP_WHITESPACE ();
1412 if (is_end_of_line[(unsigned char) *input_line_pointer])
1413 {
1414 input_line_pointer++;
1415 }
1416 else
1417 {
1418 ignore_rest_of_line ();
1419 }
1420 /* Return having already swallowed end-of-line. */
1421 } /* Return pointing just after end-of-line. */
1422
1423 void
1424 ignore_rest_of_line () /* For suspect lines: gives warning. */
1425 {
1426 if (!is_end_of_line[(unsigned char) *input_line_pointer])
1427 {
1428 if (isprint (*input_line_pointer))
1429 as_bad ("Rest of line ignored. First ignored character is `%c'.",
1430 *input_line_pointer);
1431 else
1432 as_bad ("Rest of line ignored. First ignored character valued 0x%x.",
1433 *input_line_pointer);
1434 while (input_line_pointer < buffer_limit
1435 && !is_end_of_line[(unsigned char) *input_line_pointer])
1436 {
1437 input_line_pointer++;
1438 }
1439 }
1440 input_line_pointer++; /* Return pointing just after end-of-line. */
1441 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
1442 }
1443
1444 /*
1445 * pseudo_set()
1446 *
1447 * In: Pointer to a symbol.
1448 * Input_line_pointer->expression.
1449 *
1450 * Out: Input_line_pointer->just after any whitespace after expression.
1451 * Tried to set symbol to value of expression.
1452 * Will change symbols type, value, and frag;
1453 */
1454 void
1455 pseudo_set (symbolP)
1456 symbolS *symbolP;
1457 {
1458 expressionS exp;
1459 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1460 int ext;
1461 #endif /* OBJ_AOUT or OBJ_BOUT */
1462
1463 know (symbolP); /* NULL pointer is logic error. */
1464 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1465 /* @@ Fix this right for BFD. */
1466 ext = S_IS_EXTERNAL (symbolP);
1467 #endif /* OBJ_AOUT or OBJ_BOUT */
1468
1469 (void) expression (&exp);
1470
1471 if (exp.X_op == O_illegal)
1472 as_bad ("illegal expression; zero assumed");
1473 else if (exp.X_op == O_absent)
1474 as_bad ("missing expression; zero assumed");
1475 else if (exp.X_op == O_big)
1476 as_bad ("%s number invalid; zero assumed",
1477 exp.X_add_number > 0 ? "bignum" : "floating point");
1478 else if (exp.X_op == O_subtract
1479 && (S_GET_SEGMENT (exp.X_add_symbol)
1480 == S_GET_SEGMENT (exp.X_op_symbol))
1481 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
1482 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag)
1483 {
1484 exp.X_op = O_constant;
1485 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
1486 - S_GET_VALUE (exp.X_op_symbol));
1487 }
1488
1489 switch (exp.X_op)
1490 {
1491 case O_illegal:
1492 case O_absent:
1493 case O_big:
1494 exp.X_add_number = 0;
1495 /* Fall through. */
1496 case O_constant:
1497 S_SET_SEGMENT (symbolP, absolute_section);
1498 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1499 /* @@ Fix this right for BFD. */
1500 if (ext)
1501 S_SET_EXTERNAL (symbolP);
1502 else
1503 S_CLEAR_EXTERNAL (symbolP);
1504 #endif /* OBJ_AOUT or OBJ_BOUT */
1505 S_SET_VALUE (symbolP, exp.X_add_number);
1506 symbolP->sy_frag = &zero_address_frag;
1507 break;
1508
1509 case O_register:
1510 S_SET_SEGMENT (symbolP, reg_section);
1511 S_SET_VALUE (symbolP, exp.X_add_number);
1512 symbolP->sy_frag = &zero_address_frag;
1513 break;
1514
1515 case O_symbol:
1516 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
1517 symbolP->sy_value = exp;
1518 else
1519 {
1520 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (exp.X_add_symbol));
1521 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
1522 /* @@ Fix this right for BFD! */
1523 if (ext)
1524 S_SET_EXTERNAL (symbolP);
1525 else
1526 S_CLEAR_EXTERNAL (symbolP);
1527 #endif /* OBJ_AOUT or OBJ_BOUT */
1528 S_SET_VALUE (symbolP,
1529 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
1530 symbolP->sy_frag = exp.X_add_symbol->sy_frag;
1531 }
1532 break;
1533
1534 default:
1535 /* The value is some complex expression.
1536 FIXME: Should we set the segment to anything? */
1537 symbolP->sy_value = exp;
1538 break;
1539 }
1540 }
1541 \f
1542 /*
1543 * cons()
1544 *
1545 * CONStruct more frag of .bytes, or .words etc.
1546 * Should need_pass_2 be 1 then emit no frag(s).
1547 * This understands EXPRESSIONS, as opposed to big_cons().
1548 *
1549 * Bug (?)
1550 *
1551 * This has a split personality. We use expression() to read the
1552 * value. We can detect if the value won't fit in a byte or word.
1553 * But we can't detect if expression() discarded significant digits
1554 * in the case of a long. Not worth the crocks required to fix it.
1555 */
1556
1557 /* Select a parser for cons expressions. */
1558
1559 /* Some targets need to parse the expression in various fancy ways.
1560 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
1561 (for example, the HPPA does this). Otherwise, you can define
1562 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
1563 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these
1564 are defined, which is the normal case, then only simple expressions
1565 are permitted. */
1566
1567 #ifndef TC_PARSE_CONS_EXPRESSION
1568 #ifdef BITFIELD_CONS_EXPRESSIONS
1569 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
1570 static void
1571 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1572 #endif
1573 #ifdef MRI
1574 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_mri_cons (EXP)
1575 static void
1576 parse_mri_cons PARAMS ((expressionS *exp));
1577 #endif
1578 #ifdef REPEAT_CONS_EXPRESSIONS
1579 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
1580 static void
1581 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
1582 #endif
1583
1584 /* If we haven't gotten one yet, just call expression. */
1585 #ifndef TC_PARSE_CONS_EXPRESSION
1586 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
1587 #endif
1588 #endif
1589
1590 /* worker to do .byte etc statements */
1591 /* clobbers input_line_pointer, checks */
1592 /* end-of-line. */
1593 void
1594 cons (nbytes)
1595 register unsigned int nbytes; /* 1=.byte, 2=.word, 4=.long */
1596 {
1597 expressionS exp;
1598
1599 if (is_it_end_of_statement ())
1600 {
1601 demand_empty_rest_of_line ();
1602 return;
1603 }
1604
1605 do
1606 {
1607 TC_PARSE_CONS_EXPRESSION (&exp, nbytes);
1608 emit_expr (&exp, nbytes);
1609 }
1610 while (*input_line_pointer++ == ',');
1611
1612 input_line_pointer--; /* Put terminator back into stream. */
1613 demand_empty_rest_of_line ();
1614 } /* cons() */
1615
1616 /* Put the contents of expression EXP into the object file using
1617 NBYTES bytes. If need_pass_2 is 1, this does nothing. */
1618
1619 void
1620 emit_expr (exp, nbytes)
1621 expressionS *exp;
1622 unsigned int nbytes;
1623 {
1624 operatorT op;
1625 register char *p;
1626
1627 /* Don't do anything if we are going to make another pass. */
1628 if (need_pass_2)
1629 return;
1630
1631 op = exp->X_op;
1632
1633 if (op == O_absent || op == O_illegal)
1634 {
1635 as_warn ("zero assumed for missing expression");
1636 exp->X_add_number = 0;
1637 op = O_constant;
1638 }
1639 else if (op == O_big)
1640 {
1641 as_bad ("%s number invalid; zero assumed",
1642 exp->X_add_number > 0 ? "bignum" : "floating point");
1643 exp->X_add_number = 0;
1644 op = O_constant;
1645 }
1646 else if (op == O_register)
1647 {
1648 as_warn ("register value used as expression");
1649 op = O_constant;
1650 }
1651
1652 p = frag_more (nbytes);
1653
1654 #ifndef WORKING_DOT_WORD
1655 /* If we have the difference of two symbols in a word, save it on
1656 the broken_words list. See the code in write.c. */
1657 if (op == O_subtract && nbytes == 2)
1658 {
1659 struct broken_word *x;
1660
1661 x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
1662 x->next_broken_word = broken_words;
1663 broken_words = x;
1664 x->frag = frag_now;
1665 x->word_goes_here = p;
1666 x->dispfrag = 0;
1667 x->add = exp->X_add_symbol;
1668 x->sub = exp->X_op_symbol;
1669 x->addnum = exp->X_add_number;
1670 x->added = 0;
1671 new_broken_words++;
1672 return;
1673 }
1674 #endif
1675
1676 if (op == O_constant)
1677 {
1678 register long get;
1679 register long use;
1680 register long mask;
1681 register long unmask;
1682
1683 /* JF << of >= number of bits in the object is undefined. In
1684 particular SPARC (Sun 4) has problems */
1685 if (nbytes >= sizeof (long))
1686 mask = 0;
1687 else
1688 mask = ~0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */
1689
1690 unmask = ~mask; /* Do store these bits. */
1691
1692 #ifdef NEVER
1693 "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
1694 mask = ~(unmask >> 1); /* Includes sign bit now. */
1695 #endif
1696
1697 get = exp->X_add_number;
1698 use = get & unmask;
1699 if ((get & mask) != 0 && (get & mask) != mask)
1700 { /* Leading bits contain both 0s & 1s. */
1701 as_warn ("Value 0x%lx truncated to 0x%lx.", get, use);
1702 }
1703 md_number_to_chars (p, use, nbytes); /* put bytes in right order. */
1704 }
1705 else
1706 {
1707 md_number_to_chars (p, (long) 0, nbytes);
1708
1709 /* Now we need to generate a fixS to record the symbol value.
1710 This is easy for BFD. For other targets it can be more
1711 complex. For very complex cases (currently, the HPPA and
1712 NS32K), you can define TC_CONS_FIX_NEW to do whatever you
1713 want. For simpler cases, you can define TC_CONS_RELOC to be
1714 the name of the reloc code that should be stored in the fixS.
1715 If neither is defined, the code uses NO_RELOC if it is
1716 defined, and otherwise uses 0. */
1717
1718 #ifdef BFD_ASSEMBLER
1719 #ifdef TC_CONS_FIX_NEW
1720 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1721 #else
1722 fix_new_exp (frag_now, p - frag_now->fr_literal, nbytes, exp, 0,
1723 /* @@ Should look at CPU word size. */
1724 nbytes == 2 ? BFD_RELOC_16
1725 : nbytes == 8 ? BFD_RELOC_64
1726 : BFD_RELOC_32);
1727 #endif
1728 #else
1729 #ifdef TC_CONS_FIX_NEW
1730 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
1731 #else
1732 /* Figure out which reloc number to use. Use TC_CONS_RELOC if
1733 it is defined, otherwise use NO_RELOC if it is defined,
1734 otherwise use 0. */
1735 #ifndef TC_CONS_RELOC
1736 #ifdef NO_RELOC
1737 #define TC_CONS_RELOC NO_RELOC
1738 #else
1739 #define TC_CONS_RELOC 0
1740 #endif
1741 #endif
1742 fix_new_exp (frag_now, p - frag_now->fr_literal, nbytes, exp, 0,
1743 TC_CONS_RELOC);
1744 #endif /* TC_CONS_FIX_NEW */
1745 #endif /* BFD_ASSEMBLER */
1746 }
1747 }
1748 \f
1749 #ifdef BITFIELD_CONS_EXPRESSIONS
1750
1751 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
1752 w:x,y:z, where w and y are bitwidths and x and y are values. They
1753 then pack them all together. We do a little better in that we allow
1754 them in words, longs, etc. and we'll pack them in target byte order
1755 for you.
1756
1757 The rules are: pack least significat bit first, if a field doesn't
1758 entirely fit, put it in the next unit. Overflowing the bitfield is
1759 explicitly *not* even a warning. The bitwidth should be considered
1760 a "mask".
1761
1762 To use this function the tc-XXX.h file should define
1763 BITFIELD_CONS_EXPRESSIONS. */
1764
1765 static void
1766 parse_bitfield_cons (exp, nbytes)
1767 expressionS *exp;
1768 unsigned int nbytes;
1769 {
1770 unsigned int bits_available = BITS_PER_CHAR * nbytes;
1771 char *hold = input_line_pointer;
1772
1773 (void) expression (exp);
1774
1775 if (*input_line_pointer == ':')
1776 { /* bitfields */
1777 long value = 0;
1778
1779 for (;;)
1780 {
1781 unsigned long width;
1782
1783 if (*input_line_pointer != ':')
1784 {
1785 input_line_pointer = hold;
1786 break;
1787 } /* next piece is not a bitfield */
1788
1789 /* In the general case, we can't allow
1790 full expressions with symbol
1791 differences and such. The relocation
1792 entries for symbols not defined in this
1793 assembly would require arbitrary field
1794 widths, positions, and masks which most
1795 of our current object formats don't
1796 support.
1797
1798 In the specific case where a symbol
1799 *is* defined in this assembly, we
1800 *could* build fixups and track it, but
1801 this could lead to confusion for the
1802 backends. I'm lazy. I'll take any
1803 SEG_ABSOLUTE. I think that means that
1804 you can use a previous .set or
1805 .equ type symbol. xoxorich. */
1806
1807 if (exp->X_op == O_absent)
1808 {
1809 as_warn ("using a bit field width of zero");
1810 exp->X_add_number = 0;
1811 exp->X_op = O_constant;
1812 } /* implied zero width bitfield */
1813
1814 if (exp->X_op != O_constant)
1815 {
1816 *input_line_pointer = '\0';
1817 as_bad ("field width \"%s\" too complex for a bitfield", hold);
1818 *input_line_pointer = ':';
1819 demand_empty_rest_of_line ();
1820 return;
1821 } /* too complex */
1822
1823 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
1824 {
1825 as_warn ("field width %d too big to fit in %d bytes: truncated to %d bits",
1826 width, nbytes, (BITS_PER_CHAR * nbytes));
1827 width = BITS_PER_CHAR * nbytes;
1828 } /* too big */
1829
1830 if (width > bits_available)
1831 {
1832 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */
1833 input_line_pointer = hold;
1834 exp->X_add_number = value;
1835 break;
1836 } /* won't fit */
1837
1838 hold = ++input_line_pointer; /* skip ':' */
1839
1840 (void) expression (exp);
1841 if (exp->X_op != O_constant)
1842 {
1843 char cache = *input_line_pointer;
1844
1845 *input_line_pointer = '\0';
1846 as_bad ("field value \"%s\" too complex for a bitfield", hold);
1847 *input_line_pointer = cache;
1848 demand_empty_rest_of_line ();
1849 return;
1850 } /* too complex */
1851
1852 value |= ((~(-1 << width) & exp->X_add_number)
1853 << ((BITS_PER_CHAR * nbytes) - bits_available));
1854
1855 if ((bits_available -= width) == 0
1856 || is_it_end_of_statement ()
1857 || *input_line_pointer != ',')
1858 {
1859 break;
1860 } /* all the bitfields we're gonna get */
1861
1862 hold = ++input_line_pointer;
1863 (void) expression (exp);
1864 } /* forever loop */
1865
1866 exp->X_add_number = value;
1867 exp->X_op = O_constant;
1868 } /* if looks like a bitfield */
1869 } /* parse_bitfield_cons() */
1870
1871 #endif /* BITFIELD_CONS_EXPRESSIONS */
1872 \f
1873 #ifdef MRI
1874
1875 static void
1876 parse_mri_cons (exp, nbytes)
1877 expressionS *exp;
1878 unsigned int nbytes;
1879 {
1880 if (*input_line_pointer == '\'')
1881 {
1882 /* An MRI style string, cut into as many bytes as will fit into
1883 a nbyte chunk, left justify if necessary, and separate with
1884 commas so we can try again later */
1885 int scan = 0;
1886 unsigned int result = 0;
1887 input_line_pointer++;
1888 for (scan = 0; scan < nbytes; scan++)
1889 {
1890 if (*input_line_pointer == '\'')
1891 {
1892 if (input_line_pointer[1] == '\'')
1893 {
1894 input_line_pointer++;
1895 }
1896 else
1897 break;
1898 }
1899 result = (result << 8) | (*input_line_pointer++);
1900 }
1901
1902 /* Left justify */
1903 while (scan < nbytes)
1904 {
1905 result <<= 8;
1906 scan++;
1907 }
1908 /* Create correct expression */
1909 exp->X_op = O_constant;
1910 exp->X_add_number = result;
1911 /* Fake it so that we can read the next char too */
1912 if (input_line_pointer[0] != '\'' ||
1913 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
1914 {
1915 input_line_pointer -= 2;
1916 input_line_pointer[0] = ',';
1917 input_line_pointer[1] = '\'';
1918 }
1919 else
1920 input_line_pointer++;
1921 }
1922 else
1923 expression (&exp);
1924 }
1925
1926 #endif /* MRI */
1927 \f
1928 #ifdef REPEAT_CONS_EXPRESSIONS
1929
1930 /* Parse a repeat expression for cons. This is used by the MIPS
1931 assembler. The format is NUMBER:COUNT; NUMBER appears in the
1932 object file COUNT times.
1933
1934 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */
1935
1936 static void
1937 parse_repeat_cons (exp, nbytes)
1938 expressionS *exp;
1939 unsigned int nbytes;
1940 {
1941 expressionS count;
1942 register int i;
1943
1944 expression (exp);
1945
1946 if (*input_line_pointer != ':')
1947 {
1948 /* No repeat count. */
1949 return;
1950 }
1951
1952 ++input_line_pointer;
1953 expression (&count);
1954 if (count.X_op != O_constant
1955 || count.X_add_number <= 0)
1956 {
1957 as_warn ("Unresolvable or nonpositive repeat count; using 1");
1958 return;
1959 }
1960
1961 /* The cons function is going to output this expression once. So we
1962 output it count - 1 times. */
1963 for (i = count.X_add_number - 1; i > 0; i--)
1964 emit_expr (exp, nbytes);
1965 }
1966
1967 #endif /* REPEAT_CONS_EXPRESSIONS */
1968 \f
1969 /*
1970 * big_cons()
1971 *
1972 * CONStruct more frag(s) of .quads, or .octa etc.
1973 * Makes 0 or more new frags.
1974 * If need_pass_2 == 1, generate no frag.
1975 * This understands only bignums, not expressions. Cons() understands
1976 * expressions.
1977 *
1978 * Constants recognised are '0...'(octal) '0x...'(hex) '...'(decimal).
1979 *
1980 * This creates objects with struct obstack_control objs, destroying
1981 * any context objs held about a partially completed object. Beware!
1982 *
1983 *
1984 * I think it sucks to have 2 different types of integers, with 2
1985 * routines to read them, store them etc.
1986 * It would be nicer to permit bignums in expressions and only
1987 * complain if the result overflowed. However, due to "efficiency"...
1988 */
1989 /* Worker to do .quad etc statements. Clobbers input_line_pointer, checks
1990 end-of-line. 8=.quad 16=.octa ... */
1991
1992 void
1993 big_cons (nbytes)
1994 register int nbytes;
1995 {
1996 register char c; /* input_line_pointer->c. */
1997 register int radix;
1998 register long length; /* Number of chars in an object. */
1999 register int digit; /* Value of 1 digit. */
2000 register int carry; /* For multi-precision arithmetic. */
2001 register int work; /* For multi-precision arithmetic. */
2002 register char *p; /* For multi-precision arithmetic. */
2003
2004 extern const char hex_value[]; /* In hex_value.c. */
2005
2006 /*
2007 * The following awkward logic is to parse ZERO or more strings,
2008 * comma seperated. Recall an expression includes its leading &
2009 * trailing blanks. We fake a leading ',' if there is (supposed to
2010 * be) a 1st expression, and keep demanding 1 expression for each ','.
2011 */
2012 if (is_it_end_of_statement ())
2013 {
2014 c = 0; /* Skip loop. */
2015 }
2016 else
2017 {
2018 c = ','; /* Do loop. */
2019 --input_line_pointer;
2020 }
2021 while (c == ',')
2022 {
2023 ++input_line_pointer;
2024 SKIP_WHITESPACE ();
2025 c = *input_line_pointer;
2026 /* C contains 1st non-blank character of what we hope is a number. */
2027 if (c == '0')
2028 {
2029 c = *++input_line_pointer;
2030 if (c == 'x' || c == 'X')
2031 {
2032 c = *++input_line_pointer;
2033 radix = 16;
2034 }
2035 else
2036 {
2037 radix = 8;
2038 }
2039 }
2040 else
2041 {
2042 radix = 10;
2043 }
2044 /*
2045 * This feature (?) is here to stop people worrying about
2046 * mysterious zero constants: which is what they get when
2047 * they completely omit digits.
2048 */
2049 if (hex_value[(unsigned char) c] >= radix)
2050 {
2051 as_bad ("Missing digits. 0 assumed.");
2052 }
2053 bignum_high = bignum_low - 1; /* Start constant with 0 chars. */
2054 for (;
2055 (digit = hex_value[(unsigned char) c]) < radix;
2056 c = *++input_line_pointer)
2057 {
2058 /* Multiply existing number by radix, then add digit. */
2059 carry = digit;
2060 for (p = bignum_low; p <= bignum_high; p++)
2061 {
2062 work = (*p & MASK_CHAR) * radix + carry;
2063 *p = work & MASK_CHAR;
2064 carry = work >> BITS_PER_CHAR;
2065 }
2066 if (carry)
2067 {
2068 grow_bignum ();
2069 *bignum_high = carry & MASK_CHAR;
2070 know ((carry & ~MASK_CHAR) == 0);
2071 }
2072 }
2073 length = bignum_high - bignum_low + 1;
2074 if (length > nbytes)
2075 {
2076 as_warn ("Most significant bits truncated in integer constant.");
2077 }
2078 else
2079 {
2080 register long leading_zeroes;
2081
2082 for (leading_zeroes = nbytes - length;
2083 leading_zeroes;
2084 leading_zeroes--)
2085 {
2086 grow_bignum ();
2087 *bignum_high = 0;
2088 }
2089 }
2090 if (!need_pass_2)
2091 {
2092 char *src = bignum_low;
2093 p = frag_more (nbytes);
2094 if (target_big_endian)
2095 {
2096 int i;
2097 for (i = nbytes - 1; i >= 0; i--)
2098 p[i] = *src++;
2099 }
2100 else
2101 memcpy (p, bignum_low, (int) nbytes);
2102 }
2103 /* C contains character after number. */
2104 SKIP_WHITESPACE ();
2105 c = *input_line_pointer;
2106 /* C contains 1st non-blank character after number. */
2107 }
2108 demand_empty_rest_of_line ();
2109 } /* big_cons() */
2110
2111 /* Extend bignum by 1 char. */
2112 static void
2113 grow_bignum ()
2114 {
2115 register long length;
2116
2117 bignum_high++;
2118 if (bignum_high >= bignum_limit)
2119 {
2120 length = bignum_limit - bignum_low;
2121 bignum_low = xrealloc (bignum_low, length + length);
2122 bignum_high = bignum_low + length;
2123 bignum_limit = bignum_low + length + length;
2124 }
2125 } /* grow_bignum(); */
2126 \f
2127 /*
2128 * float_cons()
2129 *
2130 * CONStruct some more frag chars of .floats .ffloats etc.
2131 * Makes 0 or more new frags.
2132 * If need_pass_2 == 1, no frags are emitted.
2133 * This understands only floating literals, not expressions. Sorry.
2134 *
2135 * A floating constant is defined by atof_generic(), except it is preceded
2136 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
2137 * reading, I decided to be incompatible. This always tries to give you
2138 * rounded bits to the precision of the pseudo-op. Former AS did premature
2139 * truncatation, restored noisy bits instead of trailing 0s AND gave you
2140 * a choice of 2 flavours of noise according to which of 2 floating-point
2141 * scanners you directed AS to use.
2142 *
2143 * In: input_line_pointer->whitespace before, or '0' of flonum.
2144 *
2145 */
2146
2147 void
2148 float_cons (float_type)
2149 /* Clobbers input_line-pointer, checks end-of-line. */
2150 register int float_type; /* 'f':.ffloat ... 'F':.float ... */
2151 {
2152 register char *p;
2153 int length; /* Number of chars in an object. */
2154 register char *err; /* Error from scanning floating literal. */
2155 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2156
2157 if (is_it_end_of_statement ())
2158 {
2159 demand_empty_rest_of_line ();
2160 return;
2161 }
2162
2163 do
2164 {
2165 /* input_line_pointer->1st char of a flonum (we hope!). */
2166 SKIP_WHITESPACE ();
2167
2168 /* Skip any 0{letter} that may be present. Don't even check if the
2169 * letter is legal. Someone may invent a "z" format and this routine
2170 * has no use for such information. Lusers beware: you get
2171 * diagnostics if your input is ill-conditioned.
2172 */
2173 if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1]))
2174 input_line_pointer += 2;
2175
2176 err = md_atof (float_type, temp, &length);
2177 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2178 know (length > 0);
2179 if (err && *err)
2180 {
2181 as_bad ("Bad floating literal: %s", err);
2182 ignore_rest_of_line ();
2183 return;
2184 }
2185
2186 if (!need_pass_2)
2187 {
2188 int count;
2189
2190 count = 1;
2191
2192 #ifdef REPEAT_CONS_EXPRESSIONS
2193 if (*input_line_pointer == ':')
2194 {
2195 expressionS count_exp;
2196
2197 ++input_line_pointer;
2198 expression (&count_exp);
2199 if (count_exp.X_op != O_constant
2200 || count_exp.X_add_number <= 0)
2201 {
2202 as_warn ("unresolvable or nonpositive repeat count; using 1");
2203 }
2204 else
2205 count = count_exp.X_add_number;
2206 }
2207 #endif
2208
2209 while (--count >= 0)
2210 {
2211 p = frag_more (length);
2212 memcpy (p, temp, length);
2213 }
2214 }
2215 SKIP_WHITESPACE ();
2216 }
2217 while (*input_line_pointer++ == ',');
2218
2219 --input_line_pointer; /* Put terminator back into stream. */
2220 demand_empty_rest_of_line ();
2221 } /* float_cons() */
2222 \f
2223 /*
2224 * stringer()
2225 *
2226 * We read 0 or more ',' seperated, double-quoted strings.
2227 *
2228 * Caller should have checked need_pass_2 is FALSE because we don't check it.
2229 */
2230
2231
2232 void
2233 stringer (append_zero) /* Worker to do .ascii etc statements. */
2234 /* Checks end-of-line. */
2235 register int append_zero; /* 0: don't append '\0', else 1 */
2236 {
2237 register unsigned int c;
2238
2239 /*
2240 * The following awkward logic is to parse ZERO or more strings,
2241 * comma seperated. Recall a string expression includes spaces
2242 * before the opening '\"' and spaces after the closing '\"'.
2243 * We fake a leading ',' if there is (supposed to be)
2244 * a 1st, expression. We keep demanding expressions for each
2245 * ','.
2246 */
2247 if (is_it_end_of_statement ())
2248 {
2249 c = 0; /* Skip loop. */
2250 ++input_line_pointer; /* Compensate for end of loop. */
2251 }
2252 else
2253 {
2254 c = ','; /* Do loop. */
2255 }
2256 while (c == ',' || c == '<' || c == '"')
2257 {
2258 SKIP_WHITESPACE ();
2259 switch (*input_line_pointer)
2260 {
2261 case '\"':
2262 ++input_line_pointer; /*->1st char of string. */
2263 while (is_a_char (c = next_char_of_string ()))
2264 {
2265 FRAG_APPEND_1_CHAR (c);
2266 }
2267 if (append_zero)
2268 {
2269 FRAG_APPEND_1_CHAR (0);
2270 }
2271 know (input_line_pointer[-1] == '\"');
2272 break;
2273 case '<':
2274 input_line_pointer++;
2275 c = get_single_number ();
2276 FRAG_APPEND_1_CHAR (c);
2277 if (*input_line_pointer != '>')
2278 {
2279 as_bad ("Expected <nn>");
2280 }
2281 input_line_pointer++;
2282 break;
2283 case ',':
2284 input_line_pointer++;
2285 break;
2286 }
2287 SKIP_WHITESPACE ();
2288 c = *input_line_pointer;
2289 }
2290
2291 demand_empty_rest_of_line ();
2292 } /* stringer() */
2293 \f
2294 /* FIXME-SOMEDAY: I had trouble here on characters with the
2295 high bits set. We'll probably also have trouble with
2296 multibyte chars, wide chars, etc. Also be careful about
2297 returning values bigger than 1 byte. xoxorich. */
2298
2299 unsigned int
2300 next_char_of_string ()
2301 {
2302 register unsigned int c;
2303
2304 c = *input_line_pointer++ & CHAR_MASK;
2305 switch (c)
2306 {
2307 case '\"':
2308 c = NOT_A_CHAR;
2309 break;
2310
2311 case '\\':
2312 switch (c = *input_line_pointer++)
2313 {
2314 case 'b':
2315 c = '\b';
2316 break;
2317
2318 case 'f':
2319 c = '\f';
2320 break;
2321
2322 case 'n':
2323 c = '\n';
2324 break;
2325
2326 case 'r':
2327 c = '\r';
2328 break;
2329
2330 case 't':
2331 c = '\t';
2332 break;
2333
2334 #ifdef BACKSLASH_V
2335 case 'v':
2336 c = '\013';
2337 break;
2338 #endif
2339
2340 case '\\':
2341 case '"':
2342 break; /* As itself. */
2343
2344 case '0':
2345 case '1':
2346 case '2':
2347 case '3':
2348 case '4':
2349 case '5':
2350 case '6':
2351 case '7':
2352 case '8':
2353 case '9':
2354 {
2355 long number;
2356
2357 for (number = 0; isdigit (c); c = *input_line_pointer++)
2358 {
2359 number = number * 8 + c - '0';
2360 }
2361 c = number & 0xff;
2362 }
2363 --input_line_pointer;
2364 break;
2365
2366 case '\n':
2367 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
2368 as_warn ("Unterminated string: Newline inserted.");
2369 c = '\n';
2370 break;
2371
2372 default:
2373
2374 #ifdef ONLY_STANDARD_ESCAPES
2375 as_bad ("Bad escaped character in string, '?' assumed");
2376 c = '?';
2377 #endif /* ONLY_STANDARD_ESCAPES */
2378
2379 break;
2380 } /* switch on escaped char */
2381 break;
2382
2383 default:
2384 break;
2385 } /* switch on char */
2386 return (c);
2387 } /* next_char_of_string() */
2388 \f
2389 static segT
2390 get_segmented_expression (expP)
2391 register expressionS *expP;
2392 {
2393 register segT retval;
2394
2395 retval = expression (expP);
2396 if (expP->X_op == O_illegal
2397 || expP->X_op == O_absent
2398 || expP->X_op == O_big)
2399 {
2400 as_bad ("expected address expression; zero assumed");
2401 expP->X_op = O_constant;
2402 expP->X_add_number = 0;
2403 retval = absolute_section;
2404 }
2405 return retval;
2406 }
2407
2408 static segT
2409 get_known_segmented_expression (expP)
2410 register expressionS *expP;
2411 {
2412 register segT retval;
2413
2414 if ((retval = get_segmented_expression (expP)) == undefined_section)
2415 {
2416 /* There is no easy way to extract the undefined symbol from the
2417 expression. */
2418 if (expP->X_add_symbol != NULL
2419 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
2420 as_warn ("symbol \"%s\" undefined; zero assumed",
2421 S_GET_NAME (expP->X_add_symbol));
2422 else
2423 as_warn ("some symbol undefined; zero assumed");
2424 retval = absolute_section;
2425 expP->X_op = O_constant;
2426 expP->X_add_number = 0;
2427 }
2428 know (retval == absolute_section || SEG_NORMAL (retval));
2429 return (retval);
2430 } /* get_known_segmented_expression() */
2431
2432 offsetT
2433 get_absolute_expression ()
2434 {
2435 expressionS exp;
2436
2437 expression (&exp);
2438 if (exp.X_op != O_constant)
2439 {
2440 if (exp.X_op != O_absent)
2441 as_bad ("bad absolute expression; zero assumed");
2442 exp.X_add_number = 0;
2443 }
2444 return exp.X_add_number;
2445 }
2446
2447 char /* return terminator */
2448 get_absolute_expression_and_terminator (val_pointer)
2449 long *val_pointer; /* return value of expression */
2450 {
2451 /* FIXME: val_pointer should probably be offsetT *. */
2452 *val_pointer = (long) get_absolute_expression ();
2453 return (*input_line_pointer++);
2454 }
2455 \f
2456 /*
2457 * demand_copy_C_string()
2458 *
2459 * Like demand_copy_string, but return NULL if the string contains any '\0's.
2460 * Give a warning if that happens.
2461 */
2462 char *
2463 demand_copy_C_string (len_pointer)
2464 int *len_pointer;
2465 {
2466 register char *s;
2467
2468 if ((s = demand_copy_string (len_pointer)) != 0)
2469 {
2470 register int len;
2471
2472 for (len = *len_pointer;
2473 len > 0;
2474 len--)
2475 {
2476 if (*s == 0)
2477 {
2478 s = 0;
2479 len = 1;
2480 *len_pointer = 0;
2481 as_bad ("This string may not contain \'\\0\'");
2482 }
2483 }
2484 }
2485 return (s);
2486 }
2487 \f
2488 /*
2489 * demand_copy_string()
2490 *
2491 * Demand string, but return a safe (=private) copy of the string.
2492 * Return NULL if we can't read a string here.
2493 */
2494 static char *
2495 demand_copy_string (lenP)
2496 int *lenP;
2497 {
2498 register unsigned int c;
2499 register int len;
2500 char *retval;
2501
2502 len = 0;
2503 SKIP_WHITESPACE ();
2504 if (*input_line_pointer == '\"')
2505 {
2506 input_line_pointer++; /* Skip opening quote. */
2507
2508 while (is_a_char (c = next_char_of_string ()))
2509 {
2510 obstack_1grow (&notes, c);
2511 len++;
2512 }
2513 /* JF this next line is so demand_copy_C_string will return a null
2514 termanated string. */
2515 obstack_1grow (&notes, '\0');
2516 retval = obstack_finish (&notes);
2517 }
2518 else
2519 {
2520 as_warn ("Missing string");
2521 retval = NULL;
2522 ignore_rest_of_line ();
2523 }
2524 *lenP = len;
2525 return (retval);
2526 } /* demand_copy_string() */
2527 \f
2528 /*
2529 * is_it_end_of_statement()
2530 *
2531 * In: Input_line_pointer->next character.
2532 *
2533 * Do: Skip input_line_pointer over all whitespace.
2534 *
2535 * Out: 1 if input_line_pointer->end-of-line.
2536 */
2537 int
2538 is_it_end_of_statement ()
2539 {
2540 SKIP_WHITESPACE ();
2541 return (is_end_of_line[(unsigned char) *input_line_pointer]);
2542 } /* is_it_end_of_statement() */
2543
2544 void
2545 equals (sym_name)
2546 char *sym_name;
2547 {
2548 register symbolS *symbolP; /* symbol we are working with */
2549
2550 input_line_pointer++;
2551 if (*input_line_pointer == '=')
2552 input_line_pointer++;
2553
2554 while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
2555 input_line_pointer++;
2556
2557 if (sym_name[0] == '.' && sym_name[1] == '\0')
2558 {
2559 /* Turn '. = mumble' into a .org mumble */
2560 register segT segment;
2561 expressionS exp;
2562 register char *p;
2563
2564 segment = get_known_segmented_expression (&exp);
2565 if (!need_pass_2)
2566 {
2567 if (segment != now_seg && segment != absolute_section)
2568 as_warn ("Illegal segment \"%s\". Segment \"%s\" assumed.",
2569 segment_name (segment),
2570 segment_name (now_seg));
2571 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp.X_add_symbol,
2572 exp.X_add_number, (char *) 0);
2573 *p = 0;
2574 } /* if (ok to make frag) */
2575 }
2576 else
2577 {
2578 symbolP = symbol_find_or_make (sym_name);
2579 pseudo_set (symbolP);
2580 }
2581 } /* equals() */
2582
2583 /* .include -- include a file at this point. */
2584
2585 /* ARGSUSED */
2586 void
2587 s_include (arg)
2588 int arg;
2589 {
2590 char *newbuf;
2591 char *filename;
2592 int i;
2593 FILE *try;
2594 char *path;
2595
2596 filename = demand_copy_string (&i);
2597 demand_empty_rest_of_line ();
2598 path = xmalloc (i + include_dir_maxlen + 5 /* slop */ );
2599 for (i = 0; i < include_dir_count; i++)
2600 {
2601 strcpy (path, include_dirs[i]);
2602 strcat (path, "/");
2603 strcat (path, filename);
2604 if (0 != (try = fopen (path, "r")))
2605 {
2606 fclose (try);
2607 goto gotit;
2608 }
2609 }
2610 free (path);
2611 path = filename;
2612 gotit:
2613 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */
2614 newbuf = input_scrub_include_file (path, input_line_pointer);
2615 buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2616 } /* s_include() */
2617
2618 void
2619 add_include_dir (path)
2620 char *path;
2621 {
2622 int i;
2623
2624 if (include_dir_count == 0)
2625 {
2626 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
2627 include_dirs[0] = "."; /* Current dir */
2628 include_dir_count = 2;
2629 }
2630 else
2631 {
2632 include_dir_count++;
2633 include_dirs = (char **) realloc (include_dirs,
2634 include_dir_count * sizeof (*include_dirs));
2635 }
2636
2637 include_dirs[include_dir_count - 1] = path; /* New one */
2638
2639 i = strlen (path);
2640 if (i > include_dir_maxlen)
2641 include_dir_maxlen = i;
2642 } /* add_include_dir() */
2643
2644 void
2645 s_ignore (arg)
2646 int arg;
2647 {
2648 while (!is_end_of_line[(unsigned char) *input_line_pointer])
2649 {
2650 ++input_line_pointer;
2651 }
2652 ++input_line_pointer;
2653
2654 return;
2655 } /* s_ignore() */
2656
2657 /*
2658 * Handle .stabX directives, which used to be open-coded.
2659 * So much creeping featurism overloaded the semantics that we decided
2660 * to put all .stabX thinking in one place. Here.
2661 *
2662 * We try to make any .stabX directive legal. Other people's AS will often
2663 * do assembly-time consistency checks: eg assigning meaning to n_type bits
2664 * and "protecting" you from setting them to certain values. (They also zero
2665 * certain bits before emitting symbols. Tut tut.)
2666 *
2667 * If an expression is not absolute we either gripe or use the relocation
2668 * information. Other people's assemblers silently forget information they
2669 * don't need and invent information they need that you didn't supply.
2670 */
2671
2672 void
2673 change_to_section (name, len, exp)
2674 char *name;
2675 unsigned int len;
2676 unsigned int exp;
2677 {
2678 #ifndef BFD_ASSEMBLER
2679 #ifdef MANY_SEGMENTS
2680 unsigned int i;
2681 extern segment_info_type segment_info[];
2682
2683 /* Find out if we've already got a section of this name etc */
2684 for (i = SEG_E0; i < SEG_E9 && segment_info[i].scnhdr.s_name[0]; i++)
2685 {
2686 if (strncmp (segment_info[i].scnhdr.s_name, name, len) == 0)
2687 {
2688 subseg_new (i, exp);
2689 return;
2690 }
2691 }
2692 /* No section, add one */
2693 strncpy (segment_info[i].scnhdr.s_name, name, 8);
2694 segment_info[i].scnhdr.s_flags = 0 /* STYP_NOLOAD */;
2695 subseg_new (i, exp);
2696 #endif
2697 #endif
2698 }
2699
2700 /*
2701 * Build a string dictionary entry for a .stabX symbol.
2702 * The symbol is added to the .<secname>str section.
2703 */
2704
2705 #ifdef SEPARATE_STAB_SECTIONS
2706
2707 static unsigned int
2708 get_stab_string_offset (string, secname)
2709 char *string, *secname;
2710 {
2711 segT save_seg;
2712 segT seg;
2713 subsegT save_subseg;
2714 unsigned int length;
2715 unsigned int old_gdb_string_index;
2716 char *clengthP;
2717 int i;
2718 char c;
2719 /* @@FIXME -- there should be no static data here!
2720 This also has the effect of making all stab string tables large enough
2721 to contain all the contents written to any of them. This only matters
2722 with the Solaris native compiler for the moment, but it should be fixed
2723 anyways. */
2724 static unsigned int gdb_string_index = 0;
2725
2726 old_gdb_string_index = 0;
2727 length = strlen (string);
2728 clengthP = (char *) &length;
2729 if (length > 0)
2730 { /* Ordinary case. */
2731 save_seg = now_seg;
2732 save_subseg = now_subseg;
2733
2734 /* Create the stabstr sections, if they are not already created. */
2735 {
2736 char *newsecname = xmalloc (strlen (secname) + 4);
2737 strcpy (newsecname, secname);
2738 strcat (newsecname, "str");
2739 #ifdef BFD_ASSEMBLER
2740 seg = bfd_get_section_by_name (stdoutput, newsecname);
2741 if (seg == 0)
2742 {
2743 seg = bfd_make_section_old_way (stdoutput, newsecname);
2744 bfd_set_section_flags (stdoutput, seg, SEC_READONLY | SEC_ALLOC);
2745 }
2746 #else
2747 change_to_section(newsecname, strlen(newsecname), 0);
2748 #endif
2749 /* free (newsecname);*/
2750 }
2751 #ifdef BFD_ASSEMBLER
2752 subseg_set (seg, save_subseg);
2753 #else
2754 /* subseg_new (seg, save_subseg); */
2755 #endif
2756 old_gdb_string_index = gdb_string_index;
2757 i = 0;
2758 while ((c = *string++))
2759 {
2760 i++;
2761 gdb_string_index++;
2762 FRAG_APPEND_1_CHAR (c);
2763 }
2764 {
2765 FRAG_APPEND_1_CHAR ((char) 0);
2766 i++;
2767 gdb_string_index++;
2768 }
2769 while (i % 4 != 0)
2770 {
2771 FRAG_APPEND_1_CHAR ((char) 0);
2772 i++;
2773 gdb_string_index++;
2774 }
2775 #ifdef BFD_ASSEMBLER
2776 subseg_set (save_seg, save_subseg);
2777 #else
2778 /* subseg_new (save_seg, save_subseg); */
2779 #endif
2780 }
2781 return old_gdb_string_index;
2782 }
2783
2784 #endif /* SEPARATE_STAB_SECTIONS */
2785
2786 /* This can handle different kinds of stabs (s,n,d) and different
2787 kinds of stab sections. */
2788
2789 static void
2790 s_stab_generic (what, secname)
2791 int what;
2792 char *secname;
2793 {
2794 extern int listing;
2795
2796 symbolS *symbol;
2797 char *string;
2798 int saved_type = 0;
2799 int length;
2800 int goof = 0;
2801 long longint;
2802 segT saved_seg = now_seg;
2803 segT seg;
2804 subsegT saved_subseg = now_subseg;
2805 subsegT subseg;
2806 int valu;
2807 #ifdef SEPARATE_STAB_SECTIONS
2808 int seg_is_new = 0;
2809 #endif
2810
2811 valu = ((char *) obstack_next_free (&frags)) - frag_now->fr_literal;
2812
2813 #ifdef SEPARATE_STAB_SECTIONS
2814 #ifdef BFD_ASSEMBLER
2815 seg = bfd_get_section_by_name (stdoutput, secname);
2816 if (seg == 0)
2817 {
2818 seg = subseg_new (secname, 0);
2819 bfd_set_section_flags (stdoutput, seg,
2820 SEC_READONLY | SEC_ALLOC | SEC_RELOC);
2821 subseg_set (saved_seg, subseg);
2822 seg_is_new = 1;
2823 }
2824 #else
2825 change_to_section (secname, strlen(secname), 0);
2826 #endif
2827 #endif /* SEPARATE_STAB_SECTIONS */
2828
2829 /*
2830 * Enter with input_line_pointer pointing past .stabX and any following
2831 * whitespace.
2832 */
2833 if (what == 's')
2834 {
2835 string = demand_copy_C_string (&length);
2836 SKIP_WHITESPACE ();
2837 if (*input_line_pointer == ',')
2838 input_line_pointer++;
2839 else
2840 {
2841 as_bad ("I need a comma after symbol's name");
2842 goof = 1;
2843 }
2844 }
2845 else
2846 string = "";
2847
2848 /*
2849 * Input_line_pointer->after ','. String->symbol name.
2850 */
2851 if (!goof)
2852 {
2853 #ifdef MAKE_STAB_SYMBOL
2854 MAKE_STAB_SYMBOL(symbol, string, secname);
2855 #else
2856 symbol = symbol_new (string, undefined_section, 0, (struct frag *) 0);
2857 #endif
2858 /* Make sure that the rest of this is going to work. */
2859 if (symbol == NULL)
2860 as_fatal ("no stab symbol created");
2861
2862 switch (what)
2863 {
2864 case 'd':
2865 S_SET_NAME (symbol, NULL); /* .stabd feature. */
2866 #ifdef STAB_SYMBOL_SET_VALUE
2867 STAB_SYMBOL_SET_VALUE (symbol, valu);
2868 #else
2869 S_SET_VALUE (symbol, valu);
2870 #endif
2871 #if STAB_SYMBOL_SET_SEGMENT
2872 #else
2873 S_SET_SEGMENT (symbol, now_seg);
2874 #endif
2875 symbol->sy_frag = frag_now;
2876 break;
2877
2878 case 'n':
2879 symbol->sy_frag = &zero_address_frag;
2880 break;
2881
2882 case 's':
2883 symbol->sy_frag = &zero_address_frag;
2884 break;
2885
2886 default:
2887 BAD_CASE (what);
2888 break;
2889 }
2890
2891 if (get_absolute_expression_and_terminator (&longint) == ',')
2892 {
2893 saved_type = longint;
2894 S_SET_TYPE (symbol, saved_type);
2895 }
2896 else
2897 {
2898 as_bad ("I want a comma after the n_type expression");
2899 goof = 1;
2900 input_line_pointer--; /* Backup over a non-',' char. */
2901 }
2902 }
2903
2904 if (!goof)
2905 {
2906 if (get_absolute_expression_and_terminator (&longint) == ',')
2907 S_SET_OTHER (symbol, longint);
2908 else
2909 {
2910 as_bad ("I want a comma after the n_other expression");
2911 goof = 1;
2912 input_line_pointer--; /* Backup over a non-',' char. */
2913 }
2914 }
2915
2916 if (!goof)
2917 {
2918 S_SET_DESC (symbol, get_absolute_expression ());
2919 if (what == 's' || what == 'n')
2920 {
2921 if (*input_line_pointer != ',')
2922 {
2923 as_bad ("I want a comma after the n_desc expression");
2924 goof = 1;
2925 }
2926 else
2927 {
2928 input_line_pointer++;
2929 }
2930 }
2931 }
2932
2933 /* Line is messed up - ignore it and get out of here. */
2934 if (goof)
2935 {
2936 ignore_rest_of_line ();
2937 #ifdef BFD_ASSEMBLER
2938 subseg_set (saved_seg, saved_subseg);
2939 #else
2940 subseg_new (saved_seg, saved_subseg);
2941 #endif
2942 return;
2943 }
2944
2945 #ifdef BFD_ASSEMBLER
2946 subseg_set (seg, subseg);
2947 #endif
2948
2949 #if 0 /* needed for elf only? */
2950 if (seg_is_new)
2951 /* allocate and discard -- filled in later */
2952 (void) frag_more (12);
2953 #endif
2954
2955 #ifdef SEPARATE_STAB_SECTIONS
2956 {
2957 char *toP;
2958
2959 change_to_section(secname, strlen(secname), 0);
2960 toP = frag_more (8);
2961 /* the string index portion of the stab */
2962 md_number_to_chars (toP, (valueT) S_GET_OFFSET_2(symbol), 4);
2963 md_number_to_chars (toP + 4, (valueT) S_GET_TYPE(symbol), 1);
2964 md_number_to_chars (toP + 5, (valueT) S_GET_OTHER(symbol), 1);
2965 md_number_to_chars (toP + 6, (valueT) S_GET_DESC(symbol), 2);
2966 }
2967 #endif
2968
2969 #ifdef SEPARATE_STAB_SECTIONS
2970 if (what == 's' || what == 'n')
2971 {
2972 cons (4);
2973 input_line_pointer--;
2974 }
2975 else
2976 {
2977 char *p = frag_more (4);
2978 md_number_to_chars (p, 0, 4);
2979 }
2980 #ifdef BFD_ASSEMBLER
2981 subseg_set (saved_seg, subseg);
2982 #else
2983 /* subseg_new (saved_seg, subseg); */
2984 #endif
2985 #else
2986 if (what == 's' || what == 'n')
2987 {
2988 pseudo_set (symbol);
2989 S_SET_TYPE (symbol, saved_type);
2990 }
2991 #endif
2992
2993 #if 0 /* for elf only? */
2994 if (what == 's' && S_GET_TYPE (symbol) == N_SO)
2995 {
2996 fragS *fragp = seg_info (seg)->frchainP->frch_root;
2997 while (fragp
2998 && fragp->fr_address + fragp->fr_fix < 12)
2999 fragp = fragp->fr_next;
3000 assert (fragp != 0);
3001 assert (fragp->fr_type == rs_fill);
3002 assert (fragp->fr_address == 0 && fragp->fr_fix >= 12);
3003 md_number_to_chars (fragp->fr_literal, (valueT) symbol->sy_name_offset,
3004 4);
3005 }
3006 #endif
3007
3008 #ifndef NO_LISTING
3009 if (listing)
3010 switch (S_GET_TYPE (symbol))
3011 {
3012 case N_SLINE:
3013 listing_source_line (S_GET_DESC (symbol));
3014 break;
3015 case N_SO:
3016 case N_SOL:
3017 listing_source_file (string);
3018 break;
3019 }
3020 #endif /* !NO_LISTING */
3021
3022 #ifdef SEPARATE_STAB_SECTIONS
3023 subseg_new (saved_seg, saved_subseg);
3024 #endif
3025
3026 demand_empty_rest_of_line ();
3027 }
3028
3029 /* Regular stab directive. */
3030
3031 void
3032 s_stab (what)
3033 int what;
3034 {
3035 s_stab_generic (what, ".stab");
3036 }
3037
3038 /* "Extended stabs", used in Solaris only now. */
3039
3040 void
3041 s_xstab (what)
3042 int what;
3043 {
3044 int length;
3045 char *secname;
3046
3047 secname = demand_copy_C_string (&length);
3048 SKIP_WHITESPACE ();
3049 if (*input_line_pointer == ',')
3050 input_line_pointer++;
3051 else
3052 {
3053 as_bad ("comma missing in .xstabs");
3054 ignore_rest_of_line ();
3055 return;
3056 }
3057 s_stab_generic (what, secname);
3058 }
3059
3060 /* Frob invented at RMS' request. Set the n_desc of a symbol. */
3061
3062 void
3063 s_desc ()
3064 {
3065 char *name;
3066 char c;
3067 char *p;
3068 symbolS *symbolP;
3069 int temp;
3070
3071 name = input_line_pointer;
3072 c = get_symbol_end ();
3073 p = input_line_pointer;
3074 *p = c;
3075 SKIP_WHITESPACE ();
3076 if (*input_line_pointer != ',')
3077 {
3078 *p = 0;
3079 as_bad ("Expected comma after name \"%s\"", name);
3080 *p = c;
3081 ignore_rest_of_line ();
3082 }
3083 else
3084 {
3085 input_line_pointer++;
3086 temp = get_absolute_expression ();
3087 *p = 0;
3088 symbolP = symbol_find_or_make (name);
3089 *p = c;
3090 S_SET_DESC (symbolP, temp);
3091 }
3092 demand_empty_rest_of_line ();
3093 } /* s_desc() */
3094
3095 /* end of read.c */
This page took 0.094105 seconds and 5 git commands to generate.