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