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