* app.c (input_buffer): New static variable.
[platform/upstream/binutils.git] / gas / read.c
1 /* read.c - read a source file -
2    Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 #if 0
23 #define MASK_CHAR (0xFF)        /* If your chars aren't 8 bits, you will
24                                    change this a bit.  But then, GNU isn't
25                                    spozed to run on your machine anyway.
26                                    (RMS is so shortsighted sometimes.)
27                                    */
28 #else
29 #define MASK_CHAR ((int)(unsigned char)-1)
30 #endif
31
32
33 /* This is the largest known floating point format (for now). It will
34    grow when we do 4361 style flonums. */
35
36 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
37
38 /* Routines that read assembler source text to build spagetti in memory.
39    Another group of these functions is in the expr.c module.  */
40
41 /* for isdigit() */
42 #include <ctype.h>
43
44 #include "as.h"
45 #include "subsegs.h"
46 #include "sb.h"
47 #include "macro.h"
48 #include "obstack.h"
49 #include "listing.h"
50 #include "ecoff.h"
51
52 #ifndef TC_START_LABEL
53 #define TC_START_LABEL(x,y) (x==':')
54 #endif
55
56 /* The NOP_OPCODE is for the alignment fill value.
57  * fill it a nop instruction so that the disassembler does not choke
58  * on it
59  */
60 #ifndef NOP_OPCODE
61 #define NOP_OPCODE 0x00
62 #endif
63
64 char *input_line_pointer;       /*->next char of source file to parse. */
65
66 #if BITS_PER_CHAR != 8
67 /*  The following table is indexed by[(char)] and will break if
68     a char does not have exactly 256 states (hopefully 0:255!)!  */
69 die horribly;
70 #endif
71
72 #ifndef LEX_AT
73 /* The m88k unfortunately uses @ as a label beginner.  */
74 #define LEX_AT 0
75 #endif
76
77 #ifndef LEX_BR
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names.  */
79 #define LEX_BR 0
80 #endif
81
82 #ifndef LEX_PCT
83 /* The Delta 68k assembler permits % inside label names.  */
84 #define LEX_PCT 0
85 #endif
86
87 #ifndef LEX_QM
88 /* The PowerPC Windows NT assemblers permits ? inside label names.  */
89 #define LEX_QM 0
90 #endif
91
92 #ifndef LEX_DOLLAR
93 /* The a29k assembler does not permits labels to start with $.  */
94 #define LEX_DOLLAR 3
95 #endif
96
97 #ifndef LEX_TILDE
98 /* The Delta 68k assembler permits ~ at start of label names.  */
99 #define LEX_TILDE 0
100 #endif
101
102 /* used by is_... macros. our ctype[] */
103 char lex_type[256] =
104 {
105   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* @ABCDEFGHIJKLMNO */
106   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* PQRSTUVWXYZ[\]^_ */
107   0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
108   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM,  /* 0123456789:;<=>? */
109   LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,  /* @ABCDEFGHIJKLMNO */
110   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
111   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,       /* `abcdefghijklmno */
112   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */
113   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
114   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
115   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
116   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
117   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
118   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
121 };
122
123
124 /*
125  * In: a character.
126  * Out: 1 if this character ends a line.
127  */
128 #define Z_ (0)
129 char is_end_of_line[256] =
130 {
131 #ifdef CR_EOL
132   99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, 99, Z_, Z_,       /* @abcdefghijklmno */
133 #else
134   99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_, Z_,       /* @abcdefghijklmno */
135 #endif
136   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
137 #ifdef TC_HPPA
138   Z_,99, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,        /* _!"#$%&'()*+,-./ */
139   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* 0123456789:;<=>? */
140 #else
141   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
142   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, 99, Z_, Z_, Z_, Z_,       /* 0123456789:;<=>? */
143 #endif
144   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
145   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
146   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
147   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
148   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
149   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
150   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
151   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
152   Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_, Z_,       /* */
153 };
154 #undef Z_
155
156 /* Functions private to this file. */
157
158 static char *buffer;    /* 1st char of each buffer of lines is here. */
159 static char *buffer_limit;      /*->1 + last char in buffer. */
160
161 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the
162    tc-<CPU>.h file.  See the "Porting GAS" section of the internals manual. */
163 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
164
165 static char *old_buffer;        /* JF a hack */
166 static char *old_input;
167 static char *old_limit;
168
169 /* Variables for handling include file directory table. */
170
171 char **include_dirs;    /* Table of pointers to directories to
172                            search for .include's */
173 int include_dir_count;  /* How many are in the table */
174 int include_dir_maxlen = 1;/* Length of longest in table */
175
176 #ifndef WORKING_DOT_WORD
177 struct broken_word *broken_words;
178 int new_broken_words;
179 #endif
180
181 /* The current offset into the absolute section.  We don't try to
182    build frags in the absolute section, since no data can be stored
183    there.  We just keep track of the current offset.  */
184 addressT abs_section_offset;
185
186 /* If this line had an MRI style label, it is stored in this variable.
187    This is used by some of the MRI pseudo-ops.  */
188 symbolS *line_label;
189
190 /* This global variable is used to support MRI common sections.  We
191    translate such sections into a common symbol.  This variable is
192    non-NULL when we are in an MRI common section.  */
193 symbolS *mri_common_symbol;
194
195 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
196    need to align to an even byte boundary unless the next pseudo-op is
197    dc.b, ds.b, or dcb.b.  This variable is set to 1 if an alignment
198    may be needed.  */
199 static int mri_pending_align;
200
201 #ifndef NO_LISTING
202 #ifdef OBJ_ELF
203 /* This variable is set to be non-zero if the next string we see might
204    be the name of the source file in DWARF debugging information.  See
205    the comment in emit_expr for the format we look for.  */
206 static int dwarf_file_string;
207 #endif
208 #endif
209
210 static void cons_worker PARAMS ((int, int));
211 static int scrub_from_string PARAMS ((char *, int));
212 static void do_align PARAMS ((int, char *, int, int));
213 static void s_align PARAMS ((int, int));
214 static void s_lcomm_internal PARAMS ((int, int));
215 static int hex_float PARAMS ((int, char *));
216 static inline int sizeof_sleb128 PARAMS ((offsetT));
217 static inline int sizeof_uleb128 PARAMS ((valueT));
218 static inline int output_sleb128 PARAMS ((char *, offsetT));
219 static inline int output_uleb128 PARAMS ((char *, valueT));
220 static inline int output_big_sleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
221 static inline int output_big_uleb128 PARAMS ((char *, LITTLENUM_TYPE *, int));
222 static int output_big_leb128 PARAMS ((char *, LITTLENUM_TYPE *, int, int));
223 static void do_org PARAMS ((segT, expressionS *, int));
224 char *demand_copy_string PARAMS ((int *lenP));
225 static segT get_segmented_expression PARAMS ((expressionS *expP));
226 static segT get_known_segmented_expression PARAMS ((expressionS * expP));
227 static void pobegin PARAMS ((void));
228 static int get_line_sb PARAMS ((sb *));
229 static void generate_file_debug PARAMS ((void));
230 \f
231
232 void
233 read_begin ()
234 {
235   const char *p;
236
237   pobegin ();
238   obj_read_begin_hook ();
239
240   /* Something close -- but not too close -- to a multiple of 1024.
241      The debugging malloc I'm using has 24 bytes of overhead.  */
242   obstack_begin (&notes, chunksize);
243   obstack_begin (&cond_obstack, chunksize);
244
245   /* Use machine dependent syntax */
246   for (p = line_separator_chars; *p; p++)
247     is_end_of_line[(unsigned char) *p] = 1;
248   /* Use more.  FIXME-SOMEDAY. */
249
250   if (flag_mri)
251     lex_type['?'] = 3;
252 }
253 \f
254 /* set up pseudo-op tables */
255
256 static struct hash_control *po_hash;
257
258 static const pseudo_typeS potable[] =
259 {
260   {"abort", s_abort, 0},
261   {"align", s_align_ptwo, 0},
262   {"ascii", stringer, 0},
263   {"asciz", stringer, 1},
264   {"balign", s_align_bytes, 0},
265   {"balignw", s_align_bytes, -2},
266   {"balignl", s_align_bytes, -4},
267 /* block */
268   {"byte", cons, 1},
269   {"comm", s_comm, 0},
270   {"common", s_mri_common, 0},
271   {"common.s", s_mri_common, 1},
272   {"data", s_data, 0},
273   {"dc", cons, 2},
274   {"dc.b", cons, 1},
275   {"dc.d", float_cons, 'd'},
276   {"dc.l", cons, 4},
277   {"dc.s", float_cons, 'f'},
278   {"dc.w", cons, 2},
279   {"dc.x", float_cons, 'x'},
280   {"dcb", s_space, 2},
281   {"dcb.b", s_space, 1},
282   {"dcb.d", s_float_space, 'd'},
283   {"dcb.l", s_space, 4},
284   {"dcb.s", s_float_space, 'f'},
285   {"dcb.w", s_space, 2},
286   {"dcb.x", s_float_space, 'x'},
287   {"ds", s_space, 2},
288   {"ds.b", s_space, 1},
289   {"ds.d", s_space, 8},
290   {"ds.l", s_space, 4},
291   {"ds.p", s_space, 12},
292   {"ds.s", s_space, 4},
293   {"ds.w", s_space, 2},
294   {"ds.x", s_space, 12},
295   {"debug", s_ignore, 0},
296 #ifdef S_SET_DESC
297   {"desc", s_desc, 0},
298 #endif
299 /* dim */
300   {"double", float_cons, 'd'},
301 /* dsect */
302   {"eject", listing_eject, 0},  /* Formfeed listing */
303   {"else", s_else, 0},
304   {"elsec", s_else, 0},
305   {"end", s_end, 0},
306   {"endc", s_endif, 0},
307   {"endfunc", s_func, 1},
308   {"endif", s_endif, 0},
309 /* endef */
310   {"equ", s_set, 0},
311   {"equiv", s_set, 1},
312   {"err", s_err, 0},
313   {"exitm", s_mexit, 0},
314 /* extend */
315   {"extern", s_ignore, 0},      /* We treat all undef as ext */
316   {"appfile", s_app_file, 1},
317   {"appline", s_app_line, 0},
318   {"fail", s_fail, 0},
319   {"file", s_app_file, 0},
320   {"fill", s_fill, 0},
321   {"float", float_cons, 'f'},
322   {"format", s_ignore, 0},
323   {"func", s_func, 0},
324   {"global", s_globl, 0},
325   {"globl", s_globl, 0},
326   {"hword", cons, 2},
327   {"if", s_if, (int) O_ne},
328   {"ifc", s_ifc, 0},
329   {"ifdef", s_ifdef, 0},
330   {"ifeq", s_if, (int) O_eq},
331   {"ifeqs", s_ifeqs, 0},
332   {"ifge", s_if, (int) O_ge},
333   {"ifgt", s_if, (int) O_gt},
334   {"ifle", s_if, (int) O_le},
335   {"iflt", s_if, (int) O_lt},
336   {"ifnc", s_ifc, 1},
337   {"ifndef", s_ifdef, 1},
338   {"ifne", s_if, (int) O_ne},
339   {"ifnes", s_ifeqs, 1},
340   {"ifnotdef", s_ifdef, 1},
341   {"include", s_include, 0},
342   {"int", cons, 4},
343   {"irp", s_irp, 0},
344   {"irep", s_irp, 0},
345   {"irpc", s_irp, 1},
346   {"irepc", s_irp, 1},
347   {"lcomm", s_lcomm, 0},
348   {"lflags", listing_flags, 0}, /* Listing flags */
349   {"linkonce", s_linkonce, 0},
350   {"list", listing_list, 1},    /* Turn listing on */
351   {"llen", listing_psize, 1},
352   {"long", cons, 4},
353   {"lsym", s_lsym, 0},
354   {"macro", s_macro, 0},
355   {"mexit", s_mexit, 0},
356   {"mri", s_mri, 0},
357   {".mri", s_mri, 0},   /* Special case so .mri works in MRI mode.  */
358   {"name", s_ignore, 0},
359   {"noformat", s_ignore, 0},
360   {"nolist", listing_list, 0},  /* Turn listing off */
361   {"nopage", listing_nopage, 0},
362   {"octa", cons, 16},
363   {"offset", s_struct, 0},
364   {"org", s_org, 0},
365   {"p2align", s_align_ptwo, 0},
366   {"p2alignw", s_align_ptwo, -2},
367   {"p2alignl", s_align_ptwo, -4},
368   {"page", listing_eject, 0},
369   {"plen", listing_psize, 0},
370   {"print", s_print, 0},
371   {"psize", listing_psize, 0},  /* set paper size */
372   {"purgem", s_purgem, 0},
373   {"quad", cons, 8},
374   {"rep", s_rept, 0},
375   {"rept", s_rept, 0},
376   {"rva", s_rva, 4},
377   {"sbttl", listing_title, 1},  /* Subtitle of listing */
378 /* scl */
379 /* sect */
380   {"set", s_set, 0},
381   {"short", cons, 2},
382   {"single", float_cons, 'f'},
383 /* size */
384   {"space", s_space, 0},
385   {"skip", s_space, 0},
386   {"sleb128", s_leb128, 1},
387   {"spc", s_ignore, 0},
388   {"stabd", s_stab, 'd'},
389   {"stabn", s_stab, 'n'},
390   {"stabs", s_stab, 's'},
391   {"string", stringer, 1},
392   {"struct", s_struct, 0},
393 /* tag */
394   {"text", s_text, 0},
395
396   /* This is for gcc to use.  It's only just been added (2/94), so gcc
397      won't be able to use it for a while -- probably a year or more.
398      But once this has been released, check with gcc maintainers
399      before deleting it or even changing the spelling.  */
400   {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
401   /* If we're folding case -- done for some targets, not necessarily
402      all -- the above string in an input file will be converted to
403      this one.  Match it either way...  */
404   {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
405
406   {"title", listing_title, 0},  /* Listing title */
407   {"ttl", listing_title, 0},
408 /* type */
409   {"uleb128", s_leb128, 0},
410 /* use */
411 /* val */
412   {"xcom", s_comm, 0},
413   {"xdef", s_globl, 0},
414   {"xref", s_ignore, 0},
415   {"xstabs", s_xstab, 's'},
416   {"word", cons, 2},
417   {"zero", s_space, 0},
418   {NULL}                        /* end sentinel */
419 };
420
421 static int pop_override_ok = 0;
422 static const char *pop_table_name;
423
424 void
425 pop_insert (table)
426      const pseudo_typeS *table;
427 {
428   const char *errtxt;
429   const pseudo_typeS *pop;
430   for (pop = table; pop->poc_name; pop++)
431     {
432       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
433       if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
434         as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
435                   errtxt);
436     }
437 }
438
439 #ifndef md_pop_insert
440 #define md_pop_insert()         pop_insert(md_pseudo_table)
441 #endif
442
443 #ifndef obj_pop_insert
444 #define obj_pop_insert()        pop_insert(obj_pseudo_table)
445 #endif
446
447 static void 
448 pobegin ()
449 {
450   po_hash = hash_new ();
451
452   /* Do the target-specific pseudo ops. */
453   pop_table_name = "md";
454   md_pop_insert ();
455
456   /* Now object specific.  Skip any that were in the target table. */
457   pop_table_name = "obj";
458   pop_override_ok = 1;
459   obj_pop_insert ();
460
461   /* Now portable ones.  Skip any that we've seen already. */
462   pop_table_name = "standard";
463   pop_insert (potable);
464 }
465 \f
466 #define HANDLE_CONDITIONAL_ASSEMBLY()                                   \
467   if (ignore_input ())                                                  \
468     {                                                                   \
469       while (! is_end_of_line[(unsigned char) *input_line_pointer++])   \
470         if (input_line_pointer == buffer_limit)                         \
471           break;                                                        \
472       continue;                                                         \
473     }
474
475
476 /* This function is used when scrubbing the characters between #APP
477    and #NO_APP.  */
478
479 static char *scrub_string;
480 static char *scrub_string_end;
481
482 static int
483 scrub_from_string (buf, buflen)
484      char *buf;
485      int buflen;
486 {
487   int copy;
488
489   copy = scrub_string_end - scrub_string;
490   if (copy > buflen)
491     copy = buflen;
492   memcpy (buf, scrub_string, copy);
493   scrub_string += copy;
494   return copy;
495 }
496
497 /*      read_a_source_file()
498  *
499  * We read the file, putting things into a web that
500  * represents what we have been reading.
501  */
502 void 
503 read_a_source_file (name)
504      char *name;
505 {
506   register char c;
507   register char *s;             /* string of symbol, '\0' appended */
508   register int temp;
509   pseudo_typeS *pop;
510
511   buffer = input_scrub_new_file (name);
512
513   listing_file (name);
514   listing_newline (NULL);
515   register_dependency (name);
516
517   /* Generate debugging information before we've read anything in to denote
518      this file as the "main" source file and not a subordinate one
519      (e.g. N_SO vs N_SOL in stabs).  */
520   generate_file_debug ();
521
522   while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
523     {                           /* We have another line to parse. */
524       know (buffer_limit[-1] == '\n');  /* Must have a sentinel. */
525     contin:                     /* JF this goto is my fault I admit it.
526                                    Someone brave please re-write the whole
527                                    input section here?  Pleeze???  */
528       while (input_line_pointer < buffer_limit)
529         {
530           /* We have more of this buffer to parse. */
531
532           /*
533            * We now have input_line_pointer->1st char of next line.
534            * If input_line_pointer [-1] == '\n' then we just
535            * scanned another line: so bump line counters.
536            */
537           if (is_end_of_line[(unsigned char) input_line_pointer[-1]])
538             {
539 #ifdef md_start_line_hook
540               md_start_line_hook ();
541 #endif
542
543               if (input_line_pointer[-1] == '\n')
544                 bump_line_counters ();
545
546               line_label = NULL;
547
548               if (flag_m68k_mri
549 #ifdef LABELS_WITHOUT_COLONS
550                   || 1
551 #endif
552                   )
553                 {
554                   /* Text at the start of a line must be a label, we
555                      run down and stick a colon in.  */
556                   if (is_name_beginner (*input_line_pointer))
557                     {
558                       char *line_start = input_line_pointer;
559                       char c;
560                       int mri_line_macro;
561
562                       LISTING_NEWLINE ();
563                       HANDLE_CONDITIONAL_ASSEMBLY ();
564
565                       c = get_symbol_end ();
566
567                       /* In MRI mode, the EQU and MACRO pseudoops must
568                          be handled specially.  */
569                       mri_line_macro = 0;
570                       if (flag_m68k_mri)
571                         {
572                           char *rest = input_line_pointer + 1;
573
574                           if (*rest == ':')
575                             ++rest;
576                           if (*rest == ' ' || *rest == '\t')
577                             ++rest;
578                           if ((strncasecmp (rest, "EQU", 3) == 0
579                                || strncasecmp (rest, "SET", 3) == 0)
580                               && (rest[3] == ' ' || rest[3] == '\t'))
581                             {
582                               input_line_pointer = rest + 3;
583                               equals (line_start,
584                                       strncasecmp (rest, "SET", 3) == 0);
585                               continue;
586                             }
587                           if (strncasecmp (rest, "MACRO", 5) == 0
588                               && (rest[5] == ' '
589                                   || rest[5] == '\t'
590                                   || is_end_of_line[(unsigned char) rest[5]]))
591                             mri_line_macro = 1;
592                         }
593
594                       /* In MRI mode, we need to handle the MACRO
595                          pseudo-op specially: we don't want to put the
596                          symbol in the symbol table.  */
597                       if (! mri_line_macro)
598                         line_label = colon (line_start);
599                       else
600                         line_label = symbol_create (line_start,
601                                                     absolute_section,
602                                                     (valueT) 0,
603                                                     &zero_address_frag);
604
605                       *input_line_pointer = c;
606                       if (c == ':')
607                         input_line_pointer++;
608                     }
609                 }
610             }
611
612           /*
613            * We are at the begining of a line, or similar place.
614            * We expect a well-formed assembler statement.
615            * A "symbol-name:" is a statement.
616            *
617            * Depending on what compiler is used, the order of these tests
618            * may vary to catch most common case 1st.
619            * Each test is independent of all other tests at the (top) level.
620            * PLEASE make a compiler that doesn't use this assembler.
621            * It is crufty to waste a compiler's time encoding things for this
622            * assembler, which then wastes more time decoding it.
623            * (And communicating via (linear) files is silly!
624            * If you must pass stuff, please pass a tree!)
625            */
626           if ((c = *input_line_pointer++) == '\t'
627               || c == ' '
628               || c == '\f'
629               || c == 0)
630             {
631               c = *input_line_pointer++;
632             }
633           know (c != ' ');      /* No further leading whitespace. */
634
635 #ifndef NO_LISTING
636           /* If listing is on, and we are expanding a macro, then give
637              the listing code the contents of the expanded line.  */
638           if (listing)
639             {
640               if ((listing & LISTING_MACEXP) && macro_nest > 0)
641                 {
642                   char *copy;
643                   int len;
644
645                   /* Find the end of the current expanded macro line.  */
646                   for (s = input_line_pointer-1; *s ; ++s)
647                     if (is_end_of_line[(unsigned char) *s])
648                       break;
649
650                   /* Copy it for safe keeping.  Also give an indication of
651                      how much macro nesting is involved at this point.  */
652                   len = s - (input_line_pointer-1);
653                   copy = (char *) xmalloc (len + macro_nest + 2);
654                   memset (copy, '>', macro_nest);
655                   copy[macro_nest] = ' ';
656                   memcpy (copy + macro_nest + 1, input_line_pointer-1, len);
657                   copy[macro_nest+1+len] = '\0';
658
659                   /* Install the line with the listing facility.  */
660                   listing_newline (copy);
661                 }
662               else
663                 listing_newline (NULL);
664             }
665 #endif
666
667           /*
668            * C is the 1st significant character.
669            * Input_line_pointer points after that character.
670            */
671           if (is_name_beginner (c))
672             {
673               /* want user-defined label or pseudo/opcode */
674               HANDLE_CONDITIONAL_ASSEMBLY ();
675
676               s = --input_line_pointer;
677               c = get_symbol_end ();    /* name's delimiter */
678               /*
679                * C is character after symbol.
680                * That character's place in the input line is now '\0'.
681                * S points to the beginning of the symbol.
682                *   [In case of pseudo-op, s->'.'.]
683                * Input_line_pointer->'\0' where c was.
684                */
685               if (TC_START_LABEL(c, input_line_pointer))
686                 {
687                   if (flag_m68k_mri)
688                     {
689                       char *rest = input_line_pointer + 1;
690
691                       /* In MRI mode, \tsym: set 0 is permitted.  */
692
693                       if (*rest == ':')
694                         ++rest;
695                       if (*rest == ' ' || *rest == '\t')
696                         ++rest;
697                       if ((strncasecmp (rest, "EQU", 3) == 0
698                            || strncasecmp (rest, "SET", 3) == 0)
699                           && (rest[3] == ' ' || rest[3] == '\t'))
700                         {
701                           input_line_pointer = rest + 3;
702                           equals (s, 1);
703                           continue;
704                         }
705                     }
706
707                   line_label = colon (s);       /* user-defined label */
708                   *input_line_pointer++ = ':';  /* Put ':' back for error messages' sake. */
709                   /* Input_line_pointer->after ':'. */
710                   SKIP_WHITESPACE ();
711
712
713                 }
714               else if (c == '='
715                        || ((c == ' ' || c == '\t')
716                            && input_line_pointer[1] == '='
717 #ifdef TC_EQUAL_IN_INSN
718                            && ! TC_EQUAL_IN_INSN (c, input_line_pointer)
719 #endif
720                            ))
721                 {
722                   equals (s, 1);
723                   demand_empty_rest_of_line ();
724                 }
725               else
726                 {               /* expect pseudo-op or machine instruction */
727                   pop = NULL;
728
729 #define IGNORE_OPCODE_CASE
730 #ifdef IGNORE_OPCODE_CASE
731                   {
732                     char *s2 = s;
733                     while (*s2)
734                       {
735                         if (isupper ((unsigned char) *s2))
736                           *s2 = tolower (*s2);
737                         s2++;
738                       }
739                   }
740 #endif
741
742                   if (flag_m68k_mri
743 #ifdef NO_PSEUDO_DOT
744                       || 1
745 #endif
746                       )
747                     {
748                       /* The MRI assembler and the m88k use pseudo-ops
749                          without a period.  */
750                       pop = (pseudo_typeS *) hash_find (po_hash, s);
751                       if (pop != NULL && pop->poc_handler == NULL)
752                         pop = NULL;
753                     }
754
755                   if (pop != NULL
756                       || (! flag_m68k_mri && *s == '.'))
757                     {
758                       /*
759                        * PSEUDO - OP.
760                        *
761                        * WARNING: c has next char, which may be end-of-line.
762                        * We lookup the pseudo-op table with s+1 because we
763                        * already know that the pseudo-op begins with a '.'.
764                        */
765
766                       if (pop == NULL)
767                         pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
768
769                       /* In MRI mode, we may need to insert an
770                          automatic alignment directive.  What a hack
771                          this is.  */
772                       if (mri_pending_align
773                           && (pop == NULL
774                               || ! ((pop->poc_handler == cons
775                                      && pop->poc_val == 1)
776                                     || (pop->poc_handler == s_space
777                                         && pop->poc_val == 1)
778 #ifdef tc_conditional_pseudoop
779                                     || tc_conditional_pseudoop (pop)
780 #endif
781                                     || pop->poc_handler == s_if
782                                     || pop->poc_handler == s_ifdef
783                                     || pop->poc_handler == s_ifc
784                                     || pop->poc_handler == s_ifeqs
785                                     || pop->poc_handler == s_else
786                                     || pop->poc_handler == s_endif
787                                     || pop->poc_handler == s_globl
788                                     || pop->poc_handler == s_ignore)))
789                         {
790                           do_align (1, (char *) NULL, 0, 0);
791                           mri_pending_align = 0;
792                           if (line_label != NULL)
793                             {
794                               symbol_set_frag (line_label, frag_now);
795                               S_SET_VALUE (line_label, frag_now_fix ());
796                             }
797                         }
798
799                       /* Print the error msg now, while we still can */
800                       if (pop == NULL)
801                         {
802                           as_bad (_("Unknown pseudo-op:  `%s'"), s);
803                           *input_line_pointer = c;
804                           s_ignore (0);
805                           continue;
806                         }
807
808                       /* Put it back for error messages etc. */
809                       *input_line_pointer = c;
810                       /* The following skip of whitespace is compulsory.
811                          A well shaped space is sometimes all that separates
812                          keyword from operands. */
813                       if (c == ' ' || c == '\t')
814                         input_line_pointer++;
815                       /*
816                        * Input_line is restored.
817                        * Input_line_pointer->1st non-blank char
818                        * after pseudo-operation.
819                        */
820                       (*pop->poc_handler) (pop->poc_val);
821
822                       /* If that was .end, just get out now.  */
823                       if (pop->poc_handler == s_end)
824                         goto quit;
825                     }
826                   else
827                     {
828                       int inquote = 0;
829
830                       /* WARNING: c has char, which may be end-of-line. */
831                       /* Also: input_line_pointer->`\0` where c was. */
832                       *input_line_pointer = c;
833                       while (!is_end_of_line[(unsigned char) *input_line_pointer]
834                              || inquote
835 #ifdef TC_EOL_IN_INSN
836                              || TC_EOL_IN_INSN (input_line_pointer)
837 #endif
838                              )
839                         {
840                           if (flag_m68k_mri && *input_line_pointer == '\'')
841                             inquote = ! inquote;
842                           input_line_pointer++;
843                         }
844
845                       c = *input_line_pointer;
846                       *input_line_pointer = '\0';
847
848                       generate_lineno_debug ();
849
850                       if (macro_defined)
851                         {
852                           sb out;
853                           const char *err;
854
855                           if (check_macro (s, &out, '\0', &err))
856                             {
857                               if (err != NULL)
858                                 as_bad (err);
859                               *input_line_pointer++ = c;
860                               input_scrub_include_sb (&out,
861                                                       input_line_pointer);
862                               sb_kill (&out);
863                               buffer_limit =
864                                 input_scrub_next_buffer (&input_line_pointer);
865                               continue;
866                             }
867                         }
868
869                       if (mri_pending_align)
870                         {
871                           do_align (1, (char *) NULL, 0, 0);
872                           mri_pending_align = 0;
873                           if (line_label != NULL)
874                             {
875                               symbol_set_frag (line_label, frag_now);
876                               S_SET_VALUE (line_label, frag_now_fix ());
877                             }
878                         }
879
880                       md_assemble (s);  /* Assemble 1 instruction. */
881
882                       *input_line_pointer++ = c;
883
884                       /* We resume loop AFTER the end-of-line from
885                          this instruction. */
886                     }           /* if (*s=='.') */
887                 }               /* if c==':' */
888               continue;
889             }                   /* if (is_name_beginner(c) */
890
891
892           /* Empty statement?  */
893           if (is_end_of_line[(unsigned char) c])
894             continue;
895
896           if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB)
897               && isdigit ((unsigned char) c))
898             {
899               /* local label  ("4:") */
900               char *backup = input_line_pointer;
901
902               HANDLE_CONDITIONAL_ASSEMBLY ();
903
904               temp = c - '0';
905
906               while (isdigit ((unsigned char) *input_line_pointer))
907                 {
908                   temp = (temp * 10) + *input_line_pointer - '0';
909                   ++input_line_pointer;
910                 }               /* read the whole number */
911
912               if (LOCAL_LABELS_DOLLAR
913                   && *input_line_pointer == '$'
914                   && *(input_line_pointer + 1) == ':')
915                 {
916                   input_line_pointer += 2;
917
918                   if (dollar_label_defined (temp))
919                     {
920                       as_fatal (_("label \"%d$\" redefined"), temp);
921                     }
922
923                   define_dollar_label (temp);
924                   colon (dollar_label_name (temp, 0));
925                   continue;
926                 }
927
928               if (LOCAL_LABELS_FB
929                   && *input_line_pointer++ == ':')
930                 {
931                   fb_label_instance_inc (temp);
932                   colon (fb_label_name (temp, 0));
933                   continue;
934                 }
935
936               input_line_pointer = backup;
937             }                   /* local label  ("4:") */
938
939           if (c && strchr (line_comment_chars, c))
940             {                   /* Its a comment.  Better say APP or NO_APP */
941               char *ends;
942               char *new_buf;
943               char *new_tmp;
944               unsigned int new_length;
945               char *tmp_buf = 0;
946
947               bump_line_counters ();
948               s = input_line_pointer;
949               if (strncmp (s, "APP\n", 4))
950                 continue;       /* We ignore it */
951               s += 4;
952
953               ends = strstr (s, "#NO_APP\n");
954
955               if (!ends)
956                 {
957                   unsigned int tmp_len;
958                   unsigned int num;
959
960                   /* The end of the #APP wasn't in this buffer.  We
961                      keep reading in buffers until we find the #NO_APP
962                      that goes with this #APP  There is one.  The specs
963                      guarentee it. . . */
964                   tmp_len = buffer_limit - s;
965                   tmp_buf = xmalloc (tmp_len + 1);
966                   memcpy (tmp_buf, s, tmp_len);
967                   do
968                     {
969                       new_tmp = input_scrub_next_buffer (&buffer);
970                       if (!new_tmp)
971                         break;
972                       else
973                         buffer_limit = new_tmp;
974                       input_line_pointer = buffer;
975                       ends = strstr (buffer, "#NO_APP\n");
976                       if (ends)
977                         num = ends - buffer;
978                       else
979                         num = buffer_limit - buffer;
980
981                       tmp_buf = xrealloc (tmp_buf, tmp_len + num);
982                       memcpy (tmp_buf + tmp_len, buffer, num);
983                       tmp_len += num;
984                     }
985                   while (!ends);
986
987                   input_line_pointer = ends ? ends + 8 : NULL;
988
989                   s = tmp_buf;
990                   ends = s + tmp_len;
991
992                 }
993               else
994                 {
995                   input_line_pointer = ends + 8;
996                 }
997
998               scrub_string = s;
999               scrub_string_end = ends;
1000
1001               new_length = ends - s;
1002               new_buf = (char *) xmalloc (new_length);
1003               new_tmp = new_buf;
1004               for (;;)
1005                 {
1006                   int space;
1007                   int size;
1008
1009                   space = (new_buf + new_length) - new_tmp;
1010                   size = do_scrub_chars (scrub_from_string, new_tmp, space);
1011
1012                   if (size < space)
1013                     {
1014                       new_tmp += size;
1015                       break;
1016                     }
1017
1018                   new_buf = xrealloc (new_buf, new_length + 100);
1019                   new_tmp = new_buf + new_length;
1020                   new_length += 100;
1021                 }
1022
1023               if (tmp_buf)
1024                 free (tmp_buf);
1025               old_buffer = buffer;
1026               old_input = input_line_pointer;
1027               old_limit = buffer_limit;
1028               buffer = new_buf;
1029               input_line_pointer = new_buf;
1030               buffer_limit = new_tmp;
1031               continue;
1032             }
1033
1034           HANDLE_CONDITIONAL_ASSEMBLY ();
1035
1036 #ifdef tc_unrecognized_line
1037           if (tc_unrecognized_line (c))
1038             continue;
1039 #endif
1040
1041           /* as_warn("Junk character %d.",c);  Now done by ignore_rest */
1042           input_line_pointer--; /* Report unknown char as ignored. */
1043           ignore_rest_of_line ();
1044         }                       /* while (input_line_pointer<buffer_limit) */
1045
1046 #ifdef md_after_pass_hook
1047       md_after_pass_hook ();
1048 #endif
1049
1050       if (old_buffer)
1051         {
1052           free (buffer);
1053           bump_line_counters ();
1054           if (old_input != 0)
1055             {
1056               buffer = old_buffer;
1057               input_line_pointer = old_input;
1058               buffer_limit = old_limit;
1059               old_buffer = 0;
1060               goto contin;
1061             }
1062         }
1063     }                           /* while (more buffers to scan) */
1064
1065  quit:
1066
1067 #ifdef md_cleanup
1068   md_cleanup();
1069 #endif
1070   input_scrub_close ();         /* Close the input file */
1071 }
1072
1073 /* For most MRI pseudo-ops, the line actually ends at the first
1074    nonquoted space.  This function looks for that point, stuffs a null
1075    in, and sets *STOPCP to the character that used to be there, and
1076    returns the location.
1077
1078    Until I hear otherwise, I am going to assume that this is only true
1079    for the m68k MRI assembler.  */
1080
1081 char *
1082 mri_comment_field (stopcp)
1083      char *stopcp;
1084 {
1085 #ifdef TC_M68K
1086
1087   char *s;
1088   int inquote = 0;
1089
1090   know (flag_m68k_mri);
1091
1092   for (s = input_line_pointer;
1093        ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1094         || inquote);
1095        s++)
1096     {
1097       if (*s == '\'')
1098         inquote = ! inquote;
1099     }
1100   *stopcp = *s;
1101   *s = '\0';
1102   return s;
1103
1104 #else
1105
1106   char *s;
1107
1108   for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++)
1109     ;
1110   *stopcp = *s;
1111   *s = '\0';
1112   return s;
1113
1114 #endif
1115
1116 }
1117
1118 /* Skip to the end of an MRI comment field.  */
1119
1120 void
1121 mri_comment_end (stop, stopc)
1122      char *stop;
1123      int stopc;
1124 {
1125   know (flag_mri);
1126
1127   input_line_pointer = stop;
1128   *stop = stopc;
1129   while (! is_end_of_line[(unsigned char) *input_line_pointer])
1130     ++input_line_pointer;
1131 }
1132
1133 void 
1134 s_abort (ignore)
1135      int ignore;
1136 {
1137   as_fatal (_(".abort detected.  Abandoning ship."));
1138 }
1139
1140 /* Guts of .align directive.  N is the power of two to which to align.
1141    FILL may be NULL, or it may point to the bytes of the fill pattern.
1142    LEN is the length of whatever FILL points to, if anything.  MAX is
1143    the maximum number of characters to skip when doing the alignment,
1144    or 0 if there is no maximum.  */
1145
1146 static void 
1147 do_align (n, fill, len, max)
1148      int n;
1149      char *fill;
1150      int len;
1151      int max;
1152 {
1153   char default_fill;
1154
1155 #ifdef md_do_align
1156   md_do_align (n, fill, len, max, just_record_alignment);
1157 #endif
1158
1159   if (fill == NULL)
1160     {
1161       int maybe_text;
1162
1163 #ifdef BFD_ASSEMBLER
1164       if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
1165         maybe_text = 1;
1166       else
1167         maybe_text = 0;
1168 #else
1169       if (now_seg != data_section && now_seg != bss_section)
1170         maybe_text = 1;
1171       else
1172         maybe_text = 0;
1173 #endif
1174
1175       if (maybe_text)
1176         default_fill = NOP_OPCODE;
1177       else
1178         default_fill = 0;
1179       fill = &default_fill;
1180       len = 1;
1181     }
1182
1183   /* Only make a frag if we HAVE to. . . */
1184   if (n != 0 && !need_pass_2)
1185     {
1186       if (len <= 1)
1187         frag_align (n, *fill, max);
1188       else
1189         frag_align_pattern (n, fill, len, max);
1190     }
1191
1192 #ifdef md_do_align
1193  just_record_alignment:
1194 #endif
1195
1196   record_alignment (now_seg, n);
1197 }
1198
1199 /* Handle the .align pseudo-op.  A positive ARG is a default alignment
1200    (in bytes).  A negative ARG is the negative of the length of the
1201    fill pattern.  BYTES_P is non-zero if the alignment value should be
1202    interpreted as the byte boundary, rather than the power of 2.  */
1203
1204 static void
1205 s_align (arg, bytes_p)
1206      int arg;
1207      int bytes_p;
1208 {
1209   register unsigned int align;
1210   char *stop = NULL;
1211   char stopc;
1212   offsetT fill = 0;
1213   int max;
1214   int fill_p;
1215
1216   if (flag_mri)
1217     stop = mri_comment_field (&stopc);
1218
1219   if (is_end_of_line[(unsigned char) *input_line_pointer])
1220     {
1221       if (arg < 0)
1222         align = 0;
1223       else
1224         align = arg;    /* Default value from pseudo-op table */
1225     }
1226   else
1227     {
1228       align = get_absolute_expression ();
1229       SKIP_WHITESPACE ();
1230     }
1231
1232   if (bytes_p)
1233     {
1234       /* Convert to a power of 2.  */
1235       if (align != 0)
1236         {
1237           unsigned int i;
1238
1239           for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1240             ;
1241           if (align != 1)
1242             as_bad (_("Alignment not a power of 2"));
1243           align = i;
1244         }
1245     }
1246
1247   if (align > 15)
1248     {
1249       align = 15;
1250       as_bad (_("Alignment too large: %u assumed"), align);
1251     }
1252
1253   if (*input_line_pointer != ',')
1254     {
1255       fill_p = 0;
1256       max = 0;
1257     }
1258   else
1259     {
1260       ++input_line_pointer;
1261       if (*input_line_pointer == ',')
1262         fill_p = 0;
1263       else
1264         {
1265           fill = get_absolute_expression ();
1266           SKIP_WHITESPACE ();
1267           fill_p = 1;
1268         }
1269
1270       if (*input_line_pointer != ',')
1271         max = 0;
1272       else
1273         {
1274           ++input_line_pointer;
1275           max = get_absolute_expression ();
1276         }
1277     }
1278
1279   if (! fill_p)
1280     {
1281       if (arg < 0)
1282         as_warn (_("expected fill pattern missing"));
1283       do_align (align, (char *) NULL, 0, max);
1284     }
1285   else
1286     {
1287       int fill_len;
1288
1289       if (arg >= 0)
1290         fill_len = 1;
1291       else
1292         fill_len = - arg;
1293       if (fill_len <= 1)
1294         {
1295           char fill_char;
1296
1297           fill_char = fill;
1298           do_align (align, &fill_char, fill_len, max);
1299         }
1300       else
1301         {
1302           char ab[16];
1303
1304           if ((size_t) fill_len > sizeof ab)
1305             abort ();
1306           md_number_to_chars (ab, fill, fill_len);
1307           do_align (align, ab, fill_len, max);
1308         }
1309     }
1310
1311   demand_empty_rest_of_line ();
1312
1313   if (flag_mri)
1314     mri_comment_end (stop, stopc);
1315 }
1316
1317 /* Handle the .align pseudo-op on machines where ".align 4" means
1318    align to a 4 byte boundary.  */
1319
1320 void 
1321 s_align_bytes (arg)
1322      int arg;
1323 {
1324   s_align (arg, 1);
1325 }
1326
1327 /* Handle the .align pseudo-op on machines where ".align 4" means align
1328    to a 2**4 boundary.  */
1329
1330 void 
1331 s_align_ptwo (arg)
1332      int arg;
1333 {
1334   s_align (arg, 0);
1335 }
1336
1337 void 
1338 s_comm (ignore)
1339      int ignore;
1340 {
1341   register char *name;
1342   register char c;
1343   register char *p;
1344   offsetT temp;
1345   register symbolS *symbolP;
1346   char *stop = NULL;
1347   char stopc;
1348
1349   if (flag_mri)
1350     stop = mri_comment_field (&stopc);
1351
1352   name = input_line_pointer;
1353   c = get_symbol_end ();
1354   /* just after name is now '\0' */
1355   p = input_line_pointer;
1356   *p = c;
1357   SKIP_WHITESPACE ();
1358   if (*input_line_pointer != ',')
1359     {
1360       as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1361       ignore_rest_of_line ();
1362       if (flag_mri)
1363         mri_comment_end (stop, stopc);
1364       return;
1365     }
1366   input_line_pointer++;         /* skip ',' */
1367   if ((temp = get_absolute_expression ()) < 0)
1368     {
1369       as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
1370       ignore_rest_of_line ();
1371       if (flag_mri)
1372         mri_comment_end (stop, stopc);
1373       return;
1374     }
1375   *p = 0;
1376   symbolP = symbol_find_or_make (name);
1377   *p = c;
1378   if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1379     {
1380       as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1381               S_GET_NAME (symbolP));
1382       ignore_rest_of_line ();
1383       if (flag_mri)
1384         mri_comment_end (stop, stopc);
1385       return;
1386     }
1387   if (S_GET_VALUE (symbolP))
1388     {
1389       if (S_GET_VALUE (symbolP) != (valueT) temp)
1390         as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
1391                 S_GET_NAME (symbolP),
1392                 (long) S_GET_VALUE (symbolP),
1393                 (long) temp);
1394     }
1395   else
1396     {
1397       S_SET_VALUE (symbolP, (valueT) temp);
1398       S_SET_EXTERNAL (symbolP);
1399     }
1400 #ifdef OBJ_VMS
1401   {
1402     extern int flag_one;
1403     if ( (!temp) || !flag_one)
1404       S_GET_OTHER(symbolP) = const_flag;
1405   }
1406 #endif /* not OBJ_VMS */
1407   know (symbolP->sy_frag == &zero_address_frag);
1408
1409   demand_empty_rest_of_line ();
1410
1411   if (flag_mri)
1412     mri_comment_end (stop, stopc);
1413 }                               /* s_comm() */
1414
1415 /* The MRI COMMON pseudo-op.  We handle this by creating a common
1416    symbol with the appropriate name.  We make s_space do the right
1417    thing by increasing the size.  */
1418
1419 void
1420 s_mri_common (small)
1421      int small;
1422 {
1423   char *name;
1424   char c;
1425   char *alc = NULL;
1426   symbolS *sym;
1427   offsetT align;
1428   char *stop = NULL;
1429   char stopc;
1430
1431   if (! flag_mri)
1432     {
1433       s_comm (0);
1434       return;
1435     }
1436
1437   stop = mri_comment_field (&stopc);
1438
1439   SKIP_WHITESPACE ();
1440
1441   name = input_line_pointer;
1442   if (! isdigit ((unsigned char) *name))
1443     c = get_symbol_end ();
1444   else
1445     {
1446       do
1447         {
1448           ++input_line_pointer;
1449         }
1450       while (isdigit ((unsigned char) *input_line_pointer));
1451       c = *input_line_pointer;
1452       *input_line_pointer = '\0';
1453
1454       if (line_label != NULL)
1455         {
1456           alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1457                                   + (input_line_pointer - name)
1458                                   + 1);
1459           sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1460           name = alc;
1461         }
1462     }
1463
1464   sym = symbol_find_or_make (name);
1465   *input_line_pointer = c;
1466   if (alc != NULL)
1467     free (alc);
1468
1469   if (*input_line_pointer != ',')
1470     align = 0;
1471   else
1472     {
1473       ++input_line_pointer;
1474       align = get_absolute_expression ();
1475     }
1476
1477   if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym))
1478     {
1479       as_bad (_("attempt to re-define symbol `%s'"), S_GET_NAME (sym));
1480       ignore_rest_of_line ();
1481       mri_comment_end (stop, stopc);
1482       return;
1483     }
1484
1485   S_SET_EXTERNAL (sym);
1486   mri_common_symbol = sym;
1487
1488 #ifdef S_SET_ALIGN
1489   if (align != 0)
1490     S_SET_ALIGN (sym, align);
1491 #endif
1492
1493   if (line_label != NULL)
1494     {
1495       expressionS exp;
1496       exp.X_op = O_symbol;
1497       exp.X_add_symbol = sym;
1498       exp.X_add_number = 0;
1499       symbol_set_value_expression (line_label, &exp);
1500       symbol_set_frag (line_label, &zero_address_frag);
1501       S_SET_SEGMENT (line_label, expr_section);
1502     }
1503
1504   /* FIXME: We just ignore the small argument, which distinguishes
1505      COMMON and COMMON.S.  I don't know what we can do about it.  */
1506
1507   /* Ignore the type and hptype.  */
1508   if (*input_line_pointer == ',')
1509     input_line_pointer += 2;
1510   if (*input_line_pointer == ',')
1511     input_line_pointer += 2;
1512
1513   demand_empty_rest_of_line ();
1514
1515   mri_comment_end (stop, stopc);
1516 }
1517
1518 void
1519 s_data (ignore)
1520      int ignore;
1521 {
1522   segT section;
1523   register int temp;
1524
1525   temp = get_absolute_expression ();
1526   if (flag_readonly_data_in_text)
1527     {
1528       section = text_section;
1529       temp += 1000;
1530     }
1531   else
1532     section = data_section;
1533
1534   subseg_set (section, (subsegT) temp);
1535
1536 #ifdef OBJ_VMS
1537   const_flag = 0;
1538 #endif
1539   demand_empty_rest_of_line ();
1540 }
1541
1542 /* Handle the .appfile pseudo-op.  This is automatically generated by
1543    do_scrub_chars when a preprocessor # line comment is seen with a
1544    file name.  This default definition may be overridden by the object
1545    or CPU specific pseudo-ops.  This function is also the default
1546    definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1547    .file.  */
1548
1549 void 
1550 s_app_file (appfile)
1551      int appfile;
1552 {
1553   register char *s;
1554   int length;
1555
1556   /* Some assemblers tolerate immediately following '"' */
1557   if ((s = demand_copy_string (&length)) != 0)
1558     {
1559       /* If this is a fake .appfile, a fake newline was inserted into
1560          the buffer.  Passing -2 to new_logical_line tells it to
1561          account for it.  */
1562       int may_omit
1563         = (! new_logical_line (s, appfile ? -2 : -1) && appfile);
1564
1565       /* In MRI mode, the preprocessor may have inserted an extraneous
1566          backquote.  */
1567       if (flag_m68k_mri
1568           && *input_line_pointer == '\''
1569           && is_end_of_line[(unsigned char) input_line_pointer[1]])
1570         ++input_line_pointer;
1571
1572       demand_empty_rest_of_line ();
1573       if (! may_omit)
1574         {
1575 #ifdef LISTING
1576           if (listing)
1577             listing_source_file (s);
1578 #endif
1579           register_dependency (s);
1580 #ifdef obj_app_file
1581           obj_app_file (s);
1582 #endif
1583         }
1584     }
1585 }
1586
1587 /* Handle the .appline pseudo-op.  This is automatically generated by
1588    do_scrub_chars when a preprocessor # line comment is seen.  This
1589    default definition may be overridden by the object or CPU specific
1590    pseudo-ops.  */
1591
1592 void
1593 s_app_line (ignore)
1594      int ignore;
1595 {
1596   int l;
1597
1598   /* The given number is that of the next line.  */
1599   l = get_absolute_expression () - 1;
1600   if (l < 0)
1601     /* Some of the back ends can't deal with non-positive line numbers.
1602        Besides, it's silly.  */
1603     as_warn (_("Line numbers must be positive; line number %d rejected."), l+1);
1604   else
1605     {
1606       new_logical_line ((char *) NULL, l);
1607 #ifdef LISTING
1608       if (listing)
1609         listing_source_line (l);
1610 #endif
1611     }
1612   demand_empty_rest_of_line ();
1613 }
1614
1615 /* Handle the .end pseudo-op.  Actually, the real work is done in
1616    read_a_source_file.  */
1617
1618 void
1619 s_end (ignore)
1620      int ignore;
1621 {
1622   if (flag_mri)
1623     {
1624       /* The MRI assembler permits the start symbol to follow .end,
1625          but we don't support that.  */
1626       SKIP_WHITESPACE ();
1627       if (! is_end_of_line[(unsigned char) *input_line_pointer]
1628           && *input_line_pointer != '*'
1629           && *input_line_pointer != '!')
1630         as_warn (_("start address not supported"));
1631     }
1632 }
1633
1634 /* Handle the .err pseudo-op.  */
1635
1636 void
1637 s_err (ignore)
1638      int ignore;
1639 {
1640   as_bad (_(".err encountered"));
1641   demand_empty_rest_of_line ();
1642 }
1643
1644 /* Handle the MRI fail pseudo-op.  */
1645
1646 void
1647 s_fail (ignore)
1648      int ignore;
1649 {
1650   offsetT temp;
1651   char *stop = NULL;
1652   char stopc;
1653
1654   if (flag_mri)
1655     stop = mri_comment_field (&stopc);
1656
1657   temp = get_absolute_expression ();
1658   if (temp >= 500)
1659     as_warn (_(".fail %ld encountered"), (long) temp);
1660   else
1661     as_bad (_(".fail %ld encountered"), (long) temp);
1662
1663   demand_empty_rest_of_line ();
1664
1665   if (flag_mri)
1666     mri_comment_end (stop, stopc);
1667 }
1668
1669 void 
1670 s_fill (ignore)
1671      int ignore;
1672 {
1673   expressionS rep_exp;
1674   long size = 1;
1675   register long fill = 0;
1676   char *p;
1677
1678 #ifdef md_flush_pending_output
1679   md_flush_pending_output ();
1680 #endif
1681
1682   get_known_segmented_expression (&rep_exp);
1683   if (*input_line_pointer == ',')
1684     {
1685       input_line_pointer++;
1686       size = get_absolute_expression ();
1687       if (*input_line_pointer == ',')
1688         {
1689           input_line_pointer++;
1690           fill = get_absolute_expression ();
1691         }
1692     }
1693
1694   /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
1695 #define BSD_FILL_SIZE_CROCK_8 (8)
1696   if (size > BSD_FILL_SIZE_CROCK_8)
1697     {
1698       as_warn (_(".fill size clamped to %d."), BSD_FILL_SIZE_CROCK_8);
1699       size = BSD_FILL_SIZE_CROCK_8;
1700     }
1701   if (size < 0)
1702     {
1703       as_warn (_("Size negative: .fill ignored."));
1704       size = 0;
1705     }
1706   else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
1707     {
1708       if (rep_exp.X_add_number < 0)
1709         as_warn (_("Repeat < 0, .fill ignored"));
1710       size = 0;
1711     }
1712
1713   if (size && !need_pass_2)
1714     {
1715       if (rep_exp.X_op == O_constant)
1716         {
1717           p = frag_var (rs_fill, (int) size, (int) size,
1718                         (relax_substateT) 0, (symbolS *) 0,
1719                         (offsetT) rep_exp.X_add_number,
1720                         (char *) 0);
1721         }
1722       else
1723         {
1724           /* We don't have a constant repeat count, so we can't use
1725              rs_fill.  We can get the same results out of rs_space,
1726              but its argument is in bytes, so we must multiply the
1727              repeat count by size.  */
1728
1729           symbolS *rep_sym;
1730           rep_sym = make_expr_symbol (&rep_exp);
1731           if (size != 1)
1732             {
1733               expressionS size_exp;
1734               size_exp.X_op = O_constant;
1735               size_exp.X_add_number = size;
1736
1737               rep_exp.X_op = O_multiply;
1738               rep_exp.X_add_symbol = rep_sym;
1739               rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
1740               rep_exp.X_add_number = 0;
1741               rep_sym = make_expr_symbol (&rep_exp);
1742             }
1743
1744           p = frag_var (rs_space, (int) size, (int) size,
1745                         (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
1746         }
1747       memset (p, 0, (unsigned int) size);
1748       /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
1749        * flavoured AS.  The following bizzare behaviour is to be
1750        * compatible with above.  I guess they tried to take up to 8
1751        * bytes from a 4-byte expression and they forgot to sign
1752        * extend. Un*x Sux. */
1753 #define BSD_FILL_SIZE_CROCK_4 (4)
1754       md_number_to_chars (p, (valueT) fill,
1755                           (size > BSD_FILL_SIZE_CROCK_4
1756                            ? BSD_FILL_SIZE_CROCK_4
1757                            : (int) size));
1758       /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
1759        * but emits no error message because it seems a legal thing to do.
1760        * It is a degenerate case of .fill but could be emitted by a compiler.
1761        */
1762     }
1763   demand_empty_rest_of_line ();
1764 }
1765
1766 void 
1767 s_globl (ignore)
1768      int ignore;
1769 {
1770   char *name;
1771   int c;
1772   symbolS *symbolP;
1773   char *stop = NULL;
1774   char stopc;
1775
1776   if (flag_mri)
1777     stop = mri_comment_field (&stopc);
1778
1779   do
1780     {
1781       name = input_line_pointer;
1782       c = get_symbol_end ();
1783       symbolP = symbol_find_or_make (name);
1784       *input_line_pointer = c;
1785       SKIP_WHITESPACE ();
1786       S_SET_EXTERNAL (symbolP);
1787       if (c == ',')
1788         {
1789           input_line_pointer++;
1790           SKIP_WHITESPACE ();
1791           if (*input_line_pointer == '\n')
1792             c = '\n';
1793         }
1794     }
1795   while (c == ',');
1796
1797   demand_empty_rest_of_line ();
1798
1799   if (flag_mri)
1800     mri_comment_end (stop, stopc);
1801 }
1802
1803 /* Handle the MRI IRP and IRPC pseudo-ops.  */
1804
1805 void
1806 s_irp (irpc)
1807      int irpc;
1808 {
1809   char *file;
1810   unsigned int line;
1811   sb s;
1812   const char *err;
1813   sb out;
1814
1815   as_where (&file, &line);
1816
1817   sb_new (&s);
1818   while (! is_end_of_line[(unsigned char) *input_line_pointer])
1819     sb_add_char (&s, *input_line_pointer++);
1820
1821   sb_new (&out);
1822
1823   err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0');
1824   if (err != NULL)
1825     as_bad_where (file, line, "%s", err);
1826
1827   sb_kill (&s);
1828
1829   input_scrub_include_sb (&out, input_line_pointer);
1830   sb_kill (&out);
1831   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1832 }
1833
1834 /* Handle the .linkonce pseudo-op.  This tells the assembler to mark
1835    the section to only be linked once.  However, this is not supported
1836    by most object file formats.  This takes an optional argument,
1837    which is what to do about duplicates.  */
1838
1839 void
1840 s_linkonce (ignore)
1841      int ignore;
1842 {
1843   enum linkonce_type type;
1844
1845   SKIP_WHITESPACE ();
1846
1847   type = LINKONCE_DISCARD;
1848
1849   if (! is_end_of_line[(unsigned char) *input_line_pointer])
1850     {
1851       char *s;
1852       char c;
1853
1854       s = input_line_pointer;
1855       c = get_symbol_end ();
1856       if (strcasecmp (s, "discard") == 0)
1857         type = LINKONCE_DISCARD;
1858       else if (strcasecmp (s, "one_only") == 0)
1859         type = LINKONCE_ONE_ONLY;
1860       else if (strcasecmp (s, "same_size") == 0)
1861         type = LINKONCE_SAME_SIZE;
1862       else if (strcasecmp (s, "same_contents") == 0)
1863         type = LINKONCE_SAME_CONTENTS;
1864       else
1865         as_warn (_("unrecognized .linkonce type `%s'"), s);
1866
1867       *input_line_pointer = c;
1868     }
1869
1870 #ifdef obj_handle_link_once
1871   obj_handle_link_once (type);
1872 #else /* ! defined (obj_handle_link_once) */
1873 #ifdef BFD_ASSEMBLER
1874   {
1875     flagword flags;
1876
1877     if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
1878       as_warn (_(".linkonce is not supported for this object file format"));
1879
1880     flags = bfd_get_section_flags (stdoutput, now_seg);
1881     flags |= SEC_LINK_ONCE;
1882     switch (type)
1883       {
1884       default:
1885         abort ();
1886       case LINKONCE_DISCARD:
1887         flags |= SEC_LINK_DUPLICATES_DISCARD;
1888         break;
1889       case LINKONCE_ONE_ONLY:
1890         flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
1891         break;
1892       case LINKONCE_SAME_SIZE:
1893         flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
1894         break;
1895       case LINKONCE_SAME_CONTENTS:
1896         flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
1897         break;
1898       }
1899     if (! bfd_set_section_flags (stdoutput, now_seg, flags))
1900       as_bad (_("bfd_set_section_flags: %s"),
1901               bfd_errmsg (bfd_get_error ()));
1902   }
1903 #else /* ! defined (BFD_ASSEMBLER) */
1904   as_warn (_(".linkonce is not supported for this object file format"));
1905 #endif /* ! defined (BFD_ASSEMBLER) */
1906 #endif /* ! defined (obj_handle_link_once) */
1907
1908   demand_empty_rest_of_line ();
1909 }
1910
1911 static void 
1912 s_lcomm_internal (needs_align, bytes_p)
1913      /* 1 if this was a ".bss" directive, which may require a 3rd argument
1914         (alignment); 0 if it was an ".lcomm" (2 args only)  */
1915      int needs_align;
1916      /* 1 if the alignment value should be interpreted as the byte boundary,
1917         rather than the power of 2. */
1918      int bytes_p;
1919 {
1920   register char *name;
1921   register char c;
1922   register char *p;
1923   register int temp;
1924   register symbolS *symbolP;
1925   segT current_seg = now_seg;
1926   subsegT current_subseg = now_subseg;
1927   const int max_alignment = 15;
1928   int align = 0;
1929   segT bss_seg = bss_section;
1930
1931   name = input_line_pointer;
1932   c = get_symbol_end ();
1933   p = input_line_pointer;
1934   *p = c;
1935   SKIP_WHITESPACE ();
1936
1937   /* Accept an optional comma after the name.  The comma used to be
1938      required, but Irix 5 cc does not generate it.  */
1939   if (*input_line_pointer == ',')
1940     {
1941       ++input_line_pointer;
1942       SKIP_WHITESPACE ();
1943     }
1944
1945   if (*input_line_pointer == '\n')
1946     {
1947       as_bad (_("Missing size expression"));
1948       return;
1949     }
1950
1951   if ((temp = get_absolute_expression ()) < 0)
1952     {
1953       as_warn (_("BSS length (%d.) <0! Ignored."), temp);
1954       ignore_rest_of_line ();
1955       return;
1956     }
1957
1958 #if defined (TC_MIPS) || defined (TC_ALPHA)
1959   if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
1960       || OUTPUT_FLAVOR == bfd_target_elf_flavour)
1961     {
1962       /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss.  */
1963       if (temp <= bfd_get_gp_size (stdoutput))
1964         {
1965           bss_seg = subseg_new (".sbss", 1);
1966           seg_info (bss_seg)->bss = 1;
1967 #ifdef BFD_ASSEMBLER
1968           if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
1969             as_warn (_("error setting flags for \".sbss\": %s"),
1970                      bfd_errmsg (bfd_get_error ()));
1971 #endif
1972         }
1973     }
1974 #endif
1975    if (!needs_align)
1976      {
1977        /* FIXME. This needs to be machine independent. */
1978        if (temp >= 8)
1979          align = 3;
1980        else if (temp >= 4)
1981          align = 2;
1982        else if (temp >= 2)
1983          align = 1;
1984        else
1985          align = 0;
1986
1987 #ifdef OBJ_EVAX
1988        /* FIXME: This needs to be done in a more general fashion.  */
1989        align = 3;
1990 #endif
1991
1992        record_alignment(bss_seg, align);
1993      }
1994
1995   if (needs_align)
1996     {
1997       align = 0;
1998       SKIP_WHITESPACE ();
1999       if (*input_line_pointer != ',')
2000         {
2001           as_bad (_("Expected comma after size"));
2002           ignore_rest_of_line ();
2003           return;
2004         }
2005       input_line_pointer++;
2006       SKIP_WHITESPACE ();
2007       if (*input_line_pointer == '\n')
2008         {
2009           as_bad (_("Missing alignment"));
2010           return;
2011         }
2012       align = get_absolute_expression ();
2013       if (bytes_p)
2014         {
2015           /* Convert to a power of 2.  */
2016           if (align != 0)
2017             {
2018               unsigned int i;
2019
2020               for (i = 0; (align & 1) == 0; align >>= 1, ++i)
2021                 ;
2022               if (align != 1)
2023                 as_bad (_("Alignment not a power of 2"));
2024               align = i;
2025             }
2026         }
2027       if (align > max_alignment)
2028         {
2029           align = max_alignment;
2030           as_warn (_("Alignment too large: %d. assumed."), align);
2031         }
2032       else if (align < 0)
2033         {
2034           align = 0;
2035           as_warn (_("Alignment negative. 0 assumed."));
2036         }
2037       record_alignment (bss_seg, align);
2038     }                           /* if needs align */
2039   else
2040     {
2041       /* Assume some objects may require alignment on some systems.  */
2042 #if defined (TC_ALPHA) && ! defined (VMS)
2043       if (temp > 1)
2044         {
2045           align = ffs (temp) - 1;
2046           if (temp % (1 << align))
2047             abort ();
2048         }
2049 #endif
2050     }
2051
2052   *p = 0;
2053   symbolP = symbol_find_or_make (name);
2054   *p = c;
2055
2056   if (
2057 #if defined(OBJ_AOUT) | defined(OBJ_BOUT)
2058        S_GET_OTHER (symbolP) == 0 &&
2059        S_GET_DESC (symbolP) == 0 &&
2060 #endif /* OBJ_AOUT or OBJ_BOUT */
2061        (S_GET_SEGMENT (symbolP) == bss_seg
2062         || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0)))
2063     {
2064       char *pfrag;
2065
2066       subseg_set (bss_seg, 1);
2067
2068       if (align)
2069         frag_align (align, 0, 0);
2070                                         /* detach from old frag */
2071       if (S_GET_SEGMENT (symbolP) == bss_seg)
2072         symbol_get_frag (symbolP)->fr_symbol = NULL;
2073
2074       symbol_set_frag (symbolP, frag_now);
2075       pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP,
2076                         (offsetT) temp, (char *) 0);
2077       *pfrag = 0;
2078
2079       S_SET_SEGMENT (symbolP, bss_seg);
2080
2081 #ifdef OBJ_COFF
2082       /* The symbol may already have been created with a preceding
2083          ".globl" directive -- be careful not to step on storage class
2084          in that case.  Otherwise, set it to static. */
2085       if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2086         {
2087           S_SET_STORAGE_CLASS (symbolP, C_STAT);
2088         }
2089 #endif /* OBJ_COFF */
2090
2091 #ifdef S_SET_SIZE
2092       S_SET_SIZE (symbolP, temp);
2093 #endif
2094     }
2095   else
2096     as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2097             S_GET_NAME (symbolP));
2098
2099   subseg_set (current_seg, current_subseg);
2100
2101   demand_empty_rest_of_line ();
2102 }                               /* s_lcomm_internal() */
2103
2104 void
2105 s_lcomm (needs_align)
2106      int needs_align;
2107 {
2108   s_lcomm_internal (needs_align, 0);
2109 }
2110
2111 void s_lcomm_bytes (needs_align)
2112      int needs_align;
2113 {
2114   s_lcomm_internal (needs_align, 1);
2115 }
2116
2117 void 
2118 s_lsym (ignore)
2119      int ignore;
2120 {
2121   register char *name;
2122   register char c;
2123   register char *p;
2124   expressionS exp;
2125   register symbolS *symbolP;
2126
2127   /* we permit ANY defined expression: BSD4.2 demands constants */
2128   name = input_line_pointer;
2129   c = get_symbol_end ();
2130   p = input_line_pointer;
2131   *p = c;
2132   SKIP_WHITESPACE ();
2133   if (*input_line_pointer != ',')
2134     {
2135       *p = 0;
2136       as_bad (_("Expected comma after name \"%s\""), name);
2137       *p = c;
2138       ignore_rest_of_line ();
2139       return;
2140     }
2141   input_line_pointer++;
2142   expression (&exp);
2143   if (exp.X_op != O_constant
2144       && exp.X_op != O_register)
2145     {
2146       as_bad (_("bad expression"));
2147       ignore_rest_of_line ();
2148       return;
2149     }
2150   *p = 0;
2151   symbolP = symbol_find_or_make (name);
2152
2153   /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 &&
2154      symbolP->sy_desc == 0) out of this test because coff doesn't have
2155      those fields, and I can't see when they'd ever be tripped.  I
2156      don't think I understand why they were here so I may have
2157      introduced a bug. As recently as 1.37 didn't have this test
2158      anyway.  xoxorich. */
2159
2160   if (S_GET_SEGMENT (symbolP) == undefined_section
2161       && S_GET_VALUE (symbolP) == 0)
2162     {
2163       /* The name might be an undefined .global symbol; be sure to
2164          keep the "external" bit. */
2165       S_SET_SEGMENT (symbolP,
2166                      (exp.X_op == O_constant
2167                       ? absolute_section
2168                       : reg_section));
2169       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2170     }
2171   else
2172     {
2173       as_bad (_("Symbol %s already defined"), name);
2174     }
2175   *p = c;
2176   demand_empty_rest_of_line ();
2177 }                               /* s_lsym() */
2178
2179 /* Read a line into an sb.  */
2180
2181 static int
2182 get_line_sb (line)
2183      sb *line;
2184 {
2185   char quote1, quote2, inquote;
2186
2187   if (input_line_pointer[-1] == '\n')
2188     bump_line_counters ();
2189
2190   if (input_line_pointer >= buffer_limit)
2191     {
2192       buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2193       if (buffer_limit == 0)
2194         return 0;
2195     }
2196
2197   /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this
2198      code needs to be changed.  */
2199   if (! flag_m68k_mri)
2200     quote1 = '"';
2201   else
2202     quote1 = '\0';
2203
2204   quote2 = '\0';
2205   if (flag_m68k_mri)
2206     quote2 = '\'';
2207 #ifdef LEX_IS_STRINGQUOTE
2208   quote2 = '\'';
2209 #endif
2210
2211   inquote = '\0';
2212   while (! is_end_of_line[(unsigned char) *input_line_pointer]
2213          || (inquote != '\0' && *input_line_pointer != '\n'))
2214     {
2215       if (inquote == *input_line_pointer)
2216         inquote = '\0';
2217       else if (inquote == '\0')
2218         {
2219           if (*input_line_pointer == quote1)
2220             inquote = quote1;
2221           else if (*input_line_pointer == quote2)
2222             inquote = quote2;
2223         }
2224       sb_add_char (line, *input_line_pointer++);
2225     }
2226   while (input_line_pointer < buffer_limit
2227          && is_end_of_line[(unsigned char) *input_line_pointer])
2228     {
2229       if (input_line_pointer[-1] == '\n')
2230         bump_line_counters ();
2231       ++input_line_pointer;
2232     }
2233   return 1;
2234 }
2235
2236 /* Define a macro.  This is an interface to macro.c, which is shared
2237    between gas and gasp.  */
2238
2239 void
2240 s_macro (ignore)
2241      int ignore;
2242 {
2243   char *file;
2244   unsigned int line;
2245   sb s;
2246   sb label;
2247   const char *err;
2248   const char *name;
2249
2250   as_where (&file, &line);
2251
2252   sb_new (&s);
2253   while (! is_end_of_line[(unsigned char) *input_line_pointer])
2254     sb_add_char (&s, *input_line_pointer++);
2255
2256   sb_new (&label);
2257   if (line_label != NULL)
2258     sb_add_string (&label, S_GET_NAME (line_label));
2259
2260   err = define_macro (0, &s, &label, get_line_sb, &name);
2261   if (err != NULL)
2262     as_bad_where (file, line, "%s", err);
2263   else
2264     {
2265       if (line_label != NULL)
2266         {
2267           S_SET_SEGMENT (line_label, undefined_section);
2268           S_SET_VALUE (line_label, 0);
2269           symbol_set_frag (line_label, &zero_address_frag);
2270         }
2271
2272       if (((flag_m68k_mri
2273 #ifdef NO_PSEUDO_DOT
2274             || 1
2275 #endif
2276             )
2277            && hash_find (po_hash, name) != NULL)
2278           || (! flag_m68k_mri
2279               && *name == '.'
2280               && hash_find (po_hash, name + 1) != NULL))
2281         as_warn (_("attempt to redefine pseudo-op `%s' ignored"),
2282                  name);
2283     }
2284
2285   sb_kill (&s);
2286 }
2287
2288 /* Handle the .mexit pseudo-op, which immediately exits a macro
2289    expansion.  */
2290
2291 void
2292 s_mexit (ignore)
2293      int ignore;
2294 {
2295   cond_exit_macro (macro_nest);
2296   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2297 }
2298
2299 /* Switch in and out of MRI mode.  */
2300
2301 void
2302 s_mri (ignore)
2303      int ignore;
2304 {
2305   int on, old_flag;
2306
2307   on = get_absolute_expression ();
2308   old_flag = flag_mri;
2309   if (on != 0)
2310     {
2311       flag_mri = 1;
2312 #ifdef TC_M68K
2313       flag_m68k_mri = 1;
2314 #endif
2315       macro_mri_mode (1);
2316     }
2317   else
2318     {
2319       flag_mri = 0;
2320       flag_m68k_mri = 0;
2321       macro_mri_mode (0);
2322     }
2323
2324   /* Operator precedence changes in m68k MRI mode, so we need to
2325      update the operator rankings.  */
2326   expr_set_precedence ();
2327
2328 #ifdef MRI_MODE_CHANGE
2329   if (on != old_flag)
2330     MRI_MODE_CHANGE (on);
2331 #endif
2332
2333   demand_empty_rest_of_line ();
2334 }
2335
2336 /* Handle changing the location counter.  */
2337
2338 static void
2339 do_org (segment, exp, fill)
2340      segT segment;
2341      expressionS *exp;
2342      int fill;
2343 {
2344   if (segment != now_seg && segment != absolute_section)
2345     as_bad (_("invalid segment \"%s\"; segment \"%s\" assumed"),
2346             segment_name (segment), segment_name (now_seg));
2347
2348   if (now_seg == absolute_section)
2349     {
2350       if (fill != 0)
2351         as_warn (_("ignoring fill value in absolute section"));
2352       if (exp->X_op != O_constant)
2353         {
2354           as_bad (_("only constant offsets supported in absolute section"));
2355           exp->X_add_number = 0;
2356         }
2357       abs_section_offset = exp->X_add_number;
2358     }
2359   else
2360     {
2361       char *p;
2362
2363       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol,
2364                     exp->X_add_number, (char *) NULL);
2365       *p = fill;
2366     }
2367 }
2368
2369 void 
2370 s_org (ignore)
2371      int ignore;
2372 {
2373   register segT segment;
2374   expressionS exp;
2375   register long temp_fill;
2376
2377 #ifdef md_flush_pending_output
2378   md_flush_pending_output ();
2379 #endif
2380
2381   /* The m68k MRI assembler has a different meaning for .org.  It
2382      means to create an absolute section at a given address.  We can't
2383      support that--use a linker script instead.  */
2384   if (flag_m68k_mri)
2385     {
2386       as_bad (_("MRI style ORG pseudo-op not supported"));
2387       ignore_rest_of_line ();
2388       return;
2389     }
2390
2391   /* Don't believe the documentation of BSD 4.2 AS.  There is no such
2392      thing as a sub-segment-relative origin.  Any absolute origin is
2393      given a warning, then assumed to be segment-relative.  Any
2394      segmented origin expression ("foo+42") had better be in the right
2395      segment or the .org is ignored.
2396
2397      BSD 4.2 AS warns if you try to .org backwards. We cannot because
2398      we never know sub-segment sizes when we are reading code.  BSD
2399      will crash trying to emit negative numbers of filler bytes in
2400      certain .orgs. We don't crash, but see as-write for that code.
2401
2402      Don't make frag if need_pass_2==1.  */
2403   segment = get_known_segmented_expression (&exp);
2404   if (*input_line_pointer == ',')
2405     {
2406       input_line_pointer++;
2407       temp_fill = get_absolute_expression ();
2408     }
2409   else
2410     temp_fill = 0;
2411
2412   if (!need_pass_2)
2413     do_org (segment, &exp, temp_fill);
2414
2415   demand_empty_rest_of_line ();
2416 }                               /* s_org() */
2417
2418 /* Handle parsing for the MRI SECT/SECTION pseudo-op.  This should be
2419    called by the obj-format routine which handles section changing
2420    when in MRI mode.  It will create a new section, and return it.  It
2421    will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2422    'M' (mixed), or 'R' (romable).  If BFD_ASSEMBLER is defined, the
2423    flags will be set in the section.  */
2424
2425 void
2426 s_mri_sect (type)
2427      char *type;
2428 {
2429 #ifdef TC_M68K
2430
2431   char *name;
2432   char c;
2433   segT seg;
2434
2435   SKIP_WHITESPACE ();
2436   
2437   name = input_line_pointer;
2438   if (! isdigit ((unsigned char) *name))
2439     c = get_symbol_end ();
2440   else
2441     {
2442       do
2443         {
2444           ++input_line_pointer;
2445         }
2446       while (isdigit ((unsigned char) *input_line_pointer));
2447       c = *input_line_pointer;
2448       *input_line_pointer = '\0';
2449     }
2450
2451   name = xstrdup (name);
2452
2453   *input_line_pointer = c;
2454
2455   seg = subseg_new (name, 0);
2456
2457   if (*input_line_pointer == ',')
2458     {
2459       int align;
2460
2461       ++input_line_pointer;
2462       align = get_absolute_expression ();
2463       record_alignment (seg, align);
2464     }
2465
2466   *type = 'C';
2467   if (*input_line_pointer == ',')
2468     {
2469       c = *++input_line_pointer;
2470       c = toupper ((unsigned char) c);
2471       if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2472         *type = c;
2473       else
2474         as_bad (_("unrecognized section type"));
2475       ++input_line_pointer;
2476
2477 #ifdef BFD_ASSEMBLER
2478       {
2479         flagword flags;
2480
2481         flags = SEC_NO_FLAGS;
2482         if (*type == 'C')
2483           flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2484         else if (*type == 'D' || *type == 'M')
2485           flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2486         else if (*type == 'R')
2487           flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2488         if (flags != SEC_NO_FLAGS)
2489           {
2490             if (! bfd_set_section_flags (stdoutput, seg, flags))
2491               as_warn (_("error setting flags for \"%s\": %s"),
2492                        bfd_section_name (stdoutput, seg),
2493                        bfd_errmsg (bfd_get_error ()));
2494           }
2495       }
2496 #endif
2497     }
2498
2499   /* Ignore the HP type.  */
2500   if (*input_line_pointer == ',')
2501     input_line_pointer += 2;
2502
2503   demand_empty_rest_of_line ();
2504
2505 #else /* ! TC_M68K */
2506 #ifdef TC_I960
2507
2508   char *name;
2509   char c;
2510   segT seg;
2511
2512   SKIP_WHITESPACE ();
2513
2514   name = input_line_pointer;
2515   c = get_symbol_end ();
2516
2517   name = xstrdup (name);
2518
2519   *input_line_pointer = c;
2520
2521   seg = subseg_new (name, 0);
2522
2523   if (*input_line_pointer != ',')
2524     *type = 'C';
2525   else
2526     {
2527       char *sectype;
2528
2529       ++input_line_pointer;
2530       SKIP_WHITESPACE ();
2531       sectype = input_line_pointer;
2532       c = get_symbol_end ();
2533       if (*sectype == '\0')
2534         *type = 'C';
2535       else if (strcasecmp (sectype, "text") == 0)
2536         *type = 'C';
2537       else if (strcasecmp (sectype, "data") == 0)
2538         *type = 'D';
2539       else if (strcasecmp (sectype, "romdata") == 0)
2540         *type = 'R';
2541       else
2542         as_warn (_("unrecognized section type `%s'"), sectype);
2543       *input_line_pointer = c;
2544     }
2545
2546   if (*input_line_pointer == ',')
2547     {
2548       char *seccmd;
2549
2550       ++input_line_pointer;
2551       SKIP_WHITESPACE ();
2552       seccmd = input_line_pointer;
2553       c = get_symbol_end ();
2554       if (strcasecmp (seccmd, "absolute") == 0)
2555         {
2556           as_bad (_("absolute sections are not supported"));
2557           *input_line_pointer = c;
2558           ignore_rest_of_line ();
2559           return;
2560         }
2561       else if (strcasecmp (seccmd, "align") == 0)
2562         {
2563           int align;
2564
2565           *input_line_pointer = c;
2566           align = get_absolute_expression ();
2567           record_alignment (seg, align);
2568         }
2569       else
2570         {
2571           as_warn (_("unrecognized section command `%s'"), seccmd);
2572           *input_line_pointer = c;
2573         }
2574     }
2575
2576   demand_empty_rest_of_line ();   
2577
2578 #else /* ! TC_I960 */
2579   /* The MRI assembler seems to use different forms of .sect for
2580      different targets.  */
2581   as_bad ("MRI mode not supported for this target");
2582   ignore_rest_of_line ();
2583 #endif /* ! TC_I960 */
2584 #endif /* ! TC_M68K */
2585 }
2586
2587 /* Handle the .print pseudo-op.  */
2588
2589 void
2590 s_print (ignore)
2591      int ignore;
2592 {
2593   char *s;
2594   int len;
2595
2596   s = demand_copy_C_string (&len);
2597   printf ("%s\n", s);
2598   demand_empty_rest_of_line ();
2599 }
2600
2601 /* Handle the .purgem pseudo-op.  */
2602
2603 void
2604 s_purgem (ignore)
2605      int ignore;
2606 {
2607   if (is_it_end_of_statement ())
2608     {
2609       demand_empty_rest_of_line ();
2610       return;
2611     }
2612
2613   do
2614     {
2615       char *name;
2616       char c;
2617
2618       SKIP_WHITESPACE ();
2619       name = input_line_pointer;
2620       c = get_symbol_end ();
2621       delete_macro (name);
2622       *input_line_pointer = c;
2623       SKIP_WHITESPACE ();
2624     }
2625   while (*input_line_pointer++ == ',');
2626
2627   --input_line_pointer;
2628   demand_empty_rest_of_line ();
2629 }
2630
2631 /* Handle the .rept pseudo-op.  */
2632
2633 void
2634 s_rept (ignore)
2635      int ignore;
2636 {
2637   int count;
2638   sb one;
2639   sb many;
2640
2641   count = get_absolute_expression ();
2642
2643   sb_new (&one);
2644   if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb))
2645     {
2646       as_bad (_("rept without endr"));
2647       return;
2648     }
2649
2650   sb_new (&many);
2651   while (count-- > 0)
2652     sb_add_sb (&many, &one);
2653
2654   sb_kill (&one);
2655
2656   input_scrub_include_sb (&many, input_line_pointer);
2657   sb_kill (&many);
2658   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2659 }
2660
2661 /* Handle the .equ, .equiv and .set directives.  If EQUIV is 1, then
2662    this is .equiv, and it is an error if the symbol is already
2663    defined.  */
2664
2665 void 
2666 s_set (equiv)
2667      int equiv;
2668 {
2669   register char *name;
2670   register char delim;
2671   register char *end_name;
2672   register symbolS *symbolP;
2673
2674   /*
2675    * Especial apologies for the random logic:
2676    * this just grew, and could be parsed much more simply!
2677    * Dean in haste.
2678    */
2679   name = input_line_pointer;
2680   delim = get_symbol_end ();
2681   end_name = input_line_pointer;
2682   *end_name = delim;
2683   SKIP_WHITESPACE ();
2684
2685   if (*input_line_pointer != ',')
2686     {
2687       *end_name = 0;
2688       as_bad (_("Expected comma after name \"%s\""), name);
2689       *end_name = delim;
2690       ignore_rest_of_line ();
2691       return;
2692     }
2693
2694   input_line_pointer++;
2695   *end_name = 0;
2696
2697   if (name[0] == '.' && name[1] == '\0')
2698     {
2699       /* Turn '. = mumble' into a .org mumble */
2700       register segT segment;
2701       expressionS exp;
2702
2703       segment = get_known_segmented_expression (&exp);
2704
2705       if (!need_pass_2)
2706         do_org (segment, &exp, 0);
2707
2708       *end_name = delim;
2709       return;
2710     }
2711
2712   if ((symbolP = symbol_find (name)) == NULL
2713       && (symbolP = md_undefined_symbol (name)) == NULL)
2714     {
2715 #ifndef NO_LISTING
2716       /* When doing symbol listings, play games with dummy fragments living
2717          outside the normal fragment chain to record the file and line info
2718          for this symbol.  */
2719       if (listing & LISTING_SYMBOLS)
2720         {
2721           extern struct list_info_struct *listing_tail;
2722           fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS));
2723           memset (dummy_frag, 0, sizeof(fragS));
2724           dummy_frag->fr_type = rs_fill;
2725           dummy_frag->line = listing_tail;
2726           symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2727           dummy_frag->fr_symbol = symbolP;
2728         }
2729       else
2730 #endif
2731         symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2732                             
2733 #ifdef OBJ_COFF
2734       /* "set" symbols are local unless otherwise specified. */
2735       SF_SET_LOCAL (symbolP);
2736 #endif /* OBJ_COFF */
2737
2738     }                           /* make a new symbol */
2739
2740   symbol_table_insert (symbolP);
2741
2742   *end_name = delim;
2743
2744   if (equiv
2745       && S_IS_DEFINED (symbolP)
2746       && S_GET_SEGMENT (symbolP) != reg_section)
2747     as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2748
2749   pseudo_set (symbolP);
2750   demand_empty_rest_of_line ();
2751 }                               /* s_set() */
2752
2753 void 
2754 s_space (mult)
2755      int mult;
2756 {
2757   expressionS exp;
2758   expressionS val;
2759   char *p = 0;
2760   char *stop = NULL;
2761   char stopc;
2762   int bytes;
2763
2764 #ifdef md_flush_pending_output
2765   md_flush_pending_output ();
2766 #endif
2767
2768   if (flag_mri)
2769     stop = mri_comment_field (&stopc);
2770
2771   /* In m68k MRI mode, we need to align to a word boundary, unless
2772      this is ds.b.  */
2773   if (flag_m68k_mri && mult > 1)
2774     {
2775       if (now_seg == absolute_section)
2776         {
2777           abs_section_offset += abs_section_offset & 1;
2778           if (line_label != NULL)
2779             S_SET_VALUE (line_label, abs_section_offset);
2780         }
2781       else if (mri_common_symbol != NULL)
2782         {
2783           valueT val;
2784
2785           val = S_GET_VALUE (mri_common_symbol);
2786           if ((val & 1) != 0)
2787             {
2788               S_SET_VALUE (mri_common_symbol, val + 1);
2789               if (line_label != NULL)
2790                 {
2791                   expressionS *symexp;
2792
2793                   symexp = symbol_get_value_expression (line_label);
2794                   know (symexp->X_op == O_symbol);
2795                   know (symexp->X_add_symbol == mri_common_symbol);
2796                   symexp->X_add_number += 1;
2797                 }
2798             }
2799         }
2800       else
2801         {
2802           do_align (1, (char *) NULL, 0, 0);
2803           if (line_label != NULL)
2804             {
2805               symbol_set_frag (line_label, frag_now);
2806               S_SET_VALUE (line_label, frag_now_fix ());
2807             }
2808         }
2809     }
2810
2811   bytes = mult;
2812
2813   expression (&exp);
2814
2815   SKIP_WHITESPACE ();
2816   if (*input_line_pointer == ',')
2817     {
2818       ++input_line_pointer;
2819       expression (&val);
2820     }
2821   else
2822     {
2823       val.X_op = O_constant;
2824       val.X_add_number = 0;
2825     }
2826
2827   if (val.X_op != O_constant
2828       || val.X_add_number < - 0x80
2829       || val.X_add_number > 0xff
2830       || (mult != 0 && mult != 1 && val.X_add_number != 0))
2831     {
2832       if (exp.X_op != O_constant)
2833         as_bad (_("Unsupported variable size or fill value"));
2834       else
2835         {
2836           offsetT i;
2837
2838           if (mult == 0)
2839             mult = 1;
2840           bytes = mult * exp.X_add_number;
2841           for (i = 0; i < exp.X_add_number; i++)
2842             emit_expr (&val, mult);
2843         }
2844     }
2845   else
2846     {
2847       if (exp.X_op == O_constant)
2848         {
2849           long repeat;
2850
2851           repeat = exp.X_add_number;
2852           if (mult)
2853             repeat *= mult;
2854           bytes = repeat;
2855           if (repeat <= 0)
2856             {
2857               if (! flag_mri)
2858                 as_warn (_(".space repeat count is zero, ignored"));
2859               else if (repeat < 0)
2860                 as_warn (_(".space repeat count is negative, ignored"));
2861               goto getout;
2862             }
2863
2864           /* If we are in the absolute section, just bump the offset.  */
2865           if (now_seg == absolute_section)
2866             {
2867               abs_section_offset += repeat;
2868               goto getout;
2869             }
2870
2871           /* If we are secretly in an MRI common section, then
2872              creating space just increases the size of the common
2873              symbol.  */
2874           if (mri_common_symbol != NULL)
2875             {
2876               S_SET_VALUE (mri_common_symbol,
2877                            S_GET_VALUE (mri_common_symbol) + repeat);
2878               goto getout;
2879             }
2880
2881           if (!need_pass_2)
2882             p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
2883                           (offsetT) repeat, (char *) 0);
2884         }
2885       else
2886         {
2887           if (now_seg == absolute_section)
2888             {
2889               as_bad (_("space allocation too complex in absolute section"));
2890               subseg_set (text_section, 0);
2891             }
2892           if (mri_common_symbol != NULL)
2893             {
2894               as_bad (_("space allocation too complex in common section"));
2895               mri_common_symbol = NULL;
2896             }
2897           if (!need_pass_2)
2898             p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
2899                           make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
2900         }
2901
2902       if (p)
2903         *p = val.X_add_number;
2904     }
2905
2906  getout:
2907
2908   /* In MRI mode, after an odd number of bytes, we must align to an
2909      even word boundary, unless the next instruction is a dc.b, ds.b
2910      or dcb.b.  */
2911   if (flag_mri && (bytes & 1) != 0)
2912     mri_pending_align = 1;
2913
2914   demand_empty_rest_of_line ();
2915
2916   if (flag_mri)
2917     mri_comment_end (stop, stopc);
2918 }
2919
2920 /* This is like s_space, but the value is a floating point number with
2921    the given precision.  This is for the MRI dcb.s pseudo-op and
2922    friends.  */
2923
2924 void
2925 s_float_space (float_type)
2926      int float_type;
2927 {
2928   offsetT count;
2929   int flen;
2930   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
2931   char *stop = NULL;
2932   char stopc;
2933
2934   if (flag_mri)
2935     stop = mri_comment_field (&stopc);
2936
2937   count = get_absolute_expression ();
2938
2939   SKIP_WHITESPACE ();
2940   if (*input_line_pointer != ',')
2941     {
2942       as_bad (_("missing value"));
2943       ignore_rest_of_line ();
2944       if (flag_mri)
2945         mri_comment_end (stop, stopc);
2946       return;
2947     }
2948
2949   ++input_line_pointer;
2950
2951   SKIP_WHITESPACE ();
2952
2953   /* Skip any 0{letter} that may be present.  Don't even check if the
2954    * letter is legal.  */
2955   if (input_line_pointer[0] == '0'
2956       && isalpha ((unsigned char) input_line_pointer[1]))
2957     input_line_pointer += 2;
2958
2959   /* Accept :xxxx, where the x's are hex digits, for a floating point
2960      with the exact digits specified.  */
2961   if (input_line_pointer[0] == ':')
2962     {
2963       flen = hex_float (float_type, temp);
2964       if (flen < 0)
2965         {
2966           ignore_rest_of_line ();
2967           if (flag_mri)
2968             mri_comment_end (stop, stopc);
2969           return;
2970         }
2971     }
2972   else
2973     {
2974       char *err;
2975
2976       err = md_atof (float_type, temp, &flen);
2977       know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
2978       know (flen > 0);
2979       if (err)
2980         {
2981           as_bad (_("Bad floating literal: %s"), err);
2982           ignore_rest_of_line ();
2983           if (flag_mri)
2984             mri_comment_end (stop, stopc);
2985           return;
2986         }
2987     }
2988
2989   while (--count >= 0)
2990     {
2991       char *p;
2992
2993       p = frag_more (flen);
2994       memcpy (p, temp, (unsigned int) flen);
2995     }
2996
2997   demand_empty_rest_of_line ();
2998
2999   if (flag_mri)
3000     mri_comment_end (stop, stopc);
3001 }
3002
3003 /* Handle the .struct pseudo-op, as found in MIPS assemblers.  */
3004
3005 void
3006 s_struct (ignore)
3007      int ignore;
3008 {
3009   char *stop = NULL;
3010   char stopc;
3011
3012   if (flag_mri)
3013     stop = mri_comment_field (&stopc);
3014   abs_section_offset = get_absolute_expression ();
3015   subseg_set (absolute_section, 0);
3016   demand_empty_rest_of_line ();
3017   if (flag_mri)
3018     mri_comment_end (stop, stopc);
3019 }
3020
3021 void
3022 s_text (ignore)
3023      int ignore;
3024 {
3025   register int temp;
3026
3027   temp = get_absolute_expression ();
3028   subseg_set (text_section, (subsegT) temp);
3029   demand_empty_rest_of_line ();
3030 #ifdef OBJ_VMS
3031   const_flag &= ~IN_DEFAULT_SECTION;
3032 #endif
3033 }                               /* s_text() */
3034 \f
3035
3036 void 
3037 demand_empty_rest_of_line ()
3038 {
3039   SKIP_WHITESPACE ();
3040   if (is_end_of_line[(unsigned char) *input_line_pointer])
3041     {
3042       input_line_pointer++;
3043     }
3044   else
3045     {
3046       ignore_rest_of_line ();
3047     }
3048   /* Return having already swallowed end-of-line. */
3049 }                               /* Return pointing just after end-of-line. */
3050
3051 void
3052 ignore_rest_of_line ()          /* For suspect lines: gives warning. */
3053 {
3054   if (!is_end_of_line[(unsigned char) *input_line_pointer])
3055     {
3056       if (isprint ((unsigned char) *input_line_pointer))
3057         as_bad (_("Rest of line ignored. First ignored character is `%c'."),
3058                 *input_line_pointer);
3059       else
3060         as_bad (_("Rest of line ignored. First ignored character valued 0x%x."),
3061                 *input_line_pointer);
3062       while (input_line_pointer < buffer_limit
3063              && !is_end_of_line[(unsigned char) *input_line_pointer])
3064         {
3065           input_line_pointer++;
3066         }
3067     }
3068   input_line_pointer++;         /* Return pointing just after end-of-line. */
3069   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3070 }
3071
3072 void
3073 discard_rest_of_line ()
3074 {
3075   while (input_line_pointer < buffer_limit
3076          && !is_end_of_line[(unsigned char) *input_line_pointer])
3077     {
3078       input_line_pointer++;
3079     }
3080   input_line_pointer++;         /* Return pointing just after end-of-line. */
3081   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3082 }
3083
3084 /*
3085  *                      pseudo_set()
3086  *
3087  * In:  Pointer to a symbol.
3088  *      Input_line_pointer->expression.
3089  *
3090  * Out: Input_line_pointer->just after any whitespace after expression.
3091  *      Tried to set symbol to value of expression.
3092  *      Will change symbols type, value, and frag;
3093  */
3094 void
3095 pseudo_set (symbolP)
3096      symbolS *symbolP;
3097 {
3098   expressionS exp;
3099 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3100   int ext;
3101 #endif /* OBJ_AOUT or OBJ_BOUT */
3102
3103   know (symbolP);               /* NULL pointer is logic error. */
3104 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3105   ext = S_IS_EXTERNAL (symbolP);
3106 #endif /* OBJ_AOUT or OBJ_BOUT */
3107
3108   (void) expression (&exp);
3109
3110   if (exp.X_op == O_illegal)
3111     as_bad (_("illegal expression; zero assumed"));
3112   else if (exp.X_op == O_absent)
3113     as_bad (_("missing expression; zero assumed"));
3114   else if (exp.X_op == O_big)
3115     {
3116       if (exp.X_add_number > 0)
3117         as_bad (_("bignum invalid; zero assumed"));
3118       else
3119         as_bad (_("floating point number invalid; zero assumed"));
3120     }
3121   else if (exp.X_op == O_subtract
3122            && (S_GET_SEGMENT (exp.X_add_symbol)
3123                == S_GET_SEGMENT (exp.X_op_symbol))
3124            && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3125            && (symbol_get_frag (exp.X_add_symbol)
3126                == symbol_get_frag (exp.X_op_symbol)))
3127     {
3128       exp.X_op = O_constant;
3129       exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3130                           - S_GET_VALUE (exp.X_op_symbol));
3131     }
3132
3133   switch (exp.X_op)
3134     {
3135     case O_illegal:
3136     case O_absent:
3137     case O_big:
3138       exp.X_add_number = 0;
3139       /* Fall through.  */
3140     case O_constant:
3141       S_SET_SEGMENT (symbolP, absolute_section);
3142 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3143       if (ext)
3144         S_SET_EXTERNAL (symbolP);
3145       else
3146         S_CLEAR_EXTERNAL (symbolP);
3147 #endif /* OBJ_AOUT or OBJ_BOUT */
3148       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3149       if (exp.X_op != O_constant)
3150         symbol_set_frag (symbolP, &zero_address_frag);
3151       break;
3152
3153     case O_register:
3154       S_SET_SEGMENT (symbolP, reg_section);
3155       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3156       symbol_set_frag (symbolP, &zero_address_frag);
3157       break;
3158
3159     case O_symbol:
3160       if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section
3161           || exp.X_add_number != 0)
3162         symbol_set_value_expression (symbolP, &exp);
3163       else
3164         {
3165           symbolS *s = exp.X_add_symbol;
3166
3167           S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s));
3168 #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER)
3169           if (ext)
3170             S_SET_EXTERNAL (symbolP);
3171           else
3172             S_CLEAR_EXTERNAL (symbolP);
3173 #endif /* OBJ_AOUT or OBJ_BOUT */
3174           S_SET_VALUE (symbolP,
3175                        exp.X_add_number + S_GET_VALUE (s));
3176           symbol_set_frag (symbolP, symbol_get_frag (s));
3177           copy_symbol_attributes (symbolP, s);
3178         }
3179       break;
3180
3181     default:
3182       /* The value is some complex expression.
3183          FIXME: Should we set the segment to anything?  */
3184       symbol_set_value_expression (symbolP, &exp);
3185       break;
3186     }
3187 }
3188 \f
3189 /*
3190  *                      cons()
3191  *
3192  * CONStruct more frag of .bytes, or .words etc.
3193  * Should need_pass_2 be 1 then emit no frag(s).
3194  * This understands EXPRESSIONS.
3195  *
3196  * Bug (?)
3197  *
3198  * This has a split personality. We use expression() to read the
3199  * value. We can detect if the value won't fit in a byte or word.
3200  * But we can't detect if expression() discarded significant digits
3201  * in the case of a long. Not worth the crocks required to fix it.
3202  */
3203
3204 /* Select a parser for cons expressions.  */
3205
3206 /* Some targets need to parse the expression in various fancy ways.
3207    You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3208    (for example, the HPPA does this).  Otherwise, you can define
3209    BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3210    REPEAT_CONS_EXPRESSIONS to permit repeat counts.  If none of these
3211    are defined, which is the normal case, then only simple expressions
3212    are permitted.  */
3213
3214 static void
3215 parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3216
3217 #ifndef TC_PARSE_CONS_EXPRESSION
3218 #ifdef BITFIELD_CONS_EXPRESSIONS
3219 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3220 static void 
3221 parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3222 #endif
3223 #ifdef REPEAT_CONS_EXPRESSIONS
3224 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3225 static void
3226 parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes));
3227 #endif
3228
3229 /* If we haven't gotten one yet, just call expression.  */
3230 #ifndef TC_PARSE_CONS_EXPRESSION
3231 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3232 #endif
3233 #endif
3234
3235 /* worker to do .byte etc statements */
3236 /* clobbers input_line_pointer, checks */
3237 /* end-of-line. */
3238 static void 
3239 cons_worker (nbytes, rva)
3240      register int nbytes;       /* 1=.byte, 2=.word, 4=.long */
3241      int rva;
3242 {
3243   int c;
3244   expressionS exp;
3245   char *stop = NULL;
3246   char stopc;
3247
3248 #ifdef md_flush_pending_output
3249   md_flush_pending_output ();
3250 #endif
3251
3252   if (flag_mri)
3253     stop = mri_comment_field (&stopc);
3254
3255   if (is_it_end_of_statement ())
3256     {
3257       demand_empty_rest_of_line ();
3258       if (flag_mri)
3259         mri_comment_end (stop, stopc);
3260       return;
3261     }
3262
3263 #ifdef md_cons_align
3264   md_cons_align (nbytes);
3265 #endif
3266
3267   c = 0;
3268   do
3269     {
3270       if (flag_m68k_mri)
3271         parse_mri_cons (&exp, (unsigned int) nbytes);
3272       else
3273         TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
3274
3275       if (rva)
3276         {
3277           if (exp.X_op == O_symbol)
3278             exp.X_op = O_symbol_rva;
3279           else
3280             as_fatal (_("rva without symbol"));
3281         }
3282       emit_expr (&exp, (unsigned int) nbytes);
3283       ++c;
3284     }
3285   while (*input_line_pointer++ == ',');
3286
3287   /* In MRI mode, after an odd number of bytes, we must align to an
3288      even word boundary, unless the next instruction is a dc.b, ds.b
3289      or dcb.b.  */
3290   if (flag_mri && nbytes == 1 && (c & 1) != 0)
3291     mri_pending_align = 1;
3292
3293   input_line_pointer--;         /* Put terminator back into stream. */
3294
3295   demand_empty_rest_of_line ();
3296
3297   if (flag_mri)
3298     mri_comment_end (stop, stopc);
3299 }
3300
3301
3302 void
3303 cons (size)
3304      int size;
3305 {
3306   cons_worker (size, 0);
3307 }
3308
3309 void 
3310 s_rva (size)
3311      int size;
3312 {
3313   cons_worker (size, 1);
3314 }
3315
3316 /* Put the contents of expression EXP into the object file using
3317    NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
3318
3319 void
3320 emit_expr (exp, nbytes)
3321      expressionS *exp;
3322      unsigned int nbytes;
3323 {
3324   operatorT op;
3325   register char *p;
3326   valueT extra_digit = 0;
3327
3328   /* Don't do anything if we are going to make another pass.  */
3329   if (need_pass_2)
3330     return;
3331
3332 #ifndef NO_LISTING
3333 #ifdef OBJ_ELF
3334   /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
3335      appear as a four byte positive constant in the .line section,
3336      followed by a 2 byte 0xffff.  Look for that case here.  */
3337   {
3338     static int dwarf_line = -1;
3339
3340     if (strcmp (segment_name (now_seg), ".line") != 0)
3341       dwarf_line = -1;
3342     else if (dwarf_line >= 0
3343              && nbytes == 2
3344              && exp->X_op == O_constant
3345              && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
3346       listing_source_line ((unsigned int) dwarf_line);
3347     else if (nbytes == 4
3348              && exp->X_op == O_constant
3349              && exp->X_add_number >= 0)
3350       dwarf_line = exp->X_add_number;
3351     else
3352       dwarf_line = -1;
3353   }
3354
3355   /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
3356      appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
3357      AT_sibling (0x12) followed by a four byte address of the sibling
3358      followed by a 2 byte AT_name (0x38) followed by the name of the
3359      file.  We look for that case here.  */
3360   {
3361     static int dwarf_file = 0;
3362
3363     if (strcmp (segment_name (now_seg), ".debug") != 0)
3364       dwarf_file = 0;
3365     else if (dwarf_file == 0
3366              && nbytes == 2
3367              && exp->X_op == O_constant
3368              && exp->X_add_number == 0x11)
3369       dwarf_file = 1;
3370     else if (dwarf_file == 1
3371              && nbytes == 2
3372              && exp->X_op == O_constant
3373              && exp->X_add_number == 0x12)
3374       dwarf_file = 2;
3375     else if (dwarf_file == 2
3376              && nbytes == 4)
3377       dwarf_file = 3;
3378     else if (dwarf_file == 3
3379              && nbytes == 2
3380              && exp->X_op == O_constant
3381              && exp->X_add_number == 0x38)
3382       dwarf_file = 4;
3383     else
3384       dwarf_file = 0;
3385
3386     /* The variable dwarf_file_string tells stringer that the string
3387        may be the name of the source file.  */
3388     if (dwarf_file == 4)
3389       dwarf_file_string = 1;
3390     else
3391       dwarf_file_string = 0;
3392   }
3393 #endif
3394 #endif
3395
3396   if (check_eh_frame (exp, &nbytes))
3397     return;
3398
3399   op = exp->X_op;
3400
3401   /* Allow `.word 0' in the absolute section.  */
3402   if (now_seg == absolute_section)
3403     {
3404       if (op != O_constant || exp->X_add_number != 0)
3405         as_bad (_("attempt to store value in absolute section"));
3406       abs_section_offset += nbytes;
3407       return;
3408     }
3409
3410   /* Handle a negative bignum.  */
3411   if (op == O_uminus
3412       && exp->X_add_number == 0
3413       && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
3414       && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
3415     {
3416       int i;
3417       unsigned long carry;
3418
3419       exp = symbol_get_value_expression (exp->X_add_symbol);
3420
3421       /* Negate the bignum: one's complement each digit and add 1.  */
3422       carry = 1;
3423       for (i = 0; i < exp->X_add_number; i++)
3424         {
3425           unsigned long next;
3426
3427           next = (((~ (generic_bignum[i] & LITTLENUM_MASK))
3428                    & LITTLENUM_MASK)
3429                   + carry);
3430           generic_bignum[i] = next & LITTLENUM_MASK;
3431           carry = next >> LITTLENUM_NUMBER_OF_BITS;
3432         }
3433
3434       /* We can ignore any carry out, because it will be handled by
3435          extra_digit if it is needed.  */
3436
3437       extra_digit = (valueT) -1;
3438       op = O_big;
3439     }
3440
3441   if (op == O_absent || op == O_illegal)
3442     {
3443       as_warn (_("zero assumed for missing expression"));
3444       exp->X_add_number = 0;
3445       op = O_constant;
3446     }
3447   else if (op == O_big && exp->X_add_number <= 0)
3448     {
3449       as_bad (_("floating point number invalid; zero assumed"));
3450       exp->X_add_number = 0;
3451       op = O_constant;
3452     }
3453   else if (op == O_register)
3454     {
3455       as_warn (_("register value used as expression"));
3456       op = O_constant;
3457     }
3458
3459   p = frag_more ((int) nbytes);
3460
3461 #ifndef WORKING_DOT_WORD
3462   /* If we have the difference of two symbols in a word, save it on
3463      the broken_words list.  See the code in write.c.  */
3464   if (op == O_subtract && nbytes == 2)
3465     {
3466       struct broken_word *x;
3467
3468       x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
3469       x->next_broken_word = broken_words;
3470       broken_words = x;
3471       x->seg = now_seg;
3472       x->subseg = now_subseg;
3473       x->frag = frag_now;
3474       x->word_goes_here = p;
3475       x->dispfrag = 0;
3476       x->add = exp->X_add_symbol;
3477       x->sub = exp->X_op_symbol;
3478       x->addnum = exp->X_add_number;
3479       x->added = 0;
3480       new_broken_words++;
3481       return;
3482     }
3483 #endif
3484
3485   /* If we have an integer, but the number of bytes is too large to
3486      pass to md_number_to_chars, handle it as a bignum.  */
3487   if (op == O_constant && nbytes > sizeof (valueT))
3488     {
3489       valueT val;
3490       int gencnt;
3491
3492       if (! exp->X_unsigned && exp->X_add_number < 0)
3493         extra_digit = (valueT) -1;
3494       val = (valueT) exp->X_add_number;
3495       gencnt = 0;
3496       do
3497         {
3498           generic_bignum[gencnt] = val & LITTLENUM_MASK;
3499           val >>= LITTLENUM_NUMBER_OF_BITS;
3500           ++gencnt;
3501         }
3502       while (val != 0);
3503       op = exp->X_op = O_big;
3504       exp->X_add_number = gencnt;
3505     }
3506
3507   if (op == O_constant)
3508     {
3509       register valueT get;
3510       register valueT use;
3511       register valueT mask;
3512       valueT hibit;
3513       register valueT unmask;
3514
3515       /* JF << of >= number of bits in the object is undefined.  In
3516          particular SPARC (Sun 4) has problems */
3517       if (nbytes >= sizeof (valueT))
3518         {
3519           mask = 0;
3520           if (nbytes > sizeof (valueT))
3521             hibit = 0;
3522           else
3523             hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3524         }
3525       else
3526         {
3527           /* Don't store these bits. */
3528           mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
3529           hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
3530         }
3531
3532       unmask = ~mask;           /* Do store these bits. */
3533
3534 #ifdef NEVER
3535       "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
3536       mask = ~(unmask >> 1);    /* Includes sign bit now. */
3537 #endif
3538
3539       get = exp->X_add_number;
3540       use = get & unmask;
3541       if ((get & mask) != 0
3542           && ((get & mask) != mask
3543               || (get & hibit) == 0))
3544         {               /* Leading bits contain both 0s & 1s. */
3545           as_warn (_("Value 0x%lx truncated to 0x%lx."),
3546                    (unsigned long) get, (unsigned long) use);
3547         }
3548       /* put bytes in right order. */
3549       md_number_to_chars (p, use, (int) nbytes);
3550     }
3551   else if (op == O_big)
3552     {
3553       unsigned int size;
3554       LITTLENUM_TYPE *nums;
3555
3556       know (nbytes % CHARS_PER_LITTLENUM == 0);
3557
3558       size = exp->X_add_number * CHARS_PER_LITTLENUM;
3559       if (nbytes < size)
3560         {
3561           as_warn (_("Bignum truncated to %d bytes"), nbytes);
3562           size = nbytes;
3563         }
3564
3565       if (target_big_endian)
3566         {
3567           while (nbytes > size)
3568             {
3569               md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3570               nbytes -= CHARS_PER_LITTLENUM;
3571               p += CHARS_PER_LITTLENUM;
3572             }
3573
3574           nums = generic_bignum + size / CHARS_PER_LITTLENUM;
3575           while (size > 0)
3576             {
3577               --nums;
3578               md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3579               size -= CHARS_PER_LITTLENUM;
3580               p += CHARS_PER_LITTLENUM;
3581             }
3582         }
3583       else
3584         {
3585           nums = generic_bignum;
3586           while (size > 0)
3587             {
3588               md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
3589               ++nums;
3590               size -= CHARS_PER_LITTLENUM;
3591               p += CHARS_PER_LITTLENUM;
3592               nbytes -= CHARS_PER_LITTLENUM;
3593             }
3594
3595           while (nbytes > 0)
3596             {
3597               md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
3598               nbytes -= CHARS_PER_LITTLENUM;
3599               p += CHARS_PER_LITTLENUM;
3600             }
3601         }
3602     }
3603   else
3604     {
3605       memset (p, 0, nbytes);
3606
3607       /* Now we need to generate a fixS to record the symbol value.
3608          This is easy for BFD.  For other targets it can be more
3609          complex.  For very complex cases (currently, the HPPA and
3610          NS32K), you can define TC_CONS_FIX_NEW to do whatever you
3611          want.  For simpler cases, you can define TC_CONS_RELOC to be
3612          the name of the reloc code that should be stored in the fixS.
3613          If neither is defined, the code uses NO_RELOC if it is
3614          defined, and otherwise uses 0.  */
3615
3616 #ifdef BFD_ASSEMBLER
3617 #ifdef TC_CONS_FIX_NEW
3618       TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3619 #else
3620       {
3621         bfd_reloc_code_real_type r;
3622
3623         switch (nbytes)
3624           {
3625           case 1:
3626             r = BFD_RELOC_8;
3627             break;
3628           case 2:
3629             r = BFD_RELOC_16;
3630             break;
3631           case 4:
3632             r = BFD_RELOC_32;
3633             break;
3634           case 8:
3635             r = BFD_RELOC_64;
3636             break;
3637           default:
3638             as_bad (_("unsupported BFD relocation size %u"), nbytes);
3639             r = BFD_RELOC_32;
3640             break;
3641           }
3642         fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp,
3643                      0, r);
3644       }
3645 #endif
3646 #else
3647 #ifdef TC_CONS_FIX_NEW
3648       TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp);
3649 #else
3650       /* Figure out which reloc number to use.  Use TC_CONS_RELOC if
3651          it is defined, otherwise use NO_RELOC if it is defined,
3652          otherwise use 0.  */
3653 #ifndef TC_CONS_RELOC
3654 #ifdef NO_RELOC
3655 #define TC_CONS_RELOC NO_RELOC
3656 #else
3657 #define TC_CONS_RELOC 0
3658 #endif
3659 #endif
3660       fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0,
3661                    TC_CONS_RELOC);
3662 #endif /* TC_CONS_FIX_NEW */
3663 #endif /* BFD_ASSEMBLER */
3664     }
3665 }
3666 \f
3667 #ifdef BITFIELD_CONS_EXPRESSIONS
3668
3669 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
3670    w:x,y:z, where w and y are bitwidths and x and y are values.  They
3671    then pack them all together. We do a little better in that we allow
3672    them in words, longs, etc. and we'll pack them in target byte order
3673    for you.
3674
3675    The rules are: pack least significat bit first, if a field doesn't
3676    entirely fit, put it in the next unit.  Overflowing the bitfield is
3677    explicitly *not* even a warning.  The bitwidth should be considered
3678    a "mask".
3679
3680    To use this function the tc-XXX.h file should define
3681    BITFIELD_CONS_EXPRESSIONS.  */
3682
3683 static void 
3684 parse_bitfield_cons (exp, nbytes)
3685      expressionS *exp;
3686      unsigned int nbytes;
3687 {
3688   unsigned int bits_available = BITS_PER_CHAR * nbytes;
3689   char *hold = input_line_pointer;
3690
3691   (void) expression (exp);
3692
3693   if (*input_line_pointer == ':')
3694     {                   /* bitfields */
3695       long value = 0;
3696
3697       for (;;)
3698         {
3699           unsigned long width;
3700
3701           if (*input_line_pointer != ':')
3702             {
3703               input_line_pointer = hold;
3704               break;
3705             }                   /* next piece is not a bitfield */
3706
3707           /* In the general case, we can't allow
3708              full expressions with symbol
3709              differences and such.  The relocation
3710              entries for symbols not defined in this
3711              assembly would require arbitrary field
3712              widths, positions, and masks which most
3713              of our current object formats don't
3714              support.
3715
3716              In the specific case where a symbol
3717              *is* defined in this assembly, we
3718              *could* build fixups and track it, but
3719              this could lead to confusion for the
3720              backends.  I'm lazy. I'll take any
3721              SEG_ABSOLUTE. I think that means that
3722              you can use a previous .set or
3723              .equ type symbol.  xoxorich. */
3724
3725           if (exp->X_op == O_absent)
3726             {
3727               as_warn (_("using a bit field width of zero"));
3728               exp->X_add_number = 0;
3729               exp->X_op = O_constant;
3730             }                   /* implied zero width bitfield */
3731
3732           if (exp->X_op != O_constant)
3733             {
3734               *input_line_pointer = '\0';
3735               as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
3736               *input_line_pointer = ':';
3737               demand_empty_rest_of_line ();
3738               return;
3739             }                   /* too complex */
3740
3741           if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
3742             {
3743               as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
3744                        width, nbytes, (BITS_PER_CHAR * nbytes));
3745               width = BITS_PER_CHAR * nbytes;
3746             }                   /* too big */
3747
3748           if (width > bits_available)
3749             {
3750               /* FIXME-SOMEDAY: backing up and reparsing is wasteful.  */
3751               input_line_pointer = hold;
3752               exp->X_add_number = value;
3753               break;
3754             }                   /* won't fit */
3755
3756           hold = ++input_line_pointer; /* skip ':' */
3757
3758           (void) expression (exp);
3759           if (exp->X_op != O_constant)
3760             {
3761               char cache = *input_line_pointer;
3762
3763               *input_line_pointer = '\0';
3764               as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
3765               *input_line_pointer = cache;
3766               demand_empty_rest_of_line ();
3767               return;
3768             }                   /* too complex */
3769
3770           value |= ((~(-1 << width) & exp->X_add_number)
3771                     << ((BITS_PER_CHAR * nbytes) - bits_available));
3772
3773           if ((bits_available -= width) == 0
3774               || is_it_end_of_statement ()
3775               || *input_line_pointer != ',')
3776             {
3777               break;
3778             }                   /* all the bitfields we're gonna get */
3779
3780           hold = ++input_line_pointer;
3781           (void) expression (exp);
3782         }                       /* forever loop */
3783
3784       exp->X_add_number = value;
3785       exp->X_op = O_constant;
3786       exp->X_unsigned = 1;
3787     }                           /* if looks like a bitfield */
3788 }                               /* parse_bitfield_cons() */
3789
3790 #endif /* BITFIELD_CONS_EXPRESSIONS */
3791 \f
3792 /* Handle an MRI style string expression.  */
3793
3794 static void
3795 parse_mri_cons (exp, nbytes)
3796      expressionS *exp;
3797      unsigned int nbytes;
3798 {
3799   if (*input_line_pointer != '\''
3800       && (input_line_pointer[1] != '\''
3801           || (*input_line_pointer != 'A'
3802               && *input_line_pointer != 'E')))
3803     TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3804   else
3805     {
3806       unsigned int scan;
3807       unsigned int result = 0;
3808
3809       /* An MRI style string.  Cut into as many bytes as will fit into
3810          a nbyte chunk, left justify if necessary, and separate with
3811          commas so we can try again later.  */
3812       if (*input_line_pointer == 'A')
3813         ++input_line_pointer;
3814       else if (*input_line_pointer == 'E')
3815         {
3816           as_bad (_("EBCDIC constants are not supported"));
3817           ++input_line_pointer;
3818         }
3819
3820       input_line_pointer++;
3821       for (scan = 0; scan < nbytes; scan++)
3822         {
3823           if (*input_line_pointer == '\'')
3824             {
3825               if (input_line_pointer[1] == '\'')
3826                 {
3827                   input_line_pointer++;
3828                 }
3829               else
3830                 break;
3831             }
3832           result = (result << 8) | (*input_line_pointer++);
3833         }
3834
3835       /* Left justify */
3836       while (scan < nbytes)
3837         {
3838           result <<= 8;
3839           scan++;
3840         }
3841       /* Create correct expression */
3842       exp->X_op = O_constant;
3843       exp->X_add_number = result;
3844       /* Fake it so that we can read the next char too */
3845       if (input_line_pointer[0] != '\'' ||
3846           (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
3847         {
3848           input_line_pointer -= 2;
3849           input_line_pointer[0] = ',';
3850           input_line_pointer[1] = '\'';
3851         }
3852       else
3853         input_line_pointer++;
3854     }
3855 }
3856 \f
3857 #ifdef REPEAT_CONS_EXPRESSIONS
3858
3859 /* Parse a repeat expression for cons.  This is used by the MIPS
3860    assembler.  The format is NUMBER:COUNT; NUMBER appears in the
3861    object file COUNT times.
3862
3863    To use this for a target, define REPEAT_CONS_EXPRESSIONS.  */
3864
3865 static void
3866 parse_repeat_cons (exp, nbytes)
3867      expressionS *exp;
3868      unsigned int nbytes;
3869 {
3870   expressionS count;
3871   register int i;
3872
3873   expression (exp);
3874
3875   if (*input_line_pointer != ':')
3876     {
3877       /* No repeat count.  */
3878       return;
3879     }
3880
3881   ++input_line_pointer;
3882   expression (&count);
3883   if (count.X_op != O_constant
3884       || count.X_add_number <= 0)
3885     {
3886       as_warn (_("Unresolvable or nonpositive repeat count; using 1"));
3887       return;
3888     }
3889
3890   /* The cons function is going to output this expression once.  So we
3891      output it count - 1 times.  */
3892   for (i = count.X_add_number - 1; i > 0; i--)
3893     emit_expr (exp, nbytes);
3894 }
3895
3896 #endif /* REPEAT_CONS_EXPRESSIONS */
3897 \f
3898 /* Parse a floating point number represented as a hex constant.  This
3899    permits users to specify the exact bits they want in the floating
3900    point number.  */
3901
3902 static int
3903 hex_float (float_type, bytes)
3904      int float_type;
3905      char *bytes;
3906 {
3907   int length;
3908   int i;
3909
3910   switch (float_type)
3911     {
3912     case 'f':
3913     case 'F':
3914     case 's':
3915     case 'S':
3916       length = 4;
3917       break;
3918
3919     case 'd':
3920     case 'D':
3921     case 'r':
3922     case 'R':
3923       length = 8;
3924       break;
3925
3926     case 'x':
3927     case 'X':
3928       length = 12;
3929       break;
3930
3931     case 'p':
3932     case 'P':
3933       length = 12;
3934       break;
3935
3936     default:
3937       as_bad (_("Unknown floating type type '%c'"), float_type);
3938       return -1;
3939     }
3940
3941   /* It would be nice if we could go through expression to parse the
3942      hex constant, but if we get a bignum it's a pain to sort it into
3943      the buffer correctly.  */
3944   i = 0;
3945   while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
3946     {
3947       int d;
3948
3949       /* The MRI assembler accepts arbitrary underscores strewn about
3950          through the hex constant, so we ignore them as well. */
3951       if (*input_line_pointer == '_')
3952         {
3953           ++input_line_pointer;
3954           continue;
3955         }
3956
3957       if (i >= length)
3958         {
3959           as_warn (_("Floating point constant too large"));
3960           return -1;
3961         }
3962       d = hex_value (*input_line_pointer) << 4;
3963       ++input_line_pointer;
3964       while (*input_line_pointer == '_')
3965         ++input_line_pointer;
3966       if (hex_p (*input_line_pointer))
3967         {
3968           d += hex_value (*input_line_pointer);
3969           ++input_line_pointer;
3970         }
3971       if (target_big_endian)
3972         bytes[i] = d;
3973       else
3974         bytes[length - i - 1] = d;
3975       ++i;
3976     }
3977
3978   if (i < length)
3979     {
3980       if (target_big_endian)
3981         memset (bytes + i, 0, length - i);
3982       else
3983         memset (bytes, 0, length - i);
3984     }
3985
3986   return length;
3987 }
3988
3989 /*
3990  *                      float_cons()
3991  *
3992  * CONStruct some more frag chars of .floats .ffloats etc.
3993  * Makes 0 or more new frags.
3994  * If need_pass_2 == 1, no frags are emitted.
3995  * This understands only floating literals, not expressions. Sorry.
3996  *
3997  * A floating constant is defined by atof_generic(), except it is preceded
3998  * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
3999  * reading, I decided to be incompatible. This always tries to give you
4000  * rounded bits to the precision of the pseudo-op. Former AS did premature
4001  * truncatation, restored noisy bits instead of trailing 0s AND gave you
4002  * a choice of 2 flavours of noise according to which of 2 floating-point
4003  * scanners you directed AS to use.
4004  *
4005  * In:  input_line_pointer->whitespace before, or '0' of flonum.
4006  *
4007  */
4008
4009 void
4010 float_cons (float_type)
4011      /* Clobbers input_line-pointer, checks end-of-line. */
4012      register int float_type;   /* 'f':.ffloat ... 'F':.float ... */
4013 {
4014   register char *p;
4015   int length;                   /* Number of chars in an object. */
4016   register char *err;           /* Error from scanning floating literal. */
4017   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4018
4019   if (is_it_end_of_statement ())
4020     {
4021       demand_empty_rest_of_line ();
4022       return;
4023     }
4024
4025 #ifdef md_flush_pending_output
4026   md_flush_pending_output ();
4027 #endif
4028
4029   do
4030     {
4031       /* input_line_pointer->1st char of a flonum (we hope!). */
4032       SKIP_WHITESPACE ();
4033
4034       /* Skip any 0{letter} that may be present. Don't even check if the
4035        * letter is legal. Someone may invent a "z" format and this routine
4036        * has no use for such information. Lusers beware: you get
4037        * diagnostics if your input is ill-conditioned.
4038        */
4039       if (input_line_pointer[0] == '0'
4040           && isalpha ((unsigned char) input_line_pointer[1]))
4041         input_line_pointer += 2;
4042
4043       /* Accept :xxxx, where the x's are hex digits, for a floating
4044          point with the exact digits specified.  */
4045       if (input_line_pointer[0] == ':')
4046         {
4047           ++input_line_pointer;
4048           length = hex_float (float_type, temp);
4049           if (length < 0)
4050             {
4051               ignore_rest_of_line ();
4052               return;
4053             }
4054         }
4055       else
4056         {
4057           err = md_atof (float_type, temp, &length);
4058           know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4059           know (length > 0);
4060           if (err)
4061             {
4062               as_bad (_("Bad floating literal: %s"), err);
4063               ignore_rest_of_line ();
4064               return;
4065             }
4066         }
4067
4068       if (!need_pass_2)
4069         {
4070           int count;
4071
4072           count = 1;
4073
4074 #ifdef REPEAT_CONS_EXPRESSIONS
4075           if (*input_line_pointer == ':')
4076             {
4077               expressionS count_exp;
4078
4079               ++input_line_pointer;
4080               expression (&count_exp);
4081               if (count_exp.X_op != O_constant
4082                   || count_exp.X_add_number <= 0)
4083                 {
4084                   as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4085                 }
4086               else
4087                 count = count_exp.X_add_number;
4088             }
4089 #endif
4090
4091           while (--count >= 0)
4092             {
4093               p = frag_more (length);
4094               memcpy (p, temp, (unsigned int) length);
4095             }
4096         }
4097       SKIP_WHITESPACE ();
4098     }
4099   while (*input_line_pointer++ == ',');
4100
4101   --input_line_pointer;         /* Put terminator back into stream.  */
4102   demand_empty_rest_of_line ();
4103 }                               /* float_cons() */
4104 \f
4105 /* Return the size of a LEB128 value */
4106
4107 static inline int
4108 sizeof_sleb128 (value)
4109      offsetT value;
4110 {
4111   register int size = 0;
4112   register unsigned byte;
4113
4114   do
4115     {
4116       byte = (value & 0x7f);
4117       /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4118          Fortunately, we can structure things so that the extra work reduces
4119          to a noop on systems that do things "properly".  */
4120       value = (value >> 7) | ~(-(offsetT)1 >> 7);
4121       size += 1;
4122     }
4123   while (!(((value == 0) && ((byte & 0x40) == 0))
4124            || ((value == -1) && ((byte & 0x40) != 0))));
4125
4126   return size;
4127 }
4128
4129 static inline int
4130 sizeof_uleb128 (value)
4131      valueT value;
4132 {
4133   register int size = 0;
4134   register unsigned byte;
4135
4136   do
4137     {
4138       byte = (value & 0x7f);
4139       value >>= 7;
4140       size += 1;
4141     }
4142   while (value != 0);
4143
4144   return size;
4145 }
4146
4147 int
4148 sizeof_leb128 (value, sign)
4149      valueT value;
4150      int sign;
4151 {
4152   if (sign)
4153     return sizeof_sleb128 ((offsetT) value);
4154   else
4155     return sizeof_uleb128 (value);
4156 }
4157
4158 /* Output a LEB128 value.  */
4159
4160 static inline int
4161 output_sleb128 (p, value)
4162      char *p;
4163      offsetT value;
4164 {
4165   register char *orig = p;
4166   register int more;
4167
4168   do
4169     {
4170       unsigned byte = (value & 0x7f);
4171
4172       /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4173          Fortunately, we can structure things so that the extra work reduces
4174          to a noop on systems that do things "properly".  */
4175       value = (value >> 7) | ~(-(offsetT)1 >> 7);
4176
4177       more = !((((value == 0) && ((byte & 0x40) == 0))
4178                 || ((value == -1) && ((byte & 0x40) != 0))));
4179       if (more)
4180         byte |= 0x80;
4181
4182       *p++ = byte;
4183     }
4184   while (more);
4185
4186   return p - orig;
4187 }
4188
4189 static inline int
4190 output_uleb128 (p, value)
4191      char *p;
4192      valueT value;
4193 {
4194   char *orig = p;
4195
4196   do
4197     {
4198       unsigned byte = (value & 0x7f);
4199       value >>= 7;
4200       if (value != 0)
4201         /* More bytes to follow.  */
4202         byte |= 0x80;
4203
4204       *p++ = byte;
4205     }
4206   while (value != 0);
4207
4208   return p - orig;
4209 }
4210
4211 int
4212 output_leb128 (p, value, sign)
4213      char *p;
4214      valueT value;
4215      int sign;
4216 {
4217   if (sign)
4218     return output_sleb128 (p, (offsetT) value);
4219   else
4220     return output_uleb128 (p, value);
4221 }
4222
4223 /* Do the same for bignums.  We combine sizeof with output here in that
4224    we don't output for NULL values of P.  It isn't really as critical as
4225    for "normal" values that this be streamlined.  */
4226
4227 static inline int
4228 output_big_sleb128 (p, bignum, size)
4229      char *p;
4230      LITTLENUM_TYPE *bignum;
4231      int size;
4232 {
4233   char *orig = p;
4234   valueT val = 0;
4235   int loaded = 0;
4236   unsigned byte;
4237
4238   /* Strip leading sign extensions off the bignum.  */
4239   while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1)
4240     size--;
4241
4242   do
4243     {
4244       if (loaded < 7 && size > 0)
4245         {
4246           val |= (*bignum << loaded);
4247           loaded += 8 * CHARS_PER_LITTLENUM;
4248           size--;
4249           bignum++;
4250         }
4251
4252       byte = val & 0x7f;
4253       loaded -= 7;
4254       val >>= 7;
4255
4256       if (size == 0)
4257         {
4258           if ((val == 0 && (byte & 0x40) == 0)
4259               || (~(val | ~(((valueT)1 << loaded) - 1)) == 0
4260                   && (byte & 0x40) != 0))
4261             byte |= 0x80;
4262         }
4263
4264       if (orig)
4265         *p = byte;
4266       p++;
4267     }
4268   while (byte & 0x80);
4269
4270   return p - orig;
4271 }
4272
4273 static inline int
4274 output_big_uleb128 (p, bignum, size)
4275      char *p;
4276      LITTLENUM_TYPE *bignum;
4277      int size;
4278 {
4279   char *orig = p;
4280   valueT val = 0;
4281   int loaded = 0;
4282   unsigned byte;
4283
4284   /* Strip leading zeros off the bignum.  */
4285   /* XXX: Is this needed?  */
4286   while (size > 0 && bignum[size-1] == 0)
4287     size--;
4288
4289   do
4290     {
4291       if (loaded < 7 && size > 0)
4292         {
4293           val |= (*bignum << loaded);
4294           loaded += 8 * CHARS_PER_LITTLENUM;
4295           size--;
4296           bignum++;
4297         }
4298
4299       byte = val & 0x7f;
4300       loaded -= 7;
4301       val >>= 7;
4302
4303       if (size > 0 || val)
4304         byte |= 0x80;
4305
4306       if (orig)
4307         *p = byte;
4308       p++;
4309     }
4310   while (byte & 0x80);
4311
4312   return p - orig;
4313 }
4314
4315 static int
4316 output_big_leb128 (p, bignum, size, sign)
4317      char *p;
4318      LITTLENUM_TYPE *bignum;
4319      int size, sign;
4320 {
4321   if (sign)
4322     return output_big_sleb128 (p, bignum, size);
4323   else
4324     return output_big_uleb128 (p, bignum, size);
4325 }
4326
4327 /* Generate the appropriate fragments for a given expression to emit a
4328    leb128 value.  */
4329
4330 void
4331 emit_leb128_expr(exp, sign)
4332      expressionS *exp;
4333      int sign;
4334 {
4335   operatorT op = exp->X_op;
4336
4337   if (op == O_absent || op == O_illegal)
4338     {
4339       as_warn (_("zero assumed for missing expression"));
4340       exp->X_add_number = 0;
4341       op = O_constant;
4342     }
4343   else if (op == O_big && exp->X_add_number <= 0)
4344     {
4345       as_bad (_("floating point number invalid; zero assumed"));
4346       exp->X_add_number = 0;
4347       op = O_constant;
4348     }
4349   else if (op == O_register)
4350     {
4351       as_warn (_("register value used as expression"));
4352       op = O_constant;
4353     }
4354
4355   if (op == O_constant)
4356     {
4357       /* If we've got a constant, emit the thing directly right now.  */
4358
4359       valueT value = exp->X_add_number;
4360       int size;
4361       char *p;
4362
4363       size = sizeof_leb128 (value, sign);
4364       p = frag_more (size);
4365       output_leb128 (p, value, sign);
4366     }
4367   else if (op == O_big)
4368     {
4369       /* O_big is a different sort of constant.  */
4370
4371       int size;
4372       char *p;
4373
4374       size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
4375       p = frag_more (size);
4376       output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
4377     }
4378   else
4379     {
4380       /* Otherwise, we have to create a variable sized fragment and 
4381          resolve things later.  */
4382
4383       frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign,
4384                 make_expr_symbol (exp), 0, (char *) NULL);
4385     }
4386 }
4387
4388 /* Parse the .sleb128 and .uleb128 pseudos.  */
4389
4390 void
4391 s_leb128 (sign)
4392      int sign;
4393 {
4394   expressionS exp;
4395
4396   do {
4397     expression (&exp);
4398     emit_leb128_expr (&exp, sign);
4399   } while (*input_line_pointer++ == ',');
4400
4401   input_line_pointer--;
4402   demand_empty_rest_of_line ();
4403 }
4404 \f
4405 /*
4406  *                      stringer()
4407  *
4408  * We read 0 or more ',' seperated, double-quoted strings.
4409  *
4410  * Caller should have checked need_pass_2 is FALSE because we don't check it.
4411  */
4412
4413
4414 void 
4415 stringer (append_zero)          /* Worker to do .ascii etc statements. */
4416      /* Checks end-of-line. */
4417      register int append_zero;  /* 0: don't append '\0', else 1 */
4418 {
4419   register unsigned int c;
4420   char *start;
4421
4422 #ifdef md_flush_pending_output
4423   md_flush_pending_output ();
4424 #endif
4425
4426   /*
4427    * The following awkward logic is to parse ZERO or more strings,
4428    * comma separated. Recall a string expression includes spaces
4429    * before the opening '\"' and spaces after the closing '\"'.
4430    * We fake a leading ',' if there is (supposed to be)
4431    * a 1st, expression. We keep demanding expressions for each
4432    * ','.
4433    */
4434   if (is_it_end_of_statement ())
4435     {
4436       c = 0;                    /* Skip loop. */
4437       ++input_line_pointer;     /* Compensate for end of loop. */
4438     }
4439   else
4440     {
4441       c = ',';                  /* Do loop. */
4442     }
4443   while (c == ',' || c == '<' || c == '"')
4444     {
4445       SKIP_WHITESPACE ();
4446       switch (*input_line_pointer)
4447         {
4448         case '\"':
4449           ++input_line_pointer; /*->1st char of string. */
4450           start = input_line_pointer;
4451           while (is_a_char (c = next_char_of_string ()))
4452             {
4453               FRAG_APPEND_1_CHAR (c);
4454             }
4455           if (append_zero)
4456             {
4457               FRAG_APPEND_1_CHAR (0);
4458             }
4459           know (input_line_pointer[-1] == '\"');
4460
4461 #ifndef NO_LISTING
4462 #ifdef OBJ_ELF
4463           /* In ELF, when gcc is emitting DWARF 1 debugging output, it
4464              will emit .string with a filename in the .debug section
4465              after a sequence of constants.  See the comment in
4466              emit_expr for the sequence.  emit_expr will set
4467              dwarf_file_string to non-zero if this string might be a
4468              source file name.  */
4469           if (strcmp (segment_name (now_seg), ".debug") != 0)
4470             dwarf_file_string = 0;
4471           else if (dwarf_file_string)
4472             {
4473               c = input_line_pointer[-1];
4474               input_line_pointer[-1] = '\0';
4475               listing_source_file (start);
4476               input_line_pointer[-1] = c;
4477             }
4478 #endif
4479 #endif
4480
4481           break;
4482         case '<':
4483           input_line_pointer++;
4484           c = get_single_number ();
4485           FRAG_APPEND_1_CHAR (c);
4486           if (*input_line_pointer != '>')
4487             {
4488               as_bad (_("Expected <nn>"));
4489             }
4490           input_line_pointer++;
4491           break;
4492         case ',':
4493           input_line_pointer++;
4494           break;
4495         }
4496       SKIP_WHITESPACE ();
4497       c = *input_line_pointer;
4498     }
4499
4500   demand_empty_rest_of_line ();
4501 }                               /* stringer() */
4502 \f
4503 /* FIXME-SOMEDAY: I had trouble here on characters with the
4504     high bits set.  We'll probably also have trouble with
4505     multibyte chars, wide chars, etc.  Also be careful about
4506     returning values bigger than 1 byte.  xoxorich. */
4507
4508 unsigned int 
4509 next_char_of_string ()
4510 {
4511   register unsigned int c;
4512
4513   c = *input_line_pointer++ & CHAR_MASK;
4514   switch (c)
4515     {
4516     case '\"':
4517       c = NOT_A_CHAR;
4518       break;
4519
4520     case '\n':
4521       as_warn (_("Unterminated string: Newline inserted."));
4522       bump_line_counters ();
4523       break;
4524
4525 #ifndef NO_STRING_ESCAPES
4526     case '\\':
4527       switch (c = *input_line_pointer++)
4528         {
4529         case 'b':
4530           c = '\b';
4531           break;
4532
4533         case 'f':
4534           c = '\f';
4535           break;
4536
4537         case 'n':
4538           c = '\n';
4539           break;
4540
4541         case 'r':
4542           c = '\r';
4543           break;
4544
4545         case 't':
4546           c = '\t';
4547           break;
4548
4549         case 'v':
4550           c = '\013';
4551           break;
4552
4553         case '\\':
4554         case '"':
4555           break;                /* As itself. */
4556
4557         case '0':
4558         case '1':
4559         case '2':
4560         case '3':
4561         case '4':
4562         case '5':
4563         case '6':
4564         case '7':
4565         case '8':
4566         case '9':
4567           {
4568             long number;
4569             int i;
4570
4571             for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++)
4572               {
4573                 number = number * 8 + c - '0';
4574               }
4575             c = number & 0xff;
4576           }
4577           --input_line_pointer;
4578           break;
4579
4580         case 'x':
4581         case 'X':
4582           {
4583             long number;
4584
4585             number = 0;
4586             c = *input_line_pointer++;
4587             while (isxdigit (c))
4588               {
4589                 if (isdigit (c))
4590                   number = number * 16 + c - '0';
4591                 else if (isupper (c))
4592                   number = number * 16 + c - 'A' + 10;
4593                 else
4594                   number = number * 16 + c - 'a' + 10;
4595                 c = *input_line_pointer++;
4596               }
4597             c = number & 0xff;
4598             --input_line_pointer;
4599           }
4600           break;
4601
4602         case '\n':
4603           /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */
4604           as_warn (_("Unterminated string: Newline inserted."));
4605           c = '\n';
4606           bump_line_counters ();
4607           break;
4608
4609         default:
4610
4611 #ifdef ONLY_STANDARD_ESCAPES
4612           as_bad (_("Bad escaped character in string, '?' assumed"));
4613           c = '?';
4614 #endif /* ONLY_STANDARD_ESCAPES */
4615
4616           break;
4617         }                       /* switch on escaped char */
4618       break;
4619 #endif /* ! defined (NO_STRING_ESCAPES) */
4620
4621     default:
4622       break;
4623     }                           /* switch on char */
4624   return (c);
4625 }                               /* next_char_of_string() */
4626 \f
4627 static segT
4628 get_segmented_expression (expP)
4629      register expressionS *expP;
4630 {
4631   register segT retval;
4632
4633   retval = expression (expP);
4634   if (expP->X_op == O_illegal
4635       || expP->X_op == O_absent
4636       || expP->X_op == O_big)
4637     {
4638       as_bad (_("expected address expression; zero assumed"));
4639       expP->X_op = O_constant;
4640       expP->X_add_number = 0;
4641       retval = absolute_section;
4642     }
4643   return retval;
4644 }
4645
4646 static segT 
4647 get_known_segmented_expression (expP)
4648      register expressionS *expP;
4649 {
4650   register segT retval;
4651
4652   if ((retval = get_segmented_expression (expP)) == undefined_section)
4653     {
4654       /* There is no easy way to extract the undefined symbol from the
4655          expression.  */
4656       if (expP->X_add_symbol != NULL
4657           && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
4658         as_warn (_("symbol \"%s\" undefined; zero assumed"),
4659                  S_GET_NAME (expP->X_add_symbol));
4660       else
4661         as_warn (_("some symbol undefined; zero assumed"));
4662       retval = absolute_section;
4663       expP->X_op = O_constant;
4664       expP->X_add_number = 0;
4665     }
4666   know (retval == absolute_section || SEG_NORMAL (retval));
4667   return (retval);
4668 }                               /* get_known_segmented_expression() */
4669
4670 offsetT
4671 get_absolute_expression ()
4672 {
4673   expressionS exp;
4674
4675   expression (&exp);
4676   if (exp.X_op != O_constant)
4677     {
4678       if (exp.X_op != O_absent)
4679         as_bad (_("bad or irreducible absolute expression; zero assumed"));
4680       exp.X_add_number = 0;
4681     }
4682   return exp.X_add_number;
4683 }
4684
4685 char                            /* return terminator */
4686 get_absolute_expression_and_terminator (val_pointer)
4687      long *val_pointer;         /* return value of expression */
4688 {
4689   /* FIXME: val_pointer should probably be offsetT *.  */
4690   *val_pointer = (long) get_absolute_expression ();
4691   return (*input_line_pointer++);
4692 }
4693 \f
4694 /*
4695  *                      demand_copy_C_string()
4696  *
4697  * Like demand_copy_string, but return NULL if the string contains any '\0's.
4698  * Give a warning if that happens.
4699  */
4700 char *
4701 demand_copy_C_string (len_pointer)
4702      int *len_pointer;
4703 {
4704   register char *s;
4705
4706   if ((s = demand_copy_string (len_pointer)) != 0)
4707     {
4708       register int len;
4709
4710       for (len = *len_pointer; len > 0; len--)
4711         {
4712           if (*s == 0)
4713             {
4714               s = 0;
4715               len = 1;
4716               *len_pointer = 0;
4717               as_bad (_("This string may not contain \'\\0\'"));
4718             }
4719         }
4720     }
4721   return s;
4722 }
4723 \f
4724 /*
4725  *                      demand_copy_string()
4726  *
4727  * Demand string, but return a safe (=private) copy of the string.
4728  * Return NULL if we can't read a string here.
4729  */
4730 char *
4731 demand_copy_string (lenP)
4732      int *lenP;
4733 {
4734   register unsigned int c;
4735   register int len;
4736   char *retval;
4737
4738   len = 0;
4739   SKIP_WHITESPACE ();
4740   if (*input_line_pointer == '\"')
4741     {
4742       input_line_pointer++;     /* Skip opening quote. */
4743
4744       while (is_a_char (c = next_char_of_string ()))
4745         {
4746           obstack_1grow (&notes, c);
4747           len++;
4748         }
4749       /* JF this next line is so demand_copy_C_string will return a
4750          null terminated string. */
4751       obstack_1grow (&notes, '\0');
4752       retval = obstack_finish (&notes);
4753     }
4754   else
4755     {
4756       as_warn (_("Missing string"));
4757       retval = NULL;
4758       ignore_rest_of_line ();
4759     }
4760   *lenP = len;
4761   return (retval);
4762 }                               /* demand_copy_string() */
4763 \f
4764 /*
4765  *              is_it_end_of_statement()
4766  *
4767  * In:  Input_line_pointer->next character.
4768  *
4769  * Do:  Skip input_line_pointer over all whitespace.
4770  *
4771  * Out: 1 if input_line_pointer->end-of-line.
4772 */
4773 int 
4774 is_it_end_of_statement ()
4775 {
4776   SKIP_WHITESPACE ();
4777   return (is_end_of_line[(unsigned char) *input_line_pointer]);
4778 }                               /* is_it_end_of_statement() */
4779
4780 void 
4781 equals (sym_name, reassign)
4782      char *sym_name;
4783      int reassign;
4784 {
4785   register symbolS *symbolP;    /* symbol we are working with */
4786   char *stop = NULL;
4787   char stopc;
4788
4789   input_line_pointer++;
4790   if (*input_line_pointer == '=')
4791     input_line_pointer++;
4792
4793   while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
4794     input_line_pointer++;
4795
4796   if (flag_mri)
4797     stop = mri_comment_field (&stopc);
4798
4799   if (sym_name[0] == '.' && sym_name[1] == '\0')
4800     {
4801       /* Turn '. = mumble' into a .org mumble */
4802       register segT segment;
4803       expressionS exp;
4804
4805       segment = get_known_segmented_expression (&exp);
4806       if (!need_pass_2)
4807         do_org (segment, &exp, 0);
4808     }
4809   else
4810     {
4811       symbolP = symbol_find_or_make (sym_name);
4812       /* Permit register names to be redefined.  */
4813       if (! reassign
4814           && S_IS_DEFINED (symbolP)
4815           && S_GET_SEGMENT (symbolP) != reg_section)
4816         as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
4817       pseudo_set (symbolP);
4818     }
4819
4820   if (flag_mri)
4821      {
4822        ignore_rest_of_line (); /* check garbage after the expression */
4823        mri_comment_end (stop, stopc);
4824      }
4825 }                               /* equals() */
4826
4827 /* .include -- include a file at this point. */
4828
4829 /* ARGSUSED */
4830 void 
4831 s_include (arg)
4832      int arg;
4833 {
4834   char *newbuf;
4835   char *filename;
4836   int i;
4837   FILE *try;
4838   char *path;
4839
4840   if (! flag_m68k_mri)
4841     {
4842       filename = demand_copy_string (&i);
4843       if (filename == NULL)
4844         {
4845           /* demand_copy_string has already printed an error and
4846              called ignore_rest_of_line.  */
4847           return;
4848         }
4849     }
4850   else
4851     {
4852       SKIP_WHITESPACE ();
4853       i = 0;
4854       while (! is_end_of_line[(unsigned char) *input_line_pointer]
4855              && *input_line_pointer != ' '
4856              && *input_line_pointer != '\t')
4857         {
4858           obstack_1grow (&notes, *input_line_pointer);
4859           ++input_line_pointer;
4860           ++i;
4861         }
4862       obstack_1grow (&notes, '\0');
4863       filename = obstack_finish (&notes);
4864       while (! is_end_of_line[(unsigned char) *input_line_pointer])
4865         ++input_line_pointer;
4866     }
4867   demand_empty_rest_of_line ();
4868   path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ );
4869   for (i = 0; i < include_dir_count; i++)
4870     {
4871       strcpy (path, include_dirs[i]);
4872       strcat (path, "/");
4873       strcat (path, filename);
4874       if (0 != (try = fopen (path, "r")))
4875         {
4876           fclose (try);
4877           goto gotit;
4878         }
4879     }
4880   free (path);
4881   path = filename;
4882 gotit:
4883   /* malloc Storage leak when file is found on path.  FIXME-SOMEDAY. */
4884   register_dependency (path);
4885   newbuf = input_scrub_include_file (path, input_line_pointer);
4886   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
4887 }                               /* s_include() */
4888
4889 void 
4890 add_include_dir (path)
4891      char *path;
4892 {
4893   int i;
4894
4895   if (include_dir_count == 0)
4896     {
4897       include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
4898       include_dirs[0] = ".";    /* Current dir */
4899       include_dir_count = 2;
4900     }
4901   else
4902     {
4903       include_dir_count++;
4904       include_dirs = (char **) realloc (include_dirs,
4905                                 include_dir_count * sizeof (*include_dirs));
4906     }
4907
4908   include_dirs[include_dir_count - 1] = path;   /* New one */
4909
4910   i = strlen (path);
4911   if (i > include_dir_maxlen)
4912     include_dir_maxlen = i;
4913 }                               /* add_include_dir() */
4914 \f
4915 /* Output debugging information to denote the source file.  */
4916
4917 static void
4918 generate_file_debug ()
4919 {
4920   if (debug_type == DEBUG_STABS)
4921     stabs_generate_asm_file ();
4922 }
4923
4924 /* Output line number debugging information for the current source line.  */
4925
4926 void
4927 generate_lineno_debug ()
4928 {
4929 #ifdef ECOFF_DEBUGGING
4930   /* ECOFF assemblers automatically generate debugging information. 
4931      FIXME: This should probably be handled elsewhere.  */
4932   if (debug_type == DEBUG_UNSPECIFIED)
4933     {
4934       if (ECOFF_DEBUGGING && ecoff_no_current_file ())
4935         debug_type = DEBUG_ECOFF;
4936       else
4937         debug_type = DEBUG_NONE;
4938     }
4939 #endif
4940
4941   switch (debug_type)
4942     {
4943     case DEBUG_UNSPECIFIED:
4944     case DEBUG_NONE:
4945       break;
4946     case DEBUG_STABS:
4947       stabs_generate_asm_lineno ();
4948       break;
4949     case DEBUG_ECOFF:
4950       ecoff_generate_asm_lineno ();
4951       break;
4952     case DEBUG_DWARF:
4953     case DEBUG_DWARF2:
4954       /* FIXME.  */
4955       break;
4956     }
4957 }
4958
4959 /* Output debugging information to mark a function entry point or end point.
4960    END_P is zero for .func, and non-zero for .endfunc.  */
4961
4962 void
4963 s_func (end_p)
4964      int end_p;
4965 {
4966   do_s_func (end_p, NULL);
4967 }
4968
4969 /* Subroutine of s_func so targets can choose a different default prefix.
4970    If DEFAULT_PREFIX is NULL, use the target's "leading char".  */
4971
4972 void
4973 do_s_func (end_p, default_prefix)
4974      int end_p;
4975      const char *default_prefix;
4976 {
4977   /* Record the current function so that we can issue an error message for
4978      misplaced .func,.endfunc, and also so that .endfunc needs no
4979      arguments.  */
4980   static char *current_name;
4981   static char *current_label;
4982
4983   if (end_p)
4984     {
4985       if (current_name == NULL)
4986         {
4987           as_bad (_("missing .func"));
4988           ignore_rest_of_line ();
4989           return;
4990         }
4991
4992       if (debug_type == DEBUG_STABS)
4993         stabs_generate_asm_endfunc (current_name, current_label);
4994
4995       current_name = current_label = NULL;
4996     }
4997   else /* ! end_p */
4998     {
4999       char *name,*label;
5000       char delim1,delim2;
5001
5002       if (current_name != NULL)
5003         {
5004           as_bad (_(".endfunc missing for previous .func"));
5005           ignore_rest_of_line ();
5006           return;
5007         }
5008
5009       name = input_line_pointer;
5010       delim1 = get_symbol_end ();
5011       name = xstrdup (name);
5012       *input_line_pointer = delim1;
5013       SKIP_WHITESPACE ();
5014       if (*input_line_pointer != ',')
5015         {
5016           if (default_prefix)
5017             asprintf (&label, "%s%s", default_prefix, name);
5018           else
5019             {
5020               char leading_char = 0;
5021 #ifdef BFD_ASSEMBLER
5022               leading_char = bfd_get_symbol_leading_char (stdoutput);
5023 #endif
5024               /* Missing entry point, use function's name with the leading
5025                  char prepended.  */
5026               if (leading_char)
5027                 asprintf (&label, "%c%s", leading_char, name);
5028               else
5029                 label = name;
5030             }
5031         }
5032       else
5033         {
5034           ++input_line_pointer;
5035           SKIP_WHITESPACE ();
5036           label = input_line_pointer;
5037           delim2 = get_symbol_end ();
5038           label = xstrdup (label);
5039           *input_line_pointer = delim2;
5040         }
5041
5042       if (debug_type == DEBUG_STABS)
5043         stabs_generate_asm_func (name, label);
5044
5045       current_name = name;
5046       current_label = label;
5047     }
5048
5049   demand_empty_rest_of_line ();
5050 }
5051 \f
5052 void 
5053 s_ignore (arg)
5054      int arg;
5055 {
5056   while (!is_end_of_line[(unsigned char) *input_line_pointer])
5057     {
5058       ++input_line_pointer;
5059     }
5060   ++input_line_pointer;
5061 }
5062
5063
5064 void
5065 read_print_statistics (file)
5066      FILE *file;
5067 {
5068   hash_print_statistics (file, "pseudo-op table", po_hash);
5069 }
5070
5071 /* end of read.c */