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