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