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