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