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