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