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