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