Fix up last commit.
[external/binutils.git] / gas / read.c
1 /* read.c - read a source file -
2    Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
3    1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4    2010, 2011, 2012  Free Software Foundation, Inc.
5
6    This file is part of GAS, the GNU Assembler.
7
8    GAS is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3, or (at your option)
11    any later version.
12
13    GAS is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GAS; see the file COPYING.  If not, write to the Free
20    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21    02110-1301, USA.  */
22
23 /* If your chars aren't 8 bits, you will change this a bit (eg. to 0xFF).
24    But then, GNU isn't spozed to run on your machine anyway.
25    (RMS is so shortsighted sometimes.)  */
26 #define MASK_CHAR ((int)(unsigned char) -1)
27
28 /* This is the largest known floating point format (for now). It will
29    grow when we do 4361 style flonums.  */
30 #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16)
31
32 /* Routines that read assembler source text to build spaghetti in memory.
33    Another group of these functions is in the expr.c module.  */
34
35 #include "as.h"
36 #include "safe-ctype.h"
37 #include "subsegs.h"
38 #include "sb.h"
39 #include "macro.h"
40 #include "obstack.h"
41 #include "ecoff.h"
42 #include "dw2gencfi.h"
43
44 #ifndef TC_START_LABEL
45 #define TC_START_LABEL(x,y,z) (x == ':')
46 #endif
47
48 /* Set by the object-format or the target.  */
49 #ifndef TC_IMPLICIT_LCOMM_ALIGNMENT
50 #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR)                \
51   do                                                            \
52     {                                                           \
53       if ((SIZE) >= 8)                                          \
54         (P2VAR) = 3;                                            \
55       else if ((SIZE) >= 4)                                     \
56         (P2VAR) = 2;                                            \
57       else if ((SIZE) >= 2)                                     \
58         (P2VAR) = 1;                                            \
59       else                                                      \
60         (P2VAR) = 0;                                            \
61     }                                                           \
62   while (0)
63 #endif
64
65 char *input_line_pointer;       /*->next char of source file to parse.  */
66
67 #if BITS_PER_CHAR != 8
68 /*  The following table is indexed by[(char)] and will break if
69     a char does not have exactly 256 states (hopefully 0:255!)!  */
70 die horribly;
71 #endif
72
73 #ifndef LEX_AT
74 #define LEX_AT 0
75 #endif
76
77 #ifndef LEX_BR
78 /* The RS/6000 assembler uses {,},[,] as parts of symbol names.  */
79 #define LEX_BR 0
80 #endif
81
82 #ifndef LEX_PCT
83 /* The Delta 68k assembler permits % inside label names.  */
84 #define LEX_PCT 0
85 #endif
86
87 #ifndef LEX_QM
88 /* The PowerPC Windows NT assemblers permits ? inside label names.  */
89 #define LEX_QM 0
90 #endif
91
92 #ifndef LEX_HASH
93 /* The IA-64 assembler uses # as a suffix designating a symbol.  We include
94    it in the symbol and strip it out in tc_canonicalize_symbol_name.  */
95 #define LEX_HASH 0
96 #endif
97
98 #ifndef LEX_DOLLAR
99 #define LEX_DOLLAR 3
100 #endif
101
102 #ifndef LEX_TILDE
103 /* The Delta 68k assembler permits ~ at start of label names.  */
104 #define LEX_TILDE 0
105 #endif
106
107 /* Used by is_... macros. our ctype[].  */
108 char lex_type[256] = {
109   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* @ABCDEFGHIJKLMNO */
110   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* PQRSTUVWXYZ[\]^_ */
111   0, 0, 0, LEX_HASH, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */
112   1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM,  /* 0123456789:;<=>? */
113   LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,  /* @ABCDEFGHIJKLMNO */
114   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */
115   0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,       /* `abcdefghijklmno */
116   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~.  */
117   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
118   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
119   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
120   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
121   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
122   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
123   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
124   3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
125 };
126
127 /* In: a character.
128    Out: 1 if this character ends a line.
129         2 if this character is a line separator.  */
130 char is_end_of_line[256] = {
131 #ifdef CR_EOL
132   1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0,       /* @abcdefghijklmno */
133 #else
134   1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,       /* @abcdefghijklmno */
135 #endif
136   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
137   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* _!"#$%&'()*+,-./ */
138   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* 0123456789:;<=>? */
139   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
140   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
141   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
142   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
143   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
144   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
145   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
146   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
147   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
148   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
149   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,       /* */
150   0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0        /* */
151 };
152
153 #ifndef TC_CASE_SENSITIVE
154 char original_case_string[128];
155 #endif
156
157 /* Functions private to this file.  */
158
159 static char *buffer;    /* 1st char of each buffer of lines is here.  */
160 static char *buffer_limit;      /*->1 + last char in buffer.  */
161
162 /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1
163    in the tc-<CPU>.h file.  See the "Porting GAS" section of the
164    internals manual.  */
165 int target_big_endian = TARGET_BYTES_BIG_ENDIAN;
166
167 /* Variables for handling include file directory table.  */
168
169 /* Table of pointers to directories to search for .include's.  */
170 char **include_dirs;
171
172 /* How many are in the table.  */
173 int include_dir_count;
174
175 /* Length of longest in table.  */
176 int include_dir_maxlen = 1;
177
178 #ifndef WORKING_DOT_WORD
179 struct broken_word *broken_words;
180 int new_broken_words;
181 #endif
182
183 /* The current offset into the absolute section.  We don't try to
184    build frags in the absolute section, since no data can be stored
185    there.  We just keep track of the current offset.  */
186 addressT abs_section_offset;
187
188 /* If this line had an MRI style label, it is stored in this variable.
189    This is used by some of the MRI pseudo-ops.  */
190 symbolS *line_label;
191
192 /* This global variable is used to support MRI common sections.  We
193    translate such sections into a common symbol.  This variable is
194    non-NULL when we are in an MRI common section.  */
195 symbolS *mri_common_symbol;
196
197 /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we
198    need to align to an even byte boundary unless the next pseudo-op is
199    dc.b, ds.b, or dcb.b.  This variable is set to 1 if an alignment
200    may be needed.  */
201 static int mri_pending_align;
202
203 #ifndef NO_LISTING
204 #ifdef OBJ_ELF
205 /* This variable is set to be non-zero if the next string we see might
206    be the name of the source file in DWARF debugging information.  See
207    the comment in emit_expr for the format we look for.  */
208 static int dwarf_file_string;
209 #endif
210 #endif
211
212 /* If the target defines the md_frag_max_var hook then we know
213    enough to implement the .bundle_align_mode features.  */
214 #ifdef md_frag_max_var
215 # define HANDLE_BUNDLE
216 #endif
217
218 #ifdef HANDLE_BUNDLE
219 /* .bundle_align_mode sets this.  Normally it's zero.  When nonzero,
220    it's the exponent of the bundle size, and aligned instruction bundle
221    mode is in effect.  */
222 static unsigned int bundle_align_p2;
223
224 /* These are set by .bundle_lock and .bundle_unlock.  .bundle_lock sets
225    bundle_lock_frag to frag_now and then starts a new frag with
226    frag_align_code.  At the same time, bundle_lock_frain gets frchain_now,
227    so that .bundle_unlock can verify that we didn't change segments.
228    .bundle_unlock resets both to NULL.  If we detect a bundling violation,
229    then we reset bundle_lock_frchain to NULL as an indicator that we've
230    already diagnosed the error with as_bad and don't need a cascade of
231    redundant errors, but bundle_lock_frag remains set to indicate that
232    we are expecting to see .bundle_unlock.  */
233 static fragS *bundle_lock_frag;
234 static frchainS *bundle_lock_frchain;
235 #endif
236
237 static void do_s_func (int end_p, const char *default_prefix);
238 static void do_align (int, char *, int, int);
239 static void s_align (int, int);
240 static void s_altmacro (int);
241 static void s_bad_end (int);
242 #ifdef OBJ_ELF
243 static void s_gnu_attribute (int);
244 #endif
245 static void s_reloc (int);
246 static int hex_float (int, char *);
247 static segT get_known_segmented_expression (expressionS * expP);
248 static void pobegin (void);
249 static int get_non_macro_line_sb (sb *);
250 static void generate_file_debug (void);
251 static char *_find_end_of_line (char *, int, int, int);
252 \f
253 void
254 read_begin (void)
255 {
256   const char *p;
257
258   pobegin ();
259   obj_read_begin_hook ();
260
261   /* Something close -- but not too close -- to a multiple of 1024.
262      The debugging malloc I'm using has 24 bytes of overhead.  */
263   obstack_begin (&notes, chunksize);
264   obstack_begin (&cond_obstack, chunksize);
265
266   /* Use machine dependent syntax.  */
267   for (p = line_separator_chars; *p; p++)
268     is_end_of_line[(unsigned char) *p] = 2;
269   /* Use more.  FIXME-SOMEDAY.  */
270
271   if (flag_mri)
272     lex_type['?'] = 3;
273 }
274 \f
275 #ifndef TC_ADDRESS_BYTES
276 #define TC_ADDRESS_BYTES address_bytes
277
278 static inline int
279 address_bytes (void)
280 {
281   /* Choose smallest of 1, 2, 4, 8 bytes that is large enough to
282      contain an address.  */
283   int n = (stdoutput->arch_info->bits_per_address - 1) / 8;
284   n |= n >> 1;
285   n |= n >> 2;
286   n += 1;
287   return n;
288 }
289 #endif
290
291 /* Set up pseudo-op tables.  */
292
293 static struct hash_control *po_hash;
294
295 static const pseudo_typeS potable[] = {
296   {"abort", s_abort, 0},
297   {"align", s_align_ptwo, 0},
298   {"altmacro", s_altmacro, 1},
299   {"ascii", stringer, 8+0},
300   {"asciz", stringer, 8+1},
301   {"balign", s_align_bytes, 0},
302   {"balignw", s_align_bytes, -2},
303   {"balignl", s_align_bytes, -4},
304 /* block  */
305 #ifdef HANDLE_BUNDLE
306   {"bundle_align_mode", s_bundle_align_mode, 0},
307   {"bundle_lock", s_bundle_lock, 0},
308   {"bundle_unlock", s_bundle_unlock, 0},
309 #endif
310   {"byte", cons, 1},
311   {"comm", s_comm, 0},
312   {"common", s_mri_common, 0},
313   {"common.s", s_mri_common, 1},
314   {"data", s_data, 0},
315   {"dc", cons, 2},
316 #ifdef TC_ADDRESS_BYTES
317   {"dc.a", cons, 0},
318 #endif
319   {"dc.b", cons, 1},
320   {"dc.d", float_cons, 'd'},
321   {"dc.l", cons, 4},
322   {"dc.s", float_cons, 'f'},
323   {"dc.w", cons, 2},
324   {"dc.x", float_cons, 'x'},
325   {"dcb", s_space, 2},
326   {"dcb.b", s_space, 1},
327   {"dcb.d", s_float_space, 'd'},
328   {"dcb.l", s_space, 4},
329   {"dcb.s", s_float_space, 'f'},
330   {"dcb.w", s_space, 2},
331   {"dcb.x", s_float_space, 'x'},
332   {"ds", s_space, 2},
333   {"ds.b", s_space, 1},
334   {"ds.d", s_space, 8},
335   {"ds.l", s_space, 4},
336   {"ds.p", s_space, 12},
337   {"ds.s", s_space, 4},
338   {"ds.w", s_space, 2},
339   {"ds.x", s_space, 12},
340   {"debug", s_ignore, 0},
341 #ifdef S_SET_DESC
342   {"desc", s_desc, 0},
343 #endif
344 /* dim  */
345   {"double", float_cons, 'd'},
346 /* dsect  */
347   {"eject", listing_eject, 0},  /* Formfeed listing.  */
348   {"else", s_else, 0},
349   {"elsec", s_else, 0},
350   {"elseif", s_elseif, (int) O_ne},
351   {"end", s_end, 0},
352   {"endc", s_endif, 0},
353   {"endfunc", s_func, 1},
354   {"endif", s_endif, 0},
355   {"endm", s_bad_end, 0},
356   {"endr", s_bad_end, 1},
357 /* endef  */
358   {"equ", s_set, 0},
359   {"equiv", s_set, 1},
360   {"eqv", s_set, -1},
361   {"err", s_err, 0},
362   {"error", s_errwarn, 1},
363   {"exitm", s_mexit, 0},
364 /* extend  */
365   {"extern", s_ignore, 0},      /* We treat all undef as ext.  */
366   {"appfile", s_app_file, 1},
367   {"appline", s_app_line, 1},
368   {"fail", s_fail, 0},
369   {"file", s_app_file, 0},
370   {"fill", s_fill, 0},
371   {"float", float_cons, 'f'},
372   {"format", s_ignore, 0},
373   {"func", s_func, 0},
374   {"global", s_globl, 0},
375   {"globl", s_globl, 0},
376 #ifdef OBJ_ELF
377   {"gnu_attribute", s_gnu_attribute, 0},
378 #endif
379   {"hword", cons, 2},
380   {"if", s_if, (int) O_ne},
381   {"ifb", s_ifb, 1},
382   {"ifc", s_ifc, 0},
383   {"ifdef", s_ifdef, 0},
384   {"ifeq", s_if, (int) O_eq},
385   {"ifeqs", s_ifeqs, 0},
386   {"ifge", s_if, (int) O_ge},
387   {"ifgt", s_if, (int) O_gt},
388   {"ifle", s_if, (int) O_le},
389   {"iflt", s_if, (int) O_lt},
390   {"ifnb", s_ifb, 0},
391   {"ifnc", s_ifc, 1},
392   {"ifndef", s_ifdef, 1},
393   {"ifne", s_if, (int) O_ne},
394   {"ifnes", s_ifeqs, 1},
395   {"ifnotdef", s_ifdef, 1},
396   {"incbin", s_incbin, 0},
397   {"include", s_include, 0},
398   {"int", cons, 4},
399   {"irp", s_irp, 0},
400   {"irep", s_irp, 0},
401   {"irpc", s_irp, 1},
402   {"irepc", s_irp, 1},
403   {"lcomm", s_lcomm, 0},
404   {"lflags", s_ignore, 0},      /* Listing flags.  */
405   {"linefile", s_app_line, 0},
406   {"linkonce", s_linkonce, 0},
407   {"list", listing_list, 1},    /* Turn listing on.  */
408   {"llen", listing_psize, 1},
409   {"long", cons, 4},
410   {"lsym", s_lsym, 0},
411   {"macro", s_macro, 0},
412   {"mexit", s_mexit, 0},
413   {"mri", s_mri, 0},
414   {".mri", s_mri, 0},   /* Special case so .mri works in MRI mode.  */
415   {"name", s_ignore, 0},
416   {"noaltmacro", s_altmacro, 0},
417   {"noformat", s_ignore, 0},
418   {"nolist", listing_list, 0},  /* Turn listing off.  */
419   {"nopage", listing_nopage, 0},
420   {"octa", cons, 16},
421   {"offset", s_struct, 0},
422   {"org", s_org, 0},
423   {"p2align", s_align_ptwo, 0},
424   {"p2alignw", s_align_ptwo, -2},
425   {"p2alignl", s_align_ptwo, -4},
426   {"page", listing_eject, 0},
427   {"plen", listing_psize, 0},
428   {"print", s_print, 0},
429   {"psize", listing_psize, 0},  /* Set paper size.  */
430   {"purgem", s_purgem, 0},
431   {"quad", cons, 8},
432   {"reloc", s_reloc, 0},
433   {"rep", s_rept, 0},
434   {"rept", s_rept, 0},
435   {"rva", s_rva, 4},
436   {"sbttl", listing_title, 1},  /* Subtitle of listing.  */
437 /* scl  */
438 /* sect  */
439   {"set", s_set, 0},
440   {"short", cons, 2},
441   {"single", float_cons, 'f'},
442 /* size  */
443   {"space", s_space, 0},
444   {"skip", s_space, 0},
445   {"sleb128", s_leb128, 1},
446   {"spc", s_ignore, 0},
447   {"stabd", s_stab, 'd'},
448   {"stabn", s_stab, 'n'},
449   {"stabs", s_stab, 's'},
450   {"string", stringer, 8+1},
451   {"string8", stringer, 8+1},
452   {"string16", stringer, 16+1},
453   {"string32", stringer, 32+1},
454   {"string64", stringer, 64+1},
455   {"struct", s_struct, 0},
456 /* tag  */
457   {"text", s_text, 0},
458
459   /* This is for gcc to use.  It's only just been added (2/94), so gcc
460      won't be able to use it for a while -- probably a year or more.
461      But once this has been released, check with gcc maintainers
462      before deleting it or even changing the spelling.  */
463   {"this_GCC_requires_the_GNU_assembler", s_ignore, 0},
464   /* If we're folding case -- done for some targets, not necessarily
465      all -- the above string in an input file will be converted to
466      this one.  Match it either way...  */
467   {"this_gcc_requires_the_gnu_assembler", s_ignore, 0},
468
469   {"title", listing_title, 0},  /* Listing title.  */
470   {"ttl", listing_title, 0},
471 /* type  */
472   {"uleb128", s_leb128, 0},
473 /* use  */
474 /* val  */
475   {"xcom", s_comm, 0},
476   {"xdef", s_globl, 0},
477   {"xref", s_ignore, 0},
478   {"xstabs", s_xstab, 's'},
479   {"warning", s_errwarn, 0},
480   {"weakref", s_weakref, 0},
481   {"word", cons, 2},
482   {"zero", s_space, 0},
483   {NULL, NULL, 0}                       /* End sentinel.  */
484 };
485
486 static offsetT
487 get_absolute_expr (expressionS *exp)
488 {
489   expression_and_evaluate (exp);
490   if (exp->X_op != O_constant)
491     {
492       if (exp->X_op != O_absent)
493         as_bad (_("bad or irreducible absolute expression"));
494       exp->X_add_number = 0;
495     }
496   return exp->X_add_number;
497 }
498
499 offsetT
500 get_absolute_expression (void)
501 {
502   expressionS exp;
503
504   return get_absolute_expr (&exp);
505 }
506
507 static int pop_override_ok = 0;
508 static const char *pop_table_name;
509
510 void
511 pop_insert (const pseudo_typeS *table)
512 {
513   const char *errtxt;
514   const pseudo_typeS *pop;
515   for (pop = table; pop->poc_name; pop++)
516     {
517       errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
518       if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
519         as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
520                   errtxt);
521     }
522 }
523
524 #ifndef md_pop_insert
525 #define md_pop_insert()         pop_insert(md_pseudo_table)
526 #endif
527
528 #ifndef obj_pop_insert
529 #define obj_pop_insert()        pop_insert(obj_pseudo_table)
530 #endif
531
532 #ifndef cfi_pop_insert
533 #define cfi_pop_insert()        pop_insert(cfi_pseudo_table)
534 #endif
535
536 static void
537 pobegin (void)
538 {
539   po_hash = hash_new ();
540
541   /* Do the target-specific pseudo ops.  */
542   pop_table_name = "md";
543   md_pop_insert ();
544
545   /* Now object specific.  Skip any that were in the target table.  */
546   pop_table_name = "obj";
547   pop_override_ok = 1;
548   obj_pop_insert ();
549
550   /* Now portable ones.  Skip any that we've seen already.  */
551   pop_table_name = "standard";
552   pop_insert (potable);
553
554   /* Now CFI ones.  */
555   pop_table_name = "cfi";
556   pop_override_ok = 1;
557   cfi_pop_insert ();
558 }
559 \f
560 #define HANDLE_CONDITIONAL_ASSEMBLY()                                   \
561   if (ignore_input ())                                                  \
562     {                                                                   \
563       char *eol = find_end_of_line (input_line_pointer, flag_m68k_mri); \
564       input_line_pointer = (input_line_pointer <= buffer_limit          \
565                             && eol >= buffer_limit)                     \
566                            ? buffer_limit                               \
567                            : eol + 1;                                   \
568       continue;                                                         \
569     }
570
571 /* This function is used when scrubbing the characters between #APP
572    and #NO_APP.  */
573
574 static char *scrub_string;
575 static char *scrub_string_end;
576
577 static int
578 scrub_from_string (char *buf, int buflen)
579 {
580   int copy;
581
582   copy = scrub_string_end - scrub_string;
583   if (copy > buflen)
584     copy = buflen;
585   memcpy (buf, scrub_string, copy);
586   scrub_string += copy;
587   return copy;
588 }
589
590 /* Helper function of read_a_source_file, which tries to expand a macro.  */
591 static int
592 try_macro (char term, const char *line)
593 {
594   sb out;
595   const char *err;
596   macro_entry *macro;
597
598   if (check_macro (line, &out, &err, &macro))
599     {
600       if (err != NULL)
601         as_bad ("%s", err);
602       *input_line_pointer++ = term;
603       input_scrub_include_sb (&out,
604                               input_line_pointer, 1);
605       sb_kill (&out);
606       buffer_limit =
607         input_scrub_next_buffer (&input_line_pointer);
608 #ifdef md_macro_info
609       md_macro_info (macro);
610 #endif
611       return 1;
612     }
613   return 0;
614 }
615
616 #ifdef HANDLE_BUNDLE
617 /* Start a new instruction bundle.  Returns the rs_align_code frag that
618    will be used to align the new bundle.  */
619 static fragS *
620 start_bundle (void)
621 {
622   fragS *frag = frag_now;
623
624   frag_align_code (0, 0);
625
626   while (frag->fr_type != rs_align_code)
627     frag = frag->fr_next;
628
629   gas_assert (frag != frag_now);
630
631   return frag;
632 }
633
634 /* Calculate the maximum size after relaxation of the region starting
635    at the given frag and extending through frag_now (which is unfinished).  */
636 static unsigned int
637 pending_bundle_size (fragS *frag)
638 {
639   unsigned int offset = frag->fr_fix;
640   unsigned int size = 0;
641
642   gas_assert (frag != frag_now);
643   gas_assert (frag->fr_type == rs_align_code);
644
645   while (frag != frag_now)
646     {
647       /* This should only happen in what will later become an error case.  */
648       if (frag == NULL)
649         return 0;
650
651       size += frag->fr_fix;
652       if (frag->fr_type == rs_machine_dependent)
653         size += md_frag_max_var (frag);
654
655       frag = frag->fr_next;
656     }
657
658   gas_assert (frag == frag_now);
659   size += frag_now_fix ();
660   if (frag->fr_type == rs_machine_dependent)
661     size += md_frag_max_var (frag);
662
663   gas_assert (size >= offset);
664
665   return size - offset;
666 }
667
668 /* Finish off the frag created to ensure bundle alignment.  */
669 static void
670 finish_bundle (fragS *frag, unsigned int size)
671 {
672   gas_assert (bundle_align_p2 > 0);
673   gas_assert (frag->fr_type == rs_align_code);
674
675   if (size > 1)
676     {
677       /* If there is more than a single byte, then we need to set up the
678          alignment frag.  Otherwise we leave it at its initial state from
679          calling frag_align_code (0, 0), so that it does nothing.  */
680       frag->fr_offset = bundle_align_p2;
681       frag->fr_subtype = size - 1;
682     }
683
684   /* We do this every time rather than just in s_bundle_align_mode
685      so that we catch any affected section without needing hooks all
686      over for all paths that do section changes.  It's cheap enough.  */
687   record_alignment (now_seg, bundle_align_p2 - OCTETS_PER_BYTE_POWER);
688 }
689
690 /* Assemble one instruction.  This takes care of the bundle features
691    around calling md_assemble.  */
692 static void
693 assemble_one (char *line)
694 {
695   fragS *insn_start_frag = NULL;
696
697   if (bundle_lock_frchain != NULL && bundle_lock_frchain != frchain_now)
698     {
699       as_bad (_("cannot change section or subsection inside .bundle_lock"));
700       /* Clearing this serves as a marker that we have already complained.  */
701       bundle_lock_frchain = NULL;
702     }
703
704   if (bundle_lock_frchain == NULL && bundle_align_p2 > 0)
705     insn_start_frag = start_bundle ();
706
707   md_assemble (line);
708
709   if (bundle_lock_frchain != NULL)
710     {
711       /* Make sure this hasn't pushed the locked sequence
712          past the bundle size.  */
713       unsigned int bundle_size = pending_bundle_size (bundle_lock_frag);
714       if (bundle_size > (1U << bundle_align_p2))
715         as_bad (_("\
716 .bundle_lock sequence at %u bytes but .bundle_align_mode limit is %u bytes"),
717                 bundle_size, 1U << bundle_align_p2);
718     }
719   else if (bundle_align_p2 > 0)
720     {
721       unsigned int insn_size = pending_bundle_size (insn_start_frag);
722
723       if (insn_size > (1U << bundle_align_p2))
724         as_bad (_("\
725 single instruction is %u bytes long but .bundle_align_mode limit is %u"),
726                 (unsigned int) insn_size, 1U << bundle_align_p2);
727
728       finish_bundle (insn_start_frag, insn_size);
729     }
730 }
731
732 #else  /* !HANDLE_BUNDLE */
733
734 # define assemble_one(line) md_assemble(line)
735
736 #endif  /* HANDLE_BUNDLE */
737
738 /* We read the file, putting things into a web that represents what we
739    have been reading.  */
740 void
741 read_a_source_file (char *name)
742 {
743   char c;
744   char *s;              /* String of symbol, '\0' appended.  */
745   int temp;
746   pseudo_typeS *pop;
747
748 #ifdef WARN_COMMENTS
749   found_comment = 0;
750 #endif
751
752   buffer = input_scrub_new_file (name);
753
754   listing_file (name);
755   listing_newline (NULL);
756   register_dependency (name);
757
758   /* Generate debugging information before we've read anything in to denote
759      this file as the "main" source file and not a subordinate one
760      (e.g. N_SO vs N_SOL in stabs).  */
761   generate_file_debug ();
762
763   while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0)
764     {                           /* We have another line to parse.  */
765 #ifndef NO_LISTING
766       /* In order to avoid listing macro expansion lines with labels
767          multiple times, keep track of which line was last issued.  */
768       static char *last_eol;
769
770       last_eol = NULL;
771 #endif
772       while (input_line_pointer < buffer_limit)
773         {
774           bfd_boolean was_new_line;
775           /* We have more of this buffer to parse.  */
776
777           /* We now have input_line_pointer->1st char of next line.
778              If input_line_pointer [-1] == '\n' then we just
779              scanned another line: so bump line counters.  */
780           was_new_line = is_end_of_line[(unsigned char) input_line_pointer[-1]];
781           if (was_new_line)
782             {
783               symbol_set_value_now (&dot_symbol);
784 #ifdef md_start_line_hook
785               md_start_line_hook ();
786 #endif
787               if (input_line_pointer[-1] == '\n')
788                 bump_line_counters ();
789             }
790
791 #ifndef NO_LISTING
792           /* If listing is on, and we are expanding a macro, then give
793              the listing code the contents of the expanded line.  */
794           if (listing)
795             {
796               if ((listing & LISTING_MACEXP) && macro_nest > 0)
797                 {
798                   /* Find the end of the current expanded macro line.  */
799                   s = find_end_of_line (input_line_pointer, flag_m68k_mri);
800
801                   if (s != last_eol)
802                     {
803                       char *copy;
804                       int len;
805
806                       last_eol = s;
807                       /* Copy it for safe keeping.  Also give an indication of
808                          how much macro nesting is involved at this point.  */
809                       len = s - input_line_pointer;
810                       copy = (char *) xmalloc (len + macro_nest + 2);
811                       memset (copy, '>', macro_nest);
812                       copy[macro_nest] = ' ';
813                       memcpy (copy + macro_nest + 1, input_line_pointer, len);
814                       copy[macro_nest + 1 + len] = '\0';
815
816                       /* Install the line with the listing facility.  */
817                       listing_newline (copy);
818                     }
819                 }
820               else
821                 listing_newline (NULL);
822             }
823 #endif
824           if (was_new_line)
825             {
826               line_label = NULL;
827
828               if (LABELS_WITHOUT_COLONS || flag_m68k_mri)
829                 {
830                   /* Text at the start of a line must be a label, we
831                      run down and stick a colon in.  */
832                   if (is_name_beginner (*input_line_pointer))
833                     {
834                       char *line_start = input_line_pointer;
835                       int mri_line_macro;
836
837                       HANDLE_CONDITIONAL_ASSEMBLY ();
838
839                       c = get_symbol_end ();
840
841                       /* In MRI mode, the EQU and MACRO pseudoops must
842                          be handled specially.  */
843                       mri_line_macro = 0;
844                       if (flag_m68k_mri)
845                         {
846                           char *rest = input_line_pointer + 1;
847
848                           if (*rest == ':')
849                             ++rest;
850                           if (*rest == ' ' || *rest == '\t')
851                             ++rest;
852                           if ((strncasecmp (rest, "EQU", 3) == 0
853                                || strncasecmp (rest, "SET", 3) == 0)
854                               && (rest[3] == ' ' || rest[3] == '\t'))
855                             {
856                               input_line_pointer = rest + 3;
857                               equals (line_start,
858                                       strncasecmp (rest, "SET", 3) == 0);
859                               continue;
860                             }
861                           if (strncasecmp (rest, "MACRO", 5) == 0
862                               && (rest[5] == ' '
863                                   || rest[5] == '\t'
864                                   || is_end_of_line[(unsigned char) rest[5]]))
865                             mri_line_macro = 1;
866                         }
867
868                       /* In MRI mode, we need to handle the MACRO
869                          pseudo-op specially: we don't want to put the
870                          symbol in the symbol table.  */
871                       if (!mri_line_macro
872 #ifdef TC_START_LABEL_WITHOUT_COLON
873                           && TC_START_LABEL_WITHOUT_COLON(c,
874                                                           input_line_pointer)
875 #endif
876                           )
877                         line_label = colon (line_start);
878                       else
879                         line_label = symbol_create (line_start,
880                                                     absolute_section,
881                                                     (valueT) 0,
882                                                     &zero_address_frag);
883
884                       *input_line_pointer = c;
885                       if (c == ':')
886                         input_line_pointer++;
887                     }
888                 }
889             }
890
891           /* We are at the beginning of a line, or similar place.
892              We expect a well-formed assembler statement.
893              A "symbol-name:" is a statement.
894
895              Depending on what compiler is used, the order of these tests
896              may vary to catch most common case 1st.
897              Each test is independent of all other tests at the (top)
898              level.  */
899           do
900             c = *input_line_pointer++;
901           while (c == '\t' || c == ' ' || c == '\f');
902
903           /* C is the 1st significant character.
904              Input_line_pointer points after that character.  */
905           if (is_name_beginner (c))
906             {
907               /* Want user-defined label or pseudo/opcode.  */
908               HANDLE_CONDITIONAL_ASSEMBLY ();
909
910               s = --input_line_pointer;
911               c = get_symbol_end ();    /* name's delimiter.  */
912
913               /* C is character after symbol.
914                  That character's place in the input line is now '\0'.
915                  S points to the beginning of the symbol.
916                    [In case of pseudo-op, s->'.'.]
917                  Input_line_pointer->'\0' where c was.  */
918               if (TC_START_LABEL (c, s, input_line_pointer))
919                 {
920                   if (flag_m68k_mri)
921                     {
922                       char *rest = input_line_pointer + 1;
923
924                       /* In MRI mode, \tsym: set 0 is permitted.  */
925                       if (*rest == ':')
926                         ++rest;
927
928                       if (*rest == ' ' || *rest == '\t')
929                         ++rest;
930
931                       if ((strncasecmp (rest, "EQU", 3) == 0
932                            || strncasecmp (rest, "SET", 3) == 0)
933                           && (rest[3] == ' ' || rest[3] == '\t'))
934                         {
935                           input_line_pointer = rest + 3;
936                           equals (s, 1);
937                           continue;
938                         }
939                     }
940
941                   line_label = colon (s);       /* User-defined label.  */
942                   /* Put ':' back for error messages' sake.  */
943                   *input_line_pointer++ = ':';
944 #ifdef tc_check_label
945                   tc_check_label (line_label);
946 #endif
947                   /* Input_line_pointer->after ':'.  */
948                   SKIP_WHITESPACE ();
949                 }
950               else if ((c == '=' && input_line_pointer[1] == '=')
951                        || ((c == ' ' || c == '\t')
952                            && input_line_pointer[1] == '='
953                            && input_line_pointer[2] == '='))
954                 {
955                   equals (s, -1);
956                   demand_empty_rest_of_line ();
957                 }
958               else if ((c == '='
959                        || ((c == ' ' || c == '\t')
960                             && input_line_pointer[1] == '='))
961 #ifdef TC_EQUAL_IN_INSN
962                            && !TC_EQUAL_IN_INSN (c, s)
963 #endif
964                            )
965                 {
966                   equals (s, 1);
967                   demand_empty_rest_of_line ();
968                 }
969               else
970                 {
971                   /* Expect pseudo-op or machine instruction.  */
972                   pop = NULL;
973
974 #ifndef TC_CASE_SENSITIVE
975                   {
976                     char *s2 = s;
977
978                     strncpy (original_case_string, s2, sizeof (original_case_string));
979                     original_case_string[sizeof (original_case_string) - 1] = 0;
980
981                     while (*s2)
982                       {
983                         *s2 = TOLOWER (*s2);
984                         s2++;
985                       }
986                   }
987 #endif
988                   if (NO_PSEUDO_DOT || flag_m68k_mri)
989                     {
990                       /* The MRI assembler uses pseudo-ops without
991                          a period.  */
992                       pop = (pseudo_typeS *) hash_find (po_hash, s);
993                       if (pop != NULL && pop->poc_handler == NULL)
994                         pop = NULL;
995                     }
996
997                   if (pop != NULL
998                       || (!flag_m68k_mri && *s == '.'))
999                     {
1000                       /* PSEUDO - OP.
1001
1002                          WARNING: c has next char, which may be end-of-line.
1003                          We lookup the pseudo-op table with s+1 because we
1004                          already know that the pseudo-op begins with a '.'.  */
1005
1006                       if (pop == NULL)
1007                         pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
1008                       if (pop && !pop->poc_handler)
1009                         pop = NULL;
1010
1011                       /* In MRI mode, we may need to insert an
1012                          automatic alignment directive.  What a hack
1013                          this is.  */
1014                       if (mri_pending_align
1015                           && (pop == NULL
1016                               || !((pop->poc_handler == cons
1017                                     && pop->poc_val == 1)
1018                                    || (pop->poc_handler == s_space
1019                                        && pop->poc_val == 1)
1020 #ifdef tc_conditional_pseudoop
1021                                    || tc_conditional_pseudoop (pop)
1022 #endif
1023                                    || pop->poc_handler == s_if
1024                                    || pop->poc_handler == s_ifdef
1025                                    || pop->poc_handler == s_ifc
1026                                    || pop->poc_handler == s_ifeqs
1027                                    || pop->poc_handler == s_else
1028                                    || pop->poc_handler == s_endif
1029                                    || pop->poc_handler == s_globl
1030                                    || pop->poc_handler == s_ignore)))
1031                         {
1032                           do_align (1, (char *) NULL, 0, 0);
1033                           mri_pending_align = 0;
1034
1035                           if (line_label != NULL)
1036                             {
1037                               symbol_set_frag (line_label, frag_now);
1038                               S_SET_VALUE (line_label, frag_now_fix ());
1039                             }
1040                         }
1041
1042                       /* Print the error msg now, while we still can.  */
1043                       if (pop == NULL)
1044                         {
1045                           char *end = input_line_pointer;
1046
1047                           *input_line_pointer = c;
1048                           s_ignore (0);
1049                           c = *--input_line_pointer;
1050                           *input_line_pointer = '\0';
1051                           if (! macro_defined || ! try_macro (c, s))
1052                             {
1053                               *end = '\0';
1054                               as_bad (_("unknown pseudo-op: `%s'"), s);
1055                               *input_line_pointer++ = c;
1056                             }
1057                           continue;
1058                         }
1059
1060                       /* Put it back for error messages etc.  */
1061                       *input_line_pointer = c;
1062                       /* The following skip of whitespace is compulsory.
1063                          A well shaped space is sometimes all that separates
1064                          keyword from operands.  */
1065                       if (c == ' ' || c == '\t')
1066                         input_line_pointer++;
1067
1068                       /* Input_line is restored.
1069                          Input_line_pointer->1st non-blank char
1070                          after pseudo-operation.  */
1071                       (*pop->poc_handler) (pop->poc_val);
1072
1073                       /* If that was .end, just get out now.  */
1074                       if (pop->poc_handler == s_end)
1075                         goto quit;
1076                     }
1077                   else
1078                     {
1079                       /* WARNING: c has char, which may be end-of-line.  */
1080                       /* Also: input_line_pointer->`\0` where c was.  */
1081                       *input_line_pointer = c;
1082                       input_line_pointer = _find_end_of_line (input_line_pointer, flag_m68k_mri, 1, 0);
1083                       c = *input_line_pointer;
1084                       *input_line_pointer = '\0';
1085
1086                       generate_lineno_debug ();
1087
1088                       if (macro_defined && try_macro (c, s))
1089                         continue;
1090
1091                       if (mri_pending_align)
1092                         {
1093                           do_align (1, (char *) NULL, 0, 0);
1094                           mri_pending_align = 0;
1095                           if (line_label != NULL)
1096                             {
1097                               symbol_set_frag (line_label, frag_now);
1098                               S_SET_VALUE (line_label, frag_now_fix ());
1099                             }
1100                         }
1101
1102                       assemble_one (s); /* Assemble 1 instruction.  */
1103
1104                       *input_line_pointer++ = c;
1105
1106                       /* We resume loop AFTER the end-of-line from
1107                          this instruction.  */
1108                     }
1109                 }
1110               continue;
1111             }
1112
1113           /* Empty statement?  */
1114           if (is_end_of_line[(unsigned char) c])
1115             continue;
1116
1117           if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) && ISDIGIT (c))
1118             {
1119               /* local label  ("4:")  */
1120               char *backup = input_line_pointer;
1121
1122               HANDLE_CONDITIONAL_ASSEMBLY ();
1123
1124               temp = c - '0';
1125
1126               /* Read the whole number.  */
1127               while (ISDIGIT (*input_line_pointer))
1128                 {
1129                   temp = (temp * 10) + *input_line_pointer - '0';
1130                   ++input_line_pointer;
1131                 }
1132
1133               if (LOCAL_LABELS_DOLLAR
1134                   && *input_line_pointer == '$'
1135                   && *(input_line_pointer + 1) == ':')
1136                 {
1137                   input_line_pointer += 2;
1138
1139                   if (dollar_label_defined (temp))
1140                     {
1141                       as_fatal (_("label \"%d$\" redefined"), temp);
1142                     }
1143
1144                   define_dollar_label (temp);
1145                   colon (dollar_label_name (temp, 0));
1146                   continue;
1147                 }
1148
1149               if (LOCAL_LABELS_FB
1150                   && *input_line_pointer++ == ':')
1151                 {
1152                   fb_label_instance_inc (temp);
1153                   colon (fb_label_name (temp, 0));
1154                   continue;
1155                 }
1156
1157               input_line_pointer = backup;
1158             }                   /* local label  ("4:") */
1159
1160           if (c && strchr (line_comment_chars, c))
1161             {                   /* Its a comment.  Better say APP or NO_APP.  */
1162               sb sbuf;
1163               char *ends;
1164               char *new_buf;
1165               char *new_tmp;
1166               unsigned int new_length;
1167               char *tmp_buf = 0;
1168
1169               s = input_line_pointer;
1170               if (strncmp (s, "APP\n", 4))
1171                 {
1172                   /* We ignore it.  */
1173                   ignore_rest_of_line ();
1174                   continue;
1175                 }
1176               bump_line_counters ();
1177               s += 4;
1178
1179               sb_new (&sbuf);
1180               ends = strstr (s, "#NO_APP\n");
1181
1182               if (!ends)
1183                 {
1184                   unsigned int tmp_len;
1185                   unsigned int num;
1186
1187                   /* The end of the #APP wasn't in this buffer.  We
1188                      keep reading in buffers until we find the #NO_APP
1189                      that goes with this #APP  There is one.  The specs
1190                      guarantee it...  */
1191                   tmp_len = buffer_limit - s;
1192                   tmp_buf = (char *) xmalloc (tmp_len + 1);
1193                   memcpy (tmp_buf, s, tmp_len);
1194                   do
1195                     {
1196                       new_tmp = input_scrub_next_buffer (&buffer);
1197                       if (!new_tmp)
1198                         break;
1199                       else
1200                         buffer_limit = new_tmp;
1201                       input_line_pointer = buffer;
1202                       ends = strstr (buffer, "#NO_APP\n");
1203                       if (ends)
1204                         num = ends - buffer;
1205                       else
1206                         num = buffer_limit - buffer;
1207
1208                       tmp_buf = (char *) xrealloc (tmp_buf, tmp_len + num);
1209                       memcpy (tmp_buf + tmp_len, buffer, num);
1210                       tmp_len += num;
1211                     }
1212                   while (!ends);
1213
1214                   input_line_pointer = ends ? ends + 8 : NULL;
1215
1216                   s = tmp_buf;
1217                   ends = s + tmp_len;
1218
1219                 }
1220               else
1221                 {
1222                   input_line_pointer = ends + 8;
1223                 }
1224
1225               scrub_string = s;
1226               scrub_string_end = ends;
1227
1228               new_length = ends - s;
1229               new_buf = (char *) xmalloc (new_length);
1230               new_tmp = new_buf;
1231               for (;;)
1232                 {
1233                   int space;
1234                   int size;
1235
1236                   space = (new_buf + new_length) - new_tmp;
1237                   size = do_scrub_chars (scrub_from_string, new_tmp, space);
1238
1239                   if (size < space)
1240                     {
1241                       new_tmp[size] = 0;
1242                       break;
1243                     }
1244
1245                   new_buf = (char *) xrealloc (new_buf, new_length + 100);
1246                   new_tmp = new_buf + new_length;
1247                   new_length += 100;
1248                 }
1249
1250               if (tmp_buf)
1251                 free (tmp_buf);
1252
1253               /* We've "scrubbed" input to the preferred format.  In the
1254                  process we may have consumed the whole of the remaining
1255                  file (and included files).  We handle this formatted
1256                  input similar to that of macro expansion, letting
1257                  actual macro expansion (possibly nested) and other
1258                  input expansion work.  Beware that in messages, line
1259                  numbers and possibly file names will be incorrect.  */
1260               sb_add_string (&sbuf, new_buf);
1261               input_scrub_include_sb (&sbuf, input_line_pointer, 0);
1262               sb_kill (&sbuf);
1263               buffer_limit = input_scrub_next_buffer (&input_line_pointer);
1264               free (new_buf);
1265               continue;
1266             }
1267
1268           HANDLE_CONDITIONAL_ASSEMBLY ();
1269
1270 #ifdef tc_unrecognized_line
1271           if (tc_unrecognized_line (c))
1272             continue;
1273 #endif
1274           input_line_pointer--;
1275           /* Report unknown char as error.  */
1276           demand_empty_rest_of_line ();
1277         }
1278     }
1279
1280  quit:
1281   symbol_set_value_now (&dot_symbol);
1282
1283 #ifdef HANDLE_BUNDLE
1284   if (bundle_lock_frag != NULL)
1285     {
1286       as_bad_where (bundle_lock_frag->fr_file, bundle_lock_frag->fr_line,
1287                     _(".bundle_lock with no matching .bundle_unlock"));
1288       bundle_lock_frag = NULL;
1289       bundle_lock_frchain = NULL;
1290     }
1291 #endif
1292
1293 #ifdef md_cleanup
1294   md_cleanup ();
1295 #endif
1296   /* Close the input file.  */
1297   input_scrub_close ();
1298 #ifdef WARN_COMMENTS
1299   {
1300     if (warn_comment && found_comment)
1301       as_warn_where (found_comment_file, found_comment,
1302                      "first comment found here");
1303   }
1304 #endif
1305 }
1306
1307 /* Convert O_constant expression EXP into the equivalent O_big representation.
1308    Take the sign of the number from X_unsigned rather than X_add_number.  */
1309
1310 static void
1311 convert_to_bignum (expressionS *exp)
1312 {
1313   valueT value;
1314   unsigned int i;
1315
1316   value = exp->X_add_number;
1317   for (i = 0; i < sizeof (exp->X_add_number) / CHARS_PER_LITTLENUM; i++)
1318     {
1319       generic_bignum[i] = value & LITTLENUM_MASK;
1320       value >>= LITTLENUM_NUMBER_OF_BITS;
1321     }
1322   /* Add a sequence of sign bits if the top bit of X_add_number is not
1323      the sign of the original value.  */
1324   if ((exp->X_add_number < 0) != !exp->X_unsigned)
1325     generic_bignum[i++] = exp->X_unsigned ? 0 : LITTLENUM_MASK;
1326   exp->X_op = O_big;
1327   exp->X_add_number = i;
1328 }
1329
1330 /* For most MRI pseudo-ops, the line actually ends at the first
1331    nonquoted space.  This function looks for that point, stuffs a null
1332    in, and sets *STOPCP to the character that used to be there, and
1333    returns the location.
1334
1335    Until I hear otherwise, I am going to assume that this is only true
1336    for the m68k MRI assembler.  */
1337
1338 char *
1339 mri_comment_field (char *stopcp)
1340 {
1341   char *s;
1342 #ifdef TC_M68K
1343   int inquote = 0;
1344
1345   know (flag_m68k_mri);
1346
1347   for (s = input_line_pointer;
1348        ((!is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t')
1349         || inquote);
1350        s++)
1351     {
1352       if (*s == '\'')
1353         inquote = !inquote;
1354     }
1355 #else
1356   for (s = input_line_pointer;
1357        !is_end_of_line[(unsigned char) *s];
1358        s++)
1359     ;
1360 #endif
1361   *stopcp = *s;
1362   *s = '\0';
1363
1364   return s;
1365 }
1366
1367 /* Skip to the end of an MRI comment field.  */
1368
1369 void
1370 mri_comment_end (char *stop, int stopc)
1371 {
1372   know (flag_mri);
1373
1374   input_line_pointer = stop;
1375   *stop = stopc;
1376   while (!is_end_of_line[(unsigned char) *input_line_pointer])
1377     ++input_line_pointer;
1378 }
1379
1380 void
1381 s_abort (int ignore ATTRIBUTE_UNUSED)
1382 {
1383   as_fatal (_(".abort detected.  Abandoning ship."));
1384 }
1385
1386 /* Guts of .align directive.  N is the power of two to which to align.
1387    FILL may be NULL, or it may point to the bytes of the fill pattern.
1388    LEN is the length of whatever FILL points to, if anything.  MAX is
1389    the maximum number of characters to skip when doing the alignment,
1390    or 0 if there is no maximum.  */
1391
1392 static void
1393 do_align (int n, char *fill, int len, int max)
1394 {
1395   if (now_seg == absolute_section)
1396     {
1397       if (fill != NULL)
1398         while (len-- > 0)
1399           if (*fill++ != '\0')
1400             {
1401               as_warn (_("ignoring fill value in absolute section"));
1402               break;
1403             }
1404       fill = NULL;
1405       len = 0;
1406     }
1407
1408 #ifdef md_flush_pending_output
1409   md_flush_pending_output ();
1410 #endif
1411 #ifdef md_do_align
1412   md_do_align (n, fill, len, max, just_record_alignment);
1413 #endif
1414
1415   /* Only make a frag if we HAVE to...  */
1416   if (n != 0 && !need_pass_2)
1417     {
1418       if (fill == NULL)
1419         {
1420           if (subseg_text_p (now_seg))
1421             frag_align_code (n, max);
1422           else
1423             frag_align (n, 0, max);
1424         }
1425       else if (len <= 1)
1426         frag_align (n, *fill, max);
1427       else
1428         frag_align_pattern (n, fill, len, max);
1429     }
1430
1431 #ifdef md_do_align
1432  just_record_alignment: ATTRIBUTE_UNUSED_LABEL
1433 #endif
1434
1435   record_alignment (now_seg, n - OCTETS_PER_BYTE_POWER);
1436 }
1437
1438 /* Handle the .align pseudo-op.  A positive ARG is a default alignment
1439    (in bytes).  A negative ARG is the negative of the length of the
1440    fill pattern.  BYTES_P is non-zero if the alignment value should be
1441    interpreted as the byte boundary, rather than the power of 2.  */
1442 #ifndef TC_ALIGN_LIMIT
1443 #define TC_ALIGN_LIMIT (stdoutput->arch_info->bits_per_address - 1)
1444 #endif
1445
1446 static void
1447 s_align (int arg, int bytes_p)
1448 {
1449   unsigned int align_limit = TC_ALIGN_LIMIT;
1450   unsigned int align;
1451   char *stop = NULL;
1452   char stopc = 0;
1453   offsetT fill = 0;
1454   int max;
1455   int fill_p;
1456
1457   if (flag_mri)
1458     stop = mri_comment_field (&stopc);
1459
1460   if (is_end_of_line[(unsigned char) *input_line_pointer])
1461     {
1462       if (arg < 0)
1463         align = 0;
1464       else
1465         align = arg;    /* Default value from pseudo-op table.  */
1466     }
1467   else
1468     {
1469       align = get_absolute_expression ();
1470       SKIP_WHITESPACE ();
1471     }
1472
1473   if (bytes_p)
1474     {
1475       /* Convert to a power of 2.  */
1476       if (align != 0)
1477         {
1478           unsigned int i;
1479
1480           for (i = 0; (align & 1) == 0; align >>= 1, ++i)
1481             ;
1482           if (align != 1)
1483             as_bad (_("alignment not a power of 2"));
1484
1485           align = i;
1486         }
1487     }
1488
1489   if (align > align_limit)
1490     {
1491       align = align_limit;
1492       as_warn (_("alignment too large: %u assumed"), align);
1493     }
1494
1495   if (*input_line_pointer != ',')
1496     {
1497       fill_p = 0;
1498       max = 0;
1499     }
1500   else
1501     {
1502       ++input_line_pointer;
1503       if (*input_line_pointer == ',')
1504         fill_p = 0;
1505       else
1506         {
1507           fill = get_absolute_expression ();
1508           SKIP_WHITESPACE ();
1509           fill_p = 1;
1510         }
1511
1512       if (*input_line_pointer != ',')
1513         max = 0;
1514       else
1515         {
1516           ++input_line_pointer;
1517           max = get_absolute_expression ();
1518         }
1519     }
1520
1521   if (!fill_p)
1522     {
1523       if (arg < 0)
1524         as_warn (_("expected fill pattern missing"));
1525       do_align (align, (char *) NULL, 0, max);
1526     }
1527   else
1528     {
1529       int fill_len;
1530
1531       if (arg >= 0)
1532         fill_len = 1;
1533       else
1534         fill_len = -arg;
1535       if (fill_len <= 1)
1536         {
1537           char fill_char;
1538
1539           fill_char = fill;
1540           do_align (align, &fill_char, fill_len, max);
1541         }
1542       else
1543         {
1544           char ab[16];
1545
1546           if ((size_t) fill_len > sizeof ab)
1547             abort ();
1548           md_number_to_chars (ab, fill, fill_len);
1549           do_align (align, ab, fill_len, max);
1550         }
1551     }
1552
1553   demand_empty_rest_of_line ();
1554
1555   if (flag_mri)
1556     mri_comment_end (stop, stopc);
1557 }
1558
1559 /* Handle the .align pseudo-op on machines where ".align 4" means
1560    align to a 4 byte boundary.  */
1561
1562 void
1563 s_align_bytes (int arg)
1564 {
1565   s_align (arg, 1);
1566 }
1567
1568 /* Handle the .align pseudo-op on machines where ".align 4" means align
1569    to a 2**4 boundary.  */
1570
1571 void
1572 s_align_ptwo (int arg)
1573 {
1574   s_align (arg, 0);
1575 }
1576
1577 /* Switch in and out of alternate macro mode.  */
1578
1579 void
1580 s_altmacro (int on)
1581 {
1582   demand_empty_rest_of_line ();
1583   macro_set_alternate (on);
1584 }
1585
1586 symbolS *
1587 s_comm_internal (int param,
1588                  symbolS *(*comm_parse_extra) (int, symbolS *, addressT))
1589 {
1590   char *name;
1591   char c;
1592   char *p;
1593   offsetT temp, size;
1594   symbolS *symbolP = NULL;
1595   char *stop = NULL;
1596   char stopc = 0;
1597   expressionS exp;
1598
1599   if (flag_mri)
1600     stop = mri_comment_field (&stopc);
1601
1602   name = input_line_pointer;
1603   c = get_symbol_end ();
1604   /* Just after name is now '\0'.  */
1605   p = input_line_pointer;
1606   *p = c;
1607
1608   if (name == p)
1609     {
1610       as_bad (_("expected symbol name"));
1611       ignore_rest_of_line ();
1612       goto out;
1613     }
1614
1615   SKIP_WHITESPACE ();
1616
1617   /* Accept an optional comma after the name.  The comma used to be
1618      required, but Irix 5 cc does not generate it for .lcomm.  */
1619   if (*input_line_pointer == ',')
1620     input_line_pointer++;
1621
1622   temp = get_absolute_expr (&exp);
1623   size = temp;
1624   size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1625   if (exp.X_op == O_absent)
1626     {
1627       as_bad (_("missing size expression"));
1628       ignore_rest_of_line ();
1629       goto out;
1630     }
1631   else if (temp != size || !exp.X_unsigned)
1632     {
1633       as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1634       ignore_rest_of_line ();
1635       goto out;
1636     }
1637
1638   *p = 0;
1639   symbolP = symbol_find_or_make (name);
1640   if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1641       && !S_IS_COMMON (symbolP))
1642     {
1643       if (!S_IS_VOLATILE (symbolP))
1644         {
1645           symbolP = NULL;
1646           as_bad (_("symbol `%s' is already defined"), name);
1647           *p = c;
1648           ignore_rest_of_line ();
1649           goto out;
1650         }
1651       symbolP = symbol_clone (symbolP, 1);
1652       S_SET_SEGMENT (symbolP, undefined_section);
1653       S_SET_VALUE (symbolP, 0);
1654       symbol_set_frag (symbolP, &zero_address_frag);
1655       S_CLEAR_VOLATILE (symbolP);
1656     }
1657
1658   size = S_GET_VALUE (symbolP);
1659   if (size == 0)
1660     size = temp;
1661   else if (size != temp)
1662     as_warn (_("size of \"%s\" is already %ld; not changing to %ld"),
1663              name, (long) size, (long) temp);
1664
1665   *p = c;
1666   if (comm_parse_extra != NULL)
1667     symbolP = (*comm_parse_extra) (param, symbolP, size);
1668   else
1669     {
1670       S_SET_VALUE (symbolP, (valueT) size);
1671       S_SET_EXTERNAL (symbolP);
1672       S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
1673     }
1674
1675   demand_empty_rest_of_line ();
1676  out:
1677   if (flag_mri)
1678     mri_comment_end (stop, stopc);
1679   return symbolP;
1680 }
1681
1682 void
1683 s_comm (int ignore)
1684 {
1685   s_comm_internal (ignore, NULL);
1686 }
1687
1688 /* The MRI COMMON pseudo-op.  We handle this by creating a common
1689    symbol with the appropriate name.  We make s_space do the right
1690    thing by increasing the size.  */
1691
1692 void
1693 s_mri_common (int small ATTRIBUTE_UNUSED)
1694 {
1695   char *name;
1696   char c;
1697   char *alc = NULL;
1698   symbolS *sym;
1699   offsetT align;
1700   char *stop = NULL;
1701   char stopc = 0;
1702
1703   if (!flag_mri)
1704     {
1705       s_comm (0);
1706       return;
1707     }
1708
1709   stop = mri_comment_field (&stopc);
1710
1711   SKIP_WHITESPACE ();
1712
1713   name = input_line_pointer;
1714   if (!ISDIGIT (*name))
1715     c = get_symbol_end ();
1716   else
1717     {
1718       do
1719         {
1720           ++input_line_pointer;
1721         }
1722       while (ISDIGIT (*input_line_pointer));
1723
1724       c = *input_line_pointer;
1725       *input_line_pointer = '\0';
1726
1727       if (line_label != NULL)
1728         {
1729           alc = (char *) xmalloc (strlen (S_GET_NAME (line_label))
1730                                   + (input_line_pointer - name)
1731                                   + 1);
1732           sprintf (alc, "%s%s", name, S_GET_NAME (line_label));
1733           name = alc;
1734         }
1735     }
1736
1737   sym = symbol_find_or_make (name);
1738   *input_line_pointer = c;
1739   if (alc != NULL)
1740     free (alc);
1741
1742   if (*input_line_pointer != ',')
1743     align = 0;
1744   else
1745     {
1746       ++input_line_pointer;
1747       align = get_absolute_expression ();
1748     }
1749
1750   if (S_IS_DEFINED (sym) && !S_IS_COMMON (sym))
1751     {
1752       as_bad (_("symbol `%s' is already defined"), S_GET_NAME (sym));
1753       ignore_rest_of_line ();
1754       mri_comment_end (stop, stopc);
1755       return;
1756     }
1757
1758   S_SET_EXTERNAL (sym);
1759   S_SET_SEGMENT (sym, bfd_com_section_ptr);
1760   mri_common_symbol = sym;
1761
1762 #ifdef S_SET_ALIGN
1763   if (align != 0)
1764     S_SET_ALIGN (sym, align);
1765 #else
1766   (void) align;
1767 #endif
1768
1769   if (line_label != NULL)
1770     {
1771       expressionS exp;
1772       exp.X_op = O_symbol;
1773       exp.X_add_symbol = sym;
1774       exp.X_add_number = 0;
1775       symbol_set_value_expression (line_label, &exp);
1776       symbol_set_frag (line_label, &zero_address_frag);
1777       S_SET_SEGMENT (line_label, expr_section);
1778     }
1779
1780   /* FIXME: We just ignore the small argument, which distinguishes
1781      COMMON and COMMON.S.  I don't know what we can do about it.  */
1782
1783   /* Ignore the type and hptype.  */
1784   if (*input_line_pointer == ',')
1785     input_line_pointer += 2;
1786   if (*input_line_pointer == ',')
1787     input_line_pointer += 2;
1788
1789   demand_empty_rest_of_line ();
1790
1791   mri_comment_end (stop, stopc);
1792 }
1793
1794 void
1795 s_data (int ignore ATTRIBUTE_UNUSED)
1796 {
1797   segT section;
1798   int temp;
1799
1800   temp = get_absolute_expression ();
1801   if (flag_readonly_data_in_text)
1802     {
1803       section = text_section;
1804       temp += 1000;
1805     }
1806   else
1807     section = data_section;
1808
1809   subseg_set (section, (subsegT) temp);
1810
1811   demand_empty_rest_of_line ();
1812 }
1813
1814 /* Handle the .appfile pseudo-op.  This is automatically generated by
1815    do_scrub_chars when a preprocessor # line comment is seen with a
1816    file name.  This default definition may be overridden by the object
1817    or CPU specific pseudo-ops.  This function is also the default
1818    definition for .file; the APPFILE argument is 1 for .appfile, 0 for
1819    .file.  */
1820
1821 void
1822 s_app_file_string (char *file, int appfile ATTRIBUTE_UNUSED)
1823 {
1824 #ifdef LISTING
1825   if (listing)
1826     listing_source_file (file);
1827 #endif
1828   register_dependency (file);
1829 #ifdef obj_app_file
1830   obj_app_file (file, appfile);
1831 #endif
1832 }
1833
1834 void
1835 s_app_file (int appfile)
1836 {
1837   char *s;
1838   int length;
1839
1840   /* Some assemblers tolerate immediately following '"'.  */
1841   if ((s = demand_copy_string (&length)) != 0)
1842     {
1843       int may_omit
1844         = (!new_logical_line_flags (s, -1, 1) && appfile);
1845
1846       /* In MRI mode, the preprocessor may have inserted an extraneous
1847          backquote.  */
1848       if (flag_m68k_mri
1849           && *input_line_pointer == '\''
1850           && is_end_of_line[(unsigned char) input_line_pointer[1]])
1851         ++input_line_pointer;
1852
1853       demand_empty_rest_of_line ();
1854       if (!may_omit)
1855         s_app_file_string (s, appfile);
1856     }
1857 }
1858
1859 static int
1860 get_linefile_number (int *flag)
1861 {
1862   SKIP_WHITESPACE ();
1863
1864   if (*input_line_pointer < '0' || *input_line_pointer > '9')
1865     return 0;
1866
1867   *flag = get_absolute_expression ();
1868
1869   return 1;
1870 }
1871
1872 /* Handle the .appline pseudo-op.  This is automatically generated by
1873    do_scrub_chars when a preprocessor # line comment is seen.  This
1874    default definition may be overridden by the object or CPU specific
1875    pseudo-ops.  */
1876
1877 void
1878 s_app_line (int appline)
1879 {
1880   char *file = NULL;
1881   int l;
1882
1883   /* The given number is that of the next line.  */
1884   if (appline)
1885     l = get_absolute_expression ();
1886   else if (!get_linefile_number (&l))
1887     {
1888       ignore_rest_of_line ();
1889       return;
1890     }
1891
1892   l--;
1893
1894   if (l < -1)
1895     /* Some of the back ends can't deal with non-positive line numbers.
1896        Besides, it's silly.  GCC however will generate a line number of
1897        zero when it is pre-processing builtins for assembler-with-cpp files:
1898
1899           # 0 "<built-in>"
1900
1901        We do not want to barf on this, especially since such files are used
1902        in the GCC and GDB testsuites.  So we check for negative line numbers
1903        rather than non-positive line numbers.  */
1904     as_warn (_("line numbers must be positive; line number %d rejected"),
1905              l + 1);
1906   else
1907     {
1908       int flags = 0;
1909       int length = 0;
1910
1911       if (!appline)
1912         {
1913           SKIP_WHITESPACE ();
1914
1915           if (*input_line_pointer == '"')
1916             file = demand_copy_string (&length);
1917
1918           if (file)
1919             {
1920               int this_flag;
1921
1922               while (get_linefile_number (&this_flag))
1923                 switch (this_flag)
1924                   {
1925                     /* From GCC's cpp documentation:
1926                        1: start of a new file.
1927                        2: returning to a file after having included
1928                           another file.
1929                        3: following text comes from a system header file.
1930                        4: following text should be treated as extern "C".
1931
1932                        4 is nonsensical for the assembler; 3, we don't
1933                        care about, so we ignore it just in case a
1934                        system header file is included while
1935                        preprocessing assembly.  So 1 and 2 are all we
1936                        care about, and they are mutually incompatible.
1937                        new_logical_line_flags() demands this.  */
1938                   case 1:
1939                   case 2:
1940                     if (flags && flags != (1 << this_flag))
1941                       as_warn (_("incompatible flag %i in line directive"),
1942                                this_flag);
1943                     else
1944                       flags |= 1 << this_flag;
1945                     break;
1946
1947                   case 3:
1948                   case 4:
1949                     /* We ignore these.  */
1950                     break;
1951
1952                   default:
1953                     as_warn (_("unsupported flag %i in line directive"),
1954                              this_flag);
1955                     break;
1956                   }
1957
1958               if (!is_end_of_line[(unsigned char)*input_line_pointer])
1959                 file = 0;
1960             }
1961         }
1962
1963       if (appline || file)
1964         {
1965           new_logical_line_flags (file, l, flags);
1966 #ifdef LISTING
1967           if (listing)
1968             listing_source_line (l);
1969 #endif
1970         }
1971     }
1972   if (appline || file)
1973     demand_empty_rest_of_line ();
1974   else
1975     ignore_rest_of_line ();
1976 }
1977
1978 /* Handle the .end pseudo-op.  Actually, the real work is done in
1979    read_a_source_file.  */
1980
1981 void
1982 s_end (int ignore ATTRIBUTE_UNUSED)
1983 {
1984   if (flag_mri)
1985     {
1986       /* The MRI assembler permits the start symbol to follow .end,
1987          but we don't support that.  */
1988       SKIP_WHITESPACE ();
1989       if (!is_end_of_line[(unsigned char) *input_line_pointer]
1990           && *input_line_pointer != '*'
1991           && *input_line_pointer != '!')
1992         as_warn (_("start address not supported"));
1993     }
1994 }
1995
1996 /* Handle the .err pseudo-op.  */
1997
1998 void
1999 s_err (int ignore ATTRIBUTE_UNUSED)
2000 {
2001   as_bad (_(".err encountered"));
2002   demand_empty_rest_of_line ();
2003 }
2004
2005 /* Handle the .error and .warning pseudo-ops.  */
2006
2007 void
2008 s_errwarn (int err)
2009 {
2010   int len;
2011   /* The purpose for the conditional assignment is not to
2012      internationalize the directive itself, but that we need a
2013      self-contained message, one that can be passed like the
2014      demand_copy_C_string return value, and with no assumption on the
2015      location of the name of the directive within the message.  */
2016   char *msg
2017     = (err ? _(".error directive invoked in source file")
2018        : _(".warning directive invoked in source file"));
2019
2020   if (!is_it_end_of_statement ())
2021     {
2022       if (*input_line_pointer != '\"')
2023         {
2024           as_bad (_("%s argument must be a string"),
2025                   err ? ".error" : ".warning");
2026           ignore_rest_of_line ();
2027           return;
2028         }
2029
2030       msg = demand_copy_C_string (&len);
2031       if (msg == NULL)
2032         return;
2033     }
2034
2035   if (err)
2036     as_bad ("%s", msg);
2037   else
2038     as_warn ("%s", msg);
2039   demand_empty_rest_of_line ();
2040 }
2041
2042 /* Handle the MRI fail pseudo-op.  */
2043
2044 void
2045 s_fail (int ignore ATTRIBUTE_UNUSED)
2046 {
2047   offsetT temp;
2048   char *stop = NULL;
2049   char stopc = 0;
2050
2051   if (flag_mri)
2052     stop = mri_comment_field (&stopc);
2053
2054   temp = get_absolute_expression ();
2055   if (temp >= 500)
2056     as_warn (_(".fail %ld encountered"), (long) temp);
2057   else
2058     as_bad (_(".fail %ld encountered"), (long) temp);
2059
2060   demand_empty_rest_of_line ();
2061
2062   if (flag_mri)
2063     mri_comment_end (stop, stopc);
2064 }
2065
2066 void
2067 s_fill (int ignore ATTRIBUTE_UNUSED)
2068 {
2069   expressionS rep_exp;
2070   long size = 1;
2071   long fill = 0;
2072   char *p;
2073
2074 #ifdef md_flush_pending_output
2075   md_flush_pending_output ();
2076 #endif
2077
2078 #ifdef md_cons_align
2079   md_cons_align (1);
2080 #endif
2081
2082   get_known_segmented_expression (&rep_exp);
2083   if (*input_line_pointer == ',')
2084     {
2085       input_line_pointer++;
2086       size = get_absolute_expression ();
2087       if (*input_line_pointer == ',')
2088         {
2089           input_line_pointer++;
2090           fill = get_absolute_expression ();
2091         }
2092     }
2093
2094   /* This is to be compatible with BSD 4.2 AS, not for any rational reason.  */
2095 #define BSD_FILL_SIZE_CROCK_8 (8)
2096   if (size > BSD_FILL_SIZE_CROCK_8)
2097     {
2098       as_warn (_(".fill size clamped to %d"), BSD_FILL_SIZE_CROCK_8);
2099       size = BSD_FILL_SIZE_CROCK_8;
2100     }
2101   if (size < 0)
2102     {
2103       as_warn (_("size negative; .fill ignored"));
2104       size = 0;
2105     }
2106   else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0)
2107     {
2108       if (rep_exp.X_add_number < 0)
2109         as_warn (_("repeat < 0; .fill ignored"));
2110       size = 0;
2111     }
2112
2113   if (size && !need_pass_2)
2114     {
2115       if (rep_exp.X_op == O_constant)
2116         {
2117           p = frag_var (rs_fill, (int) size, (int) size,
2118                         (relax_substateT) 0, (symbolS *) 0,
2119                         (offsetT) rep_exp.X_add_number,
2120                         (char *) 0);
2121         }
2122       else
2123         {
2124           /* We don't have a constant repeat count, so we can't use
2125              rs_fill.  We can get the same results out of rs_space,
2126              but its argument is in bytes, so we must multiply the
2127              repeat count by size.  */
2128
2129           symbolS *rep_sym;
2130           rep_sym = make_expr_symbol (&rep_exp);
2131           if (size != 1)
2132             {
2133               expressionS size_exp;
2134               size_exp.X_op = O_constant;
2135               size_exp.X_add_number = size;
2136
2137               rep_exp.X_op = O_multiply;
2138               rep_exp.X_add_symbol = rep_sym;
2139               rep_exp.X_op_symbol = make_expr_symbol (&size_exp);
2140               rep_exp.X_add_number = 0;
2141               rep_sym = make_expr_symbol (&rep_exp);
2142             }
2143
2144           p = frag_var (rs_space, (int) size, (int) size,
2145                         (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0);
2146         }
2147
2148       memset (p, 0, (unsigned int) size);
2149
2150       /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX
2151          flavoured AS.  The following bizarre behaviour is to be
2152          compatible with above.  I guess they tried to take up to 8
2153          bytes from a 4-byte expression and they forgot to sign
2154          extend.  */
2155 #define BSD_FILL_SIZE_CROCK_4 (4)
2156       md_number_to_chars (p, (valueT) fill,
2157                           (size > BSD_FILL_SIZE_CROCK_4
2158                            ? BSD_FILL_SIZE_CROCK_4
2159                            : (int) size));
2160       /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes)
2161          but emits no error message because it seems a legal thing to do.
2162          It is a degenerate case of .fill but could be emitted by a
2163          compiler.  */
2164     }
2165   demand_empty_rest_of_line ();
2166 }
2167
2168 void
2169 s_globl (int ignore ATTRIBUTE_UNUSED)
2170 {
2171   char *name;
2172   int c;
2173   symbolS *symbolP;
2174   char *stop = NULL;
2175   char stopc = 0;
2176
2177   if (flag_mri)
2178     stop = mri_comment_field (&stopc);
2179
2180   do
2181     {
2182       name = input_line_pointer;
2183       c = get_symbol_end ();
2184       symbolP = symbol_find_or_make (name);
2185       S_SET_EXTERNAL (symbolP);
2186
2187       *input_line_pointer = c;
2188       SKIP_WHITESPACE ();
2189       c = *input_line_pointer;
2190       if (c == ',')
2191         {
2192           input_line_pointer++;
2193           SKIP_WHITESPACE ();
2194           if (is_end_of_line[(unsigned char) *input_line_pointer])
2195             c = '\n';
2196         }
2197     }
2198   while (c == ',');
2199
2200   demand_empty_rest_of_line ();
2201
2202   if (flag_mri)
2203     mri_comment_end (stop, stopc);
2204 }
2205
2206 #ifdef OBJ_ELF
2207 #define skip_whitespace(str)  do { if (*(str) == ' ') ++(str); } while (0)
2208
2209 static inline int
2210 skip_past_char (char ** str, char c)
2211 {
2212   if (**str == c)
2213     {
2214       (*str)++;
2215       return 0;
2216     }
2217   else
2218     return -1;
2219 }
2220 #define skip_past_comma(str) skip_past_char (str, ',')
2221
2222 /* Parse an attribute directive for VENDOR.
2223    Returns the attribute number read, or zero on error.  */
2224 int
2225 s_vendor_attribute (int vendor)
2226 {
2227   expressionS exp;
2228   int type;
2229   int tag;
2230   unsigned int i = 0;
2231   char *s = NULL;
2232
2233   /* Read the first number or name.  */
2234   skip_whitespace (input_line_pointer);
2235   s = input_line_pointer;
2236   if (ISDIGIT (*input_line_pointer))
2237     {
2238       expression (& exp);
2239       if (exp.X_op != O_constant)
2240         goto bad;
2241       tag = exp.X_add_number;
2242     }
2243   else
2244     {
2245       char *name;
2246
2247       /* A name may contain '_', but no other punctuation.  */
2248       for (; ISALNUM (*input_line_pointer) || *input_line_pointer == '_';
2249            ++input_line_pointer)
2250         i++;
2251       if (i == 0)
2252         goto bad;
2253
2254       name = (char *) alloca (i + 1);
2255       memcpy (name, s, i);
2256       name[i] = '\0';
2257
2258 #ifndef CONVERT_SYMBOLIC_ATTRIBUTE
2259 #define CONVERT_SYMBOLIC_ATTRIBUTE(a) -1
2260 #endif
2261
2262       tag = CONVERT_SYMBOLIC_ATTRIBUTE (name);
2263       if (tag == -1)
2264         {
2265           as_bad (_("Attribute name not recognised: %s"), name);
2266           ignore_rest_of_line ();
2267           return 0;
2268         }
2269     }
2270
2271   type = _bfd_elf_obj_attrs_arg_type (stdoutput, vendor, tag);
2272
2273   if (skip_past_comma (&input_line_pointer) == -1)
2274     goto bad;
2275   if (type & 1)
2276     {
2277       expression (& exp);
2278       if (exp.X_op != O_constant)
2279         {
2280           as_bad (_("expected numeric constant"));
2281           ignore_rest_of_line ();
2282           return 0;
2283         }
2284       i = exp.X_add_number;
2285     }
2286   if ((type & 3) == 3
2287       && skip_past_comma (&input_line_pointer) == -1)
2288     {
2289       as_bad (_("expected comma"));
2290       ignore_rest_of_line ();
2291       return 0;
2292     }
2293   if (type & 2)
2294     {
2295       int len;
2296
2297       skip_whitespace (input_line_pointer);
2298       if (*input_line_pointer != '"')
2299         goto bad_string;
2300       s = demand_copy_C_string (&len);
2301     }
2302
2303   switch (type & 3)
2304     {
2305     case 3:
2306       bfd_elf_add_obj_attr_int_string (stdoutput, vendor, tag, i, s);
2307       break;
2308     case 2:
2309       bfd_elf_add_obj_attr_string (stdoutput, vendor, tag, s);
2310       break;
2311     case 1:
2312       bfd_elf_add_obj_attr_int (stdoutput, vendor, tag, i);
2313       break;
2314     default:
2315       abort ();
2316     }
2317
2318   demand_empty_rest_of_line ();
2319   return tag;
2320 bad_string:
2321   as_bad (_("bad string constant"));
2322   ignore_rest_of_line ();
2323   return 0;
2324 bad:
2325   as_bad (_("expected <tag> , <value>"));
2326   ignore_rest_of_line ();
2327   return 0;
2328 }
2329
2330 /* Parse a .gnu_attribute directive.  */
2331
2332 static void
2333 s_gnu_attribute (int ignored ATTRIBUTE_UNUSED)
2334 {
2335   s_vendor_attribute (OBJ_ATTR_GNU);
2336 }
2337 #endif /* OBJ_ELF */
2338
2339 /* Handle the MRI IRP and IRPC pseudo-ops.  */
2340
2341 void
2342 s_irp (int irpc)
2343 {
2344   char *file, *eol;
2345   unsigned int line;
2346   sb s;
2347   const char *err;
2348   sb out;
2349
2350   as_where (&file, &line);
2351
2352   sb_new (&s);
2353   eol = find_end_of_line (input_line_pointer, 0);
2354   sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2355   input_line_pointer = eol;
2356
2357   sb_new (&out);
2358
2359   err = expand_irp (irpc, 0, &s, &out, get_non_macro_line_sb);
2360   if (err != NULL)
2361     as_bad_where (file, line, "%s", err);
2362
2363   sb_kill (&s);
2364
2365   input_scrub_include_sb (&out, input_line_pointer, 1);
2366   sb_kill (&out);
2367   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2368 }
2369
2370 /* Handle the .linkonce pseudo-op.  This tells the assembler to mark
2371    the section to only be linked once.  However, this is not supported
2372    by most object file formats.  This takes an optional argument,
2373    which is what to do about duplicates.  */
2374
2375 void
2376 s_linkonce (int ignore ATTRIBUTE_UNUSED)
2377 {
2378   enum linkonce_type type;
2379
2380   SKIP_WHITESPACE ();
2381
2382   type = LINKONCE_DISCARD;
2383
2384   if (!is_end_of_line[(unsigned char) *input_line_pointer])
2385     {
2386       char *s;
2387       char c;
2388
2389       s = input_line_pointer;
2390       c = get_symbol_end ();
2391       if (strcasecmp (s, "discard") == 0)
2392         type = LINKONCE_DISCARD;
2393       else if (strcasecmp (s, "one_only") == 0)
2394         type = LINKONCE_ONE_ONLY;
2395       else if (strcasecmp (s, "same_size") == 0)
2396         type = LINKONCE_SAME_SIZE;
2397       else if (strcasecmp (s, "same_contents") == 0)
2398         type = LINKONCE_SAME_CONTENTS;
2399       else
2400         as_warn (_("unrecognized .linkonce type `%s'"), s);
2401
2402       *input_line_pointer = c;
2403     }
2404
2405 #ifdef obj_handle_link_once
2406   obj_handle_link_once (type);
2407 #else /* ! defined (obj_handle_link_once) */
2408   {
2409     flagword flags;
2410
2411     if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0)
2412       as_warn (_(".linkonce is not supported for this object file format"));
2413
2414     flags = bfd_get_section_flags (stdoutput, now_seg);
2415     flags |= SEC_LINK_ONCE;
2416     switch (type)
2417       {
2418       default:
2419         abort ();
2420       case LINKONCE_DISCARD:
2421         flags |= SEC_LINK_DUPLICATES_DISCARD;
2422         break;
2423       case LINKONCE_ONE_ONLY:
2424         flags |= SEC_LINK_DUPLICATES_ONE_ONLY;
2425         break;
2426       case LINKONCE_SAME_SIZE:
2427         flags |= SEC_LINK_DUPLICATES_SAME_SIZE;
2428         break;
2429       case LINKONCE_SAME_CONTENTS:
2430         flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS;
2431         break;
2432       }
2433     if (!bfd_set_section_flags (stdoutput, now_seg, flags))
2434       as_bad (_("bfd_set_section_flags: %s"),
2435               bfd_errmsg (bfd_get_error ()));
2436   }
2437 #endif /* ! defined (obj_handle_link_once) */
2438
2439   demand_empty_rest_of_line ();
2440 }
2441
2442 void
2443 bss_alloc (symbolS *symbolP, addressT size, int align)
2444 {
2445   char *pfrag;
2446   segT current_seg = now_seg;
2447   subsegT current_subseg = now_subseg;
2448   segT bss_seg = bss_section;
2449
2450 #if defined (TC_MIPS) || defined (TC_ALPHA)
2451   if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour
2452       || OUTPUT_FLAVOR == bfd_target_elf_flavour)
2453     {
2454       /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss.  */
2455       if (size <= bfd_get_gp_size (stdoutput))
2456         {
2457           bss_seg = subseg_new (".sbss", 1);
2458           seg_info (bss_seg)->bss = 1;
2459           if (!bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC))
2460             as_warn (_("error setting flags for \".sbss\": %s"),
2461                      bfd_errmsg (bfd_get_error ()));
2462         }
2463     }
2464 #endif
2465   subseg_set (bss_seg, 1);
2466
2467   if (align)
2468     {
2469       record_alignment (bss_seg, align);
2470       frag_align (align, 0, 0);
2471     }
2472
2473   /* Detach from old frag.  */
2474   if (S_GET_SEGMENT (symbolP) == bss_seg)
2475     symbol_get_frag (symbolP)->fr_symbol = NULL;
2476
2477   symbol_set_frag (symbolP, frag_now);
2478   pfrag = frag_var (rs_org, 1, 1, 0, symbolP, size, NULL);
2479   *pfrag = 0;
2480
2481 #ifdef S_SET_SIZE
2482   S_SET_SIZE (symbolP, size);
2483 #endif
2484   S_SET_SEGMENT (symbolP, bss_seg);
2485
2486 #ifdef OBJ_COFF
2487   /* The symbol may already have been created with a preceding
2488      ".globl" directive -- be careful not to step on storage class
2489      in that case.  Otherwise, set it to static.  */
2490   if (S_GET_STORAGE_CLASS (symbolP) != C_EXT)
2491     S_SET_STORAGE_CLASS (symbolP, C_STAT);
2492 #endif /* OBJ_COFF */
2493
2494   subseg_set (current_seg, current_subseg);
2495 }
2496
2497 offsetT
2498 parse_align (int align_bytes)
2499 {
2500   expressionS exp;
2501   addressT align;
2502
2503   SKIP_WHITESPACE ();
2504   if (*input_line_pointer != ',')
2505     {
2506     no_align:
2507       as_bad (_("expected alignment after size"));
2508       ignore_rest_of_line ();
2509       return -1;
2510     }
2511
2512   input_line_pointer++;
2513   SKIP_WHITESPACE ();
2514
2515   align = get_absolute_expr (&exp);
2516   if (exp.X_op == O_absent)
2517     goto no_align;
2518
2519   if (!exp.X_unsigned)
2520     {
2521       as_warn (_("alignment negative; 0 assumed"));
2522       align = 0;
2523     }
2524
2525   if (align_bytes && align != 0)
2526     {
2527       /* convert to a power of 2 alignment */
2528       unsigned int alignp2 = 0;
2529       while ((align & 1) == 0)
2530         align >>= 1, ++alignp2;
2531       if (align != 1)
2532         {
2533           as_bad (_("alignment not a power of 2"));
2534           ignore_rest_of_line ();
2535           return -1;
2536         }
2537       align = alignp2;
2538     }
2539   return align;
2540 }
2541
2542 /* Called from s_comm_internal after symbol name and size have been
2543    parsed.  NEEDS_ALIGN is 0 if it was an ".lcomm" (2 args only),
2544    1 if this was a ".bss" directive which has a 3rd argument
2545    (alignment as a power of 2), or 2 if this was a ".bss" directive
2546    with alignment in bytes.  */
2547
2548 symbolS *
2549 s_lcomm_internal (int needs_align, symbolS *symbolP, addressT size)
2550 {
2551   addressT align = 0;
2552
2553   if (needs_align)
2554     {
2555       align = parse_align (needs_align - 1);
2556       if (align == (addressT) -1)
2557         return NULL;
2558     }
2559   else
2560     /* Assume some objects may require alignment on some systems.  */
2561     TC_IMPLICIT_LCOMM_ALIGNMENT (size, align);
2562
2563   bss_alloc (symbolP, size, align);
2564   return symbolP;
2565 }
2566
2567 void
2568 s_lcomm (int needs_align)
2569 {
2570   s_comm_internal (needs_align, s_lcomm_internal);
2571 }
2572
2573 void
2574 s_lcomm_bytes (int needs_align)
2575 {
2576   s_comm_internal (needs_align * 2, s_lcomm_internal);
2577 }
2578
2579 void
2580 s_lsym (int ignore ATTRIBUTE_UNUSED)
2581 {
2582   char *name;
2583   char c;
2584   char *p;
2585   expressionS exp;
2586   symbolS *symbolP;
2587
2588   /* We permit ANY defined expression: BSD4.2 demands constants.  */
2589   name = input_line_pointer;
2590   c = get_symbol_end ();
2591   p = input_line_pointer;
2592   *p = c;
2593
2594   if (name == p)
2595     {
2596       as_bad (_("expected symbol name"));
2597       ignore_rest_of_line ();
2598       return;
2599     }
2600
2601   SKIP_WHITESPACE ();
2602
2603   if (*input_line_pointer != ',')
2604     {
2605       *p = 0;
2606       as_bad (_("expected comma after \"%s\""), name);
2607       *p = c;
2608       ignore_rest_of_line ();
2609       return;
2610     }
2611
2612   input_line_pointer++;
2613   expression_and_evaluate (&exp);
2614
2615   if (exp.X_op != O_constant
2616       && exp.X_op != O_register)
2617     {
2618       as_bad (_("bad expression"));
2619       ignore_rest_of_line ();
2620       return;
2621     }
2622
2623   *p = 0;
2624   symbolP = symbol_find_or_make (name);
2625
2626   if (S_GET_SEGMENT (symbolP) == undefined_section)
2627     {
2628       /* The name might be an undefined .global symbol; be sure to
2629          keep the "external" bit.  */
2630       S_SET_SEGMENT (symbolP,
2631                      (exp.X_op == O_constant
2632                       ? absolute_section
2633                       : reg_section));
2634       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
2635     }
2636   else
2637     {
2638       as_bad (_("symbol `%s' is already defined"), name);
2639     }
2640
2641   *p = c;
2642   demand_empty_rest_of_line ();
2643 }
2644
2645 /* Read a line into an sb.  Returns the character that ended the line
2646    or zero if there are no more lines.  */
2647
2648 static int
2649 get_line_sb (sb *line, int in_macro)
2650 {
2651   char *eol;
2652
2653   if (input_line_pointer[-1] == '\n')
2654     bump_line_counters ();
2655
2656   if (input_line_pointer >= buffer_limit)
2657     {
2658       buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2659       if (buffer_limit == 0)
2660         return 0;
2661     }
2662
2663   eol = _find_end_of_line (input_line_pointer, flag_m68k_mri, 0, in_macro);
2664   sb_add_buffer (line, input_line_pointer, eol - input_line_pointer);
2665   input_line_pointer = eol;
2666
2667   /* Don't skip multiple end-of-line characters, because that breaks support
2668      for the IA-64 stop bit (;;) which looks like two consecutive end-of-line
2669      characters but isn't.  Instead just skip one end of line character and
2670      return the character skipped so that the caller can re-insert it if
2671      necessary.   */
2672   return *input_line_pointer++;
2673 }
2674
2675 static int
2676 get_non_macro_line_sb (sb *line)
2677 {
2678   return get_line_sb (line, 0);
2679 }
2680
2681 static int
2682 get_macro_line_sb (sb *line)
2683 {
2684   return get_line_sb (line, 1);
2685 }
2686
2687 /* Define a macro.  This is an interface to macro.c.  */
2688
2689 void
2690 s_macro (int ignore ATTRIBUTE_UNUSED)
2691 {
2692   char *file, *eol;
2693   unsigned int line;
2694   sb s;
2695   const char *err;
2696   const char *name;
2697
2698   as_where (&file, &line);
2699
2700   sb_new (&s);
2701   eol = find_end_of_line (input_line_pointer, 0);
2702   sb_add_buffer (&s, input_line_pointer, eol - input_line_pointer);
2703   input_line_pointer = eol;
2704
2705   if (line_label != NULL)
2706     {
2707       sb label;
2708
2709       sb_new (&label);
2710       sb_add_string (&label, S_GET_NAME (line_label));
2711       err = define_macro (0, &s, &label, get_macro_line_sb, file, line, &name);
2712       sb_kill (&label);
2713     }
2714   else
2715     err = define_macro (0, &s, NULL, get_macro_line_sb, file, line, &name);
2716   if (err != NULL)
2717     as_bad_where (file, line, err, name);
2718   else
2719     {
2720       if (line_label != NULL)
2721         {
2722           S_SET_SEGMENT (line_label, absolute_section);
2723           S_SET_VALUE (line_label, 0);
2724           symbol_set_frag (line_label, &zero_address_frag);
2725         }
2726
2727       if (((NO_PSEUDO_DOT || flag_m68k_mri)
2728            && hash_find (po_hash, name) != NULL)
2729           || (!flag_m68k_mri
2730               && *name == '.'
2731               && hash_find (po_hash, name + 1) != NULL))
2732         as_warn_where (file,
2733                  line,
2734                  _("attempt to redefine pseudo-op `%s' ignored"),
2735                  name);
2736     }
2737
2738   sb_kill (&s);
2739 }
2740
2741 /* Handle the .mexit pseudo-op, which immediately exits a macro
2742    expansion.  */
2743
2744 void
2745 s_mexit (int ignore ATTRIBUTE_UNUSED)
2746 {
2747   if (macro_nest)
2748     {
2749       cond_exit_macro (macro_nest);
2750       buffer_limit = input_scrub_next_buffer (&input_line_pointer);
2751     }
2752   else
2753     as_warn (_("ignoring macro exit outside a macro definition."));
2754 }
2755
2756 /* Switch in and out of MRI mode.  */
2757
2758 void
2759 s_mri (int ignore ATTRIBUTE_UNUSED)
2760 {
2761   int on;
2762 #ifdef MRI_MODE_CHANGE
2763   int old_flag;
2764 #endif
2765
2766   on = get_absolute_expression ();
2767 #ifdef MRI_MODE_CHANGE
2768   old_flag = flag_mri;
2769 #endif
2770   if (on != 0)
2771     {
2772       flag_mri = 1;
2773 #ifdef TC_M68K
2774       flag_m68k_mri = 1;
2775 #endif
2776       macro_mri_mode (1);
2777     }
2778   else
2779     {
2780       flag_mri = 0;
2781 #ifdef TC_M68K
2782       flag_m68k_mri = 0;
2783 #endif
2784       macro_mri_mode (0);
2785     }
2786
2787   /* Operator precedence changes in m68k MRI mode, so we need to
2788      update the operator rankings.  */
2789   expr_set_precedence ();
2790
2791 #ifdef MRI_MODE_CHANGE
2792   if (on != old_flag)
2793     MRI_MODE_CHANGE (on);
2794 #endif
2795
2796   demand_empty_rest_of_line ();
2797 }
2798
2799 /* Handle changing the location counter.  */
2800
2801 static void
2802 do_org (segT segment, expressionS *exp, int fill)
2803 {
2804   if (segment != now_seg
2805       && segment != absolute_section
2806       && segment != expr_section)
2807     as_bad (_("invalid segment \"%s\""), segment_name (segment));
2808
2809   if (now_seg == absolute_section)
2810     {
2811       if (fill != 0)
2812         as_warn (_("ignoring fill value in absolute section"));
2813       if (exp->X_op != O_constant)
2814         {
2815           as_bad (_("only constant offsets supported in absolute section"));
2816           exp->X_add_number = 0;
2817         }
2818       abs_section_offset = exp->X_add_number;
2819     }
2820   else
2821     {
2822       char *p;
2823       symbolS *sym = exp->X_add_symbol;
2824       offsetT off = exp->X_add_number * OCTETS_PER_BYTE;
2825
2826       if (exp->X_op != O_constant && exp->X_op != O_symbol)
2827         {
2828           /* Handle complex expressions.  */
2829           sym = make_expr_symbol (exp);
2830           off = 0;
2831         }
2832
2833       p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
2834       *p = fill;
2835     }
2836 }
2837
2838 void
2839 s_org (int ignore ATTRIBUTE_UNUSED)
2840 {
2841   segT segment;
2842   expressionS exp;
2843   long temp_fill;
2844
2845 #ifdef md_flush_pending_output
2846   md_flush_pending_output ();
2847 #endif
2848
2849   /* The m68k MRI assembler has a different meaning for .org.  It
2850      means to create an absolute section at a given address.  We can't
2851      support that--use a linker script instead.  */
2852   if (flag_m68k_mri)
2853     {
2854       as_bad (_("MRI style ORG pseudo-op not supported"));
2855       ignore_rest_of_line ();
2856       return;
2857     }
2858
2859   /* Don't believe the documentation of BSD 4.2 AS.  There is no such
2860      thing as a sub-segment-relative origin.  Any absolute origin is
2861      given a warning, then assumed to be segment-relative.  Any
2862      segmented origin expression ("foo+42") had better be in the right
2863      segment or the .org is ignored.
2864
2865      BSD 4.2 AS warns if you try to .org backwards. We cannot because
2866      we never know sub-segment sizes when we are reading code.  BSD
2867      will crash trying to emit negative numbers of filler bytes in
2868      certain .orgs. We don't crash, but see as-write for that code.
2869
2870      Don't make frag if need_pass_2==1.  */
2871   segment = get_known_segmented_expression (&exp);
2872   if (*input_line_pointer == ',')
2873     {
2874       input_line_pointer++;
2875       temp_fill = get_absolute_expression ();
2876     }
2877   else
2878     temp_fill = 0;
2879
2880   if (!need_pass_2)
2881     do_org (segment, &exp, temp_fill);
2882
2883   demand_empty_rest_of_line ();
2884 }
2885
2886 /* Handle parsing for the MRI SECT/SECTION pseudo-op.  This should be
2887    called by the obj-format routine which handles section changing
2888    when in MRI mode.  It will create a new section, and return it.  It
2889    will set *TYPE to the section type: one of 'C' (code), 'D' (data),
2890    'M' (mixed), or 'R' (romable).  The flags will be set in the section.  */
2891
2892 void
2893 s_mri_sect (char *type ATTRIBUTE_UNUSED)
2894 {
2895 #ifdef TC_M68K
2896
2897   char *name;
2898   char c;
2899   segT seg;
2900
2901   SKIP_WHITESPACE ();
2902
2903   name = input_line_pointer;
2904   if (!ISDIGIT (*name))
2905     c = get_symbol_end ();
2906   else
2907     {
2908       do
2909         {
2910           ++input_line_pointer;
2911         }
2912       while (ISDIGIT (*input_line_pointer));
2913
2914       c = *input_line_pointer;
2915       *input_line_pointer = '\0';
2916     }
2917
2918   name = xstrdup (name);
2919
2920   *input_line_pointer = c;
2921
2922   seg = subseg_new (name, 0);
2923
2924   if (*input_line_pointer == ',')
2925     {
2926       int align;
2927
2928       ++input_line_pointer;
2929       align = get_absolute_expression ();
2930       record_alignment (seg, align);
2931     }
2932
2933   *type = 'C';
2934   if (*input_line_pointer == ',')
2935     {
2936       c = *++input_line_pointer;
2937       c = TOUPPER (c);
2938       if (c == 'C' || c == 'D' || c == 'M' || c == 'R')
2939         *type = c;
2940       else
2941         as_bad (_("unrecognized section type"));
2942       ++input_line_pointer;
2943
2944       {
2945         flagword flags;
2946
2947         flags = SEC_NO_FLAGS;
2948         if (*type == 'C')
2949           flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE;
2950         else if (*type == 'D' || *type == 'M')
2951           flags = SEC_ALLOC | SEC_LOAD | SEC_DATA;
2952         else if (*type == 'R')
2953           flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM;
2954         if (flags != SEC_NO_FLAGS)
2955           {
2956             if (!bfd_set_section_flags (stdoutput, seg, flags))
2957               as_warn (_("error setting flags for \"%s\": %s"),
2958                        bfd_section_name (stdoutput, seg),
2959                        bfd_errmsg (bfd_get_error ()));
2960           }
2961       }
2962     }
2963
2964   /* Ignore the HP type.  */
2965   if (*input_line_pointer == ',')
2966     input_line_pointer += 2;
2967
2968   demand_empty_rest_of_line ();
2969
2970 #else /* ! TC_M68K */
2971 #ifdef TC_I960
2972
2973   char *name;
2974   char c;
2975   segT seg;
2976
2977   SKIP_WHITESPACE ();
2978
2979   name = input_line_pointer;
2980   c = get_symbol_end ();
2981
2982   name = xstrdup (name);
2983
2984   *input_line_pointer = c;
2985
2986   seg = subseg_new (name, 0);
2987
2988   if (*input_line_pointer != ',')
2989     *type = 'C';
2990   else
2991     {
2992       char *sectype;
2993
2994       ++input_line_pointer;
2995       SKIP_WHITESPACE ();
2996       sectype = input_line_pointer;
2997       c = get_symbol_end ();
2998       if (*sectype == '\0')
2999         *type = 'C';
3000       else if (strcasecmp (sectype, "text") == 0)
3001         *type = 'C';
3002       else if (strcasecmp (sectype, "data") == 0)
3003         *type = 'D';
3004       else if (strcasecmp (sectype, "romdata") == 0)
3005         *type = 'R';
3006       else
3007         as_warn (_("unrecognized section type `%s'"), sectype);
3008       *input_line_pointer = c;
3009     }
3010
3011   if (*input_line_pointer == ',')
3012     {
3013       char *seccmd;
3014
3015       ++input_line_pointer;
3016       SKIP_WHITESPACE ();
3017       seccmd = input_line_pointer;
3018       c = get_symbol_end ();
3019       if (strcasecmp (seccmd, "absolute") == 0)
3020         {
3021           as_bad (_("absolute sections are not supported"));
3022           *input_line_pointer = c;
3023           ignore_rest_of_line ();
3024           return;
3025         }
3026       else if (strcasecmp (seccmd, "align") == 0)
3027         {
3028           int align;
3029
3030           *input_line_pointer = c;
3031           align = get_absolute_expression ();
3032           record_alignment (seg, align);
3033         }
3034       else
3035         {
3036           as_warn (_("unrecognized section command `%s'"), seccmd);
3037           *input_line_pointer = c;
3038         }
3039     }
3040
3041   demand_empty_rest_of_line ();
3042
3043 #else /* ! TC_I960 */
3044   /* The MRI assembler seems to use different forms of .sect for
3045      different targets.  */
3046   as_bad ("MRI mode not supported for this target");
3047   ignore_rest_of_line ();
3048 #endif /* ! TC_I960 */
3049 #endif /* ! TC_M68K */
3050 }
3051
3052 /* Handle the .print pseudo-op.  */
3053
3054 void
3055 s_print (int ignore ATTRIBUTE_UNUSED)
3056 {
3057   char *s;
3058   int len;
3059
3060   s = demand_copy_C_string (&len);
3061   if (s != NULL)
3062     printf ("%s\n", s);
3063   demand_empty_rest_of_line ();
3064 }
3065
3066 /* Handle the .purgem pseudo-op.  */
3067
3068 void
3069 s_purgem (int ignore ATTRIBUTE_UNUSED)
3070 {
3071   if (is_it_end_of_statement ())
3072     {
3073       demand_empty_rest_of_line ();
3074       return;
3075     }
3076
3077   do
3078     {
3079       char *name;
3080       char c;
3081
3082       SKIP_WHITESPACE ();
3083       name = input_line_pointer;
3084       c = get_symbol_end ();
3085       delete_macro (name);
3086       *input_line_pointer = c;
3087       SKIP_WHITESPACE ();
3088     }
3089   while (*input_line_pointer++ == ',');
3090
3091   --input_line_pointer;
3092   demand_empty_rest_of_line ();
3093 }
3094
3095 /* Handle the .endm/.endr pseudo-ops.  */
3096
3097 static void
3098 s_bad_end (int endr)
3099 {
3100   as_warn (_(".end%c encountered without preceding %s"),
3101            endr ? 'r' : 'm',
3102            endr ? ".rept, .irp, or .irpc" : ".macro");
3103   demand_empty_rest_of_line ();
3104 }
3105
3106 /* Handle the .rept pseudo-op.  */
3107
3108 void
3109 s_rept (int ignore ATTRIBUTE_UNUSED)
3110 {
3111   int count;
3112
3113   count = get_absolute_expression ();
3114
3115   do_repeat (count, "REPT", "ENDR");
3116 }
3117
3118 /* This function provides a generic repeat block implementation.   It allows
3119    different directives to be used as the start/end keys.  */
3120
3121 void
3122 do_repeat (int count, const char *start, const char *end)
3123 {
3124   sb one;
3125   sb many;
3126
3127   sb_new (&one);
3128   if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3129     {
3130       as_bad (_("%s without %s"), start, end);
3131       return;
3132     }
3133
3134   sb_new (&many);
3135   while (count-- > 0)
3136     sb_add_sb (&many, &one);
3137
3138   sb_kill (&one);
3139
3140   input_scrub_include_sb (&many, input_line_pointer, 1);
3141   sb_kill (&many);
3142   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3143 }
3144
3145 /* Like do_repeat except that any text matching EXPANDER in the
3146    block is replaced by the itteration count.  */
3147
3148 void
3149 do_repeat_with_expander (int count,
3150                          const char * start,
3151                          const char * end,
3152                          const char * expander)
3153 {
3154   sb one;
3155   sb many;
3156
3157   sb_new (&one);
3158   if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb))
3159     {
3160       as_bad (_("%s without %s"), start, end);
3161       return;
3162     }
3163
3164   sb_new (&many);
3165
3166   if (expander != NULL && strstr (one.ptr, expander) != NULL)
3167     {
3168       while (count -- > 0)
3169         {
3170           int len;
3171           char * sub;
3172           sb processed;
3173
3174           sb_new (& processed);
3175           sb_add_sb (& processed, & one);
3176           sub = strstr (processed.ptr, expander);
3177           len = sprintf (sub, "%d", count);
3178           gas_assert (len < 8);
3179           strcpy (sub + len, sub + 8);
3180           processed.len -= (8 - len);
3181           sb_add_sb (& many, & processed);
3182           sb_kill (& processed);
3183         }
3184     }
3185   else
3186     while (count-- > 0)
3187       sb_add_sb (&many, &one);
3188
3189   sb_kill (&one);
3190
3191   input_scrub_include_sb (&many, input_line_pointer, 1);
3192   sb_kill (&many);
3193   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3194 }
3195
3196 /* Skip to end of current repeat loop; EXTRA indicates how many additional
3197    input buffers to skip.  Assumes that conditionals preceding the loop end
3198    are properly nested.
3199
3200    This function makes it easier to implement a premature "break" out of the
3201    loop.  The EXTRA arg accounts for other buffers we might have inserted,
3202    such as line substitutions.  */
3203
3204 void
3205 end_repeat (int extra)
3206 {
3207   cond_exit_macro (macro_nest);
3208   while (extra-- >= 0)
3209     buffer_limit = input_scrub_next_buffer (&input_line_pointer);
3210 }
3211
3212 static void
3213 assign_symbol (char *name, int mode)
3214 {
3215   symbolS *symbolP;
3216
3217   if (name[0] == '.' && name[1] == '\0')
3218     {
3219       /* Turn '. = mumble' into a .org mumble.  */
3220       segT segment;
3221       expressionS exp;
3222
3223       segment = get_known_segmented_expression (&exp);
3224
3225       if (!need_pass_2)
3226         do_org (segment, &exp, 0);
3227
3228       return;
3229     }
3230
3231   if ((symbolP = symbol_find (name)) == NULL
3232       && (symbolP = md_undefined_symbol (name)) == NULL)
3233     {
3234       symbolP = symbol_find_or_make (name);
3235 #ifndef NO_LISTING
3236       /* When doing symbol listings, play games with dummy fragments living
3237          outside the normal fragment chain to record the file and line info
3238          for this symbol.  */
3239       if (listing & LISTING_SYMBOLS)
3240         {
3241           extern struct list_info_struct *listing_tail;
3242           fragS *dummy_frag = (fragS *) xcalloc (1, sizeof (fragS));
3243           dummy_frag->line = listing_tail;
3244           dummy_frag->fr_symbol = symbolP;
3245           symbol_set_frag (symbolP, dummy_frag);
3246         }
3247 #endif
3248 #ifdef OBJ_COFF
3249       /* "set" symbols are local unless otherwise specified.  */
3250       SF_SET_LOCAL (symbolP);
3251 #endif
3252     }
3253
3254   if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3255     {
3256       if ((mode != 0 || !S_IS_VOLATILE (symbolP))
3257           && !S_CAN_BE_REDEFINED (symbolP))
3258         {
3259           as_bad (_("symbol `%s' is already defined"), name);
3260           symbolP = symbol_clone (symbolP, 0);
3261         }
3262       /* If the symbol is volatile, copy the symbol and replace the
3263          original with the copy, so that previous uses of the symbol will
3264          retain the value of the symbol at the point of use.  */
3265       else if (S_IS_VOLATILE (symbolP))
3266         symbolP = symbol_clone (symbolP, 1);
3267     }
3268
3269   if (mode == 0)
3270     S_SET_VOLATILE (symbolP);
3271   else if (mode < 0)
3272     S_SET_FORWARD_REF (symbolP);
3273
3274   pseudo_set (symbolP);
3275 }
3276
3277 /* Handle the .equ, .equiv, .eqv, and .set directives.  If EQUIV is 1,
3278    then this is .equiv, and it is an error if the symbol is already
3279    defined.  If EQUIV is -1, the symbol additionally is a forward
3280    reference.  */
3281
3282 void
3283 s_set (int equiv)
3284 {
3285   char *name;
3286   char delim;
3287   char *end_name;
3288
3289   /* Especial apologies for the random logic:
3290      this just grew, and could be parsed much more simply!
3291      Dean in haste.  */
3292   name = input_line_pointer;
3293   delim = get_symbol_end ();
3294   end_name = input_line_pointer;
3295   *end_name = delim;
3296
3297   if (name == end_name)
3298     {
3299       as_bad (_("expected symbol name"));
3300       ignore_rest_of_line ();
3301       return;
3302     }
3303
3304   SKIP_WHITESPACE ();
3305
3306   if (*input_line_pointer != ',')
3307     {
3308       *end_name = 0;
3309       as_bad (_("expected comma after \"%s\""), name);
3310       *end_name = delim;
3311       ignore_rest_of_line ();
3312       return;
3313     }
3314
3315   input_line_pointer++;
3316   *end_name = 0;
3317
3318   assign_symbol (name, equiv);
3319   *end_name = delim;
3320
3321   demand_empty_rest_of_line ();
3322 }
3323
3324 void
3325 s_space (int mult)
3326 {
3327   expressionS exp;
3328   expressionS val;
3329   char *p = 0;
3330   char *stop = NULL;
3331   char stopc = 0;
3332   int bytes;
3333
3334 #ifdef md_flush_pending_output
3335   md_flush_pending_output ();
3336 #endif
3337
3338 #ifdef md_cons_align
3339   md_cons_align (1);
3340 #endif
3341
3342   if (flag_mri)
3343     stop = mri_comment_field (&stopc);
3344
3345   /* In m68k MRI mode, we need to align to a word boundary, unless
3346      this is ds.b.  */
3347   if (flag_m68k_mri && mult > 1)
3348     {
3349       if (now_seg == absolute_section)
3350         {
3351           abs_section_offset += abs_section_offset & 1;
3352           if (line_label != NULL)
3353             S_SET_VALUE (line_label, abs_section_offset);
3354         }
3355       else if (mri_common_symbol != NULL)
3356         {
3357           valueT mri_val;
3358
3359           mri_val = S_GET_VALUE (mri_common_symbol);
3360           if ((mri_val & 1) != 0)
3361             {
3362               S_SET_VALUE (mri_common_symbol, mri_val + 1);
3363               if (line_label != NULL)
3364                 {
3365                   expressionS *symexp;
3366
3367                   symexp = symbol_get_value_expression (line_label);
3368                   know (symexp->X_op == O_symbol);
3369                   know (symexp->X_add_symbol == mri_common_symbol);
3370                   symexp->X_add_number += 1;
3371                 }
3372             }
3373         }
3374       else
3375         {
3376           do_align (1, (char *) NULL, 0, 0);
3377           if (line_label != NULL)
3378             {
3379               symbol_set_frag (line_label, frag_now);
3380               S_SET_VALUE (line_label, frag_now_fix ());
3381             }
3382         }
3383     }
3384
3385   bytes = mult;
3386
3387   expression (&exp);
3388
3389   SKIP_WHITESPACE ();
3390   if (*input_line_pointer == ',')
3391     {
3392       ++input_line_pointer;
3393       expression (&val);
3394     }
3395   else
3396     {
3397       val.X_op = O_constant;
3398       val.X_add_number = 0;
3399     }
3400
3401   if (val.X_op != O_constant
3402       || val.X_add_number < - 0x80
3403       || val.X_add_number > 0xff
3404       || (mult != 0 && mult != 1 && val.X_add_number != 0))
3405     {
3406       resolve_expression (&exp);
3407       if (exp.X_op != O_constant)
3408         as_bad (_("unsupported variable size or fill value"));
3409       else
3410         {
3411           offsetT i;
3412
3413           if (mult == 0)
3414             mult = 1;
3415           bytes = mult * exp.X_add_number;
3416           for (i = 0; i < exp.X_add_number; i++)
3417             emit_expr (&val, mult);
3418         }
3419     }
3420   else
3421     {
3422       if (now_seg == absolute_section || mri_common_symbol != NULL)
3423         resolve_expression (&exp);
3424
3425       if (exp.X_op == O_constant)
3426         {
3427           offsetT repeat;
3428
3429           repeat = exp.X_add_number;
3430           if (mult)
3431             repeat *= mult;
3432           bytes = repeat;
3433           if (repeat <= 0)
3434             {
3435               if (!flag_mri)
3436                 as_warn (_(".space repeat count is zero, ignored"));
3437               else if (repeat < 0)
3438                 as_warn (_(".space repeat count is negative, ignored"));
3439               goto getout;
3440             }
3441
3442           /* If we are in the absolute section, just bump the offset.  */
3443           if (now_seg == absolute_section)
3444             {
3445               abs_section_offset += repeat;
3446               goto getout;
3447             }
3448
3449           /* If we are secretly in an MRI common section, then
3450              creating space just increases the size of the common
3451              symbol.  */
3452           if (mri_common_symbol != NULL)
3453             {
3454               S_SET_VALUE (mri_common_symbol,
3455                            S_GET_VALUE (mri_common_symbol) + repeat);
3456               goto getout;
3457             }
3458
3459           if (!need_pass_2)
3460             p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0,
3461                           (offsetT) repeat, (char *) 0);
3462         }
3463       else
3464         {
3465           if (now_seg == absolute_section)
3466             {
3467               as_bad (_("space allocation too complex in absolute section"));
3468               subseg_set (text_section, 0);
3469             }
3470
3471           if (mri_common_symbol != NULL)
3472             {
3473               as_bad (_("space allocation too complex in common section"));
3474               mri_common_symbol = NULL;
3475             }
3476
3477           if (!need_pass_2)
3478             p = frag_var (rs_space, 1, 1, (relax_substateT) 0,
3479                           make_expr_symbol (&exp), (offsetT) 0, (char *) 0);
3480         }
3481
3482       if (p)
3483         *p = val.X_add_number;
3484     }
3485
3486  getout:
3487
3488   /* In MRI mode, after an odd number of bytes, we must align to an
3489      even word boundary, unless the next instruction is a dc.b, ds.b
3490      or dcb.b.  */
3491   if (flag_mri && (bytes & 1) != 0)
3492     mri_pending_align = 1;
3493
3494   demand_empty_rest_of_line ();
3495
3496   if (flag_mri)
3497     mri_comment_end (stop, stopc);
3498 }
3499
3500 /* This is like s_space, but the value is a floating point number with
3501    the given precision.  This is for the MRI dcb.s pseudo-op and
3502    friends.  */
3503
3504 void
3505 s_float_space (int float_type)
3506 {
3507   offsetT count;
3508   int flen;
3509   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
3510   char *stop = NULL;
3511   char stopc = 0;
3512
3513 #ifdef md_cons_align
3514   md_cons_align (1);
3515 #endif
3516
3517   if (flag_mri)
3518     stop = mri_comment_field (&stopc);
3519
3520   count = get_absolute_expression ();
3521
3522   SKIP_WHITESPACE ();
3523   if (*input_line_pointer != ',')
3524     {
3525       as_bad (_("missing value"));
3526       ignore_rest_of_line ();
3527       if (flag_mri)
3528         mri_comment_end (stop, stopc);
3529       return;
3530     }
3531
3532   ++input_line_pointer;
3533
3534   SKIP_WHITESPACE ();
3535
3536   /* Skip any 0{letter} that may be present.  Don't even check if the
3537    * letter is legal.  */
3538   if (input_line_pointer[0] == '0'
3539       && ISALPHA (input_line_pointer[1]))
3540     input_line_pointer += 2;
3541
3542   /* Accept :xxxx, where the x's are hex digits, for a floating point
3543      with the exact digits specified.  */
3544   if (input_line_pointer[0] == ':')
3545     {
3546       flen = hex_float (float_type, temp);
3547       if (flen < 0)
3548         {
3549           ignore_rest_of_line ();
3550           if (flag_mri)
3551             mri_comment_end (stop, stopc);
3552           return;
3553         }
3554     }
3555   else
3556     {
3557       char *err;
3558
3559       err = md_atof (float_type, temp, &flen);
3560       know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
3561       know (err != NULL || flen > 0);
3562       if (err)
3563         {
3564           as_bad (_("bad floating literal: %s"), err);
3565           ignore_rest_of_line ();
3566           if (flag_mri)
3567             mri_comment_end (stop, stopc);
3568           return;
3569         }
3570     }
3571
3572   while (--count >= 0)
3573     {
3574       char *p;
3575
3576       p = frag_more (flen);
3577       memcpy (p, temp, (unsigned int) flen);
3578     }
3579
3580   demand_empty_rest_of_line ();
3581
3582   if (flag_mri)
3583     mri_comment_end (stop, stopc);
3584 }
3585
3586 /* Handle the .struct pseudo-op, as found in MIPS assemblers.  */
3587
3588 void
3589 s_struct (int ignore ATTRIBUTE_UNUSED)
3590 {
3591   char *stop = NULL;
3592   char stopc = 0;
3593
3594   if (flag_mri)
3595     stop = mri_comment_field (&stopc);
3596   abs_section_offset = get_absolute_expression ();
3597 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
3598   /* The ELF backend needs to know that we are changing sections, so
3599      that .previous works correctly. */
3600   if (IS_ELF)
3601     obj_elf_section_change_hook ();
3602 #endif
3603   subseg_set (absolute_section, 0);
3604   demand_empty_rest_of_line ();
3605   if (flag_mri)
3606     mri_comment_end (stop, stopc);
3607 }
3608
3609 void
3610 s_text (int ignore ATTRIBUTE_UNUSED)
3611 {
3612   int temp;
3613
3614   temp = get_absolute_expression ();
3615   subseg_set (text_section, (subsegT) temp);
3616   demand_empty_rest_of_line ();
3617 }
3618
3619 /* .weakref x, y sets x as an alias to y that, as long as y is not
3620    referenced directly, will cause y to become a weak symbol.  */
3621 void
3622 s_weakref (int ignore ATTRIBUTE_UNUSED)
3623 {
3624   char *name;
3625   char delim;
3626   char *end_name;
3627   symbolS *symbolP;
3628   symbolS *symbolP2;
3629   expressionS exp;
3630
3631   name = input_line_pointer;
3632   delim = get_symbol_end ();
3633   end_name = input_line_pointer;
3634
3635   if (name == end_name)
3636     {
3637       as_bad (_("expected symbol name"));
3638       *end_name = delim;
3639       ignore_rest_of_line ();
3640       return;
3641     }
3642
3643   symbolP = symbol_find_or_make (name);
3644
3645   if (S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
3646     {
3647       if (!S_IS_VOLATILE (symbolP))
3648         {
3649           as_bad (_("symbol `%s' is already defined"), name);
3650           *end_name = delim;
3651           ignore_rest_of_line ();
3652           return;
3653         }
3654       symbolP = symbol_clone (symbolP, 1);
3655       S_CLEAR_VOLATILE (symbolP);
3656     }
3657
3658   *end_name = delim;
3659
3660   SKIP_WHITESPACE ();
3661
3662   if (*input_line_pointer != ',')
3663     {
3664       *end_name = 0;
3665       as_bad (_("expected comma after \"%s\""), name);
3666       *end_name = delim;
3667       ignore_rest_of_line ();
3668       return;
3669     }
3670
3671   input_line_pointer++;
3672
3673   SKIP_WHITESPACE ();
3674
3675   name = input_line_pointer;
3676   delim = get_symbol_end ();
3677   end_name = input_line_pointer;
3678
3679   if (name == end_name)
3680     {
3681       as_bad (_("expected symbol name"));
3682       ignore_rest_of_line ();
3683       return;
3684     }
3685
3686   if ((symbolP2 = symbol_find_noref (name, 1)) == NULL
3687       && (symbolP2 = md_undefined_symbol (name)) == NULL)
3688     {
3689       symbolP2 = symbol_find_or_make (name);
3690       S_SET_WEAKREFD (symbolP2);
3691     }
3692   else
3693     {
3694       symbolS *symp = symbolP2;
3695
3696       while (S_IS_WEAKREFR (symp) && symp != symbolP)
3697         {
3698           expressionS *expP = symbol_get_value_expression (symp);
3699
3700           gas_assert (expP->X_op == O_symbol
3701                   && expP->X_add_number == 0);
3702           symp = expP->X_add_symbol;
3703         }
3704       if (symp == symbolP)
3705         {
3706           char *loop;
3707
3708           loop = concat (S_GET_NAME (symbolP),
3709                          " => ", S_GET_NAME (symbolP2), (const char *) NULL);
3710
3711           symp = symbolP2;
3712           while (symp != symbolP)
3713             {
3714               char *old_loop = loop;
3715               symp = symbol_get_value_expression (symp)->X_add_symbol;
3716               loop = concat (loop, " => ", S_GET_NAME (symp),
3717                              (const char *) NULL);
3718               free (old_loop);
3719             }
3720
3721           as_bad (_("%s: would close weakref loop: %s"),
3722                   S_GET_NAME (symbolP), loop);
3723
3724           free (loop);
3725
3726           *end_name = delim;
3727           ignore_rest_of_line ();
3728           return;
3729         }
3730
3731       /* Short-circuiting instead of just checking here might speed
3732          things up a tiny little bit, but loop error messages would
3733          miss intermediate links.  */
3734       /* symbolP2 = symp; */
3735     }
3736
3737   *end_name = delim;
3738
3739   memset (&exp, 0, sizeof (exp));
3740   exp.X_op = O_symbol;
3741   exp.X_add_symbol = symbolP2;
3742
3743   S_SET_SEGMENT (symbolP, undefined_section);
3744   symbol_set_value_expression (symbolP, &exp);
3745   symbol_set_frag (symbolP, &zero_address_frag);
3746   S_SET_WEAKREFR (symbolP);
3747
3748   demand_empty_rest_of_line ();
3749 }
3750 \f
3751
3752 /* Verify that we are at the end of a line.  If not, issue an error and
3753    skip to EOL.  */
3754
3755 void
3756 demand_empty_rest_of_line (void)
3757 {
3758   SKIP_WHITESPACE ();
3759   if (is_end_of_line[(unsigned char) *input_line_pointer])
3760     input_line_pointer++;
3761   else
3762     {
3763       if (ISPRINT (*input_line_pointer))
3764         as_bad (_("junk at end of line, first unrecognized character is `%c'"),
3765                  *input_line_pointer);
3766       else
3767         as_bad (_("junk at end of line, first unrecognized character valued 0x%x"),
3768                  *input_line_pointer);
3769       ignore_rest_of_line ();
3770     }
3771
3772   /* Return pointing just after end-of-line.  */
3773   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3774 }
3775
3776 /* Silently advance to the end of line.  Use this after already having
3777    issued an error about something bad.  */
3778
3779 void
3780 ignore_rest_of_line (void)
3781 {
3782   while (input_line_pointer < buffer_limit
3783          && !is_end_of_line[(unsigned char) *input_line_pointer])
3784     input_line_pointer++;
3785
3786   input_line_pointer++;
3787
3788   /* Return pointing just after end-of-line.  */
3789   know (is_end_of_line[(unsigned char) input_line_pointer[-1]]);
3790 }
3791
3792 /* Sets frag for given symbol to zero_address_frag, except when the
3793    symbol frag is already set to a dummy listing frag.  */
3794
3795 static void
3796 set_zero_frag (symbolS *symbolP)
3797 {
3798   if (symbol_get_frag (symbolP)->fr_type != rs_dummy)
3799     symbol_set_frag (symbolP, &zero_address_frag);
3800 }
3801
3802 /* In:  Pointer to a symbol.
3803         Input_line_pointer->expression.
3804
3805    Out: Input_line_pointer->just after any whitespace after expression.
3806         Tried to set symbol to value of expression.
3807         Will change symbols type, value, and frag;  */
3808
3809 void
3810 pseudo_set (symbolS *symbolP)
3811 {
3812   expressionS exp;
3813   segT seg;
3814
3815   know (symbolP);               /* NULL pointer is logic error.  */
3816
3817   if (!S_IS_FORWARD_REF (symbolP))
3818     (void) expression (&exp);
3819   else
3820     (void) deferred_expression (&exp);
3821
3822   if (exp.X_op == O_illegal)
3823     as_bad (_("illegal expression"));
3824   else if (exp.X_op == O_absent)
3825     as_bad (_("missing expression"));
3826   else if (exp.X_op == O_big)
3827     {
3828       if (exp.X_add_number > 0)
3829         as_bad (_("bignum invalid"));
3830       else
3831         as_bad (_("floating point number invalid"));
3832     }
3833   else if (exp.X_op == O_subtract
3834            && !S_IS_FORWARD_REF (symbolP)
3835            && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol))
3836            && (symbol_get_frag (exp.X_add_symbol)
3837                == symbol_get_frag (exp.X_op_symbol)))
3838     {
3839       exp.X_op = O_constant;
3840       exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol)
3841                           - S_GET_VALUE (exp.X_op_symbol));
3842     }
3843
3844   if (symbol_section_p (symbolP))
3845     {
3846       as_bad ("attempt to set value of section symbol");
3847       return;
3848     }
3849
3850   switch (exp.X_op)
3851     {
3852     case O_illegal:
3853     case O_absent:
3854     case O_big:
3855       exp.X_add_number = 0;
3856       /* Fall through.  */
3857     case O_constant:
3858       S_SET_SEGMENT (symbolP, absolute_section);
3859       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3860       set_zero_frag (symbolP);
3861       break;
3862
3863     case O_register:
3864 #ifndef TC_GLOBAL_REGISTER_SYMBOL_OK
3865       if (S_IS_EXTERNAL (symbolP))
3866         {
3867           as_bad ("can't equate global symbol `%s' with register name",
3868                   S_GET_NAME (symbolP));
3869           return;
3870         }
3871 #endif
3872       S_SET_SEGMENT (symbolP, reg_section);
3873       S_SET_VALUE (symbolP, (valueT) exp.X_add_number);
3874       set_zero_frag (symbolP);
3875       symbol_get_value_expression (symbolP)->X_op = O_register;
3876       break;
3877
3878     case O_symbol:
3879       seg = S_GET_SEGMENT (exp.X_add_symbol);
3880       /* For x=undef+const, create an expression symbol.
3881          For x=x+const, just update x except when x is an undefined symbol
3882          For x=defined+const, evaluate x.  */
3883       if (symbolP == exp.X_add_symbol
3884           && (seg != undefined_section
3885               || !symbol_constant_p (symbolP)))
3886         {
3887           *symbol_X_add_number (symbolP) += exp.X_add_number;
3888           break;
3889         }
3890       else if (!S_IS_FORWARD_REF (symbolP) && seg != undefined_section)
3891         {
3892           symbolS *s = exp.X_add_symbol;
3893
3894           if (S_IS_COMMON (s))
3895             as_bad (_("`%s' can't be equated to common symbol '%s'"),
3896                     S_GET_NAME (symbolP), S_GET_NAME (s));
3897
3898           S_SET_SEGMENT (symbolP, seg);
3899           S_SET_VALUE (symbolP, exp.X_add_number + S_GET_VALUE (s));
3900           symbol_set_frag (symbolP, symbol_get_frag (s));
3901           copy_symbol_attributes (symbolP, s);
3902           break;
3903         }
3904       S_SET_SEGMENT (symbolP, undefined_section);
3905       symbol_set_value_expression (symbolP, &exp);
3906       copy_symbol_attributes (symbolP, exp.X_add_symbol);
3907       set_zero_frag (symbolP);
3908       break;
3909
3910     default:
3911       /* The value is some complex expression.  */
3912       S_SET_SEGMENT (symbolP, expr_section);
3913       symbol_set_value_expression (symbolP, &exp);
3914       set_zero_frag (symbolP);
3915       break;
3916     }
3917 }
3918 \f
3919 /*                      cons()
3920
3921    CONStruct more frag of .bytes, or .words etc.
3922    Should need_pass_2 be 1 then emit no frag(s).
3923    This understands EXPRESSIONS.
3924
3925    Bug (?)
3926
3927    This has a split personality. We use expression() to read the
3928    value. We can detect if the value won't fit in a byte or word.
3929    But we can't detect if expression() discarded significant digits
3930    in the case of a long. Not worth the crocks required to fix it.  */
3931
3932 /* Select a parser for cons expressions.  */
3933
3934 /* Some targets need to parse the expression in various fancy ways.
3935    You can define TC_PARSE_CONS_EXPRESSION to do whatever you like
3936    (for example, the HPPA does this).  Otherwise, you can define
3937    BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or
3938    REPEAT_CONS_EXPRESSIONS to permit repeat counts.  If none of these
3939    are defined, which is the normal case, then only simple expressions
3940    are permitted.  */
3941
3942 #ifdef TC_M68K
3943 static void
3944 parse_mri_cons (expressionS *exp, unsigned int nbytes);
3945 #endif
3946
3947 #ifndef TC_PARSE_CONS_EXPRESSION
3948 #ifdef BITFIELD_CONS_EXPRESSIONS
3949 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES)
3950 static void
3951 parse_bitfield_cons (expressionS *exp, unsigned int nbytes);
3952 #endif
3953 #ifdef REPEAT_CONS_EXPRESSIONS
3954 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES)
3955 static void
3956 parse_repeat_cons (expressionS *exp, unsigned int nbytes);
3957 #endif
3958
3959 /* If we haven't gotten one yet, just call expression.  */
3960 #ifndef TC_PARSE_CONS_EXPRESSION
3961 #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP)
3962 #endif
3963 #endif
3964
3965 void
3966 do_parse_cons_expression (expressionS *exp,
3967                           int nbytes ATTRIBUTE_UNUSED)
3968 {
3969   TC_PARSE_CONS_EXPRESSION (exp, nbytes);
3970 }
3971
3972
3973 /* Worker to do .byte etc statements.
3974    Clobbers input_line_pointer and checks end-of-line.  */
3975
3976 static void
3977 cons_worker (int nbytes,        /* 1=.byte, 2=.word, 4=.long.  */
3978              int rva)
3979 {
3980   int c;
3981   expressionS exp;
3982   char *stop = NULL;
3983   char stopc = 0;
3984
3985 #ifdef md_flush_pending_output
3986   md_flush_pending_output ();
3987 #endif
3988
3989   if (flag_mri)
3990     stop = mri_comment_field (&stopc);
3991
3992   if (is_it_end_of_statement ())
3993     {
3994       demand_empty_rest_of_line ();
3995       if (flag_mri)
3996         mri_comment_end (stop, stopc);
3997       return;
3998     }
3999
4000 #ifdef TC_ADDRESS_BYTES
4001   if (nbytes == 0)
4002     nbytes = TC_ADDRESS_BYTES ();
4003 #endif
4004
4005 #ifdef md_cons_align
4006   md_cons_align (nbytes);
4007 #endif
4008
4009   c = 0;
4010   do
4011     {
4012 #ifdef TC_M68K
4013       if (flag_m68k_mri)
4014         parse_mri_cons (&exp, (unsigned int) nbytes);
4015       else
4016 #endif
4017         {
4018           if (*input_line_pointer == '"')
4019             {
4020               as_bad (_("unexpected `\"' in expression"));
4021               ignore_rest_of_line ();
4022               return;
4023             }
4024           TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes);
4025         }
4026
4027       if (rva)
4028         {
4029           if (exp.X_op == O_symbol)
4030             exp.X_op = O_symbol_rva;
4031           else
4032             as_fatal (_("rva without symbol"));
4033         }
4034       emit_expr (&exp, (unsigned int) nbytes);
4035       ++c;
4036     }
4037   while (*input_line_pointer++ == ',');
4038
4039   /* In MRI mode, after an odd number of bytes, we must align to an
4040      even word boundary, unless the next instruction is a dc.b, ds.b
4041      or dcb.b.  */
4042   if (flag_mri && nbytes == 1 && (c & 1) != 0)
4043     mri_pending_align = 1;
4044
4045   input_line_pointer--;         /* Put terminator back into stream.  */
4046
4047   demand_empty_rest_of_line ();
4048
4049   if (flag_mri)
4050     mri_comment_end (stop, stopc);
4051 }
4052
4053 void
4054 cons (int size)
4055 {
4056   cons_worker (size, 0);
4057 }
4058
4059 void
4060 s_rva (int size)
4061 {
4062   cons_worker (size, 1);
4063 }
4064
4065 /* .reloc offset, reloc_name, symbol+addend.  */
4066
4067 void
4068 s_reloc (int ignore ATTRIBUTE_UNUSED)
4069 {
4070   char *stop = NULL;
4071   char stopc = 0;
4072   expressionS exp;
4073   char *r_name;
4074   int c;
4075   struct reloc_list *reloc;
4076
4077   reloc = (struct reloc_list *) xmalloc (sizeof (*reloc));
4078
4079   if (flag_mri)
4080     stop = mri_comment_field (&stopc);
4081
4082   expression (&exp);
4083   switch (exp.X_op)
4084     {
4085     case O_illegal:
4086     case O_absent:
4087     case O_big:
4088     case O_register:
4089       as_bad (_("missing or bad offset expression"));
4090       goto err_out;
4091     case O_constant:
4092       exp.X_add_symbol = section_symbol (now_seg);
4093       exp.X_op = O_symbol;
4094       /* Fall thru */
4095     case O_symbol:
4096       if (exp.X_add_number == 0)
4097         {
4098           reloc->u.a.offset_sym = exp.X_add_symbol;
4099           break;
4100         }
4101       /* Fall thru */
4102     default:
4103       reloc->u.a.offset_sym = make_expr_symbol (&exp);
4104       break;
4105     }
4106
4107   SKIP_WHITESPACE ();
4108   if (*input_line_pointer != ',')
4109     {
4110       as_bad (_("missing reloc type"));
4111       goto err_out;
4112     }
4113
4114   ++input_line_pointer;
4115   SKIP_WHITESPACE ();
4116   r_name = input_line_pointer;
4117   c = get_symbol_end ();
4118   reloc->u.a.howto = bfd_reloc_name_lookup (stdoutput, r_name);
4119   *input_line_pointer = c;
4120   if (reloc->u.a.howto == NULL)
4121     {
4122       as_bad (_("unrecognized reloc type"));
4123       goto err_out;
4124     }
4125
4126   exp.X_op = O_absent;
4127   SKIP_WHITESPACE ();
4128   if (*input_line_pointer == ',')
4129     {
4130       ++input_line_pointer;
4131       expression (&exp);
4132     }
4133   switch (exp.X_op)
4134     {
4135     case O_illegal:
4136     case O_big:
4137     case O_register:
4138       as_bad (_("bad reloc expression"));
4139     err_out:
4140       ignore_rest_of_line ();
4141       free (reloc);
4142       if (flag_mri)
4143         mri_comment_end (stop, stopc);
4144       return;
4145     case O_absent:
4146       reloc->u.a.sym = NULL;
4147       reloc->u.a.addend = 0;
4148       break;
4149     case O_constant:
4150       reloc->u.a.sym = NULL;
4151       reloc->u.a.addend = exp.X_add_number;
4152       break;
4153     case O_symbol:
4154       reloc->u.a.sym = exp.X_add_symbol;
4155       reloc->u.a.addend = exp.X_add_number;
4156       break;
4157     default:
4158       reloc->u.a.sym = make_expr_symbol (&exp);
4159       reloc->u.a.addend = 0;
4160       break;
4161     }
4162
4163   as_where (&reloc->file, &reloc->line);
4164   reloc->next = reloc_list;
4165   reloc_list = reloc;
4166
4167   demand_empty_rest_of_line ();
4168   if (flag_mri)
4169     mri_comment_end (stop, stopc);
4170 }
4171
4172 /* Put the contents of expression EXP into the object file using
4173    NBYTES bytes.  If need_pass_2 is 1, this does nothing.  */
4174
4175 void
4176 emit_expr (expressionS *exp, unsigned int nbytes)
4177 {
4178   operatorT op;
4179   char *p;
4180   valueT extra_digit = 0;
4181
4182   /* Don't do anything if we are going to make another pass.  */
4183   if (need_pass_2)
4184     return;
4185
4186   /* Grow the current frag now so that dot_value does not get invalidated
4187      if the frag were to fill up in the frag_more() call below.  */
4188   frag_grow (nbytes);
4189   dot_value = frag_now_fix ();
4190
4191 #ifndef NO_LISTING
4192 #ifdef OBJ_ELF
4193   /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will
4194      appear as a four byte positive constant in the .line section,
4195      followed by a 2 byte 0xffff.  Look for that case here.  */
4196   {
4197     static int dwarf_line = -1;
4198
4199     if (strcmp (segment_name (now_seg), ".line") != 0)
4200       dwarf_line = -1;
4201     else if (dwarf_line >= 0
4202              && nbytes == 2
4203              && exp->X_op == O_constant
4204              && (exp->X_add_number == -1 || exp->X_add_number == 0xffff))
4205       listing_source_line ((unsigned int) dwarf_line);
4206     else if (nbytes == 4
4207              && exp->X_op == O_constant
4208              && exp->X_add_number >= 0)
4209       dwarf_line = exp->X_add_number;
4210     else
4211       dwarf_line = -1;
4212   }
4213
4214   /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will
4215      appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte
4216      AT_sibling (0x12) followed by a four byte address of the sibling
4217      followed by a 2 byte AT_name (0x38) followed by the name of the
4218      file.  We look for that case here.  */
4219   {
4220     static int dwarf_file = 0;
4221
4222     if (strcmp (segment_name (now_seg), ".debug") != 0)
4223       dwarf_file = 0;
4224     else if (dwarf_file == 0
4225              && nbytes == 2
4226              && exp->X_op == O_constant
4227              && exp->X_add_number == 0x11)
4228       dwarf_file = 1;
4229     else if (dwarf_file == 1
4230              && nbytes == 2
4231              && exp->X_op == O_constant
4232              && exp->X_add_number == 0x12)
4233       dwarf_file = 2;
4234     else if (dwarf_file == 2
4235              && nbytes == 4)
4236       dwarf_file = 3;
4237     else if (dwarf_file == 3
4238              && nbytes == 2
4239              && exp->X_op == O_constant
4240              && exp->X_add_number == 0x38)
4241       dwarf_file = 4;
4242     else
4243       dwarf_file = 0;
4244
4245     /* The variable dwarf_file_string tells stringer that the string
4246        may be the name of the source file.  */
4247     if (dwarf_file == 4)
4248       dwarf_file_string = 1;
4249     else
4250       dwarf_file_string = 0;
4251   }
4252 #endif
4253 #endif
4254
4255   if (check_eh_frame (exp, &nbytes))
4256     return;
4257
4258   op = exp->X_op;
4259
4260   /* Allow `.word 0' in the absolute section.  */
4261   if (now_seg == absolute_section)
4262     {
4263       if (op != O_constant || exp->X_add_number != 0)
4264         as_bad (_("attempt to store value in absolute section"));
4265       abs_section_offset += nbytes;
4266       return;
4267     }
4268
4269   /* Handle a negative bignum.  */
4270   if (op == O_uminus
4271       && exp->X_add_number == 0
4272       && symbol_get_value_expression (exp->X_add_symbol)->X_op == O_big
4273       && symbol_get_value_expression (exp->X_add_symbol)->X_add_number > 0)
4274     {
4275       int i;
4276       unsigned long carry;
4277
4278       exp = symbol_get_value_expression (exp->X_add_symbol);
4279
4280       /* Negate the bignum: one's complement each digit and add 1.  */
4281       carry = 1;
4282       for (i = 0; i < exp->X_add_number; i++)
4283         {
4284           unsigned long next;
4285
4286           next = (((~(generic_bignum[i] & LITTLENUM_MASK))
4287                    & LITTLENUM_MASK)
4288                   + carry);
4289           generic_bignum[i] = next & LITTLENUM_MASK;
4290           carry = next >> LITTLENUM_NUMBER_OF_BITS;
4291         }
4292
4293       /* We can ignore any carry out, because it will be handled by
4294          extra_digit if it is needed.  */
4295
4296       extra_digit = (valueT) -1;
4297       op = O_big;
4298     }
4299
4300   if (op == O_absent || op == O_illegal)
4301     {
4302       as_warn (_("zero assumed for missing expression"));
4303       exp->X_add_number = 0;
4304       op = O_constant;
4305     }
4306   else if (op == O_big && exp->X_add_number <= 0)
4307     {
4308       as_bad (_("floating point number invalid"));
4309       exp->X_add_number = 0;
4310       op = O_constant;
4311     }
4312   else if (op == O_register)
4313     {
4314       as_warn (_("register value used as expression"));
4315       op = O_constant;
4316     }
4317
4318   p = frag_more ((int) nbytes);
4319
4320 #ifndef WORKING_DOT_WORD
4321   /* If we have the difference of two symbols in a word, save it on
4322      the broken_words list.  See the code in write.c.  */
4323   if (op == O_subtract && nbytes == 2)
4324     {
4325       struct broken_word *x;
4326
4327       x = (struct broken_word *) xmalloc (sizeof (struct broken_word));
4328       x->next_broken_word = broken_words;
4329       broken_words = x;
4330       x->seg = now_seg;
4331       x->subseg = now_subseg;
4332       x->frag = frag_now;
4333       x->word_goes_here = p;
4334       x->dispfrag = 0;
4335       x->add = exp->X_add_symbol;
4336       x->sub = exp->X_op_symbol;
4337       x->addnum = exp->X_add_number;
4338       x->added = 0;
4339       x->use_jump = 0;
4340       new_broken_words++;
4341       return;
4342     }
4343 #endif
4344
4345   /* If we have an integer, but the number of bytes is too large to
4346      pass to md_number_to_chars, handle it as a bignum.  */
4347   if (op == O_constant && nbytes > sizeof (valueT))
4348     {
4349       extra_digit = exp->X_unsigned ? 0 : -1;
4350       convert_to_bignum (exp);
4351       op = O_big;
4352     }
4353
4354   if (op == O_constant)
4355     {
4356       valueT get;
4357       valueT use;
4358       valueT mask;
4359       valueT hibit;
4360       valueT unmask;
4361
4362       /* JF << of >= number of bits in the object is undefined.  In
4363          particular SPARC (Sun 4) has problems.  */
4364       if (nbytes >= sizeof (valueT))
4365         {
4366           mask = 0;
4367           if (nbytes > sizeof (valueT))
4368             hibit = 0;
4369           else
4370             hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4371         }
4372       else
4373         {
4374           /* Don't store these bits.  */
4375           mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes);
4376           hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1);
4377         }
4378
4379       unmask = ~mask;           /* Do store these bits.  */
4380
4381 #ifdef NEVER
4382       "Do this mod if you want every overflow check to assume SIGNED 2's complement data.";
4383       mask = ~(unmask >> 1);    /* Includes sign bit now.  */
4384 #endif
4385
4386       get = exp->X_add_number;
4387       use = get & unmask;
4388       if ((get & mask) != 0
4389           && ((get & mask) != mask
4390               || (get & hibit) == 0))
4391         {               /* Leading bits contain both 0s & 1s.  */
4392 #if defined (BFD64) && BFD_HOST_64BIT_LONG_LONG
4393 #ifndef __MSVCRT__
4394           as_warn (_("value 0x%llx truncated to 0x%llx"),
4395                    (unsigned long long) get, (unsigned long long) use);
4396 #else
4397           as_warn (_("value 0x%I64x truncated to 0x%I64x"),
4398                    (unsigned long long) get, (unsigned long long) use);
4399 #endif
4400 #else
4401           as_warn (_("value 0x%lx truncated to 0x%lx"),
4402                    (unsigned long) get, (unsigned long) use);
4403 #endif
4404         }
4405       /* Put bytes in right order.  */
4406       md_number_to_chars (p, use, (int) nbytes);
4407     }
4408   else if (op == O_big)
4409     {
4410       unsigned int size;
4411       LITTLENUM_TYPE *nums;
4412
4413       size = exp->X_add_number * CHARS_PER_LITTLENUM;
4414       if (nbytes < size)
4415         {
4416           int i = nbytes / CHARS_PER_LITTLENUM;
4417           if (i != 0)
4418             {
4419               LITTLENUM_TYPE sign = 0;
4420               if ((generic_bignum[--i]
4421                    & (1 << (LITTLENUM_NUMBER_OF_BITS - 1))) != 0)
4422                 sign = ~(LITTLENUM_TYPE) 0;
4423               while (++i < exp->X_add_number)
4424                 if (generic_bignum[i] != sign)
4425                   break;
4426             }
4427           if (i < exp->X_add_number)
4428             as_warn (_("bignum truncated to %d bytes"), nbytes);
4429           size = nbytes;
4430         }
4431
4432       if (nbytes == 1)
4433         {
4434           md_number_to_chars (p, (valueT) generic_bignum[0], 1);
4435           return;
4436         }
4437       know (nbytes % CHARS_PER_LITTLENUM == 0);
4438
4439       if (target_big_endian)
4440         {
4441           while (nbytes > size)
4442             {
4443               md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4444               nbytes -= CHARS_PER_LITTLENUM;
4445               p += CHARS_PER_LITTLENUM;
4446             }
4447
4448           nums = generic_bignum + size / CHARS_PER_LITTLENUM;
4449           while (size >= CHARS_PER_LITTLENUM)
4450             {
4451               --nums;
4452               md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4453               size -= CHARS_PER_LITTLENUM;
4454               p += CHARS_PER_LITTLENUM;
4455             }
4456         }
4457       else
4458         {
4459           nums = generic_bignum;
4460           while (size >= CHARS_PER_LITTLENUM)
4461             {
4462               md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM);
4463               ++nums;
4464               size -= CHARS_PER_LITTLENUM;
4465               p += CHARS_PER_LITTLENUM;
4466               nbytes -= CHARS_PER_LITTLENUM;
4467             }
4468
4469           while (nbytes >= CHARS_PER_LITTLENUM)
4470             {
4471               md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM);
4472               nbytes -= CHARS_PER_LITTLENUM;
4473               p += CHARS_PER_LITTLENUM;
4474             }
4475         }
4476     }
4477   else
4478     emit_expr_fix (exp, nbytes, frag_now, p);
4479 }
4480
4481 void
4482 emit_expr_fix (expressionS *exp, unsigned int nbytes, fragS *frag, char *p)
4483 {
4484   memset (p, 0, nbytes);
4485
4486   /* Generate a fixS to record the symbol value.  */
4487
4488 #ifdef TC_CONS_FIX_NEW
4489   TC_CONS_FIX_NEW (frag, p - frag->fr_literal, nbytes, exp);
4490 #else
4491   {
4492     bfd_reloc_code_real_type r;
4493
4494     switch (nbytes)
4495       {
4496       case 1:
4497         r = BFD_RELOC_8;
4498         break;
4499       case 2:
4500         r = BFD_RELOC_16;
4501         break;
4502       case 3:
4503         r = BFD_RELOC_24;
4504         break;
4505       case 4:
4506         r = BFD_RELOC_32;
4507         break;
4508       case 8:
4509         r = BFD_RELOC_64;
4510         break;
4511       default:
4512         as_bad (_("unsupported BFD relocation size %u"), nbytes);
4513         r = BFD_RELOC_32;
4514         break;
4515       }
4516     fix_new_exp (frag, p - frag->fr_literal, (int) nbytes, exp,
4517                  0, r);
4518   }
4519 #endif
4520 }
4521 \f
4522 #ifdef BITFIELD_CONS_EXPRESSIONS
4523
4524 /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as
4525    w:x,y:z, where w and y are bitwidths and x and y are values.  They
4526    then pack them all together. We do a little better in that we allow
4527    them in words, longs, etc. and we'll pack them in target byte order
4528    for you.
4529
4530    The rules are: pack least significant bit first, if a field doesn't
4531    entirely fit, put it in the next unit.  Overflowing the bitfield is
4532    explicitly *not* even a warning.  The bitwidth should be considered
4533    a "mask".
4534
4535    To use this function the tc-XXX.h file should define
4536    BITFIELD_CONS_EXPRESSIONS.  */
4537
4538 static void
4539 parse_bitfield_cons (exp, nbytes)
4540      expressionS *exp;
4541      unsigned int nbytes;
4542 {
4543   unsigned int bits_available = BITS_PER_CHAR * nbytes;
4544   char *hold = input_line_pointer;
4545
4546   (void) expression (exp);
4547
4548   if (*input_line_pointer == ':')
4549     {
4550       /* Bitfields.  */
4551       long value = 0;
4552
4553       for (;;)
4554         {
4555           unsigned long width;
4556
4557           if (*input_line_pointer != ':')
4558             {
4559               input_line_pointer = hold;
4560               break;
4561             }                   /* Next piece is not a bitfield.  */
4562
4563           /* In the general case, we can't allow
4564              full expressions with symbol
4565              differences and such.  The relocation
4566              entries for symbols not defined in this
4567              assembly would require arbitrary field
4568              widths, positions, and masks which most
4569              of our current object formats don't
4570              support.
4571
4572              In the specific case where a symbol
4573              *is* defined in this assembly, we
4574              *could* build fixups and track it, but
4575              this could lead to confusion for the
4576              backends.  I'm lazy. I'll take any
4577              SEG_ABSOLUTE. I think that means that
4578              you can use a previous .set or
4579              .equ type symbol.  xoxorich.  */
4580
4581           if (exp->X_op == O_absent)
4582             {
4583               as_warn (_("using a bit field width of zero"));
4584               exp->X_add_number = 0;
4585               exp->X_op = O_constant;
4586             }                   /* Implied zero width bitfield.  */
4587
4588           if (exp->X_op != O_constant)
4589             {
4590               *input_line_pointer = '\0';
4591               as_bad (_("field width \"%s\" too complex for a bitfield"), hold);
4592               *input_line_pointer = ':';
4593               demand_empty_rest_of_line ();
4594               return;
4595             }                   /* Too complex.  */
4596
4597           if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes))
4598             {
4599               as_warn (_("field width %lu too big to fit in %d bytes: truncated to %d bits"),
4600                        width, nbytes, (BITS_PER_CHAR * nbytes));
4601               width = BITS_PER_CHAR * nbytes;
4602             }                   /* Too big.  */
4603
4604           if (width > bits_available)
4605             {
4606               /* FIXME-SOMEDAY: backing up and reparsing is wasteful.  */
4607               input_line_pointer = hold;
4608               exp->X_add_number = value;
4609               break;
4610             }                   /* Won't fit.  */
4611
4612           /* Skip ':'.  */
4613           hold = ++input_line_pointer;
4614
4615           (void) expression (exp);
4616           if (exp->X_op != O_constant)
4617             {
4618               char cache = *input_line_pointer;
4619
4620               *input_line_pointer = '\0';
4621               as_bad (_("field value \"%s\" too complex for a bitfield"), hold);
4622               *input_line_pointer = cache;
4623               demand_empty_rest_of_line ();
4624               return;
4625             }                   /* Too complex.  */
4626
4627           value |= ((~(-1 << width) & exp->X_add_number)
4628                     << ((BITS_PER_CHAR * nbytes) - bits_available));
4629
4630           if ((bits_available -= width) == 0
4631               || is_it_end_of_statement ()
4632               || *input_line_pointer != ',')
4633             {
4634               break;
4635             }                   /* All the bitfields we're gonna get.  */
4636
4637           hold = ++input_line_pointer;
4638           (void) expression (exp);
4639         }
4640
4641       exp->X_add_number = value;
4642       exp->X_op = O_constant;
4643       exp->X_unsigned = 1;
4644     }
4645 }
4646
4647 #endif /* BITFIELD_CONS_EXPRESSIONS */
4648 \f
4649 /* Handle an MRI style string expression.  */
4650
4651 #ifdef TC_M68K
4652 static void
4653 parse_mri_cons (exp, nbytes)
4654      expressionS *exp;
4655      unsigned int nbytes;
4656 {
4657   if (*input_line_pointer != '\''
4658       && (input_line_pointer[1] != '\''
4659           || (*input_line_pointer != 'A'
4660               && *input_line_pointer != 'E')))
4661     TC_PARSE_CONS_EXPRESSION (exp, nbytes);
4662   else
4663     {
4664       unsigned int scan;
4665       unsigned int result = 0;
4666
4667       /* An MRI style string.  Cut into as many bytes as will fit into
4668          a nbyte chunk, left justify if necessary, and separate with
4669          commas so we can try again later.  */
4670       if (*input_line_pointer == 'A')
4671         ++input_line_pointer;
4672       else if (*input_line_pointer == 'E')
4673         {
4674           as_bad (_("EBCDIC constants are not supported"));
4675           ++input_line_pointer;
4676         }
4677
4678       input_line_pointer++;
4679       for (scan = 0; scan < nbytes; scan++)
4680         {
4681           if (*input_line_pointer == '\'')
4682             {
4683               if (input_line_pointer[1] == '\'')
4684                 {
4685                   input_line_pointer++;
4686                 }
4687               else
4688                 break;
4689             }
4690           result = (result << 8) | (*input_line_pointer++);
4691         }
4692
4693       /* Left justify.  */
4694       while (scan < nbytes)
4695         {
4696           result <<= 8;
4697           scan++;
4698         }
4699
4700       /* Create correct expression.  */
4701       exp->X_op = O_constant;
4702       exp->X_add_number = result;
4703
4704       /* Fake it so that we can read the next char too.  */
4705       if (input_line_pointer[0] != '\'' ||
4706           (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\''))
4707         {
4708           input_line_pointer -= 2;
4709           input_line_pointer[0] = ',';
4710           input_line_pointer[1] = '\'';
4711         }
4712       else
4713         input_line_pointer++;
4714     }
4715 }
4716 #endif /* TC_M68K */
4717 \f
4718 #ifdef REPEAT_CONS_EXPRESSIONS
4719
4720 /* Parse a repeat expression for cons.  This is used by the MIPS
4721    assembler.  The format is NUMBER:COUNT; NUMBER appears in the
4722    object file COUNT times.
4723
4724    To use this for a target, define REPEAT_CONS_EXPRESSIONS.  */
4725
4726 static void
4727 parse_repeat_cons (exp, nbytes)
4728      expressionS *exp;
4729      unsigned int nbytes;
4730 {
4731   expressionS count;
4732   int i;
4733
4734   expression (exp);
4735
4736   if (*input_line_pointer != ':')
4737     {
4738       /* No repeat count.  */
4739       return;
4740     }
4741
4742   ++input_line_pointer;
4743   expression (&count);
4744   if (count.X_op != O_constant
4745       || count.X_add_number <= 0)
4746     {
4747       as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4748       return;
4749     }
4750
4751   /* The cons function is going to output this expression once.  So we
4752      output it count - 1 times.  */
4753   for (i = count.X_add_number - 1; i > 0; i--)
4754     emit_expr (exp, nbytes);
4755 }
4756
4757 #endif /* REPEAT_CONS_EXPRESSIONS */
4758 \f
4759 /* Parse a floating point number represented as a hex constant.  This
4760    permits users to specify the exact bits they want in the floating
4761    point number.  */
4762
4763 static int
4764 hex_float (int float_type, char *bytes)
4765 {
4766   int length;
4767   int i;
4768
4769   switch (float_type)
4770     {
4771     case 'f':
4772     case 'F':
4773     case 's':
4774     case 'S':
4775       length = 4;
4776       break;
4777
4778     case 'd':
4779     case 'D':
4780     case 'r':
4781     case 'R':
4782       length = 8;
4783       break;
4784
4785     case 'x':
4786     case 'X':
4787       length = 12;
4788       break;
4789
4790     case 'p':
4791     case 'P':
4792       length = 12;
4793       break;
4794
4795     default:
4796       as_bad (_("unknown floating type type '%c'"), float_type);
4797       return -1;
4798     }
4799
4800   /* It would be nice if we could go through expression to parse the
4801      hex constant, but if we get a bignum it's a pain to sort it into
4802      the buffer correctly.  */
4803   i = 0;
4804   while (hex_p (*input_line_pointer) || *input_line_pointer == '_')
4805     {
4806       int d;
4807
4808       /* The MRI assembler accepts arbitrary underscores strewn about
4809          through the hex constant, so we ignore them as well.  */
4810       if (*input_line_pointer == '_')
4811         {
4812           ++input_line_pointer;
4813           continue;
4814         }
4815
4816       if (i >= length)
4817         {
4818           as_warn (_("floating point constant too large"));
4819           return -1;
4820         }
4821       d = hex_value (*input_line_pointer) << 4;
4822       ++input_line_pointer;
4823       while (*input_line_pointer == '_')
4824         ++input_line_pointer;
4825       if (hex_p (*input_line_pointer))
4826         {
4827           d += hex_value (*input_line_pointer);
4828           ++input_line_pointer;
4829         }
4830       if (target_big_endian)
4831         bytes[i] = d;
4832       else
4833         bytes[length - i - 1] = d;
4834       ++i;
4835     }
4836
4837   if (i < length)
4838     {
4839       if (target_big_endian)
4840         memset (bytes + i, 0, length - i);
4841       else
4842         memset (bytes, 0, length - i);
4843     }
4844
4845   return length;
4846 }
4847
4848 /*                      float_cons()
4849
4850    CONStruct some more frag chars of .floats .ffloats etc.
4851    Makes 0 or more new frags.
4852    If need_pass_2 == 1, no frags are emitted.
4853    This understands only floating literals, not expressions. Sorry.
4854
4855    A floating constant is defined by atof_generic(), except it is preceded
4856    by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its
4857    reading, I decided to be incompatible. This always tries to give you
4858    rounded bits to the precision of the pseudo-op. Former AS did premature
4859    truncation, restored noisy bits instead of trailing 0s AND gave you
4860    a choice of 2 flavours of noise according to which of 2 floating-point
4861    scanners you directed AS to use.
4862
4863    In:  input_line_pointer->whitespace before, or '0' of flonum.  */
4864
4865 void
4866 float_cons (/* Clobbers input_line-pointer, checks end-of-line.  */
4867             int float_type      /* 'f':.ffloat ... 'F':.float ...  */)
4868 {
4869   char *p;
4870   int length;                   /* Number of chars in an object.  */
4871   char *err;            /* Error from scanning floating literal.  */
4872   char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT];
4873
4874   if (is_it_end_of_statement ())
4875     {
4876       demand_empty_rest_of_line ();
4877       return;
4878     }
4879
4880 #ifdef md_flush_pending_output
4881   md_flush_pending_output ();
4882 #endif
4883
4884 #ifdef md_cons_align
4885   md_cons_align (1);
4886 #endif
4887
4888   do
4889     {
4890       /* input_line_pointer->1st char of a flonum (we hope!).  */
4891       SKIP_WHITESPACE ();
4892
4893       /* Skip any 0{letter} that may be present. Don't even check if the
4894          letter is legal. Someone may invent a "z" format and this routine
4895          has no use for such information. Lusers beware: you get
4896          diagnostics if your input is ill-conditioned.  */
4897       if (input_line_pointer[0] == '0'
4898           && ISALPHA (input_line_pointer[1]))
4899         input_line_pointer += 2;
4900
4901       /* Accept :xxxx, where the x's are hex digits, for a floating
4902          point with the exact digits specified.  */
4903       if (input_line_pointer[0] == ':')
4904         {
4905           ++input_line_pointer;
4906           length = hex_float (float_type, temp);
4907           if (length < 0)
4908             {
4909               ignore_rest_of_line ();
4910               return;
4911             }
4912         }
4913       else
4914         {
4915           err = md_atof (float_type, temp, &length);
4916           know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT);
4917           know (err != NULL || length > 0);
4918           if (err)
4919             {
4920               as_bad (_("bad floating literal: %s"), err);
4921               ignore_rest_of_line ();
4922               return;
4923             }
4924         }
4925
4926       if (!need_pass_2)
4927         {
4928           int count;
4929
4930           count = 1;
4931
4932 #ifdef REPEAT_CONS_EXPRESSIONS
4933           if (*input_line_pointer == ':')
4934             {
4935               expressionS count_exp;
4936
4937               ++input_line_pointer;
4938               expression (&count_exp);
4939
4940               if (count_exp.X_op != O_constant
4941                   || count_exp.X_add_number <= 0)
4942                 as_warn (_("unresolvable or nonpositive repeat count; using 1"));
4943               else
4944                 count = count_exp.X_add_number;
4945             }
4946 #endif
4947
4948           while (--count >= 0)
4949             {
4950               p = frag_more (length);
4951               memcpy (p, temp, (unsigned int) length);
4952             }
4953         }
4954       SKIP_WHITESPACE ();
4955     }
4956   while (*input_line_pointer++ == ',');
4957
4958   /* Put terminator back into stream.  */
4959   --input_line_pointer;
4960   demand_empty_rest_of_line ();
4961 }
4962 \f
4963 /* Return the size of a LEB128 value.  */
4964
4965 static inline int
4966 sizeof_sleb128 (offsetT value)
4967 {
4968   int size = 0;
4969   unsigned byte;
4970
4971   do
4972     {
4973       byte = (value & 0x7f);
4974       /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
4975          Fortunately, we can structure things so that the extra work reduces
4976          to a noop on systems that do things "properly".  */
4977       value = (value >> 7) | ~(-(offsetT)1 >> 7);
4978       size += 1;
4979     }
4980   while (!(((value == 0) && ((byte & 0x40) == 0))
4981            || ((value == -1) && ((byte & 0x40) != 0))));
4982
4983   return size;
4984 }
4985
4986 static inline int
4987 sizeof_uleb128 (valueT value)
4988 {
4989   int size = 0;
4990
4991   do
4992     {
4993       value >>= 7;
4994       size += 1;
4995     }
4996   while (value != 0);
4997
4998   return size;
4999 }
5000
5001 int
5002 sizeof_leb128 (valueT value, int sign)
5003 {
5004   if (sign)
5005     return sizeof_sleb128 ((offsetT) value);
5006   else
5007     return sizeof_uleb128 (value);
5008 }
5009
5010 /* Output a LEB128 value.  */
5011
5012 static inline int
5013 output_sleb128 (char *p, offsetT value)
5014 {
5015   char *orig = p;
5016   int more;
5017
5018   do
5019     {
5020       unsigned byte = (value & 0x7f);
5021
5022       /* Sadly, we cannot rely on typical arithmetic right shift behaviour.
5023          Fortunately, we can structure things so that the extra work reduces
5024          to a noop on systems that do things "properly".  */
5025       value = (value >> 7) | ~(-(offsetT)1 >> 7);
5026
5027       more = !((((value == 0) && ((byte & 0x40) == 0))
5028                 || ((value == -1) && ((byte & 0x40) != 0))));
5029       if (more)
5030         byte |= 0x80;
5031
5032       *p++ = byte;
5033     }
5034   while (more);
5035
5036   return p - orig;
5037 }
5038
5039 static inline int
5040 output_uleb128 (char *p, valueT value)
5041 {
5042   char *orig = p;
5043
5044   do
5045     {
5046       unsigned byte = (value & 0x7f);
5047       value >>= 7;
5048       if (value != 0)
5049         /* More bytes to follow.  */
5050         byte |= 0x80;
5051
5052       *p++ = byte;
5053     }
5054   while (value != 0);
5055
5056   return p - orig;
5057 }
5058
5059 int
5060 output_leb128 (char *p, valueT value, int sign)
5061 {
5062   if (sign)
5063     return output_sleb128 (p, (offsetT) value);
5064   else
5065     return output_uleb128 (p, value);
5066 }
5067
5068 /* Do the same for bignums.  We combine sizeof with output here in that
5069    we don't output for NULL values of P.  It isn't really as critical as
5070    for "normal" values that this be streamlined.  */
5071
5072 static inline int
5073 output_big_sleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
5074 {
5075   char *orig = p;
5076   valueT val = 0;
5077   int loaded = 0;
5078   unsigned byte;
5079
5080   /* Strip leading sign extensions off the bignum.  */
5081   while (size > 1
5082          && bignum[size - 1] == LITTLENUM_MASK
5083          && bignum[size - 2] > LITTLENUM_MASK / 2)
5084     size--;
5085
5086   do
5087     {
5088       /* OR in the next part of the littlenum.  */
5089       val |= (*bignum << loaded);
5090       loaded += LITTLENUM_NUMBER_OF_BITS;
5091       size--;
5092       bignum++;
5093
5094       /* Add bytes until there are less than 7 bits left in VAL
5095          or until every non-sign bit has been written.  */
5096       do
5097         {
5098           byte = val & 0x7f;
5099           loaded -= 7;
5100           val >>= 7;
5101           if (size > 0
5102               || val != ((byte & 0x40) == 0 ? 0 : ((valueT) 1 << loaded) - 1))
5103             byte |= 0x80;
5104
5105           if (orig)
5106             *p = byte;
5107           p++;
5108         }
5109       while ((byte & 0x80) != 0 && loaded >= 7);
5110     }
5111   while (size > 0);
5112
5113   /* Mop up any left-over bits (of which there will be less than 7).  */
5114   if ((byte & 0x80) != 0)
5115     {
5116       /* Sign-extend VAL.  */
5117       if (val & (1 << (loaded - 1)))
5118         val |= ~0 << loaded;
5119       if (orig)
5120         *p = val & 0x7f;
5121       p++;
5122     }
5123
5124   return p - orig;
5125 }
5126
5127 static inline int
5128 output_big_uleb128 (char *p, LITTLENUM_TYPE *bignum, int size)
5129 {
5130   char *orig = p;
5131   valueT val = 0;
5132   int loaded = 0;
5133   unsigned byte;
5134
5135   /* Strip leading zeros off the bignum.  */
5136   /* XXX: Is this needed?  */
5137   while (size > 0 && bignum[size - 1] == 0)
5138     size--;
5139
5140   do
5141     {
5142       if (loaded < 7 && size > 0)
5143         {
5144           val |= (*bignum << loaded);
5145           loaded += 8 * CHARS_PER_LITTLENUM;
5146           size--;
5147           bignum++;
5148         }
5149
5150       byte = val & 0x7f;
5151       loaded -= 7;
5152       val >>= 7;
5153
5154       if (size > 0 || val)
5155         byte |= 0x80;
5156
5157       if (orig)
5158         *p = byte;
5159       p++;
5160     }
5161   while (byte & 0x80);
5162
5163   return p - orig;
5164 }
5165
5166 static int
5167 output_big_leb128 (char *p, LITTLENUM_TYPE *bignum, int size, int sign)
5168 {
5169   if (sign)
5170     return output_big_sleb128 (p, bignum, size);
5171   else
5172     return output_big_uleb128 (p, bignum, size);
5173 }
5174
5175 /* Generate the appropriate fragments for a given expression to emit a
5176    leb128 value.  */
5177
5178 static void
5179 emit_leb128_expr (expressionS *exp, int sign)
5180 {
5181   operatorT op = exp->X_op;
5182   unsigned int nbytes;
5183
5184   if (op == O_absent || op == O_illegal)
5185     {
5186       as_warn (_("zero assumed for missing expression"));
5187       exp->X_add_number = 0;
5188       op = O_constant;
5189     }
5190   else if (op == O_big && exp->X_add_number <= 0)
5191     {
5192       as_bad (_("floating point number invalid"));
5193       exp->X_add_number = 0;
5194       op = O_constant;
5195     }
5196   else if (op == O_register)
5197     {
5198       as_warn (_("register value used as expression"));
5199       op = O_constant;
5200     }
5201   else if (op == O_constant
5202            && sign
5203            && (exp->X_add_number < 0) != !exp->X_unsigned)
5204     {
5205       /* We're outputting a signed leb128 and the sign of X_add_number
5206          doesn't reflect the sign of the original value.  Convert EXP
5207          to a correctly-extended bignum instead.  */
5208       convert_to_bignum (exp);
5209       op = O_big;
5210     }
5211
5212   /* Let check_eh_frame know that data is being emitted.  nbytes == -1 is
5213      a signal that this is leb128 data.  It shouldn't optimize this away.  */
5214   nbytes = (unsigned int) -1;
5215   if (check_eh_frame (exp, &nbytes))
5216     abort ();
5217
5218   /* Let the backend know that subsequent data may be byte aligned.  */
5219 #ifdef md_cons_align
5220   md_cons_align (1);
5221 #endif
5222
5223   if (op == O_constant)
5224     {
5225       /* If we've got a constant, emit the thing directly right now.  */
5226
5227       valueT value = exp->X_add_number;
5228       int size;
5229       char *p;
5230
5231       size = sizeof_leb128 (value, sign);
5232       p = frag_more (size);
5233       output_leb128 (p, value, sign);
5234     }
5235   else if (op == O_big)
5236     {
5237       /* O_big is a different sort of constant.  */
5238
5239       int size;
5240       char *p;
5241
5242       size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign);
5243       p = frag_more (size);
5244       output_big_leb128 (p, generic_bignum, exp->X_add_number, sign);
5245     }
5246   else
5247     {
5248       /* Otherwise, we have to create a variable sized fragment and
5249          resolve things later.  */
5250
5251       frag_var (rs_leb128, sizeof_uleb128 (~(valueT) 0), 0, sign,
5252                 make_expr_symbol (exp), 0, (char *) NULL);
5253     }
5254 }
5255
5256 /* Parse the .sleb128 and .uleb128 pseudos.  */
5257
5258 void
5259 s_leb128 (int sign)
5260 {
5261   expressionS exp;
5262
5263 #ifdef md_flush_pending_output
5264   md_flush_pending_output ();
5265 #endif
5266
5267   do
5268     {
5269       expression (&exp);
5270       emit_leb128_expr (&exp, sign);
5271     }
5272   while (*input_line_pointer++ == ',');
5273
5274   input_line_pointer--;
5275   demand_empty_rest_of_line ();
5276 }
5277 \f
5278 static void
5279 stringer_append_char (int c, int bitsize)
5280 {
5281   if (!target_big_endian)
5282     FRAG_APPEND_1_CHAR (c);
5283
5284   switch (bitsize)
5285     {
5286     case 64:
5287       FRAG_APPEND_1_CHAR (0);
5288       FRAG_APPEND_1_CHAR (0);
5289       FRAG_APPEND_1_CHAR (0);
5290       FRAG_APPEND_1_CHAR (0);
5291       /* Fall through.  */
5292     case 32:
5293       FRAG_APPEND_1_CHAR (0);
5294       FRAG_APPEND_1_CHAR (0);
5295       /* Fall through.  */
5296     case 16:
5297       FRAG_APPEND_1_CHAR (0);
5298       /* Fall through.  */
5299     case 8:
5300       break;
5301     default:
5302       /* Called with invalid bitsize argument.  */
5303       abort ();
5304       break;
5305     }
5306   if (target_big_endian)
5307     FRAG_APPEND_1_CHAR (c);
5308 }
5309
5310 /* Worker to do .ascii etc statements.
5311    Reads 0 or more ',' separated, double-quoted strings.
5312    Caller should have checked need_pass_2 is FALSE because we don't
5313    check it.
5314    Checks for end-of-line.
5315    BITS_APPENDZERO says how many bits are in a target char.
5316    The bottom bit is set if a NUL char should be appended to the strings.  */
5317
5318 void
5319 stringer (int bits_appendzero)
5320 {
5321   const int bitsize = bits_appendzero & ~7;
5322   const int append_zero = bits_appendzero & 1;
5323   unsigned int c;
5324 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5325   char *start;
5326 #endif
5327
5328 #ifdef md_flush_pending_output
5329   md_flush_pending_output ();
5330 #endif
5331
5332 #ifdef md_cons_align
5333   md_cons_align (1);
5334 #endif
5335
5336   /* The following awkward logic is to parse ZERO or more strings,
5337      comma separated. Recall a string expression includes spaces
5338      before the opening '\"' and spaces after the closing '\"'.
5339      We fake a leading ',' if there is (supposed to be)
5340      a 1st, expression. We keep demanding expressions for each ','.  */
5341   if (is_it_end_of_statement ())
5342     {
5343       c = 0;                    /* Skip loop.  */
5344       ++input_line_pointer;     /* Compensate for end of loop.  */
5345     }
5346   else
5347     {
5348       c = ',';                  /* Do loop.  */
5349     }
5350   /* If we have been switched into the abs_section then we
5351      will not have an obstack onto which we can hang strings.  */
5352   if (now_seg == absolute_section)
5353     {
5354       as_bad (_("strings must be placed into a section"));
5355       c = 0;
5356       ignore_rest_of_line ();
5357     }
5358
5359   while (c == ',' || c == '<' || c == '"')
5360     {
5361       SKIP_WHITESPACE ();
5362       switch (*input_line_pointer)
5363         {
5364         case '\"':
5365           ++input_line_pointer; /*->1st char of string.  */
5366 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5367           start = input_line_pointer;
5368 #endif
5369
5370           while (is_a_char (c = next_char_of_string ()))
5371             stringer_append_char (c, bitsize);
5372
5373           if (append_zero)
5374             stringer_append_char (0, bitsize);
5375
5376           know (input_line_pointer[-1] == '\"');
5377
5378 #if !defined(NO_LISTING) && defined (OBJ_ELF)
5379           /* In ELF, when gcc is emitting DWARF 1 debugging output, it
5380              will emit .string with a filename in the .debug section
5381              after a sequence of constants.  See the comment in
5382              emit_expr for the sequence.  emit_expr will set
5383              dwarf_file_string to non-zero if this string might be a
5384              source file name.  */
5385           if (strcmp (segment_name (now_seg), ".debug") != 0)
5386             dwarf_file_string = 0;
5387           else if (dwarf_file_string)
5388             {
5389               c = input_line_pointer[-1];
5390               input_line_pointer[-1] = '\0';
5391               listing_source_file (start);
5392               input_line_pointer[-1] = c;
5393             }
5394 #endif
5395
5396           break;
5397         case '<':
5398           input_line_pointer++;
5399           c = get_single_number ();
5400           stringer_append_char (c, bitsize);
5401           if (*input_line_pointer != '>')
5402             as_bad (_("expected <nn>"));
5403
5404           input_line_pointer++;
5405           break;
5406         case ',':
5407           input_line_pointer++;
5408           break;
5409         }
5410       SKIP_WHITESPACE ();
5411       c = *input_line_pointer;
5412     }
5413
5414   demand_empty_rest_of_line ();
5415 }
5416 \f
5417 /* FIXME-SOMEDAY: I had trouble here on characters with the
5418     high bits set.  We'll probably also have trouble with
5419     multibyte chars, wide chars, etc.  Also be careful about
5420     returning values bigger than 1 byte.  xoxorich.  */
5421
5422 unsigned int
5423 next_char_of_string (void)
5424 {
5425   unsigned int c;
5426
5427   c = *input_line_pointer++ & CHAR_MASK;
5428   switch (c)
5429     {
5430     case '\"':
5431       c = NOT_A_CHAR;
5432       break;
5433
5434     case '\n':
5435       as_warn (_("unterminated string; newline inserted"));
5436       bump_line_counters ();
5437       break;
5438
5439 #ifndef NO_STRING_ESCAPES
5440     case '\\':
5441       switch (c = *input_line_pointer++)
5442         {
5443         case 'b':
5444           c = '\b';
5445           break;
5446
5447         case 'f':
5448           c = '\f';
5449           break;
5450
5451         case 'n':
5452           c = '\n';
5453           break;
5454
5455         case 'r':
5456           c = '\r';
5457           break;
5458
5459         case 't':
5460           c = '\t';
5461           break;
5462
5463         case 'v':
5464           c = '\013';
5465           break;
5466
5467         case '\\':
5468         case '"':
5469           break;                /* As itself.  */
5470
5471         case '0':
5472         case '1':
5473         case '2':
5474         case '3':
5475         case '4':
5476         case '5':
5477         case '6':
5478         case '7':
5479         case '8':
5480         case '9':
5481           {
5482             long number;
5483             int i;
5484
5485             for (i = 0, number = 0;
5486                  ISDIGIT (c) && i < 3;
5487                  c = *input_line_pointer++, i++)
5488               {
5489                 number = number * 8 + c - '0';
5490               }
5491
5492             c = number & 0xff;
5493           }
5494           --input_line_pointer;
5495           break;
5496
5497         case 'x':
5498         case 'X':
5499           {
5500             long number;
5501
5502             number = 0;
5503             c = *input_line_pointer++;
5504             while (ISXDIGIT (c))
5505               {
5506                 if (ISDIGIT (c))
5507                   number = number * 16 + c - '0';
5508                 else if (ISUPPER (c))
5509                   number = number * 16 + c - 'A' + 10;
5510                 else
5511                   number = number * 16 + c - 'a' + 10;
5512                 c = *input_line_pointer++;
5513               }
5514             c = number & 0xff;
5515             --input_line_pointer;
5516           }
5517           break;
5518
5519         case '\n':
5520           /* To be compatible with BSD 4.2 as: give the luser a linefeed!!  */
5521           as_warn (_("unterminated string; newline inserted"));
5522           c = '\n';
5523           bump_line_counters ();
5524           break;
5525
5526         default:
5527
5528 #ifdef ONLY_STANDARD_ESCAPES
5529           as_bad (_("bad escaped character in string"));
5530           c = '?';
5531 #endif /* ONLY_STANDARD_ESCAPES */
5532
5533           break;
5534         }
5535       break;
5536 #endif /* ! defined (NO_STRING_ESCAPES) */
5537
5538     default:
5539       break;
5540     }
5541   return (c);
5542 }
5543 \f
5544 static segT
5545 get_segmented_expression (expressionS *expP)
5546 {
5547   segT retval;
5548
5549   retval = expression (expP);
5550   if (expP->X_op == O_illegal
5551       || expP->X_op == O_absent
5552       || expP->X_op == O_big)
5553     {
5554       as_bad (_("expected address expression"));
5555       expP->X_op = O_constant;
5556       expP->X_add_number = 0;
5557       retval = absolute_section;
5558     }
5559   return retval;
5560 }
5561
5562 static segT
5563 get_known_segmented_expression (expressionS *expP)
5564 {
5565   segT retval = get_segmented_expression (expP);
5566
5567   if (retval == undefined_section)
5568     {
5569       /* There is no easy way to extract the undefined symbol from the
5570          expression.  */
5571       if (expP->X_add_symbol != NULL
5572           && S_GET_SEGMENT (expP->X_add_symbol) != expr_section)
5573         as_warn (_("symbol \"%s\" undefined; zero assumed"),
5574                  S_GET_NAME (expP->X_add_symbol));
5575       else
5576         as_warn (_("some symbol undefined; zero assumed"));
5577       retval = absolute_section;
5578       expP->X_op = O_constant;
5579       expP->X_add_number = 0;
5580     }
5581   return retval;
5582 }
5583
5584 char                            /* Return terminator.  */
5585 get_absolute_expression_and_terminator (long *val_pointer /* Return value of expression.  */)
5586 {
5587   /* FIXME: val_pointer should probably be offsetT *.  */
5588   *val_pointer = (long) get_absolute_expression ();
5589   return (*input_line_pointer++);
5590 }
5591 \f
5592 /* Like demand_copy_string, but return NULL if the string contains any '\0's.
5593    Give a warning if that happens.  */
5594
5595 char *
5596 demand_copy_C_string (int *len_pointer)
5597 {
5598   char *s;
5599
5600   if ((s = demand_copy_string (len_pointer)) != 0)
5601     {
5602       int len;
5603
5604       for (len = *len_pointer; len > 0; len--)
5605         {
5606           if (*s == 0)
5607             {
5608               s = 0;
5609               len = 1;
5610               *len_pointer = 0;
5611               as_bad (_("this string may not contain \'\\0\'"));
5612             }
5613         }
5614     }
5615
5616   return s;
5617 }
5618 \f
5619 /* Demand string, but return a safe (=private) copy of the string.
5620    Return NULL if we can't read a string here.  */
5621
5622 char *
5623 demand_copy_string (int *lenP)
5624 {
5625   unsigned int c;
5626   int len;
5627   char *retval;
5628
5629   len = 0;
5630   SKIP_WHITESPACE ();
5631   if (*input_line_pointer == '\"')
5632     {
5633       input_line_pointer++;     /* Skip opening quote.  */
5634
5635       while (is_a_char (c = next_char_of_string ()))
5636         {
5637           obstack_1grow (&notes, c);
5638           len++;
5639         }
5640       /* JF this next line is so demand_copy_C_string will return a
5641          null terminated string.  */
5642       obstack_1grow (&notes, '\0');
5643       retval = (char *) obstack_finish (&notes);
5644     }
5645   else
5646     {
5647       as_bad (_("missing string"));
5648       retval = NULL;
5649       ignore_rest_of_line ();
5650     }
5651   *lenP = len;
5652   return (retval);
5653 }
5654 \f
5655 /* In:  Input_line_pointer->next character.
5656
5657    Do:  Skip input_line_pointer over all whitespace.
5658
5659    Out: 1 if input_line_pointer->end-of-line.  */
5660
5661 int
5662 is_it_end_of_statement (void)
5663 {
5664   SKIP_WHITESPACE ();
5665   return (is_end_of_line[(unsigned char) *input_line_pointer]);
5666 }
5667
5668 void
5669 equals (char *sym_name, int reassign)
5670 {
5671   char *stop = NULL;
5672   char stopc = 0;
5673
5674   input_line_pointer++;
5675   if (*input_line_pointer == '=')
5676     input_line_pointer++;
5677   if (reassign < 0 && *input_line_pointer == '=')
5678     input_line_pointer++;
5679
5680   while (*input_line_pointer == ' ' || *input_line_pointer == '\t')
5681     input_line_pointer++;
5682
5683   if (flag_mri)
5684     stop = mri_comment_field (&stopc);
5685
5686   assign_symbol (sym_name, reassign >= 0 ? !reassign : reassign);
5687
5688   if (flag_mri)
5689     {
5690       demand_empty_rest_of_line ();
5691       mri_comment_end (stop, stopc);
5692     }
5693 }
5694
5695 /* .incbin -- include a file verbatim at the current location.  */
5696
5697 void
5698 s_incbin (int x ATTRIBUTE_UNUSED)
5699 {
5700   FILE * binfile;
5701   char * path;
5702   char * filename;
5703   char * binfrag;
5704   long   skip = 0;
5705   long   count = 0;
5706   long   bytes;
5707   int    len;
5708
5709 #ifdef md_flush_pending_output
5710   md_flush_pending_output ();
5711 #endif
5712
5713 #ifdef md_cons_align
5714   md_cons_align (1);
5715 #endif
5716
5717   SKIP_WHITESPACE ();
5718   filename = demand_copy_string (& len);
5719   if (filename == NULL)
5720     return;
5721
5722   SKIP_WHITESPACE ();
5723
5724   /* Look for optional skip and count.  */
5725   if (* input_line_pointer == ',')
5726     {
5727       ++ input_line_pointer;
5728       skip = get_absolute_expression ();
5729
5730       SKIP_WHITESPACE ();
5731
5732       if (* input_line_pointer == ',')
5733         {
5734           ++ input_line_pointer;
5735
5736           count = get_absolute_expression ();
5737           if (count == 0)
5738             as_warn (_(".incbin count zero, ignoring `%s'"), filename);
5739
5740           SKIP_WHITESPACE ();
5741         }
5742     }
5743
5744   demand_empty_rest_of_line ();
5745
5746   /* Try opening absolute path first, then try include dirs.  */
5747   binfile = fopen (filename, FOPEN_RB);
5748   if (binfile == NULL)
5749     {
5750       int i;
5751
5752       path = (char *) xmalloc ((unsigned long) len + include_dir_maxlen + 5);
5753
5754       for (i = 0; i < include_dir_count; i++)
5755         {
5756           sprintf (path, "%s/%s", include_dirs[i], filename);
5757
5758           binfile = fopen (path, FOPEN_RB);
5759           if (binfile != NULL)
5760             break;
5761         }
5762
5763       if (binfile == NULL)
5764         as_bad (_("file not found: %s"), filename);
5765     }
5766   else
5767     path = xstrdup (filename);
5768
5769   if (binfile)
5770     {
5771       long   file_len;
5772
5773       register_dependency (path);
5774
5775       /* Compute the length of the file.  */
5776       if (fseek (binfile, 0, SEEK_END) != 0)
5777         {
5778           as_bad (_("seek to end of .incbin file failed `%s'"), path);
5779           goto done;
5780         }
5781       file_len = ftell (binfile);
5782
5783       /* If a count was not specified use the remainder of the file.  */
5784       if (count == 0)
5785         count = file_len - skip;
5786
5787       if (skip < 0 || count < 0 || file_len < 0 || skip + count > file_len)
5788         {
5789           as_bad (_("skip (%ld) or count (%ld) invalid for file size (%ld)"),
5790                   skip, count, file_len);
5791           goto done;
5792         }
5793
5794       if (fseek (binfile, skip, SEEK_SET) != 0)
5795         {
5796           as_bad (_("could not skip to %ld in file `%s'"), skip, path);
5797           goto done;
5798         }
5799
5800       /* Allocate frag space and store file contents in it.  */
5801       binfrag = frag_more (count);
5802
5803       bytes = fread (binfrag, 1, count, binfile);
5804       if (bytes < count)
5805         as_warn (_("truncated file `%s', %ld of %ld bytes read"),
5806                  path, bytes, count);
5807     }
5808 done:
5809   if (binfile != NULL)
5810     fclose (binfile);
5811   if (path)
5812     free (path);
5813 }
5814
5815 /* .include -- include a file at this point.  */
5816
5817 void
5818 s_include (int arg ATTRIBUTE_UNUSED)
5819 {
5820   char *filename;
5821   int i;
5822   FILE *try_file;
5823   char *path;
5824
5825   if (!flag_m68k_mri)
5826     {
5827       filename = demand_copy_string (&i);
5828       if (filename == NULL)
5829         {
5830           /* demand_copy_string has already printed an error and
5831              called ignore_rest_of_line.  */
5832           return;
5833         }
5834     }
5835   else
5836     {
5837       SKIP_WHITESPACE ();
5838       i = 0;
5839       while (!is_end_of_line[(unsigned char) *input_line_pointer]
5840              && *input_line_pointer != ' '
5841              && *input_line_pointer != '\t')
5842         {
5843           obstack_1grow (&notes, *input_line_pointer);
5844           ++input_line_pointer;
5845           ++i;
5846         }
5847
5848       obstack_1grow (&notes, '\0');
5849       filename = (char *) obstack_finish (&notes);
5850       while (!is_end_of_line[(unsigned char) *input_line_pointer])
5851         ++input_line_pointer;
5852     }
5853
5854   demand_empty_rest_of_line ();
5855   path = (char *) xmalloc ((unsigned long) i
5856                            + include_dir_maxlen + 5 /* slop */ );
5857
5858   for (i = 0; i < include_dir_count; i++)
5859     {
5860       strcpy (path, include_dirs[i]);
5861       strcat (path, "/");
5862       strcat (path, filename);
5863       if (0 != (try_file = fopen (path, FOPEN_RT)))
5864         {
5865           fclose (try_file);
5866           goto gotit;
5867         }
5868     }
5869
5870   free (path);
5871   path = filename;
5872 gotit:
5873   /* malloc Storage leak when file is found on path.  FIXME-SOMEDAY.  */
5874   register_dependency (path);
5875   input_scrub_insert_file (path);
5876 }
5877
5878 void
5879 add_include_dir (char *path)
5880 {
5881   int i;
5882
5883   if (include_dir_count == 0)
5884     {
5885       include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs));
5886       include_dirs[0] = ".";    /* Current dir.  */
5887       include_dir_count = 2;
5888     }
5889   else
5890     {
5891       include_dir_count++;
5892       include_dirs =
5893         (char **) realloc (include_dirs,
5894                            include_dir_count * sizeof (*include_dirs));
5895     }
5896
5897   include_dirs[include_dir_count - 1] = path;   /* New one.  */
5898
5899   i = strlen (path);
5900   if (i > include_dir_maxlen)
5901     include_dir_maxlen = i;
5902 }
5903 \f
5904 /* Output debugging information to denote the source file.  */
5905
5906 static void
5907 generate_file_debug (void)
5908 {
5909   if (debug_type == DEBUG_STABS)
5910     stabs_generate_asm_file ();
5911 }
5912
5913 /* Output line number debugging information for the current source line.  */
5914
5915 void
5916 generate_lineno_debug (void)
5917 {
5918   switch (debug_type)
5919     {
5920     case DEBUG_UNSPECIFIED:
5921     case DEBUG_NONE:
5922     case DEBUG_DWARF:
5923       break;
5924     case DEBUG_STABS:
5925       stabs_generate_asm_lineno ();
5926       break;
5927     case DEBUG_ECOFF:
5928       ecoff_generate_asm_lineno ();
5929       break;
5930     case DEBUG_DWARF2:
5931       /* ??? We could here indicate to dwarf2dbg.c that something
5932          has changed.  However, since there is additional backend
5933          support that is required (calling dwarf2_emit_insn), we
5934          let dwarf2dbg.c call as_where on its own.  */
5935       break;
5936     }
5937 }
5938
5939 /* Output debugging information to mark a function entry point or end point.
5940    END_P is zero for .func, and non-zero for .endfunc.  */
5941
5942 void
5943 s_func (int end_p)
5944 {
5945   do_s_func (end_p, NULL);
5946 }
5947
5948 /* Subroutine of s_func so targets can choose a different default prefix.
5949    If DEFAULT_PREFIX is NULL, use the target's "leading char".  */
5950
5951 static void
5952 do_s_func (int end_p, const char *default_prefix)
5953 {
5954   /* Record the current function so that we can issue an error message for
5955      misplaced .func,.endfunc, and also so that .endfunc needs no
5956      arguments.  */
5957   static char *current_name;
5958   static char *current_label;
5959
5960   if (end_p)
5961     {
5962       if (current_name == NULL)
5963         {
5964           as_bad (_("missing .func"));
5965           ignore_rest_of_line ();
5966           return;
5967         }
5968
5969       if (debug_type == DEBUG_STABS)
5970         stabs_generate_asm_endfunc (current_name, current_label);
5971
5972       current_name = current_label = NULL;
5973     }
5974   else /* ! end_p */
5975     {
5976       char *name, *label;
5977       char delim1, delim2;
5978
5979       if (current_name != NULL)
5980         {
5981           as_bad (_(".endfunc missing for previous .func"));
5982           ignore_rest_of_line ();
5983           return;
5984         }
5985
5986       name = input_line_pointer;
5987       delim1 = get_symbol_end ();
5988       name = xstrdup (name);
5989       *input_line_pointer = delim1;
5990       SKIP_WHITESPACE ();
5991       if (*input_line_pointer != ',')
5992         {
5993           if (default_prefix)
5994             {
5995               if (asprintf (&label, "%s%s", default_prefix, name) == -1)
5996                 as_fatal ("%s", xstrerror (errno));
5997             }
5998           else
5999             {
6000               char leading_char = bfd_get_symbol_leading_char (stdoutput);
6001               /* Missing entry point, use function's name with the leading
6002                  char prepended.  */
6003               if (leading_char)
6004                 {
6005                   if (asprintf (&label, "%c%s", leading_char, name) == -1)
6006                     as_fatal ("%s", xstrerror (errno));
6007                 }
6008               else
6009                 label = name;
6010             }
6011         }
6012       else
6013         {
6014           ++input_line_pointer;
6015           SKIP_WHITESPACE ();
6016           label = input_line_pointer;
6017           delim2 = get_symbol_end ();
6018           label = xstrdup (label);
6019           *input_line_pointer = delim2;
6020         }
6021
6022       if (debug_type == DEBUG_STABS)
6023         stabs_generate_asm_func (name, label);
6024
6025       current_name = name;
6026       current_label = label;
6027     }
6028
6029   demand_empty_rest_of_line ();
6030 }
6031 \f
6032 #ifdef HANDLE_BUNDLE
6033
6034 void
6035 s_bundle_align_mode (int arg ATTRIBUTE_UNUSED)
6036 {
6037   unsigned int align = get_absolute_expression ();
6038   SKIP_WHITESPACE ();
6039   demand_empty_rest_of_line ();
6040
6041   if (align > (unsigned int) TC_ALIGN_LIMIT)
6042     as_fatal (_(".bundle_align_mode alignment too large (maximum %u)"),
6043               (unsigned int) TC_ALIGN_LIMIT);
6044
6045   if (bundle_lock_frag != NULL)
6046     {
6047       as_bad (_("cannot change .bundle_align_mode inside .bundle_lock"));
6048       return;
6049     }
6050
6051   bundle_align_p2 = align;
6052 }
6053
6054 void
6055 s_bundle_lock (int arg ATTRIBUTE_UNUSED)
6056 {
6057   demand_empty_rest_of_line ();
6058
6059   if (bundle_align_p2 == 0)
6060     {
6061       as_bad (_(".bundle_lock is meaningless without .bundle_align_mode"));
6062       return;
6063     }
6064
6065   if (bundle_lock_frag != NULL)
6066     {
6067       as_bad (_("second .bundle_lock without .bundle_unlock"));
6068       return;
6069     }
6070
6071   bundle_lock_frchain = frchain_now;
6072   bundle_lock_frag = start_bundle ();
6073 }
6074
6075 void
6076 s_bundle_unlock (int arg ATTRIBUTE_UNUSED)
6077 {
6078   unsigned int size;
6079
6080   demand_empty_rest_of_line ();
6081
6082   if (bundle_lock_frag == NULL)
6083     {
6084       as_bad (_(".bundle_unlock without preceding .bundle_lock"));
6085       return;
6086     }
6087
6088   gas_assert (bundle_align_p2 > 0);
6089
6090   size = pending_bundle_size (bundle_lock_frag);
6091
6092   if (size > (1U << bundle_align_p2))
6093     as_bad (_(".bundle_lock sequence is %u bytes, but bundle size only %u"),
6094             size, 1 << bundle_align_p2);
6095   else
6096     finish_bundle (bundle_lock_frag, size);
6097
6098   bundle_lock_frag = NULL;
6099   bundle_lock_frchain = NULL;
6100 }
6101
6102 #endif  /* HANDLE_BUNDLE */
6103 \f
6104 void
6105 s_ignore (int arg ATTRIBUTE_UNUSED)
6106 {
6107   ignore_rest_of_line ();
6108 }
6109
6110 void
6111 read_print_statistics (FILE *file)
6112 {
6113   hash_print_statistics (file, "pseudo-op table", po_hash);
6114 }
6115
6116 /* Inserts the given line into the input stream.
6117
6118    This call avoids macro/conditionals nesting checking, since the contents of
6119    the line are assumed to replace the contents of a line already scanned.
6120
6121    An appropriate use of this function would be substitution of input lines when
6122    called by md_start_line_hook().  The given line is assumed to already be
6123    properly scrubbed.  */
6124
6125 void
6126 input_scrub_insert_line (const char *line)
6127 {
6128   sb newline;
6129   sb_new (&newline);
6130   sb_add_string (&newline, line);
6131   input_scrub_include_sb (&newline, input_line_pointer, 0);
6132   sb_kill (&newline);
6133   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6134 }
6135
6136 /* Insert a file into the input stream; the path must resolve to an actual
6137    file; no include path searching or dependency registering is performed.  */
6138
6139 void
6140 input_scrub_insert_file (char *path)
6141 {
6142   input_scrub_include_file (path, input_line_pointer);
6143   buffer_limit = input_scrub_next_buffer (&input_line_pointer);
6144 }
6145
6146 /* Find the end of a line, considering quotation and escaping of quotes.  */
6147
6148 #if !defined(TC_SINGLE_QUOTE_STRINGS) && defined(SINGLE_QUOTE_STRINGS)
6149 # define TC_SINGLE_QUOTE_STRINGS 1
6150 #endif
6151
6152 static char *
6153 _find_end_of_line (char *s, int mri_string, int insn ATTRIBUTE_UNUSED,
6154                    int in_macro)
6155 {
6156   char inquote = '\0';
6157   int inescape = 0;
6158
6159   while (!is_end_of_line[(unsigned char) *s]
6160          || (inquote && !ISCNTRL (*s))
6161          || (inquote == '\'' && flag_mri)
6162 #ifdef TC_EOL_IN_INSN
6163          || (insn && TC_EOL_IN_INSN (s))
6164 #endif
6165          /* PR 6926:  When we are parsing the body of a macro the sequence
6166             \@ is special - it refers to the invocation count.  If the @
6167             character happens to be registered as a line-separator character
6168             by the target, then the is_end_of_line[] test above will have
6169             returned true, but we need to ignore the line separating
6170             semantics in this particular case.  */
6171          || (in_macro && inescape && *s == '@')
6172         )
6173     {
6174       if (mri_string && *s == '\'')
6175         inquote ^= *s;
6176       else if (inescape)
6177         inescape = 0;
6178       else if (*s == '\\')
6179         inescape = 1;
6180       else if (!inquote
6181                ? *s == '"'
6182 #ifdef TC_SINGLE_QUOTE_STRINGS
6183                  || (TC_SINGLE_QUOTE_STRINGS && *s == '\'')
6184 #endif
6185                : *s == inquote)
6186         inquote ^= *s;
6187       ++s;
6188     }
6189   if (inquote)
6190     as_warn (_("missing closing `%c'"), inquote);
6191   if (inescape)
6192     as_warn (_("stray `\\'"));
6193   return s;
6194 }
6195
6196 char *
6197 find_end_of_line (char *s, int mri_string)
6198 {
6199   return _find_end_of_line (s, mri_string, 0, 0);
6200 }