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