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