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