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