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