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