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