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